Wednesday, 25 April 2018

JCL Tutorial


1.       Job Processing - Job Entry System / Job Queuing / Job Execution / Purging – JCL is submitted to JES (Job Entry System) / JES2 & JES3 (Subsystem part of OS, manages Batch Jobs & SYSOUT)

2.       8 JCL Statements - JOB / EXEC / DD / PROC / PEND / COMMENT / DELIMETER / 'NULL' ending statement
//NAME JOB Parameter
 //* Comment
/* End of data stream
// Null statement, all lines coded after this will not be executed.
3.       Job Parameters Types - Positional-param / Keyword-param

4.       JOB Statement - //Job-name JOB Positional-param, Keyword-param

Positional-parm - Account information/ Programmer name
Keyword-parm - CLASS=0 to 9 | A to Z / PRTY = 0 to 15 / NOTIFY='userid| &SYSUID' / MSGCLASS= A to Z 0 to 9 / MSGLEVEL= (ST, MSG) / TYPRUN =SCAN|HOLD / TIME = (mm,ss) or TIME = ss/ REGION = nk | nM or 0K | 0M / Miscellaneous Parameters – ADDRSPC / COND and RESTART / USER / PASSWORD
Note – Positional parameter are always preceded by Keyword parameter.

5.       EXEC Statement
//Step-name EXEC Positional-parm, Keyword-parm
Positional-parm – PGM / PROC
Keyword-parm - PARM / ADDRSPC = VIRT|REAL / ACCT= (userid)
Common Keyword Parameter of EXEC and JOB Statement – ADDRSPC / TIME / REGION / COND

6.       DD Statements   - //DD-Name DD Parameters
Parameters - DSN=Physical Dataset Name/ DSN=&name (Temporary dataset) / DSN= *.stepname.ddname(Backward Referencing).
DISP= (status, normal-disposition, abnormal-disposition) / Status - NEW/OLD/SHR/MOD / normal-disposition / abnormal-disposition - CATLG, UNCATLG, DELETE, PASS and KEEP DCB= LRECL / RECFM - FB, V, VB / BLKSIZE / DSORG - PS, PO (Partitioned Organization), DA (Direct Organization)
DCB=*.stepname.ddname
UNIT = DASD (Direct Access Storage Device) / SYSDA (System Direct Access) 
VOL = SER= (v1,v2) / VOL= REF=*.DDNAME(Backward Reference)
SYSOUT= class (A -printer/ * output to same destination MSGCLASS)
//INFILE DD DSN=SED.GLOB.DES (Name field – optnl field start at col ‘3’, max length ‘8’)
DISP = (NEW,CATLG,DELETE)
UNIT = DISP
SPACE = (CYL,(1,5),RLSE)
DCB=(RECFM=FB,LRECL=20,BLKSIZE=200)

DDNAME – JOBLIB, JOBCAT, SYSABEND, SYSIN, SYSCHK, STEPLIB, STEPCAT, SYSDUMP, SYSOUT, SYSOUD, SYSDBOUT.
//INFILE DD SYSOUT=A

7.       JOBLIB / STEPLIB
BASE Library = Partitioned Dataset = Load Module
JOBLIB - //JOBLIB DD DSN=dsnname,DISP=SHR
STEPLIB - //STEPLIB DD DSN=dsnname,DISP=SHR
INCLUDE - //name INCLUDE MEMBER=member-name
JCLLIB - //name JCLLIB ORDER=(library1,library2...)

8.       Procedure
a)       JCL Procedure - //step-name EXEC procedure name
b)      INSTREAM Procedure - //INSTPORC PROC //PEND / DSNAME & DATAC - SYMBOLIC Parameters
c)       CATALOGED Procedure - //CATLPROC PROC PROG=, BASELIB=MYCOBOL.BASE.LIB1 / PROG & BASELB - SYMBOLIC Parameters
d)      NESTED Procedure - Calling a procedure from within a procedure / SET Statement - Symbolic across job steps or procedure.
e)       SYMBOLIC Parameter – Same PROC to be reused & called by many Jobs.
//IN1 DD DSN=&ID.URMI,DISP=SHR
ID=X1 (Coded in Job 1) / ID=X2   (Coded in Job2 ) and so on.

f)       SET Statement
//Name SET Symbolic-Parameter= values
g)      INCLUDE Statement
//Name INCLUDE Member= Name <- Containing JCL Statement

9.       JCL - Conditional Processing
Return Code - 0 (successful execution) to 4095 (non-zero shows error condition) / 0, 4, 8, 12 & 16
COND Parameter - COND= (Comparison Code, logical-operator, Step name, EVEN/ONLY) COND = EVEN (even if any previous step terminates) /ONLY (only if any previous step terminates).
Logical operator – GT / GE / EQ / LT / LE / NE. Condition true then step bypassed COND in JOB then check for each step. COND in EXEC then check in that step.  //IF1    IF STP01.RC = 0 THEN
RESTART Processing – Automated (RD Parameter – R/RNC/NR/NC) / Manual (RESTART parameter).
Setting Checkpoint –
//SYSCKEOV DD DSNAME=SAMPLE.CHK, DISP=MOD
//IN1       DD DSN=SAMPLE.IN, DISP=SHR
//OUT1      DD DSN=SAMPLE.OUT, DISP= (, CATLG, CATLG)
// CHKPT=EOV, LRECL=80,RECFM=FB - A checkpoint is written in dataset SAMPLE.CHK at the end of each volume of the output dataset SAMPLE.OUT.

RESTART can be accompanied with a check id, which is the checkpoint written in the dataset coded in the SYSCKEOV DD statement. 
//CHKSAMP JOB CLASS=6, NOTIFY=&SYSUID, RESTART= (STP01, chk5)
//SYSCHK    DD DSN=SAMPLE.CHK, DISP=OLD
//STP01     EXEC PGM=MYCOBB
//IN1       DD DSN=SAMPLE.IN, DISP=SHR
//OUT1      DD DSN=SAMPLE.OUT, DISP= (, CATLG, CATLG)
//          CHKPT=EOV, LRECL=80, RECFM=FB          

Note – When COND is coded in JOB statement, the condition is tested for every job step. When condition is true at particular job step, it is bypassed along with the job steps following it. EXEC time will override JOB Time (Whichever less). JOB REGION will override EXEC region. JOB condition overrides EXEC COND.   

10.   JCL – Defining Datasets
DSN=&name | *.stepname.ddname
a)       Temporary Datasets - DSN=&name
b)      Concatenating Datasets – All datasets must be of same type. Max of 255 sequential datasets can be concatenated together. Max 16 portioned datasets can be concatenated together.
//SORTIN    DD DSN=SAMPLE.INPUT1, DISP=SHR
//          DD DSN=SAMPLE.INPUT2, DISP=SHR
//          DD DSN=SAMPLE.INPUT3, DISP=SHR
c)       Overriding Datasets –
//JSTEP1    EXEC CATLPROC, PROG=CATPRC1, DSNME=MYDATA.URMI. INPUT
//STEP1.IN1 DD DSN=MYDATA.OVER. INPUT, DISP=SHR <-- Here it will override in statement(IN1) of CATLPROC        
//CATLPROC PROC PROG=, BASELB=MYCOBOL.BASE.LIB1
//IN1       DD DSN=MYDATA.URMI. INPUT, DISP=SHR

11.   Generation Data Group (GDG) – Group of chronologically or functionally related datasets related to each other by a common name. GDG base (common name).
Latest version – X(0) / previous version – X(-1) / next version – X(+1)
DEFINE GDG(NAME(MYDATA.URMI.SAMPLE.GDG) - LIMIT(7) -  EMPTY / NOEMPTY – SCRATCH / NOSCRATCH) – (TO DATE / FOR DAYS)
SCRATCH - Physically deletes the generation when it is uncatalogued.
EMPTY - uncatalogued all the generations when the LIMIT is reached.
DELETE GDG – DELETE(X) GDG FORCE/PURGE (FORCE – don’t delete dataset yet to expire / PURGE – delete GDG versions & the GDG base irrespective of expiration date).

12.   INPUT/OUTPUT Methods - INSTREAM DATA
//STEP10 EXEC PGM=MYPROG 
//SYSIN DD * 
//CUST1 1000  ß here CUST1 value is passed to program MYPROG.
(Also, through file - //SYSIN DD DSN= SAMPLE.SYSIN.DATA, DISP=SHR)

Output in a JCL can be catalogued into a dataset or passed to the SYSOUT. SYSOUT=* redirects the output to the same class as mentioned in the MSGCLASS. Specifying MSGCLASS=Y saves the job log in the JMR (Job log Management and Retrieval).

Job logs can also be saved into a dataset by SYSOUT and SYSPRINT.
//OUT1     DD SYSOUT=*   
//SYSOUT   DD DSN=MYDATA.URMI. SYSOUT, DISP=SHR     
//SYSPRINT DD DSN=MYDATA.URMI. SYSPRINT, DISP=SHR

13.   Running COBOL Programs –
Compiling –
//STEP1     EXEC IGYCRCTL,PARM=RMODE,DYNAM,SSRANGE                                                        //SYSIN     DD DSN= MYDATA.URMI.SOURCES(MYCOBB),DISP=SHR  <- COBOL Pgm                                                
//SYSLIB    DD DSN= MYDATA.URMI.COPYBOOK(MYCOPY),DISP=SHR                                      
//SYSLMOD   DD DSN=MYDATA.URMI.LOAD(MYCOBB), DISP=SHR   <- Load Module

RUNNING –
//STEP10    EXEC PGM=MYPROG,PARM=ACCT5000      
//STEPLIB   DD DSN=MYDATA.URMI.LOADLIB,DISP=SHR 
//INPUT1    DD DSN=MYDATA.URMI.INPUT,DISP=SHR  
//OUT1      DD SYSOUT=*   <- producing one output file written to spool

//SYSTIN DD*
DSN SYSTEM(GRT1)
RUN PROGRAM(DSNSTEP2) PLAN(DSNSTEP2)
LIB(‘DB2P.RUNLIB.LOAD’)
//END

Running COBOL-DB2 Program - DBRM is bound to the DB2 region (environment) in which the COBOL will run using the IKJEFT01. COBOL-DB2 program is run using IKJEFT01 with the load library and DBRM library as the input.
//STEP001  EXEC PGM=IKJEFT01
//STEPLIB  DD DSN= MYDATA.URMI.DBRMLIB, DISP=SHR  DSN SYSTEM(SSID)      RUN PROGRAM(MYCOBB) PLAN(PLANNAME) PARM(parameters to COBOL program) -       LIB('MYDATA.URMI.LOADLIB')  END 

14.   Passing data from JCL to COBOL
a)       Through file, referred in the program using the DD name INPUT1.
b)      via PARM (PARM parameter, data received in the LINKAGE section of program in its defined variable.     
LINKAGE SECTION
01 PARM-BUFFER
05 PARM-LENGTH PIC S9(4) COMP.ß 2 bytes binary value specfy length data string
05 PARM-NAME PIC X(100).ß Max length that can be passed via PARM is 100 bytes
JCL
//MYJOB EXEC PGM=COBPROG, PARM=RAMESH

c)       via SYSIN (ACCEPT statement reads one whole record into a working storage variable defined in the program).
//SYSIN DD*
  23052014

COBOL
PROCEDURE DIVISION
ACCEPT EMP-NUMBER

15.   IBM Datasets Utilities –
a)       DSNHPC Utiliity – Precompilation
b)      IGYCRCTL - Compiler
c)       IEWL – Link Edit.
d)      IKJEFT01 – BIND / Unload table (Image copy) / Issue TSO Commands
e)       IEBGENER – Copy one sequential file to another
f)       IEBCOPY –Copy partitioned dataset(loading / unloading) .
g)      IEHPROGM –catalog / uncatalog / rename datasets.
h)      IEBCOMPR – Compare two sequential/partitioned datasets.
i)        IEFBR14 – Null pgm/execute single statement specify end of program / Dummy utility/ create empty dataset or delete an existing dataset.
j)        DSNUTILB – Unload auxiliary table(image copy).
k)      DFSORT/SORT – Sort file
l)        IDCAMS – VSAM dataset creation/REPRO – load VSAM dataset
m)    DSNUPROC – Load Tables / REORG / RUNSTATS
n)      IKFCBLOO – Compiler Pgm
o)      IFASMFDP - SMF Dump Pgm
p)      A11RMS/U11RMS – Rerun job multiple Times, restart from abended step, existing file in catalog deleted & recreated.
q)      DB2TSOB – Stop / Start database & start in utility mode from R/W status / REORG
r)       DSNTAUL -Unload / Image copy
s)       NDMSEND – NDM
t)        DSNTEP2 – Create table
u)      UCC11RMS – Delete Step
v)      IEBEDIT – to include / exclude JCL steps 
w)     IEHMOVE -  
x)      IEBGENER (SYSUT1 – read input dataset / SYSUT2 – write the data / SYSIN – Special instructions / SYSPRINT – write report what it IEBGENER did)

16.   JCL – Basic Sort Tricks –
//STEP10 EXEC PGM=SORT, REGION=1024K,PARM=Parameter
//SYSOUT DD SYSOUT=* ß OUT Msg from Sort
//SORTIN DD DSN=..,DISP=SHR ß INPUT FILE
//SORTOUT DD DSN=.., ß OUTUT FILE
//SORTFXX DD DSN=.., ß OUTPUT dataset
//SORTWKnn DD UNIT = SYSDA ß Work file if SORT request
//SYSIN DD*
    SORT CONTROL STATEMENT
//

a)      SORT a given file
SORT FIELD =   (1,3,CH,A,9,3,CH,A) [ 1 - first position, 3 – Length ,   CH – Character, A – Ascending order]

b)      Eliminate Duplicates
SORT FIELDS=(1,15,ZD,A)   SUM FIELDS=NONE <- output file will contain unique employee numbers sorted in ascending order.

c)       Split file into two or three files depends on condition
SORT FIELDS = COPY
OUTFIL FILES = 01, INCLUDE= (1,6,CH, EQ,(‘MOHANK’))
OUTFIL FILES = 02, INCLUDE= (1,6,CH, EQ,(‘SURESH’))

OUTFIL FILES = 01, ENDREC= 100
OUTFILE FILES=02, STARTREC = 101, ENDREC=200
OUTFILE FILES=02, STARTREC = 200

STARTREC and ENDREC – Splitting file into 3 parts


d)      COPY Eliminate duplicates into another file
SORT FIELDS=(1,3,CH,A)
SUM FIELDS = NONE,XSUM ß Copy to another data set defined in SORT XSUM Step.

e)       COPY records depending on condition
SORT FIELDS = COPY
INCLUDE COND = (1,6,CH,EQ,(‘SURESH’)
f)       Formatting a file using INREC
SORT FIELDS = COPY
INREC FIELDS= (7:2,5,20:10,3) ß Data at 2nd position of input file with length 5 copied to 7th position of output file.

INREC( Reformat fields before records are sorted or merged) /OUTREC (After) / SKIPREC = n (Sort skip n records in input file) / STOPAFT = n (Sort stop after n  records)
g)      Adding Sequence no. To file
SORT FIELDS = COPY
BUILD = (1:1,5,10:SEQNUM,4,ZD,START=1000,INCR=2)
h)      Adding Header/Trailer to output file
SORT FIELDS = COPY
HEADER=(1’HDR’,10:X’020110131C’)
TRAILER=(1L’TRL’,TOT=(10,9,PD,TO=PD,LENGTH=9)
i)        File Comparison (//MAIN DD* & //LOOKUP DD*)
JOIN KEYS – Fields on which two files are compared.
JOIN KEYS F1= MAIN, FIELD=(1,4,A)
JOIN KEYS F1= LOOKUP, FIELD=(1,4,A)
JOIN UNPAIRED – does a full outer join on two files.
JOIN UNPAIRED,F1,F2
REFORMAT FIELDS – Place match record in MATCH file & unmatched records in NOMATCH1, NOMATCH2

//SYSIN    DD *   OPTION COPY     INREC OVERLAY=(47:1,6) <- the content in position 1,6 is overwritten to the positio47,6 and then copied to the output file.

j)        Backing up a file - IEBGENER copies the file in SYSUT1 to file in SYSUT2.
k)      ICETOOL
//JSTEP020 EXEC PGM=ICETOOL 
//TOOLIN   DD *   COPY FROM(IN1) TO(OUT1) USING(CTL1)                                  //CTL1CNTL DD *    OPTION STOPAFT=10  ß Only first 10 records to write to output file.

  
17.   Common JCL Abends
a)       JCL Error – File attribute don’t match; For example, I have given RECFM=VB RECLEN is same as that specified in FD section. Why do I get this error? For variable record format files, you should add 4 bytes to record length in DCB in JCL (LRECL = 404 i.e. 4 Length more)
b)      S322 – Timed out, try changing job class.
c)       S806 – Load module not found. Check library specified in Joblib.
d)      S913 – Insufficient authority. Check if you have specified access to dataset.
e)       S878 – Region size is not enough.  Increase the value you have specified in region parameter of Job statement or in Exec step. Or you can give Region=0M; in this case, the system will allocate the maximum size available.
f)       S522 – Job cancelled by either user or operator.
g)      SOC4 – Storage related problem. Check your linkage, table definition, and FD section.
h)      S013 – A file open error.
i)        S722 – The Sysout or spool is full, your program is writing too many things to sysout. Increase job’s Sysout limit by specifying ‘LINES=(150,WARNING)’ option in job statement and then retry. This will increase your Sysout limit to ‘150’ thousand lines.
j)        SOC7 – Invalid character in COMP/COMP-3 numeric field – Check all COMP/COMP-3 numeric fields and arithmetic operations / Data exception error.
k)      SOC7 Abend – occurs when an invalid character is present in COMP/COMP-3 numeric field and you tried to manipulate that field by some arithmetic expressions.
l)        SB37 – Space issue (in create VSAM, recreate VSAM)
m)    SOC4E – Space Issue
n)      SOC1 - Misspelt DD Name / Read write unopened dataset.

Note – Many times for SOC7 is an un-initialized numeric item. Examine that possibility first, Examine Dump, they provide OFFSET of last instruction where abend occurs. Check in compilation output, XREF listing to get the VERB and the line no. of source code at this offset. Define datasets ‘SYSABOUT’ in JCL to capture runtime dumps. 

18.   Restore file from Tape to DASD
a)       IDCAMS (REPRO)
//INPUT DD DSN=FILE.ON.DASD
//OUTPUT DD DSN=FILE.ON.TAPE
//SYSIN DD*
REPRO INFILE(INPUT) OUTFILE(OUTPUT)  
b)      IEBGENER

19.   Copy ESDS file to KSDS
a)       REPRO         
INFILE(KSDS)  - OUTFILE(ESDS) -SKIP(100) -COUNT(100)           
b)      IEBGENER
Copy PS to PDS or vice versa
FROMKEY, TOKEY

20.   SDSF – JESJCL (Expanded JCL,PROC or Expandable step) / JESYSMSG (dataset related errors) / SYSOUT (consists of output msg which generated in JCL)  / JESMSGLG ( Time of submission system resources consumed, id job requires some dataset).


21.   SYSTEM Libraries – SYS1.LPALIIB (execution modules) / SYS1.PARMLIB (control parameter for Z/OS) / SYS1.PROCLIB (JCL Procedure) / SYS1.CMDLIB (Implement TSO commands).

22.   Run Selected Steps –
a)       Condition Codes – True (Step Skipped) / False (Step Executed)
Cond = (0,GT) – Always false / Cond=(0,LE) – Always True, Cond = EVEN / ONLY

b)      IEBEDIT –
//SYSIN DD*
   EDIT TYPE = INCLUDE, STEPNAME= (Step2,Step4)
/*

23.   JCL Dumps – Coded after EXEC statement, to check error when pgm abends.
SYSDUMP / SYSABEND / SYSMDUMP
//SYSDUMP DD SYSOUT=*

24.   Restart in IF-Else loop step
//Step01 EXEC PROC1
  IF MAXCC = 0
// Step02 EXEC PROC2
 ELSE
// Step03 EXEC PROC3

Ans – Restart = Step02 (Compiler ignore If- Else)
25.   REFERBACKS – Backward reference is used to copy information from a previous DD statement (within same Job). Also applied to pgm parameter on EXEC statement. Can be applied to 3 parameters (DSN / VOL /DCB).
Parameter = *.stepname.DDname
PGM = *.stepname.SYSLMOD
DSN = *.step010.DD1
Note – If points in same step than can omit stepname.

26.   Error Checking (OFFSET) – Compiler listing (SCLMTFS.LISTING.PGMNAME)
Then find the variable and check in C-DUMP there it will show the last record for that variable.
27.   Create a dataset in a JCL with same file organization as that of another dataset.
Ans – IEBGENER / Pass existing file in SYSUT1, new in SYSUT2 & mention DCB=*.SYSUT1

28.   PS &PDS (PDS – Folder, portioned dataset, each member can be read as sequential file / PS – Sequential file, contain PGM, JCL etc)
29.   Next (period) / Continue (Delimiter)
30.   Overriding a file ‘FILE1’ in JCL – in step02 of a PROC called in JCL.
//Step01 EXEC PROC1 à PROC1 //STEP02 EXEC PROC2   //INFILE DSN = “FILE1”.

31.   INPUT File
HCL TECHNOLOGIES !@#$
IBM MAINFRAMES %&A*

OUTPUT
TECHNOLOGIES
MAINFARMES

ANS – a) By using SORT b) By using COBOL Pgm c) By using SELCOPY

32.   INPUT File
MAINFRAME
JAVA
QC
SQL

OUTPUT File
MAINFRAM  IBM
JAVA              TCS
QC                    HP
SQL                  ORACLE
ANS – a) By using SORT b) By using COBOL Pgm

33.   There are 3 duplicates records in a file. How to remove 2 duplicates records and copy only one using JOB control language?
Ans – SORT the PS using JCL utility & update the PS file. Find the duplicates using XSUM. Write the duplicates alone in a separate PS. Take the separate PS and give the control condition inside SYSIN DD* as, sort fields with SKIPREC (3), since only 3rd one is needed to copy.
34.   //INFILE DD DSN=&&TEMP  ß Created during JOB & deleted at end of JOB.
35.   How do you restart a program from step 2?
Ans – RESTART from Step 2 / IEBEDIT
36.   If file is empty & open in Input mode or output mode. What will happen?
Ans:  VSAM file open in INPUT à -160 Error / Output – Unavailable
37.   How to include bind in JCL?





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.
DISPLAY – 1 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 PROCEDURE – SQL 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.