6 9 3 How Is the Code Different in a Function and a Form

Visual LANSA

6.9.3 How Is the Code Different in a Function and a Form?

Let's return to the marriage status example to see the differences between the code used in a LANSA function and a Visual LANSA form. Both the example function and the example form can be used to change and delete marriage status information.

Note that all validation rules for both the function and the form are defined as rules in the repository.

LANSA Function

You can use the function to display marriage status information for people identified by an identification number (#IDNO). You enter the number on a selection screen after which you can view and delete information. When you click the Change button a screen with input capable fields is displayed:

Note that this screen does not indicate in any way which fields are mandatory for a particular marital status. Validation rules are applied only when you click the OK button.

Source for the Function

Here is the source for the function:

FUNCTION OPTIONS(*NOMESSAGES *DEFERWRITE *DIRECT)

GROUP_BY NAME(#PANELDATA) FIELDS(#IDNO #STATUS #SPOUSE #MARRIED #DIVORCED)
********** COMMENT(Loop until user EXITs or CANCELs)
BEGIN_LOOP
R10: REQUEST FIELDS(#IDNO) DESIGN(*DOWN) IDENTIFY(*DESC)
********** COMMENT(Fetch file MARRIAGE details     )
FETCH FIELDS(#PANELDATA) FROM_FILE(MSTATUS) WITH_KEY(#IDNO) NOT_FOUND(R10) ISSUE_MSG(*YES)
********** COMMENT(Display results to the user      )
SET_MODE TO(*DISPLAY)
POP_UP FIELDS(#PANELDATA) DESIGN(*DOWN) AT_LOC(*UPPER 7) CHANGE_KEY(*YES) DELETE_KEY(*YES)
IF_MODE IS(*CHANGE)
UPDATE FIELDS(#PANELDATA) IN_FILE(MSTATUS)
ENDIF
IF_MODE IS(*DELETE)
DELETE FROM_FILE(MSTATUS) ISSUE_MSG(*YES)
ENDIF
END_LOOP

 

Visual LANSA Form

The Visual LANSA form has exactly the same functionality as the previous application. In addition it indicates which fields are mandatory by enabling and disabling them based on marital status. This instant feedback guides the user to enter the required information:

Source for the Form

Here is the source for the form:

***************************************************

*                                                  
* COMPONENT:  STD_FORM                             
*                                                  
***************************************************
FUNCTION OPTIONS(*DIRECT)
BEGIN_COM HEIGHT(240) LEFT(313) TOP(155) WIDTH(600)

* Component Definitions
DEFINE_COM CLASS(#IDNO.Visual) NAME(#IDNO) DISPLAYPOSITION(1) HEIGHT(19) LEFT(16) MARGINLEFT(120) PARENT(#COM_OWNER) TABPOSITION(1) TOP(16) WIDTH(209)
DEFINE_COM CLASS(#SPOUSE.Visual) NAME(#SPOUSE) DISPLAYPOSITION(2) HEIGHT(19) LEFT(200) PARENT(#COM_OWNER) TABPOSITION(2) TOP(56) WIDTH(369)
DEFINE_COM CLASS(#MARRIED.Visual) NAME(#MARRIED) DISPLAYPOSITION(3) HEIGHT(19) LEFT(200) PARENT(#COM_OWNER) TABPOSITION(3) TOP(80) WIDTH(232)
DEFINE_COM CLASS(#DIVORCED.Visual) NAME(#DIVORCED) DISPLAYPOSITION(5) HEIGHT(19) LEFT(200) PARENT(#COM_OWNER) TABPOSITION(5) TOP(104) WIDTH(232)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#SAVE) CAPTION('Save') DISPLAYPOSITION(4) LEFT(488) PARENT(#COM_OWNER) TABPOSITION(4) TOP(120)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#DELETE) CAPTION('Delete') DISPLAYPOSITION(6) LEFT(488) PARENT(#COM_OWNER) TABPOSITION(6) TOP(152)
DEFINE_COM CLASS(#PRIM_PHBN) NAME(#FETCH) CAPTION('Fetch') DISPLAYPOSITION(7) HEIGHT(17) LEFT(288) PARENT(#COM_OWNER) TABPOSITION(7) TOP(16) WIDTH(57)
DEFINE_COM CLASS(#PRIM_GPBX) NAME(#GPBX_1) CAPTION('Marital Status') DISPLAYPOSITION(8) HEIGHT(97) LEFT(16) PARENT(#COM_OWNER) TABPOSITION(8) TABSTOP(False) TOP(40) WIDTH(153)
DEFINE_COM CLASS(#PRIM_RDBN) NAME(#RDBN_1) CAPTION('Never Married') DISPLAYPOSITION(1) LEFT(16) PARENT(#GPBX_1) TABPOSITION(1) TOP(16) WIDTH(105)
DEFINE_COM CLASS(#PRIM_RDBN) NAME(#RDBN_2) CAPTION('Married') DISPLAYPOSITION(2) LEFT(16) PARENT(#GPBX_1) TABPOSITION(2) TOP(38) WIDTH(65)
DEFINE_COM CLASS(#PRIM_RDBN) NAME(#RDBN_3) CAPTION('Divorced') DISPLAYPOSITION(3) LEFT(16) PARENT(#GPBX_1) TABPOSITION(3) TOP(60) WIDTH(73)
DEFINE_COM CLASS(#PRIM_STBR) NAME(#STBR_1) DISPLAYPOSITION(9) HEIGHT(23) LEFT(0) MESSAGEPOSITION(1) PARENT(#COM_OWNER) TABPOSITION(9) TOP(190) WIDTH(592)

* Other definitions
GROUP_BY NAME(#PANELDATA) FIELDS(#STATUS #SPOUSE #MARRIED #DIVORCED)
EVTROUTINE handling(#com_owner.Initialize)
SET #com_owner caption(*component_desc)
ENDROUTINE

* Event routines
* Fetch file mstatus details     
EVTROUTINE HANDLING(#FETCH.Click)
FETCH FIELDS(#PANELDATA) FROM_FILE(mstatus) WITH_KEY(#IDNO) ISSUE_MSG(*YES)
if cond('#status *eq N')
set com(#RDBN_1) ButtonChecked(True)
set com(#spouse #married #divorced) enabled(false)
endif
if cond('#status *eq M')
set com(#RDBN_2) ButtonChecked(True)
set com(#spouse #married) enabled(true)
set com(#divorced) enabled(false)
endif
if cond('#status *eq D')
set com(#RDBN_3) ButtonChecked(True)
set com(#spouse #married #divorced) enabled(true)
endif
ENDROUTINE

* Enable and disable fields according to marital status 
EVTROUTINE HANDLING(#RDBN_1.Click )
set com(#spouse #married #divorced) enabled(false)
set com(#spouse) value(*blank)
set com(#married #divorced) value(*zero)
change #status 'N'
ENDROUTINE

EVTROUTINE HANDLING( #RDBN_2.Click )
set com(#spouse #married) enabled(true)
set com(#divorced) value(*zero)
set com(#divorced) enabled(false)
change #status 'M'
ENDROUTINE

EVTROUTINE HANDLING(#RDBN_3.Click)
set com(#spouse #married #divorced) enabled(true)
change #status 'D'
ENDROUTINE

*Save details
EVTROUTINE HANDLING(#Save.Click)
UPDATE FIELDS(#PANELDATA) IN_FILE(mstatus)
ENDROUTINE
 
EVTROUTINE HANDLING(#DELETE.Click)
DELETE FROM_FILE(mstatus) ISSUE_MSG(*YES)
ENDROUTINE
 
END_COM

 

Code Comparison

Ý 6.9 Event-Driven Programs