View previous topic :: View next topic
Author
Message
admin Администратор Joined: 01 Sep 2007 Posts: 1640
Posted: Wed Oct 24, 2007 5:22 pm Post subject: Common macros for the ALV Object Model(SALV) Applications
Common macros for the ALV Object Model(SALV) Applications
Author: Ravi Shankar Rajan
INCLUDE FOR ALV MACROS
Code:
DATA :
gv_exception TYPE string,
ob_cx_salv_msg TYPE REF TO cx_salv_msg,
ob_cx_salv_not_found TYPE REF TO cx_salv_not_found,
ob_cx_salv_existing TYPE REF TO cx_salv_existing,
ob_cx_salv_data_error TYPE REF TO cx_salv_data_error.
DEFINE _attach_alv_to_container.
try.
cl_salv_table=>factory(
exporting
r_container = &1
container_name = &2
importing
r_salv_table = &3
changing
t_table = &4 ).
catch cx_salv_msg into ob_cx_salv_msg .
call method ob_cx_salv_msg->if_message~get_text
receiving
result = gv_exception.
message i000(0k) with gv_exception.
endtry.
END-OF-DEFINITION.
DEFINE _set_title.
&1 = &2.
if &3 is initial.
&3 = &4->get_display_settings( ).
endif.
&3->set_list_header( &1 ).
*Set the striped pattern
call method &3->set_striped_pattern
exporting
value = &5.
END-OF-DEFINITION.
DEFINE _set_sort.
*Fill the sort table
if &1 is initial.
&1 = &2->get_sorts( ).
endif.
try.
call method &1->add_sort
exporting
columnname = &3
position = &4
sequence = &5
subtotal = &6
group = &7
obligatory = &8
receiving
value = &9.
if &9 is initial.
message i000(0k) with 'No Sort result found'(153).
endif.
catch cx_salv_not_found into ob_cx_salv_not_found.
call method ob_cx_salv_not_found->if_message~get_text
receiving
result = gv_exception.
message i000(0k) with gv_exception.
catch cx_salv_existing into ob_cx_salv_existing.
call method ob_cx_salv_existing->if_message~get_text
receiving
result = gv_exception.
message i000(0k) with gv_exception.
catch cx_salv_data_error into ob_cx_salv_data_error.
call method ob_cx_salv_data_error->if_message~get_text
receiving
result = gv_exception.
message i000(0k) with gv_exception.
endtry.
END-OF-DEFINITION.
DEFINE _set_aggregations.
if &1 is initial.
&1 = &2->get_aggregations( ).
endif.
try.
call method &1->add_aggregation
exporting
columnname = &3
aggregation = &4
receiving
value = &5.
if &5 is initial.
message i000(0k) with 'No Aggregate result found'(152).
endif.
catch cx_salv_data_error into ob_cx_salv_data_error.
call method ob_cx_salv_data_error->if_message~get_text
receiving
result = gv_exception.
message i000(0k) with gv_exception.
catch cx_salv_not_found into ob_cx_salv_not_found.
call method ob_cx_salv_not_found->if_message~get_text
receiving
result = gv_exception.
message i000(0k) with gv_exception.
catch cx_salv_existing into ob_cx_salv_existing.
call method ob_cx_salv_existing->if_message~get_text
receiving
result = gv_exception.
message i000(0k) with gv_exception.
endtry.
END-OF-DEFINITION.
DEFINE _set_fieldcatalog.
if &1 is initial.
&1 = &2->get_columns( ).
&1->set_optimize( 'X' ).
endif.
try.
&3 ?= &1->get_column( &4 ).
&3->set_long_text( &5 ).
&3->set_short_text( &6 ).
&3->set_medium_text( &9 ).
&3->set_visible( &7 ).
catch cx_salv_not_found into ob_cx_salv_not_found.
call method ob_cx_salv_not_found->if_message~get_text
receiving
result = gv_exception.
message i000(0k) with gv_exception.
endtry.
call method &1->set_column_position
exporting
columnname = &4
position = &8.
END-OF-DEFINITION.
DEFINE _set_functions.
*... set the functions
if &1 is initial.
&1 = &2->get_functions( ).
&1->set_all( &3 ).
endif.
END-OF-DEFINITION.
Sample Usage
Code: report ztest.
*Replace the place holders of the
*macros with your own values
*Macro to attach ALV to container
_attach_alv_to_container &1 &2 &3 &4.
*Macro for setting fieldcatalog
_set_fieldcatalog &1 &2 &3 &4 &5 &6 &7 &8 &9.
*Macro for Sorting
_set_sort &1 &2 &3 &4 &5 &6 &7 &8 &9.
*Macro for aggregations
_set_aggregations &1 &2 &3 &4 &5.
*Macro to setting ALV functions.
_set_functions &1 &2 &3.
*Macro for setting ALV Title.
_set_title &1 &2 &3 &4 &5.
https://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/wlg/6062
Back to top
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.