Function SET233S

LANSA

Function SET233S
* =======================================================
* Process ........: SET_233
* Function .......: SET233S
* Created on .....: 19/10/01 at 11:41:13
* Description ....: Receive and process salary amendments
* Version.........: 1
*
* Full Description:
*
* This function RECEIVEs data from a csv file
* sent via the LANSA user agent.
* (the data in the csv file is a list of employee salary
* updates.)
* The data is automatically mapped by the RECEIVE
* from the csv file into a working list.
* The function reads the working list and updates the
* salaries of the relevant employees on the database
* and in the list. It then SENDs back the updated
* list as a .csv file to the LANSA User agent, where
* it can be viewed (and saved) in the response tabsheet.
*
* Service used: HTTPCLIENT
*
* For the RECEIVE command.
* HANDLER: inbound csv (ISVL).
* no style sheets required
*
* For the SEND command.
* HANDLER: inbound csv (ISVL).
* no style sheets required
*
* Requires LANSA 9.1
*
* Disclaimer: The following material is supplied as an
* example only. No warranty is expressed or implied.
*
* ======================================================*
Function Options(*DIRECT)
*
Define Field(#KEYWORD) Reffld(#STD_TEXT)
Define Field(#KEYW_VAL1) Reffld(#STD_TEXTL)
Define Field(#KEYW_VAL2) Reffld(#STD_TEXTL)
Define Field(#S_233ERRO) Type(*CHAR) Length(132) Input_Atr(LC)
*
* Working list coming in with details to create the
* order detail record(s)
*
Def_List Name(#S_LSTRCV) Fields(#EMPNO #SALARY) Type(*WORKING)
*
* Outoing working list with employee details
* and a message field indicating the success
* or failure of the update.
Def_List Name(#S_LSTSND) Fields(#EMPNO #GIVENAME #SURNAME #SALARY #S_233ERRO) Type(*WORKING)
*
* Mainline
*
Change Field(#S_JSMSTS #S_JSMMSG) To(*BLANKS)
*
* Open the Java Services Manager
Use Builtin(JSM_OPEN) To_Get(#S_JSMSTS #S_JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms('After Open')
*
* Load service
* SERVICE_LOAD SERVICE(HTTPCLIENT)
Execute Subroutine(START_CMD) With_Parms('SERVICE_LOAD')
Execute Subroutine(KEYWRD) With_Parms('SERVICE' 'HTTPCLIENT' *BLANKS)
Use Builtin(JSM_COMMAND) With_Args(#S_JSMCMD) To_Get(#S_JSMSTS #S_JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms('After HTTP Load')
*
* Build the RECEIVE command
* RECEIVE HANDLER(ISVL) SVHEAD(SET233S)
* SERVICE_LIST(EMPNO,SALARY)
*
* HANDLER(ISVL) refers to the inbound csv handler
* Refer to the HTTPService.properties file that in the
* Properties directory of your JSM installation (for
* example /jsm/instance/properties/).
*
* SVHEAD can be used if the MODE is *NONE
* (or the MODE is unspecified)
* In this situation, SVHEAD contains the logical
* name that points to the field names of the columns
* in the .CSV file.
* The list of field names attached to the logical name
* is stored in the HTTPService.properties file. It
* contains entries in the form:
* sv.head.SET233S=EMPNO,SALARY
*
* The reason for using this parameter is that there
* may be more fields in the .csv
* file than there are in the list. The presence of this
* parameter allows fields in the .csv file to map
* to fields in the list, and to be dropped when not
* required.
*
* SERVICE_LIST has the field names that define the
* working list #S_LSTRCV. These are the employee number
* and new salary.
*
* MODE is not specified in this example and hence
* defaults to *NONE
* *NONE = the first line of the .csv file does not
* contain column heading data. (SVHEAD parameter
* may be used if map/drop of fields is required)
* *IGNORE = the first line of the .csv file does
* contain column heading data, but it is to be
* ignored. (i.e. skip the first line). The format of
* the .csv file must match the format of the list.
* *USE = The first line of the .csv file contains
* LANSA field names as column heading data.
* These field names will be used to map/drop
* fields if the format of the CSV file does not
* match the format of the list.
*
Execute Subroutine(START_CMD) With_Parms('RECEIVE')
Execute Subroutine(KEYWRD) With_Parms('HANDLER' 'ISVL' *BLANKS)
Execute Subroutine(KEYWRD) With_Parms('SVHEAD' 'SET233S' *BLANKS)
Execute Subroutine(KEYWRD) With_Parms('SERVICE_LIST' 'EMPNO,SALARY' *BLANKS)
*
* Receive working list with the employee number
* and the new salary
Use Builtin(JSM_COMMAND) With_Args(#S_JSMCMD) To_Get(#S_JSMSTS #S_JSMMSG #S_LSTRCV)
Execute Subroutine(CHECK_STS) With_Parms('After RECEIVE')
*
* Read through the list, update the employee salary
*
Selectlist Named(#S_LSTRCV)
Change Field(#GIVENAME #SURNAME) To(*NULL)
Fetch Fields(#SURNAME #GIVENAME) From_File(PSLMST) With_Key(#EMPNO)
If_Status Is_Not(*OKAY)
Change Field(#S_233ERRO) To('''Unsuccessful: Employee not found''')
Else
Update Fields(#SALARY) In_File(PSLMST) Io_Error(*NEXT) Val_Error(*NEXT)
*
If_Status Is_Not(*OKAY)
Change Field(#S_233ERRO) To('''Unsuccessful: Employee found but update failed''')
Else
* No errors - build a successful salary update message
* for this employee
Use Builtin(BCONCAT) With_Args('Successful: Salary of employee' #EMPNO 'successfully updated') To_Get(#S_233ERRO)
Endif
Endif
Add_Entry To_List(#S_LSTSND)
Endselect
*
*
* Build the SEND command
*
* Build the SEND command
* SEND HANDLER(ISVL)
* SERVICE_LIST(S_233ERRO)
*
* HANDLER(ISVL) refers to the inbound csv handler
* The same handler works ok with the SEND
* Refer to the HTTPService.properties file that in the
* Properties directory of your JSM installation (for
* example /jsm/instance/properties/).
*
* SERVICE_LIST has the field name that defines the
* working list #S_LSTSND. This is just the employee
* number, name, new salary, and a message
* indicating error/success
*
Execute Subroutine(START_CMD) With_Parms('SEND')
Execute Subroutine(KEYWRD) With_Parms('HANDLER' 'ISVL' *BLANKS)
Execute Subroutine(KEYWRD) With_Parms('SERVICE_LIST' 'EMPNO,GIVENAME,SURNAME,SALARY,S_233ERRO' *BLANKS)
*
* SEND a response with the messages
* for either successful salary update
* or validation errors.
Use Builtin(JSM_COMMAND) With_Args(#S_JSMCMD) To_Get(#S_JSMSTS #S_JSMMSG #S_LSTSND)
Execute Subroutine(CHECK_STS) With_Parms('After SEND')
*
* Close the Java Services Manager
Use Builtin(JSM_CLOSE) To_Get(#S_JSMSTS #S_JSMMSG)
Execute Subroutine(CHECK_STS) With_Parms('After CLOSE')
*
Return
*
* Subroutine to Start building a new JSM command
*
Subroutine Name(START_CMD) Parms((#STD_TEXTS *RECEIVED))
Change Field(#S_JSMCMD) To(#STD_TEXTS)
Endroutine
*
* Subroutine to add a keyword to an existing JSM command
*
Subroutine Name(KEYWRD) Parms(#KEYWORD #KEYW_VAL1 #KEYW_VAL2)
Use Builtin(BCONCAT) With_Args(#S_JSMCMD #KEYWORD) To_Get(#S_JSMCMD)
Use Builtin(TCONCAT) With_Args(#S_JSMCMD '(' #KEYW_VAL1 #KEYW_VAL2 ')') To_Get(#S_JSMCMD)
Endroutine
*
* Check the status of the JSM command issued
*
Subroutine Name(CHECK_STS) Parms(#STD_DESCL)
*
Define Field(#MSGDTA) Type(*CHAR) Length(132)
*
If Cond('#S_JSMSTS *NE OK')
*
Use Builtin(BCONCAT) With_Args(#STD_DESCL 'Error Status Code: ' #S_JSMSTS) To_Get(#MSGDTA)
Message Msgid(DCM9899) Msgf(DC@M01) Msgdta(#MSGDTA)
Use Builtin(BCONCAT) With_Args('Error Message: ' #S_JSMMSG) To_Get(#MSGDTA)
Message Msgid(DCM9899) Msgf(DC@M01) Msgdta(#MSGDTA)
Use Builtin(BCONCAT) With_Args(*FUNCTION 'ended in error. Review previous messages.') To_Get(#MSGDTA)
Message Msgid(DCM9899) Msgf(DC@M01) Msgdta(#MSGDTA)
Use Builtin(JSM_CLOSE) To_Get(#S_JSMSTS #S_JSMMSG)
Abort Msgid(DCM9899) Msgf(DC@M01) Msgdta(#MSGDTA)
Endif
*
Endroutine