4 5 3 Handling Re entrant Functions

LANSA Web Functions

4.5.3 Handling Re-entrant Functions

In this example of a WEBEVENT function, a single function is being written to call itself. This example is described as re-entrant. The same function is re-entered in order to process the Web page. This is a common approach as it allows the RDML logic associated with a page to be contained in the same function as the Web page itself.

In this function example, you must exchange a hidden field called RENTRY. This field tells the function if it is being called for the first time or if it is being called to process data.

For example:

    FUNCTION   OPTIONS(*DIRECT *WEBEVENT)

    GROUP_BY   NAME(#PANEL) FIELDS(#EMPNO #SURNAME... (RENTRY *HIDDEN))

    DEFINE     FIELD(#RENTRY) TYPE(*CHAR) LENGTH(1)

    IF         COND('#RENTRY *EQ Y')

    INSERT     FIELDS(#PANEL) TO_FILE(PSLMST)VAL_ERROR(T01)

    MESSAGE    MSGID(DCU0011) MSGF(DC@M01) MSGDTA('employee')

    CHANGE     FIELD(#PANEL) TO(*NULL)

    ENDIF

T01 CHANGE     FIELD(#RENTRY) TO(Y)

    REQUEST    FIELDS(#PANEL) DESIGN(*DOWN) IDENTIFY(*DESC)... USER_KEYS((01 SUBMIT))

When the function is called for the first time, the RENTRY field will have a value of NULL. The function simply displays the REQUEST asking the user to enter data for the file. Notice that RENTRY is set to YES before the function terminates.

The user key for the SUBMIT button will indicate that the next function to be called is itself. (For details, refer to 4.8 WEBEVENT Keywords.)When the function is called a second time, the variables are passed to the function and the RENTRY field is YES. The function knows it must perform the insert to the data file.

Also note how the T01 label is used. If errors occur during the INSERT, the function must display the current data. The reset of the #PANEL fields to *NULL is skipped.

Refer to 4.5.4 Final WEBEVENT Function.