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: 

help on internal table

Former Member
0 Kudos

Hi all,

I have an internal table gt_data with all required fields

to display.

for that table gt_data data comes from 3 other internal tables(lt_data, st_data, mt_data).

First i will move data fromlt_data and st_data as they are related.Upto now data is correct in gt_data.

When i move the data from mt_data to gt_data then gt_data

contains data which is not correct.

Please kindly help me.

Here is the code.


  SELECT mara~matkl lips~vgbel lips~vgpos likp~vkorg lips~prodh
  likp~kunnr  lips~matnr  likp~wadat  lips~lfimg
     vbrp~netwr FROM lips JOIN likp ON likp~vbeln = lips~vbeln
                          JOIN mara ON lips~matnr = mara~matnr

                            JOIN vbrp ON vbrp~vgbel = lips~vbeln AND
                                         vbrp~vgpos = lips~posnr INTO
  CORRESPONDING FIELDS OF TABLE mt_data WHERE likp~vkorg IN s_vkorg AND
                                              likp~kunnr IN s_kunnr AND
                                              lips~matnr IN s_matnr AND
                                              mara~matkl IN s_matkl AND
                                              lips~prodh IN s_prodh AND
                                              lips~werks IN s_werks AND
                     ( likp~vbtyp = 'C' OR  likp~vbtyp = 'D' OR
  likp~vbtyp
   = 'J' OR likp~vbtyp = 'E' OR likp~vbtyp = 'F' ) AND
                                                likp~wadat = p_datum.

  LOOP AT mt_data.
  
    MOVE-CORRESPONDING mt_data TO gt_data.
    MOVE mt_data-wadat TO gt_data-mbdat.


  COLLECT gt_data.

  ENDLOOP.

before this code i have data in gt_data(from st_data and lt_data) which is correct.

My requirement is just to add the mt_data into gt_data without disturbing previous data in gt_data.

regards.

chandu

1 ACCEPTED SOLUTION

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

By using the COLLECT statement, you are saying that if there is a record in gt_data that has the same "key" as MT_data, then add the numeric values together and update that record. This is your problem. You need to use APPEND here. If you need an aggregate of MT_DATA, you must first move that into another internal tabe and COLLECT it, then loop at that one and APPEND to GT_DATA.

Make sense?

Regards,

Rich Heilman

6 REPLIES 6

former_member181962
Active Contributor
0 Kudos

Try to use read statement in the loop.

LOOP AT mt_data.

<b>read table gt_data with key <Condition with common field>.

if sy-subrc = 0.

MOVE-CORRESPONDING mt_data TO gt_data.

MOVE mt_data-wadat TO gt_data-mbdat.

COLLECT gt_data.

endif.</b>

ENDLOOP.

Regards,

Ravi

Former Member
0 Kudos

Use below code

data : v_tabix like sy-tabix.

LOOP AT mt_data.

v_tabix = sy-tabix.

MOVE-CORRESPONDING mt_data TO gt_data.

MOVE mt_data-wadat TO gt_data-mbdat.

modify gt_data index v_tabix.

clear : mt_data, gt_data.

ENDLOOP.

Pl. award appropriate points if helpful.

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

By using the COLLECT statement, you are saying that if there is a record in gt_data that has the same "key" as MT_data, then add the numeric values together and update that record. This is your problem. You need to use APPEND here. If you need an aggregate of MT_DATA, you must first move that into another internal tabe and COLLECT it, then loop at that one and APPEND to GT_DATA.

Make sense?

Regards,

Rich Heilman

christian_wohlfahrt
Active Contributor
0 Kudos

Hi Chandu!

Do you want to summarize values or to append additional lines into gt_data.

In case you need sums, then stay with collect gt_data.

But otherwise use append gt_data in loop over mt_data.

If you just want to update specific fields, then you should use modify ... transporting fields ... and give the required fields.

Regards,

Christian

Former Member
0 Kudos

Hi ,

Collect will work properly only if the stucture of these two tables is similar and the fields other than the ones you need to add are all character fields.

Are these conditions satisfied in your case?

Thanks & Regards,

Vanita.

0 Kudos

Hi all,

As usual you guys are excellent.

Thanks and regards

chandu