Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Peculiar file formatting using cobol

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Peculiar file formatting using cobol
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    Post subject:
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    Post subject:
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: 1224
Location: Israel

PostPosted: Thu Aug 13, 2009 1:27 am    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Full Time COBOL Software Development ... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:24 am
No new posts COBOL Software Development Lead at Fi... shally Mainframe Jobs 0 Fri Jan 20, 2017 5:21 am
No new posts SORTJOIN - Copy Matched and Unmatched... Steve Ironmonger DFSORT/ICETOOL 5 Tue Jan 17, 2017 4:26 pm
No new posts Executing OO COBOL program invoking J... Virendra Shambharkar COBOL Programming 2 Tue Jan 10, 2017 6:37 pm
No new posts OO COBOL compile error Virendra Shambharkar COBOL Programming 3 Tue Jan 10, 2017 6:05 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us