What are Subscript and Index, and why do we use Subscript and Index ?

In COBOL, both subscript and index are used to access individual elements within tables (arrays).
However, they have distinct characteristics and usage:
* A subscript is an integer value that directly specifies the position or occurrence number of an element within a table.
Usage:
--> Can be any positive integer or an integer data item.
-→ Used directly with the table element name to access a specific occurrence.
--> Can be used in arithmetic expressions.
Example:
01 TABLE-A.
05 TABLE-ELEMENT PIC X(10) OCCURS 10 TIMES.
MOVE 'VALUE1' TO TABLE-ELEMENT(3) -- Accesses the 3rd element
* An index is a special type of data item that is associated with a table using the INDEXED BY clause in the OCCURS statement.
Usage:
--> Primarily used with the SET, SEARCH, and PERFORM statements for efficient table processing.
--> Cannot be used directly in arithmetic expressions.
--> Provides faster access to table elements compared to subscripts, especially for large tables.
Example:
01 TABLE-A.
05 TABLE-ELEMENT PIC X(10) OCCURS 10 TIMES INDEXED BY INDEX-A.
SET INDEX-A TO 3. -- Sets the index to the 3rd element
MOVE 'VALUE2' TO TABLE-ELEMENT. -- Accesses the element using the index
Subscribe to my newsletter
Read articles from Chanikya A directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Chanikya A
Chanikya A
8+ years of progressive experience in Mainframe Development, Migration, Enhancement, Maintenance and Support projects. • Extensive Knowledge in requirement gathering, analysis, design, development, implementation, testing, integration deployment, production support, documentation and maintenance of IBM Mainframe applications. • Extensively Design, develop and maintain complex software systems in Mainframe ensuring high quality and timely delivery. • Extensively worked on COBOL, JCL, DB2, VSAM, and CICS. • Extensively worked on Changeman, Endevor, File-aid, Git, DB2 File Manager, Connect Direct, Zeke, Jira, CA7, and Servicenow Tools • Familiarity with mainframe tools such as REXX, TSO, ISPF, and SDSF. • Having Experience in Banking and Healthcare domain. • Having Experience in Linux Shell Scripting. • Having Good verbal, written and interpersonal skills. • Having experience in develop documentation throughout the software development life cycle (SDLC) • Strong experience on co-ordination skills to work with offshore/onshore teams throughout all phases. Operating System : Linux, IBM Mainframe Z/OS, IBM Mainframe MVS, Windows 7 & 10 Programming Languages: COBOL, JCL Database & Access: DB2, CICS, VSAM, SQL Tools and Utilities: IBM IDz,TSO, ISPF,GIT,SDSF, REXX, File-aid, File Manager , Sonarqube, Jira , Servicenow, Rally, Endevor, Changeman, CA7, Zeke, Savrs, and Fault Analyzer Domain : Banking and Healthcare Debugging Tool : Xpeditor Version Control Tools : Endevor , Changeman, and Git Reporting Tools : MS Excel Presentation Tools : MS Power Point Deliverable Methods : Agile and Devops