Simplest ALV Code
Well, if not you, I reluctant to code for ALV. It's so much stereotype. And most of the boring job is to create the field catalog. Here is a quick and simple way to create ALV in just 3-4 lines of code :)
To achieve this we will use the class CL_ALV_TABLE. Even if you are not aware of object oriented programming, you can use these simple lines of codes to generate ALV report. I_TAB can be any table. You can declare it as normal table (either through type / like db table / or even OCCURS 0 type table).
Update : After NW ABAP 740, the code has been more simplified due to inline data declaration.
SELECT * FROM sflight INTO TABLE @DATA(isflight) UP TO 20 ROWS.
TRY.
cl_salv_table=>factory( importing r_salv_table = Data(lo_alv)
changing t_table = isflight ).
DATA(lo_functions) = lo_alv->get_functions( ).
lo_functions->set_all( abap_true ).
lo_alv->display( ).
CATCH cx_salv_msg INTO DATA(lx_msg).
DATA(l_msg) = lx_msg->get_text( ).
ENDTRY.
To achieve this we will use the class CL_ALV_TABLE. Even if you are not aware of object oriented programming, you can use these simple lines of codes to generate ALV report. I_TAB can be any table. You can declare it as normal table (either through type / like db table / or even OCCURS 0 type table).
DATA: lo_alv TYPE REF TO cl_salv_table,
lx_salv_msg TYPE REF TO cx_salv_msg,
l_msg(40) TYPE c .
TRY.
CALL METHOD cl_salv_table=>factory
* EXPORTING
* list_display = IF_SALV_C_BOOL_SAP=>FALSE
* r_container =
* container_name =
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = i_tab
.
CATCH cx_salv_msg INTO lx_salv_msg.
l_msg = lx_salv_msg->get_text( ).
MESSAGE e000(zyn1otc) WITH l_msg.
ENDTRY.
lo_alv->display( ).
lx_salv_msg TYPE REF TO cx_salv_msg,
l_msg(40) TYPE c .
TRY.
CALL METHOD cl_salv_table=>factory
* EXPORTING
* list_display = IF_SALV_C_BOOL_SAP=>FALSE
* r_container =
* container_name =
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = i_tab
.
CATCH cx_salv_msg INTO lx_salv_msg.
l_msg = lx_salv_msg->get_text( ).
MESSAGE e000(zyn1otc) WITH l_msg.
ENDTRY.
lo_alv->display( ).
Update : After NW ABAP 740, the code has been more simplified due to inline data declaration.
SELECT * FROM sflight INTO TABLE @DATA(isflight) UP TO 20 ROWS.
TRY.
cl_salv_table=>factory( importing r_salv_table = Data(lo_alv)
changing t_table = isflight ).
DATA(lo_functions) = lo_alv->get_functions( ).
lo_functions->set_all( abap_true ).
lo_alv->display( ).
CATCH cx_salv_msg INTO DATA(lx_msg).
DATA(l_msg) = lx_msg->get_text( ).
ENDTRY.
Comments
Post a Comment