SAP HCM BADI

From SapWiki

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.

BADI HRFORM_HRF02

Como obtener el PDF de un recibo de sueldo creado vía trn. HRFORMS y formulario definido como Smartform:

  • Implementar badi HRFORM_HRF02 método GET_FDATA
  method IF_EX_HRFORM_HRF02~GET_FDATA.
    CALL FUNCTION 'Z_GET_FDATA'
      EXPORTING
        i_fdata       = fdata
              .
  endmethod.
  • Crear grupo de Función ZHCM_PAYSLIP y crear la función
FUNCTION z_get_fdata.
*"----------------------------------------------------------------------
*"*"Interfase local
*"  IMPORTING
*"     REFERENCE(I_FDATA) TYPE  ANY
*"----------------------------------------------------------------------
* ver BADI HRFORM_HRF02_CL method get_data
  DATA ls_fdata TYPE /1pyxxfo/zpayslip_cl.

  MOVE i_fdata TO ls_fdata.

*gt_data definido como global en el grupo de función 
*data gt_fdata type TABLE OF /1PYXXFO/ZPAYSLIP_CL.

  APPEND ls_fdata TO gt_fdata. 
  EXPORT gt_fdata TO MEMORY ID 'ZPAYSLIP_CL'.

ENDFUNCTION.
  • Copiar programa HINU_HRFORMS_MAIL (ver nota 2004408 - HR-IN: HRForms Payslip via e-mail), al final del proceso(después de los SUBMIT (gv_report) ) obtener el fdata y obtener PDF del smartform, algo equivalente a:
* ver BADI HRFORM_HRF02_CL method get_data
* obtiene datos de la impresión del recibo de sueldo
  IMPORT gt_fdata TO gt_fdata FROM MEMORY ID 'ZPAYSLIP_CL'.
  
  loop at gt_fdata into data(wa).
....
....
....
    CALL FUNCTION ld_func_module_name
    EXPORTING
      control_parameters = ls_control_parameters
      output_options     = ls_output_options
      user_settings      = space
      hrdata             = wa
    IMPORTING
      job_output_info    = ls_output
    EXCEPTIONS
      formatting_error   = 1
      internal_error     = 2
      send_error         = 3
      user_canceled      = 4
      OTHERS             = 5.
...
...
...
 endloop.

Enhancement Spot PT_ABS_REQ

Este add-in empresarial (BAdI) se utiliza en el componente PT-RC-AA (Presencias/Absentismos). Se utiliza para las aplicaciones Web siguientes:

  • solicitud de absentismo: Control del procesamiento de solicitudes de absentismo. Encontrará más información en la guía de implementación (IMG) bajo Gestión de personal -> Employee Self-Service.
  • calendario de equipo: Configuración del calendario de equipo en el Manager Self-Service (MSS) y en el Employee Self-Service (ESS)
  • cuentas de tiempos (ESS): Determinación de las cuentas de tiempos
  • resumen de presencias (MSS): Ajustar leyenda

ejemplo:

METHOD if_ex_pt_abs_req~simulate_via_blop.
    DATA message_handler TYPE REF TO if_pt_req_message_handler.
    IF 1 = 2.
      CALL METHOD cl_pt_req_message_handler=>instance_get
        RECEIVING
          result = message_handler.

      CALL METHOD message_handler->add_message
        EXPORTING
          im_type       = 'E'                                           "Type of Message
          im_cl         = '0K'                                         "Message class that you created
          im_number     = '000'                                         "Message no
          im_par1       = 'SIMULATE_VIA_BLOP'
          im_par2       = 'IF_EX_PT_ABS_REQ~SIMULATE_VIA_BLOP'          "Method name as in your impl.
          im_par3       = 'BLOP'
          im_context    = ''
          im_subcontext = ''
          im_classname  = 'CL_PT_ARQ_BLOP_ADAPTER'
          im_methodname = 'MESSAGE'.
    ENDIF.
  ENDMETHOD.

HRPAY99_CURR_CONV - Implementación Cálculo de nómina: Conversión de moneda

Ejecutada desde FM HR_CONVERT_TO_LOCAL_CURRENCY

METHOD if_ex_hrpay99_curr_conv~set_conv_date_type.

* Some of the input data can be derived (compare with function
* PCLO_COMPUTE_REPAYMENT_PLAN):
*
* EMPLOYEENUMBER -> PT_P0001
* EMPLOYEENUMBER, PT_P0001 -> FLT_VAL (= MOLGA), lt_abkrs_from_p0001
* some date, lt_abkrs_from_p0001 -> PAYROLL_AREA, PERIOD_MODIFIER
* some date, PAYROLL_AREA, lt_abkrs_from_p0001
*                     -> PAYROLL_PERIOD, PERIOD_BEGIN, PERIOD_END
*
* Notice, that in case of splitted periods (WPBP split, partial
* periods), the estimated PEIROD_BEGIN and PERIOD_END could differ
* from the ones given as parameter (APER-BEGDA, APER-ENDDA).
*
* Think on retrocalculation differences.
*
* Be carfull when using an other date than proposed_convdate,
* because this may be set due to legal requirements; especially
* when proposed_convdate differs from period begin.

  pfx_type_of_rate = proposed_type_of_rate.
  pfx_conversion_date = proposed_convdate.

  IF sy-cprog <> 'HCLCALC0'. "Programa de nómina Chile
    RETURN.
  ENDIF.

  DATA ls_t511p TYPE t511p.
  DATA: lw_var(40) TYPE c.
  FIELD-SYMBOLS <fs> TYPE any.

  lw_var = '(HCLCALC0)T511P'.
  ASSIGN (lw_var) TO <fs>.
  IF sy-subrc = 0 AND <fs> IS ASSIGNED.
    MOVE <fs> TO ls_t511p.
  ELSE.
    RETURN.
  ENDIF.

  IF ps_currconv_data-foreign_currency = 'UF' AND
     ps_currconv_data-countryhr = '39' AND
     ls_t511p-konst = 'ZBSC1' AND
     proposed_type_of_rate = 'M'.

    CALL FUNCTION 'RP_LAST_DAY_OF_MONTHS'
      EXPORTING
        day_in            = proposed_convdate
      IMPORTING
        last_day_of_month = pfx_conversion_date
      EXCEPTIONS
        day_in_no_date    = 1
        OTHERS            = 2.
  ENDIF.

ENDMETHOD.

Ampliación PBAS0001 , exits EXIT_SAPFP50M_001 EXIT_SAPFP50M_002 (trn CMOD/SMOD)

ejemplo EXIT_SAPFP50M_002

data ls_p0021 type p0021.
data l_result_date type d.

case innnn-infty.
  when '0021'.
    check ipsyst-ioper = modify or
          ipsyst-ioper = insert or
          ipsyst-ioper = copy.

    clear: ls_p0021.
    call method cl_hr_pnnnn_type_cast=>prelp_to_pnnnn
      exporting
        prelp = innnn
      importing
        pnnnn = ls_p0021.

    if ls_p0021-famsa = '2'.  "hijo.

*sumar 18 años a fecha de nacimiento y limitar
      call function 'CALCULATE_DATE'
        exporting
          days        = '0'
          months      = '216'   "18 años
          start_date  = ls_p0021-fgbdt
        importing
          result_date = l_result_date.

      l_result_date+4 = '1231'.

      if l_result_date >= innnn-begda.
        innnn-endda = l_result_date.
      endif.

    endif.

endcase.