on 05-19-2013 10:11 AM
Dear All,
We are implementing ESS MSS in webdynpro ABAP and the system is ecc 6.0 and ehp 5.
We need to write the validation for the Leave.
I am trying to write the code in the CL_PT_ARQ_REQ_EXIT and in the method:IF_EX_PT_ABS_REQ~SIMULATE_VIA_BLOP
So what my idea is like if i get the date on which employee is trying to apply the leave then i can apply the logic to calculate the dates and holidays using the function module and i can display the error messages if any invlid clubbing of leave type is done..
So please guide me guys, that how to get the date on which an employee is trying to apply the leave on the ess screen.
I have followed this link:
http://wiki.sdn.sap.com/wiki/display/ERPHCM/Validations+for+ESS+Leave+request
Regards,
Sujit Kumar
Hi,
follow points below.
1)Copy all the code written in the default class.
2)
*"Local Field Symbols
FIELD-SYMBOLS :<lfs_abs_im> TYPE LINE OF ptarq_attabs_deduct_tab,
<lfs_abs_im1> TYPE LINE OF ptarq_attabs_deduct_tab,
<lfs_abs> TYPE LINE OF ptarq_attabsdata_tab,
<lfs_name> TYPE LINE OF tim_p2001_tab,
<lfs_name1> TYPE LINE OF tim_p2002_tab.
*" local Workareas
data : lwa_i2001 TYPE pa2001,
lwa_i2002 TYPE pa2002,
lwa_2001_im TYPE tim_p2001_tab,
lwa_2001 TYPE tim_p2001_tab,
lwa_2002 TYPE tim_p2002_tab,
lt_ptreq_attabsdata TYPE TABLE OF ptreq_attabsdata.
*" Get the item id of 1st record
READ TABLE im_attabs_tab ASSIGNING <lfs_abs> INDEX 1.
lv_item = <lfs_abs>-item_id.
*"fetch record using item id
READ TABLE ex_attabs_deduct_tab ASSIGNING <lfs_abs_im> WITH KEY
item_id = lv_item.
"Move Absences reocrds
lwa_2001 = <lfs_abs_im>-abs_attribs.
*"Move Attendance Records
lwa_2002 = <lfs_abs_im>-atts_attribs.
*" get Absence data i.e 2001 data
LOOP AT lwa_2001 ASSIGNING <lfs_name>.
lwa_i2001-pernr = <lfs_name>-pernr.
lwa_i2001-begda = <lfs_name>-begda.
lwa_i2001-beguz = <lfs_name>-beguz.
lwa_i2001-enduz = <lfs_name>-enduz.
lwa_i2001-endda = <lfs_name>-endda.
lwa_i2001-subty = <lfs_name>-subty.
lwa_i2001-abrtg = <lfs_name>-abrtg.
ENDLOOP.
*" get Attendance data i.e 2002 data
LOOP AT lwa_2002 ASSIGNING <lfs_name1>.
lwa_i2002-pernr = <lfs_name1>-pernr.
lwa_i2002-begda = <lfs_name1>-begda.
lwa_i2002-beguz = <lfs_name1>-beguz.
lwa_i2002-enduz = <lfs_name1>-enduz.
lwa_i2002-endda = <lfs_name1>-endda.
lwa_i2002-subty = <lfs_name1>-subty.
lwa_i2002-abrtg = <lfs_name1>-abrtg.
ENDLOOP.
*" validation for 15 days prior leave cannot be applied
CLEAR lv_check_date.
IF lwa_i2001-begda IS NOT INITIAL.
lv_check_date = lwa_i2001-begda + 15.
ELSEIF lwa_i2002-begda IS NOT INITIAL.
lv_check_date = lwa_i2002-begda + 15.
ENDIF.
IF lv_check_date < sy-datum.
lv_flag = 1.
*" Pass error : leave cannot be applied before 15 days
CALL METHOD message_handler->add_message
EXPORTING
im_type = lc_im_type "Type of Message
im_cl = lc_im_cl "Message class that you created
im_number = lc_msgno5 "Message no
im_par1 = lc_im_par1
im_par2 = lc_im_par2 "Method name as in your impl.
im_par3 = lc_im_par3
im_context = lc_im_context
im_subcontext = lc_im_subcontext
im_classname = lc_im_classname
im_methodname = lc_im_methodname.
EXIT.
ENDIF.
Do exactly as written above .
For combination of leaves create a Ztable and with structure start date ,enddate,leave type 1, leave type2 and all of them primary key.
then use below code.
CLEAR lv_flag.
LOOP AT lt_ptreq_attabsdata INTO lwa_ptreq_attabsdata.
SELECT SINGLE item_list_id INTO lv_item_list_id
FROM ptreq_items WHERE item_ins EQ lwa_ptreq_attabsdata-item_id.
IF sy-subrc = 0.
SELECT * FROM ptreq_header INTO
TABLE lt_ptreq_header WHERE item_list_id EQ lv_item_list_id
AND request_type EQ lc_req.
IF sy-subrc = 0.
SORT lt_ptreq_header BY version_no.
LOOP AT lt_ptreq_header INTO lwa_ptreq_header.
ENDLOOP.
IF lwa_ptreq_header-status = lc_rej OR lwa_ptreq_header-status = lc_with.
ELSE.
LOOP AT lt_zhrt_leave_comb INTO lwa_zhrt_leave_comb WHERE zl_leave1 EQ lwa_i2001-subty .
IF lwa_zhrt_leave_comb-zl_leave2 = lwa_ptreq_attabsdata-subty .
IF lwa_ptreq_attabsdata-operation = lc_ins.
lv_flag = 1.
ENDIF.
ELSEIF lwa_ptreq_attabsdata-operation = lc_del.
lv_flag = ''.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
ENDIF.
ENDLOOP.
ENDIF.
ENDIF.
IF lv_flag = 1 AND lv_same EQ abap_true.
CALL METHOD message_handler->add_message
EXPORTING
im_type = lc_im_type "Type of Message
im_cl = lc_im_cl "Message class that you created
im_number = lc_msgno3 "Message no
im_par1 = lc_im_par1
im_par2 = lc_im_par2 "Method name as in your impl.
im_par3 = lc_im_par3
im_context = lc_im_context
im_subcontext = lc_im_subcontext
im_classname = lc_im_classname
im_methodname = lc_im_methodname.
EXIT.
ELSE.
CALL METHOD message_handler->add_message
EXPORTING
im_type = lc_im_type "Type of Message
im_cl = lc_im_cl "Message class that you created
im_number = lc_msgno3 "Message no
im_par1 = lc_im_par1
im_par2 = lc_im_par2 "Method name as in your impl.
im_par3 = lc_im_par3
im_context = lc_im_context
im_subcontext = lc_im_subcontext
im_classname = lc_im_classname
im_methodname = lc_im_methodname.
EXIT.
ENDIF.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Siddhartha,
I understood!!
M trying the same.. but u stuck up at the table creation..
What fields it sud have??
like i want that earned leave cannot be clubbed with the casual leave like that..
So how to create the table with the field leave type 1 and 2 etc etc..
as all the leaves will have only one field and they are based on subty,,
Please guide..
Reg,
Sujit karn
Hi Sujit,
Ztable is just to aviod the harcoding of absences codes in code. My table structure is like this.
Start Date End Date ATY1 ATY2
01.01.2013 31.12.9999 1000 1000
01.01.2013 31.12.9999 1000 1001
01.01.2013 31.12.9999 1000 1016
Now which ever clubbing is not allowed, i put that entry in this table. for ex-- 1000(PL) cannot be clubbed with 1001(CL)....
Likewise you can fulfil your requirement. Table is created because its easy for client to maintain. Any changes in future can be handled through this table rather than getting into code and do technical changes for any single combination.
Regards:
Siddhartha
Dear Siddharth,
Ok i got it..
One more little concern:
If an employee apply an cl on friday, then he sud not be able to apply an pl on monday so how to validate it.. for validating according to the invalid combination as per the table entry how can we check on the previous dates applied leave and if any holiday is there in between how to check that?
Please elaborate.
Thanks,
Sujit
Hi Sujith,
For Previous day and next day follow below code...
intervening woff and Public holiday needs to be checked thru badi only
constants : lc_pos TYPE t5a4a-split VALUE '+',
lc_neg TYPE t5a4a-split VALUE '-',
for the date for which u are appling leave check one day back and one day ahead.
*"for Leave Combination get previous date
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = lwa_i2001-begda
days = 1
months = lc_per
signum = lc_neg
years = lc_per
IMPORTING
calc_date = lv_prev_date.
*For Leave Combination get next date
CALL FUNCTION 'RP_CALC_DATE_IN_INTERVAL'
EXPORTING
date = lwa_i2001-endda
days = 1
months = lc_per
signum = lc_pos
years = lc_per
IMPORTING
calc_date = lv_next_date.
DO.
REFRESH lt_dws_prev.
CLEAR lwa_dws_prev.
CALL FUNCTION 'HR_PERSONAL_WORK_SCHEDULE'
EXPORTING
pernr = lwa_i2001-pernr
begda = lv_prev_date
endda = lv_prev_date
TABLES
perws = lt_dws_prev
EXCEPTIONS
error_occured = 1
abort_occured = 2
OTHERS = 3.
*"check for WOFF,PH,Second Saturday
READ TABLE lt_dws_prev INTO lwa_dws_prev INDEX 1.
IF ( lwa_dws_prev-tpkla = lc_tpkla OR lwa_dws_prev-tagty = lc_tagty OR lwa_dws_prev-ftkla = lc_ftkla ).
lv_woff_flag = abap_true.
lv_prev_date = lv_prev_date - 1.
ELSE.
EXIT.
ENDIF.
ENDDO.
DO.
REFRESH lt_dws_next.
CLEAR lwa_dws_next.
CALL FUNCTION 'HR_PERSONAL_WORK_SCHEDULE'
EXPORTING
pernr = lwa_i2001-pernr
begda = lv_next_date
endda = lv_next_date
TABLES
perws = lt_dws_next
EXCEPTIONS
error_occured = 1
abort_occured = 2
OTHERS = 3.
*"check for WOFF,PH,Second Saturday
READ TABLE lt_dws_next INTO lwa_dws_next INDEX 1.
IF ( lwa_dws_prev-tpkla = lc_tpkla OR lwa_dws_prev-tagty = lc_tagty OR lwa_dws_prev-ftkla = lc_ftkla ).
lv_woff_flag = abap_true.
lv_next_date = lv_next_date + 1.
ELSE.
EXIT.
ENDIF.
ENDDO.
SELECT * FROM ptreq_attabsdata
INTO TABLE lt_ptreq_attabsdata_pre
WHERE pernr EQ lwa_i2001-pernr
AND infotype EQ lc_2001
AND operation EQ lc_ins
AND endda GE lv_prev_date
AND begda LE lv_prev_date.
SELECT * FROM ptreq_attabsdata
INTO TABLE lt_ptreq_attabsdata_next
WHERE pernr EQ lwa_i2001-pernr
AND infotype EQ lc_2001
AND operation EQ lc_ins
AND endda GE lv_next_date
AND begda LE lv_next_date.
and apply logic as per your condtions...
Hope it helps..:)
Hello Sujith,
Read the data from internal table im_attabs_tab.
check below sample code:
data :wa_attribs type line of tim_p2001_tab,
lv_begda type begda,
**Read the current absence record
read table im_attabs_tab into attabs_temp index 1.
clear:wa_attribs.
read table attabs_temp-abs_attribs into wa_attribs index 1.
lv_begda = wa_attribs-begda.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
9 | |
9 | |
5 | |
4 | |
3 | |
3 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.