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: 

help with small logic

Former Member
0 Kudos

Hi all,

I have an internal with more than 10000 records.

I have data like this

id matnr test

A M1

B M2

C M3

D M4

D M5

C M6

A M7

B M8

NOW I WANT TO SECT TEST A VALUE BASED ON ID

IF ID = A then test = 1

IF ID = B then test = 2

IF ID = C then test = 3

IF ID = D then test = 4

NOW MY OUTPUT SHOULD LIKE THIS

id matnr test

A M1 1

B M2 2

C M3 3

D M4 4

D M5 4

C M6 3

A M7 1

B M8 2

i DON'T WANT TO LOOP AND MODIFY EACH RECORD BY CHECKING.

Is there any statment that would single attempt i.e set test = 1 for all id = A in a single step and another single step for id = B

i did like this

teMP = 1.

modify table itab transporting teMP where id = 'A'.

teMP = 2.

modify table itab transporting temp where id = 'B'.

I know its wrong but iam looking something like this

Thanks

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can only do with MODIFY statement as you did. if you want in a single statement.

Regards

Rani.

6 REPLIES 6

Former Member
0 Kudos

without looping i think it's not possible to update internal table.

Regards

Vasu

Former Member
0 Kudos

Hi,

You can only do with MODIFY statement as you did. if you want in a single statement.

Regards

Rani.

Former Member
0 Kudos

hi do like this,

itab1[] = itab[].

delete adjacent duplicates from itab1 comparing id.

loop at itab.

read table itab1 with key itab1-id = itab-id.

if sy-subrc EQ 0.

l_index = sy-tabix.

endif.

itab-itab-test = l_index.

modify itab.

endloop.

reward if helpful

Former Member
0 Kudos

Hi,

U cannot Modify the Internal Table without Loop.

Try this,

Loop at itab.

If itab-id = 'A'.

temp = 1.

elseif itab-id = 'B'.

temp = 2.

elseif itab-id = 'C'.

temp = 3.

elseif itab-id = 'D'.

temp = 4.

endif.

modify table itab transporting temp .

endloop.

Regards,

Padmam.

Former Member
0 Kudos

Hi

Please check the following code

Regards

MD

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

TYPES : begin of TAB,

id(10),

matnr type matnr,

id1 type I,

end of TAB.

DATA : ITAB1 TYPE TABLE OF TAB.

DATA : WA_ITAB1 TYPE TAB.

WA_itab1-id = 'A'.

WA_ITAB1-matnr = 'Matnr1'.

append WA_ITAB1 TO itab1.

WA_ITAB1-id = 'B'.

WA_ITAB1-matnr = 'Matnr2'.

append WA_ITAB1 TO itab1.

WA_ITAB1-id = 'A'.

WA_ITAB1-matnr = 'Matnr3'.

append WA_ITAB1 TO itab1.

WA_ITAB1-id = 'C'.

WA_ITAB1-matnr = 'Matnr1'.

append WA_ITAB1 TO itab1.

CLEAR WA_ITAB1.

WA_ITAB1-ID1 = '1'.

MODIFY ITAB1 FROM WA_ITAB1 TRANSPORTING ID1 WHERE ID = 'A'.

WA_ITAB1-ID1 = '2'.

MODIFY ITAB1 FROM WA_ITAB1 TRANSPORTING ID1 WHERE ID = 'B'.

WA_ITAB1-ID1 = '3'.

MODIFY ITAB1 FROM WA_ITAB1 TRANSPORTING ID1 WHERE ID = 'C'.

LOOP AT ITAB1 INTO WA_ITAB1.

WRITE : / WA_ITAB1-ID,

WA_ITAB1-MATNR,

WA_ITAB1-ID1.

ENDLOOP.

Former Member
0 Kudos

Hi,

Try this,

clear wa_itab.

wa_itab-id = 'A'.

wa_itab-test = 1.

modify table itab from wa_itab transporting test where id = 'A'.

clear wa_itab.

wa_itab-id = 'B'.

wa_itab-test = 2.

modify table itab from wa_itab transporting test where id = 'B'.

clear wa_itab.

wa_itab-id = 'C'.

wa_itab-test = 3.

modify table itab from wa_itab transporting test where id = 'C'.

clear wa_itab.

wa_itab-id = 'D'.

wa_itab-test = 4.

modify table itab from wa_itab transporting test where id = 'D'.

Reward if useful.

Thanks,

Muthu.