Skip to Content

Problem with Do and enddo loop

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.

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on Feb 11, 2010 at 05:05 PM

    Hi Swetha,

    i assumed, that your table does have more then these entries and might come in different order too.

    So, you would have to look, not only for predecessors, bur maybe for successors too. As well i took for granted, that you wouldn't like to process the same sequence of adress-ids more than once. So this is what i'd do, using recursions.

    regards

    Jörg

    DATA: h_idx TYPE i.
    DO.
      h_idx = 2.
      READ TABLE lt_tadd INTO ls_tadd INDEX 1.
      IF sy-subrc NE 0.
        EXIT.
      ENDIF.
      DELETE lt_tadd INDEX 1.
      insert ls_tadd into lt_tadd_ins index 1.
      PERFORM get_pred USING ls_tadd-addid.
      PERFORM get_succ USING ls_tadd-movid.
    ENDDO.
    lt_tadd = lt_tadd_ins.
    
    **********************************************************************
    * FORM    :  get_pred
    * Created :  11.02.2010 17:17:10
    **********************************************************************
    FORM get_pred USING value(p_add).
      DATA: ls_ltadd LIKE LINE OF lt_tadd.
      READ TABLE lt_tadd WITH KEY movid = p_add INTO ls_tadd.
      IF sy-subrc EQ 0.
    *    predecessor exists.
        DELETE lt_tadd INDEX sy-tabix.
        INSERT ls_tadd INTO lt_tadd_ins INDEX h_idx.
        ADD 1 TO h_idx.
        PERFORM get_pred USING ls_tadd-addid.
      ENDIF.
    ENDFORM. "get_pred
    *&---------------------------------------------------------------------*
    *&      Form  get_succ
    *&---------------------------------------------------------------------*
    *       text
    *----------------------------------------------------------------------*
    *      -->VALUE(P_MOV)  text
    *----------------------------------------------------------------------*
    FORM get_succ USING value(p_mov).
      DATA: ls_ltadd LIKE LINE OF lt_tadd.
      READ TABLE lt_tadd WITH KEY addid = p_mov INTO ls_tadd.
      IF sy-subrc EQ 0.
    *    successor exists.
        DELETE lt_tadd INDEX sy-tabix.
        INSERT ls_tadd INTO lt_tadd_ins INDEX 1.
        CHECK ls_tadd-movid IS NOT INITIAL.
        PERFORM get_succ USING ls_tadd-movid.
      ENDIF.
    ENDFORM. "get_pred
    

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 11, 2010 at 03:48 PM

    Hello,

    Check the logic below:

    read Itab where Address is not inital and Move is not inital.
    if sy-subrc = 0.
    fill in itab1.
    DO.
    read table itab where address = move.
    if sy.subrc = 0.
    fill in the itab1.
    else.
    exit.
    endif.
    ENDDO.
    endif.
    

    Best Regards,

    Sasidhar Reddy Malti

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 11, 2010 at 04:00 PM

    Hi,

    Sort your it_addr table by move id and address id in ascending order. now your address id are sorted in way you want.

    rgds,

    PB

    Edited by: PBHATT on Feb 11, 2010 10:00 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on Feb 11, 2010 at 06:28 PM

    Try this,

    its not tested.

    here instead of write statement move it to a itab

    lv_flag = 'X'.

    loop at itab.

    if lv_flag = 'X'.

    lv_address_id = itab-address_id.

    lv_flag = ' '.

    endif.

    write / itab-address_id.

    if itab-move_id = lv_address_id.

    lv_flag = 'X'.

    skip 1.

    write: '______________________'.

    endif.

    endloop.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.