Home > Software > Mainframe > Cobol
Interview Questions   Tutorials   Discussions   Programs   

Cobol - How to declare dynamic array? what is the meaning of depending on clause in dynamic array?




568
views
asked mar September 9, 2014 11:41 AM  

How to declare dynamic array? what is the meaning of depending on clause in dynamic array?


           

1 Answers



 
answered By Mswami   0  

This is possible in COBOL using DEPENDING ON clause.

   01  PATIENT-TREATMENTS.
       05  PATIENT-NAME                PIC X(30).
       05  NUMBER-OF-TREATMENTS        PIC 99 COMP-3.
       05  TREATMENT-HISTORY OCCURS 0 TO 50 TIMES
              DEPENDING ON NUMBER-OF-TREATMENTS.
           10  TREATMENT-DATE           PIC 9(8). 
           10  TREATING-PHYSICIAN       PIC X(30).

In COBOL, you can use the OCCURS DEPENDING ON syntax to define a variable-length table in a data declaration. The storage for a variable-length table is dynamic, depending on the value in the length specifier variable. The amount of data passed is also dependent on the value in the length specifier variable: Only the number of elements specified are sent or received. The length specifier variable for a variable-length table must be a numeric type, and its direction must match the direction of the variable-length table it controls. The following COBOL code shows a variable-length table:

01 CUSTOMER-DATA.
   05 CUSTOMER-NUMBER                 PIC 9(9).
   05 LAST-NAME                       PIC X(20).
   05 FIRST-NAME                      PIC X(20).
   05 INVOICE-COUNT                   PIC 9(7) COMP-3.
   05 INVOICES OCCURS 50 TIMES DEPENDING ON INVOICE-COUNT.
      10 INVOICE-NUMBER               PIC 9(10).
      10 INVOICE-DATE                 PIC 9(7) COMP-3.
      10 INVOICE-AMOUNT               PIC S9(13)V9(2) COMP-3.
      10 INVOICE-DESCRIPTION          PIC X(40).
flag   
   add comment

Your answer

Join with account you already have

FF

Preview


Ready to start your tutorial with us? That's great! Send us an email and we will get back to you as soon as possible!

Alert