View previous topic :: View next topic
|
Author |
Message |
sub7
New User
Joined: 12 Sep 2005 Posts: 9
|
|
|
|
Hi Experts,
Need a helping hand here
I have a file having the following layout
Code: |
01 Ws-File-recs.
05 ws-client pic X(4).
05 ws-sec-id pic 9(4).
05 ws-cl-name pic x(50).
05 ws-fee-amount pic 9(9)v9(4).
05 ws-tax-amount pic 9(9)v9(4).
05 ws-type pic x(20) |
Code: |
Sample Input data:
------------------------
12340987Bell Labs 00000000000000000000000012IN..................
56780988Arrow Electronics 12345600000001234300000000NY
12340989HATHWAY 00045678999990076543210000MA.......... |
Code: |
Expected output
--------------------
1234|987|Bell Labs||0.0012|IN|
5678|988|Arrow Electronics|123456000.0000|123430000.0000|NY|
1234|989|HATHWAY|456789.9999|7654321.0000|MA|......... |
]Code'd
My need is to add pipe delimiter after removing leading,trailing space and zero's.I searched in forum but none of those were clear.
Appreciate any help!!
-Neo. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Code: |
01 ws-subscripts.
05 ws-sub-1 pic s9(4) comp.
05 ws-sub-2 pic s9(4) comp.
05 ws-move-ind pic x(01).
move-done value 'y'.
move-not-done value 'n'.
01 wk-work-rec.
05 wk-client pic x(4).
05 wk-sec-id pic x(4).
05 wk-cl-name pic x(50).
05 wk-fee-amount pic x(13).
05 wk-tax-amount pic x(13).
05 wk-type pic x(20).
* remove leading zeros, spaces.
move spaces to ws-work-rec
* ws-client
set move-not-done to true
perform varying ws-sub-1
from 1
by 1
until ws-sub-1 > 4
or move-done
if ws-client(ws-sub-1:1) = space
then
continue
else
ws-length = length(ws-client) - ws-sub-1 + 1
move ws-client(ws-sub-1:ws-length) to wk-client(1:ws-length)
set move-done to true
end-if
end-perform
* ws-sec-id
if ws-sec-id = 0
then
move '0' to wk-sec-id
else
set move-not-done to true
perform varying ws-sub-1
from 1
by 1
until ws-sub-1 > 4
or move-done
if ws-sec-id(ws-sub-1:1) = space or zero
then
continue
else
ws-length = length(ws-sec-id) - ws-sub-1 + 1
move ws-sec-id(ws-sub-1:ws-length) to wk-sec-id(1:ws-length)
set move-done to true
end-if
end-perform
end-if
* ws-cl-name
set move-not-done to true
perform varying ws-sub-1
from 1
by 1
until ws-sub-1 > 4
or move-done
if ws-cl-name(ws-sub-1:1) = space
then
continue
else
ws-length = length(ws-cl-name) - ws-sub-1 + 1
move ws-cl-name(ws-sub-1:ws-length) to wk-cl-name(1:ws-length)
set move-done to true
end-if
end-perform
* ws-fee-amount
if ws-fee-amount = 0
then
move '0' to wk-fee-amount
else
set move-not-done to true
perform varying ws-sub-1
from 1
by 1
until ws-sub-1 > 4
or move-done
if ws-fee-amount(ws-sub-1:1) = zero
then
continue
else
ws-length = length(ws-fee-amount) - ws-sub-1 + 1
move ws-fee-amount(ws-sub-1:ws-length) to wk-fee-amount(1:ws-length)
set move-done to true
end-if
end-perform
end-if
* ws-tax-amount
if ws-tax-amount = 0
then
move '0' to wk-tax-amount
else
set move-not-done to true
perform varying ws-sub-1
from 1
by 1
until ws-sub-1 > 4
or move-done
if ws-tax-amount(ws-sub-1:1) = zero
then
continue
else
ws-length = length(ws-fee-amount) - ws-sub-1 + 1
move ws-tax-amount(ws-sub-1:ws-length) to wk-tax-amount(1:ws-length)
set move-done to true
end-if
end-perform
end-if
* ws-type
set move-not-done to true
perform varying ws-sub-1
from 1
by 1
until ws-sub-1 > 4
or move-done
if ws-type(ws-sub-1:1) = space
then
continue
else
ws-length = length(ws-type) - ws-sub-1 + 1
move ws-type(ws-sub-1:ws-length) to wk-type(1:ws-length)
set move-done to true
end-if
end-perform
* at this point, all fields are left justified in wk-work-rec
* now we string, delimited by spaces
move spaces to ws-output-data
STRING ws-client
delimited by ' ' * one space
'|'
delimited by size
ws-sec-id
delimited by ' ' * one space
'|'
delimited by size
ws-cl-name
delimited by ' ' * two spaces
'|'
delimited by size
ws-fee-amount
delimited by ' ' * one space
'|'
delimited by size
ws-tax-amount
delimited by ' ' * one space
'|'
delimited by size
ws-type
delimited by ' ' * one space
INTO ws-output-data
end-string
|
|
|
Back to top |
|
|
sub7
New User
Joined: 12 Sep 2005 Posts: 9
|
|
|
|
Thank you and I really appreciate for the quick response with code sample.
However do you have any suggestion to the decimal points?
as my need was to format
12340987Bell Labs 00000000000000000000000012IN.................. (INPUT)
to
1234|987|Bell Labs||0.0012|IN| ?
and your code sample above will create
1234|987|Bell Labs||12|IN| - I suppose (No decimals)?
-Neo |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
You can use another work area:
Code: |
05 wk-temp-amount pic Z(8)9.9(4).
|
right after the "else", move ws-fee-amount to wk-temp-amount to wk-fee-amount.
That may be even better:
Code: |
05 wk-temp-amount pic Z(8)9.9(4) BLANK WHEN ZERO.
|
if you want to leave an empty spot. But that require other changes in the code. |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Just curious, Sub, how will you use the O/P? |
|
Back to top |
|
|
sub7
New User
Joined: 12 Sep 2005 Posts: 9
|
|
|
|
mmwife ,this feed is for one of our clients and they need data in this way
Is this what u r asking?
-Neo |
|
Back to top |
|
|
mmwife
Super Moderator
Joined: 30 May 2003 Posts: 1592
|
|
|
|
Hi Neo,
Sounds like it's a CSV file variation.
Thanx and |
|
Back to top |
|
|
|