Skip to Content
author's profile photo Former Member
Former Member

help on internal table

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

5 Answers

  • Best Answer
    Posted on Dec 09, 2005 at 02:53 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 09, 2005 at 02:51 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2005 at 02:52 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 09, 2005 at 02:56 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Dec 09, 2005 at 02:53 PM

    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

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.