TYPE in COBOL is contextual. In procedural COBOL, data "types" are expressed with PICTURE and USAGE. In REPORT SECTION, group types indicate formatting roles. In OO COBOL, classes represent object types.
12345678* Report group "types" REPORT SECTION. RD SALES-REPORT. 01 PAGE-HEADING. 03 LINE 1 COLUMN 20 VALUE "Sales Report". 01 DETAIL. 03 LINE PLUS 1 COLUMN 5 PIC X(20) SOURCE CUST-NAME. 03 COLUMN 35 PIC $$,$$9.99 SOURCE CUST-AMOUNT.
123456* Data description using PICTURE and USAGE 01 QUANTITY PIC 9(5) USAGE DISPLAY. 01 PRICE PIC 9(5)V99 USAGE DISPLAY. 01 TOTAL PIC 9(7)V99 USAGE DISPLAY. 01 KEY-BIN PIC S9(9) USAGE COMP. 01 PACKED-AMT PIC S9(7)V99 USAGE COMP-3.
123456789101112* OO COBOL type notions CLASS-ID. ACCOUNT. END CLASS ACCOUNT. IDENTIFICATION DIVISION. PROGRAM-ID. CREATE-ACCOUNT. DATA DIVISION. WORKING-STORAGE SECTION. 01 ACCT-REF OBJECT REFERENCE ACCOUNT. PROCEDURE DIVISION. INVOKE ACCOUNT "NEW" RETURNING ACCT-REF GOBACK.
Context | Definition | Example |
---|---|---|
Scalar data | PICTURE and USAGE | PIC 9(5) USAGE DISPLAY |
Report group | PAGE-HEADING, DETAIL | PAGE-HEADING group |
OO COBOL | CLASS-ID, OBJECT-REFERENCE | OBJECT REFERENCE ACCOUNT |
1. Where is TYPE most commonly seen in classic COBOL?
2. Does COBOL have a universal TYPE keyword for data definitions?
3. How is "type" used in OO COBOL contexts?
4. Which is the best substitute for a generic type system in procedural COBOL?
5. What is a best practice when discussing "type" in COBOL designs?