One of the most common techniques used in IBM i applications when producing "on demand" reports for end users is to actually write 2 programs.
The first program is run interactively and requests that the user specify the criteria that are to be used when producing the report. A call to the second program is then submitted to batch, passing the user's criteria as parameters.
The second program, when it is invoked in batch, uses the criteria received as parameters to produce the required report.
The main reason that this technique is used is that most reporting programs perform too many database I/Os to be efficiently run in an interactive environment, thus they are submitted to batch.
However, it is possible in LANSA to achieve exactly the same result using only one program. As an example, consider the following function, PRNTBCH, which belongs to process GLPROC01:
FIELDS(#GLNUMB #BATCH #CREDIT #DEBIT)
DEFINE FIELD(#MINCREDIT) REFFLD(#CREDIT)
IF COND('*JOBMODE = I')
REQUEST FIELDS(#GLNUMB #BATCH #MINCREDIT)
SUBMIT PROCESS(GLPROC01) FUNCTION(PRNTBCH)
EXCHANGE(#GLNUMB #BATCH #MINCREDIT)
SELECT FIELDS(#CREDIT #DEBIT) FROM_FILE(GLMASTV3)
WHERE('#CREDIT *GE #MINCREDIT')
When run interactively (i.e.: *JOBMODE = I) , this function requests that the user input a general ledger number, a batch number and a minimum credit amount. It then submits itself to batch, exchanging the general ledger number, batch number and minimum credit amount that were input by the user.
When invoked in batch, this function selects only records that match the user's request from logical file GLMASTV3 and prints them. The initial value of fields #GLNUMB, #BATCH and #MINCREDIT are established from the exchange list that was passed to the batch version of this function from the interactive version.