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

How to modify table record inside the loop

Former Member
0 Likes
1,387

Hi all,

I have a problem which is to be solved urgently.

Please help me out.

I am using hashed table (which i should), and i am in the loop. for some records i have to modify the records in the table. but while i am calling modify it is going to dump.

the code is like this.

LOOP AT t_bsisbsas.

READ TABLE t_bsidbsad6

WITH KEY bukrs = t_bsisbsas-bukrs

gjahr = t_bsisbsas-gjahr

belnr = t_bsisbsas-belnr.

IF sy-subrc EQ 0.

t_bsisbsas-kunnr = t_bsidbsad6-kunnr.

t_bsisbsas-maber = t_bsidbsad6-maber.

MODIFY t_bsisbsas TRANSPORTING maber kunnr.

CLEAR t_bsisbsas.

ELSE.

READ TABLE t_bsidbsad_ob6

WITH KEY bukrs = t_bsisbsas-bukrs

gjahr = t_bsisbsas-gjahr

belnr = t_bsisbsas-belnr.

IF sy-subrc EQ 0.

t_bsisbsas-kunnr = t_bsidbsad_ob6-kunnr.

t_bsisbsas-maber = t_bsidbsad_ob6-maber.

MODIFY t_bsisbsas TRANSPORTING maber kunnr.

CLEAR t_bsisbsas.

ENDIF.

ENDIF.

ENDLOOP.

Thanks in advance,

Umesh Vaidya

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,348

change the modify statement like this and try

MODIFY <b>table</b> t_bsisbsas TRANSPORTING maber kunnr.

or

13 REPLIES 13
Read only

Former Member
0 Likes
1,348

1)READ TABLE t_bsidbsad6

WITH <b>table</b> KEY bukrs = t_bsisbsas-bukrs

<b>note.---</b>

HASHED table will not differ in anyway id doing any operations on the table as compared to a standard table. The difference lies in when you have a READ statement the system internally uses a HASH key which will improve the performance.

use like thta..

ex...

read table i_droplist

with table key gpart = p_gpart

vkont = p_vkont.

Read only

Former Member
0 Likes
1,348

Thanks Kishan,

i want to modify the record for which i am in a loop.

please look at code , where i have put "modify".

I am getting dump at there.

Thanks

Umesh Vaidya

Read only

Former Member
0 Likes
1,349

change the modify statement like this and try

MODIFY <b>table</b> t_bsisbsas TRANSPORTING maber kunnr.

or

Read only

Former Member
0 Likes
1,348

Hello Umesh,

When u r modifying an hashed table u should not use key tables in the transportation addition.

<b>You may not use a key field as a TRANSPORTING field with HASHED or SORTED tables.</b>

If useful reward.

Vasanth

Read only

0 Likes
1,348
LOOP AT t_bsisbsas.
READ TABLE t_bsidbsad6
WITH table KEY bukrs = t_bsisbsas-bukrs
gjahr = t_bsisbsas-gjahr
belnr = t_bsisbsas-belnr.
IF sy-subrc EQ 0.
t_bsisbsas-kunnr = t_bsidbsad6-kunnr.
t_bsisbsas-maber = t_bsidbsad6-maber.
MODIFY table t_bsisbsas TRANSPORTING maber kunnr.
CLEAR t_bsisbsas.
ELSE.
READ TABLE t_bsidbsad_ob6
WITH table  KEY bukrs = t_bsisbsas-bukrs
gjahr = t_bsisbsas-gjahr
belnr = t_bsisbsas-belnr.
IF sy-subrc EQ 0.
t_bsisbsas-kunnr = t_bsidbsad_ob6-kunnr.
t_bsisbsas-maber = t_bsidbsad_ob6-maber.
MODIFY table t_bsisbsas TRANSPORTING maber kunnr.
CLEAR t_bsisbsas.
ENDIF.
ENDIF.
ENDLOOP.
Read only

Former Member
0 Likes
1,348

or

you have to use where condition

MODIFY itab TRANSPORTING f1 ... fn WHERE cond.

Read only

Former Member
0 Likes
1,348

Hi Umesh,

try this:

LOOP AT t_bsisbsas.

<b>idx = sy-tabix.</b>

READ TABLE t_bsidbsad6

WITH KEY bukrs = t_bsisbsas-bukrs

gjahr = t_bsisbsas-gjahr

belnr = t_bsisbsas-belnr.

IF sy-subrc EQ 0.

t_bsisbsas-kunnr = t_bsidbsad6-kunnr.

t_bsisbsas-maber = t_bsidbsad6-maber.

<b>MODIFY t_bsisbsas TRANSPORTING maber kunnr index idx.</b>

CLEAR t_bsisbsas.

ELSE.

READ TABLE t_bsidbsad_ob6

WITH KEY bukrs = t_bsisbsas-bukrs

gjahr = t_bsisbsas-gjahr

belnr = t_bsisbsas-belnr.

IF sy-subrc EQ 0.

t_bsisbsas-kunnr = t_bsidbsad_ob6-kunnr.

t_bsisbsas-maber = t_bsidbsad_ob6-maber.

<b>MODIFY t_bsisbsas TRANSPORTING maber kunnr index idx.</b>

CLEAR t_bsisbsas.

ENDIF.

ENDIF.

ENDLOOP.

Regards, Dieter

Read only

0 Likes
1,348

Thanks,

but i am using hashed table as i mentioned.

i got the solution.

I have to use

"modify table <tab_name> from <wa> transporting f1,..fn"

Thanks for the answer

Umesh

Read only

anversha_s
Active Contributor
0 Likes
1,348

hi,

chnage ur code like this.

LOOP AT t_bsisbsas.

READ TABLE t_bsidbsad6

WITH <b>TABLE</b> KEY bukrs = t_bsisbsas-bukrs

gjahr = t_bsisbsas-gjahr

belnr = t_bsisbsas-belnr.

IF sy-subrc EQ 0.

t_bsisbsas-kunnr = t_bsidbsad6-kunnr.

t_bsisbsas-maber = t_bsidbsad6-maber.

ELSE.

READ TABLE t_bsidbsad_ob6

WITH <b>TABLE</b> KEY bukrs = t_bsisbsas-bukrs

gjahr = t_bsisbsas-gjahr

belnr = t_bsisbsas-belnr.

IF sy-subrc EQ 0.

t_bsisbsas-kunnr = t_bsidbsad_ob6-kunnr.

t_bsisbsas-maber = t_bsidbsad_ob6-maber.

ENDIF.

ENDIF.

MODIFY t_bsisbsas TRANSPORTING maber kunnr.

CLEAR t_bsisbsas.

ENDLOOP.

rgds

anver

Read only

Former Member
0 Likes
1,348

Hi umesh,

1. Minor mistake

2. The problem is with tabix,

which gets modified with the latest value,

when READ is done.

3. so do like this.

4.

<b>DATA : TABIX LIKE SY-TABIX.</b>

LOOP AT t_bsisbsas.

TABIX = SY-TABIX.

******

MODIFY t_bsisbsas <b>INDEX TABIX.</b>

******

MODIFY t_bsisbsas <b>INDEX TABIX.</b>

ENDLOOP.

regards,

amit m.

Read only

0 Likes
1,348

Thanks Amit for your answer.

But I am using hashed table, where you cant use explicit/implicit index mechanism.

I got the answer from chandrashekar jagarlamudi.

i have to use

"modify table <tab_name> from <wa> transporting f1,...fn."

Thanks

Umesh Vaidya

Read only

Former Member
0 Likes
1,348

Hi,

LOOP AT t_bsisbsas.

READ TABLE t_bsidbsad6

WITH KEY bukrs = t_bsisbsas-bukrs

gjahr = t_bsisbsas-gjahr

belnr = t_bsisbsas-belnr.

IF sy-subrc EQ 0.

t_bsisbsas-kunnr = t_bsidbsad6-kunnr.

t_bsisbsas-maber = t_bsidbsad6-maber.

<b>MODIFY t_bsisbsas .</b>CLEAR t_bsisbsas.

ELSE.

READ TABLE t_bsidbsad_ob6

WITH KEY bukrs = t_bsisbsas-bukrs

gjahr = t_bsisbsas-gjahr

belnr = t_bsisbsas-belnr.

IF sy-subrc EQ 0.

t_bsisbsas-kunnr = t_bsidbsad_ob6-kunnr.

t_bsisbsas-maber = t_bsidbsad_ob6-maber.

<b>MODIFY t_bsisbsas .</b>

CLEAR t_bsisbsas.

ENDIF.

ENDIF.

ENDLOOP.

use modify itab index sy-tabix.

Regards

amole

Read only

0 Likes
1,348

Thanks Amole for your answer.

But I am using hashed table, where you cant use explicit/implicit index mechanism.

I got the answer from chandrashekar jagarlamudi.

i have to use

"modify table <tab_name> from <wa> transporting f1,...fn."

Thanks

Umesh Vaidya