Difference between revisions of "SAP HCM ABAP FAQ"
From SapWiki
Line 601: | Line 601: | ||
==Ejemplo Lectura IT0008== | ==Ejemplo Lectura IT0008== | ||
− | + | Ojo que esta BAPI calcula los conceptos indirectos :-) | |
− | |||
FORM get_p0008_detail tables gt_bapi_wagetypes structure bapip0008p | FORM get_p0008_detail tables gt_bapi_wagetypes structure bapip0008p |
Revision as of 20:59, 5 April 2020
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 Obtener fecha de retorno de un absentismo(P2001)
- 8 Leer caracteristica ( feature ) HR , transaccion PE03
- 9 Verificar NIF ( RUT )
- 10 Leer clase de fecha de infotipo P0041
- 11 Leer valor clase de tratamiento CC-Nomina
- 12 Leer valor clase de evaluacion CC-Nomina
- 13 Como leer texto centro de costo de empleado P0001-KOSTL
- 14 Tratamiento Infotipo 2011
- 15 Uso de CALL DIALOG para tratamiento de Infotipos
- 16 Ejemplo leer datos dinamicos empleado y exportar a MS WORD
- 17 Como leer codigo de empleado (PERNR) via usuario SAP (SY-UNAME)
- 18 Como leer textos de infotipo
- 19 Como leer datos de payroll dado un RUNID de un posting a FI
- 20 Como leer Modificaciones registradas en log en los datos de los infotipos
- 21 Como Leer Acumuladores
- 22 Ejemplo Lectura IT0008
- 23 Ejemplos estructura organizacional
- 24 Lectura de Datos Maestros (Grupo Funciones HRWPC_GENERAL_TEXTS)
- 25 Edad de empleado
- 26 Crear Absentismo
- 27 Rutinas para leer contingente
- 28 Ejemplo de HR_INFOTYPE_OPERATION
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 .
Obtener fecha de retorno de un absentismo(P2001)
p2001-endda = p2001-endda + 1. perform fecha_retorno using p2001-pernr changing p2001-endda. form fecha_retorno using p_pernr type p2001-pernr changing p_fch_retorno type p2001-begda. data l_feriado type flag. do 10 times. clear l_feriado. PERFORM es_dia_libre USING p_pernr p_fch_retorno CHANGING l_feriado. if l_feriado = 'X'. add 1 to p_fch_retorno. else. return. endif. enddo. endform. FORM es_dia_libre USING p_pernr TYPE p2001-pernr p_begda TYPE p2001-begda CHANGING p_libre TYPE xfeld. DATA: lt_persavail TYPE STANDARD TABLE OF pdpsp. CALL FUNCTION 'HR_READ_TIMEDATA_PSP' EXPORTING begin_date = p_begda end_date = p_begda person_id = p_pernr TABLES pers_avail = lt_persavail EXCEPTIONS no_capacity_available = 1 no_integration_activ = 2 timeinfo_error = 3 OTHERS = 4. IF sy-subrc <> 0. * Implement suitable error handling here ELSE. ENDIF. READ TABLE lt_persavail INTO DATA(ls_persavail) WITH KEY datum = p_begda. IF sy-subrc EQ 0. IF ls_persavail-tprog EQ 'LIBR' OR ls_persavail-tagty EQ '1'. p_libre = abap_true. ENDIF. ENDIF. ENDFORM.
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 VALUE(p0041) TYPE p0041 p_dar TYPE p0041-dar01 CHANGING p_fecha TYPE p0041-dat01. DATA l_dat LIKE p0041-dat01. DATA l_dar LIKE p0041-dar01. CLEAR p_fecha. DO 12 TIMES VARYING l_dat FROM p0041-dat01 NEXT p0041-dat02 VARYING l_dar FROM p0041-dar01 NEXT p0041-dar02. IF l_dar = p_dar. p_fecha = l_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
Ejemplo Lectura IT0008
Ojo que esta BAPI calcula los conceptos indirectos :-)
FORM get_p0008_detail tables gt_bapi_wagetypes structure bapip0008p USING p0008 LIKE p0008. DATA ld_amount_external LIKE bapicurr-bapicurr. DATA lt_return LIKE TABLE OF bapireturn1 WITH HEADER LINE.
CLEAR gt_bapi_wagetypes[].
CALL FUNCTION 'BAPI_BASICPAY_GETDETAIL' EXPORTING employeenumber = p0008-pernr subtype = p0008-subty objectid = p0008-objps lockindicator = p0008-sprps validitybegin = p0008-begda validityend = p0008-endda recordnumber = p0008-seqnr IMPORTING return = lt_return TABLES wagetypes = gt_bapi_wagetypes.
endform.
Ejemplos estructura organizacional
Mostrar todos los empleados hacia abajo de una organización
CALL FUNCTION 'RH_STRUC_GET' EXPORTING act_otype = 'O' act_objid = p_objid act_wegid = 'PERS-O' act_begda = '19000101' act_endda = '99991231' authority_check = ' ' TABLES result_objec = ti_result2 EXCEPTIONS no_plvar_found = 1 no_entry_found = 2 OTHERS = 3.
el reporte RHSTRU00, hace lo mismo, pero usando base de datos.
Organizaciones desde y hacia arriba de una persona
CALL FUNCTION 'RH_STRUC_GET' EXPORTING act_otype = 'P' act_objid = p_pernr act_wegid = 'P-S-O-O' authority_check = ' ' TABLES result_objec = lt_result EXCEPTIONS no_plvar_found = 1 no_entry_found = 2 OTHERS = 3.
Leer Gerencia de empleado(caso particular)
CALL FUNCTION 'RH_STRUC_GET' EXPORTING act_otype = 'P' act_objid = l_pernr act_wegid = 'P-S-O-O' authority_check = ' ' TABLES result_objec = lt_result EXCEPTIONS ##FM_SUBRC_OK no_plvar_found = 1 no_entry_found = 2 OTHERS = 3.
LOOP AT lt_result INTO DATA(ls_result) WHERE otype EQ 'O' AND istat = '1' AND begda <= sy-datum AND endda >= sy-datum AND ( stext CP 'GERENCIA*' ). EXIT. ENDLOOP. IF sy-subrc = 0. l_gerencia = ls_result-stext. ENDIF.
Lectura de Datos Maestros (Grupo Funciones HRWPC_GENERAL_TEXTS)
FORM textdata USING p_bukrs TYPE bukrs p_werks TYPE persa p_kostl TYPE kostl p_kokrs TYPE kokrs p_plans TYPE plans p_infty TYPE infty p_subty TYPE p2001-subty p_estado CHANGING p_butxt TYPE butxt p_werkt TYPE pbtxt p_ktext TYPE ktext p_stext TYPE stext p_stext_subty TYPE stext p_itext TYPE t582s-itext p_stext_estado.
IF p_bukrs IS NOT INITIAL. CALL FUNCTION 'HRWPC_RFC_BUKRS_TEXT_GET' EXPORTING bukrs = p_bukrs IMPORTING bukrs_text = p_butxt. ENDIF.
IF p_werks IS NOT INITIAL. CALL FUNCTION 'HRWPC_RFC_WERKS_TEXT_GET' EXPORTING werks = p_werks IMPORTING werks_text = p_werkt. ENDIF.
IF p_kostl IS NOT INITIAL. CALL FUNCTION 'HRWPC_RFC_KOSTL_TEXT_GET' EXPORTING kokrs = p_kokrs kostl = p_kostl begda = sy-datum endda = sy-datum IMPORTING kostl_text = p_ktext . ENDIF.
IF p_plans IS NOT INITIAL. CALL FUNCTION 'HRWPC_RFC_PLANS_TEXT_GET' EXPORTING plans = p_plans begda = sy-datum endda = sy-datum IMPORTING plans_text2 = p_stext. ENDIF.
IF p_subty IS NOT INITIAL. CALL FUNCTION 'HRXSS_PER_GET_ESS_SUBTYPE_TEXT' EXPORTING infty = p_infty subty = p_subty molga = c_molga IMPORTING stext = p_stext_subty. ENDIF.
ENDFORM. " TEXTDATA
Edad de empleado
FORM calculo_edad USING p_pernr CHANGING p_edad. DATA: lt_p0002 TYPE TABLE OF p0002 WITH HEADER LINE. DATA: l_pernr TYPE p0000-pernr, l_agnos TYPE p, l_meses TYPE p, l_dias TYPE p. MOVE p_pernr TO l_pernr. CLEAR p_edad.
CALL FUNCTION 'HR_READ_INFOTYPE' EXPORTING pernr = l_pernr infty = '0002' begda = sy-datum endda = sy-datum TABLES infty_tab = lt_p0002 EXCEPTIONS infty_not_found = 1 OTHERS = 2. LOOP AT lt_p0002 WHERE begda <= sy-datum AND endda >= sy-datum. ENDLOOP. CHECK sy-subrc = 0. CALL FUNCTION 'HRVE_GET_TIME_BETWEEN_DATES' EXPORTING beg_date = lt_p0002-gbdat end_date = sy-datum IMPORTING days = l_dias months = l_meses years = l_agnos EXCEPTIONS invalid_period = 1 OTHERS = 2. p_edad = l_agnos. ENDFORM. " CALCULO_EDAD
Crear Absentismo
FORM crear_abs USING p_pernr p_subty p_begda p_endda p_beguz p_enduz p_simulate CHANGING p_retorno TYPE bapiret2_tab p_hrabsatt_out TYPE bapihrabsatt_out p_text. DATA: lt_retorno LIKE bapiret2 OCCURS 0 WITH HEADER LINE, ls_key TYPE bapihrtimeskey, " Campos clave BAPI p.entradas tiempos personal (HR) ls_abs TYPE bapihrabsatt_in. " Campos presencia/absentismo, entrada sin datos adicionale. CLEAR: ls_abs. ls_abs-from_date = p_begda. " Inicio de la validez ls_abs-to_date = p_endda. " Fin de la validez ls_abs-start_time = p_beguz. " Hora de inicio ls_abs-end_time = p_enduz. " Hora final ls_abs-abs_att_hours = ''. " Horas de presencia/absentismo ls_abs-previous_day = ''. " Indicador de día anterior IF p_beguz IS NOT INITIAL AND p_enduz IS NOT INITIAL. * ----> Logica de Horas para el dia ls_abs-all_day_flag = space. ELSE. * ----> Logica Considera ls_abs-all_day_flag = 'X'. ENDIF. CALL FUNCTION 'BAPI_PTMGRATTABS_MNGCREATION' EXPORTING employeenumber = p_pernr " Nro. Personal abs_att_type = p_subty " Clase de Absentismos hrabsatt_in = ls_abs " Campos presencia/absentismo, entrada sin datos adicionales simulate = p_simulate IMPORTING hrabsatt_out = p_hrabsatt_out hrabsattext = p_text TABLES return = p_retorno. " Retorno ENDFORM.
Rutinas para leer contingente
method GET_SALDO_DIAS. *--------------------------------------------------------------------* * Calculo de saldo días *--------------------------------------------------------------------* DATA: lt_abs_quota TYPE TABLE OF bapihrquota, lt_ktart TYPE tim_quota_type_tab, ra_ktart TYPE RANGE OF p2006-ktart, wa_ktart LIKE LINE OF ra_ktart. DATA lv_saldodias TYPE anzhl. *--------------------------------------------------------------------* * Calculo de saldo días *--------------------------------------------------------------------* CALL FUNCTION 'BAPI_TIMEQUOTA_GETDETAILEDLIST' EXPORTING employeenumber = i_solicitud-pernr * QUOTASELECTIONMOD = '1' "absentismos TABLES absencequotareturntable = lt_abs_quota. CALL FUNCTION 'Z_HCM_CONTINGENTE_FROM_ABS' EXPORTING i_pernr = i_solicitud-pernr i_begda = i_solicitud-begda i_endda = i_solicitud-endda i_subty = i_solicitud-subty IMPORTING e_ktart = lt_ktart. LOOP AT lt_ktart INTO DATA(ls_ktart). wa_ktart-low = ls_ktart. wa_ktart-sign = 'I'. wa_ktart-option = 'EQ'. APPEND wa_ktart TO ra_ktart. CLEAR wa_ktart. ENDLOOP. lv_saldodias = 0. IF ra_ktart[] IS NOT INITIAL. LOOP AT lt_abs_quota INTO DATA(ls_abs_quota) WHERE quotatype IN ra_ktart. lv_saldodias = lv_saldodias + ls_abs_quota-rest_free. ENDLOOP. ENDIF. lv_saldodias = lv_saldodias - i_solicitud-quota_deduction. IF lv_saldodias < 0. lv_saldodias = 0. ENDIF. r_saldo = lv_saldodias. "type anzhl endmethod. FUNCTION z_hcm_contingente_from_abs. *"---------------------------------------------------------------------- *"*"Interfase local *" IMPORTING *" REFERENCE(I_PERNR) TYPE PERNR_D *" REFERENCE(I_BEGDA) TYPE BEGDA DEFAULT SY-DATUM *" REFERENCE(I_ENDDA) TYPE ENDDA DEFAULT SY-DATUM *" REFERENCE(I_SUBTY) TYPE T554S-SUBTY *" EXPORTING *" REFERENCE(E_KTART) TYPE TIM_QUOTA_TYPE_TAB *"---------------------------------------------------------------------- DATA lt_p0001 TYPE TABLE OF p0001. DATA ls_t503 TYPE t503. DATA ls_t001p TYPE t001p. DATA ls_t554s TYPE t554s. DATA ls_t556c TYPE t556c. DATA ls_t556r TYPE t556r. CALL FUNCTION 'HR_READ_INFOTYPE' EXPORTING pernr = i_pernr infty = '0001' TABLES infty_tab = lt_p0001 EXCEPTIONS infty_not_found = 1 OTHERS = 2. IF sy-subrc <> 0. * Implement suitable error handling here ENDIF. LOOP AT lt_p0001 INTO DATA(ls_p0001) WHERE begda <= i_endda AND endda >= i_begda. ENDLOOP. IF sy-subrc <> 0. RETURN. ENDIF. 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. SELECT SINGLE * INTO ls_t554s FROM t554s WHERE moabw = ls_t001p-moabw AND subty = i_subty AND endda >= i_begda AND begda <= i_endda. SELECT SINGLE * INTO ls_t556c FROM t556c WHERE mopgk = ls_t503-konty AND mozko = ls_t001p-mozko AND crule = ls_t554s-crule AND ctype = 'Q'. SELECT SINGLE * INTO ls_t556r FROM t556r WHERE " mopgk = ls_t503-konty AND mozko = ls_t001p-mozko AND qtype = 'A' AND dedrg = ls_t556c-deabp AND endda >= i_begda AND begda <= i_endda. * copiado de LHRTIM00QUOTADEDUCTIONF01 #986 CONSTANTS: QSTEP TYPE I VALUE 2. DATA: BEGIN OF selqtypes OCCURS 0, cktart(2) TYPE c, END OF selqtypes. DATA:qttps TYPE qttps. qttps = ls_t556r-qttps. DO 100 TIMES. selqtypes-cktart = qttps. IF selqtypes-cktart IS INITIAL. "' '" EXIT. "end-of-sequence was found ENDIF. APPEND selqtypes. SHIFT qttps BY qstep PLACES LEFT. ENDDO. loop at selqtypes. APPEND selqtypes-cktart to E_KTART. endloop. ENDFUNCTION.
Ejemplo de HR_INFOTYPE_OPERATION
PERFORM infotype_operation USING c_create p0014 p_test CHANGING l_subrc. FORM infotype_operation USING p_actio TYPE pspar-actio p_infty TYPE any p_test TYPE xfeld CHANGING p_subrc. DATA: ls_bapireturn TYPE bapiret1, ls_key TYPE bapipakey, wa TYPE p0002, l_dialog_mode(1). MOVE-CORRESPONDING p_infty TO wa. * enqueue the employye CALL FUNCTION 'BAPI_EMPLOYEE_ENQUEUE' EXPORTING number = wa-pernr IMPORTING return = ls_bapireturn. IF ls_bapireturn IS NOT INITIAL. p_subrc = 2. RETURN. ENDIF. l_dialog_mode = '0'. CALL FUNCTION 'HR_INFOTYPE_OPERATION' EXPORTING infty = wa-infty number = wa-pernr subtype = wa-subty validityend = wa-endda validitybegin = wa-begda record = p_infty "p9032 operation = p_actio nocommit = 'X' dialog_mode = l_dialog_mode IMPORTING return = ls_bapireturn key = ls_key EXCEPTIONS OTHERS = 0. IF NOT ls_bapireturn IS INITIAL. * error p_subrc = 1. ELSE. p_subrc = 0. IF p_test <> abap_true. COMMIT WORK AND WAIT. ENDIF. ENDIF. CALL FUNCTION 'BAPI_EMPLOYEE_DEQUEUE' EXPORTING number = wa-pernr IMPORTING return = ls_bapireturn. ENDFORM.