COBOL TIPS
by
Shawn M. Gordon
President
S.M.Gordon & Associates

To start off this month I want to share an interesting tidbit about the most widely publicized computer language in the world right now, C++. One of the great claims to fame in C++ is it’s ability to do what it calls ‘Object Overloading’. Now I don’t pretend to fully understand what ‘Object Overloading’ means, or does, but I was reading in a magazine an example that you might find interesting. It seems that in the C language if you want to display a variable to STDLIST (your terminal), you have to call the function and pass what type of data you are displaying.

printf(“here is a string %s”, my_string);

The key here is the ‘%s’ that means to format ‘my_string’ as a string, and display it. In C++ you can use the newer I/O facility to display text.

cout > text

What is supposed to be so amazing is that you don’t have to tell ‘cout’
what it is you want to display, by use of ‘Object Overloading’ it will
automatically convert it for you.

How many of you see the irony here? The COBOL ‘DISPLAY’ verb has had this ability for as long as I can remember. You can literally ‘DISPLAY’ any darn thing you want. I guess this means that COBOL has some Object Oriented extensions in it already, so much for COOL (COBOL Object Oriented Language).

This month I am going to show you a slightly easier way to do page
formatting in your reports. I want to start off by letting you know that the HP Laser Printers are only actually supported if you code in the PCL escape sequences yourself. Using the COBOL verbs ‘AFTER ADVANCING’ on an HP LaserJet may or may not yield the expected results. This holds true for COBOL no matter what I show you here. The results shouldn’t change randomly however, if it is right, it should stay right, if it is wrong, odd’s are it will stay wrong. That said, let’s jump into it.

How many of us set up variables to count lines, and then manually increment them so we can know when to page break. We usually set
up a SPECIAL-NAME such as NEW-PAGE just to handle this situation. Well it turns out you can let COBOL do most of this nasty stuff for you.

Below is a code fragment that shows how to set up what I am talking about;

  SPECIAL-NAMES.
      CONDITION-CODE IS CC
      TOP IS NEW-PAGE.
  INPUT-OUTPUT SECTION.
  FILE-CONTROL.
      SELECT WORK-FILE ASSIGN TO "SCRATCH".
      SELECT OUT-FILE  ASSIGN TO "MYREPT,,,LP(CCTL)".

      SELECT SFILE ASSIGN TO "SFILE".

  DATA DIVISION.
  FILE SECTION.
   FD WORK-FILE
     RECORD CONTAINS 44 CHARACTERS.
  01 TEMP-FILE               PIC X(44).

 *
  FD OUT-FILE
     LINAGE IS 64 LINES
     WITH FOOTING AT 60
     LINES AT TOP 1
     LINES AT BOTTOM 3
     RECORD CONTAINS 132 CHARACTERS.
  01 PRINT-LINE              PIC X(132).
 *
  SD SFILE
     RECORD CONTAINS 44 CHARACTERS.
  01 SORT-LINE.
     03 SKEY1                PIC X(12).
     03                      PIC X(32).
 *
  WORKING-STORAGE SECTION.
 *
  01 BLANK-LINE              PIC X(132)  VALUE SPACES.
  01 PAGE-COUNT             PIC 99      VALUE ZEROES.
  01 T1.
     03                      PIC X(08)   VALUE "MYREPT".
     03                      PIC X(41)   VALUE SPACES.
     03                      PIC X(34)   VALUE
        "WEEKLY PERFORMANCE REPORT".
     03                      PIC X(41)   VALUE SPACES.
     03                      PIC X(06)   VALUE "PAGE:".
     03 T1-PAGE              PIC Z9.
 *

  01 T2.
     03 T2-DATE              PIC X(08)   VALUE SPACES.
     03                      PIC X(54)   VALUE SPACES.
     03                      PIC X(06)   VALUE "LOC:".
     03 T2-LOC               PIC X(02)   VALUE SPACES.
     03                      PIC X(62)   VALUE SPACES.
 *
  01 H1.
     03                      PIC X(123)  VALUE SPACES.
     03                      PIC X(08)   VALUE "Adjusted".
     03                      PIC X       VALUE SPACES.
 *

 PROCEDURE DIVISION.
 A1000-INIT.
     OPEN  OUTPUT  OUT-FILE.
     PERFORM C1100-HEADER           THRU C1100-EXIT.
     PERFORM C1000-DETAIL           THRU C1000-EXIT. 
*
  C1000-DETAIL.

      WRITE PRINT-LINE FROM D1 AT END-OF-PAGE
            PERFORM C1100-HEADER    THRU C1100-EXIT.
  C1000-EXIT.  EXIT.
 *
 C1100-HEADER.
      ADD 1 TO PAGE-COUNT.
      MOVE PAGE-COUNT                 TO T1-PAGE.
      WRITE PRINT-LINE FROM T1 AFTER ADVANCING PAGE.
      WRITE PRINT-LINE FROM T2 AFTER ADVANCING 1 LINE.
      WRITE PRINT-LINE FROM H1 AFTER ADVANCING 2 LINES.
 C1100-EXIT.  EXIT.

Now obviously I am not reading or formatting the input file, the important part here is that by describing the page layout in the FD area, we only have to test for END-OF-PAGE when we write our line out. We are only keeping track of the page count so we can display it on the report.

We have told the COBOL compiler that our page is 64 lines with the footing at line 60, one blank line at the top, and three blank lines at the bottom. Look at how much hassle we have saved just be doing a little descriptive work at the top of the program.

Sometimes it takes a little trial and error to get your page layout correct, but once you get it right you can use it for the rest of your programs. This methodology can also be used for odd page sizes, and in fact is perfect for applying to various page sizes because it keeps the context of your code the same.

This month’s issue has been a little short, but I think that you will find this to be a pretty handy type. I would love to hear from some people that have found other uses for the DECLARATIVES section, other than as a debug area.