Cobol
Cobol
Cobol
ANS :Comp is a binary usage, while comp-3 indicates packed decimal. The other common usages are binary and display.
Display is the default. 3/28/00 Dave Herrmann: 'I was reading your FAQ on Cobol, as an fyi Comp is defined as the
fastest/preferred numeric data type for the machine it runs on. IBM Mainframes are typically binary and AS400's are
packed.'
COMP
Comp is used for Binary Representation
it allows only S and 9 ...
s9(01) to s9(04) it takes 2 bytes memory
s9(05) to s9(09) it takes 4 bytes memory
s9(10) to s9(18) it takes 8 bytes memory
COMP-3
Comp-3 is used for Packed Decimal values
it allows S 9 V
mostly it is useful for Decimal Caluculation Values
it takes (n/2)+1 Bytes Memory
Q2 : How include time & date in the report generation in cobol programing?
ANS : This can be done in 2 ways 1 is u can enter the date by user itself or u can excpet date form system into requried
formate date/time variable then u can get time and day into ur report generation file.
This will place the system timestamp in CCYYMMDDHHMMSSmmmmmmm format into SOME-FIELD.
Q3: Suppose i have array of 10 elements in it how to access 5 element from the array using sup script and
index?
ANS : if you have an array with 10 elements like this :
int a[] = {1 2 3 4 5 6 7 8 9 10};
To access the 5th element you need to write a[4]. Because Array index starts from 0. In this case 0th element
is 1 1st element is 2.. etc
Can we able to execute the following statement move a,b toc,d' What will happen ?
Q4 :
ANS: We ll not be able to execute the statement... It will give us a error message... As per syntax... we can move 1
variable to many or 1 to i but not many to many or many to one...
Q7 : What happens if we code Exit program instead of Stop Run in main program
Ans : If Exit program is coded in the main program it will throw abend 4038 (compilation error) since it wont be able to
return control to the O.S
Q10 : INSEPCT
Give example of Inspect TALLYING / BEFORE INTIAL / AFTER INITIAL. In which situation will use this in COBOL?
Ans : In INSPECT claues Taylling is used to count the number of char's in the string. Before and after intial is used in termes of
intialized the particular char. Before start counting or after done the counting it will intinalzs that char.
For example; variable - vara pic x(20) value mainframe question INSPECT vara tallying tally-count 'a' before intial 'e' after intial
'i'
Q11:In Cobol we may get return code of 4 or 8 or 12 or 16, If this is the case why the picture clause of return code in
alphanumeric field? why not numeric?
ANS: RETURN-CODE is a 2 byte binary field. Hence it can very much be defined as a numeric field also. It is defined as alpha
numeric field i.e. PIC X(02) because it occupies 2 bytes and COBOL converts numbers in binary to char format when they are
accessed through a variable of definition PIC X(n). RETURN-CODE can very much be defined as PIC S9(04) COMP or PIC 9(2) also.
Q12 :If a simple cobol program has no syntax error, then is it necessary to compile it?
ANS :However simple be a COBOL program (it can even be a subprogram) it is always a good practice
to copile it and make sure its syntax error free. Moreover when we compile the COBOL code it will be
converted by the compiler in to object code (the load module) and this object code is the one that a
computer(machine) can understand. Thus only after proper compilation will a program run
successfully. Also this load module will help us to run the program multiple times without
recpmpilation (if no source code changes are made)
Q14 :Redefine
ANS : If you have accepted the amount as 126778.12 from user and have to move it in COMP-3 variable then declares a
user defined fields as 9(11).99 and accept the above variable into it then move it into the desired comp-3 variable For ex
PIC 9(11)V99 COMP-3.
Amount will get modified.
To again display this amount in some report or so you can again do the reverse of above.
Move PIC 9(11)V99 COMP-3 to PIC 9(11).99
Q16 :Explain the Endevor list selection options - BX, CX, HX, LL, LO, LI, LC and SX Which among these are used to
browse the components?
Ans : BX - Browse A Browse command presents a read-only view of the element content.
CX - Changes The Changes display shows changed (and deleted) lines from the previous revision.
HX - History A History command presents a read-only view of the “history” of the source content. Every line of source for the
element is shown whether it is still present or not.
SX - Summary Summary of levels shows information about each revision.
LI - List Inputs List the inputs for a program.
LO - List Outputs list the outputs for a program.
LL - List Listings
LC - List Component
Q18 :Comp-3
Q19 : We have two files. and we want to write the matching records from both the files to a third file.There can be
duplicate records in both the input files.
ANS: In case of STATIC CALL t load module of both t main prog and t sub prog wil b combined together.... in case of DYNAMIC
CALL t load module of main and sub prog are both seperate. suppose that if u make any change in ur sub prog then in case of
DYNAMIC CALL u nee not recompile your MAIN prog once again. only t sub prog needs to b recompiled...... wher as in case of
STATIC CALL u need to recompile both t main and t sub prog Hope u understood
Syntax
Q2:What is difference between RM COBOL & MF-COBOL & Pro COBOL & VS-COBOL or Do we have
any other type of COBOL ?
ANS: We have ND-COBOL ACU-COBOL...all these depends on the machine in which we work
Q24: What is the difference between a subscript and an index in a table definition?
ANS: subscript is a working storage data definition item, typically a PIC (999) where a value must be moved to the subscript
and then incremented or decremented by ADD TO and SUBTRACT FROM statements. 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.
Q26: How to find the number of records in a flat file using COBOL ?
open input-file.
perform read-para
until ws-end-of-file = 'y'.
close input-file.
stop run.
read-para.
read input-file
at end move 'y' to ws-end-of-file
Q29:There are 2 files. These 2 files contains some common (duplicate) records. How do you copy
these common
ANS: Step 1: using pgm SORT sort and merge the two files
SORTIN DD file 1 (i/p file 1)
SORTOUT DD file 3 (o/p file containing the sorted and merged recs of both the i/p files)
Step 2: Using SUM FIELDS = NONE XSUM : the duplicates will be eliminated and written in to the file defined in the
SORTXSUM DD step
Using COBOL :
Use the MERGE verb along with the OUTPUT PROCEDURE. In the OUTPUT PROCEDURE code the logic for eliminating the
duplicates and writing them in to an output file.
If A>B
next sentence
end-if
display 1
display 2.
display 3.
if a>b
continue
end-if
display 1
display 2.
display 3.
it will display 1 2 3. if a>b. let me know if it is not correct.
Where as in COMP-3 data is stored in d form of packed decimal.i.e two digit will occupy 1 byte
Ans: Working storage section is the part of data divsion where you declare your variables you are using in your program.
But Linkage section is the part of data division which is used to 1) Receive Parameters passed from other Cobol program
(Calling program).
2) It's used to accept the Paramaters passed from the JCL to the COBOL program.
Q5: How will work GOBACK statement & STOP RUN & EXIT-PROGRAM in COBOL ?
ANS: GOBACK gives the controll to main program if we have called the subprogram from the main program.
STOP RUN: This statement halts the execution of the object program and returns control to the system.
EXIT-PROGRAM: This statement specifies the end of a called program and returns control to the calling program.
Q6:What is the reference modification
Ans: 00340 01 TREE-TYPE PIC X(15) VALUE 'BANANATREE'. 000350 01 FRUIT-TYPE PIC X(15) VALUE 'BANANA'. 000360 01 TREE-
FRUIT PIC X(5). If you wanna move only particular value to another variable instead of as a whole value you can use reference
modification.
For Eg :
You can say
004310 004320 MOVE TREE-TYPE(1:5) TO TREE-FRUIT. 004440
This will move "BANAN" to TREE-FRUIT. (The letters from position 1 of TREE-TYPE for 5 positions.So this : (colon) is called ref
modification indicator.Like this you can use MOVE TREE-TYPE(2:4) TO TREE-FRUIT.So the character from 2nd position for 4 character
length will get move.
Ans: Generally index is created in either primary key or alternate key of a table for faster access of records.
.
Q8:What is Load module & Link edit and How will it work Dynamic call?
Ans: Load Module: The object code converted into Load Module (Machine readable form) by using Link edit that's common in
COBOL.
But in Dynamic call first we have to submit the sub progs later we can use that in Link section in COBCOMP. That's the
procedure.
Q9:What if Stop Run is missing in COBOL program?
Ans: Stop Run" and "Go Back" both indicate to the program to end processing and in the latter case to transfer control to
the calling program.
If you dont specify either of these in your program the behaviour might be unpredictable. Most probably your program
will not end execution and an out of time error (S322) will be thrown...
sol: count1 = 1
Q46:Impact Analysis
ANs: i) why the new file is being introduced to the program?
ii) adding extra two columns to the output file - will that impact the other programs which might be using that file?
iii) if yes how frequently that interface is used and will there be any change in that interface?
iv) if program is used for any reporting etc will there by any changes to the hard copy reports spool settings etc.
v) the two extra columns - can they be accommodated with the existing LRECL of the output file or will that need to be reconsidered.
Figurative constant means compiler defined constants. They are zeros spaces etc.
Q49:What is the need of using comp field in COBOL
Ans: 1. When we want to store the datas in BINARY format.
2. When we are receving the datas from the JCL.
Q50:How can you redefine pic x(10) with pic 9(10) without loosing the existing data from the
record.
You can redefine pic x(10) with pic 9(10) without any data loss as long as you don't move the value of the x-variable to 9-
variable.
Q51:What is Addressing mode
Ans: AMODE is addressing mode.AMODE can be 24 31 or any. AMODE 24 implies that the addresses below the 16Meg line can be
fetched but the addresses below the 16 Meg line cannot be fetched. AMODE 31 implies that the addresses above and below the
16Meg line can be fetched. All new codes in COBOL 3 have amode as 31 by default.Hope this helps!!
Q52:Difference between GOBACK & CHAIN in COBOL?
Ans: goback:
controller should return back to where ever it comes from.
chain:
controller will go to subprogram after compleation of subprogram it will go to os.
You cannot see the output of a program unless you have executed the program. but You can see the results of a CICS
pgm using INTERTEST.
3) what is flag?
Flags would be assigned a value based on some condition. While using it for some processing there is no need to
calculating every time. u can calculate one time and keep the decision saved in a varibale. this can be used multiple
times.
4) what is impact analysis what basis how will you write test cases?
Say you are changing a module this module may be interacting with many other modules or the results of this module
may be used by some other module. Any changes done for some bug fix in this module should not change the
functionality of any module. This is main purpose of Imapct analysis.
To write the test cases we need to be aware of the functioanlity of the module and the working of the module.
// DD DSN=file2.file DISP=SHR
// DD DSN=file3.file DISP=SHR
Q55: Can Redefines clause be used in File section, if yes at which level number ? ?
Ans: We can use redifine in file section and also at any level. Redifine is just the method of representing thr
data in different formats. But the only clause is that lenght of the redefining field should be less than or
equal to the lenght of the redifined field.
Q56: Inthe example below 05 WS-VAR1 PIC X(5),05 WS-VAR2 REDEFINES WA-VAR1 PIC
9(5),PROCEDURE DIVISION MOVE MOVE 'ABCDE' TO WS-VAR1.Now what is the value of WS-
VAR1 and WS-VAR2 ?
ANS:
Q57 Infile section of a COBOL program, I have the following line.Record varying from 122 to
160 depending on WS00_RECORD_LENGTH. How would the value of
WS00_RECORD_LENGTH found out? Where will it be?
Q58:Whatare the two cobol verbs that are used in data division? (one is
COPY..what is the other)
Ans: 1)COPY
2)INCLUDE
Q59: Whatis the difference between write & move in COBOL.? What is the
meaning of 'TALLING' verb in cobol? What is the meaning of 'Eject' verb in cobol?
Ans:
ANS: call means u r calling a predifined cobol app in to u r called program while running time only.
but link u r calling sub program into main while compiling time.
Q62:What are the HIGH Values,LOW values and where we can use?
ANS: HIGH-VALUES and LOW-VALUES are the largest and smallest possible values a given variable can hold respectively.
Typically they are usually used with alphanumeric PIC X type field
ANS: 1) No
2) no
3) yes
4) yes
5) '*'
6) 8 bytes
7) 31
ANS: #.1 . Here is an example for how to initialize the normal group variable .
ex : 01 ws-details .
02 ws-name a(10 ) .
02 ws-desig a(5) .