Skip to Content
0
Feb 11, 2010 at 03:38 PM

Problem with Do and enddo loop

961 Views

Hello,

I have a following requirement for example:

Table: 'TADD' has 2 componets and below data:

AdressID Moveid

001

002 003

003 001

002 address makes a move to 003 and 003 makes a move to 001. I need to make the check in the below way.

Loop at address. It it has a move, then read the move address, keep looping until we get an address which has no move.

Finally I should sort lt_tadd in the below order.

lttadd_

001

003

002

I tired many things but nothing seems to work. Can anyone help me how this can be achieved? Do and enddo would help may be..

Edited by: Shwetha H S on Feb 11, 2010 4:41 PM

I tried this:

LOOP AT lt_tadd INTO ls_tadd WHERE moveid IS NOT INITIAL.

lv_addid = ls_tadd-moveid.

DO.

READ TABLE lt_tadd INTO ls_tadd1 WITH KEY addid = lv_addid.

READ TABLE lt_tadd_ins WITH KEY addid = ls_add1-moveid TRANSPORTING NO FIELDS.

IF sy-subrc = 0.

APPEND ls_add1 TO lt_add_ins.

ELSE.

IF ls_add1-moveid = space.

APPEND ls_add1 TO lt_add_ins.

EXIT.

ELSE.

lv_addid = ls_add1-moveid.

ENDIF.

ENDIF.

ENDDO.

ENDLOOP.

CLEAR ls_add.

LOOP AT lt_add_ins INTO ls_add.

DELETE lt_addWHERE bankid = ls_add-addid.

APPEND ls_addTO lt_add.

ENDLOOP.