Pequeña plantilla llegar-y-compilar con las nuevas características de la clase CL_SALV_TABLE, totalmente recomendado.
Toda la info de la api: parte 1 - parte 2.
REPORT zbn_reporte_a
NO STANDARD PAGE HEADING
LINE-SIZE 255.
*-----------------------------------------------------------------------
* DECLARACIONES
*-----------------------------------------------------------------------
*-----------------------------------------------------------------------
* Declaración de Tablas
*-----------------------------------------------------------------------
TABLES: pernr.
NODES: peras.
*-----------------------------------------------------------------------
* Declaración de Infotipos
*-----------------------------------------------------------------------
INFOTYPES: 0001, 0002, 0185.
*----------------------------------------------------------------------*
* 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,
c_subty_ictyp TYPE subty VALUE '01'.
*-----------------------------------------------------------------------
* INCLUDES Y TYPE-POOLS
*-----------------------------------------------------------------------
TYPE-POOLS: slis, truxs.
*----------------------------------------------------------------------*
* TYPES - Declaracion de estructuras de tablas internas *
*----------------------------------------------------------------------*
TYPES: BEGIN OF zst_alv,
icnum TYPE p0185-icnum,
pernr TYPE p0001-pernr,
vorna TYPE p0002-vorna,
cname TYPE p0002-cname,
stell TYPE p0001-stell,
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.
*-----------------------------------------------------------------------
* PANTALLAS DE SELECCION Y EVENTOS DE PANTALLA
*-----------------------------------------------------------------------
*----------------------------------------------------------------------*
* Pantalla de Selección *
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
* 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.
* tablas internas
PERFORM inicializa_tablas.
*----------------------------------------------------------------------*
* GET PERAS *
*----------------------------------------------------------------------*
GET peras.
CLEAR: st_alv.
rp_provide_from_last: p0001 space pn-begda pn-endda,
p0002 space pn-begda pn-endda,
p0185 c_subty_ictyp pn-begda pn-endda.
"id
st_alv-pernr = pernr-pernr.
st_alv-icnum = p0185-icnum.
IF st_alv-icnum IS INITIAL.
st_alv-icnum = st_alv-pernr.
ENDIF.
"nombre
st_alv-vorna = p0002-vorna.
CONCATENATE p0002-nachn p0002-name2
INTO st_alv-cname SEPARATED BY space.
"cargo
st_alv-stell = p0001-stell.
APPEND st_alv TO tt_alv.
*----------------------------------------------------------------------*
*END-OF-SELECTION
*----------------------------------------------------------------------*
END-OF-SELECTION.
IF NOT tt_alv[] IS INITIAL.
PERFORM muestra_alv.
ELSE.
MESSAGE 'No se encontraron datos' TYPE 'E'.
ENDIF.
*-----------------------------------------------------------------------
* RUTINAS
*-----------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& Form inicializa_tablas
*&---------------------------------------------------------------------*
FORM inicializa_tablas.
FREE: tt_alv.
ENDFORM. " inicializa_tablas
*&---------------------------------------------------------------------*
*& Form MUESTRA_ALV
*&---------------------------------------------------------------------*
FORM muestra_alv .
DATA: gr_table TYPE REF TO cl_salv_table.
cl_salv_table=>factory( IMPORTING r_salv_table = gr_table
CHANGING t_table = tt_alv
).
PERFORM alv_functions USING gr_table.
PERFORM alv_display USING gr_table.
PERFORM alv_columns USING gr_table.
PERFORM alv_sort USING gr_table.
gr_table->display( ).
ENDFORM. " MUESTRA_ALV
*&---------------------------------------------------------------------*
*& Form ALV_FUNCTIONS
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM alv_functions USING p_gr_table TYPE REF TO cl_salv_table.
DATA: gr_functions TYPE REF TO cl_salv_functions.
gr_functions = p_gr_table->get_functions( ).
gr_functions->set_all( abap_true ).
ENDFORM. " ALV_FUNCTIONS
*&---------------------------------------------------------------------*
*& Form ALV_DISPLAY
*&---------------------------------------------------------------------*
FORM alv_display USING p_gr_table TYPE REF TO cl_salv_table.
DATA: gr_display TYPE REF TO cl_salv_display_settings.
gr_display = p_gr_table->get_display_settings( ).
gr_display->set_striped_pattern( cl_salv_display_settings=>true ).
* gr_display->set_list_header( ).
ENDFORM. " ALV_DISPLAY
*&---------------------------------------------------------------------*
*& Form ALV_COLUMNS
*&---------------------------------------------------------------------*
FORM alv_columns USING p_gr_table TYPE REF TO cl_salv_table.
DATA: gr_columns TYPE REF TO cl_salv_columns_table.
DATA: gr_column TYPE REF TO cl_salv_column_table.
gr_columns = p_gr_table->get_columns( ).
gr_columns->set_optimize( abap_true ).
gr_column ?= gr_columns->get_column( 'ICNUM' ).
gr_column->set_key( 'X' ).
gr_column ?= gr_columns->get_column( 'PERNR' ).
gr_column->set_key( 'X' ).
ENDFORM. " ALV_COLUMNS
*&---------------------------------------------------------------------*
*& Form ALV_SORT
*&---------------------------------------------------------------------*
FORM alv_sort USING p_gr_table TYPE REF TO cl_salv_table.
DATA: gr_sorts TYPE REF TO cl_salv_sorts.
gr_sorts = p_gr_table->get_sorts( ).
gr_sorts->add_sort( 'ICNUM' ).
ENDFORM. " ALV_SORT
No hay comentarios:
Publicar un comentario