首页 > 其他分享 >ZCL_TOOLS

ZCL_TOOLS

时间:2023-05-18 23:23:59浏览次数:51  
标签:gt ZCL TOOLS Importing cx tools go TYPE

Introduction

Class: ZCL_TOOLS

  • 常用工具集合

History

VersionDateNameDescription
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) - 單值
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA 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.

Result


GET_CONFIG

  • 取得Table: ZTCFG_TOOLS設定值(僅取得Active) - 多值
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA gt_value TYPE zcl_tools=>tty_config.

START-OF-SELECTION.
  gt_value = zcl_tools=>get_config( i_main = 'ZCL_REST_SERVER' ).

Result(Debug Mode)


CONVERT_ASCII_TO_CHAR

ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
I_ASCII Importing     INT4   ASCII Code
R_CHAR Returning X   TDCHAR1   Characters

Sample

Click to Expand Code
DATA g_char TYPE tdchar1.

START-OF-SELECTION.
  g_char = zcl_tools=>convert_ascii_to_char( 65 ).
  WRITE g_char.

Result


CONVERT_CHAR_TO_ASCII

ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
I_CHAR Importing     TDCHAR1   Characters
R_ASCII Returning X   INT4   ASCII Code

Sample

Click to Expand Code
DATA g_ascii TYPE int4.

START-OF-SELECTION.
  g_ascii = zcl_tools=>convert_char_to_ascii( 'a' ).
  WRITE g_ascii.

Result


CONVERT_FLTP_TO_CHAR

  • 整理FM: FLTP_CHAR_CONVERSION,原始回傳FLSTR無定義,最長為CHAR22
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA 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.

Result


DESCRIBE_NAME

  • 取得SE11定義的component(view/table or structure) & Type Reflection(all)
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA: 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)

GT_COMPONENT

GO_TYPEDESCR


DESCRIBE_DATA

  • 取得程式內實體物件(DATA)的component(table or structure) & Type Reflection(all)
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
TYPES: 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)

GT_COMPONENT

GO_TYPEDESCR


CREATE_TABLE

  • 依component動態建立Internal Table
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 KindKeyUNIQUE
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
Click to Expand Code
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.

Result(Debug Mode)


GET_DDIF

  • 取得SE11定義之詳細資訊
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
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)

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 -- 初始化
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 -- 畫面
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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)

  1. 一定要先用INIT取得SELID,然後給DIALOG使用
  2. INIT與DIALOG分開的用意,可以先INIT初始化物件,再使用DO WHILE跑DIALOG,即可以重複利用Selection screen(判斷跳出用E_QUIT)。
  3. 若CT_TABLES有寫入Table,會自動展開該Table所有欄位
Click to Expand Code
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字)加上細部鎖定,參考
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA 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.

Result


UNLOCK_TABLE

  • 與Method LOCK_TABLE配套使用
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
START-OF-SELECTION.
  zcl_tools=>unlock_table( i_tabname = 'SPFLI' ).

UNLOCK_ALL

  • 該Session的Lock Object全解,慎用。

Sample

Click to Expand Code
START-OF-SELECTION.
  zcl_tools=>unlock_all( ).

GET_USER_INFO

  • 取得本機登入帳號/ 電腦名稱(僅Dialog可以取得,Background Job無法取得)
  • 取得本機資訊嚴重影響效率,若要重複利用,請在constructor時取一次就好(反正也不會變)
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
E_TERMINAL Exporting     STRING   Terminal
E_LOGID_ID Exporting     STRING   Login ID

Sample

Click to Expand Code
DATA: 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.

Result


DOWNLOAD_SMW0

  • 下載T-code: SMW0的資料
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
I_OBJNAME Importing     W3OBJID   SAP WWW Gateway Object Name
I_FULLPATH Importing     RLGRAP-FILENAME   Path&Filename

Sample

Click to Expand Code
DATA: 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.

Result


SAVE_DIALOG

  • 主要是為了簡化cl_gui_frontend_services=>file_save_dialog,因為原本Changing參數filename, path, fullpath不是optional,等於要全接下來,通常就是會有2個變數用不到,浪費我的記憶體。Exporting就可以自己選要接哪些,不用動
  • 副檔名預設是txt,參考I_FILTER,若為空則是預設篩選。需自訂的話,程式內有說明
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA: 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.

Result


OPEN_DIALOG

  • 簡化cl_gui_frontend_services=>file_open_dialog某些變數
  • 預設開啟副檔名為txt
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA: 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.

Result(搭配Debug Mode)


CHECK_DBCON

  • 可以僅Check DB Connection連線正常否(可再加上schema, table作為詳細條件)
  • 若有需要可以作為CL_SQL_CONNECTION factory使用
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA 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.

Result


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需要加上,否則可能會有一些奇奇怪怪的問題。
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
TYPES: 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 ).

Result


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)
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
TYPES: 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.

Result


IMPORT_SHARED_TXT

  • 匯入文字檔 from shared folder(僅能在Windows AP使用)
  • I_START_LINE: 設定從第幾列開始讀取資料,預設是從第一列開始
  • IT_FSET: 未設定,則按吃進來切割順序寫入internal table
  • ※分隔符號生效時(接收物件含structure),follow CSV delimiter rules(V006)
  • 其他注意事項參考EXPORT_SHARED_TXT
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
TYPES: 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.

Result


EXPORT_SHARED_XLSX

  • 匯出Excel to shared folder(ALV轉Excel,僅能在Windows AP使用)
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
TYPES: 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.

Result


EXPORT_SHARED_BIN

  • 匯出Binary file to shared folder(僅能在Windows AP使用, V005 add)
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA 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.

Result


IMPORT_SHARED_BIN

  • 匯入Binary file from shared folder(僅能在Windows AP使用, V005 add)
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA: 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.

Result


GET_SHARED_FILELIST

  • 取得Shared Folder指定資料夾檔案清單(V002 add)
  • 僅能在Windows AP使用,檔名非ASCII Code應該都是亂碼
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
I_PATH Importing     STRING   Path
RT_FILE Returning X   MDG_FILETABLE_T   File List

Sample

Click to Expand Code
DATA: 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.

Result(Debug Mode)


GET_HANA_DBCON

  • 取得HANA DB Connection name(若連線失敗,取得的值為空)
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
R_HANA Returning X   DBCON_NAME   Logical name for a database connection

Sample

Click to Expand Code
DATA g_dbcon TYPE dbcon_name.

START-OF-SELECTION.
  g_dbcon = zcl_tools=>get_hana_dbcon( ).

Result(Debug Mode)


CONVERT_RANGE_TO_WHERE

  • Range資料轉換為SQL WHERE
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
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 Code
DATA: 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.

Result(Debug Mode)


GET_SYSTEM_MONITOR

  • 取得系統狀況
ParameterLevelPass ValueOptionalType(Ref To)DefaultDescription
RT_SYS Returning X   TTY_SYS   System info Table

Sample

Click to Expand Code
DATA lt_sys TYPE zcl_tools=>tty_sys.

START-OF-SELECTION.
  lt_sys = zcl_tools=>get_system_monitor( ).

Result(Debug Mode)



技術提供: 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

相关文章

  • ZCL_QALV_DISPLAY
    IntroductionHistoryPublicMethodGRID_TABNAMEGRID_ALVIDGRID_CUSTGET_VARIANTGET_FCAT_TABNAMEGET_FCAT_ALVIDCONTAINER_FACTORYEVENTIntroductionClass:ZCL_QALV_DISPLAYALV簡化用法(純Display,不可進editmode)HistoryVersionDateNameDescrip......
  • ZCL_REST_CLIENT
    IntroductionHistoryPublicMethodHANDLE_REQUESTProtectedMethod_HANDLE_REQUESTSample建立RESTfulAPIClass設定API路徑LogsAppendixSMICM各環境HostName,PortIntroductionZCL_REST_CLIENTRESTful-APIconsumerenhancement-自動記錄reque......
  • ZCL_REST_SERVER
    IntroductionHistoryPublicMethodIF_HTTP_EXTENSION~HANDLE_REQUESTProtectedMethod_HANDLE_REQUESTSample建立RESTful-APIClass設定API路徑LogsAppendixSMICM各環境HostName,PortIntroductionZCL_REST_SERVERRESTful-APIproviderenhanceme......
  • ZCL_REST_SYSTEM_MONITOR
    IntroductionHistorySwaggerIntroductionClass:ZCL_REST_SYSTEM_MONITOR利用zcl_tools=>get_system_monitor(),給外部取得SAP系統狀況HistoryVersionDateNameDescriptionV0012021/10/13HuangRoy初版SwaggerItemURLSwaggerUIhttp://tao-misdb......
  • Zclip:复制页面内容到剪贴板兼容各浏览器
    WEB开发中,要让用户复制页面中的一段代码、URL地址等信息,为了避免用户拖动鼠标再进行右键复制操作而可能出现的差错,我们可以直接在页面中放置一个复制按钮,只需要轻轻一点这个复制按钮,内容将会被复制,然后用户可以粘贴到想粘贴的地方。 本文将结合实例讲解如何使用一款基于jQuery的插......
  • 使用 SAP Fiori Tools 提供的中间件导入本地下载的 SAP UI5 库文件来启动 SAP UI5 应
    本教程第100个步骤,笔者介绍了如何使用本地部署的SAPUI5库文件来运行SAPUI5应用的技巧:SAPUI5应用开发教程之一百-如何修改SAPUI5框架的源代码实现,以及使用本地部署的SAPUI5SDK我们简单回顾一下这种方法的实现步骤:从SAPUI5官网将我们想使用的SAPUI5SDK......
  • SAP Fiori Tools 里 proxy 中间件的使用场景介绍
    使用proxy中间件可以让开发人员通过配置的方式连接不同的后台系统,或者是切换不同的SAPUI5版本。下面是一个典型的ui5.yaml里的proxy配置文件的例子:-name:fiori-tools-proxyafterMiddleware:compressionconfiguration:backend:-path:/sapur......
  • 使用 SAP Fiori Tools 自带的代理服务器解决本地运行的 SAP UI5 应用访问远端服务遇到
    我们部署在本地开发环境运行的SAPUI5应用,由于浏览器安全策略的限制,无法直接访问远端OData服务,原因是我们的SAPUI5应用本地运行在localhost这个域名上,而远端请求的OData服务的域名比如说services.odata.org,二者不是同一个域名,由于浏览器安全策略,浏览器拒绝这种跨域的......
  • 使用 SAP Fiori tools 开发 SAP UI5 应用
    SAPFioritools通过为SAPBusinessApplicationStudio和VSCode开发环境提供扩展功能,简化了SAPFioriElements应用程序的开发。SAPFioritools扩展功能可帮助开发人员创建应用程序、可视化导航、自动生成代码等。结合SAPFioriElements使用,这些扩展可以提高开发效......
  • SAP Fiori Tools 的 Application Reload Middleware 介绍
    通过applicationreloadmiddleware的帮助,开发者可以在进行FioriElements开发的过程中,即时预览这些尚未完全完成开发的应用。即时的意思是,一旦有FioriElements项目相关的文件发生变化,ApplicationReloadmiddleware会自动刷新应用。npx是一个Node.js工具,它可以让......