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: 

Need to access 3 tables to take quantity for delivery.

Former Member
0 Kudos

I am a beginner in abap so this may be something easy for you experts to adress me how to do it .

Basically I have to sum values of netwr from vbap and values of lifmg from lips: I am stuck because the way I did it is not performing very well and I am having issues because I have to move the field from the second itab to the first itab .

here is my code:

types: begin of t_local,
       kunnr type kunnr,
       parvw type vbpa-parvw,
       netwr type vbap-netwr,
       lfimg type lips-lfimg,
       vbtyp_n type vbfa-vbtyp_n,
  end of t_local .

  types: begin of t_local2,
         lfimg type lips-lfimg,
    end of t_local2 .

  data: gt_local type table of t_local,
        gs_local type t_local .
  data gt_local2 type table of t_local2 .
  data gs_local2 type t_local2 .

select-option s_kunnr for kna1-kunnr .

data idx type sy-tabix .
data gs_local3 type t_local .

SELECT b~kunnr c~kunnr b~parvw  SUM( a~netwr  ) as netwr
FROM vbap AS a INNER JOIN vbpa AS b ON ( a~vbeln = b~vbeln  )
  inner join kna1 as c on b~kunnr = c~kunnr
  INTO CORRESPONDING FIELDS OF TABLE gt_local
WHERE ( b~parvw = 'AG' and c~kunnr in s_kunnr )
  group by parvw c~kunnr b~kunnr.

  select  sum( d~lfimg ) as lfimg
  from vbpa as a inner join vbap as b on ( a~vbeln = b~vbeln )
     inner join vbfa as c on ( c~vbeln = b~vbeln  )
    inner join lips as d on ( d~vbeln = c~vbelv  )
    into corresponding fields of table gt_local
  where ( a~parvw = 'WE' )
   and a~kunnr in s_kunnr
*  and c~vbtyp_n = 'J'
   group by d~lfimg .

loop at gt_local2 into gs_local2 .
  idx = sy-tabix .
  read table gt_local into gs_local index idx .
   gs_local-lfimg = gs_local2-lfimg .
   append gs_local to gt_local .
  endloop.

1 REPLY 1

mmcisme1
Active Contributor
0 Kudos

What system are you on? You are assuming gt_local2 and gt_local have the same amount of records and are in the same place. Add kunnr your second select. If you are only using the table to read, create the gt_local table as a sorted table on kunnr. Look at your second join. I don't believe you need all those tables. After your read "with key kunnr = gs_local2-kunnr" check sy-subrc.