View previous topic :: View next topic
|
Author |
Message |
indus
New User
Joined: 10 Dec 2008 Posts: 12 Location: Bangalore
|
|
|
|
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 |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
indus
New User
Joined: 10 Dec 2008 Posts: 12 Location: Bangalore
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
What do any of these questions have to do with COBOL? |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
Hi Craig,
This was from an interview for a COBOL developer . . . ?
d |
|
Back to top |
|
|
Craq Giegerich
Senior Member
Joined: 19 May 2007 Posts: 1512 Location: Virginia, USA
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Shriram Jogdand
New User
Joined: 14 Oct 2008 Posts: 65 Location: Pune
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19243 Location: Inside the Matrix
|
|
|
|
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 |
|
|
viveksurya
New User
Joined: 08 Jun 2009 Posts: 36 Location: Bangalore
|
|
|
|
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 |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6248 Location: Mumbai, India
|
|
|
|
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 ).
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 |
|
|
|