简体   繁体   English

如何通过转换退出下载数据?

[英]How to download data with conversion exit?

I try to download an internal table to my PC and the download should use the conversion exits.我尝试将内部表下载到我的 PC 并且下载应该使用转换出口。

An example: Table T002 contains a language key with one character (T0002-SPRAS).示例:表T002包含一个具有一个字符的语言键 (T0002-SPRAS)。

When I WRITE T0002-SPRAS.当我WRITE T0002-SPRAS. the conversion routine ISOLA is used and I get a two character language key ( E becomes EN ...) This conversion routine should be used for my export.使用了转换例程ISOLA并且我得到了一个两个字符的语言键( E变成了EN ...) 这个转换例程应该用于我的导出。

My test report:我的测试报告:

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'.

The result is a file without the usage of the conversion exit (English keeps E ).结果是一个没有使用转换出口的文件(英语保留E )。

The SAP documentation mention the parameter dat_mode : SAP 文档提到了参数dat_mode

If this flag is set, .... Conversion exits are not executed.如果设置了此标志,.... 不执行转换出口。

I don't set the flag,so I would expect, the conversions are done.我没有设置标志,所以我希望转换已经完成。 I tried different combinations ( dat_mode on/off, filetype ASC and DAT), but I found never a conversion.我尝试了不同的组合( dat_mode开/关、 filetype ASC 和 DAT),但我从未发现转换。

Remarks:评论:

  • I use SAP Release 7.01, Support Package SAPKB70107.我使用 SAP 版本 7.01,支持包 SAPKB70107。 It is a unicode system.它是一个 Unicode 系统。
  • T002 is only an example, my real data are other data, containing language key. T002只是一个例子,我的真实数据是其他数据,包含语言键。

I'm looking for a solution with gui_download (or another standard method/function module).我正在寻找带有gui_download (或其他标准方法/功能模块)的解决方案。

I don't want to build my own export file like this:我不想像这样构建自己的导出文件:

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.

This will be a possible solution, but in this case it would be easier for me to adapt the consumer of the export file.这将是一个可能的解决方案,但在这种情况下,我更容易适应导出文件的使用者。

I don't think it's possible.我不认为这是可能的。 You could however join the LAISO value (which is the value the SPRAS output conversion function returns) in your queries which include an SPRAS type of field, and use a custom type for the query in which you replace the SPRAS type field with the LAISO type.但是,您可以加入LAISO值(这是价值SPRAS输出转换函数返回)在查询其中包括SPRAS场的类型,以及用于查询在您更换自定义类型SPRAS与类型字段LAISO类型.
Here's an example using the T003P table:以下是使用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 ).

Okay,好的,

here goes, use SE11, go to the table, double click the data element with the conversion routine to display the data element.在这里,使用SE11,转到表格,使用转换例程双击数据元素以显示数据元素。 Then double click the domain to display the domain then double click the convers.然后双击域以显示域,然后双击转换。 routine name.例行名称。 ( ISOLA in this case ) Since you want the output value ( the input value is in the db ) you want to execute CONVERSION_EXIT_ISOLA_INPUT on the spras field for each table entry. (在本例中为 ISOLA)由于您想要输出值(输入值在 db 中),您想要在每个表条目的 spras 字段上执行 CONVERSION_EXIT_ISOLA_INPUT。

Something like就像是

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.

At this point you can just continue using cl_gui_frontend_services=>gui_download on it_table.此时您可以继续在 it_table 上使用 cl_gui_frontend_services=>gui_download 。

I realize this is close to using your WRITE statement, except that the WRITE statement would get you in trouble.我意识到这接近于使用您的 WRITE 语句,只是 WRITE 语句会给您带来麻烦。

What we have done at my work is write a program that uses the data dictionary to generate an upload download program.我们在我的工作中所做的是编写一个程序,该程序使用数据字典生成上传下载程序。

Table DD04L contains the conversion exit for each table field, and then we do something likes this :表 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.

with some defines which add code to the generated ABAP一些定义将代码添加到生成的 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.

It's a ton of fun to write..写起来很有趣..

As of ABAP 7.52, I have verified that the conversion exits are executed only when:从 ABAP 7.52 开始,我已经验证转换出口仅在以下情况下执行:

  • The parameters are either filetype = 'DAT'参数是filetype = 'DAT'

    • or filetype = 'ASC' and dat_mode = 'X'filetype = 'ASC' and dat_mode = 'X'

      (not really what the documentation says) (不是真正的文档所说的)

  • And only for fields whose data types are 'N', 'D', 'F' (except value 0) or 'T' (but not 'C' which is the most frequent case, especially concerning the conversion exits ALPHA , ISOLA and CUNIT )并且仅适用于数据类型为“N”、“D”、“F”(值 0 除外)或“T” (但不是最常见的“C”的字段,尤其是关于转换退出ALPHAISOLACUNIT )

    (you may verify these rules on data types in the subroutine Put_Char_LineBuffer of the function group SFES , and more specifically in the subroutine ConvertAsc ) (您可以在功能组SFES的子程序Put_Char_LineBuffer中,更具体地说是在子程序ConvertAsc验证有关数据类型的这些规则)

Note that the documentation embedded in the method gui_download of cl_gui_frontend_services says:需要注意的是嵌在方法的文档gui_downloadcl_gui_frontend_services说:

DAT mode: No longer supported. DAT 模式:不再支持。 Use ASC instead.请改用 ASC。

So you cannot rely on the conversions done by the method.因此,您不能依赖该方法完成的转​​换。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM