View previous topic :: View next topic
|
Author |
Message |
annu zacson
New User
Joined: 19 Aug 2008 Posts: 15 Location: Cochin
|
|
|
|
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
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
From the posted example, the input appears fixed-length. "Separation" is accomplished by using the input field names. |
|
Back to top |
|
|
annu zacson
New User
Joined: 19 Aug 2008 Posts: 15 Location: Cochin
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
Can you please show how your output will look like?
I didn't get what exactly you want? |
|
Back to top |
|
|
annu zacson
New User
Joined: 19 Aug 2008 Posts: 15 Location: Cochin
|
|
|
|
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
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
hey....
code given by Dick Brenholtz does exactly same you want.... |
|
Back to top |
|
|
annu zacson
New User
Joined: 19 Aug 2008 Posts: 15 Location: Cochin
|
|
|
|
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 |
|
|
|