• 动态内表操作 转自老白博客



    REPORT ztest.

    TYPE-POOLS : abap.
    FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                   <dyn_wa>,
                   <dyn_field>.
    DATA: dy_table TYPE REF TO data,
          dy_line TYPE REF TO data,
          xfc TYPE lvc_s_fcat,
          ifc TYPE lvc_t_fcat.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
    PARAMETERS: p_table(30) TYPE DEFAULT 'T001'.
    SELECTION-SCREEN END OF BLOCK b1.

    START-OF-SELECTION.
      PERFORM get_structure.
      PERFORM create_dynamic_itab.
      PERFORM get_data.
      PERFORM write_out.
    *---------------------------------------------------------------------*
    *       FORM get_structure                                            *
    *---------------------------------------------------------------------*
    FORM get_structure.
      DATA : idetails TYPE abap_compdescr_tab,
             xdetails TYPE abap_compdescr.
      DATA : ref_table_des TYPE REF TO cl_abap_structdescr.

      ref_table_des ?= cl_abap_typedescr=>describe_by_name( p_table ).
      idetails[] = ref_table_des->components[].
      LOOP AT idetails INTO xdetails.
        CLEAR xfc.
        xfc-fieldname = xdetails-name .
    *    xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length + xdetails-decimals.
        xfc-decimals = xdetails-decimals.
        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 <dyn_table>.

      CREATE DATA dy_line LIKE LINE OF <dyn_table>.
      ASSIGN dy_line->* TO <dyn_wa>.
    ENDFORM.                    "create_dynamic_itab

    *---------------------------------------------------------------------*
    *       FORM get_data                                                 *
    *---------------------------------------------------------------------*
    FORM get_data.
      DATA: BEGIN OF itab OCCURS .
              INCLUDE STRUCTURE spfli.
      DATA: END OF itab.

      SELECT INTO CORRESPONDING FIELDS OF TABLE <dyn_table>
                   FROM (p_table) UP TO 10 ROWS.
    ENDFORM.                    "get_data
    *---------------------------------------------------------------------*
    *       FORM write_out                                                *
    *---------------------------------------------------------------------*
    FORM write_out.
      LOOP AT <dyn_table> INTO <dyn_wa>.
        DO.
          ASSIGN COMPONENT sy-index
             OF STRUCTURE <dyn_wa> TO <dyn_field>.
          IF sy-subrc <> 0.
            EXIT.
          ENDIF.
          IF sy-index = 1.
            WRITE:/ <dyn_field>.
          ELSE.
            WRITE: <dyn_field>.
          ENDIF.
        ENDDO.
      ENDLOOP.
    ENDFORM.                    "write_out

  • 相关阅读:
    js获取input file文件二进制码
    nginx新手入门
    代码神器Atom,最常用的几大插件,你值得拥有。
    css3 3d 与案例分析
    express搭建简易web的服务器
    hosts文件管理和nginx总结
    css3 3D
    问题大神
    面试题整理
    版本控制简介,git使用----使用GitHub托管代码
  • 原文地址:https://www.cnblogs.com/eric0701/p/2754831.html
Copyright © 2020-2023  润新知