Page 1 of 1

text split in rexx

PostPosted: Sun Jun 03, 2012 1:27 am
by venkateshm
I'm working on migration. If i have a copybook in the below format, whenever line has //(double slash) it must be shifted into other line as a comment. How can I achieve this using REXX (OR MACROS).
INPUT:
01 group.
    05 st-details pic 9(8)   //student no,class
    05 st-address pic x(10)   //student address, zip-code

Desired OUTPUT:

             01 group.
                   05 st-details pic 9(8).   
          *student no,class (comment)
                   05 st-address pic x(10).   
          *student address,zipcode(comment)

Re: text split in rexx

PostPosted: Sun Jun 03, 2012 3:21 am
by MrSpock
Seems relatively simple:

- Read a record.
- Look for the // in the record.
- If found, Parse the record into variables that contain the portion left of the //, and the portion to the right of the //. Write the left-side and right-side variables as seperate records. Else, just write the record as-is.
- Repeat.

Re: text split in rexx

PostPosted: Sun Jun 03, 2012 11:22 pm
by venkateshm
thank you spock..
As i am new to REXX, i am not that much comfortable to achieve this in rexx. Anyway i will take your inputs and proceed further...

Re: text split in rexx

PostPosted: Mon Jun 04, 2012 12:10 am
by dick scherrer
Hello,

i am not that much comfortable to achieve this in rexx.
The more you work with things, the more comfortable you will become.

If you get stuck along the way, post here what you tried and what went wrong (syntax error, abend, undesired results, etc) and someone should be able to help.

Re: text split in rexx

PostPosted: Mon Jun 04, 2012 2:37 am
by enrico-sorichetti
here is one way to do it ...


#! /usr/bin/rexx

stmt.1 = "01 group."
stmt.2 = "   05 st-details pic 9(8)   //student no,class"
stmt.3 = "   05 st-address pic x(10)   //student address, zip-code"
stmt.0 = 3

do  s = 1 to stmt.0
    temp = strip(stmt.s,"T")
    say "orig >>>"temp"<<<"
    parse var temp stmt "//" cmnt
    stmt = strip(stmt,"T")

    if  stmt = temp then ,
        say "orig >>>"stmt"<<<"
    else do
        stmt = stmt "."
        say "stmt >>>"stmt"<<<"
        cmnt = "*" cmnt
        say "cmnt >>>"cmnt"<<<"
    end
    say
    say
end


I did not space things properly, just a POC on how to split lines.

Re: text split in rexx

PostPosted: Wed Jun 06, 2012 9:46 pm
by venkateshm
Hi,
thank you for your suggestions and inputs.
enrico-sorichetti your logic helped me a lot, thanks...
I got the desired output.