The first thing to understand is that array indices are zero based in C and 1 based in COBOL.Next COBOL and C have very differnt ways of representing character strings. In C a string is generally storedas an array of characters, the end of string is typically represented using a binary zero (null 0). COBOLhas no such convention. Strings are stored in named data items of a specified length. These items are typicallydeclared under WORKING-STORAGE and have a PICTURE Clause associated with them of type 'X' (there are several otherpossibilities for PICTURE clauses but 'X' represents any type of character). For example: 01 MY-VARIABLE PIC X(20).The Working Storage variable called MY-VARIABLE is declared as 20 characters long.
![](/uploads/1/2/8/0/128085886/508287357.jpg)
![3 dimensional array in cobol 3 dimensional array in cobol](/uploads/1/2/8/0/128085886/897601267.jpg)
I Am learning programming since 2005 and still keep on learning them every day. View my complete profile C C PROGRAM PRACTICAL PROGRAMS C Programs C COBOL Programs COBOL SQL Data Structure Inheritance COBOL TUTOR PART 1 Operator Overloading File Handling PL/SQL Sorting TRICKS AND TIPS. COBOL - Table Processing - Arrays in COBOL are known as tables. An array is a linear data. JCL to execute the above COBOL program −.
![Sorting An Array In Cobol Program Sorting An Array In Cobol Program](/uploads/1/2/8/0/128085886/119570912.png)
It may be assigned a valuein the PROCEDURE DIVISION as follows. MOVE 'work' TO MY-VARIABLEYou can then access the various characters of this string (or substrings) using a technique known asreference modification: DISPLAY MY-VARIABLE(3:1)will display the third character of MY-VARIABLE (1 based indexing), which is 'r'. The first number in parenthesis above (3)indicates the offset from the beginning of the variable, the second number is the number of characters starting from that position (1).There are other methods of doing this, such as REDEFINES, where MY-VARIABLE could be redefined as an array of 20 1 character cells. Thisis a somewhat outdated mechanism so I would encourage using reference modification to access parts of character strings. Despite mentioning 'string', I think you are talking about what might be termed a 'field', a piece of data.
01 a-piece-of-data.05 first-two-bytes-of-data PIC XX.05 third-byte-of-data PIC X.05 fourth-byte-of-data PIC X.a-piece-of-data is a 'group item', which is four bytes long.
![](/uploads/1/2/8/0/128085886/508287357.jpg)