Step 2 Call a Function

Visual LANSA

Step 2. Call a Function

FRM115 - Writing Reports

In this step, you will create a form that will be used to call the reporting function. The purpose of this step is to show how forms and functions can work together. In your first version, the form will simply call the function directly. (You can also invoke the process menu.)

1.  Create a form named iiiCOM19 Submit Report (where iii are your course assigned initials). If you are using iii=DEM, then your component must be named DEMCOM19.

2.  Drag and drop a push button onto the form.

a.  Set the button Name to REPORT.

b.  Set the button Caption to Generate Report.

c.  Create a Click event routine for the REPORT button.

3.  Drag and drop the DEPTMENT and SECTION fields onto the form.

4.  Drag and drop a status bar onto the form.

5.  Your finished form might appear something like the following.

6.  In the REPORT.Click event routine, simply call the iiiFN02 reporting function. Review the parameters for the CALL command.

     Your finished code should appear as follows:

EVTROUTINE HANDLING(#REPORT.Click)
CALL PROCESS(*DIRECT) FUNCTION(iiiFN02)
ENDROUTINE

 

7. Compile and execute the form.

a.  Press the Generate Report button on the form.

b.  The iiiFN02 Section Report will be executed. Notice that you cannot set focus back to the calling form. Press the EXIT button. Notice that the Form is also closed when the Function is exited. The EXIT_USED parameter on the CALL command can be used to control how the form responds when the function ends.

c.  Execute the form again. Enter a Department Code of ADM and press the Generate Report button on the form. Notice that the DEPTMENT value is not passed to the function. (The function fields are both blank.)

d.  Enter a Department Code of ADM and press OK to submit the report. Notice that the form is not closed once the report is submitted. Notice that a message appears indicating that the report was submitted.

e.  Close the form.

8.  In the REPORT.Click event routine, use the EXCHANGE command to pass the values of the DEPTMENT and SECTION fields to the function.

     Your finished code should appear as follows:

EVTROUTINE HANDLING(#REPORT.Click)
EXCHANGE FIELDS(#DEPTMENT #SECTION)
CALL PROCESS(*DIRECT) FUNCTION(iiiFN02)
ENDROUTINE

 

9.  Compile and execute the form.

a.  Enter a Department Code of ADM and a Section Code of 01. Press the Generate Report button.

b.  The iiiFN02 Section Report will be executed. Notice that the function now shows the values that were passed from the form.

c.  Exit the function without submitting the report.

d.  By using the EXCHANGE command, the DEPTMENT and SECTION fields are passed to the reporting function. The reporting function no longer requires a screen to request the DEPTMENT and SECTION fields. In the next step, you will modify the iiiFN02 function and remove the REQUEST.

10. In the REPORT.Click event routine, use the SUBMIT command instead of the CALL to invoke the report function and pass the values of the DEPTMENT and SECTION fields.

     Your finished code should appear as follows:

EVTROUTINE HANDLING(#REPORT.Click)
SUBMIT PROCESS(iiiPRO01) FUNCTION(iiiFN02) EXCHANGE(#DEPTMENT #SECTION)
ENDROUTINE

 

11. Compile and execute the form.

a.  Enter a Department Code of ADM. Press the Generate Report button.

b.  Notice that the REQUEST is not displayed and the report function is submitted to batch for execution. Also notice that the form can be used immediately after the function is submitted. The form does not have to wait for the function to return control because the function has been submitted and is executing in batch.