I encounter the following problem.
What I want to do
I want to create an infoset that would regroup, for a given Purchase Order, data from the VBAK
table with several lines from the VBPA
table that should be dispatched to different fields.
Example : for the following PO 111005229 I would like to retrieve in a first field the KUNNR
field for which PARVW = 'ER'
and in a second field the ADRNR
field for which PARVW = 'BP'
.
Desired output :
What I've tried
Joining both tables in SQ02
I tried to declare the 2 tables VBAK
and VBAP
while running the SQ02 TCode and select the desired fields :
This doesn't work :
- just like in SE16N, the query returns every line of a purchase order when a single line with filtered data is wanted ;
- when using the
CHECK VBPA-PARVW = 'ER'.
in theRecord processing
code part hoping that this would shrink the number of lines to 1 for a given PO, no value at all is returned.
Declaring only VBAK table in SQ02
I also tried to declare only the VBAK
table in SQ02, create the additional field PERNR_ER
that I want and proceed to join VBAK
with VBPA
with openSQL
code related to these specific fields.
I created the additional fields PARVW_ER
and PERNR_ER
with the following code embedded :
SELECT PARVW
INTO PARVW_ER
FROM VBPA
WHERE VBELN = VBPA~VBELN.
AND PARVW = 'ER'.
ENDSELECT.
SELECT PERNR
INTO PERNR_ER
FROM VBPA
WHERE VBELN = VBPA~VBELN.
AND PARVW = 'ER'.
ENDSELECT.
which gives as an output
I also tried
TYPES: begin of TY_TABLE,
PARVW LIKE VBPA-PARVW,
PERNR LIKE VBPA-PERNR,
END OF TY_TABLE.
DATA: WA_TABLE TYPE TY_TABLE,
IT_TABLE TYPE TABLE OF TY_TABLE.
SELECT PARVW PERNR
APPENDING CORRESPONDING FIELDS OF TABLE IT_TABLE
FROM VBPA
WHERE VBELN = VBPA~VBELN.
LOOP AT IT_TABLE INTO WA_TABLE.
IF WA_TABLE-PARVW = 'ER'.
PARVW_ER = WA_TABLE-PARVW.
PERNR_ER = WA_TABLE-PERNR.
ENDIF.
ENDLOOP.
but it returned the same.
How should I proceed to get the expected result?
Use an
INNER JOIN
on the same table and then filter out the unnecessary rows byPARVW
.Result