ABAP SALV model has some cool features. Getting the data table from the model, is one of them. Let’s explore the solution.
Problems analyzing LIST returned by LIST_FROM_MEMORY
SUBMIT is a great feature of ABAP. You can generate the report output, send LIST to the memory using SUBMIT .. EXPORTING LIST TO MEMORY. You can get this list from the memory using the FM LIST_FROM_MEMORY and use that to write the list using WRITE_LIST .
Everything is good so far, but when you need to read the values from the list, things get messy. You would need to parse the data, remove the lines, formatting etc. This would be painful and not much fun.
You can overcome this issues by a workaround:
- Export the list to the unique Memory ID from the submitted Program
- Import the list from the memory ID in the caller program
To be able to implement this workaround, you would need to modify the Submitted program in order to pass the data to the memory ID. Once you do that, caller program would be able to get it back after control is back in the main program.
Use SALV Model class CL_SALV_BS_RUNTIME_INFO
To overcome this limitation of the workaround, SALV model would be helpful. If the output of the submitted report is generated by the SALV Fullscreen model, the data can be easily retrieved back using the SALV model class CL_SALV_BS_RUNTIME_INFO. This class CL_SALV_BS_RUNTIME_INFO has few methods which can be really useful in this situation.
Let the model know, that you don’t want to generate the output, but interested in the data.
Instruct Model to get the data
cl_salv_bs_runtime_info=>set( EXPORTING display = SPACE metadata = SPACE data = ‘X’ ).
Once the report is submitted, get the data from the runtime information
DATA lo_data TYPE REF TO data. TRY. " get data from the SALV model cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lo_data ). CATCH cx_salv_bs_sc_runtime_info. Message 'Unable to get data from SALV' type 'I'. ENDTRY.
To show it in action, I’m submitting the report SALV_DEMO_TABLE_SIMPLE.
DATA: lt_outtab TYPE STANDARD TABLE OF alv_t_t2. FIELD-SYMBOLS: <lt_outtab> like lt_outtab. DATA lo_data TYPE REF TO data. " Let know the model cl_salv_bs_runtime_info=>set( EXPORTING display = abap_false metadata = abap_false data = abap_true ). SUBMIT salv_demo_table_simple AND RETURN. TRY. " get data from SALV model cl_salv_bs_runtime_info=>get_data_ref( IMPORTING r_data = lo_data ). ASSIGN lo_data->* to <lt_outtab>. BREAK-POINT. CATCH cx_salv_bs_sc_runtime_info. ENDTRY.
- Not sending the list to memory
- No need to modify the submitted program to export the data to memory
- No need to Import the data
These method does the same export and import but they are hidden from the caller.
Debugger shows that the data has been successfully retrieved from the model.
One more reason to use SALV Model