๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿง‘‍๐Ÿ’ผ SAP/ABAP

[SAP ABAP] LOOP ~ ENDLOOP / DO ~ ENDDO / WHILE ~ ENDWHILE ๋ฐ˜๋ณต๋ฌธ ์‚ฌ์šฉ๋ฒ• (List ํ™œ์šฉ)

by Jay Din 2023. 8. 22.
728x90
๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

๋ฐ˜๋ณต๋ฌธ ์ข…๋ฅ˜

ABAP ํ”„๋กœ๊ทธ๋žจ์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ์ˆœํ™˜ ๋ฐ˜๋ณต ๊ตฌ๋ฌธ์€ 3๊ฐ€์ง€๊ฐ€ ์žˆ์Šต๋‹ˆ๋‹ค.

  • DO ~ ENDDO ์ˆœํ™˜ ๊ตฌ๋ฌธ
  • WHILE ~ ENDWHILE ์ˆœํ™˜ ๊ตฌ๋ฌธ
  • LOOP ~ ENDLOOP ์ˆœํ™˜ ๊ตฌ๋ฌธ

 

๋ฐ˜๋ณต๋ฌธ ๋‚ด ๋ช…๋ น์–ด ์ข…๋ฅ˜

EXIT ์ˆœํ™˜ ๊ตฌ๋ฌธ ๋‚ด์—์„œ EXIT ๋ช…๋ น์„ ๋งŒ๋‚˜๋ฉด ์ˆœํ™˜ ๊ตฌ๋ฌธ์„ ๋น ์ ธ๋‚˜์˜ต๋‹ˆ๋‹ค.
CONTINUE CONTINUE ๋ช…๋ น์„ ๋งŒ๋‚˜๋ฉด ์ดํ›„ ํฌ๋ฆฝํŠธ๋ฅผ ์‹คํ–‰ํ•˜์ง€ ์•Š๊ณ  ๋‹ค์Œ ์ˆœํ™˜์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.
CHECK CHECK ๋ช…๋ น์€ ๊ฐ’์„ ๋น„๊ตํ•˜์—ฌ ์ฐธ์ผ ๊ฒฝ์šฐ์—๋งŒ ์ดํ›„ ๊ตฌ๋ฌธ์„ ์ˆ˜ํ–‰ํ•˜๊ณ  ๊ฑฐ์ง“์ด๋ฉด ๋‹ค์Œ ์ˆœํ™˜์„ ์‹คํ–‰ํ•ฉ๋‹ˆ๋‹ค.

 

DO ~ ENDDO ๋ฐ˜๋ณต๋ฌธ

  • ์ˆœํ™˜ ํšŸ์ˆ˜๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋Š” ๊ตฌ๋ฌธ์ž…๋‹ˆ๋‹ค. ํšŸ์ˆ˜๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ๋ฌดํ•œ LOOP๋ฅผ ์ˆ˜ํ–‰ํ•ฉ๋‹ˆ๋‹ค.
  • ํ˜„์žฌ ์ˆœํ™˜ ํšŸ์ˆ˜๋Š” ์‹œ์Šคํ…œ ๋ณ€์ˆ˜ SY-INDEX์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
DO 3 TIMES.
	~~~
ENDDO.

์˜ˆ์ œ

DO 4 TIMES.
  WRITE / SY-INDEX.
ENDDO.

 

WHILE ~ ENDWHILE ๋ฐ˜๋ณต๋ฌธ

  • WHILE ๊ตฌ๋ฌธ์˜ ๋‹ค์Œ์˜ ํ‘œํ˜„์‹์ด ์ฐธ์ด๋ฉด ๋ฐ˜๋ณต์ˆœํ™˜์„ ์ง€์†ํ•ฉ๋‹ˆ๋‹ค.
  • ํ˜„์žฌ ์ˆœํ™˜ ํšŸ์ˆ˜๋Š” ์‹œ์Šคํ…œ ๋ณ€์ˆ˜ SY-INDEX์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค.
WHILE gv_flag = 'X'.
	~~~
ENDWHILE.

์˜ˆ์ œ

DATA: NUM TYPE I VALUE 5,
      STR(10) TYPE C VALUE 'X'.

WHILE STR = 'X'.
  WRITE: / SY-INDEX.
  IF SY-INDEX > NUM.
    WRITE: / 'SY-INDEX > num -> STOP'.
    STR = 'A'.
  ENDIF.
ENDWHILE.

 

LOOP ~ ENDLOOP ๋ฐ˜๋ณต๋ฌธ

  • ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์˜ ๋ผ์ธ์„ ์ฐจ๋ก€๋Œ€๋กœ Work Area ๋˜๋Š” Header Line์œผ๋กœ ์ด๋™ํ•˜๋Š” ๋ฐ˜๋ณต๋ฌธ์ž…๋‹ˆ๋‹ค.
  • ํ˜„์žฌ ์ˆœํ™˜ ํšŸ์ˆ˜๋Š” ์‹œ์Šคํ…œ ๋ณ€์ˆ˜ SY-TABIX์— ์ €์žฅ๋ฉ๋‹ˆ๋‹ค. SY-TABIX๋Š” ์ธํ„ฐ๋„ ํ…Œ์ด๋ธ”์˜ ๋ผ์ธ ๋ฒˆํ˜ธ์ž…๋‹ˆ๋‹ค.
LOOP AT qt itab TO qs wa.
	~~~
ENDLOOP.

์˜ˆ์ œ๋ฅผ ๋งŒ๋“ค์ง€ ๋ชปํ–ˆ์Šต๋‹ˆ๋‹ค. ์ข‹์€ ์˜ˆ์ œ ์žˆ๋Š” ๋ถ„์€ ๋Œ“๊ธ€ ๋ถ€ํƒ๋“œ๋ ค์š”

 

๋ฐ˜์‘ํ˜•

 

๋ฐ˜์‘ํ˜•

LIST๋ฅผ ์ด์šฉํ•œ Subroutine ํ˜ธ์ถœ

๋‹ค์Œ ๊ตฌ๋ฌธ๊ณผ ๊ฐ™์ด LIST๋ฅผ ์ด์šฉํ•ด Subroutine์„ ์ฐจ๋ก€๋Œ€๋กœ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

PERFORM idx OF <subroutine_1> <subroutine_2> ... <subroutine_n>

์‹œ์Šคํ…œ์€ idx์˜ ์ˆœ์„œ์— ๋”ฐ๋ผ Subroutine List๋ฅผ ํ˜ธ์ถœํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.

์˜ค์ง Internal Subroutine์—์„œ๋งŒ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ์‚ฌ์šฉํ•  ์ˆ˜ ์—†๋Š” ๋‹จ์ ์ด ์žˆ์Šต๋‹ˆ๋‹ค.

DO 2 TIMES.
  PERFORM SY-INDEX OF SUBROUTINE_1 SUBROUTINE_2.
ENDDO.

FORM SUBROUTINE_1.
  WRITE / '1 subroutine is called.'.
ENDFORM.

FORM SUBROUTINE_2.
  WRITE / '2 subroutine is called.'.
ENDFORM.

 

728x90
๋ฐ˜์‘ํ˜•