Step 2 Create Salary Review Form

Visual LANSA

Step 2. Create Salary Review Form

FRM095 - Calling a Function

1.  Create a new form iiiCOM17 – Salary Review Request. Switch to the Design tab.

2.  Create the form as follows:

  • Drop a Group Box towards the top of the form and resize it. Give it a Caption of Change Request.
  • Drop fields DEPTMENT and iiiPERCNT onto the Group Box and position them as required. Remember you can use the Edit / Align dialog to align a group of components.
  • Drop a Push Button into the Change Request group box, to the right of the fields. Change Name to SUBMIT. Give it a Caption of Submit and create a Click event routine for it.
  • Drop a List View onto the form and resize and position it. Add fields EMPNO, FULLNAME, DEPTMENT, SALARY and iiiNEWSAL.
  • Add a Status Bar to the form.
  • Add field iiiTOTSAL to the form below the List View.

     Your form should look like the following:

3.  Switch to your program Source. Define four work fields:

  • NEWTOT, reference field iiiTOTSAL
  • CURTOT, reference field iiiTOTSAL
  • SRVCON, *CHAR, 1, default = *SSERVER_CONNECTED
  • SSTATUS, reference field IO$STS

4.  Define the EMPLOYS working list. This must be  identical to the DEF_LIST definition in function iiiFN21.

Def_List Name(#employs) Fields(#empno #fullname #DEPTMENT #salary #iiinewsal) Counter(#listcount) Type(*working) Entrys(*max)

 

     It is a good idea to copy the DEF_LIST definition from function iiiFN21 as it is essential that your working lists are identically defined in the calling form and the called function. If not identical, run time errors will occur. Each list must contain the same fields in the same sequence.

5.  Review the following pseudo code. You will create this in the following steps.

      Use BEGINCHECK/FILECHECK/ENDCHECK to validate DEPTMENT using file DEPTAB

      Clear list EMPLOYS

      EXCHANGE fields DEPTMENT and iiiPERCNT

      If SVRCON = N

          Call, process *direct, function iiiFN21, Pass list EMPLOYS

          else

          USE CALL_SERVER_FUNCTION, with arguments (*sserver_ssn iiiFN21 Y *default EMPLOYS) To Get(#sstatus)

      EndIf

      If (#sstatus *ne OK)

      Message 'Call server function failed'

      End if

      Clear  list LTVW_1

      CURTOT and NEWTOT = zero

      Selectlist EMPLOYS

          Accumulate SALARY in CURTOT

          Accumulate NEWSAL in NEWTOT

          Add entry LTVW_1

      End selectlist

      iiiTOTSAL = NEWTOT – CURTOT

6.  Begin the SUBMIT.Click event routine by using Begincheck/Endcheck and Filecheck to ensure the department code exists. Your code should look like the following:

Begincheck
Filecheck Field(#DEPTMENT) Using_File(deptab) Msgtxt('Department not found')
Endcheck
 

     Recall that the the Endcheck error handling will branch to the Endroutine if the Filecheck raises an error.

7.  Clear the working list EMPLOYS

Clr_List Name(#EMPLOYS)

 

8.  Add an Exchange command to pass DEPTMENT and IIIPERCNT to the called function

Exchange Fields(#deptment #iiiprccnt)

 

  • This will add these fields to the Exchange List which is passed to the called function.
  • The called function will map these values into its variables and clear the exchange list

9.  The SRVCON field contains the value of the system variable *sserver_connected. The system variable is Y when connected to a server, and N when not connected to a server.

     Add an If loop to call the function IIIFN21 locally when not connected.

If (#srvcon = N)
Call Process(*DIRECT) Function(iiifn21) Pass_Lst(#employs)
Endif
 

     Note: The CALL command is passing the working list EMPLOYS to the called function, which will return it.

10. Add an Else to the If loop, which calls the function IIIFN21 on the server.

     Your code should now look like the following:

If (#srvcon = N)
Call Process(*DIRECT) Function(iiifn21) Pass_Lst(#employs)
Else
Use Builtin(call_server_function) With_Args(*sserver_ssn 'iiifn21' Y *Default #employs) To_Get(#sstatus)
If (#sstatus *NE OK)
Message Msgtxt('Call server function failed')
Endif
Endif

 

     The CALL_SERVER_FUNCTION uses the following parameters:

WITH_ARGS

 

Server Symbolic Name

*sserver_ssn

Name of RDML function to be called

IIIFN21

Pass Current Exchange List

Y

Receive Exchange List back

*default

Working List 1

#EMPLOYS

TO_GET

 

Return Code

#SSTATUS

 

  • *sserver_ssn is a system variable which returns the server symbolic name of the server. The server symbolic name is defined by the CONNECT_SERVER BIF or by the automatic server connection to be used in this example.
  • The called function IIIFN21 is called directly
  • The (field) Exchange List is passed to IIIFN21. The Exchange List was set up by the Exchange command
  • A returned Exchange List is not required in this case (Receive Exchange List back = *default)
  • Only the first working list is passed to function IIFN21 and will be returned by IIIFN21.
  • The Return Code will be work field SSTATUS

11. Complete the SUBMIT.Click event routine, with:

  • Clear the list view
  • Initialize fields CURTOT and NEWTOT
  • Read (SELECTLIST) the returned working list EMPLOYS
  • Accumulate CURTOT
  • Accumulate NEWTOT
  • Add and entry to list view
  • End read
  • Set IIITOTSAL to (NEWTOT – CURTOT)

     Your additional code should look like the following:

. . . . . .
Endif
Clr_List Named(#LTVW_1)
#curtot #newtot := *zeroes
Selectlist Named(#employs)
#curtot += #salary
#newtot += #iiinewsal
Add_Entry To_List(#LTVW_1)
Endselect
#IIITOTSAL := (#newtot - #curtot)
Endroutine
 

12. Compile your new form.

     If required, see Appendix B. FRM095 for a complete solution.