MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

formatting output in REXX

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF
View previous topic :: View next topic  
Author Message
John Corbin
Beginner


Joined: 23 Jan 2004
Posts: 38
Topics: 21

PostPosted: Thu Jan 29, 2004 10:59 am    Post subject: formatting output in REXX Reply with quote

Hi....

I have raw output that looks like this:

AMP AAI MAA - ..SAB2
AMP AAI EAA - ..SAB4
AMP CRDP AJT - ..SAF2
AMP CRDP SUP - ..SAF6

The dots (.. ) in the last entry of each row are garbbage characters that I want get rid of.

I have created REXX code to format it so that each row is reformattred to look like this:

AMP AAI MAA - SAB2
AMP AAI EAA - SAB4
AMP CRDP AJT - SAF2
AMP CRDP SUP - SAF6

Basically each row contains 5 parts and Each can be a maximum of 7 characters in length. If an entry is not 7 characters in lerngth then it it s padded and left justitfied to 7 characters.


I can get the padding and left justified but the garbage characters are not being stripped off.

Here is my rexx code:

goodrange = Xrange('A','I') || Xrange('J','R') || Xrange('S','Z') ||,
Xrange('0','9')
PARSE VAR fastpth a1 a2 a3 a4 a5

part1=left(strip(TRANSLATE(a1,goodrange,' '),'L'),7)
part2=left(strip(TRANSLATE(a2,goodrange,' '),'L'),7)
part3=left(strip(TRANSLATE(a3,goodrange,' '),'L'),7)
part4=left(strip(TRANSLATE(a4,goodrange,' '),'L'),7)
part5=left(strip(TRANSLATE(a5,goodrange,' '),'L'),7)

Can anyone see an obvious error ?

Does REXX care how function calls are nested ?
Back to top
View user's profile Send private message
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Thu Jan 29, 2004 3:19 pm    Post subject: Reply with quote

You are translating blanks to something. Try this...
Code:

/* REXX */                                                     
line= "AMP AAI MAA - "||'0203'x||"SAB2 "                       
parse var line p1 p2 p3 p4 rest                               
valid='ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'                   
trtable=translate(xrange('00'x,'ff'x),,valid,' ')             
rest=translate(rest,' ',trtable)                               
say space(p1 p2 p3 p4 rest)                                   


or if you inisist on nested functions Smile
Code:
                                                               
say space(subword(line,1,4),                                   
translate(subword(line,5),' ',translate(xrange('00'x,'ff'x),,,
'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890' , ' ')))


This probably could use some explaination. What you want for the final translate() is all the characters that are invalid. The function
Code:
translate(xrange('00'x,'ff'x),,valid,' ')
creates a string (translate table) wherein all valid characters are turned into blanks and all invalid ones remain. Then the final translate can be used to change the invalid characters in your string to blanks. As you can see, Rexx handles nested functions just fine, though as this example shows, it can make for some impossible to read code.
Back to top
View user's profile Send private message Visit poster's website
John Corbin
Beginner


Joined: 23 Jan 2004
Posts: 38
Topics: 21

PostPosted: Fri Jan 30, 2004 11:13 am    Post subject: Reply with quote

I am confused...

What is wrong with the translate I used ....

part5=left(strip(TRANSLATE(a5,goodrange,' '),'L'),7)

I understood this to raed...

Anything in a5 that is not in goodrange, make it a blank...
Back to top
View user's profile Send private message
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Fri Jan 30, 2004 12:12 pm    Post subject: Reply with quote

It means translate all blanks in a5 to the first character of goodrange.
A good explanation is here.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group