- Introduction
- History
- Public Method
- GET_CONFIG_VALUE
- GET_CONFIG
- CONVERT_ASCII_TO_CHAR
- CONVERT_CHAR_TO_ASCII
- CONVERT_FLTP_TO_CHAR
- DESCRIBE_NAME
- DESCRIBE_DATA
- CREATE_TABLE
- GET_DDIF
- SELECTIONS_INIT
- SELECTIONS_DIALOG
- LOCK_TABLE
- UNLOCK_TABLE
- UNLOCK_ALL
- GET_USER_INFO
- DOWNLOAD_SMW0
- SAVE_DIALOG
- OPEN_DIALOG
- CHECK_DBCON
- ITAB_TO_XLSX
- EXPORT_SHARED_TXT
- IMPORT_SHARED_TXT
- EXPORT_SHARED_XLSX
- EXPORT_SHARED_BIN
- IMPORT_SHARED_BIN
- GET_SHARED_FILELIST
- GET_HANA_DBCON
- CONVERT_RANGE_TO_WHERE
- GET_SYSTEM_MONITOR
Introduction
Class: ZCL_TOOLS
- 常用工具集合
History
Version | Date | Name | Description |
---|---|---|---|
V001 | 2020/10/8 | Huang Roy | 初版 |
V002 | 2020/10/22 | Huang Roy | 新增Method: GET_FTP_FILELIST, GET_SHARE_FILELIST |
V003 | 2020/11/26 | Huang Roy | 移除Method: EXPORT_FTP_TXT, IMPORT_FTP_TXT, EXPORT_FTP_XLSX, GET_FTP_FILELIST 轉移功能至Class: ZCL_FTP |
V004 | 2021/1/7 | Huang Roy | 新增Method: GET_HANA_DBCON |
V005 | 2021/4/9 | Huang Roy | 新增Method: EXPORT_SHARED_BIN, IMPORT_SHARED_BIN |
V006 | 2021/6/24 | Huang Roy | EXPORT_SHARED_TXT, IMPORT_SHARED_TXT需要分隔時,follow CSV rules |
V007 | 2021/8/26 | Huang Roy | 新增Method: CONVERT_RANGE_TO_WHERE |
V008 | 2021/10/13 | Huang Roy | 新增Method: GET_SYSTEM_MONITOR |
Public Method
GET_CONFIG_VALUE
- 取得Table: ZTCFG_TOOLS設定值(僅取得Active) - 單值
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_MAIN | Importing | RSOBJNM | Main Object | |||
I_SUB1 | Importing | X | RSOBJNM | Sub Object 1 | ||
I_SUB2 | Importing | X | RSOBJNM | Sub Object 2 | ||
R_VALUE | Returning | X | COCF_ITEM_VALUE | Value |
Sample
Click to Expand CodeDATA g_value TYPE cocf_item_value.
START-OF-SELECTION.
g_value = zcl_tools=>get_config_value( i_main = 'ZCL_REST_SERVER'
i_sub1 = 'LOG_BASEPATH' ).
WRITE g_value.
GET_CONFIG
- 取得Table: ZTCFG_TOOLS設定值(僅取得Active) - 多值
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_MAIN | Importing | RSOBJNM | Main Object | |||
I_SUB1 | Importing | X | RSOBJNM | Sub Object 1(Nil get all) | ||
I_SUB2 | Importing | X | RSOBJNM | Sub Object 2(Nil get all) | ||
RT_VALUE | Returning | X | TTY_CONFIG | Config Table |
Sample
Click to Expand CodeDATA gt_value TYPE zcl_tools=>tty_config.
START-OF-SELECTION.
gt_value = zcl_tools=>get_config( i_main = 'ZCL_REST_SERVER' ).
CONVERT_ASCII_TO_CHAR
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_ASCII | Importing | INT4 | ASCII Code | |||
R_CHAR | Returning | X | TDCHAR1 | Characters |
Sample
Click to Expand CodeDATA g_char TYPE tdchar1.
START-OF-SELECTION.
g_char = zcl_tools=>convert_ascii_to_char( 65 ).
WRITE g_char.
CONVERT_CHAR_TO_ASCII
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_CHAR | Importing | TDCHAR1 | Characters | |||
R_ASCII | Returning | X | INT4 | ASCII Code |
Sample
Click to Expand CodeDATA g_ascii TYPE int4.
START-OF-SELECTION.
g_ascii = zcl_tools=>convert_char_to_ascii( 'a' ).
WRITE g_ascii.
CONVERT_FLTP_TO_CHAR
- 整理FM: FLTP_CHAR_CONVERSION,原始回傳FLSTR無定義,最長為CHAR22
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_DECIMAL | Importing | INT2 | Decimal Places | |||
I_FLTP | Importing | FLTP_VALUE | Floating point value | |||
R_CHAR22 | Returning | X | CHAR22 | Characters(length 22) |
Sample
Click to Expand CodeDATA g_char22 TYPE char22.
START-OF-SELECTION.
g_char22 = zcl_tools=>convert_fltp_to_char( i_decimal = 2
i_fltp = '2.500000000000E+00' ).
WRITE g_char22.
DESCRIBE_NAME
- 取得SE11定義的component(view/table or structure) & Type Reflection(all)
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_NAME | Importing | ANY | DD Name | |||
ET_COMPONENT | Exporting | ABAP_COMPONENT_TAB | Component Description Table | |||
EO_TYPEDESCR | Exporting | CL_ABAP_TYPEDESCR | Runtime Type Services |
Sample
Click to Expand CodeDATA: gt_component TYPE abap_component_tab,
go_typedescr TYPE REF TO cl_abap_typedescr.
START-OF-SELECTION.
zcl_tools=>describe_name( EXPORTING i_name = 'SPFLI'
IMPORTING et_component = gt_component
eo_typedescr = go_typedescr ).
Result(Debug Mode)
DESCRIBE_DATA
- 取得程式內實體物件(DATA)的component(table or structure) & Type Reflection(all)
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_NAME | Importing | ANY | Data Object | |||
ET_COMPONENT | Exporting | ABAP_COMPONENT_TAB | Component Description Table | |||
EO_TYPEDESCR | Exporting | CL_ABAP_TYPEDESCR | Runtime Type Services |
Sample
Click to Expand CodeTYPES: BEGIN OF ty,
f1 TYPE char10,
f2 TYPE i,
END OF ty.
DATA: gt_component TYPE abap_component_tab,
go_typedescr TYPE REF TO cl_abap_typedescr,
gt TYPE TABLE OF ty.
START-OF-SELECTION.
zcl_tools=>describe_data( EXPORTING i_data = gt
IMPORTING et_component = gt_component
eo_typedescr = go_typedescr ).
Result(Debug Mode)
CREATE_TABLE
- 依component動態建立Internal Table
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
IT_COMPONENT | Importing | ABAP_COMPONENT_TAB | Component Table | |||
I_TABLE_KIND | Importing | X | ABAP_TABLEKIND | TABLEKIND_STANDARD | Table Type | |
I_UNIQUE | Importing | X | ABAP_BOOL | ABAP_FALSE | Unique Key | |
IT_KEY | Importing | X | ABAP_KEYDESCR_TAB | Table key field | ||
EO_WORK_AREA | Exporting | DATA | Work Area | |||
EO_TABLE | Exporting | DATA | Table |
- Table Kind參考 Attributes: **C_TABLEKIND_***
- Table Kind比較
Table Kind | Key | UNIQUE |
---|---|---|
STANDARD | Optional | NON-UNIQUE/ UNIQUE |
HASHED | Necessary | UNIQUE |
SORTED | Necessary | NON-UNIQUE/ UNIQUE |
Sample
- 以Table: SCARPLAN為基礎,去掉Client,並加上FLAG,建立STANDARD TABLE)
- Dynamic Internal Table資料操作請使用FIELD-SYMBOLS
DATA: gt_component TYPE abap_component_tab,
go_typedescr TYPE REF TO cl_abap_typedescr,
go_data TYPE REF TO data,
go_cx TYPE REF TO zcx_tools.
FIELD-SYMBOLS: <gw_component> TYPE abap_componentdescr,
<gt_table> TYPE STANDARD TABLE.
START-OF-SELECTION.
zcl_tools=>describe_name( EXPORTING i_name = 'SCARPLAN'
IMPORTING et_component = gt_component ).
DELETE gt_component WHERE name = 'MANDT'.
APPEND INITIAL LINE TO gt_component ASSIGNING <gw_component>.
<gw_component>-name = 'FLAG'.
zcl_tools=>describe_name( EXPORTING i_name = 'FLAG'
IMPORTING eo_typedescr = go_typedescr ).
<gw_component>-type ?= go_typedescr.
TRY.
zcl_tools=>create_table( EXPORTING it_component = gt_component
IMPORTING eo_table = go_data ).
ASSIGN go_data->* TO <gt_table>.
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
GET_DDIF
- 取得SE11定義之詳細資訊
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_DDOBJ | Importing | DDOBJNAME | Name of Dictionary Object | |||
ES_DDIF | Exporting | DFIES | Table Fields | |||
ET_DDIF | Exporting | DFIES_TAB | Table Type for Structure DFIES |
Sample 1(單data element資訊)
Click to Expand CodeDATA: gw_ddif TYPE dfies,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
TRY.
zcl_tools=>get_ddif( EXPORTING i_ddobj = 'S_CARR_ID'
IMPORTING es_ddif = gw_ddif ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
Result(Debug Mode,完整參考Type: DFIES)
Sample 2(Table Fields資訊)
DATA: gw_ddif TYPE dfies,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
TRY.
zcl_tools=>get_ddif( EXPORTING i_ddobj = 'S_CARR_ID'
IMPORTING es_ddif = gw_ddif ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
Result(Debug Mode,完整參考Type: DFIES_TAB)
SELECTIONS_INIT
- 動態產生SELECT-OPTIONS -- 初始化
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
IT_NOT_DISPLAY | Importing | X | RSDSFIELDS_T | Selection No Display | ||
IT_FIELD_DESC | Importing | X | DRF_T_FIELD_DESCR | Field descritpion | ||
IT_FIELD_TEXTS | Importing | X | WZRE_RSDSTEXTS_TAB | Selection Texts | ||
E_SELID | Exporting | DYNSELID | Dynamic selection ID | |||
CT_TABLES | Changing | X | RSDSTABS_T | Selection Tables | ||
CT_FIELDS | Changing | RSDSFIELDS_T | Selection Fields |
SELECTIONS_DIALOG
- 動態產生SELECT-OPTIONS -- 畫面
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_SELID | I_SELID | DYNSELID | Dynamic selection ID | |||
I_TITLE | I_TITLE | X | SYTITLE | Selection screen title | ||
I_FRAME_TEXT | I_FRAME_TEXT | X | SYTITLE | Frame text | ||
I_ASWIN | I_ASWIN | X | ABAP_BOOL | Call Screen as Window | ||
E_QUIT | E_QUIT | ABAP_BOOL | Is Quit | |||
ET_RSDSWHERE | ET_RSDSWHERE | RSDS_TWHERE | Conditions: Where | |||
ET_RSDSRANGE | ET_RSDSRANGE | RSDS_TRANGE | Conditions: Range | |||
CT_FIELDS | CT_FIELDS | RSDSFIELDS_T | Selection Fields |
Sample(Method: SELECTIONS_INIT & SELECTIONS_DIALOG)
- 一定要先用INIT取得SELID,然後給DIALOG使用
- INIT與DIALOG分開的用意,可以先INIT初始化物件,再使用DO WHILE跑DIALOG,即可以重複利用Selection screen(判斷跳出用E_QUIT)。
- 若CT_TABLES有寫入Table,會自動展開該Table所有欄位
DATA: g_selid TYPE dynselid,
gt_fields TYPE rsdsfields_t,
gt_rsdswhere TYPE rsds_twhere,
go_cx TYPE REF TO zcx_tools.
FIELD-SYMBOLS <gw_fields> TYPE rsdsfields.
START-OF-SELECTION.
APPEND INITIAL LINE TO gt_fields ASSIGNING <gw_fields>.
<gw_fields>-tablename = 'SPFLI'.
<gw_fields>-fieldname = 'CARRID'.
APPEND INITIAL LINE TO gt_fields ASSIGNING <gw_fields>.
<gw_fields>-tablename = 'SPFLI'.
<gw_fields>-fieldname = 'CONNID'.
TRY.
zcl_tools=>selections_init( IMPORTING e_selid = g_selid
CHANGING ct_fields = gt_fields ).
zcl_tools=>selections_dialog( EXPORTING i_selid = g_selid
IMPORTING et_rsdswhere = gt_rsdswhere
CHANGING ct_fields = gt_fields ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
Result(Screen)
Result(Debug Mode,Condition)
LOCK_TABLE
- Lock Table(不用建立Lock Object也能使用)
- 可用I_LOCKKEY(最長120字)加上細部鎖定,參考
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_LOCKMODE | Importing | X | ENQMODE | 'E' | Lock mode | |
I_TABNAME | Importing | TABNAME | Table Name | |||
I_LOCKKEY | Importing | X | VIM_ENQKEY | Lock key for tables | ||
I_WAIT | Importing | X | ABAP_BOOL | Wait to unlock |
Sample(記得lock後再開另一session測試)
Click to Expand CodeDATA go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
TRY.
zcl_tools=>lock_table( 'SPFLI' ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
UNLOCK_TABLE
- 與Method LOCK_TABLE配套使用
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_LOCKMODE | Importing | X | ENQMODE | 'E' | Lock mode | |
I_TABNAME | Importing | TABNAME | Table Name | |||
I_LOCKKEY | Importing | X | VIM_ENQKEY | Lock key for tables |
Sample
Click to Expand CodeSTART-OF-SELECTION.
zcl_tools=>unlock_table( i_tabname = 'SPFLI' ).
UNLOCK_ALL
- 該Session的Lock Object全解,慎用。
Sample
Click to Expand CodeSTART-OF-SELECTION.
zcl_tools=>unlock_all( ).
GET_USER_INFO
- 取得本機登入帳號/ 電腦名稱(僅Dialog可以取得,Background Job無法取得)
- 取得本機資訊嚴重影響效率,若要重複利用,請在constructor時取一次就好(反正也不會變)
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
E_TERMINAL | Exporting | STRING | Terminal | |||
E_LOGID_ID | Exporting | STRING | Login ID |
Sample
Click to Expand CodeDATA: l_terminal TYPE string,
l_logid_id TYPE string.
START-OF-SELECTION.
zcl_tools=>get_user_info( IMPORTING e_terminal = l_terminal
e_logid_id = l_logid_id ).
WRITE: l_terminal, l_logid_id.
DOWNLOAD_SMW0
- 下載T-code: SMW0的資料
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_OBJNAME | Importing | W3OBJID | SAP WWW Gateway Object Name | |||
I_FULLPATH | Importing | RLGRAP-FILENAME | Path&Filename |
Sample
Click to Expand CodeDATA: l_terminal TYPE string,
l_logid_id TYPE string.
START-OF-SELECTION.
zcl_tools=>get_user_info( IMPORTING e_terminal = l_terminal
e_logid_id = l_logid_id ).
WRITE: l_terminal, l_logid_id.
SAVE_DIALOG
- 主要是為了簡化cl_gui_frontend_services=>file_save_dialog,因為原本Changing參數filename, path, fullpath不是optional,等於要全接下來,通常就是會有2個變數用不到,浪費我的記憶體。Exporting就可以自己選要接哪些,不用動
- 副檔名預設是txt,參考I_FILTER,若為空則是預設篩選。需自訂的話,程式內有說明
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_DEFAULT_PATH | Importing | X | STRING | Default Path+Filename | ||
I_TITLE | Importing | X | STRING | Window Title | ||
I_FILTER | Importing | X | STRING | FILE_FILTER_TEXT | File Filter | |
I_WITH_ENCODING | Importing | X | ABAP_BOOL | With Encoding Options | ||
E_FULLPATH | Exporting | STRING | Path+Filename | |||
E_PATH | Exporting | STRING | Path | |||
E_FILENAME | Exporting | STRING | Filename | |||
E_ENCODING | Exporting | ABAP_ENCODING | Encoding |
Sample
Click to Expand CodeDATA: g_fullpath TYPE string,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
TRY.
zcl_tools=>save_dialog( IMPORTING e_fullpath = g_fullpath ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
WRITE g_fullpath.
OPEN_DIALOG
- 簡化cl_gui_frontend_services=>file_open_dialog某些變數
- 預設開啟副檔名為txt
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_DEFAULT_PATH | Importing | X | STRING | Default Path+Filename | ||
I_TITLE | Importing | X | STRING | Window Title | ||
I_FILTER | Importing | X | STRING | FILE_FILTER_TEXT | File Filter | |
I_WITH_ENCODING | Importing | X | ABAP_BOOL | With Encoding Options | ||
I_MULTISEL | Importing | X | ABAP_BOOL | Multiple Selection | ||
ET_FILE | Exporting | FILETABLE | File List | |||
E_ENCODING | Exporting | ABAP_ENCODING | Encoding |
Sample
Click to Expand CodeDATA: g_fullpath TYPE string,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
TRY.
zcl_tools=>save_dialog( IMPORTING e_fullpath = g_fullpath ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
WRITE g_fullpath.
CHECK_DBCON
- 可以僅Check DB Connection連線正常否(可再加上schema, table作為詳細條件)
- 若有需要可以作為CL_SQL_CONNECTION factory使用
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_DBCON | Importing | DBCON_NAME | Name of db connection | |||
I_SCHEMA | Importing | X | ADBC_NAME | Schema | ||
I_TABNAME | Importing | X | ADBC_NAME | Table Name | ||
RO_SQLCON | Returning | X | CL_SQL_CONNECTION | SQL Connection Object |
Sample(僅Check DB connection連線正常,以下是隨便打的,catch exception)
Click to Expand CodeDATA go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
TRY.
zcl_tools=>check_dbcon( 'XX' ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
ITAB_TO_XLSX
- Internal table轉XLSX binary data(ALV轉Excel,若要產生更複雜的Excel,可用xlsx workbench or abap2xlsx)
- IT_FSET: 用來設定要轉成Excel的欄位及Header text(position可以省略)。
- 要取得xstring or solix_tab,看下載功能的支援方式,自行選用。
- 下載binary file,size需要加上,否則可能會有一些奇奇怪怪的問題。
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
IT_FSET | Importing | TTY_FSET | Field Setting | |||
E_XLSX | Exporting | XSTRING | XLSX Xstring | |||
ET_XLSX | Exporting | SOLIX_TAB | XLSX Binary data | |||
E_SIZE | Exporting | I | XLSX Size(XSTRLEN) | |||
CT_OUT | Changing | ANY TABLE | Output Data |
Sample(Internal Table轉xlsx,並下載到本機)
Click to Expand CodeTYPES: BEGIN OF ty,
f1 TYPE char10,
f2 TYPE char10,
END OF ty.
DATA: lw TYPE ty,
lt TYPE TABLE OF ty,
lw_fset TYPE zcl_tools=>ty_fset,
lt_fset TYPE zcl_tools=>tty_fset,
lt_xlsx TYPE solix_tab,
l_siez TYPE i,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
lw-f1 = 'XYZ'.
lw-f2 = '123'.
APPEND lw TO lt.
APPEND lw TO lt.
APPEND lw TO lt.
lw_fset-fieldname = 'F1'.
lw_fset-coltext = 'F1 Test'.
APPEND lw_fset TO lt_fset.
lw_fset-fieldname = 'F2'.
lw_fset-coltext = 'F2 Test'.
APPEND lw_fset TO lt_fset.
TRY.
zcl_tools=>itab_to_xlsx( EXPORTING it_fset = lt_fset
IMPORTING et_xlsx = lt_xlsx
e_size = l_siez
CHANGING ct_out = lt ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
cl_gui_frontend_services=>gui_download( EXPORTING bin_filesize = l_siez
filename = 'D:\test.xlsx'
filetype = 'BIN'
CHANGING data_tab = lt_xlsx ).
EXPORT_SHARED_TXT
- 匯出文字檔 to shared folder(僅能在Windows AP使用)
- I_FULLPATH: 路徑加檔名
- IT_FSET: 未設定則直接輸出
- I_WITH_HEADER: 設定是否要header,預設為輸出含header
- I_APPEND: 設定附加資訊或是直接新資料蓋過去,預設為直接蓋掉
- I_SEP: 設定分隔符號,預設是tab
- ※分隔符號生效時(輸出物件含structure),follow CSV delimiter rules(V006)
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_FULLPATH | Importing | STRING | Path+Filename(with extension) | |||
IT_FSET | Importing | X | TTY_FSET | Field Setting | ||
I_WITH_HEADER | Importing | X | ABAP_BOOL | ABAP_TRUE | Data with Header | |
I_APPEND | Importing | X | ABAP_BOOL | ABAP_FALSE | Append to same file | |
I_SEP | Importing | X | ABAP_CHAR1 | C_TAB | Separator | |
I_SILENT | Importing | X | ABAP_BOOL | ABAP_FALSE | No show message | |
IT_OUT | Importing | ANY TABLE | Output data |
Sample
Click to Expand CodeTYPES: BEGIN OF ty,
f1 TYPE char10,
f2 TYPE char10,
END OF ty.
DATA: gw TYPE ty,
gt TYPE TABLE OF ty,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
gw-f1 = 'XYZ'.
gw-f2 = '123'.
APPEND gw TO gt.
TRY.
zcl_tools=>export_shared_txt( i_fullpath = '\\10.6.254.75\purchasing_file\TestQ\Test.txt'
it_out = gt ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
IMPORT_SHARED_TXT
- 匯入文字檔 from shared folder(僅能在Windows AP使用)
- I_START_LINE: 設定從第幾列開始讀取資料,預設是從第一列開始
- IT_FSET: 未設定,則按吃進來切割順序寫入internal table
- ※分隔符號生效時(接收物件含structure),follow CSV delimiter rules(V006)
- 其他注意事項參考EXPORT_SHARED_TXT
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_FULLPATH | Importing | STRING | Path+Filename(with extension) | |||
IT_FSET | Importing | X | TTY_FSET | Field Setting | ||
I_START_LINE | Importing | X | I | 1 | Start line of Import data | |
I_SEP | Importing | X | ABAP_CHAR1 | C_TAB | Separator | |
I_SILENT | Importing | X | ABAP_BOOL | ABAP_FALSE | No show message | |
ET_IN | Exporting | STANDARD TABLE | Output data |
Sample
Click to Expand CodeTYPES: BEGIN OF ty,
f1 TYPE char10,
f2 TYPE char10,
END OF ty.
DATA: gw TYPE ty,
gt TYPE TABLE OF ty,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
gw-f1 = 'XYZ'.
gw-f2 = '123'.
APPEND gw TO gt.
TRY.
zcl_tools=>export_shared_txt( i_fullpath = '\\10.6.254.75\purchasing_file\TestQ\Test.txt'
it_out = gt ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
EXPORT_SHARED_XLSX
- 匯出Excel to shared folder(ALV轉Excel,僅能在Windows AP使用)
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_FULLPATH | Importing | STRING | Path+Filename(with extension) | |||
IT_FSET | Importing | TTY_FSET | Field Setting | |||
I_SILENT | Importing | X | ABAP_BOOL | ABAP_FALSE | No show message | |
CT_OUT | Changing | ANY TABLE | Output data |
Sample
Click to Expand CodeTYPES: BEGIN OF ty,
f1 TYPE char10,
f2 TYPE char10,
END OF ty.
DATA: gw TYPE ty,
gt TYPE TABLE OF ty,
gw_fset TYPE zcl_tools=>ty_fset,
gt_fset TYPE zcl_tools=>tty_fset,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
gw-f1 = 'XYZ'.
gw-f2 = '123'.
APPEND gw TO gt.
gw_fset-fieldname = 'F1'.
gw_fset-coltext = 'F1 Test'.
APPEND gw_fset TO gt_fset.
gw_fset-fieldname = 'F2'.
gw_fset-coltext = 'F2 Test'.
APPEND gw_fset TO gt_fset.
TRY.
zcl_tools=>export_shared_xlsx( EXPORTING i_fullpath = '\\10.6.254.75\purchasing_file\TestQ\Test.xlsx'
it_fset = gt_fset
CHANGING ct_out = gt ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
EXPORT_SHARED_BIN
- 匯出Binary file to shared folder(僅能在Windows AP使用, V005 add)
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_FULLPATH | Importing | STRING | Path+Filename(with extension) | |||
I_APPEND | Importing | X | ABAP_BOOL | ABAP_FALSE | Append to same file | |
I_XSTRING | Importing | XSTRING | Binary Data | |||
I_SILENT | Importing | X | ABAP_BOOL | ABAP_FALSE | No show message |
Sample
Click to Expand CodeDATA go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
TRY.
zcl_tools=>export_shared_bin( i_fullpath = '\\10.6.254.75\purchasing_file\TestQ\Test.txt'
i_xstring = cl_bcs_convert=>string_to_xstring( iv_string = 'abc123'
iv_codepage = '4110')
).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
IMPORT_SHARED_BIN
- 匯入Binary file from shared folder(僅能在Windows AP使用, V005 add)
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_FULLPATH | Importing | STRING | Path+Filename(with extension) | |||
I_SILENT | Importing | X | ABAP_BOOL | ABAP_FALSE | No show message | |
R_XSTRING | Returning | X | XSTRING | Output data |
Sample
Click to Expand CodeDATA: g_str TYPE string,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
TRY.
g_str = cl_bcs_convert=>xstring_to_string( iv_xstr = zcl_tools=>import_shared_bin( i_fullpath = '\\10.6.254.75\purchasing_file\TestQ\Test.txt' )
iv_cp = '4110' ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
SKIP.
WRITE / g_str.
GET_SHARED_FILELIST
- 取得Shared Folder指定資料夾檔案清單(V002 add)
- 僅能在Windows AP使用,檔名非ASCII Code應該都是亂碼
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
I_PATH | Importing | STRING | Path | |||
RT_FILE | Returning | X | MDG_FILETABLE_T | File List |
Sample
Click to Expand CodeDATA: gt_file TYPE mdg_filetable_t,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
TRY.
gt_file = zcl_tools=>get_shared_filelist( '\\10.6.254.75\purchasing_file\TestQ' ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
GET_HANA_DBCON
- 取得HANA DB Connection name(若連線失敗,取得的值為空)
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
R_HANA | Returning | X | DBCON_NAME | Logical name for a database connection |
Sample
Click to Expand CodeDATA g_dbcon TYPE dbcon_name.
START-OF-SELECTION.
g_dbcon = zcl_tools=>get_hana_dbcon( ).
CONVERT_RANGE_TO_WHERE
- Range資料轉換為SQL WHERE
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
IT_RANGE | Importing | STANDARD TABLE | Range Table | |||
I_NAME | Importing | STRING | Field Name | |||
I_NUMBER | Importing | X | ABAP_BOOL | Number data | ||
R_WHERE | Returning | X | STRING | Where Condition |
Sample
Click to Expand CodeDATA: g_where TYPE string,
gw_matnr TYPE range_s_matnr,
gt_matnr TYPE range_t_matnr,
go_cx TYPE REF TO zcx_tools.
START-OF-SELECTION.
gw_matnr = 'IEQ'.
gw_matnr-low = 'XXX'.
APPEND gw_matnr TO gt_matnr.
gw_matnr = 'ICP'.
gw_matnr-low = 'Y*'.
APPEND gw_matnr TO gt_matnr.
gw_matnr = 'EEQ'.
gw_matnr-low = 'ZZZ'.
APPEND gw_matnr TO gt_matnr.
TRY.
g_where = zcl_tools=>convert_range_to_where( it_range = gt_matnr
i_name = 'Material' ).
CATCH zcx_tools INTO go_cx.
go_cx->show( ).
ENDTRY.
GET_SYSTEM_MONITOR
- 取得系統狀況
Parameter | Level | Pass Value | Optional | Type(Ref To) | Default | Description |
---|---|---|---|---|---|---|
RT_SYS | Returning | X | TTY_SYS | System info Table |
Sample
Click to Expand CodeDATA lt_sys TYPE zcl_tools=>tty_sys.
START-OF-SELECTION.
lt_sys = zcl_tools=>get_system_monitor( ).
技術提供: Gitea 版本: 1.15.5 頁面: 639ms 樣板: 2ms 繁體中文(台灣) 授權條款 API 網站 Go1.16.9 标签:gt,ZCL,TOOLS,Importing,cx,tools,go,TYPE From: https://www.cnblogs.com/TYAING/p/17413584.html