Application Development and Automation 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: 
Read only

How to put multiple lines into one without using a table?

Former Member
0 Likes
2,985

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

1 ACCEPTED SOLUTION
Read only

juan_suros
Contributor
0 Likes
2,900

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.

19 REPLIES 19
Read only

VijayCR
Active Contributor
0 Likes
2,900

Use collect statement

Thanks

Vijay

Read only

Former Member
0 Likes
2,900

Thank you for your response, but I am looking for the way to do it without an internal table.

Read only

ramakrishnappa
Active Contributor
0 Likes
2,900

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

Read only

0 Likes
2,900

Yes I am finding this seems to be more difficult than it appears.

Read only

Former Member
0 Likes
2,900

Hello Collin,

loop your internal table which containing the data.

LOOP at internal table  to wa_tab.

collect wa_tab to internal table.

endloop.

Read only

0 Likes
2,900

Thank you for your response, but I need the process that does not use an internal table.

Read only

0 Likes
2,900

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

Read only

0 Likes
2,900

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.

Read only

Former Member
0 Likes
2,900

Hi,

Use SUM aggregate function in your SELECT query and group by PR No.

Regards

Abhi

Read only

0 Likes
2,900

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?

Read only

0 Likes
2,900

Hi,

You can try the solution suggested by Juan Suros.

Regards

Abhi

Read only

dibyajeeban_jena
Active Participant
0 Likes
2,900

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 .

Read only

0 Likes
2,900

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.

Read only

0 Likes
2,900

Hello Collin,

It's correct. WA_EBAN is a variable, and you can declare like this:

DATA: WA_EBAN TYPE EBAN.

Regards,

Renzo.

Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
2,900

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...

Read only

0 Likes
2,900

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.

Read only

juan_suros
Contributor
0 Likes
2,901

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.

Read only

0 Likes
2,900

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.

Read only

0 Likes
2,900

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.