MainframeMaster

COBOL Tutorial

COBOL TYPE - Quick Reference

Progress0 of 0 lessons

Overview

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.

Contexts for TYPE

  • Data representation - PICTURE and USAGE
  • Report groups - PAGE-HEADING, DETAIL, FOOTING
  • OO COBOL - CLASS-ID, OBJECT-REFERENCE

Syntax and Usage

Report Group Types

cobol
1
2
3
4
5
6
7
8
* 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.

Data "Type" via PIC/USAGE

cobol
1
2
3
4
5
6
* 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.

OO COBOL Object Types

cobol
1
2
3
4
5
6
7
8
9
10
11
12
* 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.

Best Practices

  • Be precise - Refer to PIC/USAGE when discussing scalar data type
  • Clarify context - Report group vs object type
  • Portability - Prefer standard constructs across compilers

TYPE Quick Reference

ContextDefinitionExample
Scalar dataPICTURE and USAGEPIC 9(5) USAGE DISPLAY
Report groupPAGE-HEADING, DETAILPAGE-HEADING group
OO COBOLCLASS-ID, OBJECT-REFERENCEOBJECT REFERENCE ACCOUNT

Test Your Knowledge

1. Where is TYPE most commonly seen in classic COBOL?

  • REPORT SECTION group classifications (e.g., PAGE-HEADING, DETAIL)
  • As a standalone verb
  • As a file status keyword
  • In the IDENTIFICATION DIVISION

2. Does COBOL have a universal TYPE keyword for data definitions?

  • Yes, in all compilers
  • No, data characteristics are defined with PICTURE and USAGE; TYPE is contextual
  • Only in JCL
  • Only in SORT statements

3. How is "type" used in OO COBOL contexts?

  • To declare intrinsic numeric types
  • To refer to classes and object types (CLASS-ID, OBJECT-REFERENCE)
  • To define file organization
  • To control terminal I/O

4. Which is the best substitute for a generic type system in procedural COBOL?

  • Using PICTURE and USAGE with naming conventions
  • Using GO TO frequently
  • Avoiding data declarations
  • Embedding SQL types directly

5. What is a best practice when discussing "type" in COBOL designs?

  • Be explicit about the COBOL construct (PIC/USAGE, REPORT group, OO class)
  • Use generic words only
  • Avoid documentation
  • Assume all compilers behave the same

Frequently Asked Questions