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

STRING cmd to concatenate fields in semicolon delimited fmt


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
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
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

Moderator Emeritus


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

PostPosted: Tue Aug 19, 2008 7:24 pm
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
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
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
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
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Sortjoin and Search for a String and ... DFSORT/ICETOOL 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts Search string in job at regular Spool... CLIST & REXX 0
Search our Forums:

Back to Top