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
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1903,7 +1903,7 @@ Notice that this line tells you to focus on the GROSS-PAY picture clause in orde
1903
1903
1904
1904
\newpage
1905
1905
1906
-
# Tables handling
1906
+
# Table handling
1907
1907
1908
1908
This section introduces the concept of tables, which are a collection of data items that have the same description. The subordinate items are called table elements. A table is the COBOL equivalent of arrays.
1909
1909
@@ -1920,7 +1920,7 @@ To code a table, we need to give the table a group name and define a subordinate
1920
1920
10 ELEMENT2 PIC 9(2).
1921
1921
```
1922
1922
1923
-
In the example above, TABLE-NAME is the name of the group item. The table also contain a subordinate item called SUBORDINATE-NAME which we are repeating n times. Each of the SUBORDINATE-ITEM have 2 elementary items, ELEMENT1 and ELEMENT2. In this case, we called SUBORDINATE-NAME as the table element definition (since it includes the OCCURS clause). Note that the OCCURS clause cannot be used in a level-01 description.
1923
+
In the example above, TABLE-NAME is the name of the group item. The table also contains a subordinate item called SUBORDINATE-NAME which we are repeating n times. Each SUBORDINATE-ITEM has 2 elementary items, ELEMENT1 and ELEMENT2. In this case, we called SUBORDINATE-NAME as the table element definition (since it includes the OCCURS clause). Note that the OCCURS clause cannot be used in a level-01 description.
1924
1924
1925
1925
Alternatively, we can also make simpler tables:
1926
1926
@@ -1929,9 +1929,9 @@ Alternatively, we can also make simpler tables:
1929
1929
05 SUBORDINATE OCCURS n TIMES PIC X(10).
1930
1930
```
1931
1931
1932
-
In this case, TABLE-NAME contains n SUBORDINATE item, each can contain up to 10 alphanumeric characters.
1932
+
In this case, TABLE-NAME contains n SUBORDINATE items, each can contain up to 10 alphanumeric characters.
1933
1933
1934
-
We can also nest multiple OCCURS elements to create table of additional dimensions, up to a limit of seven dimensions. Note the example below:
1934
+
We can also nest multiple OCCURS elements to create a table of additional dimensions, up to a limit of seven dimensions. Note the example below:
1935
1935
1936
1936
```
1937
1937
01 PROGRAM-DETAILS.
@@ -1944,11 +1944,11 @@ We can also nest multiple OCCURS elements to create table of additional dimensio
1944
1944
15 ASSIGMMENT-WEIGHTAGE PIC 9(03).
1945
1945
```
1946
1946
1947
-
Here, we are defining a degree program which have 10 course and each course will have 8 assignments. What if we don't know beforehand how many times will a table element occurs? 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 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.
1948
1948
1949
1949
## Referring to an item in a table
1950
1950
1951
-
While a table element have a collective name, the individual items within does not have a unique name. To refer to an item, we can either use subscript, index, or a combination of both.
1951
+
While a table element has a collective name, the individual items within do not have a unique name. To refer to an item, we can either use subscript, index, or a combination of both.
1952
1952
1953
1953
### Subscripting
1954
1954
@@ -1973,7 +1973,7 @@ Alternatively, we can create an index using the INDEXED BY phrase of the OCCURS
1973
1973
1974
1974
Here, INX-A is an index name. The compiler will calculate the value in the index as the occurence number minus 1 multiplied by the length of the table element. So, for example, for the second occurence of TABLE-ELEMENT, the binary value contained in INX-A is (2-1) * 3, or 3.
1975
1975
1976
-
If you happen to have another table with the same number of table elements of the same length, you can use an index name as a reference for both table.
1976
+
If you happen to have another table with the same number of table elements of the same length, you can use an index name as a reference for both tables.
1977
1977
1978
1978
We can also define an index data item using the USAGE IS INDEX clause. These index data items can be used with any table. For example,
1979
1979
@@ -2002,7 +2002,7 @@ Since we are comparing physical displacements, we cannot use index data items as
2002
2002
2003
2003
## Loading a table with data
2004
2004
2005
-
There are many ways we can load a table. The first one involves loading the table dynamically, from a screen, file or databases. 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.
2005
+
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.
2006
2006
2007
2007
### Loading a table dynamically
2008
2008
@@ -2041,7 +2041,7 @@ Here, we are taking hard-coded values of spelled out numbers from 1 to 5 and loa
2041
2041
2042
2042
### INITIALIZE a table
2043
2043
2044
-
We can also use the INITIALIZE statement to load data into a table. The table will be processed as a group item and each elementary data items within are recognized and processed. For example, assume that we have the following table:
2044
+
We can also use the INITIALIZE statement to load data into a table. The table will be processed as a group item and each elementary data item within it will be recognized and processed. For example, assume that we have the following table:
2045
2045
2046
2046
```
2047
2047
01 TABLE-ONE.
@@ -2052,14 +2052,14 @@ We can also use the INITIALIZE statement to load data into a table. The table wi
2052
2052
2053
2053
Here we have a table that contains 10 elements, each with their own NUMBER-CODE (with a value of 10) and ITEM-ID (with a value of "R3").
2054
2054
2055
-
We can move the value 3 to each of the elementary numeric data item and the value "X" into each of the elementary alphanumeric data items in the table:
2055
+
We can move the value 3 to each of the elementary numeric data items and the value "X" into each of the elementary alphanumeric data items in the table:
2056
2056
2057
2057
```
2058
2058
INITIALIZE TABLE-ONE REPLACING NUMERIC DATA BY 3.
2059
2059
INITIALIZE TABLE-ONE REPLACING ALPHANUMERIC DATA BY "X".
2060
2060
```
2061
2061
2062
-
After running the two INITIALIZE statement, NUMBER-CODE will contain the value of 3, while ITEM-ID will contain the value of "X ".
2062
+
After running the two INITIALIZE statements, NUMBER-CODE will contain the value of 3, while ITEM-ID will contain the value of "X ".
2063
2063
2064
2064
### Assigning values using VALUE clause
2065
2065
@@ -2074,7 +2074,7 @@ In the above example, the alphanumeric group data item TABLE-TWO uses a VALUE cl
2074
2074
2075
2075
## Variable-length tables
2076
2076
2077
-
If we do not know before runtime how many times will a table element occurs, we can define a variable-length table using the OCCURS DEPENDING ON (ODO) clause.
2077
+
If we do not know before runtime how many times a table element will occur, we can define a variable-length table using the OCCURS DEPENDING ON (ODO) clause.
2078
2078
2079
2079
```
2080
2080
X OCCURS 1 TO 10 TIMES DEPENDING ON Y
@@ -2131,9 +2131,9 @@ A binary search can be more efficient than a serial search, however it requires
2131
2131
2132
2132
### Serial search
2133
2133
2134
-
We can do a serial search by using the SEARCH statement. The search will begins at the current index setting and will continue until the condition in the WHEN phrase are fulfilled. To modify the index setting, we can use the SET statement If there are multiple condition in the WHEN phrase, the search will ends when the one of the conditions is satisfied and the index will remain pointing to the element that satisfied the condition.
2134
+
We can do a serial search by using the SEARCH statement. The search will begin at the current index setting and will continue until the condition in the WHEN phrase is fulfilled. To modify the index setting, we can use the SET statement. If there are multiple conditions in the WHEN phrase, the search will end when the one of the conditions is satisfied and the index will remain pointing to the element that satisfied the condition.
2135
2135
2136
-
For example, assume that we have a list of name:
2136
+
For example, assume that we have a list of names:
2137
2137
2138
2138
```
2139
2139
77 PEOPLE-SEARCH-DATA PIC X(20).
@@ -2150,17 +2150,17 @@ PROCEDURE-DIVISION.
2150
2150
DISPLAY "Found".
2151
2151
```
2152
2152
2153
-
The code above will search the list of name from an index of 1. If it found the content of PEOPLE-SEARCH-DATA, it will DISPLAY "Found", otherwise, it will DISPLAY "Not found".
2153
+
The code above will search the list of names from an index of 1. If it found the content of PEOPLE-SEARCH-DATA, it will DISPLAY "Found", otherwise, it will DISPLAY "Not found".
2154
2154
2155
-
For a more complex use case, we can also use nested SEARCH statement. We will need to delimit each nested SEARCH statement with END-SEARCH.
2155
+
For a more complex use case, we can also use nested SEARCH statements. We will need to delimit each nested SEARCH statements with END-SEARCH.
2156
2156
2157
2157
### Binary search
2158
2158
2159
2159
To do a binary search, we can use a SEARCH ALL statement. We do not need to set the index, but it will use the one associated in the OCCURS clause. To use the SEARCH ALL statement, the table must specify the ASCENDING or DESCENDING KEY phrases of the OCCURS clause, or both, and it must be ordered on the specified key.
2160
2160
2161
2161
Using the WHEN phrase, you can test any key that is named in the ASCENDING or DESCENDING KEY phrases. The test must be an equal-to condition, and the WHEN phrase must specify either a key or a condition-name associated with the key.
2162
2162
2163
-
For example, assume that we have a list of name sorted in an ascending order:
2163
+
For example, assume that we have a list of names sorted in an ascending order:
2164
2164
2165
2165
```
2166
2166
77 PEOPLE-SEARCH-DATA PIC X(20).
@@ -2177,7 +2177,7 @@ PROCEDURE-DIVISION.
2177
2177
DISPLAY "Found".
2178
2178
```
2179
2179
2180
-
The code above will search the alphabetically-sorted list of state name. If it found the content of PEOPLE-SEARCH-DATA, it will DISPLAY "Found", otherwise, it will DISPLAY "Not found".
2180
+
The code above will search the alphabetically-sorted list of names. If it found the content of PEOPLE-SEARCH-DATA, it will DISPLAY "Found", otherwise, it will DISPLAY "Not found".
0 commit comments