Skip to Content
author's profile photo
Former Member

help with small logic

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

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

6 Answers

  • Best Answer
    author's profile photo
    Former Member
    Oct 11, 2007 at 01:33 PM

    Hi,

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

    Regards

    Rani.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 11, 2007 at 01:31 PM

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

    Regards

    Vasu

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 11, 2007 at 01:43 PM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 11, 2007 at 01:54 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

  • author's profile photo
    Former Member
    Oct 11, 2007 at 02:05 PM

    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.

                    Add comment
                    10|10000 characters needed characters exceeded

                  • author's profile photo
                    Former Member
                    Oct 11, 2007 at 02:09 PM

                    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.

                    Add comment
                    10|10000 characters needed characters exceeded