Quantcast
Channel: SCN : Document List - ABAP Development
Viewing all articles
Browse latest Browse all 935

Creating a Split screen Output of Grids

$
0
0

Just thought of putting up a OOPs way of doing a Document to show the basic 'Split screen Grid Output' designing. This can be useful when users want to compare multiple data set results in a Single screen Output. For basic start up I have considered the 3 table consisting of Business Partners General Data(BUT000), Addresses (Business Address Services) table (ADRC) and an unrelated table NRIV (Number Range Intervals).

 

I had to choose due to lack of data in Development system although it has to direct relevance to the other two tables. Although you can choose any 3 Tables of your choice.

 

So the idea is to get a display something similar to the below screen capture.

 

 

So the basic steps to get started would be to get to know the Classes Used. The above can be achieved by simple operations using the classes

 

  • CL_GUI_ALV_GRID
  • CL_GUI_CUSTOM_CONTAINER

 

So the prerequisites would be to know how to get a Split Screen Display. This takes us back to the Transaction SE51 (Screen Painter). We can design a basic screen say 101 attached to our program. The screen has Custom control Areas that would decide how the split looks like

 

 

 

I have designed 3 areas in screen 101 with names as below to make 3 sub areas in the single screen.

 

  • CC_RESULT1
  • CC_RESULT2
  • CC_RESULT3

 

Now the steps involved is to select the Data and display them in the 3 Subareas. For this I did a very basic selection to get my data internal tables populated. You can put in your logic to arrive at the result set that will be displayed in these areas. my basic queries are:

 

SELECT * FROM but000 INTO TABLE gt_but000.
   IF sy-subrc EQ 0.
     SELECT * FROM adrc INTO TABLE gt_adrc.
     IF sy-subrc EQ 0.
       SELECT * FROM nriv INTO TABLE gt_nriv.
     ENDIF.
   ENDIF.

 

Then we get to the Grids and the Containers that will be used to display these selected data. The data declaration to be done for that is:

 


DATA: gcl_alvtab1 TYPE REF TO cl_gui_alv_grid,
          gcl_alvtab2 TYPE REF TO cl_gui_alv_grid,
          gcl_alvtab3 TYPE REF TO cl_gui_alv_grid,


         gr_con1  TYPE REF TO cl_gui_custom_container,
         gr_con2  TYPE REF TO cl_gui_custom_container,
         gr_con3  TYPE REF TO cl_gui_custom_container.

 

And a exception class to capture the exceptions.

 

DATA: gr_exception TYPE REF TO cx_root.

 

Then we create the custom containers that will hold the data grids. This can be achieved by the below code. This creates our first container instance 'gr_con1'. Repeat the same for creating  'gr_con2' and 'gr_con3'. Also do keep in mind to change the container_name  parameter in accordance to the container names given in screen 101 ( i.e. CC_RESULT1, CC_RESULT2, CC_RESULT3 )


    CREATE OBJECT gr_con1
         EXPORTING
           container_name = 'CC_RESULT1'
         EXCEPTIONS
           others         = 1.

       IF sy-subrc <> 0.
         "Give your error Message
         MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                      WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.

       ENDIF.

 

Then we proceed to create the Grids. So we will create the Grid Instances and assign them to their respective containers in the single shot. This can be achieved by the below code.

 

CREATE OBJECT gcl_alvtab1  "Grid Instance
         EXPORTING
           i_parent = gr_con1.      "Container Instance of the Grid

 


Then we repeat this to create our other two Grids gcl_alvtab2 and gcl_alvtab3. Then the next steps involved is to display the grids and set their headers. The display can be by the below method call

 

CALL METHOD gcl_alvtab1->set_table_for_first_display
         EXPORTING
           i_structure_name = 'BUT000'
         CHANGING
           it_outtab        = gt_but000.

 

Then similarly other grids are also displayed by changing the Internal tables(gt_adrc, gt_nriv) and the respective structures (ADRC, NRIV). The i_structure_name is used to determine the field catalog functionality of the ALV. Just in case you have a custom table and want your own fields catalog you can pass that via IT_FIELDCATALOG table instead of the structure name.

 

Then the last task is to give the individual Grids a title so as to make sense of what is being displayed in the grids. We can use the below code. Notice that to assign the title we have to refer to the instance (gcl_alvtab1, gcl_alvtab2, gcl_alvtab3) to give them their respective titles.


CALL METHOD gcl_alvtab1->set_gridtitle
         EXPORTING
           i_gridtitle = 'Partners'.

 

And the whole process has to be in a TRY..CATCH block to check for exceptions raised. Then call the screen to get the display.

 

END-OF-SELECTION.
   CALL SCREEN 101.

 

Oh and don't for get set a custom PF-STATUS (mine is ZALV_TEST_MENU ) & keep the usual F-Codes handling of the sy-ucomm to move back from the result screen. I had designed mine on the Modules as below:

 

MODULE user_command_0101 INPUT.
   CASE sy-ucomm.
     WHEN '&F03' OR '&F15' OR '&F12'.
       LEAVE TO SCREEN 0.
   ENDCASE.
ENDMODULE.                 " USER_COMMAND_0101  INPUT

 


MODULE status_0101 OUTPUT.
   SET PF-STATUS 'ZALV_TEST_MENU'.
ENDMODULE.                 " STATUS_0101  OUTPUT

 

That should get you started with the development. I avoided the complete code I think this explanation will help to get a idea and put together the pieces in your own report. Also add your own twist by implementing the whole set of other methods available in classes CL_GUI_ALV_GRID and CL_GUI_CUSTOM_CONTAINER.

 

Cheers,

Arindam



Viewing all articles
Browse latest Browse all 935

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>