Академический Документы
Профессиональный Документы
Культура Документы
Original
Initially I posted this article on SCN Power of ABAP Objects: Overcome the Restrictions of
SALV Model, which got lot of criticism and praise as well. When SCN was migrated to new
system, the code snippet formatting got lost. So, I decided to move it here with the
formatting.
Background
I was reading the help on the CL_SALV_TABLE to get more insight of how to use this new
SALV model effectively. When I came across the section Recommendation and Restriction,
I was amazed by reading Tables displayed with ALV are not ready for input.
It was very hard for me to understand this restriction because: The new SALV model is
unified object oriented model which has kind of wrapper classes which are ultimately calling
the FM REUSE_ALV_GRID_DISPLAY or REUSE_ALV_LIST_DISPLAY; class
GL_GUI_ALV_GRID and so on. So, if the ALV created with the CL_GUI_ALV_GRID can be
ready for input, why cant the ALV created with the SALV model be the Ready for input?
This propelled me to analyze how we can make the ALV Full-screen as Set ready for
Input.
Basically, to achieve this type of not achievable functionality of the Fullscreen ALV, I
get the object using the FM GET_GLOBALS_FROM_SLVC_FULLSCR and use the
methods available in the CL_GUI_GRID_DISPLAY followed by the refresh method to
refresh the ALV.
Based on the assumption if I get the ALV object from the SALV model than I can
make the SALV model ALV to Set Ready for input I have started searching the
ALV object in the SALV model. At the very top node of the SALV model
CL_SALV_MODEL, I got the methods (GET_GRID) which can provide me the ALV
grid object.
UML diagram contains the SALV hierarchy and visibility of the R_CONTROLLER:
Solution
I knew that I have to think in a different way, and I tried to inherite the class from the
class CL_SALV_MODEL_LIST, passed the ALV model to the class and tried to
access the R_CONTROLLER and BINGO I am able to access the
R_CONTROLLER in my inherited class.
UML Diagram shows the iherited class along with the existing SALV model:
Steps to follow:
When we run the report, ALV will not come directly in the input mode:
As soon as we press the My Function button, ALV will change into editable ALV.
This ALV will have its separate GUI Status which contains all the required buttons for
the Editable ALV.
UML Diagram
Here is the code, which I used to get the access of the GRID object from the SALV
model and to make ALV editable. Here I have used the PF-STATUS avaliable in the
report program SALV_DEMO_TABLE_EVENTS for easy installation of this demo
report.
*&---------------------------------------------------------------------*
*& Report ZTEST_NP_EDIT_SALV
*& Overcome the restriction of the SALV model using the power of the
*&
Object Oriented ABAP
*&---------------------------------------------------------------------*
REPORT ztest_np_edit_salv.
*----------------------------------------------------------------------*
* Define the Local class inheriting from the CL_SALV_MODEL_LIST
* to get an access of the model, controller and adapter which inturn
* provides the Grid Object
*----------------------------------------------------------------------*
CLASS lcl_salv_model DEFINITION INHERITING FROM cl_salv_model_list.
PUBLIC SECTION.
DATA: o_control TYPE REF TO cl_salv_controller_model,
o_adapter TYPE REF TO cl_salv_adapter.
METHODS:
grabe_model
IMPORTING
io_model TYPE REF TO cl_salv_model,
grabe_controller,
grabe_adapter.
PRIVATE SECTION.
DATA: lo_model TYPE REF TO cl_salv_model.
ENDCLASS.
"LCL_SALV_MODEL DEFINITION
*----------------------------------------------------------------------*
* Event handler for the added buttons
*----------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
on_user_command FOR EVENT added_function OF cl_salv_events
IMPORTING e_salv_function.
ENDCLASS.
"lcl_event_handler DEFINITION
*----------------------------------------------------------------------*
* Local Report class - Definition
*----------------------------------------------------------------------*
CLASS lcl_report DEFINITION.
PUBLIC SECTION.
TYPES: ty_t_sflights TYPE STANDARD TABLE OF sflights.
DATA: t_data TYPE ty_t_sflights.
DATA: o_salv
TYPE REF TO cl_salv_table.
DATA: o_salv_model TYPE REF TO lcl_salv_model.
METHODS:
get_data,
generate_output.
ENDCLASS.
"lcl_report DEFINITION
*----------------------------------------------------------------------*
* Global data
*----------------------------------------------------------------------*
DATA: lo_report TYPE REF TO lcl_report.
*----------------------------------------------------------------------*
* Start of selection
*----------------------------------------------------------------------*
START-OF-SELECTION.
CREATE OBJECT lo_report.
lo_report->get_data( ).
lo_report->generate_output( ).
*----------------------------------------------------------------------*
* Local Report class - Implementation
*----------------------------------------------------------------------*
CLASS lcl_report IMPLEMENTATION.
METHOD get_data.
*
test data
SELECT * FROM sflights
METHOD grabe_model.
save the model
lo_model = io_model.
ENDMETHOD.
"grabe_model
METHOD grabe_controller.
*
save the controller
o_control = lo_model->r_controller.
ENDMETHOD.
"grabe_controller
METHOD grabe_adapter.
*
save the adapter from controller
o_adapter ?= lo_model->r_controller->r_adapter.
ENDMETHOD.
"grabe_adapter
ENDCLASS.
"LCL_SALV_MODEL IMPLEMENTATION
*----------------------------------------------------------------------*
* Event Handler for the SALV
*----------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION.
METHOD on_user_command.
DATA: lo_grid TYPE REF TO cl_gui_alv_grid,
lo_full_adap TYPE REF TO cl_salv_fullscreen_adapter.
DATA: ls_layout TYPE lvc_s_layo.
CASE e_salv_function.
*
Make ALV as Editable ALV
WHEN 'MYFUNCTION'.
*
Contorller
CALL METHOD lo_report->o_salv_model->grabe_controller.
*
Adapter
CALL METHOD lo_report->o_salv_model->grabe_adapter.
*
Fullscreen Adapter (Down Casting)
lo_full_adap ?= lo_report->o_salv_model->o_adapter.
*
Get the Grid
lo_grid = lo_full_adap->get_grid( ).
*
Got the Grid .. ?
IF lo_grid IS BOUND.
*
Editable ALV
ls_layout-edit = 'X'.
*
Set the front layout of ALV
CALL METHOD lo_grid->set_frontend_layout
EXPORTING
is_layout = ls_layout.
*
refresh the table
CALL METHOD lo_grid->refresh_table_display.
ENDIF.
ENDCASE.
ENDMETHOD.
"on_user_command
ENDCLASS.
"lcl_event_handler IMPLEMENTATION
*
SALV model uses the class CL_SALV_FORM_DYDOS to generate the TOP-OFPAGE header from the SALV Form object (CL_SALV_FORM). CL_SALV_FORM is
used to generate the Header in the SALV model.
When SALV model creates an object for the CL_SALV_FORM_DYDOS, it doesnt
pass the Wallpaper picture. Thus, we are not able to get the header background
wallpaper in the SALV model.
To get the wallpaper in the header, we can use the same solution which we have
used to make Editable ALV.
ALV header without wallpaper using the SALV model:
Set the background wallpaper by accessing the GRID and TOP-of-LIST object
*
*
*
*
EXPORTING
ir_salv_fullscreen_adapter = lo_full_adap
IMPORTING
er_form_tol
= lo_form_tol.
Got the Top Of List object.. ?
IF lo_form_tol IS BOUND.
get the object using the Wide Casting
lo_dydos ?= lo_form_tol.
set the wallpaper
lo_dydos->set_wallpaper( 'ALV_BACKGROUND' ).
refresh the table
CALL METHOD lo_grid->refresh_table_display.
ENDIF.
ENDIF.