4.3.7 WAM Session Example

It is important to understand the SessionStatus property for managing your WAM sessions.

The following is an example of a typical WAM which a manages a session:

FUNCTION OPTIONS(*DIRECT)
BEGIN_COM ROLE(*EXTENDS #PRIM_WAM) SESSIONSTATUS(Active) SESSIONTIMEOUT(300)
 
*The following line declares Session state #CUSTNAME field
WEB_MAP FOR(*NONE) FIELDS(#CUSTNAME) OPTIONS(*PERSIST)
 
WEBROUTINE NAME(Start) DESC('Initial Page') OnEntry(*SessionStatus_None)
WEB_MAP FOR(*OUTPUT) FIELDS(#USERID #PASSWORD)
ENDROUTINE
 
WEBROUTINE NAME(Logon) DESC('Logon Page') OnEntry(*SessionStatus_None)
WEB_MAP FOR(*INPUT) FIELDS(#USERID #PASSWORD)

* Some authentication logic, if authentication fails can TRANSFER back to Start page
 
* The following line will create a session, when WEBROUTINE exits
#COM_SELF.SessionStatus := Active
 
TRANSFER TOROUTINE(WelcomePage)
ENDROUTINE
 
WEBROUTINE NAME(WelcomePage) DESC('Welcome Page')
ENDROUTINE
 
WEBROUTINE NAME(Logoff) DESC('Logoff page')
#COM_SELF.SessionStatus := Invalid
ENDROUTINE
 
* The following event handler will handle invalid sessions and
* TRANSFER back to starting page, for logon
EVTROUTINE HANDLING(#COM_OWNER.SessionInvalid) OPTIONS(*NOCLEARMESSAGES *NOCLEARERRORS)
TRANSFER TOROUTINE(Start)
ENDROUTINE
 
END_COM