FunciĂłn para obtener mĂșltiples HRFORM de un empleado (o de mĂșltiples si se desea) y que permite imprimir en pantalla y exportar el binario para Web Dynpro. Puede ser mejorado sin duda.
FUNCTION zhr_sgu_liquidaciones.
*"----------------------------------------------------------------------
*"*"Interfase local
*" IMPORTING
*" VALUE(I_PERNR) TYPE PERSNO
*" VALUE(I_MES_INI) TYPE PABRP OPTIONAL
*" VALUE(I_ANO_INI) TYPE PABRJ OPTIONAL
*" VALUE(I_MES_FIN) TYPE PABRP OPTIONAL
*" VALUE(I_ANO_FIN) TYPE PABRJ OPTIONAL
*" EXPORTING
*" VALUE(E_RETURN) TYPE BAPIRET2
*" VALUE(E_BIN_FILE) TYPE XSTRING
*"----------------------------------------------------------------------
DEFINE bapiret.
e_return-type = &1.
e_return-message = &2.
exit.
END-OF-DEFINITION.
DATA: BEGIN OF t_periodos OCCURS 0,
begda TYPE begda,
endda TYPE endda,
END OF t_periodos.
DATA: lv_ano_ini TYPE pabrj,
lv_mes_ini TYPE pabrp.
DATA hrpy_tt_rgdir TYPE hrpy_tt_rgdir.
DATA lt_rgdir TYPE hrpy_tt_rgdir.
DATA hrpy_st_rgdir LIKE pc261.
DATA form_object TYPE REF TO object.
DATA form_object_list TYPE pay_pm_object_tab.
* obtener perĂodos begda / endda
**********************************************************************
FREE t_periodos.
lv_mes_ini = i_mes_ini.
lv_ano_ini = i_ano_ini.
DO.
CONCATENATE lv_ano_ini lv_mes_ini '01' INTO t_periodos-begda.
CALL FUNCTION 'HR_HCP_GET_LAST_DAY_OF_MONTH'
EXPORTING
im_date = t_periodos-begda
IMPORTING
ex_last_day_of_month = t_periodos-endda.
APPEND t_periodos.
ADD 1 TO lv_mes_ini.
IF lv_mes_ini > 12.
lv_mes_ini = '01'.
ADD 1 TO lv_ano_ini.
ENDIF.
IF ( lv_ano_ini > i_ano_fin ) OR ( lv_ano_ini = i_ano_fin AND lv_mes_ini > i_mes_fin ).
EXIT.
ENDIF.
ENDDO.
IF t_periodos[] IS INITIAL.
bapiret 'E' 'No existen perĂodos para consultar'.
ENDIF.
* obtener rgdirs
**********************************************************************
CALL FUNCTION 'CU_READ_RGDIR'
EXPORTING
persnr = i_pernr
TABLES
in_rgdir = lt_rgdir
EXCEPTIONS
no_record_found = 1
OTHERS = 2.
FREE hrpy_tt_rgdir.
DELETE lt_rgdir WHERE srtza NE 'A'.
LOOP AT t_periodos.
LOOP AT lt_rgdir INTO hrpy_st_rgdir
WHERE fpbeg <= t_periodos-endda
AND fpend >= t_periodos-begda
AND ocrsn IS INITIAL.
APPEND hrpy_st_rgdir TO hrpy_tt_rgdir.
ENDLOOP.
ENDLOOP.
IF hrpy_tt_rgdir[] IS INITIAL.
bapiret 'E' 'No existen nominas para la fecha consultada'.
ENDIF.
* preparar HRFORMS
**********************************************************************
LOOP AT hrpy_tt_rgdir INTO hrpy_st_rgdir.
FREE form_object.
FREE lt_rgdir.
APPEND hrpy_st_rgdir TO lt_rgdir.
CALL FUNCTION 'HRFORMS_CALL_INIT'
EXPORTING
hrform_name = 'ZHR_LIQSUELDO'
begin_date = sy-datum
end_date = sy-datum
IMPORTING
form_object = form_object
EXCEPTIONS
form_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
bapiret 'E' 'HRFORMS_CALL_INIT'.
ENDIF.
CALL FUNCTION 'HRFORMS_CALL_PERNR'
EXPORTING
form_object = form_object
pernr = i_pernr
result_list = lt_rgdir
call_evp = ''
molga = '39'
rgdir = lt_rgdir
EXCEPTIONS
form_error = 1
payroll_read_error = 2
reject = 3
no_form = 4
OTHERS = 5.
IF sy-subrc <> 0.
bapiret 'E' 'HRFORMS_CALL_PERNR'.
ENDIF.
APPEND form_object TO form_object_list.
ENDLOOP.
DATA pdf_size TYPE i.
DATA pdf_xstring TYPE xstring.
CALL FUNCTION 'HRFORMS_CALL_PDF'
EXPORTING
form_object_list = form_object_list
IMPORTING
pdf_size = pdf_size
pdf_xstring = pdf_xstring
EXCEPTIONS
form_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
bapiret 'E' 'HRFORMS_CALL_PDF'.
ELSE.
e_bin_file = pdf_xstring.
ENDIF.
IF sy-batch IS INITIAL.
CALL FUNCTION 'HRFORMS_CALL_DISPLAY'
EXPORTING
form_object_list = form_object_list
EXCEPTIONS
form_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
bapiret 'E' 'HRFORMS_CALL_DISPLAY'.
ENDIF.
ENDIF.
bapiret 'S' 'PDF generado exitosamente'.
ENDFUNCTION.
ACTUALIZACION:
Si al imprimir masivo da error de tipo FORM_ERROR, es un error en el mandante que no puede generar el job de spool necesario, se puede bypasear con el siguiente cĂłdigo
No hay comentarios:
Publicar un comentario