IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Questions related to files in cobol


IBM Mainframe Forums -> Mainframe Interview Questions
Post new topic   Reply to topic
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
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
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

Superior Member


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

PostPosted: Mon Dec 14, 2009 5:45 pm
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

Moderator Emeritus


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

PostPosted: Mon Dec 14, 2009 8:22 pm
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
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

Moderator Emeritus


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

PostPosted: Tue Dec 15, 2009 10:18 pm
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
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

Moderator Emeritus


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

PostPosted: Tue Dec 15, 2009 10:35 pm
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
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

Moderator Emeritus


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

PostPosted: Tue Dec 15, 2009 11:08 pm
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
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

Moderator Emeritus


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

PostPosted: Wed Dec 16, 2009 8:04 pm
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
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

Superior Member


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

PostPosted: Mon Dec 28, 2009 6:37 pm
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> Mainframe Interview Questions

 


Similar Topics
Topic Forum Replies
No new posts Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts Compare 2 files(F1 & F2) and writ... JCL & VSAM 8
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts Write line by line from two files DFSORT/ICETOOL 7
Search our Forums:

Back to Top