SAP HCM ABAP FAQ

From SapWiki
Revision as of 20:09, 26 March 2020 by WikiSysop (talk | contribs)

Como leer el MOLGA de un EMPLEADO

   CALL FUNCTION 'HR_COUNTRYGROUPING_GET'
    EXPORTING
      pernr           = gd_pernr
      begda           = datum
      endda           = datum
    IMPORTING
      molga           = gd_molga
    EXCEPTIONS
      not_found       = 1
      OTHERS          = 2
             .

Detalle compañia ( campo BUKRS )

   call function 'FI_COMPANYCODE_GETDETAIL'
        exporting
             bukrs_int                  = pnpbukrs-low
             authority_check            = space
        importing
             t001_int                   = comp_det
        tables
             t001z_int                  = appendix
        exceptions
             bukrs_not_found            = 1
             no_authority_display_bukrs = 2
             others                     = 3.

Nombres de MES ( util en formularios )

   call function 'MONTH_NAMES_GET'
*     EXPORTING
*       LANGUAGE                    = SY-LANGU
*     IMPORTING
*       RETURN_CODE                 =
     tables
       month_names                 = names
    exceptions
      month_names_not_found       = 1
      others                      = 2.

Sumar / Restar meses a fecha

   call function 'HR_BR_ADD_MONTH_TO_DATE'
     exporting
       dmm_datin       = first_day
       dmm_count       = '1'
       dmm_oper        = '-'
       dmm_pos         = ' '
    importing
      dmm_daout       = aux_date.

Ultimo dia del mes

       call function 'LAST_DAY_OF_MONTHS'
         exporting
           day_in            = pnpbegda
         importing
           last_day_of_month = pnpendda
         exceptions
           day_in_no_date    = 1
           others            = 2.

Leer Horario de trabajo de empleado

 wa_pernr-pernr = p_pernr.
 append wa_pernr to tb_pernr.
 call function 'HR_PERSON_READ_WORK_SCHEDULE'
   exporting
     begin_date                = p_begda
     end_date                  = p_endda
*   GROUPING_DWS              =
*   GROUPING_ATTENDENCE       =
*   GROUPING_SUBSTITUTE       =
*   READ_FROM_DATABASE        = ' '
   tables
     pernr_tab                 = tb_pernr
     psp                       = tb_psp
    day_psp                   = tb_day_psp
 exceptions
  error_in_build_psp        = 1
  others                    = 2
           .

Leer caracteristica ( feature ) HR , transaccion PE03

 data pben0 like zben0.
 data l_back(5).
* fill feature structure
 clear pben0.
 pben0-barea = p_barea.
 pben0-bplan = p_bplan.
 pben0-depcv = 'DEP0'.   "Dummy
 clear p_val.
* get value of from feature (PE03 transaction)
 call function 'HR_FEATURE_BACKFIELD'
   exporting
     feature                     = 'ZBEN0'
     struc_content               = pben0
   importing
     back                        = l_back
   exceptions
     dummy                       = 1
     error_operation             = 2
     no_backvalue                = 3
     feature_not_generated       = 4
     invalid_sign_in_funid       = 5
     field_in_report_tab_in_pe03 = 6
     others                      = 7.
 if sy-subrc ne 0.
   p_val = space.
 else.
   if l_back <> space.
     p_val = 'X'.
   else.
     p_val = space.
   endif.
 endif.

Verificar NIF ( RUT )

call function 'TAX_NUMBER_CHECK'
 exporting
   country                  = p_land1
  tax_code_1                = p_stcd1
.

Leer clase de fecha de infotipo P0041

Form get_fecha using p0041 like p0041
                      P_dar like p0041-dar01
                      Changing p_fecha.
           DATA ld_dat LIKE p0041-dat01.
           DATA ld_dar LIKE p0041-dar01.
           CLEAR p_fecha.
           DO 12 TIMES VARYING ld_dat FROM p0041-dat01 NEXT p0041-dat02
                       VARYING ld_dar FROM p0041-dar01 NEXT p0041-dar02.
             IF ld_dar = p_dar.
               p_fecha = ld_dat.
             ENDIF.
           ENDDO.
Endform.

Leer valor clase de tratamiento CC-Nomina

*&---------------------------------------------------------------------*
*&      Form  VWTCL
*&---------------------------------------------------------------------*
*       Rescata valor de clase de tratamiento
*----------------------------------------------------------------------*
*      -->p_LGART       : ccnómina                                   *
*      -->p_CLTRAT      : clase de tratamiento                       *
*      <--p_V_CLTRAT    : valor clase de tratamiento                 *
*----------------------------------------------------------------------*
form vwtcl using i_lgart    type lgart
                i_cltrat   type c
                i_date     type d
       changing o_v_cltrat type c.
 data pack type i.
 data char100(100).
 perform read_t512w using i_lgart
                          i_date
                   changing gst_t512w.
 pack = i_cltrat - 1.
 char100 = gst_t512w-vklas.
 shift char100 by pack places.
 o_v_cltrat(1) = char100(1).
endform.           "vwtcl
*---------------------------------------------------------------------*
*       FORM read_t512w                                               *
*---------------------------------------------------------------------*
*       ........                                                      *
*---------------------------------------------------------------------*
form read_t512w using
                     i_lgart
                     i_date type d
                    changing o_t512w like t512w.
 clear o_t512w.
 loop at gtb_t512w into o_t512w
                      where lgart = i_lgart
                         and molga = '99'
                         and endda >= i_date
                         and begda <= i_date.
 endloop.
 if sy-subrc ne 0.
   select single * into o_t512w from t512w
                                 where  molga  = '99'
                                    and lgart  = i_lgart
                                    and endda >= i_date
                                    and begda <= i_date.
   if sy-subrc eq 0.
     append o_t512w to gtb_t512w.
   endif.
 endif.
endform.                                                    "read_t512w

Leer valor clase de evaluacion CC-Nomina

*&---------------------------------------------------------------------*
*&      Form  VWECL
*&---------------------------------------------------------------------*
*       Rescata valor de clase de evaluación
*----------------------------------------------------------------------*
*      -->TEV_LGART       : ccnómina                                   *
*      -->TEV_CLEVAL      : clase de evaluación                        *
*      <--TEV_V_CLEVAL    : valor clase de evaluación                  *
*----------------------------------------------------------------------*
form vwecl using tev_lgart    like it-lgart
                tev_cleval type c
       changing tev_v_cleval type c.
 cdatum = aper-endda.
 clgart = tev_lgart.
 perform re512w.
 pack = ( tev_cleval - 1 ) * 2.      "vklas-kl - 1.
 char100 = t512w-aklas.
 shift char100 by pack places.
 tev_v_cleval = char100(2).
endform.           "vwecl

Como leer texto centro de costo de empleado P0001-KOSTL

*&---------------------------------------------------------------------*
*&      Form  get_costcenter_text
*&---------------------------------------------------------------------*
form get_costcenter_text using pp_bukrs type bukrs
                              pp_kokrs type kokrs
                              p_inform_tab_kostl
                     changing p_inform_tab_kname.
 data: l_kostl like hrca_costc-costcenter,
       l_kname like hrca_costc-name,
       l_kokrs like hrca_costc-contrlarea.
 l_kostl = p_inform_tab_kostl.
 if pp_kokrs is initial.
   call function 'HRCA_CONTROLLINGAREA_FIND'
     exporting
       companycode = pp_bukrs
     importing
       contrlarea  = l_kokrs
     exceptions
       not_found   = 1
       others      = 2.
 else.
   l_kokrs = pp_kokrs.
 endif.
 call function 'HR_READ_FOREIGN_OBJECT_TEXT'
   exporting
     otype                   = 'K'
     costcenter              = l_kostl
     controllingarea         = l_kokrs
   importing
     costcenter_name         = l_kname
   exceptions
     nothing_found           = 1
     wrong_objecttype        = 2
     missing_costcenter_data = 3
     missing_object_id       = 4
     others                  = 5.
 p_inform_tab_kname = l_kname.
endform.                               " get_costcenter_text

Tratamiento Infotipo 2011

Los registros del IT2011 no se almacenan en una tabla tipo PANNNN, con NNNN = Nº Infotipo, sino en la tabla TEVEN, por lo que funciones como HR_READ_INFOTYPE, no sirven para leer los datos del IT2011, entonces un ejemplo de lectura del IT2011 es como el siguiente

     SELECT * FROM teven
              APPENDING TABLE it_teven
              WHERE pernr EQ it_pernr_plan-pernr
                    AND ldate EQ  fec_ev
                    AND stokz EQ space.

A su vez, para borrar un registro se debe utilizar un codigo como el siguiente

   teven = i_teven.
   IF teven-stokz EQ space.                                "PH9K012236
     teven-stokz = 'X'.
*    IF teven-origf EQ space.
* Bei Original-Zeitereignissen wird protokolliert, wer gelöscht hat.
     teven-uname = sy-uname.
     teven-aedtm = sy-datum.
*    ENDIF.
     UPDATE teven.
   ENDIF.

se observa que se marca a el flag STOKZ con una 'X'

Uso de CALL DIALOG para tratamiento de Infotipos

DATA: dialog_name TYPE dialg.
DATA: BEGIN OF ps OCCURS 20.
       INCLUDE STRUCTURE prelp.
DATA:   opera,                         "'U'=Update,'D'=Delete,'I'=Insert
       auth.                                               "qice5338
DATA: END OF ps.
DATA: BEGIN OF preftab OCCURS 5.
        INCLUDE STRUCTURE pref.
DATA:   opera(1).
DATA: END OF preftab.
DATA: wt TYPE STANDARD TABLE OF p0001.
DATA: BEGIN OF i582a OCCURS 20.
       INCLUDE STRUCTURE t582a.
DATA: END OF i582a.
     dialog_name = 'RP_2012'.
     pspar-pernr = wa_gt_outtab-pernr.
     pspar-infty = '2012'.
     pspar-ittxt = 'Val.prefijados transfer.tmpo.'.
     pspar-tclas = 'A'.
     pspar-aktyp = 'P'.
     pspar-begda = fec_ev.
     pspar-endda = fec_ev.
     pspar-actio = 'FAST'.
     pspar-enque = 1.
     pspar-msgst = '1'.
       CALL DIALOG dialog_name
        EXPORTING pspar FROM pspar
                  psinfo FROM psinfo
                  ps  FROM ps
                  preftab FROM preftab
                  wt FROM wt
                  i582a FROM i582a
                  dynmeas FROM dynmeas
                  initial_values FROM initial_values.

ejemplo 2

FORM ver_pa51 USING    p_row.
 DATA: pspar_2051 LIKE pspar.
 CLEAR: pspar.
 READ TABLE gt_outtab INDEX p_row.
 pspar_2051-pernr = gt_outtab-pernr.
 pspar_2051-infty = '2051'.
*  pspar_0006-ittxt = 'Direcciones'.
 pspar_2051-tclas = 'A'.
 pspar_2051-aktyp = 'A'.
 pspar_2051-actio = 'DIS'.
 pspar_2051-repna = 'MP205100'.
 pspar_2051-msgst = '1'.
 CONCATENATE fec_ev+0(6) '01' INTO pspar_2051-begda.
 pspar-endda = fec_ev.
 CALL DIALOG 'RP_2051'
   EXPORTING
     pspar FROM pspar_2051.
ENDFORM.                                                    " ver_pa51

Ejemplo leer datos dinamicos empleado y exportar a MS WORD

Ver programa RPLICO10

Como leer codigo de empleado (PERNR) via usuario SAP (SY-UNAME)

Función BAPI_USR01DOHR_GETEMPLOYEE

Como leer textos de infotipo

ejemplo I0035

 data : pskey type pskey.
 data : mytext TYPE HRPAD_TEXT_TAB .
 loop at p0035.
   e_salida-begda_0035 =  p0035-begda.
   e_salida-dat35      =  p0035-dat35.
   e_salida-blehr      = p0035-blehr.
   pskey-pernr = p0035-pernr.
   pskey-infty = '0035'.
   pskey-subty = p0035-subty.
   pskey-endda = p0035-endda.
   pskey-begda = p0035-begda.
*TRY.
   CALL METHOD CL_HRPA_TEXT_CLUSTER=>READ
     EXPORTING
       TCLAS         = 'A'
       PSKEY         = pskey
       NO_AUTH_CHECK = 
     IMPORTING
       TEXT_TAB      = mytext.
   DATA : ABC LIKE line of MYTEXT.
   LOOP AT MYTEXT INTO ABC.
   endloop.

Como leer datos de payroll dado un RUNID de un posting a FI

*&---------------------------------------------------------------------*
*&      Form  get_seqnr
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->I_PERNR    text
*      -->I_RUNID    text
*      -->O_SEQNO    text
*----------------------------------------------------------------------*
FORM get_seqnr USING i_pernr
                    i_runid
           CHANGING o_seqno.
 DATA ld_runid LIKE pcalac-runid.
 SELECT runid seqno INTO (ld_runid,o_seqno) FROM  pcalac UP TO 1 ROWS
        WHERE  pernr  = i_pernr
        AND    runid  = i_runid
   ORDER BY runid DESCENDING.
 ENDSELECT.
ENDFORM.                    "get_seqnr
*&---------------------------------------------------------------------*
*&      Form  get_rgdir
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->I_PERNR    text
*      -->I_SEQNO    text
*      -->O_INOCR    text
*      -->O_DATE     text
*----------------------------------------------------------------------*
FORM get_rgdir USING i_pernr
                    i_seqno
           CHANGING o_inocr
                    o_date.
 SELECT SINGLE inocr fpend INTO (o_inocr,o_date)
                       FROM hrpy_rgdir
                       WHERE pernr = i_pernr
                        AND  seqnr  = i_seqno.
 IF sy-subrc NE 0.
   CLEAR o_inocr.
   CLEAR o_date.
 ENDIF.
ENDFORM.                    "get_rgdir
*&---------------------------------------------------------------------*
*&      Form  get_payroll_data
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->I_PERNR    text
*      -->I_RUNID    text
*      -->O_INOCR    text
*      -->O_FPEND    text
*----------------------------------------------------------------------*
FORM get_payroll_data USING i_pernr
                           i_runid
                   CHANGING o_inocr
                            o_fpend.
 DATA ld_seqno LIKE pcalac-seqno.
 PERFORM get_seqnr USING i_pernr
               i_runid
      CHANGING ld_seqno.
 PERFORM get_rgdir USING i_pernr
                      ld_seqno
             CHANGING o_inocr
                      o_fpend.
ENDFORM.                    "get_payroll_data

Como leer Modificaciones registradas en log en los datos de los infotipos

Reporte RPUAUD00 para leer modificaciones en los infotipos