The procedure has it's own scope. The outside scope will "bleed" into the procedure but not the other way arround.
DEFINE VARIABLE i AS INTEGER NO-UNDO INIT 1.
DEFINE VARIABLE j AS INTEGER NO-UNDO.
PROCEDURE p:
MESSAGE i VIEW-AS ALERT-BOX. // 1
MESSAGE j VIEW-AS ALERT-BOX. // 0
j = 2.
END PROCEDURE.
RUN p.
MESSAGE i VIEW-AS ALERT-BOX. // 1
MESSAGE j VIEW-AS ALERT-BOX. // 2
Declaring a variable inside a procedure that has the same name as a parameter on the outside will only create a local variable.
DEFINE VARIABLE i AS INTEGER NO-UNDO INIT 1.
DEFINE VARIABLE j AS INTEGER NO-UNDO.
PROCEDURE p:
DEFINE VARIABLE i AS INTEGER NO-UNDO INIT 5.
MESSAGE i VIEW-AS ALERT-BOX. // 5
MESSAGE j VIEW-AS ALERT-BOX. // 0
j = 2.
END PROCEDURE.
RUN p.
MESSAGE i VIEW-AS ALERT-BOX. // 1
MESSAGE j VIEW-AS ALERT-BOX. // 2
Any variable created on the inside of a procedure is accessible to that procedure only.
This will generate a compiler error:
PROCEDURE p:
DEFINE VARIABLE i AS INTEGER NO-UNDO INIT 5.
END PROCEDURE.
RUN p.
MESSAGE i VIEW-AS ALERT-BOX. // Unknown Field or Variable name i - error 201