1. What kind of status code is expected when you are doing GN Calls?
GE - When you are retrieving all the segments within a parent segment using a GN call, and there are no more child segments then GE status code is returned.
GB - When there are no more segments and end of database is reached, then GB is returned
Oct 11, 2010
Mar 22, 2010
Subprograms
1. How do you call subprograms in COBOL?
Subprograms are called using CALL statement. If Program A calls program B and pass parameters x,y
then Call statement can be written in program A as
CALL B USING X,Y.
Similarly in Prog B, we should have procedure division as
PRODCEDURE DIVISION USING X,Y.
2. What is difference between static call and dynamic call?
STATIC Call:
1) Identified by Call literal.
Ex: CALL ‘PGM1’.
2) Default Compiler option is NODYNAM and so all the literal calls are considered as static calls
3) If the subprogram undergoes change, sub program and main program need to be recompiled
4) Sub modules are link edited with main module.
5) Size of load module will be large
6) Fast,Less flexible.
7) Sub-program will not be in initial stage the next time it is called unless you explicitly use INITIAL or you do a CANCEL after each call.
DYNAMIC CALL
1) Identified by Call variable and the variable should be populated at run time.
01 WS-PGM PIC X(08).
Move ‘PGM1’ to WS-PGM
CALL WS-PGM
2) If you want convert the literal calls into DYNAMIC, the program should be compiled with DYNAM option.
By default, call variables and any un-resolved calls are considered as dynamic
3) If the subprogram undergoes change, recompilation of subprogram is enough.
4) Sub modules are picked up during run time from the load library.
5) Size of load module will be less.
6) Slow compared to Static call.
More flexible.
7) Program will be in initial state every time it is called.
Please note difference between call identifier and call literal.
CALL identifier, where identifier is a data item that contains the name of a nonnested subprogram when the program is run, always results in the target subprogram being loaded when it is called. Also, the name of the shared library must match the name of the target entry point.
CALL literal, where literal is the explicit name of a nonnested subprogram being called, can be resolved statically or dynamically. If the NODYNAM compiler option is in effect, either static or dynamic linking can be done. If DYNAM is in effect, CALL literal is resolved in the same way as CALL identifier: the target subprogram is loaded when it is called, and the name of the shared library must match the name of the target entry point.
These call definitions apply only in the case of a COBOL program calling a nonnested program. When a COBOL program calls a nested program, the CALL is resolved by the compiler without any system intervention.
Your COBOL programs can call a subprogram that is linked into the same executable module as the caller (static linking) or that is provided in a shared library (dynamic linking). COBOL for AIX also provides for run-time resolution of the target subprogram from a shared library.
If you link the target program statically, it is part of the executable module of the caller and is loaded with the caller. If you link it dynamically or resolve the call at run time, it is provided in a library and is loaded either when the caller is loaded or when it is called.
Static linking and dynamic linking are done for COBOL CALL literal subprograms only. Run-time resolution is always done for COBOL CALL identifier and is done for CALL literal when the DYNAM option is in effect.
3. How would you write static call?
Following example shows how static call can be written
Subprograms are called using CALL statement. If Program A calls program B and pass parameters x,y
then Call statement can be written in program A as
CALL B USING X,Y.
Similarly in Prog B, we should have procedure division as
PRODCEDURE DIVISION USING X,Y.
2. What is difference between static call and dynamic call?
STATIC Call:
1) Identified by Call literal.
Ex: CALL ‘PGM1’.
2) Default Compiler option is NODYNAM and so all the literal calls are considered as static calls
3) If the subprogram undergoes change, sub program and main program need to be recompiled
4) Sub modules are link edited with main module.
5) Size of load module will be large
6) Fast,Less flexible.
7) Sub-program will not be in initial stage the next time it is called unless you explicitly use INITIAL or you do a CANCEL after each call.
DYNAMIC CALL
1) Identified by Call variable and the variable should be populated at run time.
01 WS-PGM PIC X(08).
Move ‘PGM1’ to WS-PGM
CALL WS-PGM
2) If you want convert the literal calls into DYNAMIC, the program should be compiled with DYNAM option.
By default, call variables and any un-resolved calls are considered as dynamic
3) If the subprogram undergoes change, recompilation of subprogram is enough.
4) Sub modules are picked up during run time from the load library.
5) Size of load module will be less.
6) Slow compared to Static call.
More flexible.
7) Program will be in initial state every time it is called.
Please note difference between call identifier and call literal.
CALL identifier, where identifier is a data item that contains the name of a nonnested subprogram when the program is run, always results in the target subprogram being loaded when it is called. Also, the name of the shared library must match the name of the target entry point.
CALL literal, where literal is the explicit name of a nonnested subprogram being called, can be resolved statically or dynamically. If the NODYNAM compiler option is in effect, either static or dynamic linking can be done. If DYNAM is in effect, CALL literal is resolved in the same way as CALL identifier: the target subprogram is loaded when it is called, and the name of the shared library must match the name of the target entry point.
These call definitions apply only in the case of a COBOL program calling a nonnested program. When a COBOL program calls a nested program, the CALL is resolved by the compiler without any system intervention.
Your COBOL programs can call a subprogram that is linked into the same executable module as the caller (static linking) or that is provided in a shared library (dynamic linking). COBOL for AIX also provides for run-time resolution of the target subprogram from a shared library.
If you link the target program statically, it is part of the executable module of the caller and is loaded with the caller. If you link it dynamically or resolve the call at run time, it is provided in a library and is loaded either when the caller is loaded or when it is called.
Static linking and dynamic linking are done for COBOL CALL literal subprograms only. Run-time resolution is always done for COBOL CALL identifier and is done for CALL literal when the DYNAM option is in effect.
3. How would you write static call?
Following example shows how static call can be written
PROCESS NODYNAM NODLL
IDENTIFICATION DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 RECORD-2 PIC X. (6)
01 RECORD-1. (2)
05 PAY PICTURE S9(5)V99.
05 HOURLY-RATE PICTURE S9V99.
05 HOURS PICTURE S99V9.
. . .
PROCEDURE DIVISION.
CALL "SUBPROG" USING RECORD-1. (1)
CALL "PAYMASTR" USING RECORD-1 RECORD-2. (5)
STOP RUN.
For calling subprogram SUBPROG, CALL literal is used. Moreover program needs to be compile with NODYNAM OPTION.
Also program needs to be statically link edited like below and link card should INCLUDE subprogm also in link editing. this will cause, subprogram to be link edited in the main program itself.
For calling subprogram SUBPROG, CALL literal is used. Moreover program needs to be compile with NODYNAM OPTION.
Also program needs to be statically link edited like below and link card should INCLUDE subprogm also in link editing. this will cause, subprogram to be link edited in the main program itself.
IMS
1. What is difference between PSB and DBD? Which one is required for an IMS program?
The data base description block contains macros that specify the name of the data base description, the storage and access methods used for the data base, the physical or logical structure of the data base, and the names of key or search fields.
The program specification block contains the program communication block. It also contains macros that specify the program's logical view of the database, the processing options for segments within the data bases accessed, and the programming language(s) that can use the program specification block. Another major function of the program specification block is security. It decides which data bases can be accessed, as well as how each segment within the database can be processed.
And both PSB and DBD are required for an IMS application program.
2. How IMS identifies, which database to access in JCL for an application program?
When IMS program gets executed, Program Name and PSB name is provided as parameters into EXEC step of DFSRRC00 like below.
//G EXEC PGM=DFSRRC00,REGION=&RGN, PARM=(DLI,&MBR,&PSB,&BUF,&SPIE&TEST&EXCPVR&RST,&PRLD,&SRCH,&CKPTID,&MON,&LOGA,&FMTO,
&IMSID,&SWAP,&DBRC,&IRLM,&IRLMNM,&BKO,&IOB,&SSM,'&APARM',&LOCKMAX,&GSGNAME,&TMINAME)
Also PSBLIB and DBDLIB is provided for IMS DD name
//IMS DD DSN=dbdlib,DISP=SHR
// DD DSN=psblib,DISP=SHR
PSB contains PCB, one PCB for each database. For examplePCB2.
PCB TYPE=DB,NAME=DPSPERSP ………
SENSEG NAME=PSEMPLRR,PARENT=0,PROCOPT=G PCB1
SENSEG NAME=PSDEPMTR,PARENT=PSEMPLRR,PROCOPT=GI
PCB TYPE=DB,NAME=DPSPAYRP……….
SENSEG NAME=PSEMPLYR,PARENT=0,PROCOPT=G
SENSEG NAME=PSPAYCKR,PARENT=PSEMPLYR,PROCOPT=K PCB2
These PCBs needs to be listed in application program in LINKAGE section in same order and also must be specified in USING in same order. Lets say these PCB masks are PCB1 and
Now if program wants to update DPSPERSP, it should use PCB1 to update the same. from DDNAME , it will get DBD to access.Then it searches DPSPAYRP dbd in DBDLIB.
DBDlib example:
DBD NAME=DPSPAYRP, ACCESS= (HISAM, VSAM)
DATASET DD1= FPSPAYRP, OVFLW = FPSPAYRO
SEGM NAME= PSEMPLYR, PARENT =0, BYTES =50
FIELD NAME = (EMPLYCOD, SEQ), BYTES =9, X
START = 1, TYPE =C
SEGM NAME = PSPAYCKR, PARENT = PSEMPLYR, BYTES =50
FIELD NAME = (PAYDATE, SEQ), BYTES =6, X
START =1, TYPE =C
FIELD NAME =PAYAMT , BYTES =4,START =7, TYPE =P
From DBDLIB it gets the DDNAME of dataset in JCL, which needs to be accessed/updated.In this case, FPSPAYRP ddname in JCL will be accessed.
3. What is difference between Basic and symbolic checkpoint?
Basic Checkpointing:
All programs can use the Basic method, it is the only checkpoint method available to MPP?S, or online programs. The application program must provide its own method of restarting, because the extended restart call is not supported. Neither OS/VS nor GSAM files are supported with the Basic checkpoint method. It is your responsibility to provide an 8-character checkpoint ID and to increment it as processing dictates. A message is sent to the master console, as well as to the JES log, with the checkpoint ID and a date and time stamp. You will need this information, if a checkpoint restart becomes necessary. A major disadvantage of the Basic checkpoint method is that you cannot change anything in your program prior to restarting.
Thus, it can be used in DL/I, BMP and MPP program. IMS resources are released. Database changes are permanent. Programmer must provide restart logic to restore variables and database position.
Symbolic Checkpointing:
Only BMP and batch programs can use this method. Up to seven I/O areas can be saved with Symbolic checkpointing. Symbolic checkpointing uses the extended restart call. For information to be saved during execution, and then later restored upon restarting, the variables will be saved in the log file every time a checkpoint call is issued. Then, when the program is restarted with the extended restart (XRST) call, the variables will be restored from the log file created during the first execution.If a restart was requested, the XRST call automatically restores all of the variables you declared in the checkpoint area. It also restores the position in all data bases and GSAM files at the current position when that checkpoint was taken. (IMS does this by issuing internal GU calls).
The data base description block contains macros that specify the name of the data base description, the storage and access methods used for the data base, the physical or logical structure of the data base, and the names of key or search fields.
The program specification block contains the program communication block. It also contains macros that specify the program's logical view of the database, the processing options for segments within the data bases accessed, and the programming language(s) that can use the program specification block. Another major function of the program specification block is security. It decides which data bases can be accessed, as well as how each segment within the database can be processed.
And both PSB and DBD are required for an IMS application program.
2. How IMS identifies, which database to access in JCL for an application program?
When IMS program gets executed, Program Name and PSB name is provided as parameters into EXEC step of DFSRRC00 like below.
//G EXEC PGM=DFSRRC00,REGION=&RGN, PARM=(DLI,&MBR,&PSB,&BUF,&SPIE&TEST&EXCPVR&RST,&PRLD,&SRCH,&CKPTID,&MON,&LOGA,&FMTO,
&IMSID,&SWAP,&DBRC,&IRLM,&IRLMNM,&BKO,&IOB,&SSM,'&APARM',&LOCKMAX,&GSGNAME,&TMINAME)
Also PSBLIB and DBDLIB is provided for IMS DD name
//IMS DD DSN=dbdlib,DISP=SHR
// DD DSN=psblib,DISP=SHR
PSB contains PCB, one PCB for each database. For examplePCB2.
PCB TYPE=DB,NAME=DPSPERSP ………
SENSEG NAME=PSEMPLRR,PARENT=0,PROCOPT=G PCB1
SENSEG NAME=PSDEPMTR,PARENT=PSEMPLRR,PROCOPT=GI
PCB TYPE=DB,NAME=DPSPAYRP……….
SENSEG NAME=PSEMPLYR,PARENT=0,PROCOPT=G
SENSEG NAME=PSPAYCKR,PARENT=PSEMPLYR,PROCOPT=K PCB2
These PCBs needs to be listed in application program in LINKAGE section in same order and also must be specified in USING in same order. Lets say these PCB masks are PCB1 and
Now if program wants to update DPSPERSP, it should use PCB1 to update the same. from DDNAME , it will get DBD to access.Then it searches DPSPAYRP dbd in DBDLIB.
DBDlib example:
DBD NAME=DPSPAYRP, ACCESS= (HISAM, VSAM)
DATASET DD1= FPSPAYRP, OVFLW = FPSPAYRO
SEGM NAME= PSEMPLYR, PARENT =0, BYTES =50
FIELD NAME = (EMPLYCOD, SEQ), BYTES =9, X
START = 1, TYPE =C
SEGM NAME = PSPAYCKR, PARENT = PSEMPLYR, BYTES =50
FIELD NAME = (PAYDATE, SEQ), BYTES =6, X
START =1, TYPE =C
FIELD NAME =PAYAMT , BYTES =4,START =7, TYPE =P
From DBDLIB it gets the DDNAME of dataset in JCL, which needs to be accessed/updated.In this case, FPSPAYRP ddname in JCL will be accessed.
3. What is difference between Basic and symbolic checkpoint?
Basic Checkpointing:
All programs can use the Basic method, it is the only checkpoint method available to MPP?S, or online programs. The application program must provide its own method of restarting, because the extended restart call is not supported. Neither OS/VS nor GSAM files are supported with the Basic checkpoint method. It is your responsibility to provide an 8-character checkpoint ID and to increment it as processing dictates. A message is sent to the master console, as well as to the JES log, with the checkpoint ID and a date and time stamp. You will need this information, if a checkpoint restart becomes necessary. A major disadvantage of the Basic checkpoint method is that you cannot change anything in your program prior to restarting.
Thus, it can be used in DL/I, BMP and MPP program. IMS resources are released. Database changes are permanent. Programmer must provide restart logic to restore variables and database position.
Symbolic Checkpointing:
Only BMP and batch programs can use this method. Up to seven I/O areas can be saved with Symbolic checkpointing. Symbolic checkpointing uses the extended restart call. For information to be saved during execution, and then later restored upon restarting, the variables will be saved in the log file every time a checkpoint call is issued. Then, when the program is restarted with the extended restart (XRST) call, the variables will be restored from the log file created during the first execution.If a restart was requested, the XRST call automatically restores all of the variables you declared in the checkpoint area. It also restores the position in all data bases and GSAM files at the current position when that checkpoint was taken. (IMS does this by issuing internal GU calls).
Mar 21, 2010
File Handling
1. Explain how files are handled in COBOL program?
Files must be declared in in INPUT-OUTPUT SECTION (In ENVOIRNMENT DIVISION) under FILE CONTROL.Logical file name is assgined using SELECT clause to file. Also organization (Whether indexed, sequential) and access mode (Seqential,random, dynamic) specified here.
Then in FILE SECTION of DATA DIVISION, FD file descriptor is specified for the file where record length , type of record (FB,VB) is specified along with record layout.
Then in prodcedure division file is opened as input,input-output,output mode.
records can be read using READ and can be written using WRITE/REWRITE statement.
Files can be closed using CLOSE statment in PROCEDURE DIVISION.
2. A MASTER-FILE has been opened in I-O mode.Following are the records in the file.
CAPGEMINI, PUNE
ACCENTURE,PUNE
INFOSYS,PUNE
COGNIZAT,PUNE.
And following COBOL statements are exected in procedure division.
READ MASTER-FILE
READ MASTER-FILE
MOVE 'WIPRO,PUNE' TO MASTER-REC
WRITE MASTER-FILE FROM MASTER-REC.
Then what will be the contents of the file?
Since MASTER-FILE has been opened in I-O mode and WRITE statement is trying to write in the same file, we will get invalid file status and no WRITE operations will be performed.
Files which are delcared as I-O, only REWRITE statment can write the records.
Hence contenets of the file will be same.
3. A MASTER-FILE has been opened in I-O mode.Following are the records in the file.
CAPGEMINI, PUNE
ACCENTURE,PUNE
INFOSYS,PUNE
COGNIZAT,PUNE.
And following COBOL statements are exected in procedure division.
READ MASTER-FILE
READ MASTER-FILE
MOVE 'WIPRO,PUNE' TO MASTER-REC
REWRITE MASTER-FILE FROM MASTER-REC.
REWRITE MASTER-FILE FROM MASTER-REC.
Then what will be the contents of the file?
After execution of above statements of contents of the file will be
CAPGEMINI, PUNE
WIPRO,PUNE
INFOSYS,PUNE
COGNIZAT,PUNE.
File has been opened in input output mode. And first two records are read. After that pointer now points to the second record in the file.
Now if REWRITE operation is performed, pointer will point to the second record and second record will be overwritten. After rewrite, pointer will still point to the second record in the file and same record will be overwritten.
4. Program A has opened a file in output mode. Program A calls Program B. Since file has already opened in Program A, can program B direcly write into that file?
If program B has to write into the files, it cannot directly write into the file.
In both Programs Prog A and Prog B, file should be defined as external in FD. Also in both the programs, file should be defined in FILE CONTROL using SELECT clause.
PROG A opens a file and calls prog B. Since file is already opened in PROG A, no open statement required in PROG B.
And Then Prog B can write into the file.
5. If records needs to be deleted from a ps file, Which one of the following verbs can be used?
DELETE
ERASE
None of the above verbs can be used to delete the record from the PS file.
6. Can 88 levels be defined in 01 level under FD?88 Levels can be defined under 01 - file layout under FD.
7. In a physically sequential file, after reading 100 records , if again first records needs to be read, then which one of the following needs to be done?
A.Address of the first record from a file needs to be stored into pointer using ADDRESS OF keyword.
After reading 100 records, point to the address stored into pointer using SET verb.
In this way records can be read from the start again.
B. Close the file, OPEN it again and read it from the start.
COBOL does not support address handling for the files. so first option is not possible.
Second option is easy. Since it is sequential file and records need to be read sequentially, closing the file, oepning it and reading the records from the start is the only option available.
8. Can COPY statement is used to copy all the content of one file to another file?
COPY statement cannot be used for file handling. If all the conetnts from one file needs to be copied to another file, the source file needs to be opened in INPUT mode and target file needs to be opened as OUTPUT.
Records from INPUT file needs to be read one by one and at a same time, those should be written in OUTPUT file.
9. If ORGANIZATION is defined as SEQUENTIAL and ACCESS MODE is defined as INDEXED in SELECT clasue, then the file must be one of these -> KSDS, RRDS,LDS,ESDS,PS?
If ORGANIZATION IS SEQUENTIAL then the ACCESS MODE must be SEQUENTIAL ONLY. And these properties are for PS file only.
For KSDS, ORGANIZATION should be INDEXED and access mode can be defined as SEQUENTIAL, RANDOM, DYNAMIC.
For ESDS, ORGANIZATION should be sequential and access mode can be defined as sequential.
for RRDS, ORGANIZATION should be relative and access mode can be defined as SEQUENTIAL, RANDOM, DYNAMIC.
10. If the records need to be written at the end of file, then how it can be done?
If the records needs to be added at the end of file, then files should be opened in EXTEND mode.
11. How will you define your record descriptions in the FILE SECTION if you want to use three different record descriptions for the same file?
FD filename
DATA RECORDS ARE rd01, rd02, rd03.
01 rd01 PIC X(n).
01 rd02 PIC X(n).
01 rd03 PIC X(n).
BACK TO COBOL
Files must be declared in in INPUT-OUTPUT SECTION (In ENVOIRNMENT DIVISION) under FILE CONTROL.Logical file name is assgined using SELECT clause to file. Also organization (Whether indexed, sequential) and access mode (Seqential,random, dynamic) specified here.
Then in FILE SECTION of DATA DIVISION, FD file descriptor is specified for the file where record length , type of record (FB,VB) is specified along with record layout.
Then in prodcedure division file is opened as input,input-output,output mode.
records can be read using READ and can be written using WRITE/REWRITE statement.
Files can be closed using CLOSE statment in PROCEDURE DIVISION.
2. A MASTER-FILE has been opened in I-O mode.Following are the records in the file.
CAPGEMINI, PUNE
ACCENTURE,PUNE
INFOSYS,PUNE
COGNIZAT,PUNE.
And following COBOL statements are exected in procedure division.
READ MASTER-FILE
READ MASTER-FILE
MOVE 'WIPRO,PUNE' TO MASTER-REC
WRITE MASTER-FILE FROM MASTER-REC.
Then what will be the contents of the file?
Since MASTER-FILE has been opened in I-O mode and WRITE statement is trying to write in the same file, we will get invalid file status and no WRITE operations will be performed.
Files which are delcared as I-O, only REWRITE statment can write the records.
Hence contenets of the file will be same.
3. A MASTER-FILE has been opened in I-O mode.Following are the records in the file.
CAPGEMINI, PUNE
ACCENTURE,PUNE
INFOSYS,PUNE
COGNIZAT,PUNE.
And following COBOL statements are exected in procedure division.
READ MASTER-FILE
READ MASTER-FILE
MOVE 'WIPRO,PUNE' TO MASTER-REC
REWRITE MASTER-FILE FROM MASTER-REC.
REWRITE MASTER-FILE FROM MASTER-REC.
Then what will be the contents of the file?
After execution of above statements of contents of the file will be
CAPGEMINI, PUNE
WIPRO,PUNE
INFOSYS,PUNE
COGNIZAT,PUNE.
File has been opened in input output mode. And first two records are read. After that pointer now points to the second record in the file.
Now if REWRITE operation is performed, pointer will point to the second record and second record will be overwritten. After rewrite, pointer will still point to the second record in the file and same record will be overwritten.
4. Program A has opened a file in output mode. Program A calls Program B. Since file has already opened in Program A, can program B direcly write into that file?
If program B has to write into the files, it cannot directly write into the file.
In both Programs Prog A and Prog B, file should be defined as external in FD. Also in both the programs, file should be defined in FILE CONTROL using SELECT clause.
PROG A opens a file and calls prog B. Since file is already opened in PROG A, no open statement required in PROG B.
And Then Prog B can write into the file.
5. If records needs to be deleted from a ps file, Which one of the following verbs can be used?
DELETE
ERASE
None of the above verbs can be used to delete the record from the PS file.
6. Can 88 levels be defined in 01 level under FD?88 Levels can be defined under 01 - file layout under FD.
7. In a physically sequential file, after reading 100 records , if again first records needs to be read, then which one of the following needs to be done?
A.Address of the first record from a file needs to be stored into pointer using ADDRESS OF keyword.
After reading 100 records, point to the address stored into pointer using SET verb.
In this way records can be read from the start again.
B. Close the file, OPEN it again and read it from the start.
COBOL does not support address handling for the files. so first option is not possible.
Second option is easy. Since it is sequential file and records need to be read sequentially, closing the file, oepning it and reading the records from the start is the only option available.
8. Can COPY statement is used to copy all the content of one file to another file?
COPY statement cannot be used for file handling. If all the conetnts from one file needs to be copied to another file, the source file needs to be opened in INPUT mode and target file needs to be opened as OUTPUT.
Records from INPUT file needs to be read one by one and at a same time, those should be written in OUTPUT file.
9. If ORGANIZATION is defined as SEQUENTIAL and ACCESS MODE is defined as INDEXED in SELECT clasue, then the file must be one of these -> KSDS, RRDS,LDS,ESDS,PS?
If ORGANIZATION IS SEQUENTIAL then the ACCESS MODE must be SEQUENTIAL ONLY. And these properties are for PS file only.
For KSDS, ORGANIZATION should be INDEXED and access mode can be defined as SEQUENTIAL, RANDOM, DYNAMIC.
For ESDS, ORGANIZATION should be sequential and access mode can be defined as sequential.
for RRDS, ORGANIZATION should be relative and access mode can be defined as SEQUENTIAL, RANDOM, DYNAMIC.
10. If the records need to be written at the end of file, then how it can be done?
If the records needs to be added at the end of file, then files should be opened in EXTEND mode.
11. How will you define your record descriptions in the FILE SECTION if you want to use three different record descriptions for the same file?
FD filename
DATA RECORDS ARE rd01, rd02, rd03.
01 rd01 PIC X(n).
01 rd02 PIC X(n).
01 rd03 PIC X(n).
BACK TO COBOL
Assembler - Basics
1. What is base register in assembler program?
When a program is loaded into memory, assembler stores the address of the starting point of the program into base register. The assembler doesn’t produce direct addresses but produces an address in the base displacement format. Addresses in this form consist of 4 hexadecimal digits or two bytes, BDDD, where B represents a base register and DDD represents a displacement.
Thus smallest displacement from base register that can be calculated is x’000’ = 0 and the largest displacement is x’FFF’ = 4096 bytes.
If the program has size of more than 4096 bytes, then one base register is not sufficient. We may have to define one/two more base register depending upon the size of the program
2. Assembler is difficult language to code. Since COBOL compilers can covert COBOL code into machine language, what is need of assembler?
COBOL is high level language. Due to limitations of the compilers, the machine code generated by COBOL is not always efficient. A good assembler program can write more efficient code with assembler.
This where efficiency matters such as online programs where response time required is minimum, assembler is the preferred language.
3. What is difference between CSECT and DSECT?
A DSECT or Dummy Section provides the programmer with the ability to describe the layout of an area of storage without reserving virtual storage for the area that is described. The DSECT layout can then be used to reference any area of storage which is addressable by the program. Think of the DSECT as a template, or pattern, which can be “dropped” on any area of storage. Once the DSECT is “positioned”, the symbolic names in the DSECT can be used to extract data from the underlying storage area
By definition, a control section (CSECT) is “a block of coding that can be relocated (independent of other coding) without altering the operating logic of the program”.For the modern programmer, a CSECT might be considered as an independentcode module or package. The match in terminology is not precise, but suggestive.
Very large assembly language programs will require more than one control section.In any case, the programs we write will require only one CSECT, even assuming the addressing constraints imposed by the old System/370 architecture.
A program with a single CSECT may be started in one of two ways. For example,
the program LAB01 may be started in one of two ways.
LAB01 START
LAB01 CSECT
The assembler allows for the specification of a load address in the START or CSECT.
This is probably a bad idea; it may be ignored by a modern operating system.
The last line in the CSECT must be END Name, such as END LAB01.
4. What is the functionality of LTORG statement?
The assembler instruction that directs the location of the literal pool is LTORG. It does not have any operands. If you do not use any LTORG instructions in your program, the literal pool is placed at the end of the first control section (CSECT) of your program.
When the assembler encounters a LTORG instruction within a program, it creates a literal pool at that point, containing all the literals specified since the last LTORG instruction, or since the beginning of the program, if this is the first LTORG
To avoid addressability problems in multi modular programs, you should code a LTORG instruction as the last instruction of each control section in the program. So, each CSECT will have its own literal pool at the end of the module.
MOD1 CSECT
LTORG
MOD2 CSECT
LTORG
MOD3 CSECT
LTORG
5. How base register is defined in an assembler program?
Base registers is defined as below
BALR R12,R0
USING *, R12
These statements are coded immediately below CSECT.
BALR instruction is RR type of instruction, which loads the address of the next instruction into operand 1 i.e. R12. Second operand is specified as R0 so no branch takes place.
USING establishes addressability. The * is used to represent the current location counter in the assembler program. The USING instruction tells assembler that R12 is to be used as the base register and that R12 will contain the address of the current instruction.
Since BALR has loaded R12 with the address of the instruction following BALR, this correctly Establishes address in the program.
6. How multiple base registers are defined in an assembler program?
Multiple Base registers are defined as below
BALR R12,R0
USING *, R12,R10,R11
BASE LM R10,R11,BASES
B MAIN
BASES DC A(BASE+4096)
DC A(BASE+8192)
MAIN MVC IN,OUT
In above example three base registers are defined i.e. R12,R10,R11.
R12 is loaded with the address of the instruction following USING. R10 is loaded with the address of R12+4096 and R11 is loaed with address of R12+8192.
7. How standard entry statements are coded into assembler program?
MAIN CSECT SUB CSECT
STM R14,R12,12(13) STM R14,R12,12(R13)
BASR R12,R0 BASR R12,R0
USING *,R12 USING *,R12
ST R13,SAVE+4 ST R13,SAVE+4
LA R13,SAVE LA R13,SAVE
... ...
LA R1,=A(X,Y,Z)
L R15,=V(SUB)
BASR R14,R15
In above scenario, MAIN is main program which calls subprogram SUB. Standard entry statements would be same in the both cases, since Main program also gets called by OS modules first.
Since we have very limited GPRS which should be shared between many programs, it is the programmers responsibilty to save the contenet of the register in the start of the program and restore the content of the registers back when exit.
To store the contents, SAVE is delcared as 18 fullword.First fullword is used by operating system. Second fullword stores address of the save area of the calling program.Third fullword contains address of save area of any called program from the current program.
Contents of registers 14,15,0,1,2,3,4,5,6,7,8,9,10,11,12 are stored in this fullword thereafter.
Register 13 contains address of the save area. Following is how standard entry statements are coded?
1. store the contents of the 14 to 12 into save area of the calling program at displacement of 12.( R13 points to save area of calling program)
2.Define base register and establish addressibility.
3.store the address of the save area of calling program (which is stored in R13) into SAVE+4. (SAVE is save area of the current program)
4. Then load address of the save area in the current program into R13.
8. How standard entry statements are coded into assembler program?
This is how standard exit statements are coded into any assembler program.
L R13,SAVE+4
LM R14,R12,12(R13)
LA R15,0
BR 14
1. Address of the save area into calling program is again restored in R13. This address is saved in save area of the current program (save+4)
2. Contents of the registers 14 to 12 are restored back.
3. Return code is set to 0 by LA R15,0
4. And branched to the R14, which store the address of the insturction to be executed in the calling program.
BACK TO ASSEMBLER
When a program is loaded into memory, assembler stores the address of the starting point of the program into base register. The assembler doesn’t produce direct addresses but produces an address in the base displacement format. Addresses in this form consist of 4 hexadecimal digits or two bytes, BDDD, where B represents a base register and DDD represents a displacement.
Thus smallest displacement from base register that can be calculated is x’000’ = 0 and the largest displacement is x’FFF’ = 4096 bytes.
If the program has size of more than 4096 bytes, then one base register is not sufficient. We may have to define one/two more base register depending upon the size of the program
2. Assembler is difficult language to code. Since COBOL compilers can covert COBOL code into machine language, what is need of assembler?
COBOL is high level language. Due to limitations of the compilers, the machine code generated by COBOL is not always efficient. A good assembler program can write more efficient code with assembler.
This where efficiency matters such as online programs where response time required is minimum, assembler is the preferred language.
3. What is difference between CSECT and DSECT?
A DSECT or Dummy Section provides the programmer with the ability to describe the layout of an area of storage without reserving virtual storage for the area that is described. The DSECT layout can then be used to reference any area of storage which is addressable by the program. Think of the DSECT as a template, or pattern, which can be “dropped” on any area of storage. Once the DSECT is “positioned”, the symbolic names in the DSECT can be used to extract data from the underlying storage area
By definition, a control section (CSECT) is “a block of coding that can be relocated (independent of other coding) without altering the operating logic of the program”.For the modern programmer, a CSECT might be considered as an independentcode module or package. The match in terminology is not precise, but suggestive.
Very large assembly language programs will require more than one control section.In any case, the programs we write will require only one CSECT, even assuming the addressing constraints imposed by the old System/370 architecture.
A program with a single CSECT may be started in one of two ways. For example,
the program LAB01 may be started in one of two ways.
LAB01 START
LAB01 CSECT
The assembler allows for the specification of a load address in the START or CSECT.
This is probably a bad idea; it may be ignored by a modern operating system.
The last line in the CSECT must be END Name, such as END LAB01.
4. What is the functionality of LTORG statement?
The assembler instruction that directs the location of the literal pool is LTORG. It does not have any operands. If you do not use any LTORG instructions in your program, the literal pool is placed at the end of the first control section (CSECT) of your program.
When the assembler encounters a LTORG instruction within a program, it creates a literal pool at that point, containing all the literals specified since the last LTORG instruction, or since the beginning of the program, if this is the first LTORG
To avoid addressability problems in multi modular programs, you should code a LTORG instruction as the last instruction of each control section in the program. So, each CSECT will have its own literal pool at the end of the module.
MOD1 CSECT
LTORG
MOD2 CSECT
LTORG
MOD3 CSECT
LTORG
5. How base register is defined in an assembler program?
Base registers is defined as below
BALR R12,R0
USING *, R12
These statements are coded immediately below CSECT.
BALR instruction is RR type of instruction, which loads the address of the next instruction into operand 1 i.e. R12. Second operand is specified as R0 so no branch takes place.
USING establishes addressability. The * is used to represent the current location counter in the assembler program. The USING instruction tells assembler that R12 is to be used as the base register and that R12 will contain the address of the current instruction.
Since BALR has loaded R12 with the address of the instruction following BALR, this correctly Establishes address in the program.
6. How multiple base registers are defined in an assembler program?
Multiple Base registers are defined as below
BALR R12,R0
USING *, R12,R10,R11
BASE LM R10,R11,BASES
B MAIN
BASES DC A(BASE+4096)
DC A(BASE+8192)
MAIN MVC IN,OUT
In above example three base registers are defined i.e. R12,R10,R11.
R12 is loaded with the address of the instruction following USING. R10 is loaded with the address of R12+4096 and R11 is loaed with address of R12+8192.
7. How standard entry statements are coded into assembler program?
MAIN CSECT SUB CSECT
STM R14,R12,12(13) STM R14,R12,12(R13)
BASR R12,R0 BASR R12,R0
USING *,R12 USING *,R12
ST R13,SAVE+4 ST R13,SAVE+4
LA R13,SAVE LA R13,SAVE
... ...
LA R1,=A(X,Y,Z)
L R15,=V(SUB)
BASR R14,R15
In above scenario, MAIN is main program which calls subprogram SUB. Standard entry statements would be same in the both cases, since Main program also gets called by OS modules first.
Since we have very limited GPRS which should be shared between many programs, it is the programmers responsibilty to save the contenet of the register in the start of the program and restore the content of the registers back when exit.
To store the contents, SAVE is delcared as 18 fullword.First fullword is used by operating system. Second fullword stores address of the save area of the calling program.Third fullword contains address of save area of any called program from the current program.
Contents of registers 14,15,0,1,2,3,4,5,6,7,8,9,10,11,12 are stored in this fullword thereafter.
Register 13 contains address of the save area. Following is how standard entry statements are coded?
1. store the contents of the 14 to 12 into save area of the calling program at displacement of 12.( R13 points to save area of calling program)
2.Define base register and establish addressibility.
3.store the address of the save area of calling program (which is stored in R13) into SAVE+4. (SAVE is save area of the current program)
4. Then load address of the save area in the current program into R13.
8. How standard entry statements are coded into assembler program?
This is how standard exit statements are coded into any assembler program.
L R13,SAVE+4
LM R14,R12,12(R13)
LA R15,0
BR 14
1. Address of the save area into calling program is again restored in R13. This address is saved in save area of the current program (save+4)
2. Contents of the registers 14 to 12 are restored back.
3. Return code is set to 0 by LA R15,0
4. And branched to the R14, which store the address of the insturction to be executed in the calling program.
BACK TO ASSEMBLER
Table Handling
1. Runs scored by 15 players into 25 matches needs to be stored into array. What kind of array is required to store the same - single or multidimensional? Define an array.
Array can be defined as
01 PLAYER-DATA.
05 PLAYER-NAME OCCURS 15 TIMES INDEXED BY PL-INDEX PIC X(25).
10 MATCH-RUNS OCCURS 25 TIMES INDEXED BY RUN-INDEX.
15 MATCH RUN PIC 9(3).
To store runs of 25 matches for 15 players, two dimensional array will be required. PLAYER-NAME stores name of player which occurs 15 times and it has been defined as X(25). Also for each player, MATCH-RUNS has been defind which occurs 25 times.
2. In above two dimensional array, if runs scored by SACHIN in each match needs to be displayed, how it can be done?
Using Search
Serial search can be used. First Player Name = "SACHIN" is found using PL-INDEX. Once it is found then using PL-INDEX, all the run scored by SACHIN can be found out.
SET PL-INDEX TO 1
SET RUN-INDEX TO 1
SEARCH PLAYER-DATA
WHEN PLAYER-NAME(PL-INDEX) = "SACHIN "
DISPLAY 'PLAYER FOUND'
AT END
PERFORM P100-EXIT
END-SEARCH
SET PL-INDEX DOWN BY 1.
PERFORM UNTIL RUN-INDEX < 25
DISPLAY PLAYER-NAME (PL-INDEX,RUN-INDEX)
END-PERFORM.
P1000-EXIT.
EXIT.
Using Perform loop
This task is quite easy using perform loop
SET PL-INDEX TO 1
SET RN-INDEX TO 1
PERFORM UNTIL END-OF-TABLE
IF PL-INDEX = 15
SET END-OF-TABLE TO TRUE
IF PLAYER-NAME(PL-INDEX) = "SACHIN "
PERFORM UNTIL RUN-INDEX < 25
DISPLAY PLAYER-NAME (PL-INDEX,RUN-INDEX)
END-PERFORM
SET END-OF-TABLE TO TRUE
END-IF
END-PERFORM
3. What is sequential search and Binary search ?
In Sequential search, table elements are searched sequentially using SEARCH verb. When table element is found, control comes out of search. If table element is not found, action defined at AT END verb is performed.
In Binary search, table must be ordered(sorted in ascending or descending) on the KEYS specified in the occurs clause.The test in when condition must be always equal condition(same is not true with Sequential search. In sequential search we can have unequal conditions in WHEN). Also we can have only one when condition in binary search (Whereas in sequential search, we can have mutilple when conditions)
In binary search data is search using SEARCH-ALL verb. Table will be devided into two parts and key will be tested. If the key to be searched lies in first part, then second part will be elliminated and search will continue in first part.Process will repeat until key is found or no specified key found in table.
If no specified key found, then action specified at AT END clause is performed.
4. Sequential search or Binary search - When to use what?
Serial search is used if table to be searched is relatively small. Binary search is more efficient if size of table to be searched in big.
Also for binary search, table needs to have key and data must be in sorted order on a key. If the data is not like this , then serial search is performed.
5. Can SEARCH and SEARCH ALL be used to find records in a sequential file?
SEARCH and SEARCH all cannot be used to find data in sequental file directly. They can be used with tables which are declared in the program in DATA division.
However, file records can be loaed into table and they can be searched.
6. What is difference between index and subscript ?
Index and subscript are used for refering a data element into table.
A subscript is a working storage data definition item, typically an interger PIC (999) where a value must be moved to the subscript and then incremented or decremented by ADD TO and SUBTRACT FROM statements. Subscript represents an occurence number of a table within a table.
An index is a register item that exists outside the program's working storage. You SET an index to a value and SET it UP BY value and DOWN BY value. An index is displacement from the start of table based upon length of table element.
index values can be changed by SET, PERFORM and SEARCH.
7. A table needs to be defined to store the names of students in the class. Maximum number of students in class can be 100. Table needs to be defined to store names of only those students who have taken admissions. Number of students who have taken admission can be retrieved from WS-ADM-COUNT. Define an table.
Table can be defined in following way
01. WS-ADM-COUNT PIC 9(2).
01. WS-STUDENTS.
05. WS-STUDENT-NAME OCCURS 1 TO 100 TIMES DEPENDING ON WS-ADM-COUNT
PIC X(25).
With above definition, WS-STUDENTS will be variable length table. Depending upon value in WS-ADM-COUNT, occurences of WS-STUDENT-NAME will be set.
if WS-ADM-COUNT has value 50, then above table will have data for 50 occurences or allocate data into storage for 50 occurences.
8. How to set an WS-INDEX to 25? How to set WS-INDEX to WS-INDEX-2
To set WS-INDEX to 25 -> SET WS-INDEX TO 25
To set WS-INDEX to WS-INDEX-2 -> SET WS-INDEX DOWN BY 2.
9. If 10 Dimension table needs to be defined in COBOL? Define any 10 dimensional table?
Tables upto 7 dimensions can be defined in COBOL
10. A two dimensional array has been defined in following way. What it does?
01. WS-TABLE OCCURS 10 TIMES PIC X(3).
05 WS-TABLE2 OCCURS 5 TIMES PIC X(5).
Above definition is wrong, since OCCURS clause cannot be specified at 01 level.If two dimensional array is required, above defintion can be modified as
01. WS-TABLE-GROUP.
05 WS-TABLE OCCURS 10 TIMES PIC X(3).
10 WS-TABLE2 OCCURS 5 TIMES PIC X(5).
BACK TO COBOL
Array can be defined as
01 PLAYER-DATA.
05 PLAYER-NAME OCCURS 15 TIMES INDEXED BY PL-INDEX PIC X(25).
10 MATCH-RUNS OCCURS 25 TIMES INDEXED BY RUN-INDEX.
15 MATCH RUN PIC 9(3).
To store runs of 25 matches for 15 players, two dimensional array will be required. PLAYER-NAME stores name of player which occurs 15 times and it has been defined as X(25). Also for each player, MATCH-RUNS has been defind which occurs 25 times.
2. In above two dimensional array, if runs scored by SACHIN in each match needs to be displayed, how it can be done?
Using Search
Serial search can be used. First Player Name = "SACHIN" is found using PL-INDEX. Once it is found then using PL-INDEX, all the run scored by SACHIN can be found out.
SET PL-INDEX TO 1
SET RUN-INDEX TO 1
SEARCH PLAYER-DATA
WHEN PLAYER-NAME(PL-INDEX) = "SACHIN "
DISPLAY 'PLAYER FOUND'
AT END
PERFORM P100-EXIT
END-SEARCH
SET PL-INDEX DOWN BY 1.
PERFORM UNTIL RUN-INDEX < 25
DISPLAY PLAYER-NAME (PL-INDEX,RUN-INDEX)
END-PERFORM.
P1000-EXIT.
EXIT.
Using Perform loop
This task is quite easy using perform loop
SET PL-INDEX TO 1
SET RN-INDEX TO 1
PERFORM UNTIL END-OF-TABLE
IF PL-INDEX = 15
SET END-OF-TABLE TO TRUE
IF PLAYER-NAME(PL-INDEX) = "SACHIN "
PERFORM UNTIL RUN-INDEX < 25
DISPLAY PLAYER-NAME (PL-INDEX,RUN-INDEX)
END-PERFORM
SET END-OF-TABLE TO TRUE
END-IF
END-PERFORM
3. What is sequential search and Binary search ?
In Sequential search, table elements are searched sequentially using SEARCH verb. When table element is found, control comes out of search. If table element is not found, action defined at AT END verb is performed.
In Binary search, table must be ordered(sorted in ascending or descending) on the KEYS specified in the occurs clause.The test in when condition must be always equal condition(same is not true with Sequential search. In sequential search we can have unequal conditions in WHEN). Also we can have only one when condition in binary search (Whereas in sequential search, we can have mutilple when conditions)
In binary search data is search using SEARCH-ALL verb. Table will be devided into two parts and key will be tested. If the key to be searched lies in first part, then second part will be elliminated and search will continue in first part.Process will repeat until key is found or no specified key found in table.
If no specified key found, then action specified at AT END clause is performed.
4. Sequential search or Binary search - When to use what?
Serial search is used if table to be searched is relatively small. Binary search is more efficient if size of table to be searched in big.
Also for binary search, table needs to have key and data must be in sorted order on a key. If the data is not like this , then serial search is performed.
5. Can SEARCH and SEARCH ALL be used to find records in a sequential file?
SEARCH and SEARCH all cannot be used to find data in sequental file directly. They can be used with tables which are declared in the program in DATA division.
However, file records can be loaed into table and they can be searched.
6. What is difference between index and subscript ?
Index and subscript are used for refering a data element into table.
A subscript is a working storage data definition item, typically an interger PIC (999) where a value must be moved to the subscript and then incremented or decremented by ADD TO and SUBTRACT FROM statements. Subscript represents an occurence number of a table within a table.
An index is a register item that exists outside the program's working storage. You SET an index to a value and SET it UP BY value and DOWN BY value. An index is displacement from the start of table based upon length of table element.
index values can be changed by SET, PERFORM and SEARCH.
7. A table needs to be defined to store the names of students in the class. Maximum number of students in class can be 100. Table needs to be defined to store names of only those students who have taken admissions. Number of students who have taken admission can be retrieved from WS-ADM-COUNT. Define an table.
Table can be defined in following way
01. WS-ADM-COUNT PIC 9(2).
01. WS-STUDENTS.
05. WS-STUDENT-NAME OCCURS 1 TO 100 TIMES DEPENDING ON WS-ADM-COUNT
PIC X(25).
With above definition, WS-STUDENTS will be variable length table. Depending upon value in WS-ADM-COUNT, occurences of WS-STUDENT-NAME will be set.
if WS-ADM-COUNT has value 50, then above table will have data for 50 occurences or allocate data into storage for 50 occurences.
8. How to set an WS-INDEX to 25? How to set WS-INDEX to WS-INDEX-2
To set WS-INDEX to 25 -> SET WS-INDEX TO 25
To set WS-INDEX to WS-INDEX-2 -> SET WS-INDEX DOWN BY 2.
9. If 10 Dimension table needs to be defined in COBOL? Define any 10 dimensional table?
Tables upto 7 dimensions can be defined in COBOL
10. A two dimensional array has been defined in following way. What it does?
01. WS-TABLE OCCURS 10 TIMES PIC X(3).
05 WS-TABLE2 OCCURS 5 TIMES PIC X(5).
Above definition is wrong, since OCCURS clause cannot be specified at 01 level.If two dimensional array is required, above defintion can be modified as
01. WS-TABLE-GROUP.
05 WS-TABLE OCCURS 10 TIMES PIC X(3).
10 WS-TABLE2 OCCURS 5 TIMES PIC X(5).
BACK TO COBOL
Mar 20, 2010
About this site
Fed up of searching good interview questions in internet Jungle! If Yes , then definitely this site will give you some kind of respite since it helps you to make your knowledge base strong and also will guide you through lot of interview questions which will make you to think, understand and make it perfect!
No doubt, this will help you in sharpening your skills!
Thease Question Banks inculdes questions which are asked frequently and also questions which will make you to understand mainframe world in better way!
As a human, again I am prone to errors. So please leave comments, your suggestions.I will try to incorporate it into this page.
Thanks!
No doubt, this will help you in sharpening your skills!
Thease Question Banks inculdes questions which are asked frequently and also questions which will make you to understand mainframe world in better way!
As a human, again I am prone to errors. So please leave comments, your suggestions.I will try to incorporate it into this page.
Thanks!
Subscribe to:
Posts (Atom)