Professional Documents
Culture Documents
---
* Non Numeric Literal - ex. "123", "HELLO" max length is 256 characters
* " is converted to ' when " is written as delimiter - ex. 'THIS ISN"T WRONG' is
converted to THIS ISN'T WRONG
---
---
---
---
* Comments in COBOL
using * in column 7
using / in column 7
using *> in any column (for COBOL 5.1 and above only)
---
IDENTIFICATION DIVISION.
PROGRAM-ID. MYPROG.
AUTHOR. SHYLENDRA.
DATE-WRITTEN. 22-SEP-2021.
DATE-COMPILED. 22-SEP-2021.
---
ENVIRONMENT DIVISION.
CONFIGURATION SECTION. (only coded in main program and not in nested program)
SOURCE-COMPUTER. IBM1. [WITH DEBUGGING MODE - used when debug lines added in
program - debug lines are those having 'D' in column 7]
OBJECT-COMPUTER. IBM1.
---
DATA DIVISION.
FILE SECTION.
FD[SD] FILE1 [IS GLOBAL/ IS EXTERNAL]
RECORD CONTAINS 80 CHARACTERS
BLOCK CONTAINS 800 CHARCATERS [RECORDS]
RECORDING MODE IS F
DATA RECORD IS FILE1-REC.
01 FILE1-REC PIC X(80).
WORKING-STORAGE SECTION.
01 WS-GROUP.
05 WS-VAR-A PIC X(10) VALUE SPACES.
05 WS-VAR-B PIC 9(10) VALUE ZEROES.
LOCAL-STORAGE SETION.
01 LS-GROUP.
05 LS-VAR-A PIC X(10) VALUE SPACES.
05 LS-VAR-B PIC 9(10) VALUE ZEROES.
LINKAGE SECTION.
[ (declaration for called pgm ; Data items must be
declared in level 01/77, max length allowed is 64K)
01 LN-NUM-A PIC 9(05).
01 LN-NUM-B PIC 9(05).
01 LN-RESULT PIC 9(10).
]
[ (declaration to receive data from JCL PARM ; max
length allowed is 100 bytes)
01 LN-DATA.
05 LN-LENGTH PIC S9(4) COMP.
05 LN-PARM PIC X(10).
]
---
---
* If 01 WS-GROUP-VAR.
02 WS-GRP.
05 WS-VAR1 PIC X(01) VALUE 'Y'.
05 WS-VAR2 PIC X(01) VALUE 'N'.
66 WS-GRP-2 RENAMES WS-VAR1 THRU WS-VAR2.
01 WS-IND-VAR PIC X(01) VALUE 'N'.
* This is valid
01 WS-GRP1.
05 WS-VAR1 PIC X(05).
01 WS-GRP-BACKUP.
05 WS-VAR1 PIC X(05). - Duplicate WS-VAR1 but under different group
variaable
They can be refered like below - WS-VAR1 of WS-GRP1 ; WS-VAR1 of WS-GRP-
BACKUP
---
---
* REDEFINES Clause used to store different data items in same storage area
(Technically address of starting byte will be same).
* Ex. 01 WS-VAR-A PIC X(20) VALUE SPACES.
01 WS-VAR-B REDEFINES WS-VAR-A PIC 9(8).
01 WS-VAR-C REDEFINES WS-VAR-A PIC X(23).
---
---
* OCCURES can not be given to 01 LEVEL. Below ex. for 60 students studying 6
subjects.
* Ex. 01 WS-STUDENT.
02 WS-NAME PIC X(35) OCCURES 60 TIMES.
05 WS-MARKS PIC 9(03) OCCURES 06 TIMES.
DISPLAY WS-MARKS(1,1) will access 1st instance of WS-MARKS in 1st instance of
WS-NAME; here (1, 1) is (idx of WS-NAME, idx of WS-MARKS)
* 6 nested level OCCURES and one outermost OCCURES clause allowed.
* SUBSCRIPT need to be declared sperately in working storage where as INDEX can
just be mentioned in OCCURES class
* Move can be used to initialize and increment SUBSCRIPT, but we need to use SET if
it is INDEX.
---
* USAGE clause specifies how data is stored in memory, and is used to reduce
storage space and increase efficiency of program.
* USAGE can be specied for al levels exccept 66 and 88.
* USAGE DISPLAY is default and applicable to all data items. Data stored in CHAR
form (1char/1digit = 1 byte)
* USAGE COMP/BINARY applicable to only numeric. 9 to 9(4) = 2 bytes half word ,
9(5) to 9(9) = 4 bytes word , 9(10) to 9(18) = 8 bytesdouble word
* USAGE COMP-1 for single precision floating point number. 4 bytes length (sign in
left most nibble).
* USAGE COMP-2 for double precision floating point number. 8 bytes length (sign in
left most nibble).
* USAGE COMP-3/PACKED DECIMAL for internal decimal items. n digits = (n+1)/2 byte
(sign stored in right most nibble)
---
* JUST clause not applicable for numeric. JUST can be used to right justify
alpanumeric values while displaying
* JUST can be appplied only at elementary level.
* data in VALUE clause not affected by JUST.
* WS-VAR1 PIC X(10) JUST [JUSTIFIED] RIGHT.
---
---------------
---------------
---
---
---------------
---------------
---
* EXIT PROGRAM only for called program and STOP RUN is only for main program.
* EXIT PROGRAM gives control back to calling program and STOP RUN gives control
back to OS.
* GOBACK based on where it is coded gives control back to either OS or to calling
program.
---
* INITIALIZE sets the data item to predefined values based on data type. FILLERS
are not affected by INITIALIZE.
---
* INSPECT WS-DATA TALLYING WS-CNT FOR ALL 'A' BEFORE INITIAL 'B' (similarly FOR
LEADING SPACES)
* INSPECT WS-DATA REPLACING ALL '-' BY '~' BEFORE INITIAL 'B'
* INSPECT WS-DATA TALLYING WS-CNT FOR ALL 'A' BEFORE INITIAL 'B' REPLACING ALL
'A' BY '*' BEFORE INITIAL 'B'
* INSPECT WS-DATA REPLACING 'ABC' BY '123' - Will replace string 'ABC' by '123'
* INSPECT WS-DATA CONVERTING 'ABC' TO '123' - Will A by 1, B by 2 and C by
3.
---
* NEXT SENTENCE will transfers the control to next cobol SENTENCE after the PERIOD.
* CONTINUE on the other hand will tranfer control to next STATEMENT.
---
---
---
* INCLUDE statement is used to insert a piece of cobol code (or DB2 stored
procedures) into source program.
* INCLUDE is also used to include DCLGENs
---
---
* PERFORM BUILD-PARA
THRU BUILD-PARA-EXIT
WITH TEST BEFORE UNTIL I > 5
END-PERFORM
---
* ADD ex.
ADD A B TO C D [ROUNDED] (C=A+B+C and D=A+B+D)
ADD A B C TO D GIVING E [ROUNDED] (E=A+B+C+D)
ADD CORR WS-GROUP1 TO WS-GROUP2 [ROUNDED] (Adds elementary item in
GROUP1 to corr elementary item in GROUP2, store value in GROUP2) - CORR is only for
+ and - and MOVE
* SUBTRACT ex.
SUBTRACT A B FROM C D [ROUNDED] (C=C-(A+B) and D=D-(A+B))
SUBTRACT A B C FROM D GIVING E [ROUNDED] (D=D-(A+B+C))
SUBTRACT CORR WS-GROUP1 FROM WS-GROUP2 [ROUNDED] (Subtract elementary item in
GROUP1 to corr elementary item in GROUP2, store value in GROUP2)
* MULTIPLY ex.
MULTIPLY A BY B C [ROUNDED] (B=A*B and C=A*C)
MULTIPLY A BY B GIVING E [ROUNDED] (E=A*B)
* DEVIDE ex.
DIVIDE A INTO B [ROUNDED] (B=B/A)
DIVIDE A BY B GIVING C REMAINDER R [ROUNDED] (C=A/B)
---
* File handling life cycle = Declare a File > Open a File > Read a File > Write to
a File > Close a File
---
PROCEDURE DIVISION.
MOVE 'ABCDEFGHIJKLMNOPQR' TO WS-TABLE.
SET I TO 1.
SEARCH WS-A
AT END DISPLAY 'M NOT FOUND IN TABLE'
NOT AT END
WHEN WS-A(I) = WS-SRCH
DISPLAY 'LETTER M FOUND IN TABLE'
END-SEARCH.
* SEARCH ALL - Binary Search; index needs no initialization; not used in multi
dimentional array; table need to be sorted; single WHEN condition allowed
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WS-TABLE.
05 WS-RECORD OCCURS 10 TIMES ASCENDING KEY IS WS-NUM INDEXED BY I.
10 WS-NUM PIC 9(2).
10 WS-NAME PIC A(3).
PROCEDURE DIVISION.
MOVE '12ABC56DEF34GHI78JKL93MNO11PQR' TO WS-TABLE.
---
ENVIRONMENT DIVISION.
INPUT-OUTPUT SECTION.
FILE-CONTROL.
SELECT INPUT ASSIGN TO IN.
SELECT INPUT2 ASSIGN TO IN2.
SELECT OUTPUT ASSIGN TO OUT.
SELECT WORK ASSIGN TO WRK.
DATA DIVISION.
FILE SECTION.
FD INPUT.
01 INPUT-STUDENT.
05 STUDENT-ID-I PIC 9(5).
05 STUDENT-NAME-I PIC A(25).
FD INPUT2.
01 INPUT2-STUDENT.
05 STUDENT-ID-I2 PIC 9(5).
05 STUDENT-NAME-I2 PIC A(25).
FD OUTPUT.
01 OUTPUT-STUDENT.
05 STUDENT-ID-O PIC 9(5).
05 STUDENT-NAME-O PIC A(25).
SD WORK.
01 WORK-STUDENT.
05 STUDENT-ID-W PIC 9(5).
05 STUDENT-NAME-W PIC A(25).
PROCEDURE DIVISION.
---
00 - Successful
10 - End of file
35 - Try to open OPEN but file not present
39 - File attribute mismatch
33 - All files in concatination are not having same specifications
04 - Invalid fixed length record
41 - Tried to OPEN which is already OPEN
42 - Tried to CLOSE which is not OPEN
47,48,49 - Read/Write/ReWrite performed on file not oppened in proper input mode
-----------------------------------------------------------------------------------
--------------------
-----------------------------------------------------------------------------------
--------------------
ACCENTURE history -
Irish based company, headquarters in Dublin, Ireland. Founded by Arthur Andersen.
Employed about 5L+ employees.
CEO JULIE SWEET.
LET THERE BE CHANGE.
Latest VERSIONS -
JCL V1
Enterprise COBOL V5 R2
DB2 V11
CICS/MVS V2 R2
DFSORT V2 R2
COBOL Questions -
1. 4 Sections in Data Division -
File Section(describe externally stored data) ,
Working Storage Section(describe internal data),
Local Storage Section(describe inernal data that is pre-invocation details)
and
Linkage Section(describe data made available by anathor PGM)
2. Difference b/w INCLUDE and COPY
INCLUDE is used for expanding at pre-compiler time and COPY is used for
expanding at compiler time
3. FOREIGN KEYs are attributes of a particular table that have matching entries to
the primary key in another table. Foreign keys are used to build a relation between
any two tables. When two tables related using foreign keys then they are called
DELTE-CONNECTED TABLES, as when primary key deleted will affect foreign key.
4. REFERENTIAL INTEGRITY rule states that consistency needs to be maintained
between primary and foreign keys. In other words, each foreign key needs to have a
primary key.
5. SELF-REFRAINING CONSTRAINT is used to restrict the changes that can be made to
the primary key through a foreign key. To implement this, the foreign key must
define the DELETE CASCADE rule.
6. DEADLOCK in DB2 - When two separate processes are fighting for the same
resources, or the resource reserved for each other, the situation is called a
deadlock. SQL code for a deadlock are -911 and -913.
7. Program abends while processing 30th reccord, how to restart it from 31st
record?
Keep a new file and update counter for every record read
When program abends fetch last counter from above file
Skip those number of records or just perform read
Start processing from next record
8. Error handling in COBOL -
While string and unstring - ON OVERFLOW
While doing Add, Subtract - ON SIZE ERROR
I/P O/P operations on file - know EOF by using AT END, Use file status, use
INVALID KEY
9. SOC4
Description - Protection Exception
Reason -
1. Missing DD statement (Identify using file status in SYSOUT, it will
be 35)
2. File attribute mismatch between DD statement and COBOL (Identify
using file status in SYSOUT, it will be 39)
3. Tried to refer the file record before OPEN statement
4. Missmatch in parameter between calling and called program
5. Index or Subscript is out of range
Analysis -
1. We use ABEND-AID to analyse and solve this
Know which statement casuing error?
Tracing variabeles of the data source
2. Open ABEND-AID and the recent job abend
It will directly show you which statement and para the error is
3. Go to grogram and trace back the source variables in that statement
How to solve -
1. Corrrect the data and re-run - ask SME or data owner for correcting
the data
2. remove the bad record and re-run - copy the original data in a
backup dataset and change the file and re-run
SOC7
Description - Data Exception
Reason -
1. Passing non numeric data into COMP field
2. Performing numeric operations on fields declared as numeric but data
is non numeric
Analysis -
1. We use ABEND-AID to analyse and solve this
Know which statement casuing error?
Tracing variabeles of the data source
2. Open ABEND-AID and the recent job abend
It will directly show you which statement and para the error is
3. Go to grogram and trace back the source variables in that statement
How to solve -
1. Corrrect the data and re-run - ask SME or data owner for correcting
the data
2. remove the bad record and re-run - copy the original data in a
backup dataset and change the file and re-run
IF THERE IS NO TOLL THEN -
1. Try recreating the abened in TEST
2. Add display statements
3. Give O/P DISP=(NEW,CATLG,CATLG) so that when abended o/p file can be
checked for last processed rec
-----------------------------------------------------------------------------------
--------------------
-----------------------------------------------------------------------------------
--------------------
DB2
12. Which utility is used to load data from file into DB2?
-----------------------------------------------------------------------------------
--------------------
-----------------------------------------------------------------------------------
--------------------
CICS
18. Difference between EXEC CICS XCTL and EXEC CICS START and EXEC CICS LINK?
XCTL will pass the control to another application having same transaction ID
- continue the task in same terminal
START will initiate new transaction - create new terminal
LINK will pass the control to an application program in lower logical level
and expects control back
-----------------------------------------------------------------------------------
--------------------
-----------------------------------------------------------------------------------
--------------------
-------
-------
To reset values of variables in called program (from first call) for second call -
Its sufficient if while compiling link edit option 'RENT' is used.
But if 'REUS' is used then either called program should be coded with 'IS
INITIAL' in PROGRAM_ID or CANCEL issued after first call.
To retain values of variables in called program (from first call) for second call -
If compiled as DYNAM:
CALL 'literal' is a dynamic call
CALL WS-identifier is a dynamic call