Page 1 of 1

Is it possible to read a STEM index and then replace?

PostPosted: Wed Dec 03, 2014 5:18 pm
by deucalion0
Hello all,

I want to write to Rexx to read in a member to a STEM variable and then check if a line has specific text, if so then replace it with new text, I am struggling to get my head around REXX syntax.

This is what I have tried so far:
DO WHILE I <= MYFILE.0           
   IF MYFILE.I =="TEXT I WISH TO REPLACE" THEN DO
   MYFILE.I == NEW TEXT               
   END                           
   SAY ' LINE ' I ' : ' MYFILE.I 
   I = I + 1   



I do hope this sort of code is possible using REXX, but I cannot seem to find any examples of this.

Any assistance with my code would be greatly appreciated!!

My goal is to replace a specific line in a member with a new line of text.

Thank you for your time!!

Code'd

Re: Is it possible to read a STEM index and then replace?

PostPosted: Wed Dec 03, 2014 5:40 pm
by enrico-sorichetti
DO WHILE I <= MYFILE.0
IF MYFILE.I =="TEXT I WISH TO REPLACE" THEN DO
MYFILE.I == NEW TEXT
END
SAY ' LINE ' I ' : ' MYFILE.I
I = I + 1


a better construct would be ...

do i = 1 to myfile.0
   if myfile.i = "text i wish to replace" then ,
      myfile.i = "new text"
   say ' line ' i ' : ' myfile.i
end


read the manual about the differences of using the strict comparison operator == V.S. the normal comparison operator =
and test Yourself with different tokens

remember that initially rexx treats everything as a string

also remember that == is not an assignment operator

if   "a" = "a    " then ,
   say '"a" = "a    "' "is true"
else ,
   say '"a" = "a    "' "is false"

if   "a" == "a    " then ,
   say '"a" == "a    "' "is true"
else ,
   say '"a" == "a    "' "is false"

if   1 = 0001  then ,
   say '1 = 0001' "is true"
else ,
   say '1 = 0001' "is false"

if   1 == 0001  then ,
   say '1 == 0001' "is true"
else ,
   say '1 == 0001' "is false"


Re: Is it possible to read a STEM index and then replace?

PostPosted: Wed Dec 03, 2014 7:48 pm
by deucalion0
Enrico, thank you so very much, this is the second time you have been a great help to me with Rexx!

I appreciate you taking the time to explain your code to me as well!

I need to get used to Rexx, I come from Java and C#, and find Rexx syntax quite different.

What is your go to manual for Rexx?

I have bookmarked lots of sites but I do not know if there is just one ultimate resource.

Thanks again!

Re: Is it possible to read a STEM index and then replace?

PostPosted: Wed Dec 03, 2014 7:53 pm
by enrico-sorichetti
here is mother of the links for IBM software

http://www-03.ibm.com/systems/z/os/zos/ ... index.html

the rex stuff is in the TSO bookshelf

Re: Is it possible to read a STEM index and then replace?

PostPosted: Wed Dec 03, 2014 8:50 pm
by deucalion0
Thank you Enrico, I have bookmarked this! :)


My problem is breaking down what i need to know, coming from different languages and using certain techniques, how to translate these techniques into Rexx.

For example, my next issue is trying to access a stem using a variable +1 like so:

MYFILE.I+1 = "Some text"


I want to edit two lines of the stem variable within one loop of code by directly accessing the next stem index by adding 1 to I, but I get a bad arithmetic error.

So I looked at the arithmetic section of the IBM manual and the Stem variables section, without seeing an example of this. So either I am not very good at looking stuff up or I am trying to do something which cannot be done.

What area would you say that this problem comes under?

Again I appreciate your consistent help!

Re: Is it possible to read a STEM index and then replace?

PostPosted: Wed Dec 03, 2014 9:13 pm
by enrico-sorichetti
MYFILE.I+1

the stem *index MUST be a VARIABLE or CONSTANT ... not an expression

* index is a bit improper, stems are not really arrays

Re: Is it possible to read a STEM index and then replace?

PostPosted: Wed Dec 03, 2014 10:51 pm
by prino
deucalion0 wrote:For example, my next issue is trying to access a stem using a variable +1 like so:

MYFILE.I+1 = "Some text"

I want to edit two lines of the stem variable within one loop of code by directly accessing the next stem index by adding 1 to I, but I get a bad arithmetic error.


j = i + 1
MYFILE.j = "Some text"

or

call value 'MYFILE.'i+1, "Some text"

or

interpret 'MYFILE.'i+1'="Some text"'

And for what it's worth, case is rarely significant in REXX, but many of us prefer to see REXX written in lowercase.

Re: Is it possible to read a STEM index and then replace?

PostPosted: Wed Dec 03, 2014 11:50 pm
by enrico-sorichetti
nice trick Robert !

Re: Is it possible to read a STEM index and then replace?

PostPosted: Thu Dec 04, 2014 1:07 am
by deucalion0
Thank you very much Robert for the various ways in which I can achieve this! I have experimented tonight and have now gotten what I wanted as well as a better understanding of Rexx syntax!

Thank you also Enrico again for your explanations!

:)