REPORT demo_flow_control_do .


DO.

  WRITE sy-index.
  IF sy-index = 3.
    EXIT.
  ENDIF.
ENDDO.

SKIP.
ULINE.

* do n times

DO 2 TIMES.
  WRITE sy-index.
  SKIP.
  DO 3 TIMES.
    WRITE sy-index.
  ENDDO.
  SKIP.
ENDDO.

SKIP.
ULINE.

* varying

DATA: BEGIN OF text,
        word1(4) TYPE c VALUE 'This',
        word2(4) TYPE c VALUE 'is',
        word3(4) TYPE c VALUE 'a',
        word4(4) TYPE c VALUE 'loop',
      END OF text.

DATA: string1(4) TYPE c, string2(4) TYPE c.

DO 4 TIMES VARYING string1 FROM text-word1 NEXT text-word2.
  WRITE string1.
  IF string1 = 'is'.
    string1 = 'was'.
  ENDIF.
ENDDO.

SKIP.

DO 2 TIMES VARYING string1 FROM text-word1 NEXT text-word3
           VARYING string2 FROM text-word2 NEXT text-word4.
  WRITE: string1, string2.
ENDDO.



Serkan AKKAVAK
Computer Engineer
ABAP Developer & SAP S/4 HANA Logistics Team Lead
Contact : serkurumsal@yandex.com