• ABAP XD01创建供应商BDC


    TABLE

     日志表:

    FUNCTION ZMM_SUPPLIER_CREATE.
    *"----------------------------------------------------------------------
    *"*"Local interface:
    *"  IMPORTING
    *"     VALUE(SYNAME) TYPE  ZSYNM OPTIONAL
    *"     VALUE(UNAME) TYPE  UNAME OPTIONAL
    *"     VALUE(FLOWID) TYPE  AWKEY OPTIONAL
    *"  TABLES
    *"      GT_INPUT STRUCTURE  ZST_SUPPLIER_CREATE OPTIONAL
    *"      GT_MESSAGE STRUCTURE  ZST_SUPPLIER_MESSAGE OPTIONAL
    *"----------------------------------------------------------------------
    
    DATA: GW_INPUT LIKE LINE OF GT_INPUT.
    DATA: MESSTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
    DATA: ZLOG LIKE ZLOG_ZMMD004_001 OCCURS 0 WITH HEADER LINE.
    DATA: L_MESSAGE TYPE BAPI_MSG.
    DATA: BEGIN OF GT_LFA1 OCCURS 0,
      LIFNR LIKE LFA1-LIFNR,
      END OF GT_LFA1.
    DATA: BEGIN OF GT_LFB1 OCCURS 0,
      LIFNR LIKE LFB1-LIFNR,
      BUKRS LIKE LFB1-BUKRS,
      END OF GT_LFB1.
    DATA: BEGIN OF GT_LFM1 OCCURS 0,
      LIFNR LIKE LFM1-LIFNR,
      EKORG LIKE LFM1-EKORG,
      END OF GT_LFM1.
    DATA: BEGIN OF GT_BNKA OCCURS 0,
      BANKS LIKE BNKA-BANKS,
      BANKL LIKE BNKA-BANKL,
      END OF GT_BNKA.
    
    LOOP AT GT_INPUT INTO GW_INPUT.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
          EXPORTING
            input  = GW_INPUT-LIFNR
          IMPORTING
            output = GW_INPUT-LIFNR.
      MODIFY GT_INPUT FROM GW_INPUT.
      CLEAR GW_INPUT.
    
    ENDLOOP.
    
    LOOP AT GT_INPUT INTO GW_INPUT.
      SELECT
        LIFNR
        FROM LFA1 INTO CORRESPONDING FIELDS OF TABLE GT_LFA1
        WHERE LIFNR = GW_INPUT-LIFNR.
    
      SELECT
        LIFNR
        BUKRS
        FROM LFB1 INTO CORRESPONDING FIELDS OF TABLE GT_LFB1
        WHERE LIFNR = GW_INPUT-LIFNR
        AND BUKRS = GW_INPUT-BUKRS.
    
      SELECT
        LIFNR
        EKORG
        FROM LFM1 INTO CORRESPONDING FIELDS OF TABLE GT_LFM1
        WHERE LIFNR = GW_INPUT-LIFNR
        AND EKORG = GW_INPUT-EKORG.
    
      SELECT
        BANKS
        BANKL
        FROM BNKA INTO CORRESPONDING FIELDS OF TABLE GT_BNKA
        WHERE BANKS = GW_INPUT-BANKS
        AND BANKL = GW_INPUT-BANKL.
    
    
      perform bdc_dynpro      using 'SAPMF02K' '0100'.
      perform bdc_field       using 'BDC_CURSOR'
                                    'RF02K-KTOKK'.
      perform bdc_field       using 'BDC_OKCODE'
                                    '/00'.
      perform bdc_field       using 'RF02K-LIFNR'
                                    GW_INPUT-LIFNR.
      perform bdc_field       using 'RF02K-BUKRS'
                                    GW_INPUT-BUKRS.
      perform bdc_field       using 'RF02K-EKORG'
                                    GW_INPUT-EKORG.
      perform bdc_field       using 'RF02K-KTOKK'
                                    GW_INPUT-KTOKK.
      perform bdc_field       using 'USE_ZAV'
                                    'X'.
    
      IF GT_LFA1[] IS INITIAL."当前供应商在SAP不存在时
    
        perform bdc_dynpro      using 'SAPMF02K' '0111'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '=VW'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'SZA1_D0100-SMTP_ADDR'.
        perform bdc_field       using 'SZA1_D0100-TITLE_MEDI'
                                      GW_INPUT-ANRED.
        perform bdc_field       using 'ADDR1_DATA-NAME1'
                                      GW_INPUT-NAME1.
        perform bdc_field       using 'ADDR1_DATA-STREET'
                                      GW_INPUT-STREET.
    *    perform bdc_field       using 'ADDR1_DATA-HOME_CITY'
    *                                  ''.
        perform bdc_field       using 'ADDR1_DATA-POST_CODE1'
                                      GW_INPUT-PSTLZ.
        perform bdc_field       using 'ADDR1_DATA-COUNTRY'
                                      GW_INPUT-LAND1.
        perform bdc_field       using 'ADDR1_DATA-LANGU'
                                      'ZH'.
        perform bdc_field       using 'SZA1_D0100-TEL_NUMBER'
                                      GW_INPUT-TELF1.
        perform bdc_field       using 'SZA1_D0100-MOB_NUMBER'
                                      GW_INPUT-TELF2.
        perform bdc_field       using 'SZA1_D0100-FAX_NUMBER'
                                      GW_INPUT-TELFX.
        perform bdc_field       using 'SZA1_D0100-SMTP_ADDR'
                                      GW_INPUT-SMTP_ADDR.
    
        perform bdc_dynpro      using 'SAPMF02K' '0120'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'LFA1-BRSCH'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '=VW'.
        perform bdc_field       using 'LFA1-STCEG'
                                      GW_INPUT-STCEG.
        perform bdc_field       using 'LFA1-BRSCH'
                                      GW_INPUT-BRSCH.
    
        perform bdc_dynpro      using 'SAPMF02K' '0130'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'LFBK-BVTYP(01)'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '=BANK'.
        perform bdc_field       using 'LFBK-BANKS(01)'
                                      GW_INPUT-BANKS.
        perform bdc_field       using 'LFBK-BANKL(01)'
                                      GW_INPUT-BANKL.
        perform bdc_field       using 'LFBK-BANKN(01)'
                                      GW_INPUT-BANKN.
        perform bdc_field       using 'LFBK-KOINH(01)'
                                      GW_INPUT-KOINH.
        perform bdc_field       using 'LFBK-BVTYP(01)'
                                      GW_INPUT-BVTYP.
        IF GT_BNKA[] IS INITIAL."如果银行不存在,创建银行信息
          perform bdc_dynpro      using 'SAPLBANK' '0100'.
          perform bdc_field       using 'BDC_CURSOR'
                                        'BNKA-BRNCH'.
          perform bdc_field       using 'BDC_OKCODE'
                                        '=ENTR'.
          perform bdc_field       using 'BNKA-BANKA'
                                        GW_INPUT-BANKA.
          perform bdc_field       using 'BNKA-STRAS'
                                        GW_INPUT-STRAS.
          perform bdc_field       using 'BNKA-ORT01'
                                        GW_INPUT-ORT01.
          perform bdc_field       using 'BNKA-BRNCH'
                                        GW_INPUT-BRNCH.
          "返回130屏幕
          perform bdc_dynpro      using 'SAPMF02K' '0130'.
          perform bdc_field       using 'BDC_CURSOR'
                                        'LFBK-BANKS(01)'.
        ENDIF.
        "130屏幕上点下一页
        perform bdc_field       using 'BDC_OKCODE'
                                      '=VW'.
    
        perform bdc_dynpro      using 'SAPMF02K' '0380'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'KNVK-NAME1(01)'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '=LSDP'.
        perform bdc_field       using 'KNVK-NAME1(01)'
                                      GW_INPUT-NAME1_C.
        perform bdc_dynpro      using 'SAPMF02K' '1361'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '/00'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'SZA5_D0700-TEL_NUMBER'.
        perform bdc_field       using 'ADDR3_DATA-NAME_LAST'
                                      GW_INPUT-NAME1_C.
        perform bdc_field       using 'SZA5_D0700-TEL_NUMBER'
                                      GW_INPUT-TELF1_C.
        perform bdc_dynpro      using 'SAPMF02K' '0380'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'KNVK-NAMEV(01)'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '=VW'.
      ENDIF.
    
      IF GT_LFB1[] IS INITIAL."当前公司下没有此供应商时
        perform bdc_dynpro      using 'SAPMF02K' '0210'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'LFB1-FDGRV'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '=VW'.
        perform bdc_field       using 'LFB1-AKONT'
                                      GW_INPUT-AKONT.
        perform bdc_field       using 'LFB1-ZUAWA'
                                      GW_INPUT-ZUAWA.
        perform bdc_field       using 'LFB1-FDGRV'
                                      GW_INPUT-FDGRV.
    
        perform bdc_dynpro      using 'SAPMF02K' '0215'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'LFB1-REPRF'.
        perform bdc_field       using 'BDC_OKCODE'
                                      '=VW'.
        perform bdc_field       using 'LFB1-ZTERM'
                                      GW_INPUT-ZTERM.
        perform bdc_field       using 'LFB1-REPRF'
                                      GW_INPUT-REPRF.
        perform bdc_field       using 'LFB1-ZWELS'
                                      'BCELPTU'.
    
        perform bdc_dynpro      using 'SAPMF02K' '0220'.
        perform bdc_field       using 'BDC_CURSOR'
                                      'LFB5-MAHNA'.
        IF GT_LFB1[] IS INITIAL."如果采购组织下供应商不存在,继续跳转屏幕;已存在,保存结束
          perform bdc_field       using 'BDC_OKCODE'
                                        '=VW'.
        ELSE.
          perform bdc_field       using 'BDC_OKCODE'
                                        '=UPDA'.
        ENDIF.
      ENDIF.
    
                IF GT_LFM1[] IS INITIAL."当前采购组织下没有此供应商时
                  perform bdc_dynpro      using 'SAPMF02K' '0310'.
                  perform bdc_field       using 'BDC_CURSOR'
                                                'LFM1-WEBRE'.
                  perform bdc_field       using 'BDC_OKCODE'
                                                '=UPDA'.
                  perform bdc_field       using 'LFM1-WAERS'
                                                GW_INPUT-WAERS.
                  perform bdc_field       using 'LFM1-ZTERM'
                                                GW_INPUT-ZTERM.
                  perform bdc_field       using 'LFM1-KALSK'
                                                GW_INPUT-KALSK.
                  perform bdc_field       using 'LFM1-WEBRE'
                                                GW_INPUT-WEBRE.
                ENDIF.
    
      REFRESH MESSTAB.
      CALL TRANSACTION 'XK01' USING BDCDATA
                       MODE   'N'
                       UPDATE 'S'
                       MESSAGES INTO MESSTAB.
    
      IF SY-SUBRC <> 0.
        ZLOG-MANDT = SY-MANDT.
        ZLOG-PERNR = '00000000'.
        ZLOG-LIFNR = GW_INPUT-LIFNR.
        ZLOG-BUKRS = GW_INPUT-BUKRS.
        ZLOG-EKORG = GW_INPUT-EKORG.
        ZLOG-FLAG = ''.
        ZLOG-NAME1 = 'ZMM_SUPPLIER_CREATE'.
        ZLOG-CAL_DATE = SY-DATUM.
        ZLOG-CAL_TIME = SY-UZEIT.
        ZLOG-MESSAGE = '失败!'.
        LOOP AT MESSTAB.
          CALL FUNCTION 'MESSAGE_TEXT_BUILD'
            EXPORTING
              msgid               = MESSTAB-MSGID
              msgnr               = MESSTAB-MSGNR
              msgv1               = MESSTAB-MSGV1
              msgv2               = MESSTAB-MSGV2
              msgv3               = MESSTAB-MSGV3
              msgv4               = MESSTAB-MSGV4
            IMPORTING
              message_text_output = L_MESSAGE.
          CONCATENATE ZLOG-MESSAGE L_MESSAGE INTO ZLOG-MESSAGE.
        ENDLOOP.
        GT_MESSAGE-LIFNR     = ZLOG-LIFNR.
        GT_MESSAGE-BUKRS     = ZLOG-BUKRS.
        GT_MESSAGE-EKORG     = ZLOG-EKORG.
        GT_MESSAGE-TYPE      = ZLOG-FLAG.
        GT_MESSAGE-MESSAGE   = ZLOG-MESSAGE.
      ELSE.
        "日志
        ZLOG-MANDT = SY-MANDT.
        ZLOG-PERNR = '00000000'.
        ZLOG-LIFNR = GW_INPUT-LIFNR.
        ZLOG-BUKRS = GW_INPUT-BUKRS.
        ZLOG-EKORG = GW_INPUT-EKORG.
        ZLOG-FLAG = 'X'.
        ZLOG-NAME1 = 'ZMM_SUPPLIER_CREATE'.
        ZLOG-CAL_DATE = SY-DATUM.
        ZLOG-CAL_TIME = SY-UZEIT.
        ZLOG-MESSAGE = '创建成功!'.
        "返回
        GT_MESSAGE-LIFNR     = ZLOG-LIFNR.
        GT_MESSAGE-BUKRS     = ZLOG-BUKRS.
        GT_MESSAGE-EKORG     = ZLOG-EKORG.
        GT_MESSAGE-TYPE      = ZLOG-FLAG.
        GT_MESSAGE-MESSAGE   = ZLOG-MESSAGE.
      ENDIF.
      APPEND ZLOG.
      APPEND GT_MESSAGE.
      CLEAR: BDCDATA[],BDCDATA,ZLOG,GT_MESSAGE,GW_INPUT,L_MESSAGE,MESSTAB[],GT_LFB1[],GT_LFM1[],GT_BNKA[].
    ENDLOOP.
    
    
    
    MODIFY ZLOG_ZMMD004_001 FROM TABLE ZLOG.
    IF SY-SUBRC = 0.
      COMMIT WORK.
    ENDIF.
    ENDFUNCTION.
    DATA:   BDCDATA LIKE BDCDATA    OCCURS 0 WITH HEADER LINE.
    *----------------------------------------------------------------------*
    *        Start new screen                                              *
    *----------------------------------------------------------------------*
    FORM BDC_DYNPRO USING PROGRAM DYNPRO.
      CLEAR BDCDATA.
      BDCDATA-PROGRAM  = PROGRAM.
      BDCDATA-DYNPRO   = DYNPRO.
      BDCDATA-DYNBEGIN = 'X'.
      APPEND BDCDATA.
    ENDFORM.
    *----------------------------------------------------------------------*
    *        Insert field                                                  *
    *----------------------------------------------------------------------*
    FORM BDC_FIELD USING FNAM FVAL.
      IF FVAL <> '/'.
        CLEAR BDCDATA.
        BDCDATA-FNAM = FNAM.
        BDCDATA-FVAL = FVAL.
        APPEND BDCDATA.
      ENDIF.
    ENDFORM.

     

  • 相关阅读:
    ASP.NET控件开发学习笔记第5回 HtmlTextWriter的相关枚举
    ASP.NET控件开发学习笔记第4回 为控件添加属性
    ASP.NET控件开发学习笔记第6回 ViewState
    构建可反转排序的泛型字典类(9完)完善
    ASP.NET控件开发学习笔记第一回 HelloWorld
    构建可反转排序的泛型字典类(7)实现IDictionary接口
    C#泛型专题系列文章目录导航
    构建可反转排序的泛型字典类(8)实现IDictionary接口
    ASP.NET控件开发学习笔记第二回 又见Hello World
    ASP.NET控件开发学习笔记第3回 自制导航控件
  • 原文地址:https://www.cnblogs.com/CtrlS/p/10193790.html
Copyright © 2020-2023  润新知