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



IBM's Command List programming language & Restructured Extended Executor

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

Postby deucalion0 » Wed Dec 03, 2014 5:18 pm

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
deucalion0
 
Posts: 58
Joined: Thu Jul 31, 2014 3:47 pm
Has thanked: 32 times
Been thanked: 0 time

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

Postby enrico-sorichetti » Wed Dec 03, 2014 5:40 pm

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"

cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

These users thanked the author enrico-sorichetti for the post:
deucalion0 (Wed Dec 03, 2014 7:49 pm)
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

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

Postby deucalion0 » Wed Dec 03, 2014 7:48 pm

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!
deucalion0
 
Posts: 58
Joined: Thu Jul 31, 2014 3:47 pm
Has thanked: 32 times
Been thanked: 0 time

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

Postby enrico-sorichetti » Wed Dec 03, 2014 7:53 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

These users thanked the author enrico-sorichetti for the post:
deucalion0 (Wed Dec 03, 2014 8:34 pm)
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

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

Postby deucalion0 » Wed Dec 03, 2014 8:50 pm

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!
deucalion0
 
Posts: 58
Joined: Thu Jul 31, 2014 3:47 pm
Has thanked: 32 times
Been thanked: 0 time

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

Postby enrico-sorichetti » Wed Dec 03, 2014 9:13 pm

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
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort

These users thanked the author enrico-sorichetti for the post:
deucalion0 (Thu Dec 04, 2014 1:06 am)
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

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

Postby prino » Wed Dec 03, 2014 10:51 pm

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.
Robert AH Prins
robert.ah.prins @ the.17+Gb.Google thingy

These users thanked the author prino for the post:
deucalion0 (Thu Dec 04, 2014 1:06 am)
User avatar
prino
 
Posts: 635
Joined: Wed Mar 11, 2009 12:22 am
Location: Vilnius, Lithuania
Has thanked: 3 times
Been thanked: 28 times

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

Postby enrico-sorichetti » Wed Dec 03, 2014 11:50 pm

nice trick Robert !
cheers
enrico
When I tell somebody to RTFM or STFW I usually have the page open in another tab/window of my browser,
so that I am sure that the information requested can be reached with a very small effort
enrico-sorichetti
Global moderator
 
Posts: 2994
Joined: Fri Apr 18, 2008 11:25 pm
Has thanked: 0 time
Been thanked: 164 times

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

Postby deucalion0 » Thu Dec 04, 2014 1:07 am

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!

:)
deucalion0
 
Posts: 58
Joined: Thu Jul 31, 2014 3:47 pm
Has thanked: 32 times
Been thanked: 0 time


Return to CLIST & REXX

 


  • Related topics
    Replies
    Views
    Last post