以windows 7環境為例:
0. 安裝openvpn,預設路徑不變,須點選openssl與rsa管理工具
go to C:\Program Files\OpenVPN\easy-rsa
1.初始化設定
modify vars.bat.sample
視需求進行以下部份的修改:
key的長度,2048安全性更高一些
set KEY_SIZE=1024
#以下部份是憑證資料
set KEY_COUNTRY=自行修改
set KEY_PROVINCE=自行修改
set KEY_CITY=自行修改
set KEY_ORG=自行修改
set KEY_EMAIL=自行修改
set KEY_CN=key的辨識值,如果有多個client,此值不可重複
set KEY_NAME=自行修改
set KEY_OU=自行修改
2. 依序執行以下檔案
init-config.bat
vars.bat
clean-all.bat
3.產生憑證
build-dh.bat #會產生檔案:dh1024.pem
build-ca.bat #會產生檔案:ca.crt ca.key
build-key-server.bat server #會產生檔案:server.csr server.key
build-key.bat client01 #會產生檔案client01.key
4.產生static key
go to C:\Program Files\OpenVPN\bin
openvpn --genkey --secret static.key #會產生檔案:static.key
-------------------------------------------------------------------------------------------------
附注Tomato VPN Server端設定:
把static.key的內容貼到Static Key欄把ca.crt的內容貼到Certificate Authority欄.
把server.crt的內容貼到Server Certificate欄.
把server.key的內容貼到Server Key欄.
把dh1024.pem的內容貼到Diffie Hellman parameters欄.
2013年11月30日 星期六
2013年11月29日 星期五
2013年11月16日 星期六
2013年11月14日 星期四
2013年11月8日 星期五
2013年11月7日 星期四
2013年10月31日 星期四
About Client copy useful information
SAP Note:
541311 CC-INFO: Parallel processes FAQ
489690 CC INFO: Copying large production client
446485 CC-ADMIN: Special copying options
365304 - CC-ADMIN: Reports for deleting tables
572139 - CC-INFO: Client copy hangs with a certain table
70643 CC-TOPIC: Client deletion (SCC5)
70290 CC-INFO: Excluding tables with 'RSCCEXPT'
541311 CC-INFO: Parallel processes FAQ
489690 CC INFO: Copying large production client
446485 CC-ADMIN: Special copying options
365304 - CC-ADMIN: Reports for deleting tables
572139 - CC-INFO: Client copy hangs with a certain table
70643 CC-TOPIC: Client deletion (SCC5)
70290 CC-INFO: Excluding tables with 'RSCCEXPT'
2013年10月30日 星期三
2013年10月23日 星期三
估算client size
Note 118823 - CC-ADMIN: Size of a client
執行程式:RSTABLESIZE
計算client size
執行程式:RSSPACECHECK
計算每個table size by client
執行程式:RSTABLESIZE
計算client size
執行程式:RSSPACECHECK
計算每個table size by client
2013年10月22日 星期二
2013年10月1日 星期二
BAPI_PO_CHANGE產生重複的表頭條件
使用bapi_po_change變更條件資料時
會產生重複的表頭條件
其中一個條件,其金額為0
另一個點選明細觀察,其條件來源(Condit.origin)
為"E"(Item total)
而用手動變更不會發生此問題
原因是bapi不會自動sort輸入的條件
但手動輸入時,系統會先sort再合併有duplicate的條件
解決方法是bapi建立條件時,先sort要輸入條件
再依序給條件計數器(COND_COUNT)值,ex: 1、2、3、4....
即可解決此問題
會產生重複的表頭條件
其中一個條件,其金額為0
另一個點選明細觀察,其條件來源(Condit.origin)
為"E"(Item total)
而用手動變更不會發生此問題
原因是bapi不會自動sort輸入的條件
但手動輸入時,系統會先sort再合併有duplicate的條件
解決方法是bapi建立條件時,先sort要輸入條件
再依序給條件計數器(COND_COUNT)值,ex: 1、2、3、4....
即可解決此問題
2013年7月30日 星期二
2013年7月2日 星期二
取得Internal Table的欄位名稱
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-cprog
fieldname = 'Internal Table Name'
TABLES
components = lt_comp.
Note:
傳到副程式時,需另行宣告才能取出使用,ex:
PERFORM input_field_info TABLES lt_comp
FORM input_field_info TABLES comp
DATA: lt_comp TYPE rstrucinfo OCCURS 0 WITH HEADER LINE.
lt_comp[] = comp[].
col = col + 1.
READ TABLE lt_comp INDEX col.
ENDFORM. " INPUT_FIELD_INFO
EXPORTING
program = sy-cprog
fieldname = 'Internal Table Name'
TABLES
components = lt_comp.
Note:
傳到副程式時,需另行宣告才能取出使用,ex:
PERFORM input_field_info TABLES lt_comp
FORM input_field_info TABLES comp
DATA: lt_comp TYPE rstrucinfo OCCURS 0 WITH HEADER LINE.
lt_comp[] = comp[].
col = col + 1.
READ TABLE lt_comp INDEX col.
ENDFORM. " INPUT_FIELD_INFO
2013年7月1日 星期一
2013年6月1日 星期六
submit使用範例
DATA: s_vkorg TYPE RANGE OF a900-vkorg,
lw_vkorg LIKE LINE OF s_vkorg,
p_locpc TYPE c.
lw_vkorg-sign = 'I'.
lw_vkorg-option = 'EQ'.
lw_vkorg-low = 'nnnn'.
APPEND lw_vkorg TO s_vkorg.
p_locpc = 'X'.
SUBMIT zreport WITH s_vkorg IN s_vkorg
WITH p_locpc = p_locpc
AND RETURN.
第一個s_vkorg是 zreport的畫面選項
第二個s_vkorg是本端呼叫的指派變數值
lw_vkorg LIKE LINE OF s_vkorg,
p_locpc TYPE c.
lw_vkorg-sign = 'I'.
lw_vkorg-option = 'EQ'.
lw_vkorg-low = 'nnnn'.
APPEND lw_vkorg TO s_vkorg.
p_locpc = 'X'.
SUBMIT zreport WITH s_vkorg IN s_vkorg
WITH p_locpc = p_locpc
AND RETURN.
第一個s_vkorg是 zreport的畫面選項
第二個s_vkorg是本端呼叫的指派變數值
其他參考
2013年5月31日 星期五
條件金額修改方法
lw_komg-vkorg = sales org.
lw_komg-vtweg = sale channel.
lw_komg-matnr = Material number.
lw_komg-werks = plant.
lt_komv-kappl = 'V'. "V = Sales and Distribution
lt_komv-kschl = condition type.
lt_komv-kbetr = amonut. "須先轉換為SAP儲存值
lt_komv-waers = currency type.
lt_komv-kpein = 1.
lt_komv-kmein = 'BOX'.
APPEND lt_komv.
CASE r_ucomm.
WHEN '&EXE'.
CALL FUNCTION 'RV_CONDITION_COPY'
EXPORTING
application = 'V'
condition_table = '900' " 3 character cond. table
condition_type = 'XXXX' " cond. type
* date_from = '20120101' " valid on
* date_to = '99991231' " valid to
enqueue = 'X' " lock entry
* i_komk = komk
* i_komp = komp
key_fields = lw_komg " key fields
maintain_mode = 'A' " A= create " B= change, " C= display " D= create
no_authority_check = 'X'
* selection_date = '20120101' " valid on
keep_old_records = ' '
overlap_confirmed = 'X'
* no_db_update = space
* IMPORTING
* e_komk = komk
* e_komp = komp
* new_record = lv_new_record
TABLES
copy_records = lt_komv
EXCEPTIONS
enqueue_on_record = 1
invalid_application = 2
invalid_condition_number = 3
invalid_condition_type = 4
no_selection = 5
table_not_valid = 6
no_authority_ekorg = 7
no_authority_kschl = 8.
IF sy-subrc = 0.
CALL FUNCTION 'RV_CONDITION_SAVE'.
COMMIT WORK.
* CALL FUNCTION 'RV_CONDITION_RESET'.
* 如果還要繼續改下一筆,要重置條件,不然會出錯
* "necessary to write data
*
* COMMIT WORK.
ELSE.
PERFORM log_error_msg.
ENDIF.
lw_komg-vtweg = sale channel.
lw_komg-matnr = Material number.
lw_komg-werks = plant.
lt_komv-kappl = 'V'. "V = Sales and Distribution
lt_komv-kschl = condition type.
lt_komv-kbetr = amonut. "須先轉換為SAP儲存值
lt_komv-waers = currency type.
lt_komv-kpein = 1.
lt_komv-kmein = 'BOX'.
APPEND lt_komv.
CASE r_ucomm.
WHEN '&EXE'.
CALL FUNCTION 'RV_CONDITION_COPY'
EXPORTING
application = 'V'
condition_table = '900' " 3 character cond. table
condition_type = 'XXXX' " cond. type
* date_from = '20120101' " valid on
* date_to = '99991231' " valid to
enqueue = 'X' " lock entry
* i_komk = komk
* i_komp = komp
key_fields = lw_komg " key fields
maintain_mode = 'A' " A= create " B= change, " C= display " D= create
no_authority_check = 'X'
* selection_date = '20120101' " valid on
keep_old_records = ' '
overlap_confirmed = 'X'
* no_db_update = space
* IMPORTING
* e_komk = komk
* e_komp = komp
* new_record = lv_new_record
TABLES
copy_records = lt_komv
EXCEPTIONS
enqueue_on_record = 1
invalid_application = 2
invalid_condition_number = 3
invalid_condition_type = 4
no_selection = 5
table_not_valid = 6
no_authority_ekorg = 7
no_authority_kschl = 8.
IF sy-subrc = 0.
CALL FUNCTION 'RV_CONDITION_SAVE'.
COMMIT WORK.
* CALL FUNCTION 'RV_CONDITION_RESET'.
* 如果還要繼續改下一筆,要重置條件,不然會出錯
* "necessary to write data
*
* COMMIT WORK.
ELSE.
PERFORM log_error_msg.
ENDIF.
2013年5月25日 星期六
2013年5月24日 星期五
2013年5月9日 星期四
2013年5月2日 星期四
2013年4月30日 星期二
2013年4月28日 星期日
2013年4月27日 星期六
2013年4月24日 星期三
排除不合的"狀態選擇設定檔"
IF NOT selid IS INITIAL.
LOOP AT objnr_tab.
DATA flg_status_ok TYPE c. "Statusprüfung OK
CALL FUNCTION 'STATUS_CHECK_BY_SELSCHEM'
EXPORTING
objnr = objnr_tab-objnr
selid = selid
IMPORTING
fullfill = flg_status_ok
EXCEPTIONS
no_stat_scheme = 01
no_stat_tab = 02.
IF sy-subrc IS INITIAL
AND flg_status_ok IS INITIAL.
DELETE objnr_tab.
ENDIF.
ENDLOOP.
ENDIF.
LOOP AT objnr_tab.
DATA flg_status_ok TYPE c. "Statusprüfung OK
CALL FUNCTION 'STATUS_CHECK_BY_SELSCHEM'
EXPORTING
objnr = objnr_tab-objnr
selid = selid
IMPORTING
fullfill = flg_status_ok
EXCEPTIONS
no_stat_scheme = 01
no_stat_tab = 02.
IF sy-subrc IS INITIAL
AND flg_status_ok IS INITIAL.
DELETE objnr_tab.
ENDIF.
ENDLOOP.
ENDIF.
2013年4月17日 星期三
SAP 確認小視窗
answer = 1確定,2否決,A取消
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
* TITLEBAR = ' '
* DIAGNOSE_OBJECT = ' '
text_question = text-001
* TEXT_BUTTON_1 = 'Ja'(001)
* ICON_BUTTON_1 = ' '
* TEXT_BUTTON_2 = 'Nein'(002)
* ICON_BUTTON_2 = ' '
* DEFAULT_BUTTON = '1'
* DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
* IV_QUICKINFO_BUTTON_1 = ' '
* IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
answer = lv_ans
* TABLES
* PARAMETER =
* EXCEPTIONS
* TEXT_NOT_FOUND = 1
* OTHERS = 2
.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
* TITLEBAR = ' '
* DIAGNOSE_OBJECT = ' '
text_question = text-001
* TEXT_BUTTON_1 = 'Ja'(001)
* ICON_BUTTON_1 = ' '
* TEXT_BUTTON_2 = 'Nein'(002)
* ICON_BUTTON_2 = ' '
* DEFAULT_BUTTON = '1'
* DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
* IV_QUICKINFO_BUTTON_1 = ' '
* IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
answer = lv_ans
* TABLES
* PARAMETER =
* EXCEPTIONS
* TEXT_NOT_FOUND = 1
* OTHERS = 2
.
2013年4月5日 星期五
物料單位轉換
包含數量轉換
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
EXPORTING
i_matnr =
i_in_me =
i_out_me =
i_menge =
* IMPORTING
* E_MENGE =
* EXCEPTIONS
* ERROR_IN_APPLICATION = 1
* ERROR = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
一般基礎單位轉換
CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
* INPUT = 0
* KZMEINH = ' '
matnr =
meinh =
* MEINS = ' '
* EXTENDED_CONV = ' '
* TYPE_UMR = ' '
* NO_OUTPUT = ' '
* CHARGE =
* CHARG_CUOBJ =
* WERKS =
* IMPORTING
* ADDKO =
* MEINS =
* OUTPUT =
* UMREN =
* UMREZ =
* BATCH_CONVERSION_ERROR =
* KZWSO =
* EXCEPTIONS
* CONVERSION_NOT_FOUND = 1
* INPUT_INVALID = 2
* MATERIAL_NOT_FOUND = 3
* MEINH_NOT_FOUND = 4
* MEINS_MISSING = 5
* NO_MEINH = 6
* OUTPUT_INVALID = 7
* OVERFLOW = 8
* OTHERS = 9
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'MD_CONVERT_MATERIAL_UNIT'
EXPORTING
i_matnr =
i_in_me =
i_out_me =
i_menge =
* IMPORTING
* E_MENGE =
* EXCEPTIONS
* ERROR_IN_APPLICATION = 1
* ERROR = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
一般基礎單位轉換
CALL FUNCTION 'MATERIAL_UNIT_CONVERSION'
EXPORTING
* INPUT = 0
* KZMEINH = ' '
matnr =
meinh =
* MEINS = ' '
* EXTENDED_CONV = ' '
* TYPE_UMR = ' '
* NO_OUTPUT = ' '
* CHARGE =
* CHARG_CUOBJ =
* WERKS =
* IMPORTING
* ADDKO =
* MEINS =
* OUTPUT =
* UMREN =
* UMREZ =
* BATCH_CONVERSION_ERROR =
* KZWSO =
* EXCEPTIONS
* CONVERSION_NOT_FOUND = 1
* INPUT_INVALID = 2
* MATERIAL_NOT_FOUND = 3
* MEINH_NOT_FOUND = 4
* MEINS_MISSING = 5
* NO_MEINH = 6
* OUTPUT_INVALID = 7
* OVERFLOW = 8
* OTHERS = 9
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
2013年4月1日 星期一
SAP指標與參考物件應用
1. 宣告參考物件:DATA dref TYPE REF TO DATA.(任意類型)
STANDARD TABLE.(Table類型的宣告)
2. 建立參考物件的記憶體位址以及其資料結構:CREATE DATA dref {TYPE type}|{LIKE dobj}
3. dref->* :取得記體位址的資料結構
4. ASSIGN dref->* TO:將記憶體位址的資料結構指派給指標變數
5. Select ... INTO
Loop at xxx INTO
ASSIGN COMPONENT sy-index
OF STRUCTURE TO .
指派值到指標變數所指的位址
6. 參考物件無法直接使用,所以必須透過指標存取
REPORT z_barry_test .
TYPE-POOLS : abap.
FIELD-SYMBOLS: TYPE STANDARD TABLE, "宣告指標變數
,
.
DATA: dy_table TYPE REF TO data, "宣告參考物件
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
DATA: itab LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.
PARAMETERS p_file TYPE localfile.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_file_name USING p_file.
START-OF-SELECTION.
PERFORM get_file_data.
PERFORM get_structure.
PERFORM create_dynamic_itab.
PERFORM get_data.
PERFORM write_out.
*---------------------------------------------------------------------*
* FORM get_structure *
*---------------------------------------------------------------------*
FORM get_structure.
LOOP AT itab.
CLEAR xfc.
xfc-fieldname = itab-value .
xfc-inttype = 'C'.
xfc-intlen = 18.
* xfc-decimals = 4.
APPEND xfc TO ifc.
ENDLOOP.
ENDFORM. "get_structure
*---------------------------------------------------------------------*
* FORM create_dynamic_itab *
*---------------------------------------------------------------------*
FORM create_dynamic_itab.
CALL METHOD cl_alv_table_create=>create_dynamic_table "建立參考物件
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO. "指派參考物件記憶體位址連結到指標變數
CREATE DATA dy_line LIKE LINE OF. "建立與指標變數所指的記憶體空間結構相同的參考物件
ASSIGN dy_line->* TO.
ENDFORM. "create_dynamic_itab
*---------------------------------------------------------------------*
* FORM get_data *
*---------------------------------------------------------------------*
FORM get_data.
DATA: BEGIN OF itab OCCURS 0 .
INCLUDE STRUCTURE eord.
DATA: END OF itab.
SELECT matnr werks vdatu bdatu lifnr reswk ekorg flifn
UP TO 10 ROWS
INTO CORRESPONDING FIELDS OF TABLE
FROM eord.
ENDFORM. "get_data
*---------------------------------------------------------------------*
* FORM write_out *
*---------------------------------------------------------------------*
FORM write_out.
LOOP AT INTO .
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE TO .
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF sy-index = 1.
WRITE:/.
ELSE.
WRITE:.
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. "write_out
*&---------------------------------------------------------------------*
*& Form GET_FILE_NAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_FILE text
*----------------------------------------------------------------------*
FORM get_file_name USING p_file.
CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
file_name = p_file
.
ENDFORM. " GET_FILE_NAME
*&---------------------------------------------------------------------*
*& Form GET_FILE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- br="" nbsp="" p2="" text="">*----------------------------------------------------------------------*
FORM get_file_data .
TYPE-POOLS : truxs.
DATA: file_str TYPE rlgrap-filename.
DATA: lv_werks1 TYPE string.
DATA: lv_werks2 TYPE string.
DATA: lv_lifnr LIKE eina-lifnr,
lv_matnr LIKE eina-matnr.
file_str = p_file.
CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = file_str
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '255'
i_end_row = '9999'
* SHEET_NAME =
TABLES
intern = itab
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " GET_FILE_DATA
-->
STANDARD TABLE.(Table類型的宣告)
2. 建立參考物件的記憶體位址以及其資料結構:CREATE DATA dref {TYPE type}|{LIKE dobj}
3. dref->* :取得記體位址的資料結構
4. ASSIGN dref->* TO
5. Select ... INTO
Loop at xxx INTO
ASSIGN COMPONENT sy-index
OF STRUCTURE
指派值到指標變數所指的位址
6. 參考物件無法直接使用,所以必須透過指標存取
REPORT z_barry_test .
TYPE-POOLS : abap.
FIELD-SYMBOLS:
DATA: dy_table TYPE REF TO data, "宣告參考物件
dy_line TYPE REF TO data,
xfc TYPE lvc_s_fcat,
ifc TYPE lvc_t_fcat.
DATA: itab LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.
PARAMETERS p_file TYPE localfile.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_file_name USING p_file.
START-OF-SELECTION.
PERFORM get_file_data.
PERFORM get_structure.
PERFORM create_dynamic_itab.
PERFORM get_data.
PERFORM write_out.
*---------------------------------------------------------------------*
* FORM get_structure *
*---------------------------------------------------------------------*
FORM get_structure.
LOOP AT itab.
CLEAR xfc.
xfc-fieldname = itab-value .
xfc-inttype = 'C'.
xfc-intlen = 18.
* xfc-decimals = 4.
APPEND xfc TO ifc.
ENDLOOP.
ENDFORM. "get_structure
*---------------------------------------------------------------------*
* FORM create_dynamic_itab *
*---------------------------------------------------------------------*
FORM create_dynamic_itab.
CALL METHOD cl_alv_table_create=>create_dynamic_table "建立參考物件
EXPORTING
it_fieldcatalog = ifc
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO
CREATE DATA dy_line LIKE LINE OF
ASSIGN dy_line->* TO
ENDFORM. "create_dynamic_itab
*---------------------------------------------------------------------*
* FORM get_data *
*---------------------------------------------------------------------*
FORM get_data.
DATA: BEGIN OF itab OCCURS 0 .
INCLUDE STRUCTURE eord.
DATA: END OF itab.
SELECT matnr werks vdatu bdatu lifnr reswk ekorg flifn
UP TO 10 ROWS
INTO CORRESPONDING FIELDS OF TABLE
FROM eord.
ENDFORM. "get_data
*---------------------------------------------------------------------*
* FORM write_out *
*---------------------------------------------------------------------*
FORM write_out.
LOOP AT
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE
IF sy-subrc <> 0.
EXIT.
ENDIF.
IF sy-index = 1.
WRITE:/
ELSE.
WRITE:
ENDIF.
ENDDO.
ENDLOOP.
ENDFORM. "write_out
*&---------------------------------------------------------------------*
*& Form GET_FILE_NAME
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_P_FILE text
*----------------------------------------------------------------------*
FORM get_file_name USING p_file.
CALL FUNCTION 'F4_FILENAME'
* EXPORTING
* PROGRAM_NAME = SYST-CPROG
* DYNPRO_NUMBER = SYST-DYNNR
* FIELD_NAME = ' '
IMPORTING
file_name = p_file
.
ENDFORM. " GET_FILE_NAME
*&---------------------------------------------------------------------*
*& Form GET_FILE_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- br="" nbsp="" p2="" text="">*----------------------------------------------------------------------*
FORM get_file_data .
TYPE-POOLS : truxs.
DATA: file_str TYPE rlgrap-filename.
DATA: lv_werks1 TYPE string.
DATA: lv_werks2 TYPE string.
DATA: lv_lifnr LIKE eina-lifnr,
lv_matnr LIKE eina-matnr.
file_str = p_file.
CALL FUNCTION 'ZALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = file_str
i_begin_col = '1'
i_begin_row = '1'
i_end_col = '255'
i_end_row = '9999'
* SHEET_NAME =
TABLES
intern = itab
* EXCEPTIONS
* INCONSISTENT_PARAMETERS = 1
* UPLOAD_OLE = 2
* OTHERS = 3
.
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " GET_FILE_DATA
-->
2013年3月29日 星期五
ABAP中讀取EXCEL中不同的SHEET數據
ABAP中讀取EXCEL中不同的SHEET數據
作者:侯志宇
function ZALSM_EXCEL_TO_INTERNAL_TABLE .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(FILENAME) LIKE RLGRAP-FILENAME
*" VALUE(I_BEGIN_COL) TYPE I
*" VALUE(I_BEGIN_ROW) TYPE I
*" VALUE(I_END_COL) TYPE I
*" VALUE(I_END_ROW) TYPE I
*" VALUE(SHEET_NAME) LIKE ALSMEX_TABLINE-VALUE OPTIONAL
*" TABLES
*" INTERN STRUCTURE ALSMEX_TABLINE
*" EXCEPTIONS
*" INCONSISTENT_PARAMETERS
*" UPLOAD_OLE
*"----------------------------------------------------------------------
data: EXCEL_TAB type TY_T_SENDER.
data: LD_SEPARATOR type C.
data: APPLICATION type OLE2_OBJECT,
WORKBOOK type OLE2_OBJECT,
RANGE type OLE2_OBJECT,
WORKSHEET type OLE2_OBJECT.
data: H_CELL type OLE2_OBJECT,
H_CELL1 type OLE2_OBJECT.
data:
LD_RC type I.
* Rückgabewert der Methode "clipboard_export "
* Makro für Fehlerbehandlung der Methods
define M_MESSAGE.
CASE SY-SUBRC.
WHEN 0.
WHEN 1.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
WHEN OTHERS. RAISE UPLOAD_OLE.
ENDCASE.
end-of-definition.
* check parameters
if I_BEGIN_ROW > I_END_ROW. raise INCONSISTENT_PARAMETERS. endif.
if I_BEGIN_COL > I_END_COL. raise INCONSISTENT_PARAMETERS. endif.
* Get TAB-sign for separation of fields
class CL_ABAP_CHAR_UTILITIES definition load.
LD_SEPARATOR = CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
* open file in Excel
if APPLICATION-HEADER = SPACE or APPLICATION-HANDLE = -1.
create object APPLICATION 'Excel.Application'.
M_MESSAGE.
endif.
call method of APPLICATION 'Workbooks' = WORKBOOK.
M_MESSAGE.
call method of WORKBOOK 'Open'
exporting
#1 = FILENAME.
M_MESSAGE.
*--ADD HOUZHIYU
** set property of application 'Visible' = 1.
** m_message.
if SHEET_NAME = SPACE."用默認模式
get property of APPLICATION 'ACTIVESHEET' = WORKSHEET.
M_MESSAGE.
else.
*-->可以實現讀取多個sheet
call method of APPLICATION 'WORKSHEETS' = WORKSHEET
exporting
#1 = SHEET_NAME.
call method of WORKSHEET 'Activate'.
M_MESSAGE.
endif.
*---END OF------------------------------------------------
* mark whole spread sheet
call method of WORKSHEET 'Cells' = H_CELL
exporting
#1 = I_BEGIN_ROW
#2 = I_BEGIN_COL.
M_MESSAGE.
call method of WORKSHEET 'Cells' = H_CELL1
exporting
#1 = I_END_ROW
#2 = I_END_COL.
M_MESSAGE.
call method of WORKSHEET 'RANGE' = RANGE
exporting
#1 = H_CELL
#2 = H_CELL1.
M_MESSAGE.
call method of RANGE 'SELECT'.
M_MESSAGE.
* copy marked area (whole spread sheet) into Clippboard
call method of RANGE 'COPY'.
M_MESSAGE.
* read clipboard into ABAP
call method CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_IMPORT
importing
DATA = EXCEL_TAB
exceptions
CNTL_ERROR = 1
* ERROR_NO_GUI = 2
* NOT_SUPPORTED_BY_GUI = 3
others = 4
.
if SY-SUBRC <> 0.
message A037(ALSMEX).
endif.
perform SEPARATED_TO_INTERN_CONVERT tables EXCEL_TAB INTERN
using LD_SEPARATOR.
* clear clipboard
refresh EXCEL_TAB.
call method CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_EXPORT
importing
DATA = EXCEL_TAB
changing
RC = LD_RC
exceptions
CNTL_ERROR = 1
* ERROR_NO_GUI = 2
* NOT_SUPPORTED_BY_GUI = 3
others = 4
.
* quit Excel and free ABAP Object - unfortunately, this does not kill
* the Excel process
call method of APPLICATION 'QUIT'.
M_MESSAGE.
* >>>>> Begin of change note 575877
* to kill the Excel process it's necessary to free all used objects
free object H_CELL. M_MESSAGE.
free object H_CELL1. M_MESSAGE.
free object RANGE. M_MESSAGE.
free object WORKSHEET. M_MESSAGE.
free object WORKBOOK. M_MESSAGE.
free object APPLICATION. M_MESSAGE.
* <<<<< End of change note 575877
endfunction.
作者:侯志宇
function ZALSM_EXCEL_TO_INTERNAL_TABLE .
*"----------------------------------------------------------------------
*"*"Local interface:
*" IMPORTING
*" VALUE(FILENAME) LIKE RLGRAP-FILENAME
*" VALUE(I_BEGIN_COL) TYPE I
*" VALUE(I_BEGIN_ROW) TYPE I
*" VALUE(I_END_COL) TYPE I
*" VALUE(I_END_ROW) TYPE I
*" VALUE(SHEET_NAME) LIKE ALSMEX_TABLINE-VALUE OPTIONAL
*" TABLES
*" INTERN STRUCTURE ALSMEX_TABLINE
*" EXCEPTIONS
*" INCONSISTENT_PARAMETERS
*" UPLOAD_OLE
*"----------------------------------------------------------------------
data: EXCEL_TAB type TY_T_SENDER.
data: LD_SEPARATOR type C.
data: APPLICATION type OLE2_OBJECT,
WORKBOOK type OLE2_OBJECT,
RANGE type OLE2_OBJECT,
WORKSHEET type OLE2_OBJECT.
data: H_CELL type OLE2_OBJECT,
H_CELL1 type OLE2_OBJECT.
data:
LD_RC type I.
* Rückgabewert der Methode "clipboard_export "
* Makro für Fehlerbehandlung der Methods
define M_MESSAGE.
CASE SY-SUBRC.
WHEN 0.
WHEN 1.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
WHEN OTHERS. RAISE UPLOAD_OLE.
ENDCASE.
end-of-definition.
* check parameters
if I_BEGIN_ROW > I_END_ROW. raise INCONSISTENT_PARAMETERS. endif.
if I_BEGIN_COL > I_END_COL. raise INCONSISTENT_PARAMETERS. endif.
* Get TAB-sign for separation of fields
class CL_ABAP_CHAR_UTILITIES definition load.
LD_SEPARATOR = CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
* open file in Excel
if APPLICATION-HEADER = SPACE or APPLICATION-HANDLE = -1.
create object APPLICATION 'Excel.Application'.
M_MESSAGE.
endif.
call method of APPLICATION 'Workbooks' = WORKBOOK.
M_MESSAGE.
call method of WORKBOOK 'Open'
exporting
#1 = FILENAME.
M_MESSAGE.
*--ADD HOUZHIYU
** set property of application 'Visible' = 1.
** m_message.
if SHEET_NAME = SPACE."用默認模式
get property of APPLICATION 'ACTIVESHEET' = WORKSHEET.
M_MESSAGE.
else.
*-->可以實現讀取多個sheet
call method of APPLICATION 'WORKSHEETS' = WORKSHEET
exporting
#1 = SHEET_NAME.
call method of WORKSHEET 'Activate'.
M_MESSAGE.
endif.
*---END OF------------------------------------------------
* mark whole spread sheet
call method of WORKSHEET 'Cells' = H_CELL
exporting
#1 = I_BEGIN_ROW
#2 = I_BEGIN_COL.
M_MESSAGE.
call method of WORKSHEET 'Cells' = H_CELL1
exporting
#1 = I_END_ROW
#2 = I_END_COL.
M_MESSAGE.
call method of WORKSHEET 'RANGE' = RANGE
exporting
#1 = H_CELL
#2 = H_CELL1.
M_MESSAGE.
call method of RANGE 'SELECT'.
M_MESSAGE.
* copy marked area (whole spread sheet) into Clippboard
call method of RANGE 'COPY'.
M_MESSAGE.
* read clipboard into ABAP
call method CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_IMPORT
importing
DATA = EXCEL_TAB
exceptions
CNTL_ERROR = 1
* ERROR_NO_GUI = 2
* NOT_SUPPORTED_BY_GUI = 3
others = 4
.
if SY-SUBRC <> 0.
message A037(ALSMEX).
endif.
perform SEPARATED_TO_INTERN_CONVERT tables EXCEL_TAB INTERN
using LD_SEPARATOR.
* clear clipboard
refresh EXCEL_TAB.
call method CL_GUI_FRONTEND_SERVICES=>CLIPBOARD_EXPORT
importing
DATA = EXCEL_TAB
changing
RC = LD_RC
exceptions
CNTL_ERROR = 1
* ERROR_NO_GUI = 2
* NOT_SUPPORTED_BY_GUI = 3
others = 4
.
* quit Excel and free ABAP Object - unfortunately, this does not kill
* the Excel process
call method of APPLICATION 'QUIT'.
M_MESSAGE.
* >>>>> Begin of change note 575877
* to kill the Excel process it's necessary to free all used objects
free object H_CELL. M_MESSAGE.
free object H_CELL1. M_MESSAGE.
free object RANGE. M_MESSAGE.
free object WORKSHEET. M_MESSAGE.
free object WORKBOOK. M_MESSAGE.
free object APPLICATION. M_MESSAGE.
* <<<<< End of change note 575877
endfunction.
2013年3月23日 星期六
金額依幣別顯示轉換
CALL FUNCTION 'CURRENCY_AMOUNT_SAP_TO_DISPLAY'
EXPORTING
currency = 幣別
amount_internal = SAP DB 儲存金額
IMPORTING
AMOUNT_DISPLAY = 顯示金額
* EXCEPTIONS
* INTERNAL_ERROR = 1
* OTHERS = 2
.
CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
EXPORTING
currency = lt_current-waers
IMPORTING
factor = lv_factor
EXCEPTIONS
too_many_decimals = 1
OTHERS = 2.
lt_current-dmbtr = lt_current-dmbtr * lv_factor . "依幣別轉換顯示金額
CALL FUNCTION 'CURRENCY_AMOUNT_DISPLAY_TO_SAP'
EXPORTING
currency = 幣別
amount_display = 顯示金額
IMPORTING
AMOUNT_INTERNAL = SAP DB 儲存金額
EXCEPTIONS
INTERNAL_ERROR = 1
OTHERS = 2
.
EXPORTING
currency = 幣別
amount_internal = SAP DB 儲存金額
IMPORTING
AMOUNT_DISPLAY = 顯示金額
* EXCEPTIONS
* INTERNAL_ERROR = 1
* OTHERS = 2
.
CALL FUNCTION 'CURRENCY_CONVERTING_FACTOR'
EXPORTING
currency = lt_current-waers
IMPORTING
factor = lv_factor
EXCEPTIONS
too_many_decimals = 1
OTHERS = 2.
lt_current-dmbtr = lt_current-dmbtr * lv_factor . "依幣別轉換顯示金額
CALL FUNCTION 'CURRENCY_AMOUNT_DISPLAY_TO_SAP'
EXPORTING
currency = 幣別
amount_display = 顯示金額
IMPORTING
AMOUNT_INTERNAL = SAP DB 儲存金額
EXCEPTIONS
INTERNAL_ERROR = 1
OTHERS = 2
.
ALV use top of page
ALV grid:
直接將form name 指派給 i_callback_top_of_page
ALV list:
it_events 的name要有TOP_OF_PAGE,並且指派自建的form name到form欄位中
Example:
gt_events TYPE slis_t_event WITH HEADER LINE.
gt_events-form = 'TOP_OF_PAGE'.
gt_events-name = 'TOP_OF_PAGE'.
APPEND gt_events.
也可以把SAP內建的EVENT全部叫出來
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = GT_EVENTS.
直接將form name 指派給 i_callback_top_of_page
ALV list:
it_events 的name要有TOP_OF_PAGE,並且指派自建的form name到form欄位中
Example:
gt_events TYPE slis_t_event WITH HEADER LINE.
gt_events-form = 'TOP_OF_PAGE'.
gt_events-name = 'TOP_OF_PAGE'.
APPEND gt_events.
也可以把SAP內建的EVENT全部叫出來
CALL FUNCTION 'REUSE_ALV_EVENTS_GET'
EXPORTING
I_LIST_TYPE = 0
IMPORTING
ET_EVENTS = GT_EVENTS.
2013年3月20日 星期三
2013年3月14日 星期四
Excel自本機上傳SAP server
TYPE-POOLS : truxs.
DATA: file_str TYPE string.
DATA: lv_raw_data TYPE truxs_t_text_data.
DATA: BEGIN OF lt_tab1 OCCURS 0, "上傳暫存
lifnr TYPE string,
descr TYPE string,
matnr TYPE string,
ekorg TYPE string,
esokz TYPE string,
ekgrp TYPE string,
netpr TYPE string,
peinh TYPE string,
meins TYPE string,
waers TYPE string,
minbm TYPE string,
aplfz TYPE string,
datab TYPE string,
datbi TYPE string,
END OF lt_tab1.
file_str = p_file.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
i_tab_raw_data = lv_raw_data
i_filename = p_file
TABLES
i_tab_converted_data = lt_tab1
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
DATA: file_str TYPE string.
DATA: lv_raw_data TYPE truxs_t_text_data.
DATA: BEGIN OF lt_tab1 OCCURS 0, "上傳暫存
lifnr TYPE string,
descr TYPE string,
matnr TYPE string,
ekorg TYPE string,
esokz TYPE string,
ekgrp TYPE string,
netpr TYPE string,
peinh TYPE string,
meins TYPE string,
waers TYPE string,
minbm TYPE string,
aplfz TYPE string,
datab TYPE string,
datbi TYPE string,
END OF lt_tab1.
file_str = p_file.
CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'
EXPORTING
* I_FIELD_SEPERATOR =
* I_LINE_HEADER =
i_tab_raw_data = lv_raw_data
i_filename = p_file
TABLES
i_tab_converted_data = lt_tab1
* EXCEPTIONS
* CONVERSION_FAILED = 1
* OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
將錯誤訊息寫入變數
Function的exceptions部份,要設定
error_message = n
才能阻擋function發出錯誤訊息
然而此法只對message type = E, A有效
如為X則仍然會強制跳出,成為short dump
DATA lv_text LIKE t100-text.
DATA: lv_msgv1 TYPE symsgv,
lv_msgv2 TYPE symsgv,
lv_msgv3 TYPE symsgv,
lv_msgv4 TYPE symsgv.
SELECT SINGLE text FROM t100 INTO lv_text
WHERE sprsl = 'M'
AND arbgb = gt_msgtab-msgid
AND msgnr = gt_msgtab-msgnr.
lv_msgv1 = gt_msgtab-msgv1. "Function或BDC傳出的錯誤訊息
lv_msgv2 = gt_msgtab-msgv2.
lv_msgv3 = gt_msgtab-msgv3.
lv_msgv4 = gt_msgtab-msgv4.
CALL FUNCTION 'FIEB_REPLACE_AMPERSAND_MESSAGE'
EXPORTING
im_text = lv_text
im_msgv1 = lv_msgv1
im_msgv2 = lv_msgv2
im_msgv3 = lv_msgv3
im_msgv4 = lv_msgv4
IMPORTING
ex_text = lv_text.
error_message = n
才能阻擋function發出錯誤訊息
然而此法只對message type = E, A有效
如為X則仍然會強制跳出,成為short dump
DATA lv_text LIKE t100-text.
DATA: lv_msgv1 TYPE symsgv,
lv_msgv2 TYPE symsgv,
lv_msgv3 TYPE symsgv,
lv_msgv4 TYPE symsgv.
SELECT SINGLE text FROM t100 INTO lv_text
WHERE sprsl = 'M'
AND arbgb = gt_msgtab-msgid
AND msgnr = gt_msgtab-msgnr.
lv_msgv1 = gt_msgtab-msgv1. "Function或BDC傳出的錯誤訊息
lv_msgv2 = gt_msgtab-msgv2.
lv_msgv3 = gt_msgtab-msgv3.
lv_msgv4 = gt_msgtab-msgv4.
CALL FUNCTION 'FIEB_REPLACE_AMPERSAND_MESSAGE'
EXPORTING
im_text = lv_text
im_msgv1 = lv_msgv1
im_msgv2 = lv_msgv2
im_msgv3 = lv_msgv3
im_msgv4 = lv_msgv4
IMPORTING
ex_text = lv_text.
ABAP BDC 模版
*BDC data declaration
DATA gt_bdctab LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA gt_msgtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
PERFORM bdc_dynpro USING 'SAPLMEOR' '0200'.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
PERFORM call_transaction USING 'ME01'.
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0829 text
* -->P_0830 text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING p_program p_dynpro.
CLEAR gt_bdctab.
gt_bdctab-program = p_program.
gt_bdctab-dynpro = p_dynpro.
gt_bdctab-dynbegin = 'X'.
APPEND gt_bdctab.
ENDFORM. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0834 text
* -->P_0835 text
*----------------------------------------------------------------------*
FORM bdc_field USING p_fnam
p_fval.
CLEAR gt_bdctab.
gt_bdctab-fnam = p_fnam.
gt_bdctab-fval = p_fval.
APPEND gt_bdctab.
ENDFORM. " BDC_FIELD
*&---------------------------------------------------------------------*
*& Form CALL_TRANSACTION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0412 text
*----------------------------------------------------------------------*
FORM call_transaction USING p_tcode.
CALL TRANSACTION p_tcode USING gt_bdctab
MODE 'N'
UPDATE 'S'
MESSAGES INTO gt_msgtab.
ENDFORM. " CALL_TRANSACTION
DATA gt_bdctab LIKE bdcdata OCCURS 0 WITH HEADER LINE.
DATA gt_msgtab LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
PERFORM bdc_dynpro USING 'SAPLMEOR' '0200'.
PERFORM bdc_field USING 'BDC_OKCODE' '/00'.
PERFORM call_transaction USING 'ME01'.
*&---------------------------------------------------------------------*
*& Form BDC_DYNPRO
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0829 text
* -->P_0830 text
*----------------------------------------------------------------------*
FORM bdc_dynpro USING p_program p_dynpro.
CLEAR gt_bdctab.
gt_bdctab-program = p_program.
gt_bdctab-dynpro = p_dynpro.
gt_bdctab-dynbegin = 'X'.
APPEND gt_bdctab.
ENDFORM. " BDC_DYNPRO
*&---------------------------------------------------------------------*
*& Form BDC_FIELD
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0834 text
* -->P_0835 text
*----------------------------------------------------------------------*
FORM bdc_field USING p_fnam
p_fval.
CLEAR gt_bdctab.
gt_bdctab-fnam = p_fnam.
gt_bdctab-fval = p_fval.
APPEND gt_bdctab.
ENDFORM. " BDC_FIELD
*&---------------------------------------------------------------------*
*& Form CALL_TRANSACTION
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->P_0412 text
*----------------------------------------------------------------------*
FORM call_transaction USING p_tcode.
CALL TRANSACTION p_tcode USING gt_bdctab
MODE 'N'
UPDATE 'S'
MESSAGES INTO gt_msgtab.
ENDFORM. " CALL_TRANSACTION
訂閱:
文章 (Atom)