Εμφάνιση αναρτήσεων με ετικέτα ibm. Εμφάνιση όλων των αναρτήσεων
Εμφάνιση αναρτήσεων με ετικέτα ibm. Εμφάνιση όλων των αναρτήσεων

Παρασκευή 28 Σεπτεμβρίου 2018

For a million IFs less

One of the first you learn in #Cobol, especially back in the day when indexed files where a common practice, is the use of SW-FIRST-READ.

In a program flow most probably there’s a loop on a cursor or a file. Many programmers inside that main loop they use an IF for controlling the first read. For example, if you want to match previous and current row/record.  The COBOL code would be something like:

01 SW-FIRST-READ PIC X VALUE ‘Y’.

  88 FIRST-READ-YES   VALUE ‘Y’.

  88 FIRST-READ-NOT   VALUE ‘N’.

MAIN-ROUTE.

   PERFORM READ-ROUTE

   #PERFORM UNTIL EOF

     #IF FIRST-READ-YES

        SET FIRST-READ-NOT TO TRUE

        MOVE CURRENT-RECORD TO PREVIOUS-RECORD

     END-IF

     IF CURRENT-RECORD = PREVIOUS-RECORD

        DISPLAY ‘SAME ACCOUNT’

        PERFORM SAME-ACCOUNT-ROUTE

     ELSE

        DISPLAY ‘NEW ACCOUNT’

        PERFORM NEW-ACCOUNT-ROUTE

     END-IF

     PERFORM READ-ROUTE

   END-PERFORM

  IF EOF AND SW-FIRST-READ

      DISPLAY ‘NO RECORDS/ROWS IN FILE/CURSOR’

      PERFORM EMPY-FILE-OR-CURSOR-ROUTE

   END-IF .

READ-ROUTE.

    READ FILE NEXT AT END SET SW-EOF TO TRUE

(OR)

   FETCH CURSOR

   IF SQLCODE = NOT-FOUND-NEXT

      SET SW-EOF TO TRUE

   END-IF

 IF SQLCODE/FILE-STATUS NOT-OK

      ERROR-HANDLING-ROUTE

    END-IF.

This is a very common practice with one fault for performance. The IF SW-FIRST-READ will execute as many times as the ROWS/RECORDS of the CURSOR/FILE – 1.000.000 or 50.000.000 times, and IF statement is not a fast one.

My recommendation would have some more code to be written, some paragraph rearrangements and involve a bit more thinking. But it will have 1.000.000 IFs less.

You will have to have separate paragraphs for #READ / #FETCH, for error handling and PERFORM these paragraphs twice, once before the main loop. That one would be the first time and will be executed only once. There’s no need to ask again. The code would look like this:

MAIN-ROUTE.

   PERFORM READ-ROUTE

   IF NOT-EOF

      MOVE CURRENT-RECORD TO PREVIOUS-RECORD

   ELSE

      DISPLAY ‘NO RECORDS/ROWS IN FILE/CURSOR’

      PERFORM EMPY-FILE-OR-CURSOR-ROUTE

   END-IF

   PERFORM UNTIL EOF

     IF CURRENT-RECORD = PREVIOUS-RECORD

        DISPLAY ‘SAME ACCOUNT’

        PERFORM SAME-ACCOUNT-ROUTE

     ELSE

        DISPLAY ‘NEW ACCOUNT’

        PERFORM NEW-ACCOUNT-ROUTE

     END-IF

   END-PERFORM

  PERFORM END-ROUTE  .

READ-ROUTE.

   READ FILE NEXT AT END SET SW-EOF TO TRUE

(OR)

   #FETCH #CURSOR

   IF SQLCODE = NOT-FOUND-NEXT

      SET SW-EOF TO TRUE

   END-IF

   IF SQLCODE/FILE-STATUS NOT-OK

      #ERRORHANDLING-ROUTE

    END-IF.

Σάββατο 25 Νοεμβρίου 2017

Multiple record output file with variable field emulation from COBOL

Hey all of you programmers (not developers :P) in the COBOL world.
I love COBOL, I’ve actually sold my fist COBOL application in 1987, a video club.  Well I guess I am ancient, but I saw things work at 8088 atx pc’s with 2 floppy disk, one for the OS and the COBOL runtime and one for the data.

I’ve worked COBOL mostly on UNIX servers with index files, and yes I’ve worked .NET VB C# and SQL SERVER too, but as life goes to circles I’m again at iseries COBOL environment with emended DB2 SQL

Oh, all you lucky ones for this blessing. Unlimeted power if you combine the tools, not only combine, overlap them to the far edges. Because I saw that COBOL programmers don’t want to be involved much with SQL and vice versa.

Well, personally I’ve worked both environments, loved both techniques and when I found them together I wanted to bring them as close they could get so I present their child.
Multiple record output file with variable field emulation from COBOL
Ok, I know, I did not invented the wheel, but I know back in the 90’s how costly was in time and effort to do all the work. Design the Cobol output records, make the Z masks, keep in track, print with semicolon, and have a csv to work in XL. OK. No variable fields though eh?

Time to go beyond. Time for the code which also started differently because of the urgent of the project.

Well I knew that the requirements of the output was a csv of multiple records and variable length fields(put that aside).
But it was damn urgent and it had its difficulties as you had to open cursor over cursor over cursor.

Get sums by customer, product month.
Calculate fields, interests, percentages,
Sup up sub totals again
Sum up totals by product month
Trail to output 8 different kind of records of other data.

All of us coding on COBOL we know, 3.000 lines of coding lol
So I decided to go by just SQL and see what happens…
1 cursor with doing_it_all_sql statement RAPID development in 2 days I’ve done the tests
That was pretty a 3 level SQL statement that turn to my cursor (not so simple as there were joins cases, complex where and so on).
  
An Inner pool fetched groups of totals per customer, product month
A middle pool took the fields and made all calculation action
And Finally an outer Join that made the total sum ups group by product month.

TOTAL_POOL:
(OUTER POOL:
(SELECT SUM(MP.FIELD1, AVG(MP.FIELD2), AND SO ON
MIDDLE POOL:
(SELECT IP.FIELD1  * MJ1.FIELD1 /MJ2.PERCENTAGE (AND SO ON)
FROM(
INNER POOL :   SELECT I_FIELD_1, I_FIELD2…. SUM(I_FIELDn
                            FROM
                            INNER JOINS
                            WHERE
                            GROUP BY I_FIELD_1, I_FIELD2…. SUM(I_FIELDn) IP
INNER JOIN MJ1 ON
INNER JOIN MJ2 ON
WHERE) AS MP
WHERE
GROUP BY SUM(MP.FIELD1, AVG(MP.FIELD2), AND SO ON) AS OUTER POOL) as TP

Standard SQL, standard procedure for SQL developers, but not for COBOL ones. It should because when you start thinking bind with the tool you are limited to the tool. When you think the solution and not the tools you choose the tool.
I had already decided to have just my output record and no other COBOL command than
WRITE OUTPUT-REC.




I  already fetched my fields  so either I have it on WORKING storage (through FETCH INTO or even better I nest an another select level above OUTER POOL that goes like this. I would recommend a different step for purposes of code control but it could be a final nest of a FROM SYSIBM.SYSDUMMY  for performance purposes.

SELECT A.TRIM([FORMAT_VARCHAR]A.FIELD) || ‘;’ || TRIM(TP.FIELD1) ||’;’||’This is a vertical label:’ ||’;’||FORMAT_VARCHAR(B.DATEFIELD, YYYYMM) and so on and so forth
FROM TP or SYSIBM.SYSDUMMY1
INTO :OUTPUT-REC
INNER JOIN A ON
INNER JOIN B ON
WHERE
ORDER BY
END-EXEC
WRITE OUTPUT-REC (the maximum length required)
And the code went on to gather the other kind of records, concat fields, format them as needed and output them, rapidly.



Hope this would be useful  to some of you 

Polykarpos Parioritsas
sr. IT Analyst

Παρασκευή 17 Νοεμβρίου 2017

τα τρία PC

6 τα ξημερώματα και με μέρες σκληρής δουλειάς αλλά..

τώρα μπήκαν σε σειρά.. 
ειδικά ο σταθμός development θα εγκαθιστά μέχρι την Κυριακή όσα πρέπει αλλά χαλάλι, αν είναι καλή η ιδέα και ευχάριστη η δουλειά, μετά την δουλειά...

Στο ένα έστησα λειτουργικό και κάνει updates(άπειρα) για να δοθεί έτοιμο,

το άλλο το είναι .net dvlp station και κάμποση COBOL  και βέβαια για διάβασμα, να παρακολουθούμε και καμιά εξέλιξη στην τεχνολογία.

COBOL freaks out there .. when I find time I'll show how I achieved variable lenngth emulation file for csv format!!! out of the box thinking and works perfect 
 



Το τρίτο ένα ρετουσάρισμα για να κάθονται οι υπόλοιποι (εγώ πάω δίπλα να γράφω κώδικα λολολ)
Δουλειά να μη σου λείπει όταν δεν κοιμάσαι 

(Φίλε Αλέξη εκεί στα κρύα.. στο αφιερώνω το post)
Και να τελειώνουμε και κανένα από τα αρχινισμένα μυθιστορήματα που περιμένουν ε;

by the way