ABAP 调用标准报表程序,获取程序输出list

如何调用标准程序,直接获取对应标准程序的字段。

注意点:1当被调用程序有Varient值时,一定要传入值,不然字段的顺序会错乱,固定了Varient才能确保取出来的字段顺序和该Varient一致

2每个报表不同,有抬头会占用行数,所以需要自己debug看一下,从第几行开始有数据

3有些报表中间会有些汇总数据一类的不需要的,需要判断删除一下,列如根据物料为空

4 有些金额,日期字段不能直接取,需要进行转换,有些So类字段需要加前导零。

  DATA: lv_string TYPE string.
  DATA: lv_string2 TYPE string.
  DATA  l_dcpfm LIKE usr01-dcpfm.
  DATA  BEGIN OF itab_list OCCURS 0.
          INCLUDE STRUCTURE abaplist.
  DATA  END OF itab_list.
  DATA: BEGIN OF vlist OCCURS 0, "这个调用程序ALV输出的长度要根据实际长度来确认
     line TYPE c LENGTH 300,
  END OF vlist.
  DATA: lt_itab TYPE TABLE OF string.
  SELECT SINGLE dcpfm INTO l_dcpfm
  FROM usr01
  WHERE bname = sy-uname.
  CLEAR gt_out.
  SUBMIT rm07docs
     WITH matnr IN matnr[]
     WITH werks IN werks[]
     WITH lgort IN lgort[]
     WITH lifnr IN lifnr[]
     WITH kunnr IN kunnr[]
     WITH bwart   IN bwart[]
     WITH sobkz   IN sobkz[]
     WITH aufnr   IN aufnr[]
     WITH ebeln   IN ebeln[]
     WITH ebelp   IN ebelp[]
     WITH grund   IN grund[]
     WITH kostl   IN kostl[]
     WITH mat_kdau IN mat_kdau[]
     WITH mat_kdpo IN mat_kdpo[]
     WITH mat_pspn IN mat_pspn[]
     WITH sgtxt  IN sgtxt[]
     WITH umlgo  IN umlgo[]
     WITH umwrk   IN umwrk[]
     WITH budat   IN budat[]
     WITH usnam   IN usnam[]
     WITH vgart   IN vgart[]
     WITH cpudt   IN cpudt[]
     WITH mblnr   IN mblnr[]
     WITH tcode2  IN tcode2[]
     WITH xblnr   IN xblnr[]
     WITH rhier_l = ''
     WITH rflat_l = 'X'
     WITH alv_def = '/MKS'
     WITH database = database
     WITH shortdoc = shortdoc
     WITH archive  = archive
     WITH pa_aistr = pa_aistr
     WITH pa_dbstd = pa_dbstd
     WITH pa_dbmat = pa_dbmat
     WITH pa_dbdat = pa_dbdat
     WITH pa_maa   = pa_maa
     EXPORTING LIST TO MEMORY
     AND RETURN.
  CALL FUNCTION 'LIST_FROM_MEMORY'
    TABLES
      listobject = itab_list
    EXCEPTIONS
      not_found  = 4
      OTHERS     = 8.
  FREE MEMORY .
  CALL FUNCTION 'LIST_TO_ASCI'
    EXPORTING
      list_index         = -1
    TABLES
      listasci           = vlist
      listobject         = itab_list
    EXCEPTIONS
      empty_list         = 1
      list_index_invalid = 2
      OTHERS             = 3.
  IF sy-subrc = 0.

    LOOP AT vlist.
      AT LAST.
        CONTINUE.
      ENDAT.
      IF sy-tabix > 3 . “每个报表不同,需要Debug看从第几行开始有的数据内容
        CLEAR:gs_out.
        CLEAR: lt_itab,lv_string.
        SPLIT vlist-line AT '|' INTO TABLE lt_itab.
        IF lt_itab IS NOT INITIAL.
*            GS_OUT-kunnr = gs_kunnr-kunnr.
*            GS_OUT-bukrs = p_bukrs.
          LOOP AT lt_itab INTO lv_string.
            CASE sy-tabix.
              WHEN '2'.
                gs_out-lifnr = lv_string.
                CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                  EXPORTING
                    input  = gs_out-lifnr
                  IMPORTING
                    output = gs_out-lifnr.

              WHEN '3'.
                gs_out-matnr = lv_string.
              WHEN '4'.
                gs_out-maktx = lv_string.
              WHEN '5'.
                gs_out-werks = lv_string.
              WHEN '6'.
                gs_out-lgort = lv_string.
              WHEN '7'.
                gs_out-bwart = lv_string.
              WHEN '8'.
                gs_out-sobkz = lv_string.
              WHEN '9'.
                gs_out-ebeln = lv_string.
                CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                  EXPORTING
                    input  = gs_out-ebeln
                  IMPORTING
                    output = gs_out-ebeln.
              WHEN '10'.
                gs_out-ebelp = lv_string.
                CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                  EXPORTING
                    input  = gs_out-ebelp
                  IMPORTING
                    output = gs_out-ebelp.
              WHEN '11'.
                gs_out-mblnr = lv_string.
                CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                  EXPORTING
                    input  = gs_out-mblnr
                  IMPORTING
                    output = gs_out-mblnr.
              WHEN '12'.
                gs_out-zeile = lv_string.
                CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
                  EXPORTING
                    input  = gs_out-zeile
                  IMPORTING
                    output = gs_out-zeile.
*              WHEN '13'.
*                gs_out-bldat = lv_string.
              WHEN '13'.
                gs_out-budat_c = lv_string.
                CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL' “日期字段转换”
                  EXPORTING
                    date_external            = gs_out-budat_c
*                   ACCEPT_INITIAL_DATE      =
                  IMPORTING
                    date_internal            = gs_out-budat
                  EXCEPTIONS
                    date_external_is_invalid = 1
                    OTHERS                   = 2.
                IF sy-subrc = 0.

                ENDIF.
              WHEN '14'.
                IF lv_string CS '-'.
                  SPLIT  lv_string AT '-' INTO gs_out-erfmg_c lv_string2.
                ELSE.
                  gs_out-erfmg_c = lv_string.
                ENDIF.
                CALL FUNCTION 'UNITS_STRING_CONVERT'
                  EXPORTING
                    units_string = gs_out-erfmg_c
                    dcpfm        = l_dcpfm    "此时为X
*                   MLLN         = 'M'
*                   TSND         = 'T'
                  IMPORTING
                    units        = gs_out-erfmg
                  EXCEPTIONS
                    invalid_type = 1
                    OTHERS       = 2.
                IF lv_string CS '-'.
                  gs_out-erfmg = 0 - gs_out-erfmg.
                ENDIF.
              WHEN '15'.
                gs_out-erfme = lv_string.
              WHEN '16'.
                IF lv_string CS '-'.
                  SPLIT  lv_string AT '-' INTO gs_out-dmbtr_c lv_string2.
                ELSE.
                  gs_out-dmbtr_c = lv_string.
                ENDIF.
                CALL FUNCTION 'UNITS_STRING_CONVERT' “金额字段转换
                  EXPORTING
                    units_string = gs_out-dmbtr_c
                    dcpfm        = l_dcpfm    "此时为X
*                   MLLN         = 'M'
*                   TSND         = 'T'
                  IMPORTING
                    units        = gs_out-dmbtr
                  EXCEPTIONS
                    invalid_type = 1
                    OTHERS       = 2.
                IF lv_string CS '-'.
                  gs_out-dmbtr = 0 - gs_out-dmbtr.
                ENDIF.
            ENDCASE.
            CLEAR lv_string.
          ENDLOOP.
          IF gs_out IS NOT INITIAL.
            SELECT SINGLE bldat INTO gs_out-bldat
              FROM mkpf
              WHERE mblnr = gs_out-mblnr.
            APPEND gs_out  TO gt_out.
            CLEAR gs_out.
          ENDIF.
        ENDIF.
      ENDIF.

    ENDLOOP.
    DELETE gt_out WHERE matnr = ''.

上一篇:ABAP 调用程序时获取的数量,金额和日期字段会出现 逗号,-,负号等非法字段,所需要进行转化


下一篇:FaceShifter: Towards High Fidelity And Occlusion Aware Face Swapping