Difference between revisions of "SAP ABAP ALV OM EX01"

From SapWiki
(Created page with " *&---------------------------------------------------------------------* *& Report YALV *&---------------------------------------------------------------------* *& ejemplo...")
 
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
  *&---------------------------------------------------------------------*
+
  <nowiki>*&---------------------------------------------------------------------*
*& Report YALV
+
*& Report YALV
*&---------------------------------------------------------------------*
+
*&---------------------------------------------------------------------*
*& ejemplo alv con user command y double click
+
*& ejemplo alv con user command y double click
*&---------------------------------------------------------------------*
+
*&---------------------------------------------------------------------*
REPORT yalv.
+
REPORT yalv.
TYPES: BEGIN OF ty_data,
+
TYPES: BEGIN OF ty_data,
          vbeln TYPE vbrk-vbeln,
+
        vbeln TYPE vbrk-vbeln,
          fkart TYPE vbrk-fkart,
+
        fkart TYPE vbrk-fkart,
          fkdat TYPE vbrk-fkdat,
+
        fkdat TYPE vbrk-fkdat,
          netwr TYPE vbrk-netwr,
+
        netwr TYPE vbrk-netwr,
          waerk TYPE vbrk-waerk,
+
        waerk TYPE vbrk-waerk,
        END OF ty_data.
+
      END OF ty_data.
+
 
DATA gt_data TYPE TABLE OF ty_data.
+
DATA gt_data TYPE TABLE OF ty_data.
DATA wa_data LIKE LINE OF gt_data.
+
DATA wa_data LIKE LINE OF gt_data.
+
 
**********************************************************************
+
**********************************************************************
* ALV data
+
* ALV data
**********************************************************************
+
**********************************************************************
DATA: gr_table  TYPE REF TO cl_salv_table.
+
DATA: gr_table  TYPE REF TO cl_salv_table.
DATA: gr_selections TYPE REF TO cl_salv_selections,
+
DATA: gr_selections TYPE REF TO cl_salv_selections,
      gt_rows      TYPE salv_t_row.
+
      gt_rows      TYPE salv_t_row.
DATA: gr_functions TYPE REF TO cl_salv_functions_list.
+
DATA: gr_functions TYPE REF TO cl_salv_functions_list.
+
 
*DATA : gt_color TYPE lvc_t_scol,
+
*DATA : gt_color TYPE lvc_t_scol,
*      st_color TYPE lvc_s_scol.
+
*      st_color TYPE lvc_s_scol.
+
 
*---------------------------------------------------------------------*
+
*---------------------------------------------------------------------*
*      CLASS lcl_handle_events DEFINITION
+
*      CLASS lcl_handle_events DEFINITION
*---------------------------------------------------------------------*
+
*---------------------------------------------------------------------*
*  define a local class for handling events of cl_salv_table
+
*  define a local class for handling events of cl_salv_table
*---------------------------------------------------------------------*
+
*---------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
+
CLASS lcl_handle_events DEFINITION.
  PUBLIC SECTION.
+
  PUBLIC SECTION.
    METHODS:
+
    METHODS:
      on_user_command FOR EVENT added_function OF cl_salv_events
+
      on_user_command FOR EVENT added_function OF cl_salv_events
        IMPORTING e_salv_function,
+
        IMPORTING e_salv_function,
+
 
      on_double_click FOR EVENT double_click OF cl_salv_events_table
+
      on_double_click FOR EVENT double_click OF cl_salv_events_table
        IMPORTING row column.
+
        IMPORTING row column.
+
 
ENDCLASS.                    "lcl_handle_events DEFINITION
+
ENDCLASS.                    "lcl_handle_events DEFINITION
+
 
*---------------------------------------------------------------------*
+
*---------------------------------------------------------------------*
*      CLASS lcl_handle_events IMPLEMENTATION
+
*      CLASS lcl_handle_events IMPLEMENTATION
*---------------------------------------------------------------------*
+
*---------------------------------------------------------------------*
* §5.2 implement the events for handling the events of cl_salv_table
+
* §5.2 implement the events for handling the events of cl_salv_table
*---------------------------------------------------------------------*
+
*---------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
+
CLASS lcl_handle_events IMPLEMENTATION.
  METHOD on_user_command.
+
  METHOD on_user_command.
    PERFORM user_command USING e_salv_function.
+
    PERFORM user_command USING e_salv_function.
  ENDMETHOD.                    "on_user_command
+
  ENDMETHOD.                    "on_user_command
+
 
  METHOD on_double_click.
+
  METHOD on_double_click.
    PERFORM double_click USING row column.
+
    PERFORM double_click USING row column.
  ENDMETHOD.                    "on_double_click
+
  ENDMETHOD.                    "on_double_click
+
 
ENDCLASS.                    "lcl_handle_events IMPLEMENTATION
+
ENDCLASS.                    "lcl_handle_events IMPLEMENTATION
* for handling the events of cl_salv_table
+
* for handling the events of cl_salv_table
DATA: gr_events TYPE REF TO lcl_handle_events.
+
DATA: gr_events TYPE REF TO lcl_handle_events.
**********************************************************************
+
**********************************************************************
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
*
+
*
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
SELECT-OPTIONS s_vbeln FOR wa_data-vbeln.
+
SELECT-OPTIONS s_vbeln FOR wa_data-vbeln.
+
 
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
START-OF-SELECTION.
+
START-OF-SELECTION.
*--------------------------------------------------------------------*
+
*--------------------------------------------------------------------*
+
 
  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_data FROM vbrk UP TO 100 ROWS
+
  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_data FROM vbrk UP TO 100 ROWS
                                                      WHERE vbeln IN s_vbeln.
+
                                                    WHERE vbeln IN s_vbeln.
+
 
  PERFORM display_alv.
+
  PERFORM display_alv.
+
 
*&---------------------------------------------------------------------*
+
*&---------------------------------------------------------------------*
*&      Form  user_command
+
*&      Form  user_command
*&---------------------------------------------------------------------*
+
*&---------------------------------------------------------------------*
*      Displays the content based on the selection criteria.
+
*      Displays the content based on the selection criteria.
*----------------------------------------------------------------------*
+
*----------------------------------------------------------------------*
FORM user_command USING i_function TYPE salv_de_function.
+
FORM user_command USING i_function TYPE salv_de_function.
+
 
  gr_selections = gr_table->get_selections( ).
+
  gr_selections = gr_table->get_selections( ).
+
 
* set selection mode
+
* set selection mode
  gr_selections->set_selection_mode(
+
  gr_selections->set_selection_mode(
  if_salv_c_selection_mode=>row_column ).
+
  if_salv_c_selection_mode=>row_column ).
+
 
  gt_rows = gr_selections->get_selected_rows( ).
+
  gt_rows = gr_selections->get_selected_rows( ).
+
 
  DATA(l_lines) = lines( gt_rows ).
+
  IF lines( gt_rows ) = 0.
+
    MESSAGE i000(0k) WITH 'Debe seleccionar al menos un registro'(i01).
  IF l_lines = 0.
+
    RETURN.
    RETURN.
+
  ENDIF.
  ENDIF.
+
 
+
  CLEAR wa_data.
  CLEAR wa_data.
+
  LOOP AT gt_rows INTO DATA(l_tabix).
  LOOP AT gt_rows INTO DATA(l_tabix).
+
 
+
    READ TABLE gt_data INDEX l_tabix INTO wa_data.
    READ TABLE gt_data INDEX l_tabix INTO wa_data.
+
 
+
    CASE i_function.
    CASE i_function.
+
      WHEN 'PRINT'. "ICON_PRINT
      WHEN 'PRINT'. "ICON_PRINT
+
        MESSAGE i000(0k) WITH 'N° factura:' wa_data-vbeln.
        MESSAGE i000(0k) WITH 'N° factura:' wa_data-vbeln.
+
    ENDCASE.
    ENDCASE.
+
 
+
  ENDLOOP.
  ENDLOOP.
+
 
+
  IF i_function <> 'LOG'.
ENDFORM.
+
    gr_table->refresh( refresh_mode = if_salv_c_refresh=>full ).
+
  ENDIF.
*&---------------------------------------------------------------------*
+
 
*&      Form  double_click
+
ENDFORM.
*&---------------------------------------------------------------------*
+
 
*      Diplays the popup for the selected row.
+
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
+
*&      Form  double_click
FORM double_click USING i_row    TYPE i
+
*&---------------------------------------------------------------------*
                        i_column TYPE lvc_fname.
+
*      Diplays the popup for the selected row.
+
*----------------------------------------------------------------------*
  READ TABLE gt_data INTO wa_data INDEX i_row.
+
FORM double_click USING i_row    TYPE i
+
                        i_column TYPE lvc_fname.
  CASE i_column.
+
 
    WHEN 'VBELN'.
+
  READ TABLE gt_data INTO wa_data INDEX i_row.
      SET PARAMETER ID 'VF' FIELD wa_data-vbeln.
+
 
      CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
+
  CASE i_column.
  ENDCASE.
+
    WHEN 'VBELN'.
+
      SET PARAMETER ID 'VF' FIELD wa_data-vbeln.
ENDFORM.                    " double_click
+
      CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
+
  ENDCASE.
FORM display_alv.
+
 
  DATA: lr_events TYPE REF TO cl_salv_events_table,
+
ENDFORM.                    " double_click
        lr_columns TYPE REF TO cl_salv_columns_table,
+
 
        lr_column  TYPE REF TO cl_salv_column,
+
FORM display_alv.
        lr_grid TYPE REF TO cl_salv_form_layout_grid,
+
  DATA: lr_events TYPE REF TO cl_salv_events_table,
        lr_layout TYPE REF TO cl_salv_layout,
+
        lr_columns TYPE REF TO cl_salv_columns_table,
        ls_key    TYPE salv_s_layout_key,
+
        lr_column  TYPE REF TO cl_salv_column,
        lr_sorts TYPE REF TO cl_salv_sorts,
+
        lr_grid TYPE REF TO cl_salv_form_layout_grid,
        lr_sort  TYPE REF TO cl_salv_sort.
+
        lr_layout TYPE REF TO cl_salv_layout,
+
        ls_key    TYPE salv_s_layout_key,
*... Create Instance
+
        lr_sorts TYPE REF TO cl_salv_sorts,
  TRY.
+
        lr_sort  TYPE REF TO cl_salv_sort.
      CALL METHOD cl_salv_table=>factory
+
 
        IMPORTING
+
*... Create Instance
          r_salv_table = gr_table
+
  TRY.
        CHANGING
+
      CALL METHOD cl_salv_table=>factory
          t_table      = gt_data.
+
        IMPORTING
    CATCH cx_salv_msg.
+
          r_salv_table = gr_table
  ENDTRY.
+
        CHANGING
+
          t_table      = gt_data.
  gr_table->set_screen_status(
+
    CATCH cx_salv_msg.
    pfstatus      =  'STAT_ALV'  "copiar de SALV_DEMO_TABLE_LAYOUT    SALV_STANDARD
+
  ENDTRY.
    report        =  sy-repid
+
 
    set_functions = gr_table->c_functions_all ).
+
  gr_table->set_screen_status(
+
    pfstatus      =  'STAT_ALV'  "copiar de SALV_DEMO_TABLE_LAYOUT    SALV_STANDARD
* setting default ALV generic funtions
+
    report        =  sy-repid
  gr_functions = gr_table->get_functions( ).
+
    set_functions = gr_table->c_functions_all ).
+
 
  gr_functions->set_all( ).
+
* setting default ALV generic funtions
+
  gr_functions = gr_table->get_functions( ).
* set layout
+
 
  lr_layout = gr_table->get_layout( ).
+
  gr_functions->set_all( ).
* set the Layout Key
+
 
  ls_key-report = sy-repid.
+
* set layout
  lr_layout->set_key( ls_key ).
+
  lr_layout = gr_table->get_layout( ).
+
* set the Layout Key
*  LR_LAYOUT->SET_SAVE_RESTRICTION( 3 ).
+
  ls_key-report = sy-repid.
+
  lr_layout->set_key( ls_key ).
  lr_layout->set_save_restriction( ).
+
 
  lr_layout->set_default( 'X' ).
+
*  LR_LAYOUT->SET_SAVE_RESTRICTION( 3 ).
+
 
* edit ALV columns
+
  lr_layout->set_save_restriction( ).
  lr_columns = gr_table->get_columns( ).
+
  lr_layout->set_default( 'X' ).
* optimize output
+
 
  lr_columns->set_optimize( 'X' ).
+
* edit ALV columns
+
  lr_columns = gr_table->get_columns( ).
*----------------------------------------------------------------------*
+
* optimize output
*  Set column names
+
  lr_columns->set_optimize( 'X' ).
*----------------------------------------------------------------------*
+
 
  DEFINE m_column_names.
+
*----------------------------------------------------------------------*
    TRY.
+
*  Set column names
        lr_column = lr_columns->get_column( &1 ).
+
*----------------------------------------------------------------------*
        lr_column->set_long_text( &2 ).
+
  DEFINE m_column_names.
        lr_column->set_medium_text( &2 ).
+
    TRY.
        lr_column->set_short_text( &3 ).
+
        lr_column = lr_columns->get_column( &1 ).
      CATCH cx_salv_not_found.
+
        lr_column->set_long_text( &2 ).
      CATCH cx_salv_existing.
+
        lr_column->set_medium_text( &2 ).
      CATCH cx_salv_data_error.
+
        lr_column->set_short_text( &3 ).
    ENDTRY.
+
      CATCH cx_salv_not_found.
  END-OF-DEFINITION.
+
      CATCH cx_salv_existing.
+
      CATCH cx_salv_data_error.
  DEFINE m_no_display.
+
    ENDTRY.
    TRY.
+
  END-OF-DEFINITION.
        lr_column = lr_columns->get_column( '&1' ).
+
 
        lr_column->set_visible( if_salv_c_bool_sap=>false ).
+
  DEFINE m_no_display.
      CATCH cx_salv_not_found.
+
    TRY.
    ENDTRY.
+
        lr_column = lr_columns->get_column( '&1' ).
  END-OF-DEFINITION.
+
        lr_column->set_visible( if_salv_c_bool_sap=>false ).
+
      CATCH cx_salv_not_found.
  DEFINE m_set_moneda.
+
    ENDTRY.
    TRY.
+
  END-OF-DEFINITION.
        lr_column = lr_columns->get_column( '&1' ).
+
 
        lr_column->set_currency_column( 'WAERK' ).
+
  DEFINE m_set_moneda.
      CATCH cx_salv_not_found.
+
    TRY.
      CATCH cx_salv_existing.
+
        lr_column = lr_columns->get_column( '&1' ).
      CATCH cx_salv_data_error.
+
        lr_column->set_currency_column( 'WAERK' ).
    ENDTRY.
+
      CATCH cx_salv_not_found.
  END-OF-DEFINITION.
+
      CATCH cx_salv_existing.
+
      CATCH cx_salv_data_error.
  m_set_moneda netwr.
+
    ENDTRY.
+
  END-OF-DEFINITION.
* register to the events of cl_salv_table
+
 
  lr_events = gr_table->get_event( ).
+
  m_set_moneda netwr.
  CREATE OBJECT gr_events.
+
 
+
* register to the events of cl_salv_table
* register to the event USER_COMMAND
+
  lr_events = gr_table->get_event( ).
  SET HANDLER gr_events->on_user_command FOR lr_events.
+
  CREATE OBJECT gr_events.
+
 
* register to the event DOUBLE_CLICK
+
* register to the event USER_COMMAND
  SET HANDLER gr_events->on_double_click FOR lr_events.
+
  SET HANDLER gr_events->on_user_command FOR lr_events.
+
 
  gr_selections = gr_table->get_selections( ).
+
* register to the event DOUBLE_CLICK
+
  SET HANDLER gr_events->on_double_click FOR lr_events.
* set selection mode
+
 
  gr_selections->set_selection_mode(
+
  gr_selections = gr_table->get_selections( ).
  if_salv_c_selection_mode=>row_column ).
+
 
*----------------------------------------------------------------------*
+
* set selection mode
*METHOD OF CREATING TOP-OF-LIST
+
  gr_selections->set_selection_mode(
*----------------------------------------------------------------------*
+
  if_salv_c_selection_mode=>row_column ).
  PERFORM create_top_of_list CHANGING lr_grid.
+
*----------------------------------------------------------------------*
  gr_table->set_top_of_list( lr_grid ).
+
*METHOD OF CREATING TOP-OF-LIST
+
*----------------------------------------------------------------------*
*... Display table
+
  PERFORM create_top_of_list CHANGING lr_grid.
  gr_table->display( ).
+
  gr_table->set_top_of_list( lr_grid ).
+
 
ENDFORM.                    "display_alv
+
*... Display table
+
  gr_table->display( ).
FORM create_top_of_list CHANGING lr_grid TYPE REF TO cl_salv_form_layout_grid.
+
 
  DATA : lr_flow  TYPE REF TO cl_salv_form_layout_flow,
+
ENDFORM.                    "display_alv
          lr_label TYPE REF TO cl_salv_form_label,
+
 
          lr_text  TYPE REF TO cl_salv_form_text,
+
FORM create_top_of_list CHANGING lr_grid TYPE REF TO cl_salv_form_layout_grid.
          l_text  TYPE string.
+
  DATA : lr_flow  TYPE REF TO cl_salv_form_layout_flow,
+
        lr_label TYPE REF TO cl_salv_form_label,
  l_text = 'Reporte Facturas'.
+
        lr_text  TYPE REF TO cl_salv_form_text,
+
        l_text  TYPE string.
  CREATE OBJECT lr_grid.
+
 
  CALL METHOD lr_grid->create_header_information
+
  l_text = 'Reporte Facturas'.
    EXPORTING
+
 
      row    = 1
+
  CREATE OBJECT lr_grid.
      column  = 1
+
  CALL METHOD lr_grid->create_header_information
*    ROWSPAN =
+
    EXPORTING
*    COLSPAN =
+
      row    = 1
      text    = l_text
+
      column  = 1
      tooltip = sy-title.
+
*    ROWSPAN =
*********************************************
+
*    COLSPAN =
  CALL METHOD lr_grid->create_flow
+
      text    = l_text
    EXPORTING
+
      tooltip = sy-title.
      row    = 2
+
*********************************************
      column  = 1
+
  CALL METHOD lr_grid->create_flow
    RECEIVING
+
    EXPORTING
      r_value = lr_flow.
+
      row    = 2
+
      column  = 1
  CALL METHOD lr_flow->create_label
+
    RECEIVING
    EXPORTING
+
      r_value = lr_flow.
      text    = 'Fecha:'
+
 
      tooltip = 'Fecha:'
+
  CALL METHOD lr_flow->create_label
    RECEIVING
+
    EXPORTING
      r_value = lr_label.
+
      text    = 'Fecha:'
+
      tooltip = 'Fecha:'
  l_text = |{ sy-datum DATE = USER }|.
+
    RECEIVING
+
      r_value = lr_label.
  CALL METHOD lr_flow->create_text
+
 
    EXPORTING
+
  l_text = |{ sy-datum DATE = USER }|.
      text    = l_text
+
 
      tooltip = l_text
+
  CALL METHOD lr_flow->create_text
    RECEIVING
+
    EXPORTING
      r_value = lr_text.
+
      text    = l_text
************************************************
+
      tooltip = l_text
ENDFORM.                    "create_top_of_list
+
    RECEIVING
 +
      r_value = lr_text.
 +
************************************************
 +
ENDFORM.                    "create_top_of_list</nowiki>

Latest revision as of 18:35, 15 April 2020

*&---------------------------------------------------------------------*
*& Report YALV
*&---------------------------------------------------------------------*
*& ejemplo alv con user command y double click
*&---------------------------------------------------------------------*
REPORT yalv.
TYPES: BEGIN OF ty_data,
         vbeln TYPE vbrk-vbeln,
         fkart TYPE vbrk-fkart,
         fkdat TYPE vbrk-fkdat,
         netwr TYPE vbrk-netwr,
         waerk TYPE vbrk-waerk,
       END OF ty_data.

DATA gt_data TYPE TABLE OF ty_data.
DATA wa_data LIKE LINE OF gt_data.

**********************************************************************
* ALV data
**********************************************************************
DATA: gr_table  TYPE REF TO cl_salv_table.
DATA: gr_selections TYPE REF TO cl_salv_selections,
      gt_rows       TYPE salv_t_row.
DATA: gr_functions TYPE REF TO cl_salv_functions_list.

*DATA : gt_color TYPE lvc_t_scol,
*       st_color TYPE lvc_s_scol.

*---------------------------------------------------------------------*
*       CLASS lcl_handle_events DEFINITION
*---------------------------------------------------------------------*
*   define a local class for handling events of cl_salv_table
*---------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
  PUBLIC SECTION.
    METHODS:
      on_user_command FOR EVENT added_function OF cl_salv_events
        IMPORTING e_salv_function,

      on_double_click FOR EVENT double_click OF cl_salv_events_table
        IMPORTING row column.

ENDCLASS.                    "lcl_handle_events DEFINITION

*---------------------------------------------------------------------*
*       CLASS lcl_handle_events IMPLEMENTATION
*---------------------------------------------------------------------*
* §5.2 implement the events for handling the events of cl_salv_table
*---------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
  METHOD on_user_command.
    PERFORM user_command USING e_salv_function.
  ENDMETHOD.                    "on_user_command

  METHOD on_double_click.
    PERFORM double_click USING row column.
  ENDMETHOD.                    "on_double_click

ENDCLASS.                    "lcl_handle_events IMPLEMENTATION
* for handling the events of cl_salv_table
DATA: gr_events TYPE REF TO lcl_handle_events.
**********************************************************************
*--------------------------------------------------------------------*
*
*--------------------------------------------------------------------*
SELECT-OPTIONS s_vbeln FOR wa_data-vbeln.

*--------------------------------------------------------------------*
START-OF-SELECTION.
*--------------------------------------------------------------------*

  SELECT * INTO CORRESPONDING FIELDS OF TABLE gt_data FROM vbrk UP TO 100 ROWS
                                                     WHERE vbeln IN s_vbeln.

  PERFORM display_alv.

*&---------------------------------------------------------------------*
*&      Form  user_command
*&---------------------------------------------------------------------*
*      Displays the content based on the selection criteria.
*----------------------------------------------------------------------*
FORM user_command USING i_function TYPE salv_de_function.

  gr_selections = gr_table->get_selections( ).

* set selection mode
  gr_selections->set_selection_mode(
  if_salv_c_selection_mode=>row_column ).

  gt_rows = gr_selections->get_selected_rows( ).

  IF lines( gt_rows ) = 0.
    MESSAGE i000(0k) WITH 'Debe seleccionar al menos un registro'(i01).
    RETURN.
  ENDIF.

  CLEAR wa_data.
  LOOP AT gt_rows INTO DATA(l_tabix).

    READ TABLE gt_data INDEX l_tabix INTO wa_data.

    CASE i_function.
      WHEN 'PRINT'. "ICON_PRINT
        MESSAGE i000(0k) WITH 'N° factura:' wa_data-vbeln.
    ENDCASE.

  ENDLOOP.

  IF i_function <> 'LOG'.
    gr_table->refresh( refresh_mode = if_salv_c_refresh=>full ).
  ENDIF.

ENDFORM.

*&---------------------------------------------------------------------*
*&      Form  double_click
*&---------------------------------------------------------------------*
*       Diplays the popup for the selected row.
*----------------------------------------------------------------------*
FORM double_click USING i_row    TYPE i
                        i_column TYPE lvc_fname.

  READ TABLE gt_data INTO wa_data INDEX i_row.

  CASE i_column.
    WHEN 'VBELN'.
      SET PARAMETER ID 'VF' FIELD wa_data-vbeln.
      CALL TRANSACTION 'VF03' AND SKIP FIRST SCREEN.
  ENDCASE.

ENDFORM.                    " double_click

FORM display_alv.
  DATA: lr_events TYPE REF TO cl_salv_events_table,
        lr_columns TYPE REF TO cl_salv_columns_table,
        lr_column  TYPE REF TO cl_salv_column,
        lr_grid TYPE REF TO cl_salv_form_layout_grid,
        lr_layout TYPE REF TO cl_salv_layout,
        ls_key    TYPE salv_s_layout_key,
        lr_sorts TYPE REF TO cl_salv_sorts,
        lr_sort  TYPE REF TO cl_salv_sort.

*... Create Instance
  TRY.
      CALL METHOD cl_salv_table=>factory
        IMPORTING
          r_salv_table = gr_table
        CHANGING
          t_table      = gt_data.
    CATCH cx_salv_msg.
  ENDTRY.

  gr_table->set_screen_status(
    pfstatus      =  'STAT_ALV'  "copiar de SALV_DEMO_TABLE_LAYOUT    SALV_STANDARD
    report        =  sy-repid
    set_functions = gr_table->c_functions_all ).

* setting default ALV generic funtions
  gr_functions = gr_table->get_functions( ).

  gr_functions->set_all( ).

* set layout
  lr_layout = gr_table->get_layout( ).
* set the Layout Key
  ls_key-report = sy-repid.
  lr_layout->set_key( ls_key ).

*  LR_LAYOUT->SET_SAVE_RESTRICTION( 3 ).

  lr_layout->set_save_restriction( ).
  lr_layout->set_default( 'X' ).

* edit ALV columns
  lr_columns = gr_table->get_columns( ).
* optimize output
  lr_columns->set_optimize( 'X' ).

*----------------------------------------------------------------------*
*  Set column names
*----------------------------------------------------------------------*
  DEFINE m_column_names.
    TRY.
        lr_column = lr_columns->get_column( &1 ).
        lr_column->set_long_text( &2 ).
        lr_column->set_medium_text( &2 ).
        lr_column->set_short_text( &3 ).
      CATCH cx_salv_not_found.
      CATCH cx_salv_existing.
      CATCH cx_salv_data_error.
    ENDTRY.
  END-OF-DEFINITION.

  DEFINE m_no_display.
    TRY.
        lr_column = lr_columns->get_column( '&1' ).
        lr_column->set_visible( if_salv_c_bool_sap=>false ).
      CATCH cx_salv_not_found.
    ENDTRY.
  END-OF-DEFINITION.

  DEFINE m_set_moneda.
    TRY.
        lr_column = lr_columns->get_column( '&1' ).
        lr_column->set_currency_column( 'WAERK' ).
      CATCH cx_salv_not_found.
      CATCH cx_salv_existing.
      CATCH cx_salv_data_error.
    ENDTRY.
  END-OF-DEFINITION.

  m_set_moneda netwr.

* register to the events of cl_salv_table
  lr_events = gr_table->get_event( ).
  CREATE OBJECT gr_events.

* register to the event USER_COMMAND
  SET HANDLER gr_events->on_user_command FOR lr_events.

* register to the event DOUBLE_CLICK
  SET HANDLER gr_events->on_double_click FOR lr_events.

  gr_selections = gr_table->get_selections( ).

* set selection mode
  gr_selections->set_selection_mode(
  if_salv_c_selection_mode=>row_column ).
*----------------------------------------------------------------------*
*METHOD OF CREATING TOP-OF-LIST
*----------------------------------------------------------------------*
  PERFORM create_top_of_list CHANGING lr_grid.
  gr_table->set_top_of_list( lr_grid ).

*... Display table
  gr_table->display( ).

ENDFORM.                    "display_alv

FORM create_top_of_list CHANGING lr_grid TYPE REF TO cl_salv_form_layout_grid.
  DATA : lr_flow  TYPE REF TO cl_salv_form_layout_flow,
         lr_label TYPE REF TO cl_salv_form_label,
         lr_text  TYPE REF TO cl_salv_form_text,
         l_text   TYPE string.

  l_text = 'Reporte Facturas'.

  CREATE OBJECT lr_grid.
  CALL METHOD lr_grid->create_header_information
    EXPORTING
      row     = 1
      column  = 1
*     ROWSPAN =
*     COLSPAN =
      text    = l_text
      tooltip = sy-title.
*********************************************
  CALL METHOD lr_grid->create_flow
    EXPORTING
      row     = 2
      column  = 1
    RECEIVING
      r_value = lr_flow.

  CALL METHOD lr_flow->create_label
    EXPORTING
      text    = 'Fecha:'
      tooltip = 'Fecha:'
    RECEIVING
      r_value = lr_label.

  l_text = |{ sy-datum DATE = USER }|.

  CALL METHOD lr_flow->create_text
    EXPORTING
      text    = l_text
      tooltip = l_text
    RECEIVING
      r_value = lr_text.
************************************************
ENDFORM.                    "create_top_of_list