2012-05-10 23 views
0

我嘗試下載一個內部表格到我的電腦,下載應該使用轉換出口。SAP:如何使用轉換退出下載數據?

示例: 表T002包含一個帶有一個字符(T0002-SPRAS)的語言鍵。

當我WRITE T0002-SPRAS.常規ISOLA轉換使用,我得到兩個字符的語言鍵(ê成爲EN ...) 這個轉換例程應該用於導出文件的。

我的測試報告:

REPORT Y_MY_DOWNLOAD_TEST. 

CONSTANTS: c_filename type string VALUE 'C:\temp\test.txt'. 
data: it_table type table of t002. 

start-of-selection. 

    SELECT * from t002 into table it_table. 

* Start file download 
    CALL METHOD cl_gui_frontend_services=>gui_download 
    EXPORTING 
     filename     = c_filename 
     filetype     = 'ASC' "or DAT 
     WRITE_FIELD_SEPARATOR  = 'X' 
     WRITE_LF     = 'X' 
*  DAT_MODE     = SPACE 
     codepage     = '4110'  "UNICODE 
     SHOW_TRANSFER_STATUS  = 'X' 
     WRITE_LF_AFTER_LAST_LINE = 'X' 
    CHANGING 
     data_tab     = it_table 
    EXCEPTIONS 
     OTHERS     = 99. 

    write: 'end'. 

結果是沒有轉換出口的使用文件(英文保持Ë)。

SAP documentation提參數dat_mode

如果該標誌被設置,....轉換出口不被執行。

我沒有設置標誌,所以我期望轉換完成。 我嘗試過不同的組合(dat_mode開/關,filetype ASC和DAT),但我從未發現過轉換。

備註:

  • 我使用的SAP版本7.01,支持包SAPKB70107。這是一個unicode系統。
  • T002只是一個例子,我的真實數據是其他數據,包含語言鍵。

我正在尋找與gui_download(或其他標準方法/功能模塊)的解決方案。

我不想建立自己的導出文件是這樣的:

data: 
    tmp type string, 
    targetline type string, 
    targettable type table of string. 
loop at it_table into sourceline. 
    "This could be done dynamic with field symbols and ASSIGN COMPONENT 
    write sourceline-field1 to tmp. 
    CONCATENATE targetline ';' tmp into targetline. 
    "... 
    APPEND targetline to targettable. 
endloop. 

這將是一個可能的解決方案,但在這種情況下,它會更容易讓我適應導出文件的消費者。

+0

PLS檢查此[鏈接](http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/840ad679- 0601-0010-cd8e-9989fd650822#q-18) – Dhivya

+0

有趣的提示,但我沒有發現任何問題。我發現了三個標題*以Microsoft Excel格式*保存內部表格,但它們處理其他主題(在調試,掃描程序和比較程序期間下載),而不是從ABAP下載。 – knut

回答

1

我不認爲這是可能的。但是,您可以在查詢中加入LAISO值(其值爲SPRAS輸出轉換函數返回值),其中包括SPRAS字段類型,並使用自定義類型作爲替換SPRAS類型字段與LAISO類型的查詢。
以下是使用T003P表的示例:

types: begin of ty_t003p, 
     client type mandt, 
     spras type laiso, 
     auart type aufart, 
     txt type auarttext, 
     end of ty_t003p. 

data ta_t003p type standard table of ty_t003p. 

select t003p~client t002~laiso t003p~auart t003p~txt into table ta_t003p from t003p inner join t002 on t002~spras = t003p~spras. 

cl_gui_frontend_services=>gui_download(
    exporting 
    filename = 'C:\temp\test.txt' 
    filetype = 'DAT' 
    changing 
    data_tab = ta_t003p). 
+1

該視圖是一個好主意。我使用了一個通用選擇,但是我可以在'SE11'中定義一個視圖,並用它來代替我的原始表。感謝這個想法。 – knut

0

好吧,

在這裏不用,使用SE11,轉到表,雙擊數據元素與轉換例程來顯示數據元素。然後雙擊該域以顯示該域,然後雙擊該對話。例程名稱。 (在這種情況下爲ISOLA)由於您希望輸出值(輸入值在數據庫中),您希望對每個表條目的spras字段執行CONVERSION_EXIT_ISOLA_INPUT。

喜歡的東西

data: wa_table type t002. 

loop at it_table into wa_table. 
CALL FUNCTION 'CONVERSION_EXIT_ISOLA_OUTPUT' 
    EXPORTING 
    input   = wa_table-spras 
IMPORTING 
    OUTPUT  = wa_table-spras. 

modify it_table from wa_table index sy-tabix. 

endloop. 

此時你可以繼續使用上it_table cl_gui_frontend_services => gui_download。

我意識到這是接近使用你的WRITE語句,除了WRITE語句會讓你陷入困境。

我們在我的工作中所做的是編寫一個使用數據字典生成上傳下載程序的程序。

表DD04L包含每個表字段的轉換出口,然後我們做一些喜歡這樣的:

CONCATENATE 'wa_db-' wa_field-fieldname INTO g_string. 

    SELECT SINGLE * FROM dd03l INTO wa_dd03l WHERE tabname EQ p_tab AND fieldname EQ wa_field-fieldname. 
    SELECT SINGLE * FROM dd04l INTO wa_dd04l WHERE rollname EQ wa_dd03l-rollname. 

    IF wa_dd04l-lowercase IS INITIAL. 
    _repl 'translate wa_field to upper case.' g_string. 
    ENDIF. 
    _add 'if g_oops is initial.'. 
    IF wa_dd04l-convexit IS NOT INITIAL. 

    _add 'try.'. 
    _repl 'move wa_field to &.' g_string. 
    _add 'CATCH CX_DYNAMIC_CHECK into gcl_dynamic_check.'. 
    _add 'l_error = gcl_dynamic_check->get_text().'. 
    _add 'l_long_error = gcl_dynamic_check->GET_LONGTEXT().'. 
    _repl 'concatenate ''Conversion error'' wa_field ''into & ->'' l_error into l_error separated by space.' g_string. 
    _add 'condense l_error.' . 
    _add 'write l_error. new-line.' . 
    _add 'write l_long_error. new-line.' . 
    _add 'ENDTRY.'. 


    CONCATENATE 'CONVERSION_EXIT_' wa_dd04l-convexit '_INPUT' INTO g_fm. 

    _repl ' CALL FUNCTION ''&''' g_fm. 
    _add '  EXPORTING'. 
    _repl '  input    = &' g_string. 
    _add '  IMPORTING'. 
    _repl '  output   = &' g_string. 
    _add '  EXCEPTIONS'. 
    _add '  length_error  = 1'. 
    _add '  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. 

一些定義哪些代碼添加到生成的ABAP

DEFINE _repl. 
    wa_prog = &1. 
    replace all occurrences of '&' in wa_prog with &2. 
    append wa_prog to it_prog. 
END-OF-DEFINITION. 

DEFINE _add. 
    append &1 to it_prog. 
END-OF-DEFINITION. 

這是一噸有趣的寫..

+0

但表格字段的內部長度爲1.轉換後的結果(2個字符)將移動到1個字符長的字段中並縮短。如果我用另一個2字符字段(我想避免的)使用另一個表,我可以使用更簡單的'將wa_table-spras寫入wa_table2-spras' - 不需要通過'call function'調用cenversion退出。 – knut

+0

是的,即使在發生器中也是一個缺陷..雖然你的對手真的需要2個字符嗎? – tomdemuyt

+0

我有選擇哪一方必須進行轉換。我可以提供一個帶有1和2個字符代碼(= T002)的列表,對方可以轉換該標誌。但在此之前,我想檢查SAP是否存在一個簡單的可能性。在過去,我使用SE16導出 - 沒有轉換問題。爲了避免其他問題,我用一個小報告取代了SE16 - 現在我有這個轉換問題。 – knut

相關問題