How to execute Report given the results of a previ

2019-07-26 21:08发布

问题:

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);

回答1:

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.



标签: submit sap abap