Application Development and Automation 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: 
Read only

Get data from temp table

aneel_munawar
Participant
0 Likes
745


Dear All ABAP Exeprts,


I have written a query  but it gives error on 

t_vbak-KNUMV as KNUMV  line

I want to get KNUMV from the   t_vbak  table. How can I write this query.?

Regards,

Aneel




SELECT vbeln " Sales Document

     posnr " Sales Document Item

     matnr " Material Number

     arktx " Short text for sales order

     " item

     kwmeng " Cumulative Order Quantity

     vrkme " Sales unit

    t_vbak-KNUMV as KNUMV

     FROM vbap

     INTO TABLE t_vbap

     FOR ALL ENTRIES IN t_vbak

     WHERE vbeln EQ t_vbak-vbeln.

1 ACCEPTED SOLUTION
Read only

philipdavy
Contributor
0 Likes
703

Hi Aneel,

  • You may have to do it in two steps.
  • I guess your T_VBAK internal table is already filled.
  • Now you are going to join this internal table with the values of database table VBAP comparing the VBELN.

Pseudo Code.

SELECT * from vbak where ""some condition


SELECT

   

     vbeln " Sales Document

     posnr " Sales Document Item

     matnr " Material Number

     arktx " Short text for sales order

     " item

     kwmeng " Cumulative Order Quantity

     vrkme

     FROM vbap

     INTO TABLE t_vbap

     FOR ALL ENTRIES IN t_vbak

     WHERE vbeln EQ t_vbak-vbeln.

LOOP AT IT_VBAP ITO WA_VBAP.

READ TABLE IT_VBAK INTO WA_VBAK WHERE VBELN = WA_VBELN.

WA_FINAL-KNUMV  =  WA_VBAK-KNUMV.

******

some codes

append wa_final to it_final.

*******

ENDLOOP.

Regards,

Philip.

3 REPLIES 3
Read only

philipdavy
Contributor
0 Likes
704

Hi Aneel,

  • You may have to do it in two steps.
  • I guess your T_VBAK internal table is already filled.
  • Now you are going to join this internal table with the values of database table VBAP comparing the VBELN.

Pseudo Code.

SELECT * from vbak where ""some condition


SELECT

   

     vbeln " Sales Document

     posnr " Sales Document Item

     matnr " Material Number

     arktx " Short text for sales order

     " item

     kwmeng " Cumulative Order Quantity

     vrkme

     FROM vbap

     INTO TABLE t_vbap

     FOR ALL ENTRIES IN t_vbak

     WHERE vbeln EQ t_vbak-vbeln.

LOOP AT IT_VBAP ITO WA_VBAP.

READ TABLE IT_VBAK INTO WA_VBAK WHERE VBELN = WA_VBELN.

WA_FINAL-KNUMV  =  WA_VBAK-KNUMV.

******

some codes

append wa_final to it_final.

*******

ENDLOOP.

Regards,

Philip.

Read only

RaymondGiuseppi
Active Contributor
0 Likes
703

Not possible in a single SELECT statement, every field of the result must come from the database : single columns and aggregates. So execute your SELECT and then merge the two internal table into a final table.

You could (should) also consider building a JOIN with the first SELECT which built T_VBAK, as a single JOIN between VBAK and VBAK should give (much) better performance in a single SELECT statement.

Regards,

Raymond

Read only

sriharsha_parayatham
Participant
0 Likes
703

Do join instead of for all entries ,