CREATE OR REPLACE PACKAGE BODY ZCONTENTS.PKG_A0EPE_RM_MANAGEMENT AS
PROCEDURE SP_A0EPE_RM_MGT_STEP2_U(
IN_USER_ID IN VARCHAR2
,IN_USER_NAME IN CLOB
) AS
V_COUNT INTEGER;
V_STATUS VARCHAR2(50);
V_CD SEP_ARRAY := SEP_ARRAY();
BEGIN
DELETE FROM JTA0EPE_A_RM_DEPT_JOBDUTY
WHERE TENANT_ID = CM_TENANT_ID
AND BUKRS = IN_BUKRS
AND RM_UID = IN_RM_UID;
FOR DEPTJOBDUTYCD IN (
SELECT COLUMN_VALUE DEPT_JOB_CD
FROM TABLE(SF_A0EPZ_LOBSTR_TOKENIZER(IN_JOBDUTY_CD_ARR, PKG_A0EPZ_TYPES.G_ROW_SEP))
)
LOOP
V_DEPT_JOB_CD:=SF_A0EPZ_LOBSTR_TOKENIZER(DEPTJOBDUTYCD.DEPT_JOB_CD, PKG_A0EPZ_TYPES.G_FIELD_SEP);
INSERT INTO JTA0EPE_A_RM_DEPT_JOBDUTY(
TENANT_ID,
BUKRS,
RM_UID,
DEPTCD,
JOBDUTYCD,
CREATOR_ID,
CREATE_DTTM,
UPDATER_ID,
UPDATE_DTTM
) VALUES(
CM_TENANT_ID,
IN_BUKRS,
IN_RM_UID,
V_DEPT_JOB_CD(1),
V_DEPT_JOB_CD(2),
CM_USER_ID,
GET_SERVER_DTTM(),
CM_USER_ID,
GET_SERVER_DTTM()
);
END LOOP;
DELETE FROM JTA0EPE_A_RM_ASSIGN A
WHERE TENANT_ID = CM_TENANT_ID
AND BUKRS = IN_BUKRS
AND RM_UID = IN_RM_UID
AND AUTO_YN= 'D';
FOR IUSER IN (
SELECT U.USER_ID from JTA0EPZ_M_USER u , JTA0EPE_A_RM_DEPT_JOBDUTY d
where u.deptcd = d.deptcd and u.jobdutycd = d.jobdutycd
and u.user_id not in (select aa.user_id from JTA0EPE_A_RM_ASSIGN aa )
and d.TENANT_ID=CM_TENANT_ID and d.BUKRS=IN_BUKRS and d.RM_UID=IN_RM_UID
)LOOP
INSERT INTO JTA0EPE_A_RM_ASSIGN (
TENANT_ID
,BUKRS
,RM_UID
,USER_ID
,ASSIGN_STATUS_CD
,CREATOR_ID
,CREATE_DTTM
,UPDATER_ID
,UPDATE_DTTM
,AUTO_YN
) VALUES (
CM_TENANT_ID
,IN_BUKRS
,IN_RM_UID
,IUSER.USER_ID
,'ASSIGNED'
,CM_USER_ID
,GET_SERVER_DTTM()
,CM_USER_ID
,GET_SERVER_DTTM()
,'D'
);
END LOOP;
END SP_A0EPE_RM_MGT_STEP2_U;
END;