Page 1 of 1

COBOL Tips.

Posted: Fri May 24, 2013 11:16 pm
by Anuj Dhawan
1. Do you know how COBOL Compiler finds a data-set as VSAM data-set? When the ORGANIZATION clause is coded for a file, the COBOL compiler interprets it as a VSAM data-set. Hence, the ORGANIZATION clause should not be coded with a non-VSAM data-set.

Re: COBOL Tips.

Posted: Tue May 28, 2013 8:38 pm
by Anuj Dhawan
2. Using an odd number of digits for PACKED DECIMAL (COMP-3) is 5% to 20% faster than using an even number of digits... why? It's a "Tip of the Day" section and not the "Explanation of the Day" section. So I leave that for the reader to explore... :)

Re: COBOL Tips.

Posted: Tue Jul 16, 2013 6:34 pm
by Anuj Dhawan
3. MERGE statement can have OUTPUT PROCEDURE but not INPUT PROCEDURE.

Re: COBOL Tips.

Posted: Tue Jul 16, 2013 6:37 pm
by Anuj Dhawan
4. For a table with less than 50 entries use SEARCH ( Sequential Search) and for greater than 50 entries, use SEARCH ALL ( Binary Search). (though opinions vary, however, it's usually advisable).

Re: COBOL Tips.

Posted: Tue Jul 16, 2013 6:43 pm
by Robert Sample
Regarding tip 1: COBOL recognizes a VSAM ESDS file by the presence of AS-ddname in the SELECT statement.

Re: COBOL Tips.

Posted: Tue Aug 06, 2013 3:36 pm
by Anuj Dhawan
5. Carefully use the verb INITALIZE. It generates a move for every non-filler elementary data item, especially on very long records or large files. If you need to use INITALIZE do it once in "housekeeping" and save in "working-storage". Then move the group from working storage wherever you would code the INITALIZE.

Re: COBOL Tips.

Posted: Tue Aug 06, 2013 3:36 pm
by Anuj Dhawan
6. Always remove test compile options such as “Displays”, before implementing into production.

Re: COBOL Tips.

Posted: Sat Aug 10, 2013 10:39 pm
by Anuj Dhawan
7. In continuation with what Robert has said that if you are accessing ESDS VSAM file, then in COBOL SELECT clause has AS-DDNAME. If you are not doing that then an S213 ABEND might occur when attempting to open data set.

Re: COBOL Tips.

Posted: Sat Aug 10, 2013 10:41 pm
by Anuj Dhawan
8. Have you ever thought why it's READ FILE in COBOL and not READ RECORD as it's in WRITE RECORD? :)

The answer is: You READ FILE because, there is no way out to know in advance:
  1. If there is actually a record to read or not
  2. For variable or undefined length files, one does not know how long the next record will be if there is one.
And You WRITE RECORD because without knowing above two answers one can not write in and while WRITing program already know them.

Re: COBOL Tips.

Posted: Tue Oct 01, 2013 1:53 pm
by Anuj Dhawan
9. For Enterprise Cobol V 4.1 (onwards) for zOS, if you compile the program using the compiler option "XREF ON", one can see from where the Copybook came that was used while compiling the Program.

In the listing find for "COPY/BASIS" (when XREF ON is used) - This section lists the copybooks and their location.


Re: COBOL Tips.

Posted: Tue Oct 01, 2013 2:27 pm
by Anuj Dhawan
10. It's advisable that, if possible avoid doing a sort within a COBOL program. COBOL sorts are very inefficient. If you must do a sort in a COBOL program, specifying the FASTSRT compiler option may be handy for tuning. On the other hand, if you are using INPUT/OUTPUT procedure then FASTSRT compiler option will not increase the performance. It is better to use the (DF)SORT control statements like INREC, OUTREC, SUM, SKIPREC, INCLUDE or OMIT ,STOPAFT etc and put them under the ddname SORTCNTL or IGZSRTCD.

Re: COBOL Tips.

Posted: Tue Dec 31, 2013 9:06 pm
by zprogrammer
11.When ever we do processing reading a file better to have an approach like this


Templace

Code: Select all

         Open file
         Read file
         process until EOF
                     "MAIN PROCESSING"
                      Read file
         Close file   

Re: COBOL Tips.

Posted: Tue Feb 11, 2014 1:13 am
by zprogrammer
12.A simple and effective way to debug your program When you have no DEBUGGING TOOL in place is

You could add display after start of every section and start of every para

On execution you could see the program flow and understand the problem much faster

Re: COBOL Tips.

Posted: Wed Mar 12, 2014 12:02 am
by Quasar Chunawala
13. As a follow-on tip to the above, I worked at a shop, where all COBOL batch modules had this standard -

Code: Select all

5500-GET-TRADES.
    MOVE '5500-GET-TRADES' TO WS-PARA-NAME
    PERFORM 9000-DEBUG THRU 9000-EXIT
    ...
    para-body
    ...
5500-EXIT. EXIT.

9000-DEBUG.
    IF LS-DEBUG-SW = 'Y'
        DISPLAY WS-PARA-NAME
    END-IF.
9000-EXIT. EXIT.
You can code the JCL as,

Code: Select all

//* By Default
//STEP010 EXEC PGM=MYPROG01,PARM='N'           
//* Turn on debug mode
//STEP020 EXEC PGM=MYPROG01,PARM='Y'           

Re: COBOL Tips.

Posted: Tue Apr 29, 2014 5:10 pm
by Anuj Dhawan
14. This is not really a "tip" but interesting to know:

In SELECT INFILE ASSIGN TO UT-S-INFILE or SELECT INFILE ASSIGN TO DA-S-INFILE - what does UT-S- and DA-S- stands for?

The syntax for SELECT clause in COBOL is SELECT file-name ASSIGN TO DD-name.

Keeping above in mind, for the second line above, the first Part in DDNAME is "Device Class" - UT stands for utility (Tape or sequential disk) and DA stands for direct access (Disk). Second Part in DDNAMAE: is "Method of Organization" - S – Sequential (Printer, Terminal, Disk or Tape).

Re: COBOL Tips.

Posted: Tue Apr 29, 2014 5:36 pm
by Anuj Dhawan
15. ALL31: ALL31 specifies whether an application can run entirely in AMODE 31 or whether the application has one or more AMODE 24 routines.

The ALL31 option allows LE to take advantage of knowing that there are no AMODE(24) routines in the application. It specifies that the entire application will run in AMODE(31). This can help to improve the performance
for an all AMODE(31) application because Linkage Editor can minimize the amount of mode switching across calls to common run time library routines.

This option does not implicitly alter storage, in particular storage managed by the STACK and HEAP run-time options. However, you must be aware of your application's requirements for stack and heap storage,
because such storage can potentially be allocated above the line while running in AMODE 24