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
 

 

Array to Array movement in REXX

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> CLIST & REXX
View previous topic :: :: View next topic  
Author Message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Fri May 22, 2009 4:26 pm    Post subject: Array to Array movement in REXX
Reply with quote

I have the below set of records in a stem variable say ABC.

Code:
ABCD.EFGHI.JKLM.OPFGTH
&ADDED                               
ABCD.EFGHI.JKLM.OPFGTH1
&DISC


I want to filter only rows which starts with '&' into another stem variable called AB.

Code:
&DISC
&ADDED


Below code is not working

Code:
Do J = 1 to ABC.0           
  If Pos("&",ABC.J) = 0 Then
  AB.J = ABC.J             
End     


Need information on the same.
Back to top
View user's profile Send private message

expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Fri May 22, 2009 4:34 pm    Post subject:
Reply with quote

Where do you set the value for AB.?
Putting data into AB.0 will do you no good at all
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Fri May 22, 2009 4:51 pm    Post subject:
Reply with quote

Quote:
If Pos("&",ABC.J) = 0 Then


Suggest you look-up the POS function:
Quote:
...returns the position of one string, needle, in another, haystack....


here is the Link.

Also, even experienced REXX coders use the TRACE facility to always to debug their code.
Had you done so, you would not have had to make this post.
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Fri May 22, 2009 5:31 pm    Post subject: Reply to: Array to Array movement in REXX
Reply with quote

that's a typo there

Code:
AB.0 = 0                   
J = 1                       
Do I = 1 to ABC.0           
  If Pos("&",ABC.I) = 1 Then
  AB.J = ABC.I             
  J = J + 1                 
End


I don't see the output of the Pos, after these statements

Code:
Do I = 1 to AB.0           
  Say Right(I,2) AB.I       
End


What could be the reasons?
Back to top
View user's profile Send private message
superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Fri May 22, 2009 5:43 pm    Post subject: Reply to: Array to Array movement in REXX
Reply with quote

This worked for me:
Code:

J = 0                             
DO I = 1 TO ABC.0                 
  IF POS("&",ABC.I) = 1 THEN       
    DO                             
      J = J + 1                   
      AB.J = ABC.I                 
      AB.0 = J                     
    END                           
END                               
DO I = 1 TO AB.0                   
  SAY AB.I                         
END                               
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Fri May 22, 2009 5:46 pm    Post subject: Reply to: Array to Array movement in REXX
Reply with quote

Thanks a lot, Kevin
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Fri May 22, 2009 5:49 pm    Post subject:
Reply with quote

We all code differently but I would change
Code:

AB.0 = 0                   
J = 1                       
Do I = 1 to ABC.0           
  If Pos("&",ABC.I) = 1 Then
  AB.J = ABC.I             
  J = J + 1                 
End
to
Code:

AB.0 = 0                   
J = 0                       
Do I = 1 to ABC.0           
  If Pos("&",ABC.I) = 1 Then do
    J = J + 1
    AB.J = ABC.I                 
  End
End
A.0 = J

Because that way the J variable contains the true number of entries in the array, rather than one more than actually exists.
Back to top
View user's profile Send private message
superk

Moderator Team Head


Joined: 26 Apr 2004
Posts: 4648
Location: Raleigh, NC, USA

PostPosted: Fri May 22, 2009 5:49 pm    Post subject: Reply to: Array to Array movement in REXX
Reply with quote

Code:

Do I = 1 to AB.0


You see why that's wrong, I hope. icon_wink.gif
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon May 25, 2009 5:59 pm    Post subject: Reply to: Array to Array movement in REXX
Reply with quote

I was not able to figure out the reason.

Code:
J = 1; DS. = '';       
                       
Do I = 1 to FDS.0     
    Do                 
     DS.J = FDS.I     
     DS.0 = J         
           J = J + 1     
    End               
End                   

Trace I             
I = 0;               
Do I = 1 to DS.0     
  Say Right(I,2) DS.I
End   


For the above code, I get the message listed below, How do I fix it?

Code:
*-* I = 0           
>L>   "0"           
*-* Do I = 1 to DS.0
>L>   "1"           
>V>   ""             
+++  Do I = 1 to DS.0
IRX0041I Error running DSLIMIT, line 80: Bad arithmetic conversion
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Mon May 25, 2009 6:51 pm    Post subject:
Reply with quote

What was the result of displaying DS.0
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon May 25, 2009 7:06 pm    Post subject: Reply to: Array to Array movement in REXX
Reply with quote

0 to N strings like

Code:
ABCD.EFGHI.JKLM.OPFGTH
ABCD.EFGHI.JKLM.OPFGTH1
ABCD.EFGHI.JKLM.OPFGT3
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon May 25, 2009 7:17 pm    Post subject:
Reply with quote

Expat,

did you expect a different answer?
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Mon May 25, 2009 7:33 pm    Post subject:
Reply with quote

dbzTHEdinosauer wrote:
Expat,
did you expect a different answer?

Errrrrrrrrrrrrrrrr just a little icon_cry.gif
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Mon May 25, 2009 7:39 pm    Post subject: Re: Reply to: Array to Array movement in REXX
Reply with quote

HameedAli wrote:
0 to N strings like
Code:
ABCD.EFGHI.JKLM.OPFGTH
ABCD.EFGHI.JKLM.OPFGTH1
ABCD.EFGHI.JKLM.OPFGT3

And substituting your code above
Code:
Do I = 1 to DS.0

we get
Code:
 Do I = 1 to ABCD.EFGHI.JKLM.OPFGTH

So yeah, an arithmatic error is exactly what I would expect to see.

Do you know the use of the .0 variable of a stem. If not, please read the REXX reference manual by clicking the "IBM manuals" button at the top of this page. Quickly.
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Mon May 25, 2009 8:31 pm    Post subject: Reply to: Array to Array movement in REXX
Reply with quote

Oh! Correct me if my understanding is wrong.

I derived this understanding from

Rexx Reference Manual (TSO) by David Grund Sr. Rev 6 – April 27, 2007 Page 53

Quote:
Example 2: Read a disk file into an array
"Alloc fi(DDIn) Da(Rexx.exec(TestData)) shr"
"ExecIO * DiskR DDIn (Stem Lines. Finis "
"Free Fi(DDIn)"
And then, to process the array:
Say "The disk file contains " Lines.0 "lines. Here they
are:"
Do I = 1 to Lines.0
Say Lines.I
End


The above means the array elements of Lines will be displayed from 1 to maximum no of elements.

Is my understanding wrong?
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


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

PostPosted: Mon May 25, 2009 8:51 pm    Post subject:
Reply with quote

Oh my! aren't we touchy?

Hameed Ali,

I ran your code
(after loading FDS.0 with 2, FDS.1 with "on" and FDS.2 with "OFF")
Code:
J = 1; DS. = '';       
                       
Do I = 1 to FDS.0     
    Do                 
     DS.J = FDS.I     
     DS.0 = J         
           J = J + 1     
    End               
End                   

Trace I             
I = 0;               
Do I = 1 to DS.0     
  Say Right(I,2) DS.I
End   


and did not have any problem.

Try using TRACE ?R in the future.
had you done that, we (more importantly you) would know what is in DS.0.

you have left some code out.

Oh, and by the way, I doubt if even David Grund Sr. would refer to a stem variable as an array.
stem.0 is normally used as a counter.

earlier you said something was a 'typo'
stop typing your code, use cut & paste.
Back to top
View user's profile Send private message
expat

Global Moderator


Joined: 14 Mar 2007
Posts: 8593
Location: Back in jolly old England

PostPosted: Tue May 26, 2009 11:25 am    Post subject:
Reply with quote

At this point I suggest that you follow Dicks advice and use TRACE ?R to see exactly what happens where.
Back to top
View user's profile Send private message
HameedAli

Active User


Joined: 16 Apr 2009
Posts: 151
Location: India

PostPosted: Tue May 26, 2009 1:34 pm    Post subject: Reply to: Array to Array movement in REXX
Reply with quote

I was able to fix the issue, with Trace ?R
Thanks Dick Brenholtz and Expat
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1218
Location: Israel

PostPosted: Tue May 26, 2009 8:44 pm    Post subject:
Reply with quote

Instead of using
Code:
If Pos("&",ABC.I) = 1 Then
you should use
Code:
If Left(ABC.I,1) = "&" Then

Why is it better?
LEFT will take the leftmost character and compare it to "&"
POS will search the whole string for "&" and compare result to 1

Why is it important?
I have no idea. I only know that LEFT is the right tool for the job, and POS is not.
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 -> CLIST & REXX All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts What is the command to check MODE of ... rohanthengal CLIST & REXX 6 Fri Nov 18, 2016 1:48 pm
This topic is locked: you cannot edit posts or make replies. Rexx to create GDG by scanning JJ result krish.deepu CLIST & REXX 5 Tue Oct 25, 2016 5:32 pm
No new posts Replace repeated JCL with looping REXX prino CLIST & REXX 3 Thu Oct 13, 2016 5:30 am
This topic is locked: you cannot edit posts or make replies. Need to code a Rexx PGM sundaram.naveen CLIST & REXX 18 Thu Oct 06, 2016 6:45 pm
No new posts Need Rexx Program to Load in to DB2 T... Hareesh Verma CLIST & REXX 22 Tue Sep 20, 2016 2:59 pm


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