Un buen ejemplo de uso de las macros para leer el cluster de Chile (CL), mezclado con la base de datos PNPCE usado de manera correcta. Llegar y usar.
También permite encontrar todos los usuarios que tienen cluster en algún período.
*&---------------------------------------------------------------------*
*& Report CLUSTER_PNPCE
*&---------------------------------------------------------------------*
* LOG DE MODIFICACION:
*
* FECHA PROGRAMADOR CORRECCION DESCRIPCION
*-----------------------------------------------------------------------
* ddmmaaaa xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx
*-----------------------------------------------------------------------
REPORT cluster_pnpce
NO STANDARD PAGE HEADING
LINE-SIZE 255.
*-----------------------------------------------------------------------
* DECLARACIONES
*-----------------------------------------------------------------------
*-----------------------------------------------------------------------
* Declaración de Tablas
*-----------------------------------------------------------------------
TABLES: pernr.
NODES: peras.
TABLES: t554s, pcl1, pcl2, pc261. "Lectura de cluster HR
*-----------------------------------------------------------------------
* Declaración de Infotipos
*-----------------------------------------------------------------------
INFOTYPES: 0001 AS PERSON TABLE NAME p0001,
0002 AS PERSON TABLE NAME p0002,
2001 AS PERSON TABLE NAME p2001.
*----------------------------------------------------------------------*
* Declaración 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.
*----------------------------------------------------------------------*
* TYPES - Declaracion de estructuras de tablas internas *
*----------------------------------------------------------------------*
TYPES: BEGIN OF zst_alv,
pernr TYPE pernr-pernr,
seqnr TYPE pc261-seqnr,
begda TYPE p2001-begda,
endda TYPE p2001-endda,
split(2) TYPE c,
val TYPE p DECIMALS 2,
END OF zst_alv.
*-----------------------------------------------------------------------
* Declaración de Tablas Internas
*-----------------------------------------------------------------------
*Reporte
DATA: st_alv TYPE zst_alv,
tt_alv TYPE TABLE OF zst_alv.
*----------------------------------------------------------------------*
* Declaración 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, "año 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
*-----------------------------------------------------------------------
*----------------------------------------------------------------------*
* CLS : Refresca tablas *
*----------------------------------------------------------------------*
DEFINE: cls.
refresh &1. clear &1.
END-OF-DEFINITION.
*----------------------------------------------------------------------*
* Pantalla de Selección *
*----------------------------------------------------------------------*
SELECT-OPTIONS: p_ocrsn FOR pc261-ocrsn NO INTERVALS NO-EXTENSION.
*----------------------------------------------------------------------*
* Eventos de Pantalla *
*----------------------------------------------------------------------*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ocrsn-low.
* PERFORM request_ocrsn USING '99' CHANGING p_ocrsn-low.
*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ocrsn-high.
* PERFORM request_ocrsn USING '99' CHANGING p_ocrsn-high.
*-----------------------------------------------------------------------
* RUTINA PRINCIPAL
*-----------------------------------------------------------------------
*Lectura de cluster HR
INCLUDE rpc2cd09. "Cluster CD data definition
INCLUDE rpc2ca00. "Cluster CA Data-Definition
INCLUDE rpppxd00. "Data Definition buffer PCL1/PCL2 Buffer
INCLUDE rpppxd10. "Common part buffer PCL1/PCL2
INCLUDE rpppxm00. "Buffer handling routine
INCLUDE rpc2rx09. "Cluster IN data definition
*Especificos del pais/cluster
* INCLUDE RPC2RXX0. "internacional
INCLUDE pc2rxcl0. "chile
*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
rp-sel-ein-aus-init. "status ocupacion <> 0
pnptimed = 'A'.
* 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 peras.
rp-init-buffer.
cls: rgdir, rt.
PERFORM lee_cluster USING pernr-pernr CHANGING subrc.
CHECK subrc IS INITIAL.
rp_provide_from_last: p0001 space begda endda,
p0002 space begda endda.
* Loop at wpbp data for specific payroll results period
LOOP AT wpbp.
st_alv-pernr = pernr-pernr.
st_alv-seqnr = rgdir-seqnr.
st_alv-begda = wpbp-begda.
st_alv-endda = wpbp-endda.
st_alv-split = wpbp-apznr.
* loop at rt data for specific payroll results period
LOOP AT rt WHERE lgart EQ '/560'.
st_alv-val = rt-betrg.
APPEND st_alv TO tt_alv.
ENDLOOP.
ENDLOOP.
* Process BT table
LOOP AT bt.
ENDLOOP.
* etc................
*---------------------------------------------------------------------------*
* 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.
cls: tt_alv.
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 = 'PERNR'.
ls_fieldcat-ref_table = 'PA0001'.
APPEND ls_fieldcat TO gs_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SEQNR'.
ls_fieldcat-ref_table = 'PA0001'.
APPEND ls_fieldcat TO gs_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BEGDA'.
ls_fieldcat-ref_table = 'PA0001'.
APPEND ls_fieldcat TO gs_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ENDDA'.
ls_fieldcat-ref_table = 'PA0001'.
APPEND ls_fieldcat TO gs_fieldcat.
* Asignación PC205
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SPLIT'.
ls_fieldcat-scrtext_l = 'Asignación PC205'.
ls_fieldcat-scrtext_m = 'Asignación PC205'.
ls_fieldcat-scrtext_s = 'Asignación PC205'.
APPEND ls_fieldcat TO gs_fieldcat.
* Nómina de personal: Importe por unidad
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'VAL'.
ls_fieldcat-scrtext_l = 'Importe por unidad'.
ls_fieldcat-scrtext_m = 'Importe por unidad'.
ls_fieldcat-scrtext_s = 'Importe por unidad'.
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
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 Selección de Datos'.
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 = ''
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 nómina para determinación período
IF pnpxabkr IS INITIAL.
* Verificar Fecha inicio período selección de datos
IF pnpbegda IS INITIAL.
* Asignar Fecha de inicio período selección de personal
begda = pnpbegps.
endda = pnpendps.
ELSE.
* Asignar Fecha inicio período selección de datos
begda = pnpbegda.
endda = pnpendda.
ENDIF.
* Verificar Fecha final período
IF endda IS INITIAL.
endda = begda.
ENDIF.
* Asignar Año 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 = pnpbegps.
endda = pnpendps.
ENDIF.
ENDFORM. "INITIALIZE_PERIOD
*&---------------------------------------------------------------------*
*& Form LEE_CLUSTER
*&---------------------------------------------------------------------*
FORM lee_cluster USING pernr TYPE persno
CHANGING subrc.
CLEAR: cd-key, subrc.
cd-key-pernr = pernr.
rp-imp-c2-cu.
IF rgdir[] IS INITIAL.
subrc = 4.
EXIT.
ENDIF.
* Eliminar motivo de nómina (dependiendo de parámetro)
IF p_ocrsn IS INITIAL.
DELETE rgdir WHERE ocrsn NE p_ocrsn.
ENDIF.
IF NOT p_ocrsn IS INITIAL.
IF p_ocrsn NE '*ALL'.
DELETE rgdir WHERE ocrsn NE p_ocrsn.
ENDIF.
ENDIF.
* rgdir the table where all payroll results periods are stored
LOOP AT rgdir WHERE abkrs IN pnpabkrs
AND fpbeg GE pn-begda
AND fpend LE pn-endda
AND srtza EQ 'A'
AND void NE 'V'.
CLEAR st_alv.
* set key to specific payroll results period(current rgdir loop pass)
UNPACK rgdir-seqnr TO rx-key-seqno.
MOVE pernr TO rx-key-pernr.
* Retrieves data for specific payroll results period
rp-imp-c2-cl. "chile
* rp-imp-c2-rx. "internacional
IF rt[] IS INITIAL.
subrc = 4.
ENDIF.
ENDLOOP.
ENDFORM. " LEE_CLUSTER
*&---------------------------------------------------------------------*
*& Form REQUEST_OCRSN
*&---------------------------------------------------------------------*
FORM request_ocrsn USING p_molga
CHANGING p_ocrsn.
CALL FUNCTION 'HR_OC_F4_POPUP_OCRSN'
EXPORTING
molga = p_molga
IMPORTING
ocrsn = p_ocrsn.
ENDFORM. " REQUEST_OCRSN
*& Report CLUSTER_PNPCE
*&---------------------------------------------------------------------*
* LOG DE MODIFICACION:
*
* FECHA PROGRAMADOR CORRECCION DESCRIPCION
*-----------------------------------------------------------------------
* ddmmaaaa xxxxxxxxxxxxx xxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxx
*-----------------------------------------------------------------------
REPORT cluster_pnpce
NO STANDARD PAGE HEADING
LINE-SIZE 255.
*-----------------------------------------------------------------------
* DECLARACIONES
*-----------------------------------------------------------------------
*-----------------------------------------------------------------------
* Declaración de Tablas
*-----------------------------------------------------------------------
TABLES: pernr.
NODES: peras.
TABLES: t554s, pcl1, pcl2, pc261. "Lectura de cluster HR
*-----------------------------------------------------------------------
* Declaración de Infotipos
*-----------------------------------------------------------------------
INFOTYPES: 0001 AS PERSON TABLE NAME p0001,
0002 AS PERSON TABLE NAME p0002,
2001 AS PERSON TABLE NAME p2001.
*----------------------------------------------------------------------*
* Declaración 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.
*----------------------------------------------------------------------*
* TYPES - Declaracion de estructuras de tablas internas *
*----------------------------------------------------------------------*
TYPES: BEGIN OF zst_alv,
pernr TYPE pernr-pernr,
seqnr TYPE pc261-seqnr,
begda TYPE p2001-begda,
endda TYPE p2001-endda,
split(2) TYPE c,
val TYPE p DECIMALS 2,
END OF zst_alv.
*-----------------------------------------------------------------------
* Declaración de Tablas Internas
*-----------------------------------------------------------------------
*Reporte
DATA: st_alv TYPE zst_alv,
tt_alv TYPE TABLE OF zst_alv.
*----------------------------------------------------------------------*
* Declaración 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, "año 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
*-----------------------------------------------------------------------
*----------------------------------------------------------------------*
* CLS : Refresca tablas *
*----------------------------------------------------------------------*
DEFINE: cls.
refresh &1. clear &1.
END-OF-DEFINITION.
*----------------------------------------------------------------------*
* Pantalla de Selección *
*----------------------------------------------------------------------*
SELECT-OPTIONS: p_ocrsn FOR pc261-ocrsn NO INTERVALS NO-EXTENSION.
*----------------------------------------------------------------------*
* Eventos de Pantalla *
*----------------------------------------------------------------------*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ocrsn-low.
* PERFORM request_ocrsn USING '99' CHANGING p_ocrsn-low.
*
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_ocrsn-high.
* PERFORM request_ocrsn USING '99' CHANGING p_ocrsn-high.
*-----------------------------------------------------------------------
* RUTINA PRINCIPAL
*-----------------------------------------------------------------------
*Lectura de cluster HR
INCLUDE rpc2cd09. "Cluster CD data definition
INCLUDE rpc2ca00. "Cluster CA Data-Definition
INCLUDE rpppxd00. "Data Definition buffer PCL1/PCL2 Buffer
INCLUDE rpppxd10. "Common part buffer PCL1/PCL2
INCLUDE rpppxm00. "Buffer handling routine
INCLUDE rpc2rx09. "Cluster IN data definition
*Especificos del pais/cluster
* INCLUDE RPC2RXX0. "internacional
INCLUDE pc2rxcl0. "chile
*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
rp-sel-ein-aus-init. "status ocupacion <> 0
pnptimed = 'A'.
* 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 peras.
rp-init-buffer.
cls: rgdir, rt.
PERFORM lee_cluster USING pernr-pernr CHANGING subrc.
CHECK subrc IS INITIAL.
rp_provide_from_last: p0001 space begda endda,
p0002 space begda endda.
* Loop at wpbp data for specific payroll results period
LOOP AT wpbp.
st_alv-pernr = pernr-pernr.
st_alv-seqnr = rgdir-seqnr.
st_alv-begda = wpbp-begda.
st_alv-endda = wpbp-endda.
st_alv-split = wpbp-apznr.
* loop at rt data for specific payroll results period
LOOP AT rt WHERE lgart EQ '/560'.
st_alv-val = rt-betrg.
APPEND st_alv TO tt_alv.
ENDLOOP.
ENDLOOP.
* Process BT table
LOOP AT bt.
ENDLOOP.
* etc................
*---------------------------------------------------------------------------*
* 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.
cls: tt_alv.
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 = 'PERNR'.
ls_fieldcat-ref_table = 'PA0001'.
APPEND ls_fieldcat TO gs_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SEQNR'.
ls_fieldcat-ref_table = 'PA0001'.
APPEND ls_fieldcat TO gs_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'BEGDA'.
ls_fieldcat-ref_table = 'PA0001'.
APPEND ls_fieldcat TO gs_fieldcat.
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'ENDDA'.
ls_fieldcat-ref_table = 'PA0001'.
APPEND ls_fieldcat TO gs_fieldcat.
* Asignación PC205
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'SPLIT'.
ls_fieldcat-scrtext_l = 'Asignación PC205'.
ls_fieldcat-scrtext_m = 'Asignación PC205'.
ls_fieldcat-scrtext_s = 'Asignación PC205'.
APPEND ls_fieldcat TO gs_fieldcat.
* Nómina de personal: Importe por unidad
CLEAR ls_fieldcat.
ls_fieldcat-fieldname = 'VAL'.
ls_fieldcat-scrtext_l = 'Importe por unidad'.
ls_fieldcat-scrtext_m = 'Importe por unidad'.
ls_fieldcat-scrtext_s = 'Importe por unidad'.
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
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 Selección de Datos'.
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 = ''
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 nómina para determinación período
IF pnpxabkr IS INITIAL.
* Verificar Fecha inicio período selección de datos
IF pnpbegda IS INITIAL.
* Asignar Fecha de inicio período selección de personal
begda = pnpbegps.
endda = pnpendps.
ELSE.
* Asignar Fecha inicio período selección de datos
begda = pnpbegda.
endda = pnpendda.
ENDIF.
* Verificar Fecha final período
IF endda IS INITIAL.
endda = begda.
ENDIF.
* Asignar Año 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 = pnpbegps.
endda = pnpendps.
ENDIF.
ENDFORM. "INITIALIZE_PERIOD
*&---------------------------------------------------------------------*
*& Form LEE_CLUSTER
*&---------------------------------------------------------------------*
FORM lee_cluster USING pernr TYPE persno
CHANGING subrc.
CLEAR: cd-key, subrc.
cd-key-pernr = pernr.
rp-imp-c2-cu.
IF rgdir[] IS INITIAL.
subrc = 4.
EXIT.
ENDIF.
* Eliminar motivo de nómina (dependiendo de parámetro)
IF p_ocrsn IS INITIAL.
DELETE rgdir WHERE ocrsn NE p_ocrsn.
ENDIF.
IF NOT p_ocrsn IS INITIAL.
IF p_ocrsn NE '*ALL'.
DELETE rgdir WHERE ocrsn NE p_ocrsn.
ENDIF.
ENDIF.
* rgdir the table where all payroll results periods are stored
LOOP AT rgdir WHERE abkrs IN pnpabkrs
AND fpbeg GE pn-begda
AND fpend LE pn-endda
AND srtza EQ 'A'
AND void NE 'V'.
CLEAR st_alv.
* set key to specific payroll results period(current rgdir loop pass)
UNPACK rgdir-seqnr TO rx-key-seqno.
MOVE pernr TO rx-key-pernr.
* Retrieves data for specific payroll results period
rp-imp-c2-cl. "chile
* rp-imp-c2-rx. "internacional
IF rt[] IS INITIAL.
subrc = 4.
ENDIF.
ENDLOOP.
ENDFORM. " LEE_CLUSTER
*&---------------------------------------------------------------------*
*& Form REQUEST_OCRSN
*&---------------------------------------------------------------------*
FORM request_ocrsn USING p_molga
CHANGING p_ocrsn.
CALL FUNCTION 'HR_OC_F4_POPUP_OCRSN'
EXPORTING
molga = p_molga
IMPORTING
ocrsn = p_ocrsn.
ENDFORM. " REQUEST_OCRSN
No hay comentarios:
Publicar un comentario