Está en la página 1de 7

* ABAP HR: Plantilla Reporte PNP con LVC

*Reporte estndar HR con B.DD. PNP y salida en LVC

*&---------------------------------------------------------------------*
*& Report ZEHS_FIN_LICENCIAS
*&
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Report ZEHS_FIN_LICENCIAS
*&---------------------------------------------------------------------*
* LOG DE MODIFICACION:
*
* FECHA PROGRAMADOR CORRECCION DESCRIPCION
*-----------------------------------------------------------------------
* ddmmaaaa xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx
*-----------------------------------------------------------------------
REPORT zehs_fin_licencias
NO STANDARD PAGE HEADING
LINE-SIZE 255.

*-----------------------------------------------------------------------
* DECLARACIONES
*-----------------------------------------------------------------------

*-----------------------------------------------------------------------
* Declaracin de Tablas
*-----------------------------------------------------------------------
TABLES: pernr.

*-----------------------------------------------------------------------
* Declaracin de Infotipos
*-----------------------------------------------------------------------
INFOTYPES: 0001, 0002.

*----------------------------------------------------------------------*
* Declaracin de Constantes *
*----------------------------------------------------------------------*
CONSTANTS:
c_false TYPE char1 VALUE cl_pt_req_const=>c_false,
c_true TYPE char1 VALUE cl_pt_req_const=>c_true.

*-----------------------------------------------------------------------
* INCLUDES Y TYPE-POOLS
*-----------------------------------------------------------------------
TYPE-POOLS: slis, truxs.
INCLUDE <icon>.

*----------------------------------------------------------------------*
* TYPES - Declaracion de estructuras de tablas internas *
*----------------------------------------------------------------------*
TYPES: BEGIN OF zst_alv,
campo,
campo2,
END OF zst_alv.
*-----------------------------------------------------------------------
* Declaracin de Tablas Internas
*-----------------------------------------------------------------------
*Reporte
DATA: st_alv TYPE zst_alv,
tt_alv TYPE TABLE OF zst_alv WITH HEADER LINE.

*----------------------------------------------------------------------*
* Declaracin de Variables *
*----------------------------------------------------------------------*
*Variables para la lectura de cluster
DATA: subrc LIKE sy-subrc, "indicador de acierto
begda LIKE t549q-begda, "inicio de periodo
endda LIKE t549q-endda, "fin de periodo
pabrj LIKE t549q-pabrj, "ao de ejecucion
pabrp LIKE t549q-pabrp. "mes de ejecucion

*----------------------------------------------------------------------*
* DATOS PARA MANEJO ALV *
*----------------------------------------------------------------------*
DATA: gs_layout TYPE lvc_s_layo,
gs_fieldcat TYPE lvc_t_fcat,
g_exit_caused_by_caller,
gs_exit_caused_by_user TYPE slis_exit_by_user,
g_repid LIKE sy-repid.
*Variants
DATA: gs_variant LIKE disvariant,
g_save.

*"Callback
DATA: gt_events TYPE slis_t_event,
gt_list_top_of_page TYPE slis_t_listheader.

*-----------------------------------------------------------------------
* PANTALLAS DE SELECCION Y EVENTOS DE PANTALLA
*-----------------------------------------------------------------------

*-----------------------------------------------------------------------
* MACROS
*-----------------------------------------------------------------------
*----------------------------------------------------------------------*
* ZAP : Refresca tablas *
*----------------------------------------------------------------------*
DEFINE: cls.
refresh &1. clear &1.
END-OF-DEFINITION.

*----------------------------------------------------------------------*
* Pantalla de Seleccin *
*----------------------------------------------------------------------*

*----------------------------------------------------------------------*
* Eventos de Pantalla *
*----------------------------------------------------------------------*

*-----------------------------------------------------------------------
* RUTINA PRINCIPAL
*-----------------------------------------------------------------------

*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
rp-sel-ein-aus-init. "status ocupacion <> 0
rp-init-with-sydatum.

*----------------------------------------------------------------------*
* START-OF-SELECTION *
*----------------------------------------------------------------------*
START-OF-SELECTION.
PERFORM initialize_period USING pnpxabkr pnpbegda pnpendda
pn-begda pn-endda pnpdisbd
pnpdised pnpdispp pnpdispj
pnppabrp pnppabrj
CHANGING pabrj pabrp begda endda.
* tablas internas
PERFORM inicializa_tablas.

* estructura alv
PERFORM inicializa_alv.

*----------------------------------------------------------------------*
* GET PERNR - Obtiene datos de Base de Datos Logica PNP estruc.: PERNR *
*----------------------------------------------------------------------*
GET pernr.

*----------------------------------------------------------------------*
* END-OF-SELECTION *
*----------------------------------------------------------------------*
END-OF-SELECTION.
IF NOT tt_alv[] IS INITIAL.
PERFORM muestra_alv TABLES tt_alv.
ELSE.
MESSAGE 'No se encontraron datos' TYPE 'E'.
ENDIF.

*-----------------------------------------------------------------------
* RUTINAS
*-----------------------------------------------------------------------

*&---------------------------------------------------------------------*
*& Form inicializa_tablas
*&---------------------------------------------------------------------*
FORM inicializa_tablas.
ENDFORM. " inicializa_tablas

*&---------------------------------------------------------------------*
*& Form inicializa_alv
*&---------------------------------------------------------------------*
FORM inicializa_alv.
g_repid = sy-repid.
PERFORM layout_init USING gs_layout.
* TODO: inicializar fieldcat
PERFORM fieldcat_init.
PERFORM eventtab_build USING gt_events[].
gs_variant-report = g_repid.
g_save = 'X'.

ENDFORM. "inicializa_alv

*&---------------------------------------------------------------------*
*& Form layout_init
*&---------------------------------------------------------------------*
FORM layout_init USING rs_layout TYPE lvc_s_layo.
rs_layout-zebra = 'X'.
rs_layout-edit = ' '.
ENDFORM. "layout_init

*&---------------------------------------------------------------------*
*& Form fieldcat_init
*&---------------------------------------------------------------------*
FORM fieldcat_init.

DATA: ls_fieldcat TYPE lvc_s_fcat.

CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'CAMPO1'.
ls_fieldcat-scrtext_l = text-c01.
ls_fieldcat-scrtext_m = text-c01.
ls_fieldcat-scrtext_s = text-c01.
APPEND ls_fieldcat TO gs_fieldcat.

CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'CAMPO1'.
ls_fieldcat-scrtext_l = text-c02.
ls_fieldcat-scrtext_m = text-c02.
ls_fieldcat-scrtext_s = text-c02.
APPEND ls_fieldcat TO gs_fieldcat.

ENDFORM. "fieldcat_init

*&---------------------------------------------------------------------*
*& Form eventtab_build
*&---------------------------------------------------------------------*
FORM eventtab_build USING rt_events TYPE slis_t_event.
DATA: g_status_set TYPE slis_formname VALUE 'PF_STATUS_SET',
g_user_command TYPE slis_formname VALUE 'USER_COMMAND',
g_top_of_page TYPE slis_formname VALUE 'TOP_OF_PAGE',
g_top_of_list TYPE slis_formname VALUE 'TOP_OF_LIST',
g_data_changed TYPE slis_formname VALUE 'DATA_CHANGED',
g_end_of_list TYPE slis_formname VALUE 'END_OF_LIST'.

DATA: ls_event TYPE slis_alv_event.


*
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
i_list_type = 0
IMPORTING
et_events = rt_events.

* top of page
READ TABLE rt_events WITH KEY name = slis_ev_top_of_page
INTO ls_event.
IF sy-subrc = 0.
MOVE g_top_of_page TO ls_event-form.
APPEND ls_event TO rt_events.
ENDIF.

* data changed: procesar cambios en datos especificos de alv modificable


ls_event-name = slis_ev_data_changed.
ls_event-form = g_data_changed.
APPEND ls_event TO rt_events.

ENDFORM. "eventtab_build

*&---------------------------------------------------------------------*
*& Form muestra_alv
*&---------------------------------------------------------------------*
FORM muestra_alv TABLES gt_outtab.
DATA e VALUE 'E'.

CHECK gs_fieldcat[] IS NOT INITIAL.

* TODO: inicializar cabecera


PERFORM comment_build USING gt_list_top_of_page[].

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY_LVC'


EXPORTING
i_buffer_active = 'X'
i_callback_program = g_repid
* i_callback_pf_status_set = 'ALV_STATUS' "insertar PF-STATUS propio
* i_callback_user_command = 'USER_COMMAND' "controlar acciones sobre
registros
* i_structure_name = ''
it_fieldcat_lvc = gs_fieldcat[]
is_layout_lvc = gs_layout
i_default = 'A'
i_save = g_save
is_variant = gs_variant
it_events = gt_events[]

IMPORTING
e_exit_caused_by_caller = g_exit_caused_by_caller
es_exit_caused_by_user = gs_exit_caused_by_user
TABLES
t_outtab = gt_outtab
EXCEPTIONS
program_error = 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.

ENDFORM. "muestra_alv

*&---------------------------------------------------------------------*
*& Form comment_build
*&---------------------------------------------------------------------*
FORM comment_build USING lt_top_of_page TYPE slis_t_listheader.
DATA: ls_line TYPE slis_listheader.
data: begtxt(10),
endtxt(10).
DATA: texto TYPE string.

write begda to begtxt dd/mm/yyyy.


write endda to endtxt dd/mm/yyyy.

* LIST HEADING LINE: TYPE H


CLEAR ls_line.
ls_line-typ = 'H'.
* LS_LINE-KEY: NOT USED FOR THIS TYPE
ls_line-info = sy-title.
APPEND ls_line TO lt_top_of_page.

CLEAR ls_line.
ls_line-typ = 'S'.
ls_line-key = 'Periodo'.
CONCATENATE begtxt 'al' endtxt INTO texto SEPARATED BY space.
ls_line-info = texto.
APPEND ls_line TO lt_top_of_page.
ENDFORM. "comment_build

*&---------------------------------------------------------------------*
*& Form top_of_page
*&---------------------------------------------------------------------*
FORM top_of_page.
CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'
EXPORTING
i_logo = '' "<-- inserte logo empresa
it_list_commentary = gt_list_top_of_page.
ENDFORM. "top_of_page

*&---------------------------------------------------------------------*
*& Form INITIALIZE_PERIOD
*&---------------------------------------------------------------------*
FORM initialize_period USING pnpxabkr pnpbegda pnpendda
pnpbegps pnpendps
pnpdisbd pnpdised
pnpdispp pnpdispj
pnppabrp pnppabrj
CHANGING pabrj pabrp begda endda.

IF pnpbegps IS INITIAL.
pnpbegps = sy-datum.
ENDIF.

IF pnpendps IS INITIAL.
pnpendps = sy-datum.
ENDIF.

* Verificar rea de nmina para determinacin perodo


IF pnpxabkr IS INITIAL.
* Verificar Fecha inicio perodo seleccin de datos
IF pnpbegda IS INITIAL.
* Asignar Fecha de inicio perodo seleccin de personal
begda = pnpbegps.
endda = pnpendps.
ELSE.
* Asignar Fecha inicio perodo seleccin de datos
begda = pnpbegda.
endda = pnpendda.
ENDIF.
* Verificar Fecha final perodo
IF endda IS INITIAL.
endda = begda.
ENDIF.
* Asignar Ao y Periodo
pabrj = begda+0(4).
pabrp = begda+4(2).
ELSE.
pabrp = pnpdispp.
IF NOT ( pnpdispp IS INITIAL ).
pabrj = pnpdispj.
ELSE.
pabrp = pnppabrp.
pabrj = pnppabrj.
ENDIF.
begda = pnpdisbd.
endda = pnpdised.
ENDIF.

ENDFORM. "INITIALIZE_PERIOD

*-----------------------------------------------------------------------
* MODULE POOL
*-----------------------------------------------------------------------