2015 Jan 30 12:54 PM
Hi friends i have written the code for displaying the three distinct record in same program by giving the radio button in the selection screen.
Here in the above case i used the subroutine for calling the report, but for each and every report i am using some different logic for fetching the fields i.e. field need for output may change but tables are same. So i had used the single start of selection by defining the subroutine.
The main issue is for displaying the output to ALV , for three times i am using the same code for all three reports, only change is output Internal table name. So please help me by giving information about the alternate methods to display the output without repeating the same set of code each and every time.
Note: I had searched it before posting but failed to find because of no knowledge on the key words what exactly to search.
Thanks in advance
D vishnu vardhan.
2015 Jan 30 2:12 PM
Hi Vishnu,
Since we are using the different internal table, we can re-use the same code by storing the internal table name into variable as shown below.
"Data Declarations
Data: l_name type string.
"Assign Internal table into variable L_NAME
l_name = 'IT_FINAL'.
"Display the ALV Report
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = layout
i_default = 'X'
i_save = 'A'
it_fieldcat = it_fieldcatalog
TABLES
* t_outtab = it_final
t_outtab = (L_NAME) "Internal Table name
EXCEPTIONS
program_error = 1
OTHERS = 2.
Regards
Rajkumar Narasimman
Hi friends i have written the code for displaying the three distinct record in same program by giving the radio button in the selection screen.
Here in the above case i used the subroutine for calling the report, but for each and every report i am using some different logic for fetching the fields i.e. field need for output may change but tables are same. So i had used the single start of selection by defining the subroutine.
The main issue is for displaying the output to ALV , for three times i am using the same code for all three reports, only change is output Internal table name. So please help me by giving information about the alternate methods to display the output without repeating the same set of code each and every time.
Note: I had searched it before posting but failed to find because of no knowledge on the key words what exactly to search.
Thanks in advance
D vishnu vardhan.
2015 Jan 30 2:12 PM
Hi Vishnu,
Since we are using the different internal table, we can re-use the same code by storing the internal table name into variable as shown below.
"Data Declarations
Data: l_name type string.
"Assign Internal table into variable L_NAME
l_name = 'IT_FINAL'.
"Display the ALV Report
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
i_callback_program = sy-repid
is_layout = layout
i_default = 'X'
i_save = 'A'
it_fieldcat = it_fieldcatalog
TABLES
* t_outtab = it_final
t_outtab = (L_NAME) "Internal Table name
EXCEPTIONS
program_error = 1
OTHERS = 2.
Regards
Rajkumar Narasimman
2015 Jan 30 2:17 PM
Can we use this for cl_salv_table.
can you please give me an example to understan better.
2015 Jan 30 2:59 PM
If the type of your tables is identical, something similar might work for you.
TYPES: BEGIN OF ty_table,
number TYPE i,
END OF ty_table,
tyt_table TYPE TABLE OF ty_table.
DATA: lt_table1 TYPE tyt_table,
lt_table2 TYPE tyt_table.
FIELD-SYMBOLS: <ls_line> TYPE ty_table.
DATA: lo_structdescr TYPE REF TO cl_abap_structdescr.
DATA: lt_components TYPE cl_abap_structdescr=>component_table.
DATA: lo_table_line TYPE REF TO cl_abap_structdescr.
DATA: lo_tabledescr TYPE REF TO cl_abap_tabledescr.
DATA: lo_table TYPE REF TO data.
FIELD-SYMBOLS: <lt_talbe> TYPE STANDARD TABLE.
DATA: lo_alv TYPE REF TO cl_salv_table.
PARAMETERS: p_tab1 TYPE boole_d RADIOBUTTON GROUP rad1,
p_tab2 TYPE boole_d RADIOBUTTON GROUP rad1.
* Filling tables
* Table 1
APPEND INITIAL LINE TO lt_table1 ASSIGNING <ls_line>.
<ls_line>-number = 1.
APPEND INITIAL LINE TO lt_table1 ASSIGNING <ls_line>.
<ls_line>-number = 2.
* Table 2
APPEND INITIAL LINE TO lt_table2 ASSIGNING <ls_line>.
<ls_line>-number = 3.
APPEND INITIAL LINE TO lt_table2 ASSIGNING <ls_line>.
<ls_line>-number = 4.
lo_structdescr ?= cl_abap_typedescr=>describe_by_name( 'TY_TABLE' ).
lt_components = lo_structdescr->get_components( ).
lo_tabledescr = cl_abap_tabledescr=>create( EXPORTING p_line_type = lo_structdescr
p_table_kind = cl_abap_tabledescr=>tablekind_std ).
CREATE DATA lo_table TYPE HANDLE lo_tabledescr.
ASSIGN lo_table->* TO <lt_talbe>.
IF p_tab1 EQ 'X'.
<lt_talbe> = lt_table1.
ELSE.
<lt_talbe> = lt_table2.
ENDIF.
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lo_alv
CHANGING
t_table = <lt_talbe>.
lo_alv->display( ).
2015 Jan 30 3:36 PM
Hi Vishnu,
I hope the same dynamic variable concept which we used before won't work in class cl_salv_table. In order to reuse the code for all the ALV, it is required to create the dynamic internal table.
Create the dynamic internal table using RTTS method, please find the link below.
Regards,
Rajkumar Narasimman
2015 Jan 30 3:52 PM
Hi,
Try to employ sorting and summing using cl_salv_table own methods.
Have a look at program SALV_DEMO_METADATA .
See form set_sort, form set_aggregations.
regards.
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |