Ejemplo de ALV Orientado A Objetos
Ejemplo de ALV Orientado A Objetos
Ejemplo de ALV Orientado A Objetos
****************************************************************
* LOCAL CLASSES: Definition
****************************************************************
CLASS LCL_EVENT_RECEIVER DEFINITION.
PUBLIC SECTION.
METHODS:
* Hotspot click control
HANDLE_HOTSPOT_CLICK
FOR EVENT HOTSPOT_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW_ID E_COLUMN_ID,
* Double-click control
HANDLE_DOUBLE_CLICK
FOR EVENT DOUBLE_CLICK OF CL_GUI_ALV_GRID
IMPORTING E_ROW E_COLUMN.
PRIVATE SECTION.
ENDCLASS.
****************************************************************
* LOCAL CLASSES: Implementation
****************************************************************
CLASS LCL_EVENT_RECEIVER IMPLEMENTATION.
METHOD HANDLE_HOTSPOT_CLICK.
* PERFORM HANDLE_HOTSPOT_CLICK USING E_ROW_ID E_COLUMN_ID.
ENDMETHOD.
METHOD HANDLE_DOUBLE_CLICK.
* PERFORM HANDLE_DOUBLE_CLICK USING E_ROW E_COLUMN.
ENDMETHOD. "handle_double_click
ENDCLASS.
*Pantalla de Selección
SELECTION-SCREEN BEGIN OF BLOCK BL01 WITH FRAME TITLE TEXT-S01.
PARAMETER: P_BUKRS LIKE BKPF-BUKRS,
P_GJAHR LIKE BKPF-GJAHR.
SELECTION-SCREEN END OF BLOCK BL01.
*Proceso Principal
START-OF-SELECTION.
SELECT * INTO TABLE IT_BKPF FROM BKPF
WHERE BUKRS EQ P_BUKRS
AND GJAHR EQ P_GJAHR.
CALL SCREEN 100.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'M0600'. " Menú
SET TITLEBAR 'T0600'. " Título
GS_LAYOUT_LIST-SEL_MODE = 'A'.
GS_LAYOUT_LIST-EXCP_ROLLN = 'IT_BUKRS'.
GS_LAYOUT_LIST-NUMC_TOTAL = 'X'.
GS_LAYOUT_LIST-GRID_TITLE = 'MI Primer ALV OO'.
IF G_CUSTOM_CONTAINER_LIST IS INITIAL.
CREATE OBJECT G_CUSTOM_CONTAINER_LIST
EXPORTING CONTAINER_NAME = G_CONTAINER_LIST.
CREATE OBJECT GRID_LIST
EXPORTING I_PARENT = G_CUSTOM_CONTAINER_LIST.
* Llena Datos del ALV
PERFORM ESTABLECER_LAYOUT_600.
PERFORM CARGAR_GRID_LIST.
* Llamado de Eventos
CREATE OBJECT EVENT_RECEIVER.
SET HANDLER EVENT_RECEIVER->HANDLE_DOUBLE_CLICK FOR GRID_LIST.
ENDIF.
* Ingresa datos en Custom-Control
CALL METHOD CL_GUI_CONTROL=>SET_FOCUS EXPORTING CONTROL = GRID_LIST.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE USER_COMMAND_0100 INPUT.
CASE SY-UCOMM.
WHEN 'BACK'. SET SCREEN 0. LEAVE SCREEN.
WHEN 'LEAV'. SET SCREEN 0. LEAVE SCREEN.
WHEN 'CANC'. SET SCREEN 0. LEAVE SCREEN.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
*& Form ESTABLECER_LAYOUT_600
*&---------------------------------------------------------------------*
FORM ESTABLECER_LAYOUT_600.
FREE GT_FIELDCAT_LIST.
CLEAR: WA_FIELDCAT_LIST,GT_FIELDCAT_LIST.
**Campo 1**
WA_FIELDCAT_LIST-FIELDNAME = 'BUKRS'.
WA_FIELDCAT_LIST-TABNAME = 'IT_BKPF'.
WA_FIELDCAT_LIST-COLTEXT = 'Sociedad'.
WA_FIELDCAT_LIST-OUTPUTLEN = 10.
WA_FIELDCAT_LIST-COL_POS = '1'.
WA_FIELDCAT_LIST-FIX_COLUMN = 'X'.
APPEND WA_FIELDCAT_LIST TO GT_FIELDCAT_LIST.
**Campo 2**
WA_FIELDCAT_LIST-FIELDNAME = 'BELNR'.
WA_FIELDCAT_LIST-TABNAME = 'IT_BKPF'.
WA_FIELDCAT_LIST-COLTEXT = 'Documento'.
WA_FIELDCAT_LIST-OUTPUTLEN = 10 .
WA_FIELDCAT_LIST-COL_POS = '2'.
WA_FIELDCAT_LIST-FIX_COLUMN = 'X'.
APPEND WA_FIELDCAT_LIST TO GT_FIELDCAT_LIST.
**Campo 3**
WA_FIELDCAT_LIST-FIELDNAME = 'GJAHR'.
WA_FIELDCAT_LIST-TABNAME = 'IT_BKPF'.
WA_FIELDCAT_LIST-COLTEXT = 'Año'.
WA_FIELDCAT_LIST-OUTPUTLEN = 4 .
WA_FIELDCAT_LIST-COL_POS = '3'.
APPEND WA_FIELDCAT_LIST TO GT_FIELDCAT_LIST.
ENDFORM. " ESTABLECER_LAYOUT_600
*&---------------------------------------------------------------------*
*& Form CARGAR_GRID_LIST
*&---------------------------------------------------------------------*
FORM CARGAR_GRID_LIST.
CALL METHOD GRID_LIST->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING I_STRUCTURE_NAME = 'IT_BKPF'
IS_LAYOUT = GS_LAYOUT_LIST
CHANGING
IT_OUTTAB = IT_BKPF[]
IT_FIELDCATALOG = GT_FIELDCAT_LIST.
ENDFORM. " CARGAR_GRID_LIST