Sample Relationship Handler Function

Visual LANSA Framework

Sample Relationship Handler Function

* =======================================================

* Component   : DF_PROC/DFREL01

* Type        : Function

* Disclaimer  : The following material is supplied as

* sample material only. No warranty concerning this

* material or its use in any way whatsoever is

* expressed or implied

* =======================================================

FUNCTION OPTIONS(*DIRECT *LIGHTUSAGE *MLOPTIMIZE) 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)

 

* The Employee group

 

GROUP_BY NAME(#EMPLOYEE) FIELDS(#EMPNO #GIVENAME #SURNAME #PHONEBUS #ADDRESS1 #ADDRESS2 #ADDRESS3 #POSTCODE #PHONEHME #DEPTMENT #SECTION)

 

* Clear all keys and additional columns

 

EXECUTE SUBROUTINE(CLEARKEYS)

EXECUTE SUBROUTINE(CLEARCOLS)

 

* Field #SRC_TYPE (Source Business Object Type) is

* the source object of the relationship so switch

* on that initially .....

 

CASE OF_FIELD(#SRC_TYPE)

 

* Expand Sections in a Department/Organization

 

WHEN VALUE_IS('= DEM_ORG')

EXECUTE SUBROUTINE(ORGSEC)

 

* Expand Employees in a Department/Section

 

WHEN VALUE_IS('= DEM_ORG_SEC')

EXECUTE SUBROUTINE(SECEMP)

 

OTHERWISE

 

ABORT MSGTXT('Unknown source business object type encountered by function DFREL01')

 

ENDCASE

 

* Finished ... always use a return command

 

RETURN

 

* Return the sections in a department/organization

 

SUBROUTINE NAME(ORGSEC)

 

CHANGE FIELD(#DEPTMENT) TO(#SRC_AK1)

 

* We can now read all the EMPLOYEES in the specified

* department/section and add them to the instance list

 

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('DEM_ORG_SEC' #SECDESC #SECTION)

ENDSELECT

 

* Finished

 

ENDROUTINE

 

SUBROUTINE NAME(SECEMP)

 

CHANGE FIELD(#DEPTMENT) TO(#SRC_AK1)

CHANGE FIELD(#SECTION) TO(#SRC_AK2)

 

SELECT FIELDS(#EMPLOYEE) FROM_FILE(PSLMST1) WITH_KEY(#DEPTMENT #SECTION)

 

EXECUTE SUBROUTINE(SETAKEY) WITH_PARMS(1 #DEPTMENT)

EXECUTE SUBROUTINE(SETAKEY) WITH_PARMS(2 #SECTION)

EXECUTE SUBROUTINE(SETAKEY) WITH_PARMS(3 #EMPNO)

 

EXECUTE SUBROUTINE(SETNCOL) WITH_PARMS(1 #POSTCODE)

EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(1 #ADDRESS1)

EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(2 #ADDRESS2)

EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(3 #ADDRESS3)

EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(4 #PHONEBUS)

EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(5 #PHONEHME)

EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(6 #DEPTMENT)

EXECUTE SUBROUTINE(SETACOL) WITH_PARMS(7 #SECTION)

 

USE BUILTIN(TCONCAT) WITH_ARGS(#SURNAME ',' #GIVENAME) TO_GET(#FULLNAME)

 

EXECUTE SUBROUTINE(ADDTOLIST) WITH_PARMS('DEM_ORG_SEC_EMP' #FULLNAME #EMPNO)

 

ENDSELECT

 

* Finished

 

ENDROUTINE

 

* =======================================================

INCLUDE PROCESS(*DIRECT) FUNCTION(VFREL2)

     

Note: To add values to Date/Time additional columns use the SETDCOL subroutine in the same way that the SETACOL subroutine is used to add values to alphanumeric additional columns.

To convert the values in date/Time fields to ISO format (required for Date/Time additional columns) see the Date/Time Additional Column Programming Example.