Application Development and Automation 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: 
Read only

Add Value to internal table

Former Member
0 Likes
9,658

Hi,

How i can Add a value to internal table e.g.

i have table like that :

f_name field1

aaa          001
aaa          002
aaa          003
bbb          001
bbb          002
bbb          003
ccc           001
ccc           002
ccc           003

i want to add to table new row with name and number 000

field_name    field1
aaa               000
aaa               001
aaa               002
aaa               003
bbb               000
bbb               001
bbb               002
bbb               003
ccc                000
ccc                001
ccc                002
ccc                003

Regards

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
4,727

hi,

take one more internal table itab2.

Loop at itab1.

at end of f_name.

itab2-fname = f_name.

itab2-number = '000'.

append itab2.

endat.

endloop.

append itab2 from itab2.

sort itab2 by f_name number,

Hi,

How i can Add a value to internal table e.g.

i have table like that :

f_name field1

aaa          001
aaa          002
aaa          003
bbb          001
bbb          002
bbb          003
ccc           001
ccc           002
ccc           003

i want to add to table new row with name and number 000

field_name    field1
aaa               000
aaa               001
aaa               002
aaa               003
bbb               000
bbb               001
bbb               002
bbb               003
ccc                000
ccc                001
ccc                002
ccc                003

Regards

9 REPLIES 9
Read only

Former Member
0 Likes
4,727

Hi,

internal table => Append or Collect itab

DB-table => Modify table

Regards

Nicole

Read only

Former Member
0 Likes
4,728

hi,

take one more internal table itab2.

Loop at itab1.

at end of f_name.

itab2-fname = f_name.

itab2-number = '000'.

append itab2.

endat.

endloop.

append itab2 from itab2.

sort itab2 by f_name number,

Read only

Former Member
0 Likes
4,727

Hi,

Populate the data in Itab header.Write an INSERT with index = 1. You will get the data as the first record in Itab.

Thanks,

Vivekanand

Read only

former_member156446
Active Contributor
0 Likes
4,727

you need to populate the wa_itab with values you want and use append statment.

append tvbdpl to z_tvbdpl.~~ append wa_itab to itab

Read only

Former Member
0 Likes
4,727

loop at itab into wa.

if wa-field_name ne temp.

wa-field1 = 000.

insert wa into itab index sy-tabix.

endif.

wa-field_name = temp.

endloop.

Read only

former_member203501
Active Contributor
0 Likes
4,727

data: begin of itab occurs 0,

field1 type char10 ,

field2 type i,

end of itab .

itab-field1 = 'test1'.

itab-field2 = '01'.

append itab .

itab-field1 = 'test2'.

itab-field2 = '02'.

append itab .

loop at itab .

write:/ itab-field1 ,

itab-field2 .

endloop .

Read only

Former Member
0 Likes
4,727

Hi,

try doing like this:


data: g_field1 type field1,
i_tab_temp type table of.................      "declare one more internal table like i_tab
wa_itab_temp like line of i_tab_temp.     "declare one more WA for the internal table.

loop at i_tab into wa_itab.
if g_field1 is initial.
  g_field1 = wa_itab-field1.
  wa_itab_temp-field1 = wa_itab-field1.
  wa_itab_temp-field2 =  '000'.
  append wa_tab_temp to i_tab_temp. 
endif.
if wa_tab-field1 = g_field.
   wa_itab_temp-field1 = wa_itab-field1.
  wa_itab_temp-field2 =   wa_itab-field1.
  append wa_tab_temp to i_tab_temp. 
else.
g_field1 = wa_itab-field1.
  wa_itab_temp-field1 = wa_itab-field1.
  wa_itab_temp-field2 =  '000'.
  append wa_tab_temp to i_tab_temp. 
endif.
endloop.

So i_tab_temp will be your final table if you want you can refresh i_tab.

Regards,

Neha

Read only

Former Member
0 Likes
4,727

Hi,

You should consider using a table type SORTED table. Then if you use the INSERT statement, The line will be inserted into the table according to the table key.

Or you can think of appending all the lines and then later sorting the table by the 2 fields of the internal table will give you the expected result.

regards,

Advait

Read only

Former Member
0 Likes
4,727

Hi Vijay,

Simple way is, append the records to internal table as normal way & sort on the first field.

You will get the entries in the desired format.

-Sujatha