‎2014 Feb 16 11:36 PM
Hello everyone,
This is my first question so I apologize if it is a little fuzzy.
I need to know how to put multiple lines into one line. Specifically, I am going through the purchase order table (EBAN) and I need to create a program that shows one line per purchase requisition instead of the SAP default of one line per each line item on the purchase requisition.
Example:
Original
PR Date Creator Value
10000 1/1/2014 me val1
10000 1/1/2014 me val2
10000 1/1/2014 me val3
10001 1/2/2014 me val1
10001 1/2/2014 me val2
What I Need
PR Date Creator Value
10000 1/1/2014 me sum(val1, val2, val3)
10001 1/2/2014 me sum(val1, val2)
And to throw a wrench into the question I need to be able to do this without using an internal table.
Thank you for your help,
Collin
‎2014 Feb 17 11:25 PM
Try something like this:
REPORT group_eban.
TABLES: eban.
SELECT-OPTIONS: s_banfn FOR eban-banfn.
SELECT banfn badat ernam SUM( bumng )
FROM eban INTO CORRESPONDING FIELDS OF eban
WHERE banfn IN s_banfn
GROUP BY banfn badat ernam.
ENDSELECT.
‎2014 Feb 17 1:37 AM
‎2014 Feb 17 6:51 PM
Thank you for your response, but I am looking for the way to do it without an internal table.
‎2014 Feb 17 3:00 AM
Hi Collin,
As suggested by Vijay, you can be able to meet your requirement by using COLLECT statement.
However you need to collect the records into an internal table but you are not okay to use internal table.
Regards,
Rama
‎2014 Feb 17 6:52 PM
Yes I am finding this seems to be more difficult than it appears.
‎2014 Feb 17 3:02 AM
Hello Collin,
loop your internal table which containing the data.
LOOP at internal table to wa_tab.
collect wa_tab to internal table.
endloop.
‎2014 Feb 17 6:53 PM
Thank you for your response, but I need the process that does not use an internal table.
‎2014 Feb 17 8:17 PM
What is the reason to avoid an internal table by all means? Is this an academic experiment?
You might as well ask how to take a shower without getting wet, at least as long as you don't disclose the rationale behind this artificial limitation.
Thomas
‎2014 Feb 17 8:52 PM
That is a very good question. As you guessed, this is an academic experiment to see if it is plausible to do such a thing. Taking a shower without getting wet is a very good analogy for this, but nonetheless it was my goal to make this process work if at all possible.
‎2014 Feb 17 3:20 AM
Hi,
Use SUM aggregate function in your SELECT query and group by PR No.
Regards
Abhi
‎2014 Feb 17 6:54 PM
I have tried to do this because it makes sense to me logically, but I cannot seem to get it to display properly. Could you possibly show me an example?
‎2014 Feb 18 2:20 AM
Hi,
You can try the solution suggested by Juan Suros.
Regards
Abhi
‎2014 Feb 17 4:15 AM
Hi,
> Use Collect key word
> Use AT NEW PERNR .....
SUM.
APPEND TO ITAB .
ENDAT .
>Use SUM aggregate function in your SELECT query and group by PR No.
In above process u will need at least one internal table to keep the data .
..for without internal table
SELECT * FROM EBAN INTO WA_EBAN .
put logic for adding all line item for a single pr no. and use WRITE to display .
ENDSELECT .
‎2014 Feb 17 6:59 PM
This way makes the most sense to me now, but I cannot get it to display correctly. Because I am new to these discussion boards and am not complete familiar with some terminology, in the line your wrote, "SELECT * FROM EBAN INTO WA_EBAN" is wa_eban a variable declared earlier? And if so of what type?
Thank you for putting up with my newness of ABAP.
‎2014 Feb 17 8:04 PM
Hello Collin,
It's correct. WA_EBAN is a variable, and you can declare like this:
DATA: WA_EBAN TYPE EBAN.
Regards,
Renzo.
‎2014 Feb 17 10:43 PM
You can use a structure, as already suggested, and do SELECT in a LOOP or SELECT... ENDSELECT. But neither of these would be a recommended solution, so this exercise just doesn't make any sense IMHO. I'd suggest to study the examples provided in ABAP Editor instead of coming up with some made-up challenges. I honestly don't recall ever having a requirement to avoid internal tables or to make a program as inefficient as possible...
‎2014 Feb 17 11:10 PM
I appreciate your input, but at this point in time I am not worried about the recommended solution because I know that this would not be the way. I'm trying to broaden my understanding of how the code would work and trying to be able to develop my explanation of what I am trying to accomplish more clearly.
‎2014 Feb 17 11:25 PM
Try something like this:
REPORT group_eban.
TABLES: eban.
SELECT-OPTIONS: s_banfn FOR eban-banfn.
SELECT banfn badat ernam SUM( bumng )
FROM eban INTO CORRESPONDING FIELDS OF eban
WHERE banfn IN s_banfn
GROUP BY banfn badat ernam.
ENDSELECT.
‎2014 Feb 18 2:40 AM
Thank you very much for your response. With this code I get a screen which is looking for a value that does not have any possible entries. I am newer to ABAP so I will play around with it and see what I can find. Thanks again.
‎2014 Feb 18 3:29 PM
Here is a complete example.
REPORT group_eban.
TABLES: eban.
SELECT-OPTIONS: s_banfn FOR eban-banfn.
WRITE: /01 'PR',12 'Date', 23 'Creator',47 'Value'.
SELECT banfn badat ernam SUM( bumng )
FROM eban INTO CORRESPONDING FIELDS OF eban
WHERE banfn IN s_banfn
GROUP BY banfn badat ernam.
WRITE: /01 eban-banfn, eban-badat, eban-ernam, eban-bumng.
ENDSELECT.