Skip to Content

Leave Validation in Ess Mss through Badi-CL_PT_ARQ_REQ

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

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on May 20, 2013 at 05:28 AM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member sujit kumar

      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..:)

  • author's profile photo Former Member
    Former Member
    Posted on May 19, 2013 at 01:49 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.