SET208E

LANSA

SET208E
* =======================================================
* Process ........: SET_208
* Function .......: SET208E
* Description ....: Handle Employee Create/Update
*
* This function is called by SET208H to handle the
* processing of new or updated employee information
* that has been received in MS-Word document SET208E.DOC
*
* Disclaimer: The following material is supplied as
* sample material only. No warranty concerning the
* material or its use in any way whatsoever is
* expressed or implied.
*
* =======================================================
FUNCTION OPTIONS(*DIRECT *HEAVYUSAGE)
*
* Group of all field sin a department
*
GROUP_BY NAME(#XG_EMPINF) FIELDS(#SURNAME #GIVENAME #ADDRESS1 #ADDRESS2 #ADDRESS3 #POSTCODE #PHONEHME #PHONEBUS #DEPTMENT #SECTION #SALARY #STARTDTE)
*
* Other locally defined fields
*
DEFINE FIELD(#START_DD) LENGTH(2) DECIMALS(0) REFFLD(#STARTDTE) EDIT_CODE(4) DEFAULT(0) TO_OVERLAY(#STARTDTE)
DEFINE FIELD(#START_MM) LENGTH(2) DECIMALS(0) REFFLD(#STARTDTE) EDIT_CODE(4) DEFAULT(0) TO_OVERLAY(#STARTDTE 3)
DEFINE FIELD(#START_YY) LENGTH(2) DECIMALS(0) REFFLD(#STARTDTE) EDIT_CODE(4) DEFAULT(0) TO_OVERLAY(#STARTDTE 5)
DEFINE FIELD(#SAVE$STS) REFFLD(#IO$STS)
*
* Extract the employee number from the document
*
CHANGE FIELD(#EMPNO) TO(*BLANKS)
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(EMPNO #EMPNO)
*
* If no employee number was specified issue an
* error and finish up ....
*
IF_NULL FIELD(#EMPNO)
EXECUTE SUBROUTINE(MESSAGE) WITH_PARMS('You must specify an employee number' 'for all transactions' *BLANKS *BLANKS)
RETURN
ENDIF
*
* Try and locate an employee with the specified number
*
CHANGE FIELD(#XG_EMPINF) TO(*DEFAULT)
FETCH FIELDS(#XG_EMPINF) FROM_FILE(PSLMST) WITH_KEY(#EMPNO) IO_STATUS(#SAVE$STS)
*
* Now extract the details from the MS-Word document. Note
* that existing details are only overwritten by non-blank
* details coming from the MS-Word document
*
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(SURNAME #SURNAME)
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(GIVENAME #GIVENAME)
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(ADDRESS1 #ADDRESS1)
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(ADDRESS2 #ADDRESS2)
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(ADDRESS3 #ADDRESS3)
EXECUTE SUBROUTINE(GET_NUMBER) WITH_PARMS(POSTCODE #POSTCODE)
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(PHONEHME #PHONEHME)
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(PHONEBUS #PHONEBUS)
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(DEPTMENT #DEPTMENT)
EXECUTE SUBROUTINE(GET_ALPHA) WITH_PARMS(SECTION #SECTION)
EXECUTE SUBROUTINE(GET_NUMBER) WITH_PARMS(SALARY #SALARY)
EXECUTE SUBROUTINE(GET_NUMBER) WITH_PARMS(START_DAY #START_DD)
EXECUTE SUBROUTINE(GET_NUMBER) WITH_PARMS(START_MONTH #START_MM)
EXECUTE SUBROUTINE(GET_NUMBER) WITH_PARMS(START_YEAR #START_YY)
*
* Now either update the employee details
*
IF COND('#Save$Sts = OK')
EXECUTE SUBROUTINE(MESSAGE) WITH_PARMS('Results for attempted update of employee' #EMPNO #GIVENAME #SURNAME)
UPDATE FIELDS(#XG_EMPINF) IN_FILE(PSLMST) IO_ERROR(*NEXT) VAL_ERROR(*NEXT)
IF_STATUS IS(*OKAY)
EXECUTE SUBROUTINE(MESSAGE) WITH_PARMS(#EMPNO #GIVENAME #SURNAME 'was successfully updated')
ENDIF
ELSE
*
* or, create the employee details
*
EXECUTE SUBROUTINE(MESSAGE) WITH_PARMS('Results for attempted creation of employee' #EMPNO #GIVENAME #SURNAME)
INSERT FIELDS(#EMPNO #XG_EMPINF) TO_FILE(PSLMST) IO_ERROR(*NEXT) VAL_ERROR(*NEXT)
IF_STATUS IS(*OKAY)
EXECUTE SUBROUTINE(MESSAGE) WITH_PARMS(#EMPNO #GIVENAME #SURNAME 'was successfully created')
ENDIF
ENDIF
*
* Finished
*
RETURN
* =====================================================
* Get_Alpha : Locate an alphanumeric value
* =====================================================
SUBROUTINE NAME(GET_ALPHA) PARMS((#S_208NAME *RECEIVED) (#S_208AVAL *BOTH))
DEFINE FIELD(#S_208ADFT) REFFLD(#S_208AVAL) DESC('Default alphanumeric value')
CHANGE FIELD(#S_208ADFT) TO(#S_208AVAL)
CHANGE FIELD(#S_208OPER) TO(LOCATE)
CHANGE FIELD(#S_208INST) TO(1)
EXCHANGE FIELDS(#S_208OPER #S_208NAME #S_208INST)
CALL PROCESS(*DIRECT) FUNCTION(SET208L)
IF_NULL FIELD(#S_208AVAL)
CHANGE FIELD(#S_208AVAL) TO(#S_208ADFT)
ENDIF
ENDROUTINE
* =====================================================
* Get_Number : Locate a numeric value
* =====================================================
SUBROUTINE NAME(GET_NUMBER) PARMS((#S_208NAME *RECEIVED) (#S_208NVAL *BOTH))
DEFINE FIELD(#S_208NDFT) REFFLD(#S_208NVAL) DESC('Default numeric value')
CHANGE FIELD(#S_208NDFT) TO(#S_208NVAL)
CHANGE FIELD(#S_208OPER) TO(LOCATE)
CHANGE FIELD(#S_208INST) TO(1)
EXCHANGE FIELDS(#S_208OPER #S_208NAME #S_208INST)
CALL PROCESS(*DIRECT) FUNCTION(SET208L)
IF_NULL FIELD(#S_208NVAL)
CHANGE FIELD(#S_208NVAL) TO(#S_208NDFT)
ENDIF
ENDROUTINE
* =====================================================
* MESSAGE : Dynamically build a text message
* =====================================================
SUBROUTINE NAME(MESSAGE) PARMS((#TEXT01 *RECEIVED) (#TEXT02 *RECEIVED) (#TEXT03 *RECEIVED) (#TEXT04 *RECEIVED))
DEFINE FIELD(#TEXT01) REFFLD(#S_208MSG)
DEFINE FIELD(#TEXT02) REFFLD(#TEXT01)
DEFINE FIELD(#TEXT03) REFFLD(#TEXT01)
DEFINE FIELD(#TEXT04) REFFLD(#TEXT01)
USE BUILTIN(BCONCAT) WITH_ARGS(#TEXT01 #TEXT02 #TEXT03 #TEXT04) TO_GET(#S_208MSG)
MESSAGE MSGID(DCM9899) MSGF(DC@M01) MSGDTA(#S_208MSG)
ENDROUTINE