Application Development 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: 

How to retrieve ALV output into an internal table?

teja8099151
Discoverer
0 Kudos
3,485

We are trying to develop a report in that we designed selection screen for program name, variant, email recipient.

And our requirement is if we pass the above data in selection screen, we have to get the ALV data corresponding to the given program name & variant and it needs to be send to given recipient as an attachment in Excel file.

For the above requirement, We are submitting the program name given in selection screen in a custom program and trying to get the ALV data of submitted program by using by using below command & we are passing the variant value to the p_var.

SUBMIT (p_prog) USING SELECTION-SET p_var AND RETURN.

And then using CL_SALV_BS_RUNTIME_INFO=>GET_DATA_REF( ) method to retrieve ALV output into an internal table.

It works fine for maximum all the reports, but it is throwing dump when the technical fieldname first character is number(The fieldname in the present scenario is 3PL_VFDAT_SHORT).dump.png

So, is there any alternative method for retrieving ALV output without using the above Class/Method CL_SALV_BS_RUNTIME_INFO=>GET_DATA_REF( ).

1 ACCEPTED SOLUTION

raymond_giuseppi
Active Contributor
2,805

Well you could build the internal table yourself with

import t_component to lt_component from memory id cl_salv_bs_runtime_info=>c_memid_data_def.
" adapt the table of component
cl_salv_bs_ddic=>create_data_from_components(
  exporting
    t_component = lt_component
  importing
    r_data      = r_data
    r_datadescr = r_data_descr ).

and then

  assign r_data->* to <lt_data>.
  try.
      cl_salv_bs_runtime_info=>get_data(
        importing
          t_data = <lt_data> ).
    catch cx_salv_bs_sc_runtime_info .
  endtry.

" or even import t_data to t_data from memory id cl_salv_bs_runtime_info=>c_memid_data.

Alas (or not) most of those objects cannot be enhanced

6 REPLIES 6

Sandra_Rossi
Active Contributor
0 Kudos
2,805

I think the standard fails because GET_DATA_REF creates the structure dynamically with the strict check activated. This is probably the code in method CREATE_DATA_FOR_COMPONENT of CL_SALV_BS_DDIC which creates the structure, you can see that the strict check is deactivated only if the field contains a hyphen but you could do a modification of standard to allow a digit at the beginning:

        if ls_comp-name ca '-'.
          l_strict = abap_false.
        endif.
      endloop.

      r_datadescr = cl_abap_structdescr=>get(
                      p_components = lt_comp
                      p_strict     = l_strict ).
I think SAP won't change it, but you can try to ask by opening a ticket at SAP Support.

A better solution is to adapt your custom programs to avoid using CL_SALV_BS_RUNTIME_INFO=>GET_DATA_REF( ).

0 Kudos
2,805

Hi Sandra.

Thank You for your response.

Is there any other ways to implement this without using CL_SALV_BS_RUNTIME_INFO=>GET_DATA_REF()?

I need to build excel dynamically based on submit program.

0 Kudos
2,805

Refactor the custom program which generates the ALV, so that this part can be called externally (class pool, function module, etc.)

Now change your code to call this part instead of SUBMIT of the whole program.

This is called structured programming, you create pieces which can be reused.

0 Kudos
2,805

Dear Sandra,

What if I have so many Custom ALV program. We have close to 40 - All the ALV output need to be sent as attachment

0 Kudos
2,805

Of course, I would try to create a generic solution, but I can't help because I know nothing about these 40 ALV. If you want some assistance then please give us more insight about what these programs are, and maybe we can give you another solution. Report Painter?

raymond_giuseppi
Active Contributor
2,806

Well you could build the internal table yourself with

import t_component to lt_component from memory id cl_salv_bs_runtime_info=>c_memid_data_def.
" adapt the table of component
cl_salv_bs_ddic=>create_data_from_components(
  exporting
    t_component = lt_component
  importing
    r_data      = r_data
    r_datadescr = r_data_descr ).

and then

  assign r_data->* to <lt_data>.
  try.
      cl_salv_bs_runtime_info=>get_data(
        importing
          t_data = <lt_data> ).
    catch cx_salv_bs_sc_runtime_info .
  endtry.

" or even import t_data to t_data from memory id cl_salv_bs_runtime_info=>c_memid_data.

Alas (or not) most of those objects cannot be enhanced