How to Show the ALV Output and the Selection Screen on the same Screen? Typically the ALV yield is shown in another screen. Not on a similar screen where you have the choice boundaries and select choices. In any case, at times client need to see what they input in the screen and what they get yield in the ALV in a similar screen. It simply assists them with performing better, report better and break down better. This prerequisite and situation isn’t new. We have answer for it from in those days in 2008.
On the off chance that the arrangement is as of now there, why again another article?
🙂 The previous arrangement gave utilizes SALV class “CL_SALV_TABLE”. We will utilize “CL_GUI_ALV_GRID” class because of its upgraded highlights.
Expectations (How to Show the ALV Output and the Selection Screen on the same Screen)
- Choice Screen and ALV on A similar Screen.
- Add a Button on the ALV Toolbar.
- Handle Client Order.
For additional data on the use and working of the class CL_GUI_ALV_GRID, you can allude to the demo programs gave by SAP the name like “BCALV_GRID* “.
Output (How to Show the ALV Output and the Selection Screen on the same Screen)
Below is the Final Output which the Client is Expecting.
Let’s Design
High Level Programming Paradigm:
All in all, Pseudo Code for this necessity.
- Docking Holder should be made in the Introduction occasion.
- ALV should be made on that Docking Holder.
- Trade the Chose Result Table Information to ABAP Memory (this part we could do without. Yet, till we track down an improved arrangement, we should utilize it).
- Import information from ABAP Memory and Produce the Result.
Global Data Declarations
CLASS lcl_report DEFINITION DEFERRED.
DATA: lo_report TYPE REF TO lcl_report. "Reference object of the local class
DATA: alv_container TYPE REF TO cl_gui_docking_container, "ALV Container
alv_grid TYPE REF TO cl_gui_alv_grid, "ALV Grid
layout TYPE lvc_s_layo. "Layout Options
DATA gv_carrid TYPE sflight-carrid. "Variable for Select-options declaration.
Selection Screen Declarations
SELECTION-SCREEN: BEGIN OF BLOCK block_1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_carrid FOR gv_carrid.
SELECTION-SCREEN: END OF BLOCK block_1.
Local Class Definition
CLASS lcl_report DEFINITION .
PUBLIC SECTION.
DATA: gt_data TYPE STANDARD TABLE OF sflight.
METHODS :
get_data,
generate_output,
toolbar FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object, "To add some buttons on the ALV toolbar
user_command FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS.
Local Class Implementation
- Method: GET_DATA
CLASS lcl_report IMPLEMENTATION.
"Method Get Data
METHOD get_data.
* data selection
SELECT * FROM sflight
INTO TABLE me->gt_data
WHERE carrid IN s_carrid.
IF sy-dbcnt IS INITIAL.
MESSAGE s398(00) WITH 'No data selected'.
ENDIF.
*
* Export to memory
EXPORT data = me->gt_data TO MEMORY ID sy-cprog.
ENDMETHOD.
- Method: GENERATE_OUTPUT
"Method generate_output
METHOD generate_output.
* Local data
DATA: variant TYPE disvariant.
DATA: repid TYPE sy-repid.
* Import output table from the memory and free afterwards
IMPORT data = me->gt_data FROM MEMORY ID sy-cprog.
FREE MEMORY ID sy-cprog.
*
* Only if there is some data
CHECK me->gt_data IS NOT INITIAL.
repid = sy-repid.
variant-report = sy-repid.
variant-username = sy-uname.
layout-zebra = 'X'.
CHECK alv_container IS INITIAL.
CREATE OBJECT alv_container
EXPORTING
repid = repid
dynnr = sy-dynnr
side = alv_container->dock_at_bottom
extension = 200.
CREATE OBJECT alv_grid
EXPORTING
i_parent = alv_container.
* ALV Specific. Data selection.
SET HANDLER : lo_report->toolbar FOR alv_grid.
SET HANDLER : lo_report->user_command FOR alv_grid.
CALL METHOD alv_grid->set_table_for_first_display
EXPORTING
is_layout = layout
is_variant = variant
i_save = 'U'
i_structure_name = 'SFLIGHT'
CHANGING
it_outtab = me->gt_data.
ENDMETHOD.
- Method: TOOLBAR
In this technique, we will make one Press Button (similarly as an illustration no usefulness) for instance to save a record, on the off chance that we had made this ALV as editable.
"Method Tool-bar
METHOD toolbar.
DATA: lv_toolbar TYPE stb_button.
* Push Button "For Example SAVE
CLEAR lv_toolbar.
MOVE 'FC_SAVE' TO lv_toolbar-function. "Function Code
lv_toolbar-icon = icon_system_save. "Save Icon
MOVE 'Save'(100) TO lv_toolbar-text. "Push button Text
MOVE 'Save'(100) TO lv_toolbar-quickinfo. "Push button Quick-Info
MOVE space TO lv_toolbar-disabled. "Push button enabled
APPEND lv_toolbar TO e_object->mt_toolbar.
ENDMETHOD.
- Method: USER_COMMAND
This strategy will be utilized to deal with every one of the orders given by the client, for instance assuming client push on the Save button we made above and so on. I have kept this segment as clear, you can add the rationale as required.
"Method User_command
METHOD user_command.
IF e_ucomm = ' '.
ENDIF.
ENDMETHOD. "USER_COMMAND
ENDCLASS. "lcl_report IMPLEMENTATION
In the event that you set the break-point at above strategy and press the Save button on the ALV, the execution will stop. Kindly check the underneath screen capture:
Finally, the Events of the program execution
INITIALIZATION.
* object for the report
CREATE OBJECT lo_report.
* generate output
lo_report->generate_output( ).
START-OF-SELECTION.
* Get data
lo_report->get_data( ).
Conclusion
In this blog entry we took in the nuts and bolts of making an ALV on the determination screen with the utilization of CL_GUI_ALV_GRID class.
On the off chance that you simply duplicate the above code scraps and glue it to your SE38 supervisor and actuate it. Very much like one of our sluggish editors. You will find the result like underneath. Indeed!! It is a functioning code. What’s more, you don’t have to configuration any screen components.
For what reason did we have to utilize ABAP Memory when all information is there in the program and we are showing them in a similar program?
At the point when the program control arrives at Introduction occasion, all memory is Invigorated and worldwide information is made FREE. After all everything ought to be instated in the Introduction occasion. That is the occupation of Introduction occasion. Thusly, we must have the ALV information some place to pull it back when we are in Instatement occasion. Presently you know why we had to take help of the ABAP Memory. 😛
YOU MAY BE INTERESTED IN
Call instance method from workflow using class
Using ABAP Classes in Workflow
Best Practices for SAP Cloud Platform Development: A Comprehensive Guide
Leveraging SAP HANA for Advanced Analytics
SAP ABAP Training Institute in Pune, SAP ABAP Courses Online