1

My problem is the following:
I have one report called Y5000112.
My colleagues always execute it manually once with selection screen variant V1 and then execute it a second time with variant V2 adding the results of the first execution to the selection.
Those results in this case are PERNR.

My goal:
Automate this - execute that query twice with one click and automatically fill the PERNR selection of the second execution with the PERNR results of the first execution.

I found out how to trigger a report execution and after that another one, how to set it to a certain variant and got this far - [EDIT] after the first answer I got a bit further but I still have no idea how to loop through my results and put them into the next Report submit:

DATA: t_list TYPE TABLE OF abaplist.
*      lt_seltab TYPE TABLE OF rsparams,
*      ls_selline LIKE LINE OF lt_seltab.

SUBMIT Y5000114
USING SELECTION-SET 'MA OPLAN TEST'
EXPORTING LIST TO MEMORY
AND RETURN.

CALL FUNCTION 'LIST_FROM_MEMORY'
TABLES
  listobject = t_list
EXCEPTIONS
  not_found = 1
  OTHERS = 2.
IF sy-subrc <> 0.
  WRITE 'Unable to get list from memory'.
ELSE.
* I want to fill ls_seltab here with all pernr (table pa0020) but I haven't got a clue how to do this
*  LOOP AT t_list.
*    WRITE /t_list.
*  ENDLOOP.

  SUBMIT Y5000114
*  WITH-SELECTION-TABLE ls_seltab
  USING SELECTION-SET 'MA OPLAN TEST2'
  AND RETURN.
ENDIF.

P.S.
I'm not very familiar with ABAP so if I didn't provide enough Information just let me know in the comments and I'll try to find out whatever you need to know in order to solve this.

Here's my imaginary JS-Code that can express very generally what I'm trying to accomplish.

function submitAndReturnExport(Reportname,VariantName,OptionalPernrSelection)
{...return resultObject;}

var t_list = submitAndReturnExport("Y5000114","MA OPLAN TEST");
var pernrArr = [];
for (var i in t_list)
{
 pernrArr.push(t_list[i]["pernr"]);
}
submitAndReturnExport("Y5000114","MA OPLAN TEST2",pernrArr);
Sandra Rossi
  • 11,934
  • 5
  • 22
  • 48
Cold_Class
  • 3,214
  • 4
  • 39
  • 82

1 Answers1

3

It's not that easy as it supposed to, so there won't be any one-line snippet.
There is no standard way of getting results from report. Try EXPORTING LIST TO MEMORY clause, but consider that the report may need to be adapted:

SUBMIT [report_name]
WITH SELECTION-TABLE [rspar_tab]
EXPORTING LIST TO MEMORY
AND RETURN.

The result of the above statement should be read from memory and adapted for output:

call function 'LIST_FROM_MEMORY'
  TABLES
   listobject       = t_list
  EXCEPTIONS
   not_found        = 1
   others           = 2.

if sy-subrc <> 0.
  message 'Unable to get list from memory' type 'E'.
endif.

call function 'WRITE_LIST'
  TABLES
   listobject       = t_list
  EXCEPTIONS
   EMPTY_LIST       = 1
   OTHERS           = 2
        .
 if sy-subrc <> 0.
  message 'Unable to write list' type 'E'.
 endif.

Another (and more efficient approach, IMHO) is to gain access to resulting grid via class cl_salv_bs_runtime_info. See the example here

P.S. Executing the same report with different parameters which are mutually-dependent (output pars of 1st iteration = input pars for the 2nd) is definitely a bad design, and those manipulations should be done internally.
As for me one'd better rethink the whole architecture of the report.

Suncatcher
  • 10,355
  • 10
  • 52
  • 90
  • 1
    And how do I put that t_list back into the second report selection? – Cold_Class Jan 13 '17 at 11:58
  • 2
    As usual: looping through it, extracting necessary field and constructing seltab for the second submit. Nobody told you that'd be easy as a pie. – Suncatcher Jan 13 '17 at 12:04
  • 1
    true, thx for all the information - once I was successful with it I will accept your answer :) – Cold_Class Jan 13 '17 at 12:09
  • The reason for the bad design is that I don't have a development key and there is no known possibility to me how to specify an AND-Operator in my Query-Selection-GUI - Therefore I execute it first with the first selector and the outcome with the second selector and then I got my AND-Operator. Now I found out where I can execute some code (with some restrictions though) and I'm experimenting there. – Cold_Class Jan 13 '17 at 14:49
  • I edited my question as you can see I was not able to find out how to execute you sentence: "Looping through it, ..." I tried many Solutions from Google but since I lack the Basics I always got Syntax error and never managed to do it succesfully. – Cold_Class Jan 26 '17 at 11:00
  • 1
    @Cold_Class, read [this manual](https://help.sap.com/saphelp_nw70/helpdata/en/9f/dba51a35c111d1829f0000e829fbfe/content.htm) **attentively**, it already contains needed code snippet. You should use `WITH SELECTION-TABLE` addition, not the `USING SELECTION-SET` you are using in the code sample you provided. `USING SELECTION-SET` is used for variants, and you can't supply both variant and seltab to report at one time. – Suncatcher Jan 26 '17 at 12:19
  • If I can't supply both then what does this sentence from your link mean - 'The only combination possible for the WITH SELECTION-TABLE addition is USING SELECTION-SET.'? – Cold_Class Jan 27 '17 at 15:57
  • I read through it - and learned some new things indeed - but I don't know how to retrieve the data - in this case the `PERNR` - from `t_list` in order to append it to my `rspar_tab` -> so from your sentence I still don't know how to: 'extracting necessary field' - I don't even know where I should get its name from cause I don't have access to any code. I only see the report in a GUI (Query Manager) and I know the origin is pa0020-PERNR. It's difficult to code in a tiny user-exit window xD – Cold_Class Jan 27 '17 at 17:25