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

Batch COBOL - for sorting the file based on Last name.


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
nprathap4u

New User


Joined: 24 Apr 2007
Posts: 15
Location: India

PostPosted: Fri Dec 07, 2007 12:44 pm
Reply with quote

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
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Fri Dec 07, 2007 4:40 pm
Reply with quote

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
View user's profile Send private message
ulfnsc

New User


Joined: 15 Jan 2004
Posts: 19
Location: Stockholm, SWEDEN

PostPosted: Fri Dec 07, 2007 5:12 pm
Reply with quote

Hi Gnanas
Why REVERSE?... Is it OP's requirement??
Back to top
View user's profile Send private message
Gnanas N

Active Member


Joined: 06 Sep 2007
Posts: 792
Location: Chennai, India

PostPosted: Fri Dec 07, 2007 5:19 pm
Reply with quote

Quote:
Why REVERSE?...


Then only we can find out spaces to eliminate.

Correct me if I am wrong.
Back to top
View user's profile Send private message
nprathap4u

New User


Joined: 24 Apr 2007
Posts: 15
Location: India

PostPosted: Fri Dec 07, 2007 5:56 pm
Reply with quote

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Fri Dec 07, 2007 6:01 pm
Reply with quote

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
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 -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
Search our Forums:

Back to Top