代码之家  ›  专栏  ›  技术社区  ›  ekekakos

如何动态创建内部表的名称

  •  0
  • ekekakos  · 技术社区  · 5 年前


    我想做的是不止一次地运行BAPI‘BAPI_ACC_BILLING_POST’,我想不止一次地填充结构和表格,也就是说,我想让GIT_ACCOUNTGL、GIT_ACCOUNTGL01、GIT_ACCOUNTGL02等运行BAPI,运行次数与ITABs的次数相同;我有。
    有人能告诉我怎么做吗?

    0 回复  |  直到 4 年前
        1
  •  4
  •   Florian    5 年前

    使用一张桌子。每行代表您描述的一个ITAB。根据表的索引而不是某个名称对表进行寻址。

    TYPES table_type TYPE STANDARD TABLE OF bapiacgl09 WITH EMPTY KEY.
    TYPES collection_type TYPE STANDARD TABLE OF table_type WITH EMPTY KEY.
    
    DATA all_results TYPE collection_type.
    
    " collect the results
    DO 100 TIMES.
      DATA(single_result) = " call bapi
      INSERT single_result INTO TABLE all_results.
    ENDDO.
    
    " access a specific result by index
    DATA(forty_second_result) = all_results[ 42 ].
    
    " iterate all results
    LOOP AT all_results INTO single_result.
    ENDLOOP.
    
        2
  •  0
  •   Sandra Rossi    5 年前

    TYPES : BEGIN OF ty_bapiarglist,
              " arguments passed to the BAPI
              accountgl TYPE STANDARD TABLE OF bapiacgl01 WITH EMPTY KEY,
              " ...
              " arguments returned by the BAPI
              return    TYPE STANDARD TABLE OF bapiret2 WITH EMPTY KEY,
              " ...
            END OF ty_bapiarglist.
    
    DATA: bapiarglist  TYPE ty_bapiarglist,
          bapiarglists TYPE TABLE OF ty_bapiarglist.
    
    "++++++++++++++
    " Call BAPI
    " Fill lists of arguments
    "++++++++++++++
    
    LOOP AT someitab...
    
      " fill arguments to transmit
      " bapiarglist-accountgl = ...
    
      CALL FUNCTION 'BAPI_ACC_BILLING_POST'
         ...
         TABLES
           accountgl = bapiarglist-accountgl
           return    = bapiarglist-return
           ...
    
      APPEND bapiarglist TO bapiarglists.
    
    ENDLOOP.
    
    "++++++++++++++
    " Later usage
    "++++++++++++++
    
    LOOP AT bapiarglists INTO bapiarglist.
      ...
    ENDLOOP.