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:




    IF         COND('#RENTRY *EQ Y')


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





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.