This website is not affiliated with, sponsored by, or approved by SAP AG.

Select multiple lines for condition

Development (ABAP Development WorkBench, ABAP/4 programming)

Moderators: Snowy, thx4allthefish, YuriT, Gothmog

Select multiple lines for condition

Postby rpinxt » Thu Mar 06, 2014 5:03 am

Hi All,

Please have a look at this code:
Code: Select all
CLEAR RP_MATERIAL.
SELECT SINGLE MATNR FROM MARA
  INTO RP_MATERIAL
  WHERE PRDHA = RP_PRODH.

Actually this works like a charm.
However a given Product Hierarchy (PRDHA) contains 8 materials.
This code only gives me the first material of the product hierarchy.

So my first thought was it did this because of select SINGLE.

Therefore I tried this code:
Code: Select all
CLEAR RP_MATERIAL.
SELECT MATNR FROM MARA
  INTO RP_MATERIAL
  WHERE PRDHA = RP_PRODH.
ENDSELECT.

Thinking this would give me not a SINGLE but all materials belonging to this Product Hierarchy.
Unfortunately this only gave me the LAST material of the 8 materials that belong to that Product Hierarchy.... :?

So where am I going wrong?
Thanks!
rpinxt
 
Posts: 146
Joined: Mon Jul 23, 2012 8:02 am

Re: Select multiple lines for condition

Postby Gothmog » Thu Mar 06, 2014 5:24 am

SELECT (...) INTO TABLE is your friend here.
You should really read the help on SELECT to understand how a SELECt ENDSELECT block works, when to use SELECT SINGLE, etc.
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1941
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

Re: Select multiple lines for condition

Postby rpinxt » Thu Mar 06, 2014 5:43 am

Thanks Gothmog, but I was reading things and looking for example on the internet.
But I am not able to "translate" the technical details into my own needs always.

That is why I am happy that support forums like this exist.
They can alter my code to let me see (making it visual is important for me) what the correct way would be.
From that I then learn how to use these things in future queries.

So now I changed my code to this:
Code: Select all
CLEAR RP_MATERIAL.
SELECT MATNR FROM MARA
  INTO TABLE RP_MATERIAL
  WHERE PRDHA = RP_PRODH.


But now it says that RP_MATERIAL is not an internal table so I guess this has to be set.
Other things that comes to mind then is if I then still will be able to use RP_MATERIAL as a field to use in the selections when running the report?
Thanks.
rpinxt
 
Posts: 146
Joined: Mon Jul 23, 2012 8:02 am

Re: Select multiple lines for condition

Postby Gothmog » Thu Mar 06, 2014 6:05 am

Please note that this is not a training forum, and that if you will continue writing code in queries (you're still working with queries there, right?), you really need to attend a basic course in ABAP, as it's clear that much of the syntax and concepts are quite murky for you.

How you'll code things will depend on what you want to do with the result of this selection.
You could get all the selected materials in a table (declare, for example, by DATA itab TYPE STANDARD TABLE OF struc), and use it in selections, LOOP on it to treat individual materials...

There are always many ways to do something - and some are worse than others depending on the context.
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1941
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home

Re: Select multiple lines for condition

Postby rpinxt » Thu Mar 06, 2014 6:10 am

Ok thanks.
I will keep scanning the net and see if I can solve it with the pointers received here.
rpinxt
 
Posts: 146
Joined: Mon Jul 23, 2012 8:02 am

Re: Select multiple lines for condition

Postby Sharpshooter » Thu Mar 06, 2014 7:15 am

Have you also reviewed the topic in the "ABAP Knowledge Corner" in this forum?
http://www.sapfans.com/forums/viewtopic.php?f=31&t=326612

Dave
Good luck!
Sharpshooter
 
Posts: 1171
Joined: Wed Mar 17, 2010 12:01 pm
Location: In the dark

Re: Select multiple lines for condition

Postby rpinxt » Thu Mar 06, 2014 8:11 am

Thanks Sharpshooter,
I also will read this and see if combined with other knowledge will resolve my query :)
rpinxt
 
Posts: 146
Joined: Mon Jul 23, 2012 8:02 am

Re: Select multiple lines for condition

Postby Gothmog » Fri Mar 07, 2014 4:14 am

Don't forget that F1 is your best friend - the ABAP syntax is quite well documented, and this documentation is easily available from the ABAP editor with F1.
68 74 74 70 3a 2f 2f 74 69 6e 79 75 72 6c 2e 63 6f 6d 2f 62 64 6f 37 6d 77 67
Gothmog
 
Posts: 1941
Joined: Wed Sep 12, 2007 4:46 am
Location: Probably not home


Return to ABAP

Who is online

Users browsing this forum: No registered users and 10 guests





loading...


This website is not affiliated with, sponsored by, or approved by SAP AG.