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 Profile Log in to check your private messages Log in
 
Batch COBOL - for sorting the file based on Last name.

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Batch COBOL - for sorting the file based on Last name.
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: 788
Location: Chennai, India

PostPosted: Fri Dec 07, 2007 4:40 pm    Post subject:
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    Post subject:
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: 788
Location: Chennai, India

PostPosted: Fri Dec 07, 2007 5:19 pm    Post subject:
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    Post subject:
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: 1439
Location: Bangalore,India

PostPosted: Fri Dec 07, 2007 6:01 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Split 1 file into 10 output Files - S... Prasanth Kumar SYNCSORT 5 Sat Sep 16, 2017 12:02 am
No new posts Generate public-private key in batch ... vasanthz All Other Mainframe Topics 3 Fri Sep 15, 2017 9:20 am
No new posts Working with hex values in Filemanage... Emile Straker IBM Tools 0 Tue Sep 12, 2017 1:42 am
No new posts BUILD OUTFIL based on condition other... balaji81_k DFSORT/ICETOOL 13 Fri Sep 08, 2017 11:06 pm
This topic is locked: you cannot edit posts or make replies. Extract all "IF" Statements... Adarsh Damodaran CLIST & REXX 1 Wed Sep 06, 2017 9:28 am

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