Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
jyothi7
Newcomer
0 Kudos

Top of page and end of page using SALV 

I am happy to share my very first blog post on SAP OABAP Programming using SALV. In this blog post you will learn how to Create a Top of page and end of page using SALV. 

Introduction: -

In SAP, the System Application and Products, 'SALV' stands for SAP List Viewer. It's a framework used to simplify the display of data in a user-friendly format within SAP applications. 

  • Timesaving: Implementing SALV can save developers time as it provides pre-defined functionalities for handling data. Developers can focus on business logic rather than building data display functionalities from scratch. 
  • Standardization: SALV follows SAP's standard programming guidelines, promoting uniformity in coding practices across applications, making maintenance and updates more manageable. 

Before writing code, we need to know what and all classes we need to use. 

Class names: CL_SALV_TABLE, 

                      CL_SALV_FORM_LAYOUT_GRID, 

                      CL_SALV_FORM_LABEL, 

                      CL_SALV_FORM_LAYOUT_FLOW. 

How to create a program to display the top of page and end of page using SALV 

Step 1. Go to ABAP editor transaction (SE38) provide a program name and type of the program. 

Step 2. Declare class and methods. 

jyothi7_0-1706942170399.png

Step 3. In this step am implementing the build_salesorder method. 

jyothi7_1-1706942170400.png

Step 4. Implementing disp_salesorder method to display the data in SALV. 

           Call factory method to display the data. 

jyothi7_2-1706942170401.png

Step 5. Top_of_page method takes some variable with a different class; we can see the classes.  

jyothi7_3-1706942170402.png

jyothi7_4-1706942170403.png

Step 6. End_of_page method also declare some classes whatever we did in top of page we need to do in end of page Method also. 

jyothi7_5-1706942170404.png

jyothi7_6-1706942170405.png

Step 9. create a object for main class, using object call the methods and display the records in SALV. 

jyothi7_7-1706942170405.png

Refer the code below for the whole program. 

 

 

 

 

 

CLASS sales_order_disp DEFINITION. 
   PUBLIC SECTION. 
    DATA : o_salv TYPE REF TO cl_salv_table. 
    METHODS : build_salesorder, 
              disp_salesorder. 
  PRIVATE SECTION. 
    DATA : lt_vbak TYPE TABLE OF vbak. 
     METHODS : build_top_of_page CHANGING obj_salv TYPE REF TO 
               cl_salv_table, 
               build_end_of_page CHANGING obj_salv TYPE REF TO 
               cl_salv_table. 
ENDCLASS. 
 
CLASS sales_order_disp IMPLEMENTATION. 
    METHOD build_salesorder. 
     SELECT * FROM vbak INTO TABLE lt_vbak . 
    ENDMETHOD. 
    METHOD disp_salesorder. 
 "========THIS METHOD FOR TO DISPLAYING  SALV DISPLAY 
     TRY. 
         cl_salv_table=>factory( 
           IMPORTING 
             r_salv_table   =      o_salv  " Basis Class Simple ALV Tables 
           CHANGING 
             t_table        = lt_vbak 
         ). 
       CATCH cx_salv_msg. " ALV: General Error Class with Message 
     ENDTRY. 
"USING ME KEYWORD CALLING TOP OF PAGE  METHOD THIS IS IN PRIVATE SECTION" 
     me->build_top_of_page( 
       CHANGING 
         obj_salv = o_salv 
     ). 
"USING ME KEYWORD CALLING END OF PAGE  METHOD THIS IS IN PRIVATE SECTION"
     me->build_end_of_page( 
       CHANGING 
         obj_salv = o_salv 
     ). 
"=============TO DISPLAY=============== 
     o_salv->display( ). 
   ENDMETHOD. 
 
"============TO DISPLAY THE TOP LINES=============== 
   METHOD build_top_of_page. 
     DATA: o_label TYPE REF TO cl_salv_form_label, 
           o_flow  TYPE REF TO cl_salv_form_layout_flow.
 
"======creating object for CL_SALV_FORM_LAYOUT_GRID=============== 
     DATA(o_layout) = NEW cl_salv_form_layout_grid( ). 
 
"====using layout objcet am calling isntance method name as CREATE_LABEL 
     o_layout->create_label( 
       EXPORTING 
         row         =   1               " Natural Number 
         column      =   1               " Natural Number 
       RECEIVING 
         r_value     =   o_label               " Label 
     ). 
"=========CL_SALV_FROM_LABEL using this class refernce am calling the 
 SET_TEXT method to write something in top========" 

     o_label->set_text( value = 'Sales order details' ). 
    o_layout->create_flow( 
       EXPORTING 
         row     =    2              " Natural Number 
         column  =     1             " Natural Number 
       RECEIVING 
         r_value = o_flow 
     ). 
"==========cl_salv_form_layout_flow using this class we can add one more row and we can write a information of Top ========="
     o_flow->create_text( 
       EXPORTING 
         text     =  sy-uname 
     ). 
   obj_salv->set_top_of_list( value = o_layout ). 
    o_layout->create_flow( 
       EXPORTING 
         row     =    3             " Natural Number 
         column  =     1             " Natural Number 
       RECEIVING 
         r_value = o_flow 
     ). 
     o_flow->create_text( 
       EXPORTING 
         text     = sy-datum 
     ). 
     obj_salv->set_top_of_list( value = o_layout ). 
   ENDMETHOD. 

  METHOD build_end_of_page. 
     DATA: o_label TYPE REF TO cl_salv_form_label, 
           o_flow  TYPE REF TO cl_salv_form_layout_flow. 
     DATA(o_end) = NEW cl_salv_form_layout_grid( ). 
 
    o_end->create_label( 
       EXPORTING 
         row         =    1              " Natural Number 
         column      =     1             " Natural Number 
       RECEIVING 
         r_value     =     o_label             " Label 
     ). 
 
    o_label->set_text( value =  'SAP Labs India'). 
 
    o_end->create_flow( 
       EXPORTING 
         row     =    2              " Natural Number 
         column  =     1             " Natural Number 
       RECEIVING 
         r_value = o_flow 
     ). 
 
    o_flow->create_text( 
       EXPORTING 
         text     = 'End of page' 
        ). 
 
    obj_salv->set_end_of_list( value =  o_end ). 
  ENDMETHOD. 
ENDCLASS. 
 
START-OF-SELECTION. 
"creating the object for SALES_ORDER_DISP class and calling the method 

 DATA(o_sales) =  NEW sales_order_disp( ). 
  o_sales->build_salesorder( ). 
  o_sales->disp_salesorder( ). 

 

 

 

 

 

 

OUTPUT: 

jyothi7_8-1706942170408.png

 

 

 

 

Labels in this area