【SAP-ABAP】MIRO--界面增强增加数据导出导入按钮

需求:在MIRO界面当中增加两个按钮,按钮功能为:可以将对应的行项目信息导出和导入,因为实际业务中,可能存在大批量采购订单开票的情况,无法做到数据对账,所以用此功能来解决问题。

效果截图:

此方法用到修改了标准屏幕,一般没啥影响,胆子小或者经常升级的可以酌情考虑是否做这样的需求(要给SAP去魅,再厉害的软件终究是软件,没什么不能做的)

第一步:找到程序及屏幕

Se93->miro:确认程序为SAPLMR1M

第二步:SE80输入程序,确认一下具体的屏幕6310

别问我怎么找到这个屏幕的,你指定到行项目,试试F1瞅瞅

第三步:给标准屏幕增加两个按钮(放心改,领导同意了,怕啥)

点击格式,修改,增加按钮,给按钮命名

第四步:找一下屏幕的增强位置,双击6310屏幕中的MODULE fcode_6310.

第五步:在fcode_6310(LMR1MI30)里面找一下增强点

第六步:找到对应的位置创建增强,大概在这个位置吧

第七步:码上增强代码(天下代码一大抄,抄抄抄)

ENHANCEMENT 1  ZTEST_004.    "active version



  TYPES:

* 内容

   BEGIN OF TYP_DRSEG,

    RBLGP TYPE DRSEG-RBLGP,"项目

    WRBTR TYPE DRSEG-WRBTR,"金额

    MENGE TYPE DRSEG-MENGE,"数量

    MEINS TYPE DRSEG-MEINS,"单位

    EBELN TYPE DRSEG-EBELN,"采购订单

    EBELP TYPE DRSEG-EBELP,"采购订单项目

    TXZ01 TYPE DRSEG-TXZ01,"描述

    LFBNR TYPE DRSEG-LFBNR,"参考凭证

    MATNR TYPE DRSEG-MATNR,"物料号

     MWSKZ TYPE DRSEG-MWSKZ,"税码

     BPMNG TYPE DRSEG-BPMNG,"订单单价数量

     BPRME TYPE DRSEG-BPRME,"采购订单价格单位

     BUDAT TYPE MKPF-BUDAT,"过账日期

   END OF TYP_DRSEG,

* 表头行

  BEGIN OF TYP_HEAD,

    NAME(20),

  END OF TYP_HEAD.



* 临时数据

  DATA:

    ls_drsegt TYPE typ_drseg,

    LT_drsegt TYPE TABLE OF typ_drseg,

    LS_HEAD TYPE TYP_HEAD,

    LT_HEAD TYPE TABLE OF TYP_HEAD,

    LS_MKPF TYPE MKPF.



  DATA: WA_OBJDATA     LIKE WWWDATATAB,

        LV_FILENAME    TYPE STRING VALUE 'ZMIR7' ,

        LV_FULLPATH    TYPE STRING,

        LV_PATH        TYPE STRING.

  IF ok-code = 'ZEXPORT'.

    CLEAR ok-code.

    CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_SAVE_DIALOG

      EXPORTING

        DEFAULT_EXTENSION    = 'XLS'

        DEFAULT_FILE_NAME    = LV_FILENAME

      CHANGING

        FILENAME             = LV_FILENAME

        PATH                 = LV_PATH

        FULLPATH             = LV_FULLPATH

      EXCEPTIONS

        CNTL_ERROR           = 1

        ERROR_NO_GUI         = 2

        NOT_SUPPORTED_BY_GUI = 3

        OTHERS               = 4.

    IF LV_FULLPATH = ''.

      MESSAGE E001(ZMM4001) WITH TEXT-M13.

      "文件路径错误

    ENDIF.

*

    IF SY-SUBRC = 0.

      CLEAR LT_HEAD.



      LS_HEAD-NAME = '项目(不允许修改)'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '金额'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '数量'.

      APPEND LS_HEAD TO LT_HEAD.

      LS_HEAD-NAME = '订单单位'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '采购订单'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '采购订单项目'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '采购订单文本'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '参考凭证'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '物料号'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '税码'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '订单单价数量'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '采购订单价格单位'.

      APPEND LS_HEAD TO LT_HEAD.



      LS_HEAD-NAME = '过账日期'.

      APPEND LS_HEAD TO LT_HEAD.



      REFRESH lt_drsegt.

      LOOP AT ydrseg.

         MOVE-CORRESPONDING ydrseg to ls_drsegt.

         SELECT SINGLE * FROM MKPF INTO LS_MKPF WHERE MBLNR = ydrseg-LFBNR.

         ls_drsegt-BUDAT = LS_MKPF-BUDAT.

         APPEND ls_drsegt TO lt_drsegt.

         CLEAR ls_drsegt.

      ENDLOOP.



      CALL FUNCTION 'GUI_DOWNLOAD'

        EXPORTING

*         BIN_FILESIZE                    =

          FILENAME                        = LV_FULLPATH

*         FILETYPE                        = 'ASC'

*         APPEND                          = ' '

          WRITE_FIELD_SEPARATOR           = 'X'

*         HEADER                          = '00'

*         TRUNC_TRAILING_BLANKS           = ' '

*         WRITE_LF                        = 'X'

*         COL_SELECT                      = ' '

*         COL_SELECT_MASK                 = ' '

*         DAT_MODE                        = ' '

*         CONFIRM_OVERWRITE               = ' '

*         NO_AUTH_CHECK                   = ' '

*         CODEPAGE                        = ' '

*         IGNORE_CERR                     = ABAP_TRUE

*         REPLACEMENT                     = '#'

*         WRITE_BOM                       = ' '

*         TRUNC_TRAILING_BLANKS_EOL       = 'X'

*         WK1_N_FORMAT                    = ' '

*         WK1_N_SIZE                      = ' '

*         WK1_T_FORMAT                    = ' '

*         WK1_T_SIZE                      = ' '

*         WRITE_LF_AFTER_LAST_LINE        = ABAP_TRUE

*         SHOW_TRANSFER_STATUS            = ABAP_TRUE

*         VIRUS_SCAN_PROFILE              = '/SCET/GUI_DOWNLOAD'

*       IMPORTING

*         FILELENGTH                      =

        TABLES

          DATA_TAB                        = lt_drsegt

          FIELDNAMES                      = LT_HEAD

       EXCEPTIONS

         FILE_WRITE_ERROR                = 1

         NO_BATCH                        = 2

         GUI_REFUSE_FILETRANSFER         = 3

         INVALID_TYPE                    = 4

         NO_AUTHORITY                    = 5

         UNKNOWN_ERROR                   = 6

         HEADER_NOT_ALLOWED              = 7

         SEPARATOR_NOT_ALLOWED           = 8

         FILESIZE_NOT_ALLOWED            = 9

         HEADER_TOO_LONG                 = 10

         DP_ERROR_CREATE                 = 11

         DP_ERROR_SEND                   = 12

         DP_ERROR_WRITE                  = 13

         UNKNOWN_DP_ERROR                = 14

         ACCESS_DENIED                   = 15

         DP_OUT_OF_MEMORY                = 16

         DISK_FULL                       = 17

         DP_TIMEOUT                      = 18

         FILE_NOT_FOUND                  = 19

         DATAPROVIDER_EXCEPTION          = 20

         CONTROL_FLUSH_ERROR             = 21

         OTHERS                          = 22 .

      IF SY-SUBRC <> 0.

*   Implement suitable error handling here

      ENDIF.

    ENDIF.

  ENDIF.



IF ok-code = 'ZIMPORT'.

  CLEAR ok-code.

  DATA: L_FILETAB   TYPE FILETABLE,

        L_RC        TYPE I.

  DATA PC_FILE(80).

  CLEAR L_FILETAB.

  REFRESH L_FILETAB.

  CALL METHOD CL_GUI_FRONTEND_SERVICES=>FILE_OPEN_DIALOG

    EXPORTING

      DEFAULT_FILENAME     = '*.xls'

      INITIAL_DIRECTORY    = 'D:\'

      MULTISELECTION       = ''

    CHANGING

      FILE_TABLE           = L_FILETAB

      RC                   = L_RC

    EXCEPTIONS

      CNTL_ERROR           = 1

      ERROR_NO_GUI         = 2

      NOT_SUPPORTED_BY_GUI = 3

      OTHERS               = 4.

  CHECK L_RC EQ 1.

  READ TABLE L_FILETAB INDEX 1 INTO PC_FILE.



  TYPES:truxs_t_text_data2(4096) type c occurs 0.

* 临时变量

  DATA:lv_index TYPE sy-tabix,

       LIT_RAW TYPE TRUXS_T_TEXT_DATA2,

       LV_FILE TYPE RLGRAP-FILENAME.



  LV_FILE = PC_FILE.

  REFRESH lt_drsegt.

* 读取文件数据

  CALL FUNCTION 'TEXT_CONVERT_XLS_TO_SAP'

    EXPORTING

*     I_FIELD_SEPERATOR          =

      I_LINE_HEADER              = 'X'

      I_TAB_RAW_DATA             = LIT_RAW

      I_FILENAME                 = LV_FILE

    TABLES

      I_TAB_CONVERTED_DATA       = lt_drsegt

   EXCEPTIONS

     CONVERSION_FAILED          = 1

     OTHERS                     = 2

            .

  IF SY-SUBRC <> 0.

     MESSAGE ID SY-MSGID TYPE 'S' NUMBER SY-MSGNO DISPLAY LIKE 'E'

             WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

     LEAVE LIST-PROCESSING.

  ENDIF.



  CHECK lt_drsegt[] IS NOT INITIAL.



  LOOP AT  ydrseg.

    lv_index = sy-tabix.

    READ TABLE lt_drsegt INTO lS_drsegt WITH KEY RBLGP = ydrseg-RBLGP.

    IF SY-SUBRC <> 0.

      DELETE ydrseg index lv_index.

    ELSE.

      ydrseg-WRBTR = lS_drsegt-WRBTR."金额

      ydrseg-MENGE = lS_drsegt-MENGE."数量

      MODIFY ydrseg INDEX lv_index

      TRANSPORTING WRBTR

                   MENGE.



    ENDIF.

  ENDLOOP.

ENDIF.

ENDENHANCEMENT.
相关推荐
山茶花开时。6 天前
[SAP ABAP] 序列化与反序列化
开发语言·sap·abap
左甜甜8 天前
SAP MMPV报错MMPV_DATE_CHECK
sap
SAP女战士10 天前
【ABAP SAP】开发-BUG修补记录_采购申请打印时品名规格品牌为空
运维·数据库·bug·sap·abap开发
Cindy的SAP加油站12 天前
SAP Ariba_Order Fulfillment Status
sap·sap ariba
SAP学习成长之路13 天前
ADBC 查询语法介绍:EXECUTE_QUERY
java·服务器·开发语言·数据库·sap·abap·零售
需己以听的以听15 天前
4.模块化技术之子程序
sap·gui·abap·模块化·改行学it·子程序
syounger15 天前
近四分之一SAP ECC用户对未来规划尚不明朗
sap
HeathlX17 天前
ABAP - 系统集成之SAP的数据同步到OA(泛微E9)服务器数据库
数据库·abap
SAP学习成长之路20 天前
SAP HANA 上进行 ABAP 开发:简介
开发语言·数据结构·数据库·sap·abap·代码规范
Fireworks_me22 天前
SAP Native SQL 的简单说明
sql·abap