Difference between revisions of "SAP HCM BADI"

From SapWiki
Line 80: Line 80:
  
 
===ejemplo de AFTER_INPUT===
 
===ejemplo de AFTER_INPUT===
 +
* validar fechas al actualizar IT0041
 
  method IF_EX_HRPAD00INFTY~AFTER_INPUT.
 
  method IF_EX_HRPAD00INFTY~AFTER_INPUT.
 
   
 
   

Revision as of 18:51, 27 March 2020

BADI HRPAD00INFTY (Tarea actualiz./Actualiz.infotipo)

ejemplo de IN_UPDATE

  • enviar datos a sistema externo al crear, modificar o borrar registros de IT2001 y IT2002
METHOD if_ex_hrpad00infty~in_update.
  DATA: lt_p0001 TYPE TABLE OF p0001,
        ls_p0001 TYPE p0001.

  DATA: lt_oper TYPE TABLE OF psoper,
        ls_oper  TYPE psoper,
        ls_prel  TYPE prelp,
        ls_prel_old  TYPE prelp.

  DATA: ls_t503 TYPE t503,
        ls_t001p TYPE t001p.

  DATA l_f(1).

  CHECK ipspar-infty = '2001' OR ipspar-infty = '2002'.

  CLEAR: ls_oper.
  LOOP AT new_image INTO ls_oper WHERE infty = '2001' or infty = '2002'.
    APPEND ls_oper TO lt_oper.
  ENDLOOP.

  sort lt_oper by opera.  "primero borrar 'D' => después insertar 'I'

  CLEAR: ls_oper.
  LOOP AT old_image INTO ls_oper WHERE infty = '2001' or infty = '2002'.
    MOVE-CORRESPONDING ls_oper TO ls_prel_old.
    EXIT.
  ENDLOOP.

  CALL FUNCTION 'HR_READ_INFOTYPE'
    EXPORTING
      pernr           = ipspar-pernr
      infty           = '0001'
    TABLES
      infty_tab       = lt_p0001
    EXCEPTIONS
      infty_not_found = 1
      OTHERS          = 2.
  IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
  ENDIF.

  LOOP AT lt_p0001 INTO ls_p0001 WHERE begda <= ipspar-endda AND
                                       endda >= ipspar-begda.
  ENDLOOP.

  SELECT SINGLE * INTO ls_t503 FROM  t503
         WHERE  persg  = ls_p0001-persg
         AND    persk  = ls_p0001-persk.

  SELECT SINGLE * INTO ls_t001p FROM  t001p
         WHERE  werks  = ls_p0001-werks
         AND    btrtl  = ls_p0001-btrtl.

  LOOP AT lt_oper INTO ls_oper.
    MOVE-CORRESPONDING ls_oper TO ls_prel.

    CALL FUNCTION 'Z_HCM_ENVIA_DATA'
      EXPORTING
        tclas                 = ipspar-tclas
        innnn                 = ls_prel
        i001p                 = ls_t001p
        i_opera               = ls_oper-opera
     EXCEPTIONS
       error_occured         = 1
       OTHERS                = 2
              .
    IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
  ENDLOOP.

ENDMETHOD.

ejemplo de AFTER_INPUT

  • validar fechas al actualizar IT0041
method IF_EX_HRPAD00INFTY~AFTER_INPUT.

  DATA: ls_p0041 TYPE p0041,
        lv_date TYPE begda,
        lv_date2 TYPE begda,
        lv_date3 TYPE begda,
        lv_years(4) type n.

  DATA: datar_0041 TYPE datar,
        date_0041  TYPE datum.
** Check country code
  CHECK i001p-molga EQ '39'.  "CL Chile
** Check infotype
  CHECK new_innnn-infty EQ '0041'.
** No check for Delete operation
  CHECK NOT ipsyst-ioper = 'DEL'.
** Convert to structure
  CALL METHOD cl_hr_pnnnn_type_cast=>prelp_to_pnnnn
    EXPORTING
      prelp = new_innnn
    IMPORTING
      pnnnn = ls_p0041.

    DO 12 TIMES VARYING datar_0041 FROM ls_p0041-dar01 NEXT ls_p0041-dar02
              VARYING date_0041  FROM ls_p0041-dat01 NEXT ls_p0041-dat02.
    IF datar_0041 = '07'.  "vacaciones legales
      lv_date = date_0041.
    ELSEIF datar_0041 = '02'. "antiguedad
      lv_date2 = date_0041.
    ELSEIF datar_0041 = '04'. "progresivos
      lv_date3 = date_0041.
*    ELSEIF date_0041 IS INITIAL.
*      EXIT.
    ENDIF.
  ENDDO.

  if lv_date <> lv_date2.
    MESSAGE e016(RP) WITH 'Fecha Vac. Legales' lv_date 'distinto a Fecha Antigüedad'  lv_date2.
  endif.

  if lv_date3(4) < lv_date2(4).
    lv_years = lv_date2(4) - lv_date3(4).

    if lv_years > 10.
      message e016(RP) WITH 'Fecha Progresivos'
                            'permite el reconocimiento máximo de 10 años'
                            'respecto a Fecha Antigüedad' lv_date2.
    ELSEIF lv_date3+4(4) NE lv_date2+4(4).
        message e016(RP) WITH 'Mes y día de progresivos deben ser'
                              'igual al de antigüedad legal'.
    endif.
  endif.

endmethod.