
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.
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.
Step 3. In this step am implementing the build_salesorder method.
Step 4. Implementing disp_salesorder method to display the data in SALV.
Call factory method to display the data.
Step 5. Top_of_page method takes some variable with a different class; we can see the classes.
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.
Step 9. create a object for main class, using object call the methods and display the records in SALV.
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:
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
11 | |
8 | |
6 | |
5 | |
5 | |
4 | |
4 | |
3 | |
2 | |
2 |