Wednesday, 25 April 2018

COBOL Tutorials

1.       COBOL DIVISION
a)      Identification Division
b)      Environment Division - Input-Output Section / File-Control
Select File1 (Logical Name) Assign to DDNAME (Physical Name)
Organization is SEQUENTIAL/INDEXED SEQUENTIAL/RELATIVE
Access is SEQUENTIAL/ RANDOM/ DYNAMIC
Record Key is X
RELATIVE KEY is Y
ALTERNATIVE RECORD IS Z
FILE STATUS IS WS_FILE_STATUS
c)       Data Division - File Section/ Working-Storage Section/ Linkage Section
d)      Procedure Division / Division/ Section/ Paragraph/ Sentence/ Word/ Character

2.       Positions
1-6(Sequence)/ 7(INDICATOR * - /) / 8-11(AREA A)/ 12-72(AREA B)/ 73-80(ID)

3.       Data Items - PIC 9/ 9 V S X A
4.       Editing Characters - Z $ * _ + _ . , / 0 B BLANK WHEN ZERO

5.       COBOL Level

Elementary Items/ Group Data Items / LEVEL Number/ 01/ 02-49/ 66 -Rename/ 77- Cannot be subdivided/ 88- Condition Name

6.        COBOL Verbs
a)      Data Manipulation (Arithmetic Verbs) - INITIALIZE/MOVE/ADD/SUBTRACT/MULTIPLY/DIVIDE/COMPUTE
b)      I/O Verbs - ACCEPT/DISPLAY  
c)       String Handling Verbs - STRING/UNSTRING/INSPECT/EXAMINE
d)      File Handling Verbs - OPEN/CLOSE/READ/WRITE/REWRITE/START/DELETE
e)       PROGRAM Branching Verbs - CALL/EXIT/EXIT PROGRAM/GO TO/ PERFORM/ STOP/ STOP RUN/ GOBACK/ EXIT RUN / NEXT / CONTINUE
STOP Run – Control back to operating system. Stop program even if used in subroutine.
GOBACK – Control back to calling program or sub program.
Exit Run – Control back to main program.

7.       Conditional Expressions
IF ELSE END-IF / Relation Condition (=,>, < etc.) / Sign Condition (Positive, Negative or Zero) / CLASS Condition (NUMERIC, ALPHABETIC) / Condition-name Condition (88 condition) / EVALUATE
8.       COBOL Loop Statement - Perform Thru / Perform Until / Perform Times / Perform Varying
9.       COMPUTATIONAL   - COMP, COMP-1, COMP-2, COMP-3, COMP-4
BINARY FORMAT (COMP & COMP-4) – Occupies 2 or 4 or 8 bytes of storage [<= 4 (2 byte), 5 to 9 (4 bytes), 10 to 18 (8 bytes)]. If signed, left most bit used to represent sign.
PACKED Decimal Format(COMP-3) - 1 byte for two decimal digits. Right most digit bit is used to represent sign. Efficient when odd no. Of bytes are present.
COMP-1 (Short floating format)Occupies 4 byte of storage.
COMP-2 (Long floating format) -    Occupies 8 byte of storage. Internally stored in hexadecimal format.
DISPLAY1 digit per byte. Sign and decimal doesn’t require bytes.
Note – 4 Bit = 1 nibbles (1 nibble is used to sign in COMP-3)

10.   Compiling COBOL Program – IGYCRCTL utility
11.   Executing COBOL Program – EXEC PGM = ABC, PARM = ACCT5000
12.   Executing COBOL DB2 Program – IKJEFTO1
13.   COBOL Data Layout
REDEFINES CLAUSE/ RENAMES CLAUSE/ USAGE CLAUSE i.e. USAGE IS DISPLAY or COMP/ COPYBOOK i.e. COPY ABC (Compile time, rest run time)

14.   TABLE Handling
Table/Array Processing/ OCCUR Clause/ OCCUR DEPENDING ON (ODO, variable length table) / One & Two-Dimensional Table/SUBSCRIPT (Indicates position of an entry) / INDEX/ SET Statement/ Search/Search All
INDEX – Value to be added to the address of a table to locate an item, displacement from beginning of table. Index can be modified only by a PERFORM, SEARCH or SET statements.
Searching a table (Serial & Binary) – SERIAL – Use PERFORM.VARYING with subscripting or indexing. Use SEARCH & Indexing.  BINARY – Indexing & SEARCH ALL.
Variable Length Table
01 WS-SAMPLE-TABLE
      05 WS_SAMPLE_TABLE_FIELD OCCURS 1 TO 10 TIMES DEPENDING ON VAR-X Loading data into table
a)       Dynamically loading the table – SUBSCRIPT or INDEX using PERFORM
b)      By using Initialization – REPLACING (not variable length table)
c)       By using VALUE Clause.

15.   FILE Handling
File Organization - SEQUENTIAL/ RANDOM/ DYNAMIC
File Access Mode - SEQUENTIAL/INDEXED SEQUENTIAL/RELATIVE
File Open Mode - INPUT/OUTPUT/IO/EXTEND - OPEN MODE FILENAME
OUTPUT – If sequential file tan earlier records deleted / not happen with indexed or relative fi Extend – Append records in a sequential file can not be used with Random or Dynamic file.
START – can be performed only Index and Relative file. Use to place file pointer at a specific record.
Syntax – Read write Sequential / Dynamic and Random file and all open mode use.
File Handling Verbs - OPEN/READ/WRITE/REWRITE/DELETE/START/CLOSE
READ file-name NEXT RECORD INTO ws-file-status
AT END DISPLAY ‘End of file’
NOT AT END DISPLAY ‘Record Details:’, WS-file-structure
END-READ

16.   COBOL SUBROUTINES
INTERNAL (Perform)/EXTERNAL (CALL)
CALLING Program/CALLED Program (Linkage Section/Procedure Division Using/Exit Program)
CALL BY REFERENCE (Default)/ CALL BY CONTENT
TYPES OF CALL
a)      Static Call - Default (NO DYNAM) - Occupy more space, time is less, fast execution, changes in called pgm, have to compile calling pgm as well.
b)      Dynamic Call - Dynam - Occupy less space, slow execution, here only changed pgm to be recompiled.

Transfer control from one pgm to another pgm. Nested pgm transfer the item referred by GIVING clause to main pgm. GIVING data item must be numeric & could be declared as BINARY, REAL, DOUBLE, EBCDIC or COMPUTATIONAL.

17.   SORT   - Internal Sort (COBOL)/ EXTERNAL SORT (JCL)
SORT WORK-FILE ON ASCENDING KEY rec-key1 USING INPUT-FILE GIVING OUTPUT-FILE
MERGE WORK-FILE ON ASCENDING KEY rec-key1 USING INPUT-FILE1, INPUT-FILE2 GIVING OUTPUT-FILE. 

18.   STORED PROCEDURESQL Procedure (written in SQL, logic in SQL procedure body itself) / External Procedure (Load & run unit of code written in entirely diff language) / Must be defined in catalogue (SYSIBM.SYSROUTINES) / Parameter type (IN / OUT / INOUT)
Calling a stored Procedure
EXEC SQL
      CALL MYPROC (:INPUT,:OUTPUT)
END_EXEC
a)       How to create stored procedure? – DB2 Development Centre Tool / Code directly on Query Builder.

19.   COBOL Database Interface
Embedded SQL/ DB2 Application Programming / EXEC SQL ENDEXEC/HOST VARIABLE/SQLCA/ SQLCODE CURSOR/DECLARE/OPEN/FETCH/CLOSE
TSO (Time Sharing Option) /ISPF (Interactive System productivity facility) /MVS (Multiple Storage System) / CAF (Call Attachment Facility) /RRSAF (Recoverable Resource Service attachment facility).
20.   FILES Status
0 - I/O operation Successful.
1 - End of File
2 - Invalid Key
3 - Permanent I/O Error
4 - Logic Error

00 – I/O operation successful
02 – Duplicate record key found (READ ok)
04 – Length of record too large (READ ok)
10 – File at END
23 – Record not found



For VSAM Only

91 - Password Failure
92 -  Logical Error
93 – Resource not available
94 – No file position indicator for sequential request
95 – Invalid or incomplete file information
96 – No DD statement specified for this file.
97 – OPEN statement executives successful.


21.   COBOL Questions
a)       Input file
HCL TECHNOLOGIES !@#$
IBM  MAINFRAME %&A

OUTPUT FILE
TECHNOLOGIES
MAINFRAME

ANS – BY USING SORT/ BY USING COBOL PGM/ BY USING SELCOPY

b)      Input file
MAINFRAME
JAVA

OUTPUT FILE
MAINFRAME IBM
JAVA               TCS

ANS – BY USING SORT/ BY USING COBOL PGM

c)       How table is defined in COBOL & what are diff ways table are accessed?
Ans – OCCURS & accessed using SUBSCRIPT or INDEX.

d)      COBOL pgm to select distinct records from a file? – SORT and then Input Field NOT = WS-Variable.
e)       How to read file through Index/Key?
f)       How we read KSDS file?
g)      Sort files i.e. compare two files through DFSORT & write in third file?
h)      File like below (Sequential file) – ABXYZPRAVINMNOPPRAVIN / We have to write all PRAVIN in output file. (Using COBOL/JCL)
ANS – ESDS file (File Organization as sequential and access mode as sequential with ESDS dataset. Records are referenced by RBA (Relative byte address). RBA of first record ‘0’, second record ‘80’, if we have 80-byte records (max length).
i)        If I can move ‘AB’ in PIC 9(2).
ANS – No, cannot move alphabetic to Numeric data type.
j)        Member used with INCLUDE will get expanded at pre-compilation stage and member used with COPY will get expanded at compilation stage. If you COPY to expand DB2 DCLGEN member, your program will fail at pre-compilation stage saying host variable are not defined.
k)      DECLARATIVES – Beginning of Procedure division / DECLARITIVES & END DECLARATIVES in AREA A / Exception handling / Interrupt handling – HI98/HI99
l)        Processing VSAM file – COBOL Pgm use VSAM in 3 ways:1) To load a file 2) To retrieve records from a file. 3) To update a file. VSAM processing is the only way for program to use Indexed or relative file organization. Data protection against unauthorized access.
m)    Compiler option SSRANGE – If you want array bounds checking. Default is NOSSRANGE.
n)      IS NUMERIC – used to check if any item is numeric if yes than returns ‘TRUE’.

22.   COBOL MIPS -
a)       Group Initialize – costliest
b)      Evaluate instead of IF
c)       Binary variable instead of COMP or Display.
d)      Search vs Search All
e)       Index instead of Subscript
f)       Positional move instead of STRING.
g)      File access mode – specify proper access mode i.e. Sequential, Random or Dynamic.
h)      Avoid Rounded in Arithmetic operation

i)        MIPS – STROBE Report / SAR (like ZAPC to see in which step taking more time) / MS Access / CPU Chart / BAR Chart.

No comments:

Post a Comment