时数的计算比较复杂,要考虑到排班,休息时间段等因素,所以直接交给标准去算方便很多
模拟前台提交数据:
FUNCTION ZFM_********.
*"----------------------------------------------------------------------
*"*"本地接口:
*" IMPORTING
*" REFERENCE(IV_USER) TYPE ZEHRUSER OPTIONAL
*" REFERENCE(IV_BEGDA) TYPE BEGDA OPTIONAL
*" REFERENCE(IV_ENDDA) TYPE ENDDA OPTIONAL
*" REFERENCE(IV_BEGUZ) TYPE P2001-BEGUZ OPTIONAL
*" REFERENCE(IV_ENDUZ) TYPE P2001-ENDUZ OPTIONAL
*" REFERENCE(IV_AWART) TYPE AWART OPTIONAL
*" REFERENCE(IV_INFTY) TYPE PRELP-INFTY OPTIONAL
*" REFERENCE(IV_OPERATION) TYPE PSPAR-ACTIO DEFAULT 'INS'
*" EXPORTING
*" REFERENCE(EV_STDAZ) TYPE ABSTD
*" REFERENCE(EV_ABWTG) TYPE ABWTG
*" REFERENCE(E_MESSAGE) TYPE ZSHR_MESSAGE
*"----------------------------------------------------------------------
DATA: LS_RETURN TYPE BAPIRETURN1.
"锁定人员
CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE'
EXPORTING
NUMBER = IV_USER
IMPORTING
RETURN = LS_RETURN.
IF LS_RETURN-TYPE = 'E'.
E_MESSAGE-MSGTY = 'E'.
E_MESSAGE-MSGTX = LS_RETURN-MESSAGE.
RETURN.
ENDIF.
"区分信息类
CASE IV_INFTY.
WHEN '2001'."请假 "其他信息类型也可以类似的写法
PERFORM FRM_QJ_SIM USING IV_USER IV_INFTY IV_AWART IV_BEGDA IV_ENDDA IV_BEGUZ IV_ENDUZ IV_OPERATION
CHANGING EV_STDAZ EV_ABWTG E_MESSAGE.
WHEN '2002'. "公出
PERFORM FRM_GC_SIM USING IV_USER IV_INFTY IV_AWART IV_BEGDA IV_ENDDA IV_BEGUZ IV_ENDUZ IV_OPERATION
CHANGING EV_STDAZ EV_ABWTG E_MESSAGE.
WHEN '2011'."忘打卡&跨天补卡 时间事件的信息类型 没有时数的说法,这里就写一下创建
PERFORM FRM_WDK_SIM USING IV_USER IV_INFTY IV_AWART IV_BEGDA IV_ENDDA IV_BEGUZ IV_ENDUZ IV_OPERATION
CHANGING EV_STDAZ EV_ABWTG E_MESSAGE.
ENDCASE.
"解锁
CALL FUNCTION 'HR_EMPLOYEE_DEQUEUE'
EXPORTING
NUMBER = IV_USER.
ENDFUNCTION.
FORM FRM_QJ_SIM USING IV_USER IV_INFTY IV_AWART IV_BEGDA IV_ENDDA IV_BEGUZ IV_ENDUZ IV_OPERATION
CHANGING EV_STDAZ EV_ABWTG E_MESSAGE STRUCTURE ZSHR_MESSAGE.
DATA:LS_P2001 TYPE P2001.
DATA:LS_RETURN TYPE BAPIRETURN1.
DATA:LS_KEY LIKE BAPIPAKEY.
DATA:LS_INFO_KEY LIKE PSKEY.
DATA:LS_PRELP TYPE PRELP.
LS_P2001-PERNR = IV_USER."员工号
LS_P2001-INFTY = IV_INFTY."信息类型
LS_P2001-SUBTY = IV_AWART."子信息类型
LS_P2001-BEGDA = IV_BEGDA."开始日期
LS_P2001-ENDDA = IV_ENDDA."结束日期
LS_P2001-ABWTG = IV_AWART.
LS_P2001-BEGUZ = IV_BEGUZ. "开始时间
LS_P2001-ENDUZ = IV_ENDUZ."结束时间
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
INFTY = LS_P2001-INFTY
NUMBER = LS_P2001-PERNR
SUBTYPE = LS_P2001-SUBTY
VALIDITYEND = LS_P2001-BEGDA
VALIDITYBEGIN = LS_P2001-BEGDA
RECORD = LS_P2001
OPERATION = IV_OPERATION
NOCOMMIT = 'X' "模拟前台输入不提交
IMPORTING
RETURN = LS_RETURN
KEY = LS_KEY.
IF LS_RETURN-TYPE = 'E' OR LS_KEY IS INITIAL.
E_MESSAGE-MSGTY = 'E'.
E_MESSAGE-MSGTX = LS_RETURN-MESSAGE.
ENDIF.
LS_INFO_KEY-PERNR = LS_KEY-EMPLOYEENO.
LS_INFO_KEY-INFTY = LS_P2001-INFTY.
LS_INFO_KEY-SUBTY = LS_KEY-SUBTYPE.
LS_INFO_KEY-OBJPS = LS_KEY-OBJECTID.
LS_INFO_KEY-SPRPS = LS_KEY-LOCKINDIC.
LS_INFO_KEY-ENDDA = LS_KEY-VALIDEND.
LS_INFO_KEY-BEGDA = LS_KEY-VALIDBEGIN.
LS_INFO_KEY-SEQNR = LS_KEY-RECORDNR.
CALL FUNCTION 'HR_PSBUFFER_GETDETAIL'
EXPORTING
INFOTYPE_KEY = LS_INFO_KEY
IMPORTING
INFOTYPE_RECORD = LS_PRELP
EXCEPTIONS
RECORD_NOT_FOUND = 1
KEY_NOT_SUPPLIED = 2
OTHERS = 3.
IF SY-SUBRC = 0.
*&记录DOCNR
CLEAR LS_P2001.
CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PRELP_TO_PNNNN
EXPORTING
PRELP = LS_PRELP
IMPORTING
PNNNN = LS_P2001.
EV_STDAZ = EV_STDAZ + LS_P2001-STDAZ.
EV_ABWTG = EV_ABWTG + LS_P2001-ABWTG.
ENDIF.
IF EV_STDAZ = 0.
E_MESSAGE-MSGTY = 'E'.
E_MESSAGE-MSGTX = '请假时数为0,请检查是否为周末或节假日请假!'.
ENDIF.
"模拟结束
ROLLBACK WORK .
ENDFORM.
FORM FRM_GC_SIM USING IV_USER IV_INFTY IV_AWART IV_BEGDA IV_ENDDA IV_BEGUZ IV_ENDUZ IV_OPERATION
CHANGING EV_STDAZ EV_ABWTG E_MESSAGE STRUCTURE ZSHR_MESSAGE.
DATA:LS_P2002 TYPE P2002.
DATA:LS_RETURN TYPE BAPIRETURN1.
DATA:LS_KEY LIKE BAPIPAKEY.
DATA:LS_INFO_KEY LIKE PSKEY.
DATA:LS_PRELP TYPE PRELP.
LS_P2002-PERNR = IV_USER."员工号
LS_P2002-INFTY = IV_INFTY."信息类型
LS_P2002-SUBTY = IV_AWART."子信息类型
LS_P2002-BEGDA = IV_BEGDA."开始日期
LS_P2002-ENDDA = IV_ENDDA."结束日期
LS_P2002-ABWTG = IV_AWART.
LS_P2002-BEGUZ = IV_BEGUZ. "开始时间
LS_P2002-ENDUZ = IV_ENDUZ."结束时间
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
INFTY = LS_P2002-INFTY
NUMBER = LS_P2002-PERNR
SUBTYPE = LS_P2002-SUBTY
VALIDITYEND = LS_P2002-BEGDA
VALIDITYBEGIN = LS_P2002-BEGDA
RECORD = LS_P2002
OPERATION = IV_OPERATION
NOCOMMIT = 'X' "模拟前台输入不提交
IMPORTING
RETURN = LS_RETURN
KEY = LS_KEY.
IF LS_RETURN-TYPE = 'E' OR LS_KEY IS INITIAL.
E_MESSAGE-MSGTY = 'E'.
E_MESSAGE-MSGTX = LS_RETURN-MESSAGE.
ENDIF.
LS_INFO_KEY-PERNR = LS_KEY-EMPLOYEENO.
LS_INFO_KEY-INFTY = LS_P2002-INFTY.
LS_INFO_KEY-SUBTY = LS_KEY-SUBTYPE.
LS_INFO_KEY-OBJPS = LS_KEY-OBJECTID.
LS_INFO_KEY-SPRPS = LS_KEY-LOCKINDIC.
LS_INFO_KEY-ENDDA = LS_KEY-VALIDEND.
LS_INFO_KEY-BEGDA = LS_KEY-VALIDBEGIN.
LS_INFO_KEY-SEQNR = LS_KEY-RECORDNR.
CALL FUNCTION 'HR_PSBUFFER_GETDETAIL'
EXPORTING
INFOTYPE_KEY = LS_INFO_KEY
IMPORTING
INFOTYPE_RECORD = LS_PRELP
EXCEPTIONS
RECORD_NOT_FOUND = 1
KEY_NOT_SUPPLIED = 2
OTHERS = 3.
IF SY-SUBRC = 0.
*&记录DOCNR
CLEAR LS_P2002.
CALL METHOD CL_HR_PNNNN_TYPE_CAST=>PRELP_TO_PNNNN
EXPORTING
PRELP = LS_PRELP
IMPORTING
PNNNN = LS_P2002.
EV_STDAZ = EV_STDAZ + LS_P2002-STDAZ.
EV_ABWTG = EV_ABWTG + LS_P2002-ABWTG.
ENDIF.
IF EV_STDAZ = 0.
E_MESSAGE-MSGTY = 'E'.
E_MESSAGE-MSGTX = '公出时数为0,请检查是否为周末或节假日请假!'.
ENDIF.
"模拟结束
ROLLBACK WORK .
ENDFORM.
FORM FRM_WDK_SIM USING IV_USER IV_INFTY IV_AWART IV_BEGDA IV_ENDDA IV_BEGUZ IV_ENDUZ IV_OPERATION
CHANGING EV_STDAZ EV_ABWTG E_MESSAGE STRUCTURE ZSHR_MESSAGE.
DATA:LS_P2011 TYPE P2011.
DATA:LS_RETURN TYPE BAPIRETURN1.
DATA:LS_KEY LIKE BAPIPAKEY.
DATA:LS_INFO_KEY LIKE PSKEY.
DATA:LS_PRELP TYPE PRELP.
LS_P2011-PERNR = IV_USER."员工号
LS_P2011-INFTY = IV_INFTY."信息类型
LS_P2011-SUBTY = IV_AWART."子信息类型
LS_P2011-BEGDA = IV_BEGDA."开始日期
* LS_P2011-ENDDA = IV_ENDDA."结束日期
LS_P2011-BEGUZ = IV_BEGUZ. "开始时间
* LS_P2011-ENDUZ = IV_ENDUZ."结束时间
CALL FUNCTION 'HR_INFOTYPE_OPERATION'
EXPORTING
INFTY = '2011'
NUMBER = LS_P2011-PERNR
SUBTYPE = LS_P2011-SUBTY
VALIDITYEND = LS_P2011-BEGDA
VALIDITYBEGIN = LS_P2011-BEGUZ
RECORD = LS_P2011
OPERATION = 'INS'
NOCOMMIT = 'X'
IMPORTING
RETURN = LS_RETURN
KEY = LS_KEY.
IF LS_RETURN-TYPE = 'E' OR LS_KEY IS INITIAL.
E_MESSAGE-MSGTY = 'E'.
E_MESSAGE-MSGTX = LS_RETURN-MESSAGE.
ENDIF.
"模拟结束
ROLLBACK WORK .
ENDFORM.