欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

[SAP] abap——调用报表的运行结果

程序员文章站 2022-06-22 20:26:25
在一些情况下我们需要调用报表运行,获取运行的结果,用Submit来实现。例:接口根据iv_bukrs、iv_lifnr、iv_spmon三个字段值获取程序报表ZFI1001运行后edmbtr的值。DATA: ra_bukrs TYPE RANGE OF bukrs, ls_bukrs LIKE LINE OF ra_bukrs, ra_lifnr TYPE RANGE OF lifnr, ls_lifnr LIKE LINE OF ra_lifnr....

在一些情况下我们需要调用报表运行,获取运行的结果,用Submit来实现。

例:接口根据iv_bukrs、iv_lifnr、iv_spmon三个字段值获取程序报表ZFI1001运行后edmbtr的值。

DATA:  ra_bukrs TYPE RANGE OF bukrs,
       ls_bukrs LIKE LINE OF ra_bukrs,
       ra_lifnr TYPE RANGE OF lifnr,
       ls_lifnr LIKE LINE OF ra_lifnr.

  DATA:it_memory LIKE TABLE OF abaplist.

  DATA: BEGIN OF it_list OCCURS 0,
          line(1000),
        END OF it_list.
  DATA: BEGIN OF it_string OCCURS 0,
         str TYPE c LENGTH 100,
        END OF it_string.
  DATA: BEGIN OF is_indx,
    bukrs(2),
    lifnr(2),
    edmbtr(2),
    END OF is_indx.
  data ls_indx like is_indx.
  DATA L_ENDLINE TYPE I.

  IF iv_bukrs IS NOT INITIAL.
    ls_bukrs-low = iv_bukrs.
    ls_bukrs-sign = 'I'.
    ls_bukrs-option = 'EQ'.
    APPEND ls_bukrs TO ra_bukrs.
  ENDIF.

  IF iv_lifnr IS NOT INITIAL.
    ls_lifnr-low = iv_lifnr.
    ls_lifnr-sign = 'I'.
    ls_lifnr-option = 'EQ'.
    APPEND ls_lifnr TO ra_lifnr.
  ENDIF.

  "调用ZFI1001报表程序
  SUBMIT zfi1001  WITH s_bukrs IN ra_bukrs
                  WITH s_lifnr IN ra_lifnr
                  WITH p_spmon = iv_spmon
                  EXPORTING LIST TO MEMORY AND RETURN.
  "获取缓存
  CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
      listobject = it_memory
    EXCEPTIONS
      not_found  = 1
      OTHERS     = 2.

  IF it_memory[] IS INITIAL.
    RETURN.
  ENDIF.
  
  "将缓存转换格式
  CALL FUNCTION 'LIST_TO_ASCI'
    TABLES
      listasci           = it_list[]
      listobject         = it_memory
    EXCEPTIONS
      empty_list         = 1
      list_index_invalid = 2
      OTHERS             = 3.
  
  IF it_list[] IS NOT INITIAL.
    READ TABLE it_list INDEX 4."读ALV表头字段名称的那一行
    IF sy-subrc = 0.
      SPLIT it_list AT '|' INTO TABLE it_string.
      "读取要获取字段所处的列
      LOOP AT it_string.
        CONDENSE it_string-str NO-GAPS.
        IF it_string-str = '公司'.
          ls_indx-bukrs = sy-tabix.
        ENDIF.
        IF it_string-str = '供应商'.
          ls_indx-lifnr = sy-tabix.
        ENDIF.
        IF it_string-str = '余额'.
          ls_indx-edmbtr = sy-tabix.
        ENDIF.
      ENDLOOP.

      DESCRIBE TABLE IT_LIST LINES L_ENDLINE.
      L_ENDLINE = L_ENDLINE - 1.

      LOOP AT IT_LIST FROM 6 TO L_ENDLINE."读取表的值
        REFRESH IT_STRING.
        SPLIT IT_LIST AT '|' INTO TABLE IT_STRING.

        READ TABLE IT_STRING INDEX ls_indx-bukrs.
        CONDENSE IT_STRING-STR NO-GAPS.
        et_balance-bukrs = IT_STRING-STR.

        READ TABLE IT_STRING INDEX ls_indx-lifnr.
        CONDENSE IT_STRING-STR NO-GAPS.
        et_balance-lifnr = IT_STRING-STR.

        READ TABLE IT_STRING INDEX ls_indx-edmbtr.
        CONDENSE IT_STRING-STR NO-GAPS.
*        REPLACE '*' WITH '' INTO IT_STRING-STR.
        REPLACE ALL OCCURRENCES OF ',' IN IT_STRING-STR WITH ''.     "金额字段格式转换
        et_balance-edmbtr = IT_STRING-STR.

        et_balance-SPMON = iv_SPMON.
        APPEND et_balance.
        CLEAR:et_balance.
      ENDLOOP.
    ENDIF.
  ENDIF.

ENDFUNCTION.

 

本文地址:https://blog.csdn.net/Mona_1220/article/details/107665022