【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.
相关推荐
cyqweqe1231 天前
SAP采购发票税额总额非自动计算。TAX不写行号
abap
SAP学习成长之路2 天前
【翻译】伯明翰市议会因 Oracle 系统崩溃而面临 £216.5M 的损失
数据库·oracle·sap
乐乐82344 天前
ABAP:SET CURSOR FIELD设置鼠标焦点
abap
向上的车轮4 天前
ODOO学习笔记(4):Odoo与SAP的主要区别是什么?
笔记·学习·sap·odoo
哲讯智能科技6 天前
SAP Business One市场价格解析
运维·sap·erp
小九不懂SAP10 天前
SAP(PP生产制造)拆解工单业务处理
sap·制造·s4·pp
冰魄禾11 天前
SAP ABAP开发学习——BAPI
运维·开发语言·笔记·运维开发·sap·abap
syounger14 天前
是我们“辜负”了IBM、SAP么?
sap
Liquid UI15 天前
Amcor 如何借助 Liquid UI 实现SAP PM可靠性
ui·自动化·sap·制造