Skip to Content
avatar image
Former Member

how to insert one column of data into an existing internal table?

hello.

I already have an internal table with data inside it.

But now i want to insert one column of data into a field inside the internal table just now.

What should i do??

Thanks in advance.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

8 Answers

  • Best Answer
    avatar image
    Former Member
    May 02, 2008 at 09:45 AM

    Hi,

    I wish this example clarifies your doubt.

    First we create an internal table type with a field called 'unfilled' .

    This field will be filled separately after all the other fields get the data from a standard SAP table t001k.

    TYPES: BEGIN OF t_tabletype,

    bukrs TYPE bukrs,

    butxt TYPE butxt,

    unfilled(10) TYPE c,

    END OF t_tabletype.

    Creating an internal table of above table type.

    DATA: i_tabletype TYPE TABLE OF t_tabletype.

    Creating a workarea of the above internal table.

    DATA: wa_tabletype LIKE LINE OF i_tabletype.

    Populating the internal table i_tabletype from t001k.

    SELECT bukrs

    butxt

    INTO CORRESPONDING FIELDS OF TABLE i_tabletype

    FROM t001k.

    suppose you want to fill the field unfilled with your name.

    Then proceed as follows:

    LOOP AT i_tabletype INTO wa_tabletype.

    wa_tabletype-unfilled = 'Lim'.

    MODIFY i_tabletype FROm wa_tabletype INDEX sy-tabix TRANSPORTING unfilled.

    ENDLOOP.

    CLEAR wa_tabletype.

    Regards,

    Prosenjit.

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 02, 2008 at 09:10 AM

    My situation is like this:-

    ITAB_A got F1, F2, F3.

    ITAB_B got F2, F4.

    ITAB_OUTPUT got F1, F2, F3, F4.

    How am i going to move the F4's data into the output internal table ??

    Edited by: Jiansi Lim on May 2, 2008 11:11 AM

    Add comment
    10|10000 characters needed characters exceeded

    • assuming that F2 is a unique key of table ITAB_B:

      data: wa_output like line of itab_output.
      field-symbols: <fs_a> like line of itab_a.
      field-symbols: <fs_b> like line of itab_b.
      loop at itab_a assigning <fs_a>.
        clear wa_output.
        move-corresponding <fs_a> to wa_output.
        read table itab_b assigning <fs_b> with table key f2 = <fs_a>-f2.
        if sy-subrc = 0.
          move-corresponding <fs_b> to wa_output.
        endif.
        append wa_output to itab_output.
      endloop.
      

      ITAB_B must be declared as sorted table with unique key F2.

      Greetings

      Thomas

  • avatar image
    Former Member
    May 02, 2008 at 09:25 AM

    Hi Jainsi,

    Try this code.

    *******************************************************************

    data : lv_index type sy-tabix.

    loop at itab_output into wa_output.

    lv_index = sy-index.

    read itab_b into wa_itab_b where f2 eq wa_output-f2.

    if sy-subrc eq 0.

    move wa_itab_b-f4 to wa_output-f4.

    modify itab_output index lv_index

    from wa_output transporting f4.

    endif.

    endloop.

    *******************************************************************

    Hope this is helpful to you. If you need further information, revert back.

    Reward all the helpful answers.

    Regards

    Nagaraj T

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 02, 2008 at 06:09 AM

    hii ,

    u have to loop at that table and move that particular field into that particular corresponding field

    Add comment
    10|10000 characters needed characters exceeded

  • May 02, 2008 at 06:13 AM

    hi,

    loop at your internal table then transfer data into the column inside the loop then use modify <table name> index <loop index>.

    see this code as an example:

    data:
      ld_index type sytabix.
    
    loop at itab into wa_itab.
      move sy-tabix to ld_index.
    
      move 'test' to wa_itab-text.
    
      modify itab from wa_itab index ld_index.
    endloop.
    

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 02, 2008 at 06:16 AM

    does anyone has some sample coding??

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 02, 2008 at 06:16 AM

    Hi,

    Do one thing. Declare a work area of same structure as your internal table.

    Pass the value to be inserted in the column of the in the work area.

    Append the workarea to the internal table .

    Hope this helps.

    Regards

    Sourabh

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    May 02, 2008 at 10:32 AM

    Thanks guys,

    But my code still can not run well, bcz keep appear the runtime error, saying that in the MODIFY part there got error.

    the error is like this "Error in an ABAP/4 statement when processing an internal table."

    Anyone have any idea about this??

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Hi,

      As per my understanding say..u have 100records in ur internal table which is having 5 columns...but only 4 columns is filled up now..and now u need to populate values in tht 5th col for all those 100 records ..rite???

      field-symbols : <fs_output> type (type of itab_output)

      loop at itab_output ASSIGNING <fs_output>.

      read itab_b into wa_itab_b where f2 eq <fs_output>-f2.

      if sy-subrc eq 0.

      <fs_output>-f4 =wa_itab_b-f4

      endif.

      endloop.

      This way u can update the 4 column....

      Rewards if it really workds for u....

      Regards,

      ABAPer 007