View previous topic :: View next topic
|
Author |
Message |
nprathap4u
New User
Joined: 24 Apr 2007 Posts: 15 Location: India
|
|
|
|
Write a COBOL batch program for the following requirement:
Requirement:
* file length - 80
* Record contains : only Names ( ie. First & Last name )
FYI :
There may be chances of spaces between first n Last name and there may be chances of spaces
before first name.
for example:
i/p:
Code: |
****************************
000001 MARK VANTSON
000002 ATKIN GEFF
000003 SAN BARB
000004 MARK VANTSON
000005 BILL BOUD
**************************** |
o/p: should be
Code: |
****************************
000001 SAN BARB
000002 BILL BOUD
000003 ATKIN GEFF
000004 MARK VANTSON
000005 MARK VANTSON
**************************** |
Now,
Below are the things need to be done.
* Need to be sorted in Asc order using Last name.
* There should be only one space between first & Last name. |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Prathap,
This will work for breaking name into First and Last Name. I think Name contains spaces in the starting, it won't work, ie, 1st and 4th records of your sample input.
Code: |
UNSTRING FULL-NAME DELIMITED BY ALL SPACES
INTO FNAME, LNAME. |
After that use, INSPECT, REVERSE and STRING functions to build a record as you like.
Above FNAME and LNAME will contain trailing spaces.
So,
Code: |
INSPECT FUNCTION REVERSE(FNAME) TALLYING FCOUNT
FOR LEADING SPACES.
INSPECT FUNCTION REVERSE(LNAME) TALLYING LCOUNT
FOR LEADING SPACES.
STRING FNAME(1:40 - FCOUNT) SPACE LNAME(1:40 - LCOUNT)
DELIMITED BY SIZE INTO OUTREC. |
Then WRITE the OUTREC.
I assume the Picture clause of FNAME and LNAME as X(40).
Quote: |
Need to be sorted in Asc order using Last name. |
Use JCL SORT utility.
I havn't checked the above code. Change according to your requirement.
Correct me if I am wrong. |
|
Back to top |
|
|
ulfnsc
New User
Joined: 15 Jan 2004 Posts: 19 Location: Stockholm, SWEDEN
|
|
|
|
Hi Gnanas
Why REVERSE?... Is it OP's requirement?? |
|
Back to top |
|
|
Gnanas N
Active Member
Joined: 06 Sep 2007 Posts: 792 Location: Chennai, India
|
|
|
|
Then only we can find out spaces to eliminate.
Correct me if I am wrong. |
|
Back to top |
|
|
nprathap4u
New User
Joined: 24 Apr 2007 Posts: 15 Location: India
|
|
|
|
Hi gnanas,
Thanks for your reply.
HELLO murmohk1,
Being a sen. member for this forum..
would u be asking like this or WHAT??????
Quote: |
Why dont you write your own? We are here to 'assist' not to do your work. |
This is the one of the good Qns asked by an interviewer.....
i thought of sharing to all...thts it....
Please avoid such kind of reply.... |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Prathap,
Quote: |
Please avoid such kind of reply.... |
This had been informed several times in the forum. And I try to put it one more time -
'We expect some basic work before anyone 'starts the topic'. We are not being paid for your work. The forum intention is to help each other in a professional way. And PLEASE REMEMBER we have our own work to do'. |
|
Back to top |
|
|
|