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: 

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

Former Member
0 Kudos

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.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

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.

12 REPLIES 12

Former Member
0 Kudos

hii ,

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

peter_ruiz2
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

does anyone has some sample coding??

Former Member
0 Kudos

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

Former Member
0 Kudos

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

0 Kudos

Hi Jiansi,

Try this..

loop at itab_a into wa_itab_a .

read itab_b into wa_itab_b where f2 eq wa_itab_a-f2.

if sy-subrc eq 0.

move f4 to wa_itab_output-f4.

modify itab_output from wa_itab_output transporting f4.

endif.

endloop.

Regards,

Chitra

0 Kudos

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

Former Member
0 Kudos

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

Former Member
0 Kudos

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.

Former Member
0 Kudos

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??

0 Kudos

Hi Jiansi,

You have to use TRANSPORTING <fieldname> in the modify statement .

Regards,

Chitra

0 Kudos

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