Chinaunix首页 | 论坛 | 博客
  • 博客访问: 596473
  • 博文数量: 154
  • 博客积分: 10208
  • 博客等级: 上将
  • 技术积分: 2225
  • 用 户 组: 普通用户
  • 注册时间: 2007-11-16 14:02
文章分类

全部博文(154)

文章存档

2012年(4)

2011年(44)

2010年(50)

2009年(4)

2008年(52)

我的朋友

分类:

2011-04-02 15:15:40

*&---------------------------------------------------------------------*
*&      Form  FRM_CALL_BAPI_POST
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*  -->  p1        text
*  <--  p2        text
*----------------------------------------------------------------------*
FORM frm_call_bapi_post .
* 创建BP 参数
  DATA: lv_businesspartner       TYPE bapibus1006_head-bpartner.
  DATA: lt_return                TYPE STANDARD TABLE OF bapiret2,
        lwa_return               TYPE bapiret2,
        lt_telefondata           TYPE STANDARD TABLE OF bapiadtel,
        lwa_telefondata          TYPE bapiadtel.
  DATA: ls_centraldata           TYPE bapibus1006_central,
        ls_central               TYPE bapibus1006_central_search,
        ls_traldataorganization  TYPE bapibus1006_central_organ,
        ls_addressdata           TYPE bapibus1006_address.
* 添加银行数据  参数
  DATA: ls_bankdetaildata TYPE bapibus1006_bankdetail,
        lv_wait TYPE bapita-wait.
  DATA: lt_guid TYPE STANDARD TABLE OF bus000___i,
        lwa_guid TYPE bus000___i.
  DATA: lt_upload TYPE STANDARD TABLE OF ty_upload,
        lwa_upload TYPE ty_upload,
        lv_name1 TYPE ty_upload-name1,
        lv_flg   TYPE c,
        ls_bank_address TYPE bapi1011_address,
        ls_bank_addressx TYPE bapi1011_addressx.
  DATA: lt_result TYPE STANDARD TABLE OF bapibus1006_bp_addr,
        lwa_result TYPE bapibus1006_bp_addr.

  lt_upload[] = gt_upload[].
  lv_wait = 1.
  IF gt_upload IS NOT INITIAL.
    LOOP AT gt_upload INTO gwa_upload.
      CLEAR: lt_result, ls_central.
      ls_central-mc_name1 = gwa_upload-name1.
      CALL FUNCTION 'BAPI_BUPA_SEARCH_2'
        EXPORTING
*         TELEPHONE                         =
*         EMAIL                             =
*         URL                               =
*         ADDRESSDATA                       =
          centraldata                       =  ls_central
*         BUSINESSPARTNERROLECATEGORY       =
*         ALL_BUSINESSPARTNERROLES          =
*         BUSINESSPARTNERROLE               =
*         COUNTRY_FOR_TELEPHONE             =
*         FAX_DATA                          =
*         VALID_DATE                        =
*         OTHERS                            =
        TABLES
          searchresult                      = lt_result
          return                            = lt_return.
      .
      IF lt_result IS NOT INITIAL.
        READ TABLE lt_result INTO lwa_result INDEX 1.
        CLEAR gwa_output.
        gwa_output-name1 = gwa_upload-name1.
        gwa_output-msg = lwa_result-partner.
        CONCATENATE '该贷款机构' gwa_output-name1 '已存在,bP 号码为:' gwa_output-msg INTO gwa_output-msg.
        gwa_output-icon = '@0A@'.
        APPEND gwa_output TO gt_output.
        CONTINUE.
      ENDIF.

      CLEAR: lv_businesspartner,
             lt_return,
             lt_telefondata,
             ls_centraldata,
             ls_traldataorganization,
             ls_addressdata,
             ls_bankdetaildata.
      ls_centraldata-searchterm1 = gwa_upload-searchterm1.
      ls_centraldata-partnertype = gwa_upload-partnertype.
      PERFORM frm_convert_format CHANGING ls_centraldata-partnertype.
      ls_traldataorganization-name1 = gwa_upload-name1.

      ls_addressdata-city = gwa_upload-city.
      ls_addressdata-street = gwa_upload-street.
      ls_addressdata-country = 'CN'. "gwa_upload-bank_ctry.
      ls_addressdata-region = gwa_upload-region.
      IF gwa_upload-postl_cod1 IS INITIAL.
        ls_addressdata-postl_cod1 = '000000'.
      ELSE.
        ls_addressdata-postl_cod1 = gwa_upload-postl_cod1.
      ENDIF.
      lwa_telefondata-telephone = gwa_upload-telephone.
      APPEND lwa_telefondata TO lt_telefondata.
      CLEAR lv_name1.
      lv_name1 = gwa_upload-name1.
      AT END OF name1.
        CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
          EXPORTING
            partnercategory         = '2'
            partnergroup            = '0001'
            centraldata             = ls_centraldata
            centraldataorganization = ls_traldataorganization
            addressdata             = ls_addressdata
          IMPORTING
            businesspartner         = lv_businesspartner
          TABLES
            telefondata             = lt_telefondata
            return                  = lt_return.
        READ TABLE lt_return INTO lwa_return WITH KEY type = 'E'.
        IF sy-subrc = 0.
* 创建出错
          CLEAR gwa_output.
          gwa_output-name1 = gwa_upload-name1.
          gwa_output-bpno = lv_businesspartner.
          CONCATENATE lwa_return-type lwa_return-id lwa_return-number lwa_return-message
                      INTO gwa_output-msg SEPARATED BY space.
          gwa_output-icon = '@0A@'.
          APPEND gwa_output TO gt_output.
        ELSE.
          CLEAR: lt_guid, lv_flg.
          CALL FUNCTION 'BUP_MEMORY_BUT000_GET'
            EXPORTING
              iv_partner = lv_businesspartner
            IMPORTING
              es_but000  = lwa_guid.

          LOOP AT lt_upload INTO lwa_upload WHERE name1 = lv_name1.
            CLEAR: ls_bankdetaildata.
            ls_bankdetaildata-bank_ctry = 'CN'."gwa_upload-bank_ctry. "银行国家代码
            ls_bankdetaildata-bank_key  = lwa_upload-bank_key. "银行代码
            ls_bankdetaildata-bankaccountname = lwa_upload-bankaccountname.
            ls_bankdetaildata-bank_acct = lwa_upload-bank_acct."银行帐户号码
            CLEAR: lt_return, lwa_return.
* 检查是否存在
            CALL FUNCTION 'BAPI_BANK_GETDETAIL'
              EXPORTING
                bankcountry        = 'CN'
                bankkey            = ls_bankdetaildata-bank_key
              IMPORTING
                bank_address       = ls_bank_address
*                bank_detail        =
                return             = lwa_return
                      .
            IF lwa_return-type = 'E'.
              CLEAR lwa_return.
              ls_bank_address-bank_name = ls_bankdetaildata-bankaccountname.
              CALL FUNCTION 'BAPI_BANK_CREATE'
                EXPORTING
                  bank_ctry             = 'CN'
                  bank_key              = ls_bankdetaildata-bank_key
                  bank_address          = ls_bank_address
*               BANK_METHOD           =
*               BANK_FORMATTING       =
*               BANK_ADDRESS1         =
*               I_XUPDATE             = 'X'
                IMPORTING
                  return                = lwa_return
*               BANKCOUNTRY           =
*               BANKKEY               =
                        .
            ELSE.
              IF ls_bank_address-bank_name <> ls_bankdetaildata-bankaccountname.
                ls_bank_address-bank_name = ls_bankdetaildata-bankaccountname.
                ls_bank_addressx-bank_name = 'X'.
                CALL FUNCTION 'BAPI_BANK_CHANGE'
                  EXPORTING
                    bankcountry          = 'CN'
                    bankkey              = ls_bankdetaildata-bank_key
                    bank_address         = ls_bank_address
                    bank_addressx        = ls_bank_addressx
*                   BANK_DETAIL          =
*                   BANK_DETAILX         =
*                   BANK_ADDRESS1        =
*                   BANK_ADDRESS1X       =
                  IMPORTING
                    return               = lwa_return
                          .

              ENDIF.
            ENDIF.
            IF lwa_return-type = 'E'.
* 添加银行数据出错
              CLEAR gwa_output.
              gwa_output-name1 = gwa_upload-name1.
              gwa_output-msg = text-t04.
              CONCATENATE lwa_return-type lwa_return-id lwa_return-number lwa_return-message
                          INTO gwa_output-msg SEPARATED BY space.
              gwa_output-icon = '@0A@'.
              APPEND gwa_output TO gt_output.
              lv_flg = 'X'.
              EXIT.
            ELSE.
              CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_ADD'
                EXPORTING
                  businesspartner = lv_businesspartner
                  bankdetaildata  = ls_bankdetaildata
                TABLES
                  return          = lt_return.


              READ TABLE lt_return INTO lwa_return WITH KEY type = 'E'.
              IF sy-subrc = 0.
* 添加银行数据出错
                CLEAR gwa_output.
                gwa_output-name1 = gwa_upload-name1.
                gwa_output-msg = text-t03.
                CONCATENATE lwa_return-type lwa_return-id lwa_return-number lwa_return-message
                            INTO gwa_output-msg SEPARATED BY space.
                gwa_output-icon = '@0A@'.
                APPEND gwa_output TO gt_output.
                lv_flg = 'X'.
                EXIT.
              ENDIF.
            ENDIF.
          ENDLOOP.
          CLEAR lt_return.
          CALL FUNCTION 'BAPI_BUPA_ROLE_ADD'
            EXPORTING
              businesspartner                = lv_businesspartner
              businesspartnerrole            = 'TR0100'
*                   DIFFERENTIATIONTYPEVALUE       =
            TABLES
              return                         = lt_return.
          .
*添加角色出错
          READ TABLE lt_return INTO lwa_return WITH KEY type = 'E'.
          IF sy-subrc = 0.
            CLEAR gwa_output.
            gwa_output-name1 = gwa_upload-name1.
            gwa_output-msg = text-t05.
            CONCATENATE lwa_return-type lwa_return-id lwa_return-number lwa_return-message
                        INTO gwa_output-msg SEPARATED BY space.
            gwa_output-icon = '@0A@'.
            APPEND gwa_output TO gt_output.
            lv_flg = 'X'.
          ENDIF.
          IF lv_flg IS INITIAL.
* 成功
            CLEAR gwa_output.
            gwa_output-name1 = lv_name1.
            gwa_output-bpno = lv_businesspartner.
            gwa_output-msg  = text-t02.
            gwa_output-icon = '@08@'.
            APPEND gwa_output TO gt_output.
            CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
          ELSE.
            CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
          ENDIF.
        ENDIF.
      ENDAT.
    ENDLOOP.
  ENDIF.
  SORT gt_output BY  bpno name1.
  DELETE ADJACENT DUPLICATES FROM gt_output COMPARING name1 bpno.
ENDFORM.                    " FRM_CALL_BAPI_POST
阅读(718) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~