IBM Mainframes COBOL Training Class4 Data ItemsVariable Declaration
IBM Mainframes COBOL Training Class-4
Data. Items/Variable Declaration in COBOL § Syntax: Only in DATA DIVISION. LEVEL-NO VAR-NAME PIC DATATYPE (SIZE) VALUE LITERAL. 1 2 3 4 5 6 Level Number Variable Name Picture Data type and size Value clause Literal / constant
Level Numbers in COBOL § There are two types of data Items. § Group data Item & Elementary data item § Level Number specifies the type of the data item and the hierarchical level of the data items. we have Different Level Numbers 01, 02…to… 49, 66, 77 and 88 § § § 01 Group Data Item And Elementary Data Item. 02 To 49 Group Data Item Or Sub-group Item. 66 Rename (Grouping The Different Groups). 77 Purely Elementary Data Item. 88 Condition Name Condition.
Rules to Name a Data Item § The variable-name should not exceed more than 30 characters. § Only the allowable special char is hyphen. § Hyphen should not be present at the starting or else at the ending. § We should not give any reserved words. § E. g. : Display, Division, Section etc…
Data types in COBOL § We have Five Types But Basically only three Data Type In Cobol Max Data Size Numeric (0 -9) 9 18 Alphabetic (a-z) A 160 Cobol-85 Alpha Numeric (a-z)/(0 -9) X 120 Cobol-74 Signed (+Ve, -Ve) S Combination with Numeric 9 +Ve S 9 (+Ve, -Ve) Assumed decimal point V 9(3) v 9(2)
Size & PICTURE Clause § DATA SIZE: Ø Data size is used to allocate the memory internally. Numeric, Alphanumeric and Alphabetic datatypes are going to take 1 byte of memory internally. § PICTURE CLAUSE /PIC: Ø PIC is used to identify the data type and data size. This clause always has to be preceded before specifying type and size § NOTE: Group data items does not contain PIC Clause
Few examples 01 EMP-DET. 05 EMP-ID 05 EMP-NAME 05 EMP-LOC. 10 CITY 10 STATE 05 EMP-DOB 01 STUDENT_DETAILS. 05 WS-SUB 1 PIC 05 WS-SUB 2 PIC 05 WS-SUB 3 PIC 05 WS-SUM PIC 05 WS-AVG PIC PIC 9(4). X(10). PIC PIC X(10). X(8). 9(3) V 9(2).
Value Clause & Constants § VALUE CLAUSE is used to assign values to the variable at the time of declaration and only in DATA DIVISION. It helps in removing garbage values from the variable memory location. § CONSTANTS are used along with the value clause to assign initial value to the data items. ØThree types of Constants: 1. Numeric Constants 2. Non-Numeric Constants 3. Figurative Constants
Constants § Contd. . Figurative constants are reserved words that name and refer to specific constant values. The reserved words for figurative constants and their meanings are: § ZERO/ZEROS/ZEROES § SPACE/SPACES § Numeric Constants are any numerical value signed/unsigned. § 10, -10 99. 99 etc. , § Non-Numeric Constants are any value that are specified in between quotes (‘). § ‘hello’ , ‘ 10’ , ‘ 123 abc’ etc.
Edited Picture Symbols Edit Symbol Meaning Z Zero suppression * Check protection , Comma insertion -/+ Plus or Minus sign insertion
Edited Picture Symbols Edit Symbol Meaning $ Dollar sign insertion CR Credit symbol DB Debit symbol B Blank insertion / Slash insertion . Decimal point insertion BLANK WHEN ZERO Blank insertion when the value is zero
Edit Symbol Value Edited Value ZZ 999 00012 ***99 12 ***12 $9999 0123 $0123 -9999 1234 -1234 +9999 1234 +1234 99, 999 1234 01, 234 99. 99 12. 345 12. 34 99 CR/DB 12 12 CR/DB 99 1234 12 34
Addition Program IDENTIFICATION DIVISION. PROGRAM-ID. ADDPGM. ENVIRONMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-A PIC 9(3) VALUE 01 WS-B PIC 9(3) VALUE 01 WS-C PIC 9(4) VALUE PROCEDURE DIVISION. COMPUTE WS-C = WS-A + DISPLAY ‘WS-C: ’ WS-C. STOP RUN. 800. 700. ZEROS. WS-B.
Run JCL for Add program //FSS 197 EX JOB 123, ’TEAM’, NOTIFY=&SYSUID //STEP 1 EXEC PGM=ADDPGM //STEPLIB DD DSN=FSS 197. TEAM. LOAD, DISP=SHR //SYSPRINT DD SYSOUT=* //SYSOUT DD SYSOUT=* //
Employee Details Program ID DIVISION. PROGRAM-ID. EMPDETPG. ENVIROMENT DIVISION. DATA DIVISION. WORKING-STORAGE SECTION. 01 WS-EMPDET. 05 EMPID PIC X(5) 05 ENAME PIC X(10) 05 ELOC PIC X(10) 05 ESAL PIC 9(5)V 9(2) PROCEDURE DIVISION. ACCEPT EMPID ACCEPT ENAME ACCEPT ELOC ACCEPT ESAL DISPLAY WS-EMPDET STOP RUN. VALUE SPACES. ZERO.
Thank You Polsani Anil Kumar
- Slides: 16