[ABAP] NATIVE SQL
๐ OPEN SQL๋ง์ผ๋ก๋ ์ํ๋ ์ฟผ๋ฆฌ๋ฅผ ์ธ ์ ์๋ ๊ฒฝ์ฐ๊ฐ ์๋๋ฐ, NATIVE SQL์ ์ฌ์ฉํด SELECT ํ๋ ๋ ๊ฐ์ง ๋ฐฉ๋ฒ์ ์์๋ณด์. ๐
TYPES: BEGIN OF gty_s_test,
f1 TYPE ~,
f2 TYPE ~,
... ,
END OF gty_s_test,
gty_t_test TYPE TABLE OF gty_s_test.
DATA: gt_test TYPE TABLE OF gty_s_test WITH HEADER LINE.
"or
DATA: gt_test TYPE gty_t_test WITH HEADER LINE.
DATA: gt_test2 TYPE TABLE OF gty_s_test.
SELECT ํ ํ๋๋ฅผ TYPES๋ฌธ์ผ๋ก ์ ์ธํ๊ณ ํ ์ด๋ธ๋ ๋ง๋ค์ด์ฃผ๊ธฐ.
๐ EXEC SQL PERFORMING โฆ
์ฒซ ๋ฒ์งธ ๋ฐฉ๋ฒ์ PERFORM ๊ตฌ๋ฌธ์ผ๋ก Subroutine์ ํธ์ถํด FORM ๊ตฌ๋ฌธ์ ์ํํ๋ฏ์ด PERFORMING/FORM ๊ตฌ๋ฌธ ์ฌ์ฉํ๊ธฐ.
EXEC SQL PERFORMING append_data.
SELECT
f1, f2, ...
INTO :gt_test
FROM ...
ENDEXEC.
FORM append_data.
APPEND gt_test.
CLEAR gt_test.
ENDFORM.
ํ
์ด๋ธ์ ๋ฐ๋ก ๋ฃ์ ์๋ ์๊ณ ,
EXEC SQL PERFORMING append_data.
SELECT
f1, f2, ...
INTO :gs_test
FROM ...
ENDEXEC.
FORM append_data.
APPEND gs_test TO gt_test.
CLEAR gs_test.
ENDFORM.
์คํธ๋ญ์ณ์ ๋ฃ๊ณ ํ ์ด๋ธ์ append ํ ์๋ ์๋ค.
๐ EXEC SQL. OPEN dbcur FOR โฆ
DATA: ls_test TYPE gty_s_test.
EXEC SQL.
OPEN dbcur FOR
SELECT
f1, f2, ...
FROM ...
END EXEC.
DO.
EXEC SQL.
FETCH NEXT dbcur INTO :ls_test-f1,
:ls_test-f2,
...
END EXEC.
IF sy-subrc EQ 0.
APPEND ls_test TO gt_test2.
CLEAR ls_test.
ELSE.
EXIT.
ENDIF.
ENDDO.
EXEC SQL.
CLOSE dbcur
ENDEXEC.
์ด๊ฑด ์ด๋ฒ์ ์ฒ์ ์๊ฒ ๋ ๋ฐฉ๋ฒ. dbcur์ด๋ผ๋ database cursur๋ฅผ ๋ง๋ค์ด ๋ฐ์ดํฐ๋ฅผ ์ฝ๊ณ , ์ฑ๊ณต ์ append.
๐ฅ ์ ์ธํ ๋ณ์๋ฅผ NATIVE SQL ์์์ ์ฌ์ฉํ ๋๋ ๋ณ์ ์์ โ : โ ๋ฃ์ด์ฃผ๊ธฐ!!
๐ฅ BETWEEN ๋ฑ ์ฌ์ฉ ์ ๋ฐ์ดํ ์์ด ย ย :๋ณ์๋ช
ย ย ์ผ๋ก๋ง ์ฐ๊ธฐ!! (โโ ์ผ๋ค๊ฐ ์์๋์ง n์๊ฐ ํจใ
)