连接动态结构的字段



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

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.
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(。

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

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.

希望对您有所帮助。

您可以使用

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.

相关内容

  • 没有找到相关文章

最新更新