[an error occurred while processing this directive]
HP OpenVMS Systems Documentation |
HP COBOL
|
Previous | Contents | Index |
INITIALIZE-SEARCH. MOVE 1 TO CUSTOMER-REGION. MOVE "NH" TO CUSTOMER-USPS-STATE. DISPLAY "States in customer's region:". SEARCH-LOOP. SEARCH STATES AT END GO TO SEARCH-END WHEN STATE-USPS-CODE (STATE-INDEX) = CUSTOMER-USPS-STATE SET STATE-NUM TO STATE-INDEX WHEN STATE-REGION (STATE-INDEX) = CUSTOMER-REGION DISPLAY STATE-USPS-CODE (STATE-INDEX) " " WITH NO ADVANCING. SET STATE-INDEX UP BY 1. GO TO SEARCH-LOOP. SEARCH-END. DISPLAY " " DISPLAY "Customer state index number = " STATE-NUM. |
States in customer's region: CT DC DE MA MD ME NJ NY PA RI VT Customer state index number = 31 |
GET-NAME. DISPLAY "Enter name: " NO ADVANCING. ACCEPT CUSTOMER-NAME. SET NAME-INDEX TO 1. SEARCH NAME-ENTRY AT END DISPLAY " Table full" SET NAME-INDEX TO 1 PERFORM SHOW-TABLE 8 TIMES STOP RUN WHEN LAST-NAME (NAME-INDEX) = CUSTOMER-NAME ADD 1 TO NAME-COUNT (NAME-INDEX) WHEN LAST-NAME (NAME-INDEX) = SPACES MOVE CUSTOMER-NAME TO LAST-NAME (NAME-INDEX) MOVE 1 TO NAME-COUNT (NAME-INDEX). GO TO GET-NAME. SHOW-TABLE. DISPLAY LAST-NAME (NAME-INDEX) " " NAME-COUNT (NAME-INDEX). SET NAME-INDEX UP BY 1. |
Enter name: CRONKITE
Enter name: GEORGE
Enter name: PHARES
Enter name: CRONKITE
Enter name: BELL
Enter name: SMITH
Enter name: FRANKLIN
Enter name: HENRY
Enter name: GEORGE
Enter name: ROBBINS
Enter name: BELL
Enter name: FRANKLIN
Enter name: SMITH
Enter name: BELL
Enter name: SMITH
Table full
CRONKITE 002
GEORGE 002
PHARES 001
BELL 003
SMITH 003
FRANKLIN 002
HENRY 001
ROBBINS 001
The SET statement sets values of indexes associated with table elements. It can also change the value of a conditional variable, change the status of an external switch, and store the address of a COBOL identifier reference at run time.
rsult
is an index-name, the identifier of an index data item, or an elementary numeric data item described as an integer.val
is a positive integer, which can be signed. It can also be an index-name (or the identifier of an index data item) or an elementary numeric data item described as an integer.indx
is an index-name.increm
is an integer, which can be signed. It can also be the identifier of an elementary numeric data item described as an integer.cond-name
is a condition-name that must be associated with a conditional variable.switch-name
is the name of an external switch defined in the SPECIAL-NAMES paragraph.pointer-id
is a data-name whose data description entry must contain the USAGE IS POINTER clause.identifier
is a data item in the File, Working-Storage, Linkage, or Subschema Section.status-code-id
is a word or longword integer data item represented by PIC S9(1) to S9(9) COMP or PIC 9(1) to 9(9) COMP.
No two occurrences of cond-name can refer to the same conditional variable.
Sending Item | Receiving Item | ||
---|---|---|---|
Integer Data Item | Index | Index Data Item | |
Integer Literal | Invalid/Rule 7 | Valid/Rule 5 | Invalid/Rule 6 |
Integer Data Item | Invalid/Rule 7 | Valid/Rule 5 | Invalid/Rule 6 |
Index | Valid/Rule 7 | Valid/Rule 5 | Valid/Rule 6* |
Index Data Item | Invalid/Rule 7 | Valid/Rule 5* | Valid/Rule 6* |
The examples assume these Environment and Data Division entries:
SPECIAL-NAMES. SWITCH 1 UPDATE-RUN ON STATUS IS DO-UPDATE SWITCH 3 REPORT-RUN ON STATUS IS DO-REPORT OFF STATUS IS SKIP-REPORT SWITCH 4 IS NEW-YEAR ON STATUS IS BEGIN-YEAR OFF IS CONTINUE-YEAR. DATA DIVISION. WORKING-STORAGE SECTION. 01 YEAR-LEVEL PIC 99. 88 FRESHMAN VALUE 1. 88 SOPHOMORE VALUE 2. 88 JUNIOR VALUE 3. 88 SENIOR VALUE 4. 88 FIRST-MASTERS VALUE 5. 88 MASTERS VALUE 5,6. 88 FIRST-DOCTORAL VALUE 7. 88 DOCTORAL VALUE 7,8. 88 NON-DEGREE-UNDERGRAD VALUE 9. 88 NON-DEGREE-GRAD VALUE 10. 88 UNDERGRAD VALUE 9, 1 THROUGH 4. 88 GRAD VALUE 10, 5 THROUGH 8. 01 COURSES-AVAILABLE. 02 OCCURS 100 TIMES INDEXED BY COURSE-INDEX. 03 COURSE-NAME PIC X(10). 03 COURSE-INSTRUCTOR PIC X(20). 03 COURSE-LOCATION PIC X(10). 03 COURSE-CODE PIC 9(5). 01 POINTER-VAL USAGE IS POINTER. 01 THREE-DIMENSIONAL-TABLE. 02 X OCCURS 5 TIMES INDEXED BY I. 03 Y OCCURS 7 TIMES INDEXED BY J. 04 Z PIC X(17) OCCURS 3 TIMES. 01 K PIC S9(9) COMP. 01 RETURN-STATUS PIC S9(9) COMP. 01 DECREMENT-VALUE PIC 9 VALUE 1. |