Skip to Content
Author's profile photo Amarpreet Singh

Using the output of a Standard/Already Developed ALV report

So Recently, in one of my Objects that a member of my team was supposed to develop an ABAP Report which had to have an output that was exactly same as the one of the standard Transactions(IE05) . 

Here’s what i ended up doing:

  1. We need to call the SET method of the class CL_SALV_BS_RUNTIME_INFO as shown below :
      • cl_salv_bs_runtime_info=>set(

                             EXPORTING

                                 display  = abap_false

                                 metadata = abap_false

                                 data     = abap_true

                          ) .

      •   What this does is to tell the system that the report has to be running with no DISPLAY no METADATA on only get the ALV DATA.                   

     2. Z* report where i used the used the SUBMIT Statement so call the standard report .

                              SUBMIT riequi20 AND RETURN .

      • The AND RETURN addition ensures that the the control is returned to the calling program .
      • You can use the various other additions of the SUBMIT statement to pass on the selection screen parameters .

     3. Next use the GetDataRef method of the class CL_SALV_BS_RUNTIME_INFO to get the actual data  into a local object  type ref’ed to DATA.

                    DATA obj_data TYPE REF TO data .

                   FIELD-SYMBOL <fs_data> TYPE any .

                    TRY.

                         cl_salv_bs_runtime_info=>get_data_ref(

                          IMPORTING

                              r_data = obj_data

                             ) .

                          ASSIGN obj_data->* TO <fs_data>.

                    CATCH cx_salv_bs_sc_runtime_info.

                         Write : / data not captured.

                     ENDTRY.

      4. The data from the ALV should now be in the fs_data Field-Symbol. We can now change or do any further validations on it.

Thanks to Glen Simpsons Blog for this, it saved me lot of time .

Oputput Problems

I ran into one tiny little problem. Some of the fields like the System Status and the User Status and others did not have any values in them. This was very Weird as when i Ran the Standard report with the same selection screen parameters the values were populated.

So as mentioned in my SCN discussion.

I had the complete set of data that the Standard report outputs in my internal table and i just the ALV Class to output it to my screen.

PROBLEM:

But after checking the data (100+ fields) in the ALV report my Z program creates, I found that some of the Fields which the Standard report does have values for are not populated.

Debugging:

So, i decided to debug the Standard program so see why i didn’t get some of the fields into my output.

Turned out that the internal table that was being fed into the REUSE_ALV_GRID_DISPLAY( Location: RIEQUI20 > MIEQUI20 > MIOLXF14 line 108 of include )  FM in the Standard report also does not have the values for the same fields when the FM for ALV is called. (PFA image of the point where the FM is being called.(in case some of you want to debug it yourselves )

e.g. : the value of the table OBJECT_TAB-STTXT is Empty  when the REUSE_ALV_GRID_DISPLAY is called ,

but in the final ALV output  the fields System Status (STTXT) has the corresponding values . This was very troubling and as with all such situations it had avery simple solution.

http://f.cl.ly/items/0L3X2H2107043c3G242G/Screen%20Shot%202013-08-03%20at%202.20.54%20PM.png

Solution and Reason


What was happening was that the there was a default LAYOUT on the ALV screen that was set based on which the standard program did not fetch some of the fields that it did not have to display.

So i went into the standard Report output, click on the change layout button (Ctrl + F8 ) and create a New Default Layout with all the fields i wanted an output for .

Hope this helps some save some time.

Have a Good day.

Amarpreet.

Assigned Tags

      8 Comments
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member

      Thanks for the blog. Nicley put. Pretty similar to this though

      http://scn.sap.com/community/abap/blog/2011/07/07/gain-programmatic-access-to-data-of-sapgui-alv-reports

      Regards,

      Ravi

      Author's profile photo Amarpreet Singh
      Amarpreet Singh
      Blog Post Author

      Thanks 🙂 .

      Yes , I've mentioned glen's blog in my post specifically,

      The Reason i created this was because i wanted to document the problem i ran into .

      Author's profile photo Shruti D
      Shruti D

      Hi Amarpreet,

      I have a small query on this topic.

      If there are any changes made to standard/already existing alv report , wouldn't that affect the our program which is making use of this ??

      Regards,

      Shruti D

      Author's profile photo Amarpreet Singh
      Amarpreet Singh
      Blog Post Author

      If by changes you mean enhancements to the standard objects, then sure it would.

      But since we are only using the output i don't see how it would have a negative impact on the output that we are using.

      Either way the only alternative would be either to create a new report from scratch which would take a lot of effort or to create a z* copy to the standard report which won't be a very good idea as it includes a lot of code in the enhancement  spot which i not copied to the custom report and it would play well with any future upgrades.

      What do you think !!

      Amarpreet.

      Author's profile photo Shruti D
      Shruti D

      Yes, by changes, I mean modification in the output of the standard/already existing ALV report. As you explained the issue you had encountered related to LAYOUT and the solution you implemented for that, then it is a definitely a concern for developer to go with the standard report alv. However my query is answered.

      And whether to copy the standard code or to develop it from scratch or to make use of standard output using SUBMIT and RETURN depends on the volume of the development and left to developer.

      Thank you.

      Shruti

      Author's profile photo Nic Teunckens
      Nic Teunckens

      Thanks for figuring out / posting the issue when callling reports RIEQUI20, as I expercienced just now the missing Output as well ... This is a great timesaver for me.

      Greetings

      Nic

      Author's profile photo Carlos Vivo
      Carlos Vivo

      Nevertheless, if you'd like to get the data directly as it's defined by the layout, you should use metadata and convert the table based on fieldcat and dynamic table generation:

      DATA: lt_html  TYPE STANDARD TABLE OF w3html,
            list_tab TYPE TABLE OF abaplist.
      DATA: receivers  TYPE somlreci1.
      DATA: entries    TYPE sodlienti1.
      DATA: gt_receivers  TYPE STANDARD TABLE OF somlreci1.
      DATA: gt_entries TYPE STANDARD TABLE OF sodlienti1,
            list_xls   TYPE truxs_t_text_data.
      DATA recipient      TYPE REF TO if_recipient_bcs.
      DATA recipient_mail TYPE adr6-smtp_addr.
      DATA ls_metadata1 TYPE cl_salv_bs_runtime_info=>s_type_metadata.
      DATA: gw_dyn_fcat  TYPE lvc_s_fcat,
            gt_dyn_fcat  TYPE lvc_t_fcat,
            gt_dyn_table TYPE REF TO data.
      
      
      INITIALIZATION.
      
        title1 = 'Source of list'.
        title2 = 'Destination'.
      
      START-OF-SELECTION.
      
        CALL FUNCTION 'LIST_FREE_MEMORY'.
      
      
      
        "=================
        " EXTRACT ALV DATA
        "=================
        TYPES ty_range_agr_name TYPE RANGE OF agr_name.
        FIELD-SYMBOLS <table> TYPE table.
        FIELD-SYMBOLS <table2> TYPE table.
        DATA(actgrps) = VALUE ty_range_agr_name( sign = 'I' option = 'CP' ( low = 'Z*' ) ).
        cl_salv_bs_runtime_info=>set( display  = abap_false metadata = abap_true data = abap_true ).
      
        SUBMIT (prog) USING SELECTION-SET variant AND RETURN.
        ls_metadata1 = cl_salv_bs_runtime_info=>get_metadata( ).
        cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = DATA(lr_data) ).
        ASSIGN lr_data->* TO <table>.
      
        DATA(gv_pos) = 0.
        LOOP AT ls_metadata1-t_fcat INTO DATA(fcat) WHERE no_out EQ space.
          ADD 1 TO gv_pos.
      
          MOVE-CORRESPONDING fcat TO gw_dyn_fcat.
          APPEND gw_dyn_fcat TO gt_dyn_fcat.
          CLEAR gw_dyn_fcat.
        ENDLOOP.
      
        cl_alv_table_create=>create_dynamic_table(
            EXPORTING
              i_style_table             = 'X'                 " Add Style Table
              it_fieldcatalog           =  gt_dyn_fcat                 " Field Catalog
            IMPORTING
              ep_table                  =  gt_dyn_table                " Pointer to Dynamic Data Table
            EXCEPTIONS
              generate_subpool_dir_full = 1                " At Most 36 Subroutine Pools Can Be Generated Temporarily
              OTHERS                    = 2
          ).
      
        ASSIGN gt_dyn_table->* TO <table2>.
        MOVE-CORRESPONDING <table> TO <table2>.
      
        "==================
        " CREATE EXCEL FILE
        "==================
        DATA(workbook) = NEW zcl_excel( ).
        DATA(worksheet) = workbook->get_active_worksheet( ).
        worksheet->bind_table( ip_table = <table2> ).
        DATA(xlsx_generator) = CAST zif_excel_writer( NEW zcl_excel_writer_2007( ) ).
        DATA(xlsx_data) = xlsx_generator->write_file( workbook ).
      Author's profile photo Carlos Vivo
      Carlos Vivo

      You need to implement the ABAP2XLSX package from abapGit webpage