Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Questions related to files in cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions
View previous topic :: :: View next topic  
Author Message
indus

New User


Joined: 10 Dec 2008
Posts: 12
Location: Bangalore

PostPosted: Fri Dec 11, 2009 5:49 pm    Post subject: Questions related to files in cobol
Reply with quote

1.How we will find out the number of lines in a file.
I said I will do a M,F8 and see the last line number.
2.Suppose I have a file with structure emp1,emp2,emp3,emp4. How will I reformat the file in such a way that emp4 first then emp3 then emp2 and then emp4.
This I also I could not answer. Interviewer wanted this to be done through Sort utility.

Can anyone help me in finding out the answers for this...
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Fri Dec 11, 2009 6:03 pm    Post subject:
Reply with quote

1. count them as they are created. counting afterwards is realllllllly stupid.

2. don't have a sort answer but you need to start insuring that your finished product (you post for example) is correct. you will have nothing but problems if you do not proof your code before compiling.
Quote:
How will I reformat the file in such a way that emp4 first then emp3 then emp2 and then emp4.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Dec 14, 2009 5:45 pm    Post subject:
Reply with quote

As these are interview questions and I've been through some stupid interviews lately, I'll try to answer from the perpesctive "what the **** they want to listen..tell them":

1. a. Below job will write the input record count to SORTOUT as an 5-digit number:
Code:
 //step001 EXEC PGM=ICETOOL
//TOOLMSG DD SYSOUT=*
//DFSMSG DD SYSOUT=*
//IN DD DSN=... input file
//OUT DD DSN=... output file
//TOOLIN DD *
COUNT FROM(IN) WRITE(OUT) DIGITS(5)


b. You can use TALLY function if your shop has file-aid.

2. Your second question is not clear. Do you want the emp4 to appear twice in output or just want to read the file in reverse-order?
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Mon Dec 14, 2009 8:22 pm    Post subject:
Reply with quote

Hello,

Quote:
Suppose I have a file with structure emp1,emp2,emp3,emp4.
Suggest you show an example of the "input" record(s) and what is wanted as "output".
Back to top
View user's profile Send private message
indus

New User


Joined: 10 Dec 2008
Posts: 12
Location: Bangalore

PostPosted: Tue Dec 15, 2009 10:15 pm    Post subject: Reply to: Questions related to files in cobol
Reply with quote

Thank you Anuj for your reply.

Also about the second question the interviewer wants the file to be read in the reversed order.

Thanks,
Indu
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Dec 15, 2009 10:18 pm    Post subject:
Reply with quote

Hello,

Quote:
the interviewer wants the file to be read in the reversed order
Append a "sequence number" to each record and sort descending on this sequence number.

The data will be in "reverse" order. . .
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Dec 15, 2009 10:20 pm    Post subject:
Reply with quote

What do any of these questions have to do with COBOL?
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Dec 15, 2009 10:35 pm    Post subject: Reply to: Questions related to files in cobol
Reply with quote

Hi Craig,

This was from an interview for a COBOL developer . . . ?

d
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Tue Dec 15, 2009 11:01 pm    Post subject:
Reply with quote

That makes sense. My last big interview was for a CICS/COBOL/VSAM position. One of the first questions was the relationship of PSB and PCBs. I answered that PCB's had been banned by the EPA and that is what she wrote down. I hadn't worked with IMS for 10 years at that time and really didn't want to. I got the job but after a few run in's with data center I was tempted to call the EPA and report that they still were using PCBs. I would loved to have seen the guys in there protective suits show up to try and remove the PCBs from the IMS applications.
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Tue Dec 15, 2009 11:08 pm    Post subject: Reply to: Questions related to files in cobol
Reply with quote

Heh, heh, heh. . .

Quote:
One of the first questions was the relationship of PSB and PCBs. I answered that PCB's had been banned by the EPA and that is what she wrote down
Our tax $ at work. . .?
Back to top
View user's profile Send private message
Shriram Jogdand

New User


Joined: 14 Oct 2008
Posts: 65
Location: Pune

PostPosted: Wed Dec 16, 2009 6:29 pm    Post subject: Reply to: Questions related to files in cobol
Reply with quote

2. If you want to have file in reverse order through SORT then code the following in SYSIN DD *

SORT FIELDS=(starting-postion of emp-id, length of that fields, CH,D)

e.g

SORT FIELDS=(1,5,CH,D)
Back to top
View user's profile Send private message
dick scherrer

Site Director


Joined: 23 Nov 2006
Posts: 19270
Location: Inside the Matrix

PostPosted: Wed Dec 16, 2009 8:04 pm    Post subject:
Reply with quote

Hello,

Unless all of the emp-id will be unique, that will not guarantee the data will be returned in reverse order. . .

Also, what if the input file was in seqence by emp4, emp2, emp3, emp1. The decending sort wouldn't even be close. . .
Back to top
View user's profile Send private message
viveksurya

New User


Joined: 08 Jun 2009
Posts: 36
Location: Bangalore

PostPosted: Mon Dec 28, 2009 1:27 pm    Post subject:
Reply with quote

Hi Indus,

For second query, understanding that you want the words in reverse order. Here is a suggested way:

Code:
//SORTIN   DD *                                               
EMP1,EMP2,EMP3,EMP4                                           
WRK1,WRK2,WRK3,WRK4                                           
//SORTOUT DD  DSN=VS059U.FILE.OUTPUT,DISP=(NEW,CATLG,DELETE),
//            DCB=(RECFM=FB,LRECL=80),                       
//            SPACE=(TRK,(2,12),RLSE)                         
//SYSIN   DD  *                                               
   SORT FIELDS=(1,5,CH,A)                                     
   OUTREC FIELDS=(1:16,4,5:10,5,10:5,5,C',',16:1,4)


Output:

Code:
000001 EMP4,EMP3,EMP2,EMP1
000002 WRK4,WRK3,WRK2,WRK1



Hope this helps.
Back to top
View user's profile Send private message
Anuj Dhawan

Senior Member


Joined: 22 Apr 2006
Posts: 6258
Location: Mumbai, India

PostPosted: Mon Dec 28, 2009 6:37 pm    Post subject: Re: Reply to: Questions related to files in cobol
Reply with quote

You're welcome indu.

indus wrote:
Also about the second question the interviewer wants the file to be read in the reversed order.
If this has to be done by/in COBOL - it's not doable (I believe), and as you said, it's a sequential file - you have to read each record one-by-one. COBOL READ verb does a sequentail read, one-record-per-read - there is no magic trick to reach at last record in first read (unless you have only one record in the file icon_smile.gif).

However, if SORT can be an option - try on what Dick has suggested or alternateviely if you have File-aid, you can use the below job to read the "x" records from bottom and then use the output from this as an input to COBOL program
Code:
//COPYREC  EXEC PGM=FILEAID
//DD01     DD  DSN=YR1MM.REC.FILE,DISP=SHR
//DD01O    DD  DSN=...reversed.recds,DISP=(,CATLG,DELETE),
//         DCB=*.DD01
//SYSIN    DD  *
$$DD01 COPYBACK OUT=X
//SYSPRINT DD  SYSOUT=A
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> Mainframe Interview Questions All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts High CPU consumption Job using IAM fi... aswinir JCL & VSAM 8 Thu Dec 01, 2016 8:28 pm
This topic is locked: you cannot edit posts or make replies. RANDOM Function in COBOL swapnil781 COBOL Programming 2 Tue Nov 15, 2016 6:17 pm
No new posts Regarding COBOL Stored Procedure opti... selvamsrinivasan85 DB2 4 Fri Nov 04, 2016 8:57 pm
No new posts Match or compare two files in VB Format anatol DFSORT/ICETOOL 14 Thu Nov 03, 2016 7:41 pm
No new posts COBOL Version 6.1 Virendra Shambharkar COBOL Programming 5 Tue Nov 01, 2016 11:24 am


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us