Step 4 Create a Relationship Handler to Load Sections

Visual LANSA Framework

Step 4. Create a Relationship Handler to Load Sections

In this step you will create a relationship handler that loads Sections into the instance list when a Department is expanded.

You could have loaded the all the Sections in the hidden filter code together with the Departments, but by using a relationship handler you can improve filter performance by first only adding root or parent objects to the instance list and then dynamically adding the child objects.

 

1.   In the Visual LANSA editor, create a process iiiPROC2 – Framework Functions. Create a function belonging to this process.  Specify iiiFN04 as the name of your function and Relationship Handler as the description. (iii are your initials. If you are using an unlicensed or trial version of Visual LANSA, you must always use the three characters DEM to replace iii).

2.   Replace the existing code in the function with this code that indicates that this function is a relationship handler:

FUNCTION OPTIONS(*DIRECT *LIGHTUSAGE) RCV_LIST(#VIS_LIST #PID_LIST #COL1_LIST #COL2_LIST #COL3_LIST #COL4_LIST #COL5_LIST #COL6_LIST #COL7_LIST #COL8_LIST #COL9_LIST #COLA_LIST)

 

INCLUDE PROCESS(*DIRECT) FUNCTION(VFREL1)

INCLUDE PROCESS(*DIRECT) FUNCTION(VFREL2)

The VFREL1 and VFREL2 functions which you include contain the standard definitions for relationship builder functions.

 

3.   Next clear all the keys and additional columns in the instance list:

EXECUTE SUBROUTINE(CLEARKEYS)

EXECUTE SUBROUTINE(CLEARCOLS)

   

The subroutines you call in the relationship handler are contained in the VFREL2 function.

 

4.   Get the key value of the selected department:

 

CHANGE FIELD(#DEPTMENT) TO(#SRC_AK1)

  

 

5.   Select the sections in the current department and set the values of the instance list entry:

SELECT FIELDS(*ALL) FROM_FILE(SECTAB) WITH_KEY(#DEPTMENT)

    EXECUTE SUBROUTINE(SETAKEY) WITH_PARMS(1 #DEPTMENT)

    EXECUTE SUBROUTINE(SETAKEY) WITH_PARMS(2 #SECTION)

    EXECUTE SUBROUTINE(SETNCOL) WITH_PARMS(1 #SECPCODE)

    EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(1 #SECADDR1)

    EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(2 #SECADDR2)

    EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(3 #SECADDR3)

    EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(4 #SECPHBUS)

    EXECUTE SUBROUTINE(ADDTOLIST) WITH_PARMS('DEPARTMENT_SECTIONS' #SECDESC #SECTION)

ENDSELECT

 

  • The SETAKEY subroutine sets the  key values of the child instance list. The first parameter of the subroutine is the key position and the second parameter is the value of the key. There is also a SETNKEY subroutine to set a numeric key.
  • The SETNCOL and SETACOL subroutines add additional columns for the child instance list entry.
  • The ADDTOLIST subroutine adds the entry to the instance list. The first parameter of the subroutine is the child business object name, the second parameter is the Visual ID 1 column and the third parameter is the Visual ID 2 column.

 

 

Your code will now look like this:

  

6.   Compile the function.

7.   Display the Framework.

8.   Display the properties of the Company Departments business object.

9.   In the Instance List/Relations tab select the Department Sections business object.

10.   In the Relationship Handler field, type in the name of the relationship handler.

 

12.   Close the Company Departments properties.

13.   Save and restart the Framework.

14.   Select the Company Departments business object in the iii HR application.

15.   Expand a department in the instance list.

 

The sections in each department you expand are loaded dynamically.

Note that only the section name and identifier are shown in the list. In the next step you change the instance list to show additional columns for the sections.