Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve COBOL snippets in doc, and improve code readability in COBOL sources #279

Merged
merged 17 commits into from
Oct 19, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -1091,7 +1091,7 @@ There are many ways we can load a table. The first one involves loading the tabl
To load a table dynamically, we need to use the PERFORM statement with either subscripting or indexing. When doing this, we need to make sure that the data does not exceed the space allocated for the table. We will discuss file handling and the use of PERFORM clause in a later chapter. For example,

```COBOL
PROCEDURE DIVISION
PROCEDURE DIVISION.
...
PERFORM READ-FILE.
PERFORM VARYING SUB FROM 1 BY 1 UNTIL END-OF-FILE
Expand Down Expand Up @@ -1177,7 +1177,7 @@ We must ensure that the ODO object correctly specifies the number of occurrences
The following example shows how we can use an OCCURS DEPENDING ON clause:

```COBOL
WORKING-STORAGE SECTION
WORKING-STORAGE SECTION.
01 MAIN-AREA.
03 REC-1.
05 FIELD-1 PIC 9.
Expand Down Expand Up @@ -1763,8 +1763,8 @@ The code we have built so far is still not optimal, the repetition of the perfor
MOVE 'THE NUMBER IS: ' TO MSG-HEADER OF PRINT-REC.

PERFORM VARYING COUNTER FROM 01 BY 1 UNTIL COUNTER EQUAL 11
MOVE COUNTER TO MSG-TO-WRITE
WRITE PRINT-REC
MOVE COUNTER TO MSG-TO-WRITE
WRITE PRINT-REC
END-PERFORM.

CLOSE PRINT-LINE.
Expand Down Expand Up @@ -1899,8 +1899,8 @@ There is no requirement about the order that paragraphs should appear within a C
2000-READ-NEXT-RECORD.
PERFORM 4000-READ-RECORD
PERFORM UNTIL LASTREC = 'Y'
PERFORM 5000-WRITE-RECORD
PERFORM 4000-READ-RECORD
PERFORM 5000-WRITE-RECORD
PERFORM 4000-READ-RECORD
END-PERFORM.
*
3000-CLOSE-STOP.
Expand All @@ -1910,7 +1910,7 @@ There is no requirement about the order that paragraphs should appear within a C
*
4000-READ-RECORD.
READ ACCT-REC
AT END MOVE 'Y' TO LASTREC
AT END MOVE 'Y' TO LASTREC
END-READ.
*
5000-WRITE-RECORD.
Expand All @@ -1935,8 +1935,8 @@ There is no requirement about the order that paragraphs should appear within a C
2000-READ-NEXT-RECORD.
PERFORM 4000-READ-RECORD
PERFORM UNTIL LASTREC = 'Y'
PERFORM 5000-WRITE-RECORD
PERFORM 4000-READ-RECORD
PERFORM 5000-WRITE-RECORD
PERFORM 4000-READ-RECORD
END-PERFORM.
2000-READ-NEXT-RECORD-END.
```
Expand All @@ -1953,8 +1953,8 @@ Perhaps the simplest way of repeating a perform statement is to use the TIMES ke

```COBOL
PERFORM 10 TIMES
MOVE FIELD-A TO FIELD-B
WRITE RECORD
MOVE FIELD-A TO FIELD-B
WRITE RECORD
END-PERFORM.
```
*Example 10. TIMES*
Expand Down Expand Up @@ -2000,9 +2000,9 @@ Adding the UNTIL keyword to a perform sentence allows you to iterate over a grou
```COBOL
MOVE 0 TO COUNTER.
PERFORM UNTIL COUNTER = 10
ADD 1 TO COUNTER GIVING COUNTER
MOVE COUNTER TO MSG-TO-WRITE
WRITE PRINT-REC
ADD 1 TO COUNTER GIVING COUNTER
MOVE COUNTER TO MSG-TO-WRITE
WRITE PRINT-REC
END-PERFORM.
```
*Example 13. PERFORM UNTIL*
Expand All @@ -2024,9 +2024,9 @@ In this case, the Boolean condition is evaluated before the loop is executed. H

```COBOL
PERFORM WITH TEST AFTER UNTIL COUNTER = 10
ADD 1 TO COUNTER GIVING COUNTER
MOVE COUNTER TO MSG-TO-WRITE
WRITE PRINT-REC
ADD 1 TO COUNTER GIVING COUNTER
MOVE COUNTER TO MSG-TO-WRITE
WRITE PRINT-REC
END-PERFORM.
```
*Example 15. PERFORM WITH TEST AFTER UNTIL*
Expand Down Expand Up @@ -2490,7 +2490,7 @@ Observe in Example 1. 'The State is not Texas' is written as a result of the fi


```COBOL
WORKING-STORAGE.
WORKING-STORAGE SECTION.
01 USA-STATE PIC X(2) VALUE SPACES.
88 STATE VALUE 'TX'.
....
Expand Down Expand Up @@ -2521,7 +2521,7 @@ Other level number data-names require the condition expression to include a Bool


```COBOL
WORKING-STORAGE.
WORKING-STORAGE SECTION.
01 USA-STATE.
05 STATE PIC X(2) VALUE SPACES.
....
Expand Down Expand Up @@ -2610,7 +2610,7 @@ A PERFORM with UNTIL phrase is a conditional expression. In the UNTIL phrase fo


```COBOL
WORKING-STORAGE.
WORKING-STORAGE SECTION.
01 FACIAL-EXP PIC X(11) VALUE SPACES.
88 HAPPY VALUE 'HAPPY'.
....
Expand All @@ -2628,7 +2628,7 @@ END-PERFORM.
It is also possible to use PERFORM statement without the use of an 88-level conditional name, observe Example 6.

```COBOL
WORKING-STORAGE.
WORKING-STORAGE SECTION.
01 FACIAL-EXP PIC X(11) VALUE SPACES.
....
....
Expand All @@ -2647,7 +2647,7 @@ END-PERFORM.
The SEARCH statement searches a table for an element that satisfies the specified condition and adjusts the associated index to indicate that element. Tables, effectively an array of values, are created with an OCCURS clause applied to WORK-STORAGE data names. A WHEN clause is utilized in SEARCH statements to verify if the element searched for satisfies the specified condition. Assuming FACIAL-EXP has many possible values, then SEARCH WHEN is an alternative conditional expression, observe Example 7.

```COBOL
WORKING-STORAGE.
WORKING-STORAGE SECTION.
01 FACIAL-EXP-TABLE REDEFINES FACIAL-EXP-LIST.
05 FACIAL-EXP PIC X(11) OCCURS n TIMES INDEXED BY INX-A.
88 HAPPY VALUE "HAPPY".
Expand All @@ -2657,7 +2657,7 @@ PROCEDURE DIVISION.
....
....
SEARCH FACIAL-EXP
WHEN HAPPY(INX-A) DISPLAY 'I am glad you are happy'
WHEN HAPPY(INX-A) DISPLAY 'I am glad you are happy'
END-SEARCH
```
*Example 7. SEARCH WHEN statement*
Expand Down Expand Up @@ -3294,7 +3294,9 @@ Example 6 shows a usage of the COBOL function UPPER-CASE where a string or alpha
```COBOL
MOVE FUNCTION UPPER-CASE("This is shouting!") TO SOME-FIELD
DISPLAY SOME-FIELD
Output - THIS IS SHOUTING!
```
```
Output: THIS IS SHOUTING!
```

*Example 6. Character-handling intrinsic function*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@
* and the call to WRITE-RECORD depend on READ-RECORD having
* been executed before.
* The loop starts at the next line with PERFORM UNTIL
PERFORM UNTIL LASTREC = 'Y'
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
PERFORM UNTIL LASTREC = 'Y'
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
.
*
CLOSE-STOP.
Expand All @@ -84,7 +84,7 @@
*
READ-RECORD.
READ ACCT-REC
AT END MOVE 'Y' TO LASTREC
AT END MOVE 'Y' TO LASTREC
END-READ.
*
WRITE-RECORD.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@
*
READ-NEXT-RECORD.
PERFORM READ-RECORD
PERFORM UNTIL LASTREC = 'Y'
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
PERFORM UNTIL LASTREC = 'Y'
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
.
*
CLOSE-STOP.
Expand All @@ -65,7 +65,7 @@
*
READ-RECORD.
READ ACCT-REC
AT END MOVE 'Y' TO LASTREC
AT END MOVE 'Y' TO LASTREC
END-READ.
*
WRITE-RECORD.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@
* paragraph of the code, executes it and returns control to
* the following line.
*
PERFORM UNTIL LASTREC = 'Y'
PERFORM UNTIL LASTREC = 'Y'
* here PERFORM allows a loops to be entered
*
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
.
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
.
*
CLOSE-STOP.
CLOSE ACCT-REC.
Expand All @@ -151,7 +151,7 @@
*
READ-RECORD.
READ ACCT-REC
AT END MOVE 'Y' TO LASTREC
AT END MOVE 'Y' TO LASTREC
END-READ.
*
WRITE-RECORD.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@
* paragraph of the code, executes it and returns control to
* the following line.
*
PERFORM UNTIL LASTREC = 'Y'
PERFORM UNTIL LASTREC = 'Y'
* here PERFORM allows a loops to be entered
*
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
.
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
.
*
CLOSE-STOP.
CLOSE ACCT-REC.
Expand All @@ -151,7 +151,7 @@
*
READ-RECORD.
READ ACCT-REC
AT END MOVE 'Y' TO LASTREC
AT END MOVE 'Y' TO LASTREC
END-READ.
*
WRITE-RECORD.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@
*
READ-NEXT-RECORD.
PERFORM READ-RECORD
PERFORM UNTIL LASTREC = 'Y'
PERFORM IS-STATE-VIRGINIA
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
PERFORM UNTIL LASTREC = 'Y'
PERFORM IS-STATE-VIRGINIA
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
.
*
CLOSE-STOP.
Expand All @@ -141,7 +141,7 @@
*
READ-RECORD.
READ ACCT-REC
AT END MOVE 'Y' TO LASTREC
AT END MOVE 'Y' TO LASTREC
END-READ.
*
IS-STATE-VIRGINIA.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,11 @@
*
READ-NEXT-RECORD.
PERFORM READ-RECORD
PERFORM UNTIL LASTREC = 'Y'
PERFORM IS-STATE-VIRGINIA
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
PERFORM UNTIL LASTREC = 'Y'
PERFORM IS-STATE-VIRGINIA
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
.
*
CLOSE-STOP.
Expand All @@ -141,7 +141,7 @@
*
READ-RECORD.
READ ACCT-REC
AT END MOVE 'Y' TO LASTREC
AT END MOVE 'Y' TO LASTREC
END-READ.
*
IS-STATE-VIRGINIA.
Expand Down
20 changes: 10 additions & 10 deletions COBOL Programming Course #2 - Learning COBOL/Labs/cbl/CBL0008.cobol
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@
*
READ-NEXT-RECORD.
PERFORM READ-RECORD
PERFORM UNTIL LASTREC = 'Y'
PERFORM LIMIT-BALANCE-TOTAL
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
PERFORM UNTIL LASTREC = 'Y'
PERFORM LIMIT-BALANCE-TOTAL
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
.
*
WRITE-TLIMIT-TBALANCE.
MOVE TLIMIT TO TLIMIT-O.
MOVE TBALANCE TO TBALANCE-O.
WRITE PRINT-REC FROM TRAILER-1.
WRITE PRINT-REC FROM TRAILER-2.
MOVE TLIMIT TO TLIMIT-O.
MOVE TBALANCE TO TBALANCE-O.
WRITE PRINT-REC FROM TRAILER-1.
WRITE PRINT-REC FROM TRAILER-2.
*
CLOSE-STOP.
CLOSE ACCT-REC.
Expand All @@ -163,7 +163,7 @@
*
READ-RECORD.
READ ACCT-REC
AT END MOVE 'Y' TO LASTREC
AT END MOVE 'Y' TO LASTREC
END-READ.
*
* The LIMIT-BALANCE-TOTAL paragraph performs an arithmetic
Expand Down
20 changes: 10 additions & 10 deletions COBOL Programming Course #2 - Learning COBOL/Labs/cbl/CBL0009.cobol
Original file line number Diff line number Diff line change
Expand Up @@ -143,18 +143,18 @@
*
READ-NEXT-RECORD.
PERFORM READ-RECORD
PERFORM UNTIL LASTREC = 'Y'
PERFORM LIMIT-BALANCE-TOTAL
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
PERFORM UNTIL LASTREC = 'Y'
PERFORM LIMIT-BALANCE-TOTAL
PERFORM WRITE-RECORD
PERFORM READ-RECORD
END-PERFORM
.
*
WRITE-TLIMIT-TBALANCE.
MOVE TLIMIT TO TLIMIT-O.
MOVE TBALANCE TO TBALANCE-O.
WRITE PRINT-REC FROM TRAILER-1.
WRITE PRINT-REC FROM TRAILER-2.
MOVE TLIMIT TO TLIMIT-O.
MOVE TBALANCE TO TBALANCE-O.
WRITE PRINT-REC FROM TRAILER-1.
WRITE PRINT-REC FROM TRAILER-2.
*
CLOSE-STOP.
CLOSE ACCT-REC.
Expand All @@ -163,7 +163,7 @@
*
READ-RECORD.
READ ACCT-REC
AT END MOVE 'Y' TO LASTREC
AT END MOVE 'Y' TO LASTREC
END-READ.
*
* The LIMIT-BALANCE-TOTAL paragraph performs an arithmetic
Expand Down
Loading