1、通过函数操作。
INFOTYPES: 0001. DATA: ZRETURN TYPE BAPIRETURN1, ZPAKEY TYPE BAPIPAKEY. GET PERNR. LOOP AT P0001 WHERE ... *锁定人员编号 CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE' EXPORTING NUMBER = PERNR-PERNR * IMPORTING * RETURN = . ... *新建信息类型 CALL FUNCTION 'HR_INFOTYPE_OPERATION' EXPORTING INFTY = '0001' NUMBER = P0001-PERNR * SUBTYPE = ' ' * OBJECTID = LOCKINDICATOR = P0001-SPRPS VALIDITYEND = P0001-ENDDA VALIDITYBEGIN = P0001-BEGDA RECORDNUMBER = P0001-SEQNR RECORD = P0001 OPERATION = 'INS' * TCLAS = 'A' DIALOG_MODE = '1' * NOCOMMIT = * VIEW_IDENTIFIER = * SECONDARY_RECORD = IMPORTING RETURN = ZRETURN KEY = ZPAKEY . COMMIT WORK.
*解除锁定 CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE' EXPORTING NUMBER = PERNR-PERNR * IMPORTING * RETURN = . ENDLOOP.
OPERATION: MOD(change) INS(insert) COPY(copy) DEL(delete) LIS9(delimit)
批量处理可能用到的清空缓存的函数,在调用HR_INFOTYPE_OPERATION之前使用。
CALL FUNCTION 'HR_INITIALIZE_BUFFER' EXPORTING * TCLAS = 'A' PERNR = PERNR . CALL FUNCTION 'HR_PSBUFFER_INITIALIZE' .
2、更新数据库。
PARAMETERS: P_NATIO_O LIKE P0002-NATIO DEFAULT 'DE', P_NATIO_N LIKE P0002-NATIO DEFAULT 'D'. UPDATE PA0002 SET NATIO = P_NATIO_N WHERE PERNR = P0002-PERNR AND NATIO = P_NATIO_O. IF SY-SUBRC = 0. ENDIF.