[USflag] The American Programmer [USflag]


Home
Books on Mainframe Programming
Mainframe Manuals and Tutorials
System Abend codes, Sqlcodes, VSAM/QSAM codes
Everything about the IBM AS/400 Midrange Computer - iSeries
Everything about CICS
Cobol programs, manuals, books
  Sample Cobol code: The Simple, Single File COBOL Program
  Sample Cobol code: The Simple, Single File Report COBOL Program with Record Count or Final Totals
  Sample Cobol code: The Simple, Single File Report COBOL Program with Record Count or Final Totals
  Sample Cobol code: The Sequence Check COBOL Program
  Sample Cobol code: The Record Selection COBOL Program
  Sample Cobol code: The Edit or Validate COBOL Program
  Sample Cobol code: The The One Level Subtotal (Control Break) COBOL Program
  Sample Cobol code: The Three Level Subtotal (Control Break) COBOL Program
  Sample Cobol code: The Sequential File, Batch Update COBOL Program
  Sample Cobol code: The COBOL Sort
  Sample Cobol code: The CASE Structure: COBOL EVALUATE
  Sample Cobol code: Direct Subscripting in COBOL
  Sample Cobol code: The Sequential, or Serial Search in COBOL
  Sample Cobol code: The Binary Search in COBOL
  Sample Cobol code: Loading a Table from a Sequential File in a COBOL program
  Sample Cobol code: The VSAM File Read Sequentially in a COBOL program
  Sample Cobol code: The VSAM KSDS, Read Randomly in a COBOL program
  Sample Cobol code: The VSAM File, Read Randomly in a COBOL program
  Sample Cobol code: VSAM Initial Load in a COBOL program
  Sample Cobol code: VSAM File Maintenance (Add, Change, Delete) in a COBOL program
  Sample Cobol code: VSAM Read Sequentially, with START, in a COBOL program
  Sample Cobol code: Creating a Variable Format File in a COBOL program
  Sample Cobol code: Reading a Variable Format File in a COBOL program
  Sample Cobol code: Creating a Variable Format File with Occurs Depending On in a COBOL program
  Sample Cobol code: COBOL Reading a Variable Format File with Occurs Depending On, in a COBOL program
  Sample Cobol code: COBOL The Table Load with Occurs Depending On
  Sample Cobol/DB2 code: Singleton Select
  Sample Cobol code: logic to compare two sorted input files
  Sample Cobol code: logic to merge two sorted input files into one
  Sample Cobol code: Illustrates how Occurs Depending On (ODO) works
  Manuals on the COBOL programming language.
  Books on Cobol
  Abend Codes from Cobol programs
Everything about DB2 and SQL
Everything about IMS
Everything about Java and JavaScript
Everything about JCL and JES
Everything about REXX
Everything about zOS, VSAM, Tivoli, Assembler
Everything about TSO, ISPF, Spufi
Site Map and Site Search

           Home   > COBOL   > COBOL Occurs Depending On

COBOL: Occurs Depending On

If you lie awake at night wondering how COBOL Occurs Depending On works, this is the solution. Just run the program.
Now I sleep soundly at night.
(The thing after the ODO counter moves.)

At one time, I used this feature of COBOL to pick my way through memory and display all sorts of interesting things. (In my program.)
You can't reference memory that is not in your address space (region) so don't try to look at other peoples' programs.

000100 ID DIVISION.
       PROGRAM-ID. 'ODO'.
      * A simple program that illustrates how the COBOL
      * OCCURS DEPENDING ON works.
      * Run it. It needs to display its output.
       ENVIRONMENT DIVISION.
       INPUT-OUTPUT SECTION.

       DATA DIVISION.
       FILE SECTION.

       WORKING-STORAGE SECTION.

       01  ODO-PLAY-AREA.
           05  ODO-COUNTER   PIC 9(4)  VALUE  100.
           05  ODO-THING     PIC X     OCCURS 100 TIMES
                 DEPENDING ON ODO-COUNTER.
           05  THING-AFTER-ODO-THING PIC X(30).

       PROCEDURE DIVISION.

            MOVE 0 TO ODO-COUNTER
            MOVE  'I COME AFTER ODO THING' TO THING-AFTER-ODO-THING
            DISPLAY ODO-PLAY-AREA
            MOVE SPACES TO THING-AFTER-ODO-THING

            MOVE 10 TO ODO-COUNTER
            MOVE  'I COME AFTER ODO THING' TO THING-AFTER-ODO-THING
            DISPLAY ODO-PLAY-AREA
            MOVE SPACES TO THING-AFTER-ODO-THING

            MOVE 20 TO ODO-COUNTER
            MOVE  'I COME AFTER ODO THING' TO THING-AFTER-ODO-THING
            DISPLAY ODO-PLAY-AREA
            MOVE SPACES TO THING-AFTER-ODO-THING

            MOVE 30 TO ODO-COUNTER
            MOVE  'I COME AFTER ODO THING' TO THING-AFTER-ODO-THING
            DISPLAY ODO-PLAY-AREA
            MOVE SPACES TO THING-AFTER-ODO-THING

            MOVE 40 TO ODO-COUNTER
            MOVE  'I COME AFTER ODO THING' TO THING-AFTER-ODO-THING
            DISPLAY ODO-PLAY-AREA
            MOVE SPACES TO THING-AFTER-ODO-THING

            GOBACK.
Learn how to use all the features of COBOL: COBOL Programming Books

[Books Computer]

Home Books for Computer Professionals Privacy Terms |
Site Map and Site Search Programming Manuals and Tutorials The REXX Files Top of Page |