Popular

Showing posts with label Cobol. Show all posts
Showing posts with label Cobol. Show all posts

COBOL INDEX, COBOL Sub-script - What is the difference between Index and Sub-script?

Subscript is the slot-no. or position in the table. Index is the displacement (in no of bytes)/actual address from the beginning of the array. Indexes are much faster than subscripts. Subscripts have to be converted internally to the address.
For example,
01 WS-TABLE.
  
05 WS-NAME OCCURS 5 TIMES PIC X(10).
----------------------- Subscript Index -----------------------
  
0        0    1        10
  
2        20
  
3        30
  
..       ..
-----------------------

Since index is much more efficient, you should declare a table and Index it.
01 WS-TABLE.
   05 WS-NAME OCCURS 5 TIMES PIC X(3) INDEXED BY I.

You use indexes just like subscripts, except for the fact that they are much faster and efficient.
PERFORM 1000-DISPLAY-DATA VARYING I FROM 1 BY 1 UNTIL I > 5
1000-DISPLAY-DATA.
   DISPLAY WS-NAME(I).

To increment or decrement an Index, SET Verb is used. SET I UP BY WS-LIT-ONE.
SET I TO 1.

You cannot MOVE data to Indexes. You also cannot perform Arithmetic Operations on an Index.

COBOL PICTURE Clauses COBOL Picture Clause Usage Descriptions

Some examples
- PICTURE 999 a three digit (+iveonly) integer
- PICTURE S999 a three digit (+ive/-ive) integer
- PICTURE XXXX a four character text item or string
- PICTURE 99V99 a +ive‘real’in the range 0 to 99.99
- PICTURE S9V9 a +ive/-ive‘real’in the range ?
- If you wish you can use the abbreviation PIC.
- Numeric values can have a maximum of 18 (eighteen) digits (i.e. 9’s).
- The limit on string values is usually system-dependent.


Abbreviating recurring symbols

Recurring symbols can be specified using a ‘repeat’factor inside round brackets
  • PIC 9(6) is equivalent to PICTURE 999999
  • PIC 9(6)V99 is equivalent to PIC 999999V99
  • PICTURE X(10) is equivalent to PIC XXXXXXXXXX
  • PIC S9(4)V9(4) is equivalent to PIC S9999V9999
  • PIC 9(18) is equivalent to PIC 999999999999999999

Can you pass an Index to another COBOL Program, via LINKAGE SECTION?

No, an INDEX is not a Working-storage area. It is maintained by the System. You can only send the data which is in Working-storage areas(Rough-work area) or in File Input-Output Areas to a COBOL Program.

You can pass a Subscript to another COBOL Program.