There are two ways to pass information to a program that is invoked by the System (DTW_SYSTEM) language environment, directly and indirectly.
%DEFINE INPARM1 = "SWITCH1" %FUNCTION(DTW_SYSTEM) sys1() { %EXEC{ /QSYS.LIB/NETDATA.LIB/RPGCALL1.PGM ('$(INPARM1)' 'literalstring') %} %}
The Net.Data variable INPARM1 is referenced and passed to the program. The parameters are passed to the program in the same way the parameters are passed to the program when the program is called from the command line. The parameters that are passed to the program using this method are considered input type parameters (the parameters passed to the program can be used and manipulated by the program, but changes to the parameters are not reflected back to Net.Data).
Pass parameters indirectly, by using environment variables. Environment variables are character strings of the form "name=value" that are stored in an environment space outside of the program. The strings are stored in a temporary space associated with the process.
When Net.Data calls a DTW_SYSTEM language environment function, the language environment stores any function parameters that are input (IN) or input/output (INOUT) in the environment space prior to executing the statement within the %EXEC block. After the successful completion of the statement, the DTW_SYSTEM language environment determines whether there are any output (OUT or INOUT) function parameters. If so, the language environment retrieves the value corresponding to the function parameter from the environment space and updates the function parameter value with the new value. When Net.Data gets control, it in turn updates all OUT or INOUT parameters with the new values obtained from the DTW_SYSTEM language environment.
Set and retrieve environment variables using the APIs described in Table 7:
Table 7. Environment Variable APIs
ILE Programming Language | To retrieve, use... | To set, use... |
---|---|---|
C, C++ | getenv() | putenv() |
CL(1), RPG, COBOL | QtmhGetEnv()(2) | QtmhPutEnv()(3) |
|
You can pass Net.Data tables to a program called by the System language environment. The program accesses the values of a Net.Data macro table parameter by their Net.Data name. The column headings and field values are contained in variables identified with the table name and column number. For example, in the table myTable, the column headings are myTable_N_j, and the field values are myTable_V_i_j, where i is the row number and j is the column number. The number of rows and columns for the table are myTable_ROWS and myTable_COLS.
It is not recommended that you pass tables with many rows because the number of environment variables for the process is limited.