10-19-2015 10:33 AM
Hello!
I'm trying to make a couple queries which needs some coding. I'm not an ABAPer at all, but have practical knowledge with simple queries/ adding calculation-fields etc.
Theres mainly two queries I would love to have, and I've seen a couple threads and code-snips aiming to achieve just what I'm trying to get.
Ie., I'm trying to get table VBBE field OMENG summarized at plant level (directly in the result, so I can use that sum to calculate in additional fields).
However, I'm obivously terrible at this, as I'm not getting it to work.
From discussion:
TYPES: BEGIN OF ST_VBBE ,
MATNR TYPE VBBE-MATNR,
WERKS TYPE VBBE-WERKS,
OMENG TYPE VBBE-OMENG,
END OF ST_VBBE.
data : IT_VBBE TYPE TABLE OF ST_VBBE,
WA_VBBE TYPE ST_VBBE,
it_vbbe_f TYPE TABLE OF st_vbbe,
WA_VBBE_F TYPE ST_VBBE.
START-OF-SELECTION.
SELECT MATNR WERKS OMENG
FROM VBBE INTO TABLE IT_VBBE UP TO 500 rows.
BREAK-POINT.
LOOP AT IT_VBBE INTO WA_VBBE.
COLLECT WA_VBBE INTO IT_VBBE_f.
ENDLOOP.
Exactly where do I put this to use?
What I've done is:
- Created table joins in SQVI
- Converted the quickview in SQ01
- Then adding this whole code in SQ02, Extras -> Code -> Section: Data
I bet this is horribly wrong and theres pieces missing, but the code gives no syntax errors while in SQ02.
Also 'Infoset xxxxx has no inconsistencies' when I do a check of it.
But when I save this, and trying to execute in SQ01, I get an ABAP runtime error 😕
As the discussion-title indicates of course, do I need to COLLECT this data somehow?
How do I do that?
Any advice or a small guide to using this code-snippet would mean a lot to me
10-29-2015 5:41 PM
Thanks to everyone who tried to help me out.
With some help, I managed to find the solution to my requirement, which was a lot easier than I originally thought.
I created an Extra -> 'Additional field' in SQ02. Called it TOT_OMENG with these settings:
(I later found out I wanted the values from field VMENG instead of OMENG)
Then in 'Coding for addition' (button to the left of "Sequence"), I used the following code:
So, this code just sums up the VMENG-column of table VBBE, based on EKPO-MATNR og -WERKS, and the material av.date (VMENG) less than or equal to the system date.
Then I put this additional field into the same field-group as the rest.
Then in SQ01, I could go to the basic list output and select this new field. Voila!
10-19-2015 10:42 AM
10-19-2015 11:25 AM
I'm not able to see exactly what the error is. It's just a short dump without info.
To be more specific, the error occurs in SQ01, when I'm trying to call the query. So it happens before the selection-screen.. if it helps.
10-19-2015 1:19 PM
Code looks good.
Could you please paste snapshot of error from ST22 transaction?
10-20-2015 7:19 AM
10-20-2015 8:44 AM
Have you written any code for selection screen as well? Error message is pretty much straight forward. There must be a statement "SELECTION-SCREEN BEGIN OF BLOCK .." in the code somewhere. This statement must be followed with "SELECTION-SCREEN END OF BLOCK.." statement.
10-20-2015 8:49 AM
You position of code is wrong...write it in the correct section i.e START-OF-SELECTION.
You have defined your own block for START-OF-SELECTION in a wrong section.
10-20-2015 9:10 AM
Yes, that's what I'm guessing.
As I said, I have no clue as to where to put the code
I dont know if its right, but I took a wild guess and did it like this:
Now I didn't get the error when calling the query at least
But when I execute, ABAP debugger is starting, and I get thrown here:
Does that mean there's a problem at that BREAK-POINT.?
10-20-2015 9:46 AM
10-20-2015 12:33 PM
When I removed the BREAK-POINT, I could finally get a result up when executing the query
However, I guess there's something missing, cause I do want to retrieve the sum of the field VBBE-OMENG (could be 50 rows of data for one material, I'd like to find the sum). And that sum I want populated in a different column.
Maybe I forgot to mention that.
Anyways, I haven't done anything else with the query. And as I'm trying to not get mind-blown by code, and seeing the statement "COLLECT WA_VBBE INTO IT_VBBE_f."
What does that mean? Is the result posted somewhere in an internal table?
Should I make an additional field and retrieve IT_VBBE_f, to get the result posted in a field?
EDIT: My result now seems to be the same as without the code.
10-21-2015 10:20 AM
Hi Vegard,
If you want to sum up VBBE-OMENG for material only, then you will have to remove plant from the internal table. Below code should sum up VBBE-OMENG for each material.
TYPES: BEGIN OF ST_VBBE ,
MATNR TYPE VBBE-MATNR,
OMENG TYPE VBBE-OMENG,
END OF ST_VBBE.
data : IT_VBBE TYPE TABLE OF ST_VBBE,
WA_VBBE TYPE ST_VBBE,
it_vbbe_f TYPE TABLE OF st_vbbe,
WA_VBBE_F TYPE ST_VBBE.
START-OF-SELECTION.
SELECT MATNR OMENG
FROM VBBE INTO TABLE IT_VBBE UP TO 500 rows.
SORT IT_VBBE BY MATNR.
LOOP AT IT_VBBE INTO WA_VBBE.
COLLECT WA_VBBE INTO IT_VBBE_f.
ENDLOOP.
Thanks & Regards,
Tejas Asodekar
10-21-2015 11:08 AM
Hello Tejas.
Sorry, I do mean material by plant, so the first code should be right I guess.
But where should the result present itself? In the OMENG-field?
Even if I execute the query with material and plant, theres no change, just the normal result.
Putting plant and some material:
I want this result (proper good paint-job):
Do you mean the code would make the result (here 136) end up in the OMENG-column?
Shouldn't I make an additional field, list that field, and get the result from the code / retrieved / collected or whatever, in that new field?
Sorry for all the newbie questions
10-21-2015 11:25 AM
Hi Vegard,
At the end of your code, you will get the summarized amount in OMENG-field IT_VBBE_f table.
If suppose, the data in IT_VBBE is like the one below
Material Plant Amount
000001 P001 10
000002 P001 10
000001 P001 10
000002 P002 10
Then, your output in IT_VBBE_F would be something like this
Material Plant Amount
000001 P001 20
000002 P001 10
000002 P002 10
You will have to make sure that you are displaying OMENG column from internal table IT_VBBE_f in your query output. You can do this in new column as well as in existing column as well.
10-21-2015 12:04 PM
Ok, thanks for the good explanation
Unfortunately, I can't seem to find info on how to display from internal table.
Do I make an additional field in SQ02 and add some code to get it? Like a READ-statement?
10-27-2015 10:22 AM
Bump
Does anyone know of a straight forward, noob-friendly guide, to retrieve result of internal table to a new, additional field in SQ02?
As Tejas explained the internal table, how do i get the amount in the query-result for the material/plant?
Material Plant Amount
000001 P001 20
000002 P001 10
000002 P002 10
Hope to hearing from you
10-29-2015 5:41 PM
Thanks to everyone who tried to help me out.
With some help, I managed to find the solution to my requirement, which was a lot easier than I originally thought.
I created an Extra -> 'Additional field' in SQ02. Called it TOT_OMENG with these settings:
(I later found out I wanted the values from field VMENG instead of OMENG)
Then in 'Coding for addition' (button to the left of "Sequence"), I used the following code:
So, this code just sums up the VMENG-column of table VBBE, based on EKPO-MATNR og -WERKS, and the material av.date (VMENG) less than or equal to the system date.
Then I put this additional field into the same field-group as the rest.
Then in SQ01, I could go to the basic list output and select this new field. Voila!