Kbase P17210: Why is the value change of a variable inside an internal pro
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  3/11/2003 |
|
Status: Unverified
GOAL:
Why is the value change of a variable inside an internal procedure not seen in the main procedure?
SYMPTOM(s):
When executing code like:
/***Main Procedure***/
DEFINE VARIABLE i AS INTEGER NO-UNDO.
MESSAGE i VIEW-AS ALERT-BOX INFO BUTTONS OK.
RUN internalp.
MESSAGE i VIEW-AS ALERT-BOX INFO BUTTONS OK.
/***Internal Procedure***/
PROCEDURE internalp:
DEFINE VARIABLE i AS INTEGER NO-UNDO.
i = 7.
END.
The value assigned to i inside the internal procedure is not reflected outside.
CAUSE:
When a variable is defined inside a procedure, it can be used only inside that procedure or its internal subprocedures.
Because the variable i is defined in the internal procedure above, all changes to it are local to that internal procedure or any subprocedures thereof.
FIX:
/*** To have these changes act on the variable defined in the Main procedure, do not define the variable with the same name inside the internal procedure. ***/
DEFINE VARIABLE i AS INTEGER NO-UNDO.
MESSAGE i VIEW-AS ALERT-BOX INFO BUTTONS OK.
RUN internalp.
MESSAGE i VIEW-AS ALERT-BOX INFO BUTTONS OK.
PROCEDURE internalp:
i = 7.
END.