Application Development 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: 

Creating Two Internal Tables with Only One Select Query in ABAP

Lumos
Explorer
0 Kudos
1,136

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,
       apo~ordno,
       vbak~vgbel,
       vbak~auart,
       ct~quantity,
       ct~category
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'
INTO TABLE @DATA(lt_bm).
1 ACCEPTED SOLUTION

jmodaal
Active Contributor
445

Hello,

maybe not (?) with keeping the inline declaration of the internal table. But with using a type for it, it can be done like this:

private section.    
  types: begin of TResult4Category,
           ordid type (?)-ordid,
           ordno type (?)-ordno,
           vgbel type vbak-vgbel,
           auart type vbak-auart,
           quantity type (?)-quantity,
           category type (?)-category,
         end of TResult4Category,
         TResult4CatTable type standard table of TResult4Category with default key.
  methods: 
    getData4Category
      importing i_category type (?)-category
      returning value(result) type TResult4CatTable.
  ...

  data(result4BM) = getData4Category( 'BM' ).
  data(result4BL) = getData4Category( 'BL' ).
  ...
  method getData4Category.
    SELECT apo~ordid,
        ...
        where ct~category EQ i_category
...
INTO TABLE result.
endmethod.
3 REPLIES 3

jmodaal
Active Contributor
446

Hello,

maybe not (?) with keeping the inline declaration of the internal table. But with using a type for it, it can be done like this:

private section.    
  types: begin of TResult4Category,
           ordid type (?)-ordid,
           ordno type (?)-ordno,
           vgbel type vbak-vgbel,
           auart type vbak-auart,
           quantity type (?)-quantity,
           category type (?)-category,
         end of TResult4Category,
         TResult4CatTable type standard table of TResult4Category with default key.
  methods: 
    getData4Category
      importing i_category type (?)-category
      returning value(result) type TResult4CatTable.
  ...

  data(result4BM) = getData4Category( 'BM' ).
  data(result4BL) = getData4Category( 'BL' ).
  ...
  method getData4Category.
    SELECT apo~ordid,
        ...
        where ct~category EQ i_category
...
INTO TABLE result.
endmethod.

0 Kudos
445

Thank you for your valuable answer! I actually wrote it wrong on the question like "class method" it should have been "global class method" . This implementation is being done inside a classic badi method which connects to a generated global class method. But I will definitely keep this solution in my mind for the further implementations!

445

ihkn

For information, by using Eclipse ADT, you may use a Quick Fix to create the type automatically from the inline declarations.