SAP HCM ABAP FAQ
From SapWiki
Contents
- 1 Como leer el MOLGA de un EMPLEADO
- 2 Detalle compañia ( campo BUKRS )
- 3 Nombres de MES ( util en formularios )
- 4 Sumar / Restar meses a fecha
- 5 Ultimo dia del mes
- 6 Leer Horario de trabajo de empleado
- 7 Leer caracteristica ( feature ) HR , transaccion PE03
- 8 Verificar NIF ( RUT )
- 9 Leer clase de fecha de infotipo P0041
- 10 Leer valor clase de tratamiento CC-Nomina
- 11 Leer valor clase de evaluacion CC-Nomina
- 12 Como leer texto centro de costo de empleado P0001-KOSTL
- 13 Tratamiento Infotipo 2011
- 14 Uso de CALL DIALOG para tratamiento de Infotipos
- 15 Ejemplo leer datos dinamicos empleado y exportar a MS WORD
- 16 Como leer codigo de empleado (PERNR) via usuario SAP (SY-UNAME)
- 17 Como leer textos de infotipo
- 18 Como leer datos de payroll dado un RUNID de un posting a FI
- 19 Como leer Modificaciones registradas en log en los datos de los infotipos
- 20 Como Leer Acumuladores
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
Como Leer Acumuladores
data: char96(96), "char-feld fuer 96 char 0/1 hexin(12) type x, "hex feld fuer 96 bit 0/1 x128 type x value '80', hex type x, hextm type x, ps type p, pc type p. data: pack type p,pack1 type p,pack2 type p.
data gd_num type i. data gd_res(1) type c.
gd_num = '85'. "acummulates in /185 perform get_kumul using gd_num gs_t512w-lgart gs_t512w-kumul changing gd_res. if gd_res eq 'X'. * acumula => do something endif.
*---------------------------------------------------------------------* * FORM HEXINCHAR * *---------------------------------------------------------------------* form hexinchar using anzahl. "und Feld HEXIN. if not hexin is initial. * maximale Laenge HEXINPUT ist 12 = L'HEXIN bzw. L'CHAR96/8 s. a. MAX do anzahl times varying hex from hexin(1) next hexin+1(1) range hexin. "UC XMS shift char96 by 8 places. ps = 0. "set sum pc = 10000000. "set char hextm = x128. "set hex do 8 times. if hex o hextm. ps = ps + pc. endif. hextm = hextm / 2. pc = pc / 10. enddo. unpack ps to char96+88(8). enddo. ps = ( 12 - anzahl ) * 8. "MAX = 12, maximale Laenge HEXINPUT shift char96 by ps places. "linksbuendig nach CHAR96 endif. endform. "END OF HEXINCHAR *---------------------------------------------------------------------* * FORM GET_KUMUL * *---------------------------------------------------------------------* form get_kumul using gc_num type i gc_lgart type lgart p_kumul changing gc_acum type c. data gc_kumula like char96.
clear: char96, hexin. clear gc_acum. hexin = p_kumul. perform hexinchar using 12. gc_kumula = char96.
if gc_kumula is not initial. pack = gc_num - 1. "vklas-kl - 1. shift gc_kumula by pack places. if gc_kumula(1) eq '1'. gc_acum = 'X'. else. gc_acum = space. endif. endif. endform. "get_kumul