You are on page 1of 4

TYPES: tyt_reporte TYPE STANDARD TABLE OF zej_cp_alv_anti_trami_prep.

DATA: lo_alv TYPE REF TO cl_salv_table.


CLASS: lcl_handle_events DEFINITION DEFERRED.
DATA: gr_events TYPE REF TO lcl_handle_events.
DATA: gt_reporte TYPE STANDARD TABLE OF zej_cp_alv_anti_trami_prep.

FORM user_command .

IF sy-ucomm EQ 'APROBAR'.
PERFORM handler_aprobar_presupuesto.
ENDIF.

ENDFORM.

FORM handler_aprobar_presupuesto .
DATA: lt_selected TYPE STANDARD TABLE OF zej_cp_alv_anti_trami_prep.
DATA: lr_selections_d TYPE REF TO cl_salv_selections,
lr_selections_h TYPE REF TO cl_salv_selections,
lt_row_d TYPE salv_t_row,
lt_row_h TYPE salv_t_row,
lv_row TYPE i,
lv_column TYPE i.
DATA ls_reporte TYPE zej_cp_alv_anti_trami_prep.
"zej_cp_alv_aprob_trami_presup.
DATA lt_return TYPE bapiret2_t.
DATA lv_docyear TYPE bapi_0050_fields-doc_year.
DATA lv_docnumber TYPE bapi_0050_fields-document.
DATA lv_answer TYPE c.
DATA lv_estado TYPE zej_cp_estado_aprob_presup.
DATA ls_return TYPE bapiret2.
DATA lv_mensaje1 TYPE zej_cp_texto.
DATA lv_mensaje2 TYPE zej_cp_texto.
DATA lv_error TYPE flag.
*--------------------------------------------------------------------*

lr_selections_h = lo_alv->get_selections( ).
lt_row_h = lr_selections_h->get_selected_rows( ).

IF lt_row_h[] IS INITIAL.
RETURN.
ENDIF.

PERFORM popup_confirmacion CHANGING lv_answer.


IF lv_answer <> 1.
RETURN.
ENDIF.

LOOP AT lt_row_h INTO lv_row.


ls_reporte = gt_reporte[ lv_row ].
APPEND ls_reporte TO lt_selected.
ENDLOOP.

LOOP AT lt_selected INTO ls_reporte.


" Procesar
ENDLOOP.

ENDFORM.

*----------------------------------------------------------------------*
* CLASS lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
CLASS lcl_handle_events DEFINITION.
PUBLIC SECTION.
CLASS-METHODS on_user_command FOR EVENT added_function OF cl_salv_events
IMPORTING e_salv_function.
* METHODS : on_double_click FOR EVENT double_click OF cl_salv_events_table
* IMPORTING row column.
* METHODS : on_link_click FOR EVENT link_click OF cl_salv_events_table
* IMPORTING row column.
ENDCLASS. "lcl_handle_events DEFINITION
*----------------------------------------------------------------------*
* CLASS lcl_handle_events IMPLEMENTATION
*----------------------------------------------------------------------*
CLASS lcl_handle_events IMPLEMENTATION.
METHOD on_user_command.

PERFORM user_command.

ENDMETHOD.
* METHOD on_double_click.
* PERFORM get_ord_info USING row column.
* ENDMETHOD. "on_double_click
* METHOD on_link_click.
* PERFORM get_ord_info USING row column.
* ENDMETHOD. "on_link_click
ENDCLASS. "lcl_handle_events IMPLEMENTATION

FORM mostrar_alv_anualidades .

DATA: lr_columns TYPE REF TO cl_salv_columns_table,


lr_column TYPE REF TO cl_salv_column_table,
" lr_column TYPE REF TO cl_salv_column,
lr_functions TYPE REF TO cl_salv_functions_list,
lr_display TYPE REF TO cl_salv_display_settings,
lr_layout TYPE REF TO cl_salv_layout,
lr_sorts TYPE REF TO cl_salv_sorts,
ls_key TYPE salv_s_layout_key.
DATA: lr_select TYPE REF TO cl_salv_selections.
DATA: lr_events TYPE REF TO cl_salv_events_table.

TRY.
cl_salv_table=>factory( IMPORTING r_salv_table = lo_alv
CHANGING t_table = gt_reporte ).

" Standard:
* pfstatus = 'STANDARD_FULLSCREEN'
* report = 'SAPLSLVC_FULLSCREEN'
" ALV-Toolbar
lo_alv->set_screen_status(
pfstatus = 'ZPF_STATUS_ALV'
report = sy-repid
set_functions = lo_alv->c_functions_all ).

* Get functions object


lr_functions = lo_alv->get_functions( ).
* Set all the functions
lr_functions->set_all( if_salv_c_bool_sap=>true ).

* Get column object


lr_columns = lo_alv->get_columns( ).

* These are optional functions


* If you want to change the description of columns, call and set as shown below

lr_column ?= lr_columns->get_column( columnname = 'CMMTITEM' ).


lr_column->set_visible( value = if_salv_c_bool_sap=>true ).

lr_column ?= lr_columns->get_column( columnname = 'FISCYEAR' ).


lr_column->set_visible( value = if_salv_c_bool_sap=>false ).

lr_column ?= lr_columns->get_column( columnname = 'DOCYEAR' ).


lr_column->set_visible( value = if_salv_c_bool_sap=>false ).

lr_column ?= lr_columns->get_column( columnname = 'DELETE_RECORD' ).


lr_column->set_technical( value = if_salv_c_bool_sap=>true ).

lr_column ?= lr_columns->get_column( columnname = 'VALTYPE' ).


lr_column->set_visible( value = if_salv_c_bool_sap=>false ).

lr_column ?= lr_columns->get_column( columnname = 'BUDCAT' ).


lr_column->set_visible( value = if_salv_c_bool_sap=>false ).

lr_column ?= lr_columns->get_column( columnname = 'CMMTITEM' ).


lr_column->set_visible( value = if_salv_c_bool_sap=>false ).

* CATCH cx_salv_not_found. "

* Optimize the columns


lr_columns->set_optimize( ).

* Get sort column


* lr_sorts = lr_alv->get_sorts( ).
* lr_sorts->clear( ).

* Sort table
* lr_sorts->add_sort( columnname = 'AUFNR' ).

* Get Layout
lr_layout = lo_alv->get_layout( ).

ls_key-report = sy-repid.
* Set Layout
lr_layout->set_key( ls_key ).
lr_layout->set_default( ' ' ).
lr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).

* Optional, if there is a layout from selection screen use it


* IF NOT p_layout IS INITIAL.
* lr_layout->set_initial_layout( p_layout ).
* ENDIF.

* Get Display setting


lr_display = lo_alv->get_display_settings( ).

lr_select = lo_alv->get_selections( ).
lr_select->set_selection_mode( if_salv_c_selection_mode=>row_column ).

lr_display->set_striped_pattern( cl_salv_display_settings=>true ).

lr_events = lo_alv->get_event( ).
SET HANDLER lcl_handle_events=>on_user_command FOR lr_events.
* CREATE OBJECT gr_events.
* SET HANDLER gr_events->if_salv_events_actions_table FOR lr_events.

lo_alv->display( ).

* Catch exceptions
CATCH cx_salv_msg.
CATCH cx_salv_not_found.
CATCH cx_salv_data_error.
CATCH cx_salv_existing.
ENDTRY.

ENDFORM.