Anda di halaman 1dari 7

*&---------------------------------------------*

*& Report ZZZGEPE


*&---------------------------------------------*
REPORT zzzgepe.
************************************************
* C L A S E
************************************************
CLASS lcl_event_receiver DEFINITION DEFERRED.
************************************************
* T A B L A S
************************************************
TABLES: bkpf.
************************************************
* T I P O S
************************************************
TYPE-POOLS icon.
TYPES: BEGIN OF ty_bkpf,
bukrs TYPE bkpf-bukrs,
belnr TYPE bkpf-belnr,
gjahr TYPE bkpf-gjahr,
blart TYPE bkpf-blart,
bldat TYPE bkpf-bldat,
budat TYPE bkpf-budat,
monat TYPE bkpf-monat,
cpudt TYPE bkpf-cpudt,
usnam TYPE bkpf-usnam,
tcode TYPE bkpf-tcode,
waers TYPE bkpf-waers,
END OF ty_bkpf.
************************************************
* V A R I A B L E S G L O B A L E S
************************************************
DATA: it_bkpf TYPE TABLE OF ty_bkpf,
wa_bkpf TYPE ty_bkpf,
g_custom_container TYPE REF TO cl_gui_custom_container,
gt_fieldcatalog TYPE lvc_t_fcat,
gs_fcat TYPE lvc_s_fcat,
gs_layout TYPE lvc_s_layo,
g_repid LIKE sy-repid,
grid TYPE REF TO cl_gui_alv_grid,
event_receiver TYPE REF TO lcl_event_receiver.
************************************************
* D E F I N I C I O N D E C L A S E S
************************************************
CLASS lcl_event_receiver DEFINITION.
PUBLIC SECTION.
METHODS:
handle_double_click
FOR EVENT double_click OF cl_gui_alv_grid
IMPORTING e_row e_column .
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed.
METHODS:
handle_data_changed_finished

FOR EVENT data_changed_finished OF cl_gui_alv_grid


IMPORTING e_modified et_good_cells.
METHODS:
handle_before_user_command
FOR EVENT before_user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
PRIVATE SECTION.
ENDCLASS. "LCL_EVENT_RECEIVER DEFINITION
************************************************
* I M P L E M E N T A C I O N D E C L A S E S
************************************************
CLASS lcl_event_receiver IMPLEMENTATION.
METHOD handle_double_click.
PERFORM handle_double_click USING e_row e_column.
ENDMETHOD. "HANDLE_DOUBLE_CLICK
METHOD handle_data_changed.
PERFORM handle_data_changed USING er_data_changed.
ENDMETHOD. "HANDLE_DATA_CHANGED
METHOD handle_data_changed_finished.
PERFORM handle_data_changed_finished USING e_modified et_good_cells.
ENDMETHOD. "HANDLE_DATA_CHANGED_FINISHED
METHOD handle_before_user_command.
PERFORM handle_before_user_command USING e_ucomm.
ENDMETHOD. "HANDLE_BEFORE_USER_COMMAND
ENDCLASS. "lcl_event_receiver IMPLEMENTATION
************************************************
* P A R A M E T R O S D E S E L E C C I O N ************************************************
SELECTION-SCREEN BEGIN OF BLOCK 001 WITH FRAME TITLE text-001.
PARAMETERS: p_bukrs TYPE bkpf-bukrs.
SELECT-OPTIONS: so_belnr FOR bkpf-belnr.
PARAMETERS: p_gjahr TYPE bkpf-gjahr.
SELECT-OPTIONS: so_blart FOR bkpf-blart,
so_bldat FOR bkpf-bldat.
SELECTION-SCREEN END OF BLOCK 001.
************************************************
* START OF SELECTION
************************************************
START-OF-SELECTION.
CALL SCREEN '0100'.
*----------------------------------------------*
* MODULE buscar_datos OUTPUT
*----------------------------------------------*
MODULE buscar_datos OUTPUT.
PERFORM buscar_datos.
ENDMODULE. " buscar_datos OUTPUT
*----------------------------------------------*
*& Module mostrar_alv OUTPUT
*----------------------------------------------*
MODULE mostrar_alv OUTPUT.

* se obtiene una instancia del objeto grid


IF g_custom_container IS INITIAL.
PERFORM cargar_fieldcat.
PERFORM inicializar_layout.
CREATE OBJECT g_custom_container
EXPORTING
container_name = 'CCONTAINER'.
CREATE OBJECT grid
EXPORTING
i_parent = g_custom_container.
* Permite seleccionar por filas
gs_layout-sel_mode = 'D'.
gs_layout-stylefname = 'CELLSTYLES'.
* Se inicializa la pantalla del reporte
CALL METHOD grid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_fieldcatalog = gt_fieldcatalog
it_outtab = it_bkpf.
* Se crean los eventos, con sus respectivos manejadores.
CREATE OBJECT event_receiver.
SET HANDLER event_receiver->handle_double_click FOR grid.
SET HANDLER event_receiver->handle_data_changed FOR grid.
SET HANDLER event_receiver->handle_data_changed_finished FOR grid.
SET HANDLER event_receiver->handle_before_user_command FOR grid.
CALL METHOD grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_enter.
CALL METHOD grid->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = grid.
ELSE.
CALL METHOD grid->refresh_table_display
EXCEPTIONS
finished = 1
OTHERS = 2.
ENDIF.
ENDMODULE. " mostrar_alv OUTPUT
*----------------------------------------------*
* Module status_0100 OUTPUT
*----------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS '0100'.
ENDMODULE. "status_0100 OUTPUT
*----------------------------------------------*
* Form buscar_datos
*----------------------------------------------*
FORM buscar_datos .

SELECT bukrs belnr gjahr blart bldat budat


monat cpudt usnam tcode waers
FROM bkpf
INTO TABLE it_bkpf
WHERE bukrs EQ p_bukrs
AND belnr IN so_belnr
AND gjahr EQ p_gjahr
AND blart IN so_blart
AND bldat IN so_bldat.
ENDFORM. " buscar_datos
*----------------------------------------------*
* Form cargar_fieldcat
*----------------------------------------------*
FORM cargar_fieldcat .
* Sociedad.
CLEAR gs_fcat.
gs_fcat-fieldname = 'BUKRS'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Sociedad'.
gs_fcat-edit = space.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
* Nmero de documento contable.
CLEAR gs_fcat.
gs_fcat-fieldname = 'BELNR'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Nro. Doc. Contable'.
gs_fcat-edit = space.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
* Ejecicio.
CLEAR gs_fcat.
gs_fcat-fieldname = 'GJAHR'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Ejercicio'.
gs_fcat-edit = space.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
* Clase de documento.
CLEAR gs_fcat.
gs_fcat-fieldname = 'BLART'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Clase Doc.'.
gs_fcat-edit = 'X'.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
* fecha del documento.
CLEAR gs_fcat.
gs_fcat-fieldname = 'BLDAT'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Fecha Doc.'.
gs_fcat-edit = 'X'.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
* fecha de contabilizacin del documento.
CLEAR gs_fcat.
gs_fcat-fieldname = 'BUDAT'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Fecha Cont. Doc.'.

gs_fcat-edit = 'X'.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
* Mes contable.
CLEAR gs_fcat.
gs_fcat-fieldname = 'MONAT'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Mes contable'.
gs_fcat-edit = 'X'.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
* Da del registro del documento contable.
CLEAR gs_fcat.
gs_fcat-fieldname = 'CPUDT'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Da Reg. Doc. Contable'.
gs_fcat-edit = 'X'.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
* Nombre del usuario.
CLEAR gs_fcat.
gs_fcat-fieldname = 'USNAM'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Nombre del usuario'.
gs_fcat-edit = 'X'.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
* Cdigo de Transaccin.
CLEAR gs_fcat.
gs_fcat-fieldname = 'TCODE'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Cdigo transaccin'.
gs_fcat-edit = 'X'.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
* Clave de moneda.
CLEAR gs_fcat.
gs_fcat-fieldname = 'WAERS'.
gs_fcat-tabname = 'IT_BKPF'.
gs_fcat-coltext = 'Clave de moneda'.
gs_fcat-edit = 'X'.
gs_fcat-just = 'C'.
gs_fcat-col_opt = 'X'.
APPEND gs_fcat TO gt_fieldcatalog.
ENDFORM. " cargar_fieldcat
*----------------------------------------------*
* Form inicializar_layout
*----------------------------------------------*
FORM inicializar_layout .
gs_layout-col_opt = 'X'.
ENDFORM. " inicializar_layout
*----------------------------------------------*
* MODULE user_command_0100 INPUT
*----------------------------------------------*
MODULE user_command_0100 INPUT.

CASE sy-ucomm.
WHEN 'BACK' OR 'RETURN' OR 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE. "user_command_0100 INPUT
*----------------------------------------------*
* Form handle_double_click
*----------------------------------------------*
FORM handle_double_click USING p_e_row
p_e_column.
ENDFORM. " HANDLE_DOUBLE_CLICK
*----------------------------------------------*
* Form HANDLE_DATA_CHANGED
*----------------------------------------------*
FORM handle_data_changed USING p_er_data_changed.
PERFORM validar_entrada USING p_er_data_changed.
ENDFORM. " HANDLE_DATA_CHANGED
*----------------------------------------------*
*& Form HANDLE_BEFORE_USER_COMMAND
*----------------------------------------------*
FORM handle_before_user_command USING p_e_ucomm.
ENDFORM. " HANDLE_BEFORE_USER_COMMAND
*----------------------------------------------*
*& Form HANDLE_DATA_CHANGED_FINISHED
*----------------------------------------------*
FORM handle_data_changed_finished USING p_e_modified
p_et_good_cells.
ENDFORM. " HANDLE_DATA_CHANGED_FINISHED
*----------------------------------------------*
*& Form validar_entrada
*----------------------------------------------*
FORM validar_entrada USING p_change TYPE REF TO
cl_alv_changed_data_protocol.
* Ac se codifica toda la validacin de la entrada que se acaba
* de cargar desde el AVL.
ENDFORM. " VALIDAR_ENTRADA
NOTA1: Cuando creamos la pantalla, en la misma solamente se crea un CUSTOM CONTROL y se le pone el nombre
CCONTAINER, ya que este nombre lo necesitamos para especificar en el cdigo del programa.
NOTA2: Fjense que cuando modificamos un campo de las columnas que tenemos para modificar (segn definicin de
fieldcat) al darle enter nos lleva al mtodo handle_data_changed_finished.

Imagen de la dynpro.