I use var INDEPENDENT with programs and it works correctly, but when used with subprograms when it occupies the dynamic part (&) it does not execute correctly.
Correct:
PROGRAM1
move ‘READ (10) ART BY C-ART = 2B’ to +W-Query
RUN PROGRAM2
PROGRAM2
&W-Query ← OK consult
END-READ
Incorrect:
PROGRAM1
move ‘READ (10) ART BY C-ART = 2B’ to +W-Query
CALLNAT SUBPROGAM
SUBPROGRAM
&W-Query ← NOK consult
END-READ
(the query returns me from the first value and not according to my selection criteria)
INDEPENDENT variables used with the dynamic prefix “&” are effective ONLY at compile time. When you issue a CALLNAT to a subprogram, it will execute the code compiled with whatever & values were in effect AT COMPILE TIME, not run time. It works dynamically with the program type only with the RUN command, which does a compile and run. A CALLNAT only does a “run” of the compiled subprogram code.
If you really need to do this, you could
set a value for the independent variable in ‘program1’
stack command ‘cat subprog’
stack command ‘fetch program2’
‘program2’ does CALLNAT ‘subprog’ to the newly-compiled version of subprog, using the values of the independent variables set at compile time.
Do you really need the query to be dynamic? How many possible values will it take on? Could you use a DECIDE statement to choose one of the options (assuming you have various descriptors to read by) and the loop just do a PERFORM to operate on the view (“ART”)?
If this doesn’t give you some other approaches, please explain more about what you are attempting to do as dynamic programs are not a best practice for production programs.
As of Natural 9 the character-based editor is replaced with a GUI, either Natural for Windows or Natural ONE. In either case your dynamic code will be obsolete because both replacements include Data Browser.