Skip to Content
0

Select statement to use existing internal table data

Apr 07, 2017 at 08:28 PM

228

avatar image

Hi All,

Here is my requirement. I have an internal table with Sales Order and Creation date. Now, I just need to get the item details into another internal table (from VBAP) AND I need to get the Creation date from the first internal table. I know we can get the items into second internal table and then loop through the list and query the first table to get the Creation date.

My question, is it possible to get the data into second internal table directly while querying the VBAP table with the new ABAP standards (we are on 7.50 with SP 5).

Thanks in advance,

Chandra

10 |10000 characters needed characters left characters exceeded

I'm rather curious what business scenario would require such data selection? It's not unusual to search for, say, order items created in the last X days. In this case we'd just use a date range in WHERE condition. But to search so specifically for "order A items created on X date and order B items created on Y date" in one swoop seems rather odd...

Just wondering if by chance you might be over-thinking the requirement or there is some miscommunication.

1
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Horst Keller
Apr 07, 2017 at 09:54 PM
1

Using internal tables as data sources of joins is not yet possible in that release ...

Share
10 |10000 characters needed characters left characters exceeded
Raghu Govindarajan Apr 12, 2017 at 08:28 PM
-1

Is this what you are looking for?

TYPES:
  BEGIN OF ty_new_tab,
    vbeln TYPE vbeln,
    posnr TYPE posnr,
    matnr TYPE matnr,
    erdat TYPE erdat,
  END OF ty_new_tab,

  tty_new_tab TYPE STANDARD TABLE OF ty_new_tab WITH EMPTY KEY.

SELECT * FROM vbak
  INTO TABLE @DATA(vbak_tab)
  UP TO 20 ROWS.

SELECT * FROM vbap
  FOR ALL ENTRIES IN @vbak_tab
  WHERE vbeln = @vbak_tab-vbeln
  INTO TABLE @DATA(vbap_tab).

DATA(new_tab) =
  VALUE tty_new_tab(
      FOR vbap_line IN vbap_tab
        ( vbeln = vbap_line-vbeln
          posnr = vbap_line-posnr
          matnr = vbap_line-matnr
          erdat = vbak_tab[ vbeln = vbap_line-vbeln ]-erdat
        )
   ).

cl_demo_output=>display( new_tab ).
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Yes, this technically does a LOOP with the FOR statement, but this is a single command and a single place where the data extraction is being dealt with. This is opposed to older ABAP which would have been..

DATA:
  vbak_line TYPE vbak,
  new_line  TYPE ty_new_tab,
  new_tab   TYPE tty_new_tab.

MOVE-CORRESPONDING vbap_tab TO new_tab.

LOOP AT new_tab INTO new_line.
  READ TABLE vbak_tab WITH KEY vbeln = sy-subrc INTO vbak_line.
  new_line-erdat = vbak_line-erdat.
  MODIFY new_tab FROM new_line.
ENDLOOP.
0
John Vo Apr 08, 2017 at 02:49 AM
-3

Just join vbak, vbap then for all entries with internal sale then get sale create date in vbak and some item data in vbap.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

How is this helpful to OP? They already said explicitly they're aware of such option.

0
Palash Mazumder Apr 11, 2017 at 06:26 PM
-4

Use the inner join,,,,,,

Share
10 |10000 characters needed characters left characters exceeded