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: 

modify contents in a table

Former Member
0 Kudos

Hi all,

I have a table 'tab' with some records and this table 'tab' has two keys. I want to read a particular record with the two keys(I have these two key values). This record has a field unit of measure which is always 'L' and I want to overwrite Unit of measure value to 'Kg' in that field and modify the table with that row entry.

How can I do this. Please help..... Waiting....

1 ACCEPTED SOLUTION

former_member184619
Active Contributor
0 Kudos

Hi Raju,

Do like tjis:-

read table itab with key key1 = ? key2 = ?.

itab-unit = 'KG'.

modify itab index sy-tabix.

Hope this helps.

Reward if helpful.

Regards

-


Sachin Dhingra

12 REPLIES 12

Former Member
0 Kudos

READ TABLE TAB WITH KEY KEY1 = VALUE1

KEY2 = VALUE2.

IF SY-SUBRC EQ 0.

UOMFIELD = 'KG'.

MODIFY TAB.

ENDIF.

laxmanakumar_appana
Active Contributor
0 Kudos

Hi,

Check this code :

select fld1 fld2 form Ztable into table i_tab.

loop at i_tab where fld1 = <val1> and
                    fld2 = <val2>.
 i_tab-fld2 = 'kg'.
 modify i_tab.
endloop.
 
Changed code : 

<b>
loop at i_tab where unit = 'L'.

 i_tab-unit = 'kg'.
 modify i_tab.

endloop.</b>



modify ztable from table i_tab.

Regards

Appana

*Reward Points for helpful answers

Message was edited by: L Appana

0 Kudos

Hi Guys,

Thanks for the replies. I will show how my table looks like

key1 key2 name unit amount

-


1 2 asd P 100.00

3 4 ash L 200.00

5 6 adsf P 300.00

-


Let us say I have the key values 3 and 4. Here I want to read the record with keys 3 and 4 and overwrite the value 'L' in the field of the record with 'Kg' and modify the table with that record. SO modified table should look like....

key1 key2 name unit amount

-


1 2 asd P 100.00

3 4 ash Kg 200.00

5 6 adsf P 300.00

-


Please help. Waiting for replies......

0 Kudos

Sorry I have formatting problems. here is my table

key1 | key2 | name | unit |amount

-


1 | 2 | asd | P | 100.00

3 | 4 | ash | L | 200.00

5 | 6 | adsf | P |300.00

-


I want the table to be modifed as

key1 | key2 | name | unit |amount

-


1 | 2 | asd | P | 100.00

3 | 4 | ash | Kg | 200.00

5 | 6 | adsf | P |300.00

-


0 Kudos

Again, is it internal table?

0 Kudos

Use te code button above and enclose your lines between the tags to keep the format intact.

0 Kudos

Hi,

It is an internal table. Waiting.....

0 Kudos

In that case all you have to do is as follows


CLEAR itab-unit.
itab-unit = 'KG'.
MODIFY itab TRANSPORTING unit WHERE unit = 'L'.

0 Kudos

read table ITAB with key KEY1 = 3

KEY2 = 4.

IF SY-SUBRC = 0.

ITAB-NAME = 'KG'.

MODIFY ITAB INDEX SY-TABIX TRANSPORTING NAME.

ENDIF.

Regards

Srikanth.

Former Member
0 Kudos

Are you talking about internal table or database table? It looks like you are talking about database table. Is it standard SAP or custom table? If it is standard SAP table, I don't suggest you modify them this way. Let us know the table name. If it is custom table, you are saying that it has two key fields key1 and key2, let us say. Is UOM one of them or is it a non-key field?

former_member184619
Active Contributor
0 Kudos

Hi Raju,

Do like tjis:-

read table itab with key key1 = ? key2 = ?.

itab-unit = 'KG'.

modify itab index sy-tabix.

Hope this helps.

Reward if helpful.

Regards

-


Sachin Dhingra

Former Member
0 Kudos

Hi Raju,

Let this be internal table it_test

key1 | key2 | name | unit |amount
------------------------------------
1 | 2 | asd  | P | 100.00
3 | 4 | ash  | L | 200.00
5 | 6 | adsf | P |300.00
-------------------------------------

Lets assume that ( name = L ) can occur mulitple times

for different records in the internal table.

Then add this chunk of code to modify the contents of the field name form <b>L</b> to <b>Kg</b>.


LOOP AT it_test WHERE name = 'L'.

  it_test-name = 'Kg'.

  MODIFY it_test INDEX sy-tabix TRANSPORTING name.

ENDLOOP.

Regards,

AS