Case 1. Go to SE38 and create a report program. Provide below code. Execute it.
_____________________________________________________________________________
REPORT zsalv_table_diaplay.
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.
ENDCLASS.
CLASS sales_order_disp IMPLEMENTATION.
METHOD build_salesorder.
SELECT * FROM vbak INTO TABLE lt_vbak UP TO 50 ROWS.
ENDMETHOD.
METHOD disp_salesorder.
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.
endtry.
o_salv->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: o_salesord TYPE REF TO sales_order_disp.
CREATE OBJECT o_salesord.
o_salesord->build_salesorder( ).
o_salesord->disp_salesorder( ).
_______________________________________________________________________________
O/P: The report output is as follows:
_______________________________________________________________________________
Case 2: Making Hot Spot on for a particular column(VBELN: Sales Document)
REPORT zsalv_table_diaplay.
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.
ENDCLASS.
CLASS sales_order_disp IMPLEMENTATION.
METHOD build_salesorder.
SELECT * FROM vbak INTO TABLE lt_vbak UP TO 50 ROWS.
ENDMETHOD.
METHOD disp_salesorder.
DATA : o_cols TYPE REF TO cl_salv_columns_table,
o_col TYPE REF TO cl_salv_column_table.
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.
ENDTRY.
**********START OF HOT SPOT ON ***************
o_cols = o_salv->get_columns( ).
TRY.
o_col ?= o_cols->get_column( 'VBELN' ). " sales reder number
CATCH cx_salv_not_found.
ENDTRY.
o_col->set_cell_type( if_salv_c_cell_type=>hotspot ).
* o_col->set_cell_type( value = 5 ).
**********END OF HOT SPOT ON ****************
o_salv->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: o_salesord TYPE REF TO sales_order_disp.
CREATE OBJECT o_salesord.
o_salesord->build_salesorder( ).
o_salesord->disp_salesorder( ).
______________________________________________________________________________
O/P: The report output is as follows:
______________________________________________________________________________
Case 3: Hiding a particular column (ERZET: Entry time)
REPORT zsalv_table_diaplay.
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.
ENDCLASS.
CLASS sales_order_disp IMPLEMENTATION.
METHOD build_salesorder.
SELECT * FROM vbak INTO TABLE lt_vbak UP TO 50 ROWS.
ENDMETHOD.
METHOD disp_salesorder.
DATA : o_cols TYPE REF TO cl_salv_columns_table,
o_col TYPE REF TO cl_salv_column_table.
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.
ENDTRY.
**********START OF HOT SPOT ON ***************
o_cols = o_salv->get_columns( ).
TRY.
o_col ?= o_cols->get_column( 'VBELN' ). " sales reder number
CATCH cx_salv_not_found.
ENDTRY.
o_col->set_cell_type( if_salv_c_cell_type=>hotspot ).
* o_col->set_cell_type( value = 5 ).
**********END OF HOT SPOT ON ****************
**********START OF HIDING A COLUMN ***************
TRY.
o_col ?= o_cols->get_column( 'ERZET' ). " Entry time
CATCH cx_salv_not_found.
ENDTRY.
o_col->set_visible( value = if_salv_c_bool_sap=>false ).
**********END OF HIDING A COLUMN ****************
o_salv->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: o_salesord TYPE REF TO sales_order_disp.
CREATE OBJECT o_salesord.
o_salesord->build_salesorder( ).
o_salesord->disp_salesorder( ).
___________________________________________________________________________
O/P: The report output is as follows:
______________________________________________________________________________
Case 4: Adding top-of-page and end-of-page
REPORT zsalv_table_diaplay.
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 UP TO 10 ROWS.
ENDMETHOD.
METHOD disp_salesorder.
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.
ENDTRY.
me->build_top_of_page(
CHANGING
obj_salv = o_salv ).
me->build_end_of_page(
CHANGING
obj_salv = o_salv ).
o_salv->display( ).
ENDMETHOD.
METHOD build_top_of_page.
DATA : o_top TYPE REF TO cl_salv_form_layout_grid,
o_label TYPE REF TO cl_salv_form_label,
o_flow TYPE REF TO cl_salv_form_layout_flow.
CREATE OBJECT o_top.
o_top->create_label(
EXPORTING
row = 1 " Natural Number
column = 1 " Natural Number
RECEIVING
r_value = o_label ).
o_label->set_text( value = 'Sales Order Details' ).
o_top->create_flow(
EXPORTING
row = 2 " Natural Number
column = 1 " Natural Number
RECEIVING
r_value = o_flow ).
o_flow->create_text(
EXPORTING
text = 'For the Month of Dec-2013' ).
obj_salv->set_top_of_list( value = o_top ).
ENDMETHOD.
METHOD build_end_of_page.
DATA : o_end TYPE REF TO cl_salv_form_layout_grid,
o_label TYPE REF TO cl_salv_form_label,
o_flow TYPE REF TO cl_salv_form_layout_flow.
CREATE OBJECT o_end.
o_end->create_label(
EXPORTING
row = 1 " Natural Number
column = 1 " Natural Number
RECEIVING
r_value = o_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 = 'All rights reserved.' ).
obj_salv->set_end_of_list( value = o_end ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: o_salesord TYPE REF TO sales_order_disp.
CREATE OBJECT o_salesord.
o_salesord->build_salesorder( ).
o_salesord->disp_salesorder( ).
_______________________________________________________________________________
O/P: The report output is as follows:
REPORT zsalv_table_diaplay.
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.
ENDCLASS.
CLASS sales_order_disp IMPLEMENTATION.
METHOD build_salesorder.
SELECT * FROM vbak INTO TABLE lt_vbak UP TO 50 ROWS.
ENDMETHOD.
METHOD disp_salesorder.
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.
endtry.
o_salv->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: o_salesord TYPE REF TO sales_order_disp.
CREATE OBJECT o_salesord.
o_salesord->build_salesorder( ).
o_salesord->disp_salesorder( ).
_______________________________________________________________________________
O/P: The report output is as follows:
_______________________________________________________________________________
Case 2: Making Hot Spot on for a particular column(VBELN: Sales Document)
REPORT zsalv_table_diaplay.
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.
ENDCLASS.
CLASS sales_order_disp IMPLEMENTATION.
METHOD build_salesorder.
SELECT * FROM vbak INTO TABLE lt_vbak UP TO 50 ROWS.
ENDMETHOD.
METHOD disp_salesorder.
DATA : o_cols TYPE REF TO cl_salv_columns_table,
o_col TYPE REF TO cl_salv_column_table.
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.
ENDTRY.
**********START OF HOT SPOT ON ***************
o_cols = o_salv->get_columns( ).
TRY.
o_col ?= o_cols->get_column( 'VBELN' ). " sales reder number
CATCH cx_salv_not_found.
ENDTRY.
o_col->set_cell_type( if_salv_c_cell_type=>hotspot ).
* o_col->set_cell_type( value = 5 ).
**********END OF HOT SPOT ON ****************
o_salv->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: o_salesord TYPE REF TO sales_order_disp.
CREATE OBJECT o_salesord.
o_salesord->build_salesorder( ).
o_salesord->disp_salesorder( ).
______________________________________________________________________________
O/P: The report output is as follows:
______________________________________________________________________________
Case 3: Hiding a particular column (ERZET: Entry time)
REPORT zsalv_table_diaplay.
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.
ENDCLASS.
CLASS sales_order_disp IMPLEMENTATION.
METHOD build_salesorder.
SELECT * FROM vbak INTO TABLE lt_vbak UP TO 50 ROWS.
ENDMETHOD.
METHOD disp_salesorder.
DATA : o_cols TYPE REF TO cl_salv_columns_table,
o_col TYPE REF TO cl_salv_column_table.
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.
ENDTRY.
**********START OF HOT SPOT ON ***************
o_cols = o_salv->get_columns( ).
TRY.
o_col ?= o_cols->get_column( 'VBELN' ). " sales reder number
CATCH cx_salv_not_found.
ENDTRY.
o_col->set_cell_type( if_salv_c_cell_type=>hotspot ).
* o_col->set_cell_type( value = 5 ).
**********END OF HOT SPOT ON ****************
**********START OF HIDING A COLUMN ***************
TRY.
o_col ?= o_cols->get_column( 'ERZET' ). " Entry time
CATCH cx_salv_not_found.
ENDTRY.
o_col->set_visible( value = if_salv_c_bool_sap=>false ).
**********END OF HIDING A COLUMN ****************
o_salv->display( ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: o_salesord TYPE REF TO sales_order_disp.
CREATE OBJECT o_salesord.
o_salesord->build_salesorder( ).
o_salesord->disp_salesorder( ).
___________________________________________________________________________
O/P: The report output is as follows:
______________________________________________________________________________
Case 4: Adding top-of-page and end-of-page
REPORT zsalv_table_diaplay.
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 UP TO 10 ROWS.
ENDMETHOD.
METHOD disp_salesorder.
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.
ENDTRY.
me->build_top_of_page(
CHANGING
obj_salv = o_salv ).
me->build_end_of_page(
CHANGING
obj_salv = o_salv ).
o_salv->display( ).
ENDMETHOD.
METHOD build_top_of_page.
DATA : o_top TYPE REF TO cl_salv_form_layout_grid,
o_label TYPE REF TO cl_salv_form_label,
o_flow TYPE REF TO cl_salv_form_layout_flow.
CREATE OBJECT o_top.
o_top->create_label(
EXPORTING
row = 1 " Natural Number
column = 1 " Natural Number
RECEIVING
r_value = o_label ).
o_label->set_text( value = 'Sales Order Details' ).
o_top->create_flow(
EXPORTING
row = 2 " Natural Number
column = 1 " Natural Number
RECEIVING
r_value = o_flow ).
o_flow->create_text(
EXPORTING
text = 'For the Month of Dec-2013' ).
obj_salv->set_top_of_list( value = o_top ).
ENDMETHOD.
METHOD build_end_of_page.
DATA : o_end TYPE REF TO cl_salv_form_layout_grid,
o_label TYPE REF TO cl_salv_form_label,
o_flow TYPE REF TO cl_salv_form_layout_flow.
CREATE OBJECT o_end.
o_end->create_label(
EXPORTING
row = 1 " Natural Number
column = 1 " Natural Number
RECEIVING
r_value = o_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 = 'All rights reserved.' ).
obj_salv->set_end_of_list( value = o_end ).
ENDMETHOD.
ENDCLASS.
START-OF-SELECTION.
DATA: o_salesord TYPE REF TO sales_order_disp.
CREATE OBJECT o_salesord.
o_salesord->build_salesorder( ).
o_salesord->disp_salesorder( ).
_______________________________________________________________________________
O/P: The report output is as follows:
No comments:
Post a Comment