hexagon logo

Subroutines - Must I define a variable in the main program?

Is it absolutely necessary to instantiate a variable within the main program before it is called in a subroutine? 

______________________________________________________________________________________

ASSIGN/VAR1=<VALUE>                     <----------------------- IS THIS NECESSARY?

CS1 = CALLSUB/<SUBROUTINE TITLE>,<SUBPROGRAM PATH>:VAR1

***INSIDE SUBROUTINE***

SUBROUTINE/<SUBROUTINE TITLE>,

sVAR1 = <DEFAULT VALUE> : <DESCRIPTION>

ASSIGN/sVAR1=<VALUE> + 1

ENDSUB/

COMMENT/OPER,NO,FULL SCREEN=NO,AUTO-CONTINUE=NO,OVC=NO,

"VAR1: " + VAR1

Parents
  • After doing some testing, I found the following:

    Without defining VAR1 previously in the main program, the comment won't report the value that sVAR1 gives VAR1. What I did is set it up as is shown above, and then deleted the initial assignment. The link to VAR1 in the comment is still valid, but VAR1 defaults to 0 when opening the program. I was hoping that the variable would default to the value defined in the subroutine, but that's not the case. Also, it is likely a bad idea to have the connection to an uninstantiated variable in the event that something gets edited and the link gets broken.

Reply
  • After doing some testing, I found the following:

    Without defining VAR1 previously in the main program, the comment won't report the value that sVAR1 gives VAR1. What I did is set it up as is shown above, and then deleted the initial assignment. The link to VAR1 in the comment is still valid, but VAR1 defaults to 0 when opening the program. I was hoping that the variable would default to the value defined in the subroutine, but that's not the case. Also, it is likely a bad idea to have the connection to an uninstantiated variable in the event that something gets edited and the link gets broken.

Children