Reusable Part S_206F02 - Interface

LANSA

Reusable Part S_206F02 - Interface
* ===================================================================
*
* Component : S_206F02
* Type : Reusable Part
* Ancestor : PRIM_OBJT
*
* Description : Interface Form
*
* 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)
Begin_Com Left(441) Top(183)
* The SET function which will establish the connection to the iSeries
Define_Com Class(#VL_SAM003) Name(#S_COMSERVER) Visible(False)
* The timer used to periodically check for messages
Define_Com Class(#PRIM_TIMR) Name(#TIMR_1) Interval(0)
* The working list used to send data back from the iSeries
Def_List Name(#S_WRKMESS) Fields(#S_206CMD #S_206TYPE #S_206FRM #S_206TO #S_206MESS) Counter(#S_206CNT) Type(*WORKING) Entrys(1000)

* This field is used to count the number of entries in the working list
Define Field(#S_206CNT) Type(*DEC) Length(7) Decimals(0)
* This field holds the return code for the CALL_SERVER_FUNCTION command
Define Field(#S_206RTN) Type(*CHAR) Length(2)
* This field holds the symbolic server name of the iSeries being used.
Define Field(#S_206SSN) Type(*CHAR) Length(10)

* This signal returns the message, the command, the users alias and the message type back to the program.
Define_Evt Name(ReceiveMsg)
Define_Map For(*input) Class(#S_206MESS) Name(#Message)
Define_Map For(*input) Class(#S_206CMD) Name(#Request)
Define_Map For(*input) Class(#S_206ALS) Name(#Alias)
Define_Map For(*input) Class(#S_206TYPE) Name(#Type)

* This signal returns the alias of a new user
Define_Evt Name(AddUser)
Define_Map For(*input) Class(#S_206FRM) Name(#Alias)

* This signal returns the alias of an existing user to be deleted from the user list
Define_Evt Name(DeleteUser)
Define_Map For(*input) Class(#S_206FRM) Name(#Alias)

Mthroutine Name(getqueue)
* This routine should be called first because it acquires the message queue which is necessary for communication.
* The Job Queue defaults to QINTER and the Users Alias to the User Name. This could be easily changed.
Change Field(#S_206JOBQ) To(QINTER)
Change Field(#S_206FRM) To(*USER)
Exchange Fields(#S_206JOBQ #S_206FRM)
Use Builtin(CALL_SERVER_FUNCTION) With_Args(#S_206SSN SET206A Y Y #S_WRKMESS) To_Get(#S_206RTN)
Get_Entry Number(1) From_List(#S_WRKMESS)
* The timer only begins to tick once a data queue has been obtained
Set Com(#TIMR_1) Interval(1000)
Endroutine

Mthroutine Name(sendtoall)
* Method routine which sends a message to all users currently using the system. It receives a message.
Define_Map For(*input) Class(#S_206MESS) Name(#Message)
Change Field(#S_206MESS) To('#MESSAGE.VALUE')
Clr_List Named(#S_WRKMESS)
Change Field(#S_206CMD) To(MG)
Change Field(#S_206TYPE) To(B)
Change Field(#S_206FRM) To(*USER)
Exchange Fields(#S_206CMD #S_206TYPE #S_206FRM #S_206MESS)
Use Builtin(CALL_SERVER_FUNCTION) With_Args(#S_206SSN SET206A Y N #S_WRKMESS) To_Get(#S_206RTN)
Endroutine

Mthroutine Name(sendtoone)
* Method routine which sends a message to a specific user in the system. It receives the message and the alias of the user to
* whom the message will be sent.
Define_Map For(*input) Class(#S_206MESS) Name(#Message)
Define_Map For(*input) Class(#S_206TO) Name(#SendTo)
Change Field(#S_206MESS) To('#MESSAGE.VALUE')
Change Field(#S_206TO) To('#SENDTO.VALUE')
Clr_List Named(#S_WRKMESS)
Change Field(#S_206CMD) To(MG)
Change Field(#S_206TYPE) To(I)
Change Field(#S_206FRM) To(*USER)
Exchange Fields(#S_206CMD #S_206TYPE #S_206FRM #S_206TO #S_206MESS)
Use Builtin(CALL_SERVER_FUNCTION) With_Args(#S_206SSN SET206A Y N #S_WRKMESS) To_Get(#S_206RTN)
Endroutine

Mthroutine Name(starting)
* Define the iSeries S_COMSERVER and connect to the S_COMSERVER using VL_SAM003
Invoke Method(#S_COMSERVER.uConnectModal)
* Get the name of the S_COMSERVER
Change Field(#S_206SSN) To('#S_COMSERVER.UUSINGSSN')
Invoke Method(#COM_OWNER.getqueue)
Endroutine

Mthroutine Name(ending)
* This routine should be called as part of a Closing event to delete the data queue created on the iSeries.
Change Field(#S_206CMD) To(CL)
Exchange Fields(#S_206CMD #S_206TYPE)
Use Builtin(CALL_SERVER_FUNCTION) With_Args(#S_206SSN SET206A Y Y #S_WRKMESS) To_Get(#S_206RTN)
Invoke Method(#S_COMSERVER.uDisconnect)
Endroutine

Evtroutine Handling(#TIMR_1.Tick) Options(*NOCLEARMESSAGES *NOCLEARERRORS)
* This routine periodically checks to see whether there are any new messages. The timer is set to one second by default
* although this can be easily changed to alter the frequency of the checks.
Clr_List Named(#S_WRKMESS)
Change Field(#S_206CMD) To(CK)
Exchange Fields(#S_206CMD)
Use Builtin(CALL_SERVER_FUNCTION) With_Args(#S_206SSN SET206A Y Y #S_WRKMESS) To_Get(#S_206RTN)
If Cond('#S_206CNT *GT *ZERO')
Selectlist Named(#S_WRKMESS)
Case Of_Field(#S_206CMD)
When Value_Is('= ''DU''')
* if the message is an delete user message we signal that a user needs to be deleted
Signal Event(DeleteUser) Alias(#S_206FRM)
When Value_Is('= ''AU''')
* if the message is an add user message we signal that a user needs to be added
Signal Event(AddUser) Alias(#S_206FRM)
Otherwise
* if the message is just a message we signal that we have received a message
Signal Event(ReceiveMsg) Message(#S_206MESS) Request(#S_206CMD) Alias(#S_206FRM) Type(#S_206TYPE)
Endcase
Endselect
Endif
Endroutine
End_Com