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

[SAP ABAP] IF-ENDIF์™€ CASE-ENDCASE ์กฐ๊ฑด๋ถ€ ๋ž€? (์ฐจ์ด์ , ์‚ฌ์šฉ๋ฒ•)

by Jay Din 2024. 3. 20.
728x90
๋ฐ˜์‘ํ˜•

IF-ENDIF์™€ CASE-ENDCASE ์ฐจ์ด์  ์ •๋ฆฌ

IF - ENDIF ๋ฒ”์œ„, ํฌ๊ธฐ ๋น„๊ต ๋“ฑ ์กฐ๊ฑด์ด ์žˆ์„ ๋•Œ
CASE - ENDCASE ๋‹จ์ผ๊ฐ’์ผ ๊ฒฝ์šฐ

 

IF - ENDIF ๋ž€?

IF๋ฌธ์€ ์ฃผ์–ด์ง„ ์กฐ๊ฑด์ด ์ฐธ์ธ์ง€ ๊ฑฐ์ง“์ธ์ง€์— ๋”ฐ๋ผ ์ฝ”๋“œ๋ฅผ ์‹คํ–‰ํ•˜๊ฑฐ๋‚˜ ๊ฑด๋„ˆ๋›ฐ๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

 

์˜ˆ์ œ

DATA: lv_score TYPE i.
lv_score = 85.

IF 100 >= lv_score and lv_score >= 90.
  WRITE 'Aํ•™์ ์ž…๋‹ˆ๋‹ค.'.
ELSEIF 89 >= lv_score and lv_score >= 80.
  WRITE 'Bํ•™์ ์ž…๋‹ˆ๋‹ค.'.
ELSEIF 79 >= lv_score and lv_score >= 70.
  WRITE 'Cํ•™์ ์ž…๋‹ˆ๋‹ค.'.
ELSE.
  WRITE 'Dํ•™์ ์ž…๋‹ˆ๋‹ค.'.
ENDIF.

์‹คํ–‰ํ™”๋ฉด

 

CASE - ENDCASE ๋ž€?

if ๋ฌธ๊ณผ ๋น„์Šทํ•˜์ง€๋งŒ ์ข€ ๋” ์ผ์ •ํ•œ ํ˜•์‹์ด ์žˆ๋Š” ์กฐ๊ฑด·ํŒ๋‹จ๋ฌธ์ž…๋‹ˆ๋‹ค.

์ž…๋ ฅ ๋ณ€์ˆ˜์˜ ๊ฐ’๊ณผ ์ผ์น˜ํ•˜๋Š” ์ž…๋ ฅ๊ฐ’์ด ์žˆ๋‹ค๋ฉด ํ•ด๋‹น case ๋ฌธ์— ์†ํ•œ ๋ฌธ์žฅ๋“ค์ด ์‹คํ–‰๋œ๋‹ค.

 

์˜ˆ์ œ

DATA: lv_grade TYPE char1.
lv_grade = 'B'.

CASE lv_grade.
  WHEN 'A'.
    WRITE '์šฐ์ˆ˜ํ•ฉ๋‹ˆ๋‹ค.'.
  WHEN 'B'.
    WRITE '๋ณดํ†ต์ž…๋‹ˆ๋‹ค.'.
  WHEN 'C'.
    WRITE '๋ฏธํกํ•ฉ๋‹ˆ๋‹ค.'.
  WHEN OTHERS.
    WRITE '๋“ฑ๊ธ‰์„ ์•Œ ์ˆ˜ ์—†์Šต๋‹ˆ๋‹ค.'.
ENDCASE.

์‹คํ–‰ํ™”๋ฉด

 

728x90
๋ฐ˜์‘ํ˜•