You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: COBOL Programming Course #1 - Getting Started/COBOL Programming Course #1 - Getting Started.md
+25-1Lines changed: 25 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1944,7 +1944,7 @@ We can also nest multiple OCCURS elements to create a table of additional dimens
1944
1944
15 ASSIGMMENT-WEIGHTAGE PIC 9(03).
1945
1945
```
1946
1946
1947
-
Here, we are defining a degree program which has 10 courses and each course will have 8 assignments. What if we don't know how many times will a table element will occur? To solve that, we can use variable-length table, using the OCCURS DEPENDING ON (ODO) clause which we will be going into more details on a later section.
1947
+
Here, we are defining a degree program which has 10 courses and each course will have 8 assignments. What if we don't know how many times a table element will occur? To solve that, we can use variable-length table, using the OCCURS DEPENDING ON (ODO) clause which we will be going into more details on a later section.
1948
1948
1949
1949
## Referring to an item in a table
1950
1950
@@ -2000,6 +2000,30 @@ The integer there represents the number of occurences. So it will be converted t
2000
2000
2001
2001
Since we are comparing physical displacements, we cannot use index data items as subscripts or indexes. We can only directly use it in SEARCH and SET statements or in comparisons with indexes.
2002
2002
2003
+
The following example shows how to calculate displacements to elements that are referenced with indexes.
2004
+
2005
+
Consider the following two dimensional table, TABLE-2D:
2006
+
2007
+
```
2008
+
01 TABLE-2D.
2009
+
05 TABLE-ROW OCCURS 2 TIMES INDEXED BY INX-A.
2010
+
10 TABLE-COL OCCURS 5 TIMES INDEXED BY INX-B PIC X(4).
2011
+
```
2012
+
2013
+
Suppose we code the following index:
2014
+
2015
+
```
2016
+
TABLE-COL (INX-A + 2, INXB - 1)
2017
+
```
2018
+
2019
+
This will cause the computation of the displacement to the TABLE-COL element:
2020
+
2021
+
```
2022
+
(contents of INX-A) + (20 * 2) + (contents of INX-B) - (4 * 1)
2023
+
```
2024
+
2025
+
The calculation is based on the length of the elements. Each occurence of TABLE-ROW is 20 bytes in length (5 * 4) and each occurence of TABLE-COL is 4 bytes in length.
2026
+
2003
2027
## Loading a table with data
2004
2028
2005
2029
There are many ways we can load a table. The first one involves loading the table dynamically, from a screen, file or database. We can also use the REDEFINES clause on hard-coded field values along with an OCCURS clause. The third way is using the INITIALIZE statement, and lastly, we can also use the VALUE clause when defining the table.
0 commit comments