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

Cobol - What is dynamic array in Cobol? what is the difference b/w array and table in Cobol?




603
views
asked mar August 22, 2014 12:43 PM  

What is dynamic array in Cobol? what is the difference b/w array and table in Cobol?


           

1 Answers



 
answered By Mswami   0  
To define a one-dimensional table, set up a group item that includes one OCCURS clause. Remember that the OCCURS clause cannot appear in a data description entry whose level-number is 01, 66, 77, or 88.

For example:

01 TABLE-ONE.
05 ELEMENT-ONE OCCURS 3 TIMES.
  10 ELEMENT-A PIC X(4).
  10 ELEMENT-B PIC 9(4).


TABLE-ONE is the group item that contains the table. ELEMENT-ONE is an element of a one-dimensional table that occurs three times. ELEMENT-A and ELEMENT-B are elementary items subordinate to ELEMENT-ONE.

Dynamic Array:
This is possible in COBOL using DEPENDING ON clause.

Example:

  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).




When a group item containing a subordinate OCCURS DEPENDING ON item is referred to, the part of the table area used in the operation is determined as follows:

  •     If the object is outside the group, only that part of the table area that is specified by the object at the start of the operation will be used.
  •     If the object is included in the same group and the group data item is referenced as a sending item, only that part of the table area that is specified by the value of the object at the start of the operation will be used in the operation.
  •     If the object is included in the same group and the group data item is referenced as a receiving item, the maximum length of the group item will be used in the operation.

When reference modification is applied to a group item containing a variable-length table, reference modification creates a unique data item from the referenced data item. The length of this referenced data item is determined by first applying the previous rules. Subsequently, the rules for reference modification are applied to determine the length of the unique data item.
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