SAP ABAP ALV OM

From SapWiki
Revision as of 18:32, 26 March 2020 by WikiSysop (talk | contribs)

ALV SIMPLE

DATA: gr_table  TYPE REF TO cl_salv_table.
DATA: gr_functions TYPE REF TO cl_salv_functions_list.
*&---------------------------------------------------------------------*
*&      Form  display_alv
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
FORM display_alv .

  DATA: lr_columns TYPE REF TO cl_salv_columns_table,
        lr_column  TYPE REF TO cl_salv_column.
  DATA: lr_layout TYPE REF TO cl_salv_layout,
        ls_key    TYPE salv_s_layout_key.
 
*... 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.
 
* 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
*----------------------------------------------------------------------*
  TRY.
      lr_column = lr_columns->get_column( 'DDTEXT' ).
      lr_column->set_long_text( 'Desc. Estatus' ).
      lr_column->set_medium_text( 'Desc. Estatus' ).
      lr_column->set_short_text( 'Desc.Estat' ).
    CATCH cx_salv_not_found.
    CATCH cx_salv_existing.
    CATCH cx_salv_data_error.
  ENDTRY.

*--------------------------------------------------------------------*
* hide columns
*--------------------------------------------------------------------*
  TRY.
      lr_column = lr_columns->get_column( 'FECHA_FIRMA' ).
      lr_column->set_technical( 'X' ).
    CATCH cx_salv_not_found.
    CATCH cx_salv_existing.
    CATCH cx_salv_data_error.
  ENDTRY.

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

ENDFORM.                    " DISPLAY_ALV

Función para desplegar un LOG usando ALV OM

* ----- Output in Log --------------------------------------------------
TYPES: BEGIN OF ty_news,
         icon(4),
         pernr   TYPE zhr_solicitudes-pernr,
         begda   TYPE zhr_solicitudes-begda,
         endda   TYPE zhr_solicitudes-endda,
         subty   TYPE zhr_solicitudes-subty,
         text    LIKE bapiret2-message,
       END OF ty_news.

DATA: news TYPE TABLE OF ty_news.
..
..
CALL FUNCTION 'Z_DISPLAY_LOG'
   EXPORTING
    START_COLUMN       = 8
    END_COLUMN         = 120
    START_LINE         = 3
    END_LINE           = 15
  CHANGING
    i_news = news.
FUNCTION Z_DISPLAY_LOG.
*"----------------------------------------------------------------------
*"*"Interfase local
*"  IMPORTING
*"     REFERENCE(START_COLUMN) TYPE  I DEFAULT 8
*"     REFERENCE(END_COLUMN) TYPE  I DEFAULT 120
*"     REFERENCE(START_LINE) TYPE  I DEFAULT 3
*"     REFERENCE(END_LINE) TYPE  I DEFAULT 15
*"  CHANGING
*"     REFERENCE(I_NEWS) TYPE  TABLE
*"----------------------------------------------------------------------
* SALV Data
  DATA: gr_table  TYPE REF TO cl_salv_table.
  DATA: gr_functions TYPE REF TO cl_salv_functions_list.
  DATA: lr_columns TYPE REF TO cl_salv_columns_table,
        lr_column  TYPE REF TO cl_salv_column.

  try.
* SALV Create Instance
  CALL METHOD cl_salv_table=>factory
  IMPORTING
    r_salv_table = gr_table
  CHANGING
    t_table      = i_news.           "internal table

    CATCH cx_salv_msg.      "#EC NO_HANDLER
  ENDTRY.

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

  gr_functions->set_all( ).
*... §4.1 set the size and position of the Popup via coordinates
  gr_table->set_screen_popup(
  start_column = start_column
  end_column   = end_column
  start_line   = start_line
  end_line     = end_line ).

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

  TRY.
    lr_column = lr_columns->get_column( 'ICON' ).
    lr_column->set_long_text( 'Status' ).
    lr_column->set_medium_text( 'Status' ).
    lr_column->set_short_text( 'Status' ).
  CATCH cx_salv_not_found.   "#EC NO_HANDLER
  CATCH cx_salv_existing.    "#EC NO_HANDLER
  CATCH cx_salv_data_error.  "#EC NO_HANDLER
  ENDTRY.

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