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 Usergroups Profile Log in to check your private messages Log in
 

 

STRING cmd to concatenate fields in semicolon delimited fmt

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
annu zacson

New User


Joined: 19 Aug 2008
Posts: 15
Location: Cochin

PostPosted: Tue Aug 19, 2008 2:29 pm    Post subject: STRING cmd to concatenate fields in semicolon delimited fmt
Reply with quote

I have to create an output file in a semicolon delimited format. How to use STRING command to perform this:
For eg:
Assume the input data is given below:
customer id Account No First Name Last Name
001 2345 Mark Parker
002 4567 Any James
003 Missing field John Hanes

The output file should be:
001;2345;Mark;Parker;;
002;4567;Any;James;;
003;;John;Hanes;;

I need a semicolon at the end of each field plus at the end of each record.
If any fields are missing, it should be denoted a semicoln as specified in the third row.
please let me know how to do this using STRING command in cobol?
Back to top
View user's profile Send private message

dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Tue Aug 19, 2008 2:38 pm    Post subject:
Reply with quote

i assume a missing field is all spaces.
you can start with this:

Code:

string field-1 delimited by spaces
         ';'
         field-2 delimited by spaces
         ';'
   into receiving-field
end-string
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue Aug 19, 2008 2:40 pm    Post subject:
Reply with quote

how you r seperating fields from input file?
is it fixed length input file?

or is there a space in between two fields of input file?
Back to top
View user's profile Send private message
dick scherrer

Site Director


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

PostPosted: Tue Aug 19, 2008 7:24 pm    Post subject:
Reply with quote

Hello,

From the posted example, the input appears fixed-length. "Separation" is accomplished by using the input field names.
Back to top
View user's profile Send private message
annu zacson

New User


Joined: 19 Aug 2008
Posts: 15
Location: Cochin

PostPosted: Mon Aug 25, 2008 8:31 am    Post subject: Reply to: STRING cmd to concatenate fields in semicolon deli
Reply with quote

Thanks for helping me out.
My input file is of fixed length and looks like this:
amex_cust_id A/N 12
cust_acct_ky N 11
national_id A/N 20
gender_cd A 01
last_nm A/N 30
cm_first_nm A/N 20

cm_mid_initl_nm A/N 20

my second doubt is , how will i remove the trailing spaces? for example, for the field last_nm, if the last_nm is only 5 chars, the actual length is 30 chars, so how ill i remove the last 25 chars so that i can concatenate that field in semicolon delimited format with the next field cm_first_nm?
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon Aug 25, 2008 11:15 am    Post subject:
Reply with quote

Can you please show how your output will look like?
I didn't get what exactly you want?
Back to top
View user's profile Send private message
annu zacson

New User


Joined: 19 Aug 2008
Posts: 15
Location: Cochin

PostPosted: Mon Aug 25, 2008 12:41 pm    Post subject: Reply to: STRING cmd to concatenate fields in semicolon deli
Reply with quote

Suppose my input file is like this (please see attachment) with the structure declared above:
Here Nat_id is declared as 20 CHARS. but the value is N12345. So i need to remove the trailing spaces ie 14 chars and concatenate with the next field.
so the output will look like this:
37222222222;111111111111;N12345;M;PARKER;A;MARK;;

The output file is also of the same record length as input file.
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Mon Aug 25, 2008 12:42 pm    Post subject:
Reply with quote

annu,

the example STRING instruction that I provided does just that.

I am afraid that you will just have to look at the documentation explaining the COBOL STRING instruction,
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Mon Aug 25, 2008 1:58 pm    Post subject:
Reply with quote

hey.... icon_evil.gif
code given by Dick Brenholtz does exactly same you want....
Back to top
View user's profile Send private message
annu zacson

New User


Joined: 19 Aug 2008
Posts: 15
Location: Cochin

PostPosted: Mon Aug 25, 2008 3:40 pm    Post subject: Reply to: STRING cmd to concatenate fields in semicolon deli
Reply with quote

That code is giving an error as it is telling STRING function cannot be found. So I wrote like this:
string field-1 ';'
field-2 ';' ‘;’
into receiving-field DELIMITED BY SPACES
end-string

now its working..
Thanks.
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 Syncsort Help to group fields sudhakarraju SYNCSORT 6 Thu Dec 29, 2016 1:38 am
No new posts SQZ pipe delimited file with 1 column... Rick Silvers DFSORT/ICETOOL 2 Sun Nov 06, 2016 8:11 pm
No new posts Access SQLCA fields inside a stored p... gangapd DB2 4 Thu Oct 27, 2016 10:20 am
No new posts To trim spaces in a pipe delimited da... Nish84 COBOL Programming 16 Mon Oct 10, 2016 1:54 pm
This topic is locked: you cannot edit posts or make replies. Checking wether a string starts from ... sundaram.naveen CLIST & REXX 9 Thu Oct 06, 2016 11:56 am


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