Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Stems and internal functions

Status
Not open for further replies.

KiwiREXXDude

Programmer
May 27, 2003
95
AU
I am trying to get a protected internal function to read a passed stem on the OS/390 mainframe without much luck. I know you can do it because I have done it at another site.

This is what I think should happen;
Code:
rv = MyFunc(STEM1.)
return

MyFunc: procedure
  arg InStem.
  do i = 1 to InStem.0
    say 'Line 'i' = 'InStem.i
  end
  return 1

The REXX version is 3.48.
 
Sorry, KiwiREXXDude, this won't work on standard REXX. Arguments to the call statement (or function calls) are always 'call by value' arguments - not 'call by reference'. This means you can only pass a single value as an argument.

If it is an internal subroutine - as in your sample - the stem variable STEM1. has a global and you could use it directly in the subroutine. This would not work, if you make MyFunc an external subroutine.

This feature is really missing in REXX ... if you need to pass multiple lines of data, you could use the REXX queue (stack) for that purpose...

regards
Wolfgang
 
Wolfgang, thanks for the response.

What I want to do is have 2 or more stems which can both be processed by a single internal subroutine. I have sort of accomplished it my passing in the name of the stem and then using interpret, but I have an adversion to using interpret for some reason.

I have done a bit of ObjectREXX development where you can pass stems and arrays between objects and that would just make things entirely too easy.

Are IBM planning on releasing an updated version of OS/390 REXX I wonder?
 
You have probably found a solution to this by now (August) but in case you are still interested, the following code works using IBM Object REXX on Windows XP. The code uses standard code not the object stuff (struggling to understand that!!!)

It is wrapping around a lot in this panel so if you want me to email it you just let me know.

Regards
Chris Bezant

/***********************************************************************************************/
/* Set up a TEST stem and add some initial data */
/***********************************************************************************************/
test. = ''
test.1 = 'Fred'
test.2 = 'jim'
test.0 = 2

/***********************************************************************************************/
/* Display the initial contents */
/***********************************************************************************************/
do i = 1 to test.0
say 'Test.'i '=' test.i
end
say

/***********************************************************************************************/
/* Set up a TEST stem and add some initial data */
/***********************************************************************************************/
trial. = ''
trial.1 = 'Jane'
trial.2 = 'Freda'
trial.0 = 2

/***********************************************************************************************/
/* Display the initial contents */
/***********************************************************************************************/
do i = 1 to trial.0
say 'Trial.'i '=' trial.i
end
say

/***********************************************************************************************/
/* Now add extra data to the stem and re-display its contents */
/***********************************************************************************************/
TempData = 'Charlie'
call AddToArray 'test. TempData'
TempData = 'Arthur'
call AddToArray 'test. TempData'
do i = 1 to test.0
say 'Test.'i '=' test.i
end
say

/***********************************************************************************************/
/* Now add extra data to the stem and re-display its contents */
/***********************************************************************************************/
TempData = 'Annabelle'
call AddToArray 'trial. TempData'
TempData = 'Sheila'
call AddToArray 'trial. TempData'
do i = 1 to trial.0
say 'Trial.'i '=' trial.i
end
say

return


/*==============[ Pass the array name in as a string and the value to be assigned ]===============*/

AddToArray:
/***********************************************************************************************/
/* Arguments must not have comma separators. */
/* Data to be stored must be in a variable. */
/* The call must be of the form AddToArray 'arrayname. data' */
/***********************************************************************************************/

/***********************************************************************************************/
/* The arguments are stored in the special RESULT variable because it is a variable known to */
/* exist and it is safe to borrow it at this point. This entry point is not in a procedure and */
/* therefore can see the common variables so if we used our own variable name it might */
/* conflict with a variable name used elsewhere in the code. The argument variable names are */
/* exposed in the called routine by using the temporary contents of the RESULT variable. */
/***********************************************************************************************/
result = arg(1) /* store args to expose them in procedure */

/***********************************************************************************************/
/* Call the real code to do the job with the passed arguments. By convention we use the same */
/* name as the entry point above prepended with an underscore. */
/***********************************************************************************************/
call _AddToArray arg(1)

return

_AddToArray:
/***********************************************************************************************/
/* Woody's appendStem routine. Append a value to a stem variable; Increment the count stored */
/* in stem.0 */
/***********************************************************************************************/

/***********************************************************************************************/
/* As this is a procedure all variables are localised except the input parameter variables. */
/* The use of underscores in local variable names is a convention not a requirement. */
/***********************************************************************************************/
procedure expose ( result ) /* expose the argument variables */
parse arg _stemname _stemvalue /* separate the arguments */
_num = value(_stemname || '0') + 1 /* increment the index value */
call value _stemname || '0', _num /* assign new index value to 0 element */
call value _stemname || _num, value(_stemvalue) /* assign value to new element */
return

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top