Introduction
Class: ZCX_STATIC_CHECK
- Enhance Exception Class: CX_STATIC_CHECK
- Easy to trace exception
History
Version | Date | Name | Description |
---|---|---|---|
V001 | 2020/10/8 | Huang Roy | 初版 |
V002 | 2020/10/22 | Huang Roy | Add Method: GET_SHOW_MSG_STR |
Class Screen
- Long Text: 設定如文章一般的超長訊息
- 左側為Text ID,右為Text
- 請
不要
修改此Exception Class,以繼承方式加上新的textid或是直接自訂訊息 - 繼承的Exception Class皆可以upcasting to ZCX_STATIC_CHECK
- Exception Class一定要是YCX_ or ZCX_ 開頭
RAISE Syntax
- textid未設定,預設是使用exception class同名text id
- msg1~msg4為自訂訊息,在text內可以用 &msgN& 作為變數附加訊息
RAISE EXCEPTION TYPE zcx_static_check
EXPORTING
textid = xx
msg1 = xx
msg2 = xx
msg3 = xx
msg4 = xx.
Public Method
SHOW
- 顯示錯誤訊息視窗(Background Job顯示於spool)
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_LONG | Importing | X | ABAP_BOOL | Show Long Text |
Sample 1: 使用textid(zcx_static_check=>no_data)
- 由於是static check,須在methods後加上RAISING語法,未加時check syntax會提示。
- 如果沒有Raising指定exception作為通道,在實際執行時會直接short dump
CLASS lcl_test DEFINITION FINAL.
PUBLIC SECTION.
CLASS-METHODS trigger_exception RAISING zcx_static_check.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD trigger_exception.
RAISE EXCEPTION TYPE zcx_static_check
EXPORTING
textid = zcx_static_check=>no_data.
ENDMETHOD.
ENDCLASS.
DATA: go_cx TYPE REF TO zcx_static_check.
START-OF-SELECTION.
TRY.
lcl_test=>trigger_exception( ).
CATCH zcx_static_check INTO go_cx.
go_cx->show( ).
ENDTRY.
Result(左dialog,右backgroun。如訊息,出錯於YQQTEST第17列)
Sample 2: 使用textid+自訂message(zcx_static_check=>no_data_memo)
Click to Expand CodeCLASS lcl_test DEFINITION FINAL.
PUBLIC SECTION.
CLASS-METHODS trigger_exception RAISING zcx_static_check.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD trigger_exception.
RAISE EXCEPTION TYPE zcx_static_check
EXPORTING
textid = zcx_static_check=>no_data_memo
msg1 = 'QQQQQ'.
ENDMETHOD.
ENDCLASS.
DATA: go_cx TYPE REF TO zcx_static_check.
START-OF-SELECTION.
TRY.
lcl_test=>trigger_exception( ).
CATCH zcx_static_check INTO go_cx.
go_cx->show( ).
ENDTRY.
Sample 3: 完全自訂message
Click to Expand CodeCLASS lcl_test DEFINITION FINAL.
PUBLIC SECTION.
CLASS-METHODS trigger_exception RAISING zcx_static_check.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD trigger_exception.
RAISE EXCEPTION TYPE zcx_static_check
EXPORTING
msg1 = 'Q'
msg2 = 'Q'
msg3 = 'Q'
msg4 = 'Q'.
ENDMETHOD.
ENDCLASS.
DATA: go_cx TYPE REF TO zcx_static_check.
START-OF-SELECTION.
TRY.
lcl_test=>trigger_exception( ).
CATCH zcx_static_check INTO go_cx.
go_cx->show( ).
ENDTRY.
Sample 4: Global Class
- 同local class,只是raising在Exception設定,未設定時check syntax會提示。
Method Code
METHOD trigger_exception.
RAISE EXCEPTION TYPE zcx_static_check
EXPORTING
textid = zcx_static_check=>no_data.
ENDMETHOD.
Report Code:
DATA: go_cx TYPE REF TO zcx_static_check.
START-OF-SELECTION.
TRY.
ycl_qqtest=>trigger_exception( ).
CATCH zcx_static_check INTO go_cx.
go_cx->show( ).
ENDTRY.
GET_SHOW_MSG
- 取得Method: SHOW顯示的所有文字
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_LONG | Importing | X | ABAP_BOOL | Show Long Text | ||
RT_MSG | Returning | X | CHAR80_T | Show Message |
Sample:
Click to Expand CodeCLASS lcl_test DEFINITION FINAL.
PUBLIC SECTION.
CLASS-METHODS trigger_exception RAISING zcx_static_check.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD trigger_exception.
RAISE EXCEPTION TYPE zcx_static_check
EXPORTING
textid = zcx_static_check=>no_data.
ENDMETHOD.
ENDCLASS.
DATA: go_cx TYPE REF TO zcx_static_check,
gt_msg TYPE char80_t.
START-OF-SELECTION.
TRY.
lcl_test=>trigger_exception( ).
CATCH zcx_static_check INTO go_cx.
gt_msg = go_cx->get_show_msg( ).
ENDTRY.
GET_SHOW_MSG_STR
- 取得Method: SHOW顯示的所有文字(String型)(V002 Add)
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_LONG | Importing | X | ABAP_BOOL | Show Long Text | ||
R_MSG | Returning | X | STRING | Show Message |
Sample:
Click to Expand CodeCLASS lcl_test DEFINITION FINAL.
PUBLIC SECTION.
CLASS-METHODS trigger_exception RAISING zcx_static_check.
ENDCLASS.
CLASS lcl_test IMPLEMENTATION.
METHOD trigger_exception.
RAISE EXCEPTION TYPE zcx_static_check
EXPORTING
textid = zcx_static_check=>no_data.
ENDMETHOD.
ENDCLASS.
DATA: go_cx TYPE REF TO zcx_static_check,
g_msg TYPE string.
START-OF-SELECTION.
TRY.
lcl_test=>trigger_exception( ).
CATCH zcx_static_check INTO go_cx.
g_msg = go_cx->get_show_msg_str( ).
ENDTRY.
技術提供: Gitea 版本: 1.15.5 頁面: 456ms 樣板: 2ms 繁體中文(台灣) 授權條款 API 網站 Go1.16.9 标签:exception,zcx,check,cx,static,go,STATIC,ZCX,CHECK From: https://www.cnblogs.com/TYAING/p/17413589.html