메뉴 건너뛰기

SAP 한국 커뮤니티

[ABAP] Dynamic SQL ( UPDATE/DELETE clause,Rel6.10 )

문바이 2011.11.18 15:47 조회 수 : 630

이글은 자료실에 있는 DynamicOpenSql 영문파일을 정리한 것이다.

 

 

Dynamic Open SQL.

내역 : UPDATE/DELETE절을 이용한 동적처리
---------------------------------------------------------------------
사전지식 :  Oracle Native SQL사용가능( 집합함수를 사용할 줄 안다.)
            Oracle Procedure Exception처리를 해본 경험이 있다.
            또는   Java/C++  Exception처리를 해본 경험이 있다.
---------------------------------------------------------------------

문법 : Rel6.10 이후 방식
      DELETE FROM (table_clause) WHERE( where_clause ).
      UPDATE (table_clause) SET( Set_clause ) WHERE( where_clause ).
            기존 버전의 단점을 개선 하고 native SQL처럼 사용한다.

생각 : 본문의 코딩이 워낙 쉬어서 주석을 달지 않았음.

 

프로그램 원문.
--------------------------------------------------------------------*

REPORT   YTEST_DYNAMIC_OPEN_SQL05.

parameters: p_tabnm     type tabname,
            p_column    type fieldname,
            p_where(80) type c lower case,
            p_value(30) type c.

data: lv_set_clause    type string,
      lo_value_ref     type ref to data,
      lo_xref          type ref to cx_sy_dynamic_osql_error,
      lv_message       type string,
      lv_count         type string.

concatenate p_column ' = p_value' into lv_set_clause.

try.
  update (p_tabnm) set (lv_set_clause) where (p_where).
    if sy-dbcnt <> 0.
      lv_count = sy-dbcnt.
      concatenate 'The field '' p_column'
        '' 'has been set to the new value' 'p_value'
        'in' lv_count 'row[s] of table '' p_tabnm ' into lv_message.
    else.
      lv_message = 'No p_columns changed.'.
    endif.
  catch cx_sy_dynamic_osql_error into lo_xref.
    lv_message = lo_xref->get_text( ).
endtry.
write: / lv_message.