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

Peculiar file formatting using cobol


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
sub7

New User


Joined: 12 Sep 2005
Posts: 9

PostPosted: Wed Aug 12, 2009 8:54 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Wed Aug 12, 2009 9:28 pm
Reply with quote

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
View user's profile Send private message
sub7

New User


Joined: 12 Sep 2005
Posts: 9

PostPosted: Wed Aug 12, 2009 9:59 pm
Reply with quote

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
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Thu Aug 13, 2009 1:27 am
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sat Aug 15, 2009 10:29 pm
Reply with quote

Just curious, Sub, how will you use the O/P?
Back to top
View user's profile Send private message
sub7

New User


Joined: 12 Sep 2005
Posts: 9

PostPosted: Sat Aug 15, 2009 10:41 pm
Reply with quote

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
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Sun Aug 16, 2009 1:59 am
Reply with quote

Hi Neo,

Sounds like it's a CSV file variation.

Thanx and
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 Compare 2 files and retrive records f... DFSORT/ICETOOL 3
No new posts FTP VB File from Mainframe retaining ... JCL & VSAM 8
No new posts Extract the file name from another fi... DFSORT/ICETOOL 6
No new posts How to split large record length file... DFSORT/ICETOOL 10
No new posts Replace each space in cobol string wi... COBOL Programming 3
Search our Forums:

Back to Top