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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send array to macro

Status
Not open for further replies.

2215903

Programmer
Jun 30, 2006
3
CA

We know we can send a parameter or some parameters to
the macro. How can sen an array to the macro? I have tried this:

submac aarr.

That will not work.

Aprreciate any hint.

 
I didn't write this, I found it. I don't remember where or I'd happily credit the author.

Code:
   /***********************************************************************************************/
   /* 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
 
But , that is not a macro. It is a function call.
However, thanks anyway.


 
Hmm... Sorry, when you said 'macro' I assumed you meant you wanted to pass information between REXX routines being used as an ISPF edit macro.

Good luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top