Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to minimize the code for the displaying three reports with same fields and different sort and aggregate option.

Former Member
0 Likes
1,114

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.

1 ACCEPTED SOLUTION
Read only

rajkumarnarasimman
Active Contributor
0 Likes
1,048

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.

5 REPLIES 5
Read only

rajkumarnarasimman
Active Contributor
0 Likes
1,049

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

Read only

0 Likes
1,048

Can we use this for cl_salv_table.

can you please give me an example to understan better.

Read only

0 Likes
1,048

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( ).

Read only

0 Likes
1,048

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

Read only

rosenberg_eitan
Active Contributor
0 Likes
1,048

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.