View previous topic :: View next topic
|
Author |
Message |
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 55 Location: India
|
|
|
|
Hi,
I have a title records which is of length 13 and I need to write a layout in rexx.
For example,
Record of length - 133
Code: |
CLAIM NUMBER CO LOSS IND |
Layout
Code: |
01 WS-TITLE1.
05 FILLER PIC X(1) VALUE SPACES.
05 WS-H1 PIC X(4) VALUE 'CLAIM'.
05 FILLER PIC X(1) VALUE SPACES.
05 WS-H2 PIC X(6) VALUE 'NUMBER'.
05 FILLER PIC X(4) VALUE SPACES.
05 WS-H3 PIC X(2) VALUE 'CO'
05 FILLER PIC X(1) VALUE SPACES.
05 WS-H4 PIC X(4) VALUE 'LOSS'.
05 FILLER PIC X(1) VALUE SPACES.
05 WS-H5 PIC X(3) VALUE 'IND'.
05 FILLER PIC X(106) VALUE SPACES. |
|
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Well done, off you go then, and thanks for letting us know.
If you have any questions, please feel free to ask them. |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
Quote: |
and I need to write a layout in rexx.
|
Why? REXX does not use layouts. What you may be able to use is stem variables e.g.
Code: |
WS-Title1.WS-H1
WS-Title1.WS-H2
etc. |
Then you you either parse input into these stem variables or concatenate them (with appropriate spacing) into an output variable. REXX variables do not have attributes such as used in Cobol or PL/1.
Garry. |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Garry,
I guess the TS is trying to generate COBOL layout statements from a input string using REXX. But then, only TS knows exactly what he is trying to do. |
|
Back to top |
|
|
venkatatcts
New User
Joined: 16 Mar 2009 Posts: 55 Location: India
|
|
|
|
Yes exactly. I need a help how to calculate filler when there is a space and length for each variable in rexx.
Thanks. |
|
Back to top |
|
|
Garry Carroll
Senior Member
Joined: 08 May 2006 Posts: 1193 Location: Dublin, Ireland
|
|
|
|
venkatatcts wrote: |
Yes exactly. I need a help how to calculate filler when there is a space and length for each variable in rexx.
Thanks. |
And still we have no idea what you are trying to achieve or why ! Are you inputting data to build a record or are you extracting data from a record?
The LENGTH function will tell you how many bytes the variable currently occupies. LEFT and RIGHT functions will allow you to extract data from the LEFT or RIGHT of a variable padding the result to a specified length. POS will give the position of a given value (e.g. space) in a variable...... The list goes on and on....
Garry. |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Hello,
Refer the string manipulation functions
LENGTH - to get the length of a string,
WORDS - to determine the number of words in a string,
WORD - to get a particular WORD from a string.
With these 3 functions and some looping based on the number of words on the string,and with some appending, the requirement could be done. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
edited to fix a glitch ( the TS did not BBCODE the sample string )
I mildly disagree
a smarter parsing is needed, WORD,WORDS and friends will ignore the spaces
but a trick with POS will fix it
since I am in a very very good good mood mood here is a snippet ,
most probably very dirty, since it was very quick
Code: |
#!/opt/oorexx/bin/rexx
trace "O"
/* 1234567890123456789012345678901234567890 */
string = "CLAIM CLAIM NUMBER CO LOSS IND"
string = " CLAIM NUMBER CO LOSS IND"
lrec = 133
leng = 0
offs01 = 7
offs05 = 10
stmt.1 = copies(" ",offs01) || "01 WS-TITLE"
stmt.0 = 1
f = 0 /* field number */
curr = 1
do i = 1 to words(string)
w = word(string,i)
next = pos(w,string,curr)
if next > curr then do
flen = next-curr
leng = leng+flen
s = stmt.0+1
stmt.s = copies(" ",offs05) || "05 "left("FILLER",8) left("PIC X("flen")",10) "VALUE SPACES."
stmt.0 = s
curr = next
end
wlen = length(w)
f = f + 1
s = stmt.0+1
stmt.s = copies(" ",offs05) || "05 "left("WS-H"f,8) left("PIC X("wlen")",10) "VALUE '"w"'."
stmt.0 = s
leng = leng + wlen
curr = curr + length(w)
end
if lrec > leng then do
s = stmt.0+1
stmt.s = copies(" ",offs05) || "05 "left("FILLER",8) left("PIC X("lrec-leng")",10) "VALUE SPACES."
stmt.0 = s
end
do s = 1 to stmt.0
say right(s,2) stmt.s
end
exit
|
and here is the result ( Your computations for the final filler were wrong )
Code: |
1 01 WS-TITLE
2 05 FILLER PIC X(1) VALUE SPACES.
3 05 WS-H1 PIC X(5) VALUE 'CLAIM'.
4 05 FILLER PIC X(1) VALUE SPACES.
5 05 WS-H2 PIC X(6) VALUE 'NUMBER'.
6 05 FILLER PIC X(4) VALUE SPACES.
7 05 WS-H3 PIC X(2) VALUE 'CO'.
8 05 FILLER PIC X(1) VALUE SPACES.
9 05 WS-H4 PIC X(4) VALUE 'LOSS'.
10 05 FILLER PIC X(1) VALUE SPACES.
11 05 WS-H5 PIC X(3) VALUE 'IND'.
12 05 FILLER PIC X(105) VALUE SPACES.
|
it takes into account also multiple spaces ...
tested on my mac using Object REXX,but since the snippet does not use anything platform specific, it will work also on TSO
if I have time tomorrow I might IPL zOS and test under TSO
if somebody asks why I provided the snippet...
I coded it instead of solving a crossword puzzle
but for what reason is not enough to code
Code: |
01 WS-title.
05 FILLER PIC X(1) VALUE SPACES.
05 FILLER PIC X(132) VALUE 'CLAIM NUMBER CO LOSS IND'. |
I strongly suggest that everybody install on his/her PC object REXX
it is very handy for quick and dirty proofs of concepts |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Quote: |
WORD,WORDS and friends will ignore the spaces |
I did not notice that the filler sizes were different.
The code above is slick. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
I did not notice that the filler sizes were different. |
in the sample posted the <words> were separated by one single space,
but since that is an uncommon situation in titles I was being proactive in providing a more general approach
the starting post was bbcoded for clarity and my snippet was abridged ! |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
To make it more general the desired record length should also be passed. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
Quote: |
To make it more general the desired record length should also be passed. |
when doing a proof of concept I rarely care to pass the parameters,
it' s boring to retype them every time a test is run!
furthermore while it might be simple to pass the lrecl for the title line,
not the same can be said for the string , parsing parms with multiple space
is not trivial for a newcomer!
but here is how to do it
Code: |
000008 Parse arg args
==CHG> strdel = left(args,1)
000010 strstr = 2
==CHG> iif verify(strdel,"""'","M") = 0 then do
000012 say "no starting string delimiter"
000013 exit
000014 end
==CHG> strend = pos(strdel,args,strstr)
000016 if strend = 0 then do
000017 say "no ending string delimiter"
000018 exit
000019 end
000020 strlen = strend - strstr
000021 string = substr(args,strstr,strlen)
000022 say length(string) ">>>"string"<<<"
000023 lrecl1 = strip(substr(args,strend+1))
000024 if lrecl1 = "" then lrecl1 = 133
000025 say lrecl1
000026 exit
|
tested and working ( at least it was before the cut and paste
for proper string handling must be invoked with
<rexxscriptname> 'a b c d e f' <lrecl>
<rexxscriptname> "a b c d e f" <lrecl>
anyway some care must be taken when writing scripts for different environments
under tso the apost's and the quotes are passed
so it is quite easy to determine a string argument
under unix like the apost' s and quotrs are not passed
and while the spaces are mantained all the pams are junked in one big string
so it is pretty complicated to pass more than one parameter
but for proper handling also the length of the title string should be tested agains the lrecl and the script failed if greater ! |
|
Back to top |
|
|
vasanthz
Global Moderator
Joined: 28 Aug 2007 Posts: 1742 Location: Tirupur, India
|
|
|
|
Ahem.. ahem.. Someone seems to be in extremely good-mood streak (: |
|
Back to top |
|
|
|