Skip to Content
Jan 27, 2022 at 08:46 AM

Creating Two Internal Tables with Only One Select Query in ABAP

639 Views Last edit Jan 27, 2022 at 08:53 AM 5 rev

Hi all! I must create 2 select queries which are almost the same. But the only difference between them is one's category will be "BL" and the other's category will be "BM". Code example is shown down below. Depending on the same VBELN values on two different internal table I need to add a control which checks either the VBELN values are the same or not, and then if they are the same I need to sum the QUANTITY values.

So for that, is there any way to do it in only one SELECT query rather than repeating myself for the performance sake?
Or is there any way to create 2 different internal tables with inline declaration and store the data in the related itabs?
Thanks in advance! :)

Note: @ct_ionodes is a change table parameter coming from a class method. (Table Type)

SELECT apo~ordid,
FROM XXX               AS apo
INNER JOIN @ct_ionodes AS ct  ON ct~orderid EQ apo~ordid
INNER JOIN vbak               ON vbak~vbeln EQ apo~ordno
WHERE ct~category EQ 'BM'
  AND vbak~vgbel  EQ vbak~vbeln
  AND vbak~auart  EQ 'ZCT1'