Scenario:SL and CL leaves are accrued monthly basis and when the leave applied if over and above the entitlements (say 1 days is accrued for two months jan and feb) and leave –SL is applied for 2 days,one day need to be deducted from SL quota and remaini
Scenario:SL and CL leaves are accrued monthly basis and when the leave applied if over and above the entitlements (say 1 days is accrued for two months jan and feb) and leave –SL is applied for 2 days,one day need to be deducted from SL quota and remaining one day needs to be deducted from EL quota.whilst quota deduction can be handled in standard configuration ,the challenge is to have absence created in 2001 (EL –one day need to be created in 2001 subtype)
BADI was implemeneted to map the requirement
BADI tcode SE18/SE19
Thanks to his ABAP mate
my abap mate coded something like below
Report ZTEST.
tables: p2001.
DATA RETURN TYPE BAPIRETURN1.
DATA RETURN1 TYPE BAPIRETURN1.
DATA personaldatakey TYPE BAPIPAKEY.
DATA: leave_bal TYPE TABLE OF bapiabwkon,” with header line.
wa LIKE LINE OF leave_bal,
Lt type PRELP.
import leave_bal1 TO leave_bal FROM MEMORY ID ‘leavebal’.
import new_innnn TO Lt FROM MEMORY ID ‘new_innnn’.
p2001–pernr = ‘100097’.
p2001–SUBTY = ‘0100’.
p2001–endda = lt–endda .“”‘20130409’.
p2001–begda = lt–begda.“”‘20130409’.
p2001–AWART = ‘AL’.
*CALL FUNCTION ‘BAPI_EMPLOYEE_ENQUEUE’
* EXPORTING
* NUMBER = ‘100097’
* IMPORTING
* RETURN = RETURN1
.
CALL FUNCTION ‘HR_PSBUFFER_INITIALIZE’.
call function ‘HR_INFOTYPE_OPERATION’
EXPORTING
infty = ‘2001’
number = ‘100097’
SUBTYPE = ‘AL’
* lockindicator = ‘X’
validityend = lt–endda
validitybegin = lt–begda
record = p2001
DIALOG_MODE = ‘2’
NOCOMMIT = ‘X’
operation = ‘INS’
* nocommit = nocommit
objectid = ‘ ‘
tclas = ‘A’ “(tclas = ‘B’ for applicant data)
IMPORTING
return = return
key = personaldatakey
EXCEPTIONS
others = 0.
case return–type.
when ‘E’ or ‘A’.
exit.
when others.
commit work.
MESSAGE ‘Record Created’ type ‘S’.
* LEAVE TO TRANSACTION ‘PA30’.
IF NEW_INNNN–INFTY = ‘2001’ and IPSYST–IOPER = ‘INS’ AND SY–UCOMM IS INITIAL.” AND NEW_INNNN-SUBTY = ‘SLWR’.
DATA RETURN1 TYPE BAPIRETURN1.
DATA: leave_bal1 TYPE TABLE OF bapiabwkon,” with header line.
wa1 LIKE LINE OF leave_bal1,
bal type bapiabwkon–ENTITLE,
leavetype type bapiabwkon–QUOTATYPE.
clear return1.
CALL FUNCTION ‘BAPI_EMPLOYEE_ENQUEUE’
EXPORTING
NUMBER = ‘100097’
IMPORTING
RETURN = RETURN1.
break abc_abap2.
CALL FUNCTION ‘REMAINING_TIMEQUOTA’
EXPORTING
employeenumber = NEW_INNNN–PERNR
LANGUAGE = SY–LANGU
date = NEW_INNNN–BEGDA
TABLES
timequota = leave_bal1.
if leave_bal1[] is not INITIAL.
if NEW_INNNN–subty eq ‘SL’.
leavetype = ’02’.
elseif NEW_INNNN–subty eq ‘MAL’.
leavetype = ’10’.
endif.
loop at leave_bal1 into wa1 where QUOTATYPE eq leavetype and QUOTABEG leNEW_INNNN–begda and QUOTAEND ge NEW_INNNN–endda.
bal = bal + ( wa1–entitle – wa1–deduct ).
endloop.
if bal le 0.
export leave_bal1 from leave_bal1 to memory id ‘leavebal’.
export new_innnn from new_innnn to MEMORY id ‘new_innnn’.
submit ztest and RETURN.
endif.
endif.
CALL FUNCTION ‘BAPI_EMPLOYEE_DEQUEUE’
EXPORTING
NUMBER = ‘100097’
IMPORTING
RETURN = RETURN1.
endif.
ENDCASE.