3

我们如何连接动态工作区的字段?这个想法在下面的代码中:

LOOP AT lt_final INTO DATA(ls_final).
  CONCATENATE ls_final-field1
              ls_final-field2
              ls_final-field3
              ls_final-field4
              ls_final-field5
         INTO ls_attachment SEPARATED BY lc_tab.   "lc_tab is horizontal tab

  APPEND ls_attachment TO lt_attachment.
  CLEAR: ls_attachment.
ENDLOOP.

(此代码将用于发送电子邮件附件。)现在,我的问题是,上面代码中的内部表是一个动态内部表,因此我不确定有多少字段以及字段名称。

如何连接字段?任何想法,请帮助..

LOOP AT <dynamic_table> INTO DATA(ls_final).
  CONCATENATE ls_final-(?)
              ls_final-(?)
              ls_final-(?)
              ls_final-(?)
              ls_final-(?) 
              "or more fields insert here depending on dynamic table
         INTO ls_attachment SEPARATED BY lc_tab.   "lc_tab is horizontal tab

  APPEND ls_attachment TO lt_attachment.
  CLEAR: ls_attachment.
ENDLOOP.
4

3 回答 3

5
FIELD-SYMBOLS: <lv_field> TYPE ANY.

LOOP AT lt_final
     ASSIGNING FIELD-SYMBOL(<ls_final>).
  DO.
    ASSIGN COMPONENT sy-index
           OF STRUCTURE <ls_final>
           TO <lv_field>.
    IF sy-subrc EQ 0.
      IF sy-index EQ 1.
        ls_attachment = <lv_field>.
      ELSE.
        ls_attachment = ls_attachment && lc_tab && <lv_field>.
      ENDIF.
    ELSE.
      EXIT.
    ENDIF.
  ENDDO.
ENDLOOP.

我希望它是自我解释的,但是:您可以使用系统变量(sy-index),它由 SAP 自动递增。在第一步中,只需复制值,还没有要连接的内容(否则字符串开头会出现不必要的 lc_tab)。

于 2017-12-29T08:06:55.727 回答
3

只需按索引阅读您的结构。

data :
     lv_attachment type string.
     lv_index type i value 1.
field-symbols:
             <lv_value> type any.

while 1 = 1.
    assign component lv_index of structure ls_final to <lv_value>.
    if sy-subrc <> 0.
      exit.
    endif.
    concatenate lv_attachment <lv_value> into lv_attachment separated by lc_tab.
    lv_index = lv_index + 1.
endwhile.

希望能帮助到你。

于 2017-12-29T02:15:28.247 回答
2

您可以CL_ABAP_CONTAINER_UTILITIES为该任务使用类,方法FILL_CONTAINER_C

这是填充动态表并将其字段连接到container字段的示例:

PARAMETERS: p_tab TYPE string.

FIELD-SYMBOLS: <fs_tab> TYPE STANDARD TABLE.

DATA tab TYPE REF TO data.
CREATE DATA tab TYPE TABLE OF (p_tab).
ASSIGN tab->* TO <fs_tab>.

SELECT * UP TO 100 ROWS
  INTO TABLE <fs_tab>
  FROM (p_tab).

LOOP AT <fs_tab> ASSIGNING FIELD-SYMBOL(<fs_line>).

CALL METHOD CL_ABAP_CONTAINER_UTILITIES=>FILL_CONTAINER_C
  EXPORTING
    IM_VALUE                = <fs_line>
  IMPORTING
    EX_CONTAINER            = DATA(container)
  EXCEPTIONS
    ILLEGAL_PARAMETER_TYPE = 1
    others                 = 2.

CONDENSE container.

" do smth

ENDLOOP.
于 2018-03-25T14:54:20.827 回答