14
MFSTUDY CENTER MEMBERS FAQ’s COBOL Q. define call by value and call by refernce? A. call by value-change of argument value in sub program will not be visible inmain program whereas in call by reference,it would be visible. Q. by seeing cobol programme.how u find static call prg or dynamic call prg. call ws-var using x,y ==> ws-var is working storage variable which got populated during runtime ---then this call would be dynamic call. By seeing program we cant say a call is static or not..bcoz link edit option decided the call.if we havementioned DYNAM option,all the sub programs will be attached to main module.(static)..so refer the IEWL listing to decide type of call. Q. My Understanding is as below. If we are calling the pgm Statically we will have a Single Load Module,If we are calling the pgm dynamically we will have different Load Modules. Here are my Queries: If we are Compiling the pgm which is calling another pgm Statically we need to Compile the sub pgm first and then the Maing pgm. Load Module will be created after the link edit only.After the Compilation We will get object Module.In that scenario, How the Sytem will recognise these two Object Modules and Link EDIT them to creata a Load Module . If we are passing "NODYNAM" in PARM of LINKEDIT Then where will specify the Object Modules and How these Object Modules are getting Link Edited to get a Single Load Module. I suspect that we need to specify the sub programs in SYSLIB. Please Correct me If I am travelling in a wrong Path. MFSTUDY CENTER MEMBERS FAQ’s

MFAQ-COBOL

Embed Size (px)

Citation preview

Page 1: MFAQ-COBOL

MFSTUDY CENTER MEMBERS FAQ’s

COBOL

Q. define call by value and call by refernce?

A. call by value-change of argument value in sub program will not be visible inmain program whereas in call by reference,it would be visible.

Q. by seeing cobol programme.how u find static call prg or dynamic call prg.

call ws-var using x,y ==> ws-var is working storage variable which got populated during runtime ---then this call would be dynamic call.

By seeing program we cant say a call is static or not..bcoz link edit option decided the call.if we havementioned DYNAM option,all the sub programs will be attached to main module.(static)..so refer the IEWL listing to decide type of call.

Q. My Understanding is as below.If we are calling the pgm Statically we will have a Single Load Module,If we are calling the pgm dynamically we will have different Load Modules. Here are my Queries:If we are Compiling the pgm which is calling another pgm Statically we need to Compile the sub pgm first and then the Maing pgm.Load Module will be created after the link edit only.After the Compilation We will get object Module.In that scenario, How the Sytem will recognise these two Object Modules and Link EDIT them to creata a Load Module .If we are passing "NODYNAM" in PARM of LINKEDIT Then where will specify the Object Modules and How these Object Modules are getting Link Edited to get a Single Load Module. I suspect that we need to specify the sub programs in SYSLIB. Please Correct me If I am travelling in a wrong Path.

A. Please see the answer below. 1. How the System will recognize these two Object Modules and Link EDIT them to create a Load Module ? When compiled COBOL program and you have an object module created by the compiler. When you link edit, the link editor ensures that all subroutine calls from main program are resolved when load module is generated and merges all subroutines with the main program. A statically called module is bound with the calling module at link edit, and therefore becomes part of the executable load module.   LINK indicates that the object module is to be processed by the linkage editor program. The object module, which is the output of the compiler, is written on the disk referred as SYSLNK.   The linkage editor program will link-edit the object module which is located on SYSLNK.

MFSTUDY CENTER MEMBERS FAQ’s

Page 2: MFAQ-COBOL

MFSTUDY CENTER MEMBERS FAQ’s

Q. What are the different ways to load a compiled program ?

A. DYNAM--This is a compiler option,when specified,u make a dynamic call on a subprogram.Dynamically called modules dont get bound to calling program's load module at link edit time(IEWL)..soo both load modules exist seperately when this compiler option is usedand are loaded from the program library.

NODYNAM--This is the default option in the compiler option.WHen specified,called program's load module gets bound to the callign pgm's load module and so becomes a part of the executable load module and are link edited to the load module of the main pgm.ur 1st and 2nd question means the same thing..

Q. What is below 16m and above 16m ?

A. Programs (compiled) using 24 bits mode can use only 16MB of space,so these are reffered to (Below 16MB). Programs(compiled) using 31 bits mode can use above 16MB of space,so these are reffered to (Above 16MB)

Q. How to get a perticular char in place of a null value ?

A. Asssuming that u had asked how to update a null place with a validvalue-- (H.V)ws-empno. (H.V)ws-phone-no. (H.V)ws-phone n-IND-------------Indicator variable declared in W.Ssection. MOVE 2120 TO WS-EMPNO. MOVE '616161 ' TO WS-PHONE-NO. MOVE ZEROES TO WS-PHONE-NO-IND.

PERFORM UPDATE-PARA. ...... UPDATE-PARA. EXEC SQL UPDATE EMPLOYEE SET PHONE = :WS-PHONE-NO :WS-PHONE-NO-IND WHERE EMPNO = :WS-EMPNO END-EXEC.

hope u know to use Host Variables.....(colon)

Q. can any one give me the logic for checking trailer record. my prog should abend if there is no trailer record?

A. The logic was if the last record is a detail and if the end -of -file is reached then there is no trailer.. this is working fine..

Q. how to swap two variables without using an third variable in COBOL.for eg if a=10,b=20 how to get a=20 and b=10 without using third variable.

A. i think this workslet a=9 and b=7a=a-b;after this a=2 and b=7;b=a+b;after this a=2,b=9a=b-a;after this a=7 and b=9

MFSTUDY CENTER MEMBERS FAQ’s

Page 3: MFAQ-COBOL

MFSTUDY CENTER MEMBERS FAQ’s

Q. what is the function in cobol to get date along with the centuryvalue.and for time too.

A. its FUNCTION CURRENT-DATE.

Q. COBOL PROGRAM WITH DYNAMIC ALLOCATION IS GIVEN BELOW.

A. IDENTIFICATION DIVISION.PROGRAM-ID. DYNMUTHU.ENVIRONMENT DIVISION.INPUT-OUTPUT SECTION.FILE-CONTROL.SELECT OPTIONAL OUTFILE ASSIGN TO OUTFILE.DATA DIVISION.FILE SECTION.FD OUTFILE.01 INRECORD PIC X(80).WORKING-STORAGE SECTION.01 BPXWDYN PIC X(8) VALUE 'BPXWDYN'.01 WS-RECORD PIC X(80).01 ALLOC-STRING.05 ALLOC-LENGTH PIC S9(4) BINARY VALUE 50.05 ALLOC-TEXT PIC X(50) VALUE"ALLOC DD(OUTFILE) DSN('CDT7148.TEST1') OLD".PROCEDURE DIVISION.CALL BPXWDYN USING ALLOC-STRINGIF RETURN-CODE NOT = ZEROTHEN DISPLAY 'ALLOC FAILED, RETURN-CODE WAS ' RETURN-CODEELSE DISPLAY 'ALLOC OK'END-IFOPEN OUTPUT OUTFILE.DISPLAY 'OPENED'.MOVE 'T' TO INRECORD.WRITE INRECORD.CLOSE OUTFILE.STOP RUN.

Q. how to find the length of a elementary item or group item in COBOL.

A. You can also use 'LENGTH OF'  statement to find the length of a variable in COBOL. But if the variable is having spaces,that will also be included in the count.So, those spaces have to eliminated from the count. So, you can use the following logic,i feel it has to work fine,

    01  WK-LEN               S9(4) COMP.        01  Length-Table        10 WK-LENGTH-TO-BE-FND  OCCURS 1 TO 254 TIMES                                                                   DEPENDING ON WK-LEN  PIC X.     In the cobol program,        MOVE LENGTH OF WK-LENGTH-TO-BE-FND TO WK-LEN                  PERFORM 100-EXAMINE-LAST-CHAR THRU 100-EXIT                                            UNTIL WK-LENGTH-DETERMINED-SW.       100-EXAMINE-LAST-CHAR.

MFSTUDY CENTER MEMBERS FAQ’s

Page 4: MFAQ-COBOL

MFSTUDY CENTER MEMBERS FAQ’s

        IF WK-LENGTH-TO-BE-FND (WK-LEN) = SPACE            SUBTRACT 1 FROM WK-LEN        ELSE            SET WK-LENGTH-DETERMINED-SW TO TRUE.        END-IF.                IF WK-LEN = 0          SET WK-LENGTH-DETERMINED-SW TO TRUE.        END-IF.       100-EXIT.          EXIT.       At the end you will have the correct length in the WK-LEN.

Q. How do i display a COMP-3 in the Z,ZZZ,ZZZ format.

A. Move that COMP-3 variable to the Z9(7) variable and then display the Z9(7) variable, you can see. U cannot display the COMP-3 variable directly.

Q. IS there any command in cobol which can lock the VSAM or flat file?

A. If there is one option availabe in cobol suppose Vsam file name is file1.

OPEN INPUT FILE1.CLOSE FILE1 WITH LOCK.

Q. My program generates following output file in the form of report. There is a requirement that I should use this file as input and using the value 123456-00-0, read another file and extract records from that file to an output file.

********************************* Top of Data**********************************BDXX240--XX COUNTY OF PANAMA REPORT JOT140 PERSONS ON JOT/ CASES PURGED FROM MDE

CASE NUMBER PN PERSON LAST PERSON LAST NAME FIRST NAME 123456-00-0 01 REMOJA MLASA

*** END OF REPORT JOT240 ********************************** Bottom of Data********************************

My doubts:

1. Is it possible to use such report files as input files?2. If I have to read this file, how the contents should be read because it does not have any copybook structure?

A. 1. Yes, you can use Report Files as Input Files.

2. You can declare a FD entry in File Section like this.

FD xxx-yyy RECORDING MODE IS F

MFSTUDY CENTER MEMBERS FAQ’s

Page 5: MFAQ-COBOL

MFSTUDY CENTER MEMBERS FAQ’s

LABEL RECORDS ARE STANDARD DATA RECORD IS INPUT-REC1.

01 INPUT-REC1 PIC X(133).

You can READ this file with the usual READ statement like this

READ xxx-yyy,

The first record of this Input File will be available in INPUT-REC1.

You can EXAMINE or INSPECT this to search for the Key value you are looking for.

Once you get the value you are searching for, you can pass this as a KEY to the second VSAM file (ideally a KSDS) and extract the record and write to an output file.

Q. I have a report file that has four headings followed by detail records and finally end of report line. This report does not have any copybook record structure available. I would like to extract only detail records to a seperate file using either SORT or some other utility like file-aid. Is it possible to do so? I have tried it out myself but could not succeed. program01                   county of panama               date:02/06/2003                detail transaction records                          page 1                         person last name           person first name                                                     pin                                age                         somebody1           01         lm                      30                         somebody2           02         kr                       24                         somebody3           01         zz                      16                 *** end of report *** Please suggest.

A. You can use a SORT to extract the detail records alone.

Since it is a Report you can use a OMIT condition in SORT to omit the lines where 'date:' , 'page', 'age' appears. Something like this:

SORT fields=copyOMIT cond=((50,5,ch,eq,c'date:'),or, (51,4,ch,eq,c'page'),or, (53,3,ch,eq,c'age'))

You can use the above condition if you are sure that the detail records will not have the above values in the column mentioned.

Q. whats the difference between 01 Level & 77 level..?i.e whast the need for a 77 level . we can declare them using 01 level & having no sub-fields.that will fulfill the purpose.so whats the need for a seperate 77 level for delcaring elementaryitems.

A.Literal difference is : '01' if for group item.-file declarations /record descriptions whereas 77 for elementary items. I used to group all elementary items under one meaningful group item

MFSTUDY CENTER MEMBERS FAQ’s

Page 6: MFAQ-COBOL

MFSTUDY CENTER MEMBERS FAQ’s

(01).like all counters under one 01 ws-counter items. all constants under one 01 ws-constant item etc..Though you can declare elementary item on 01,it not a good practise. There are chances for 77 to be removed in future cobol compilers. (read somewhere..not sure!)

Q. given a File with some records & you want to search the file for a record.What search would you decide & on what basis?

I think this is one of the famous interview Questions.Given an option of SEARCH and SEARCH ALL..which one you prefer and why?

A.Based on number of records.If your file has lot of records go for binary search.if it has only 10 or 20,serial search is preferable.

Q. suppose you want to call aprogram.how would u decide which call you would decide. static call or dynamic call..?

A. Hope you know the difference and the way of making these calls.If you want your application should be faster , go for static calls.But size of load module will become large.And if there is any change in sub program,you need to compile main program also after the successful compilation of sub program.If you want more flexibility then go for dynamic call..For this also more detail answer available in files section.

Q. When we makes a cal statement in Cobol ; by default is what?call be reference or content?    If it is call by reference(what I think) -Does that programe is compiled statically or dynamically?   for example I had used CAll anotherproc using A,B,C and in the called pgm I had used Linkage section and  Procedure divsion using x y z.In this case this pgm is performinng a static call or dynamic call.Does  vscobol-2  support the static calls?(it should support otherwsie how I can run the above pgm!!)

A. default is Call by reference. Static linking and dynamic linking is no way related to call by reference or by content.

Q.How about passing Index/Subscripts?(I am sure that Index cant be passed) A : Subscript should be passed as a separate parameter

Q.Which types of Vsam files can be accessed using cobol-jcl  programme? I want access files in all modes for exaple by key,alternateindex,RBA,RRN etc? A : All types files are accessed by using cobol jcl except RBA on ESDS

Q.Its mandatory that before laoding KSDS file using REpro we have to firast Sort the Inputfile.Otherwise the compiler will show errors.IF Iam using a normal Cobol pgm to read from a sequential file (whch contains UNSORTED data) and want to write to a VSAM KSDS cluster (sequential read n write) ..why does the compiler doent show error at that time? A: It is mandatory if you are using the KSDS file. in the case of program it is not required but if you use the process speed improves. Compilation process comes at the time of compilation, it doesn't deal any run time issues

Q. I accept that LOW-VALUES is a reserved for COBOL,But I don't think the spaces and Low-values are same.To my knowledge Spaces are greater than Low-values.The hexadecimal values of Low-values are X'00' Spaces are X'40' High-values are X'FF'.

So, Low-values have least values and High-values have Highest values. (ie. Low-values < Spaces < High-values.)

MFSTUDY CENTER MEMBERS FAQ’s

Page 7: MFAQ-COBOL

MFSTUDY CENTER MEMBERS FAQ’s

So,I feel we need to check for both Spaces and low-values in the given code.

A. the difference between High values,Low-values and spaces.The results are exactly same as what Satish said.

Low values == > X'00' (but i think this is compiler specific.)High Values == > X'FF'Spaces == > X'40'

Spaces are greater than LOW-Values.

Q. Is it possible to code condition (88 level) name in Parm paramer (in likage section)?

A. Yes, you can verywell use conditional names in Linkage section:

Ex:LINKAGE SECTION.01 PARM-AREA. 04 PARM-LENGTH PIC S9(4) COMP. 04 PARM-IND PIC X(01). 88 PARM-A VALUE 'A'. 88 PARM-B VALUE 'B'. 88 PARM-C VALUE 'C'.

Hope this helps.

Q. i need some clarification, can you clarify

LINKAGE SECTION.01 PARM-AREA.04 PARM-LENGTH PIC S9(4) COMP.04 PARM-IND PIC X(10).88 PARM-A VALUE'A*******************'.88 PARM-B VALUE 'B****************'.88 PARM-C VALUE'C******************'.

the above is the declaration, My doubt is i have a hardcoded value, with that i want to check with parm-area. whether i should check both lenths or only the parm-ind with the hardcode valuelet me clarify

A. I observed that you define the filed PARM-IND as 10 bytes, and you are trying to accomadate the values more than 10 characters. (i.e ur value ''A*******************'" is more than 10 characters.It should be less than or equal 10 bytes. if it is more than 10 characters, it maygive comiler error).

For ex: if u definedLINKAGE SECTION.

01 PARM-AREA.

04 PARM-LENGTH PIC S9(4) COMP.

MFSTUDY CENTER MEMBERS FAQ’s

Page 8: MFAQ-COBOL

MFSTUDY CENTER MEMBERS FAQ’s

04 PARM-IND PIC X(03).

88 PARM-A VALUE 'ABC'88 PARM-D VALUE 'DEF'88 PARM-G VALUE 'GHK'

The procedure division could be like

PROCEDURE DIVISION USING PARM-AREA.IF PARM-Ado the processELSEIF PARM-Ddo the processELSEdo the processEND-IFEND-IF

So no need to check the length of parameter.

Hope this helps

Q. i need to have different type of evaluate statments syntax.

A. DIFFERENT EVALUATE STATEMENTS IN COBOL

EVALUATEWHEN A=B AND C=DImperative statementWHEN (D+X)/Y = 4Imperative statementWHEN OTHERImperative statementEND-EVALUATE

EVALUATE SQLCODE ALSO FILE-STATUSWHEN 100 ALSO '00'Imperative statementWHEN -305 ALSO '32'Imperative statementWHEN OTHERImperative statementEND-EVALUATE

EVALUATE SQLCODE ALSO A=BWHEN 100 ALSO TRUEImperative statementWHEN -305 ALSO FALSEImperative statementEND-EVALUATE

EVALUATE SQLCODE ALSO TRUEWHEN 100 ALSO A=BImperative statement

MFSTUDY CENTER MEMBERS FAQ’s

Page 9: MFAQ-COBOL

MFSTUDY CENTER MEMBERS FAQ’s

WHEN -305 ALSO (A/C=4)Imperative statementEND-EVALUATE

Q. when we precompile the db2-cobol program .after completion of precompilation .we add one statement to the cobol source program.

1.what is the next process .we want to again precompile the program?2.same thing in db2 we add one statement to db2 program what is the next process.we want to again precompile the program?

A. If you make any changes/add statements in cobol-db2 program, you need to do precompile,bind the DBRM to package, bind the package to plan and finallyexecute.

Because when we precompile the cobol-db2 program, the execution goes as follows..the output spilts into modules DBRM and Object Module. Finally both the time stamps need to match in order to execute successfully.

Q. i've a doubt regarding comp-3 variable in cobol .i declared one variable like this01 year pic x(5) comp-3.after that i moved that one in to ordinary variable01 tempyear pic x(3).move year to tempyear.after that if i want to print year it is printing correct value , but when I tried to print tempyear variable , it is printing junk thing. is there any way to retrieve the original value using tempyear variable..

A. First of all a comp-3 variable is signed, So it should be S9(5) COMP-3

Move it to a -ZZZZ9 variable & print it.ie., Move S9(5) COMP-3 variable to -ZZZZ9 & print it.

Q. how to calculate bytes in this data division entries. 01  A.        02   B OCCURS 10 TIMES                03 C PIC  999.               03 D OCCURS 15 TIMES.                  04 E  PIC 999.                  04 F OCCURS 20 TIMES.                       05 G PIC XXX.                                 05 H PIC 99.

A. The size occupied by A is as follows:

(((2 + 3) * 20 + 3) * 15) + 3) * 10 = ??? (please calculate..)

Q. Can an INDEX be direct referred in comparison statement like below

05  FILLER REDEFINES FORMS-TABLE                          OCCURS 20 TIMES INDEXED BY FRM-NDX.                 15  FORM-ID           PIC  X(03).                   15  FORM-COUNT        PIC  9(09) COMP-3.    

MFSTUDY CENTER MEMBERS FAQ’s

Page 10: MFAQ-COBOL

MFSTUDY CENTER MEMBERS FAQ’s

Can an index being referred like this

IF FRM-NDX = +20 .

A. Yes. Indexes can be reffered to in relational conditions as well.

cobol rules for using index names in a relational condition

a) when an index or index data item is compared with another index, their internal values are compared without conversion b) when an index or index date item is compared with an indentifier or literal, the occurence number to which the index name corresponds is compared with the value of the indetifier/literal and the rule for numeric comparison applies.

Q. If there is a table in cobol with occurs 10 times. What will happen if we enter value to the 11 Subscript place when the complier option is NOssrange. Will it give system abend or accept the value into the table. If accepting where to 10 th place or 11 th place.

A. The physical location of the table is contiguous. It will move the data to the physical location as if the 11th occurance existed. If your table is in working storage, then fields that exist in yourCOBOL listing will get overlaid.

If your table is in the FD (or SD) structure the you are probably overlay the next buffer area of the I/O. If reading then you have destroyed then first few bytes of the next record, if writing, then you are going to be ok, because you will fix those first bytes on the next write.

If your table is in Linkage Section, then the same thing applies as the working storage as above, unless it is the last thing in the '01' structure, then who knows what you've "stepped on".

Anyhow, just don't do that.

MFSTUDY CENTER MEMBERS FAQ’s