IBM MAINFRAME HELP & SUPPORT FORUMS
Technical Forums for IBM Mainframe Applications like COBOL, JCL, CICS, DB2, FileAid, DFSORT, Endevor, Xpediter, CoolGen, CA-7&11, AbendAid, IMS, IDMS, PL/I, MqSeries, SyncSort, Assembler, ChangeMan, Easytrieve, InterTest, REXX, CLIST etc...
 

STRING cmd to concatenate fields in semicolon delimited fmt

THIS IS AN ARCHIVE FORUM: CLICK HERE TO GO TO THE ORIGINAL TOPIC

 
       IBMMAINFRAMES.com - IBM Mainframe Support Forums Index -> Mainframe COBOL
View previous topic :: View next topic  
Author Message
annu zacson



Joined: 19 Aug 2008
Posts: 5
Location: Cochin

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

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  
dbzTHEdinosauer



Joined: 20 Oct 2006
Posts: 1639
Location: germany

Posted: Tue Aug 19, 2008 2:38 pm    Post subject:  

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  
Sambhaji



Joined: 16 Feb 2007
Posts: 267
Location: Pune, India

Posted: Tue Aug 19, 2008 2:40 pm    Post subject:  

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  
dick scherrer



Joined: 23 Nov 2006
Posts: 8733
Location: 221 B Baker St

Posted: Tue Aug 19, 2008 7:24 pm    Post subject:  

Hello,

From the posted example, the input appears fixed-length. "Separation" is accomplished by using the input field names.
Back to top  
annu zacson



Joined: 19 Aug 2008
Posts: 5
Location: Cochin

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

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  
Sambhaji



Joined: 16 Feb 2007
Posts: 267
Location: Pune, India

Posted: Mon Aug 25, 2008 11:15 am    Post subject:  

Can you please show how your output will look like?
I didn't get what exactly you want?
Back to top  
annu zacson



Joined: 19 Aug 2008
Posts: 5
Location: Cochin

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

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  
dbzTHEdinosauer



Joined: 20 Oct 2006
Posts: 1639
Location: germany

Posted: Mon Aug 25, 2008 12:42 pm    Post subject:  

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  
Sambhaji



Joined: 16 Feb 2007
Posts: 267
Location: Pune, India

Posted: Mon Aug 25, 2008 1:58 pm    Post subject:  

hey.... :evil:
code given by Dick Brenholtz does exactly same you want....
Back to top  
annu zacson



Joined: 19 Aug 2008
Posts: 5
Location: Cochin

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

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  
 
       IBMMAINFRAMES.com - IBM Mainframe Support Forums Index -> Mainframe COBOL
Page 1 of 1
THIS IS AN ARCIVE FORUM IN READ ONLY MODE. IF YOU WANT TO ASK YOUR DOUBTS USE THE ACTUAL FORUM