이글은 자료실에 있는 DynamicOpenSql 영문파일을 정리한 것이다.
Dynamic Open SQL.
내역 : Exception Handling (예외처리).
---------------------------------------------------------------------
사전지식 : Oracle Native SQL사용가능( 집합함수를 사용할 줄 안다.)
Oracle Procedure Exception처리를 해본 경험이 있다.
또는 Java/C++ Exception처리를 해본 경험이 있다.
---------------------------------------------------------------------
기술 : 가) Exception Handling
DATA : xref type ref to cx_dynamic_check. (내가 처리할 exception 유형을 선언한다)
try. --> 예외처리 block의 시작을 말한다.
"명령을 수행한다.(잘못된 명령으로 exception이 발생한다면 아래 catch블럭으로 이동한다)
create data dref type table of (tabname).
assign dref->* to <itab>.
"오류가 발생하지 않았다면 데이타를 읽어들인다.
select *
from (tabname) up to 20 rows
into table <itab>.
"오류가 발생하지 않았다면 catch를 만나는 순간 endtry 밖으로 이동한다.
"오류가 발생하였다면 catch로 바로 온다.
catch cx_sy_dynamic_osql_error
cx_sy_create_data_error into xref.
message_txt = xref->get_text( ).
** i = xref->get_id( ).
message message_txt type 'E'.
endtry. --> 예외처리 block의 종료를 말한다.
생각 : Dynamic SQL을 사용한다는 것은 Runtime에 예측가능하지 못한 상황을 접할 가능성이 있다는 것을 시사한다
따라서 이와같이 경우에 ABAP의 exception handing기술을 사용해서 오류를 처리해야만
사용자가 Dump 뜨는 화면을 접하는 것을 막을 수 있다.
이 방법을 조금만 응용하면 여러가지 Dump 화면을 제어할 수 있으므로 특히 유심히 보자
프로그램 원문.
--------------------------------------------------------------------*
REPORT YTEST_DYNAMIC_OPEN_SQL03.
parameter tabname type tabname.
data: dref type ref to data,
xref type ref to cx_dynamic_check,
message_txt type string,
i type i.
field-symbols: <itab> type standard table,
<row> type any,
<component> type any.
start-of-selection.
try.
* dynamically create appropriate internal table
create data dref type table of (tabname).
assign dref->* to <itab>.
* fetch the data
select *
from (tabname) up to 20 rows
into table <itab>.
catch cx_sy_dynamic_osql_error
cx_sy_create_data_error into xref.
message_txt = xref->get_text( ).
** i = xref->get_id( ).
message message_txt type 'E'.
endtry.
* display the result
loop at <itab> assigning <row>.
new-line.
do.
assign component sy-index of structure <row>
to <component>.
if sy-subrc <> 0.
exit. " no more components
endif.
write: <component>.
enddo.
endloop.
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
42 | ABAP [선언문] 명령어 정리표 Rev01 [57] | 문바이 | 2011.05.18 | 6230 |
41 | ABAP Certi 7.0 요약 정리 [101] | 뽀꼬 | 2011.06.15 | 5662 |
40 | [ABAPDOCU] 뜯어봅시다. 2 [42] | 뽀꼬 | 2011.09.06 | 2149 |
39 | [ABAPDOCU] 뜯어봅시다. 3 [30] | 뽀꼬 | 2011.09.07 | 938 |
38 | [ABAPDOCU] 뜯어봅시다 1 [54] | 뽀꼬 | 2011.09.08 | 1752 |
37 | [ABAPDOCU] 뜯어봅시다 4 [20] | 뽀꼬 | 2011.09.08 | 684 |
36 | [ABAPDOCU] 뜯어봅시다 5 [16] | 뽀꼬 | 2011.09.09 | 556 |
35 | [ABAPDOCU] 뜯어봅시다 6 [22] | 뽀꼬 | 2011.09.14 | 519 |
34 | [번외] Field symbol과 Data reference [14] | 뽀꼬 | 2011.09.14 | 950 |
33 | [ABAPDOCU] 뜯어봅시다 7 [14] | 뽀꼬 | 2011.09.15 | 525 |
32 | [ABAPDOCU] 뜯어봅시다 8 [14] | 뽀꼬 | 2011.09.19 | 466 |
31 | [ABAPDOCU] 뜯어봅시다 9 [15] | 뽀꼬 | 2011.09.20 | 386 |
30 | [ABAPDOCU] 뜯어봅시다 10 [14] | 뽀꼬 | 2011.09.22 | 389 |
29 | [ABAPDOCU] 뜯어봅시다 11 [14] | 뽀꼬 | 2011.09.26 | 385 |
28 | [ABAPDOCU] 뜯어봅시다 12 [7] | 뽀꼬 | 2011.09.28 | 294 |
27 | [ABAPDOCU] 뜯어봅시다 13 [7] | 뽀꼬 | 2011.09.29 | 260 |
26 | [ABAPDOCU] 뜯어봅시다 14 [10] | 뽀꼬 | 2011.09.30 | 275 |
25 | [ABAPDOCU] 뜯어봅시다 15 [7] | 뽀꼬 | 2011.10.04 | 315 |
24 | [ABAPDOCU] 뜯어봅시다 16 [8] | 뽀꼬 | 2011.10.07 | 285 |
23 | [ABAPDOCU] 뜯어봅시다 17 [6] | 뽀꼬 | 2011.10.11 | 485 |
좋은 정보 감사합니다. 잘 보고 갑니다.