2019年9月4日星期三

BP Create Vendor

REPORT ZBPADD2.
DATA:L_PARTN_CAT       TYPE BAPIBUS1006_HEAD-PARTN_CAT,
     LS_CENTRAL        TYPE BAPIBUS1006_CENTRAL,
     LS_PARTN_GROUP    TYPE BAPIBUS1006_HEAD,
     LS_CENTRAL_PERSON TYPE BAPIBUS1006_CENTRAL_PERSON,
     LS_CENTRAL_ORGAN  TYPE BAPIBUS1006_CENTRAL_ORGAN,
     L_PARTN_GRP       TYPE BAPIBUS1006_HEAD-PARTN_GRP,
     LS_CENTRAL_GROUP  TYPE BAPIBUS1006_CENTRAL_GROUP,
     LS_ADDRESS        TYPE BAPIBUS1006_ADDRESS,
     L_BPARTNER        TYPE BAPIBUS1006_HEAD-BPARTNER,
     LT_BAPIADTEL      LIKE TABLE OF BAPIADTEL WITH HEADER LINE,
     LT_BAPIRET2       LIKE TABLE OF BAPIRET2 WITH HEADER LINE,
     LT_GUID           LIKE TABLE OF BUS000___I WITH HEADER LINE,
     LT_CUSTO          TYPE TABLE OF BUS000_EEW WITH HEADER LINE.

DATA:LS_BUT0BK TYPE BUT0BK,
     LV_BKVID  TYPE BUT0BK-BKVID,
     LV_TYPE   TYPE CHAR1,
     L_STR     TYPE STRING,
     L_ROLE    TYPE BAPIBUS1006_HEAD-PARTNERROLE VALUE 'FLVN00'.

DATA:LS_BANKDETAIL TYPE BAPIBUS1006_BANKDETAIL.
DATA:LS_BANKDETAIL_X TYPE BAPIBUS1006_BANKDETAIL_X.
DATA:LT_RETURN TYPE TABLE OF BAPIRET2.
DATA:LS_RETURN TYPE BAPIRET2.


L_PARTN_CAT                      '2'.
LS_CENTRAL_ORGAN-NAME1           'aaa'.
LS_CENTRAL-SEARCHTERM1           'aaa'.
LS_CENTRAL_ORGAN-FOUNDATIONDATE  '20190220'.
LS_ADDRESS-COUNTRY              'JP'.
LS_ADDRESS-CITY                 'TOKYO'.
LS_ADDRESS-POSTL_COD1           '270-2261'.
LS_ADDRESS-STREET               'aaa'.
L_PARTN_GRP 'Z001'.

CLEAR LT_BAPIADTEL.
LT_BAPIADTEL-COUNTRY 'JP'.
LT_BAPIADTEL-STD_NO 'X'.
"電話
LT_BAPIADTEL-TELEPHONE '010-84522355'.
APPEND LT_BAPIADTEL.
LS_ADDRESS-LANGU '1'.
LS_ADDRESS-STREET 'BACK STRET'.

CALL FUNCTION 'BAPI_BUPA_CREATE_FROM_DATA'
  EXPORTING
*   USINESSPARTNEREXTERN    =
    BUSINESSPARTNEREXTERN   '0000999962'
    PARTNERCATEGORY         L_PARTN_CAT
    PARTNERGROUP            L_PARTN_GRP
    CENTRALDATA             LS_CENTRAL
    CENTRALDATAPERSON       LS_CENTRAL_PERSON
    CENTRALDATAORGANIZATION LS_CENTRAL_ORGAN
    CENTRALDATAGROUP        LS_CENTRAL_GROUP
    ADDRESSDATA             LS_ADDRESS
*   UPLICATE_MESSAGE_TYPE   =
*   CCEPT_ERROR             = ' '
  IMPORTING
    BUSINESSPARTNER         L_BPARTNER
  TABLES
    TELEFONDATA             LT_BAPIADTEL
*   AXDATA                  =
*   ELETEXDATA              =
*   ELEXDATA                =
*   _MAILDATA               =
*   MLADDRESSDATA           =
*   400ADDRESSDATA          =
*   FCADDRESSDATA           =
*   RTADDRESSDATA           =
*   SFADDRESSDATA           =
*   RIADDRESSDATA           =
*   AGADDRESSDATA           =
*   DDRESSNOTES             =
*   OMMUNICATIONNOTES       =
*   OMMUNICATIONUSAGE       =
*   ELEFONDATANONADDRESS    =
*   AXDATANONADDRESS        =
*   ELETEXDATANONADDRESS    =
*   ELEXDATANONADDRESS      =
*   _MAILDATANONADDRESS     =
*   MLADDRESSDATANONADDRESS =
*   400ADDRESSDATANONADDRESS          =
*   FCADDRESSDATANONADDRESS =
*   RTADDRESSDATANONADDRESS =
*   SFADDRESSDATANONADDRESS =
*   RIADDRESSDATANONADDRESS =
*   AGADDRESSDATANONADDRESS =
*   OMMUNICATIONNOTESNONADDRESS       =
*   OMMUNICATIONUSAGENONADDRESS       =
    RETURN                  LT_BAPIRET2.
*   DDRESSDUPLICATES        =


IF LT_BAPIRET2[] IS INITIAL.
  CALL FUNCTION 'BUP_MEMORY_BUT000_GET'
    EXPORTING
      IV_PARTNER       L_BPARTNER
    IMPORTING
      ES_BUT000        LT_GUID
    EXCEPTIONS
      NOT_FOUND        1
      PARAMETER_ERROR  2
      BPEXT_NOT_UNIQUE 3
      OTHERS           4.
  READ TABLE LT_GUID INDEX 1.
  LT_CUSTO-PARTNR_GUID LT_GUID-PARTNER_GUID.
  APPEND LT_CUSTO.

  CALL FUNCTION 'BUPA_CENTRAL_CI_CHANGE'
    EXPORTING
      IS_BUS000_EEW LT_CUSTO.

  IF SY-SUBRC EQ 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT 'X'.
  ENDIF.

ELSE.
  CLEAR L_STR.
  LOOP AT LT_BAPIRET2 WHERE TYPE 'E'.
    IF L_STR IS INITIAL.
      L_STR LT_BAPIRET2-MESSAGE.
    ELSE.
      CONCATENATE L_STR LT_BAPIRET2-MESSAGE INTO L_STR.
    ENDIF.
  ENDLOOP.
ENDIF.

*->添加银行数据
IF L_BPARTNER IS NOT INITIAL.
*->添加业务角色
  CALL FUNCTION 'BAPI_BUPA_ROLE_ADD'
    EXPORTING
      BUSINESSPARTNER     L_BPARTNER
      BUSINESSPARTNERROLE L_ROLE
    TABLES
      RETURN              LT_RETURN.
  CALL FUNCTION 'BAPI_BUPA_ROLE_ADD'
    EXPORTING
      BUSINESSPARTNER     L_BPARTNER
      BUSINESSPARTNERROLE 'FLVN01'
    TABLES
      RETURN              LT_RETURN.

  LS_BANKDETAIL-BANK_CTRY       'JP'.
  LS_BANKDETAIL-BANK_KEY        '0001027'.
  LS_BANKDETAIL-BANK_ACCT       '100122'.
  LS_BANKDETAIL-BANKACCOUNTNAME 'aaaa'.
  LS_BANKDETAIL-CTRL_KEY        '01'.
  LS_BANKDETAIL-ACCOUNTHOLDER   'aa'.

  CALL FUNCTION 'BAPI_BUPA_BANKDETAIL_ADD'
    EXPORTING
      BUSINESSPARTNER L_BPARTNER
      BANKDETAILDATA  LS_BANKDETAIL
    TABLES
      RETURN          LT_RETURN.

  READ TABLE LT_RETURN INTO LS_RETURN WITH KEY TYPE 'E'.

  IF SY-SUBRC NE 0.
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
      EXPORTING
        WAIT 'X'.
  ENDIF.
ENDIF.

CLEAR LT_RETURN[].
DATALS_MASTER_DATA           TYPE VMDS_EI_MAIN,
      LS_MASTER_DATA_CORRECT   TYPE VMDS_EI_MAIN,
      LS_MESSAGE_CORRECT       TYPE CVIS_MESSAGE,
      LS_MASTER_DATA_DEFECTIVE TYPE VMDS_EI_MAIN,
      LS_MESSAGE_DEFECTIVE     TYPE CVIS_MESSAGE.

DATALT_VENDOR        TYPE VMDS_EI_EXTERN_T,
      LS_VENDOR        TYPE VMDS_EI_EXTERN,
      LS_PURCHASE_DATA TYPE VMDS_EI_VMD_PURCHASING,
      LT_PURCHASE      TYPE VMDS_EI_PURCHASING_T,
      LS_PURCHASE      TYPE VMDS_EI_PURCHASING,
      LS_COMPANY       TYPE VMDS_EI_COMPANY,
      LT_FUNCTIONS     TYPE STANDARD TABLE OF VMDS_EI_FUNCTIONS,
      LS_FUNCTION      TYPE VMDS_EI_FUNCTIONS.

REFRESH LT_FUNCTIONSLT_VENDOR.
CLEARLS_VENDORLS_PURCHASE_DATA.
LS_VENDOR-HEADER-OBJECT_INSTANCE-LIFNR L_BPARTNER.
LS_VENDOR-HEADER-OBJECT_TASK  'U'" I/U/D
LS_PURCHASE_DATA-CURRENT_STATE SPACE.
LS_VENDOR-CENTRAL_DATA-CENTRAL-DATA-KTOKK 'SUPL'.
LS_VENDOR-CENTRAL_DATA-CENTRAL-DATAX-KTOKK 'X'.

LS_COMPANY-TASK                                'I'.
LS_COMPANY-DATA_KEY-BUKRS                      '1000'.
LS_COMPANY-DATA-AKONT                          =  '0004142000'.
LS_COMPANY-DATAX-AKONT                         =  'X'.
APPEND LS_COMPANY TO LS_VENDOR-COMPANY_DATA-COMPANY.
LS_PURCHASE-TASK 'I' .
LS_PURCHASE-DATA_KEY-EKORG '1000'.
LS_PURCHASE-FUNCTIONS-CURRENT_STATE SPACE.
LS_PURCHASE-DATA-WAERS 'JPY'.
LS_PURCHASE-DATAX-WAERS 'X'.
CLEAR LS_FUNCTION.
LS_FUNCTION-TASK  'I'.
LS_FUNCTION-DATA_KEY-PARVW 'LF'.
LS_FUNCTION-DATA-PARTNER   L_BPARTNER.
*ls_function-datax-partner  = 'X'.
APPEND LS_FUNCTION TO LT_FUNCTIONS.
LS_FUNCTION-TASK  'I'.
LS_FUNCTION-DATA_KEY-PARVW 'RS'.
LS_FUNCTION-DATA-PARTNER   L_BPARTNER.
*ls_function-datax-partner  = 'X'.
APPEND LS_FUNCTION TO LT_FUNCTIONS.
LS_PURCHASE-FUNCTIONS-FUNCTIONS LT_FUNCTIONS[].
APPEND LS_PURCHASE TO LT_PURCHASE.

LS_PURCHASE_DATA-PURCHASING[]  LT_PURCHASE[].
LS_VENDOR-PURCHASING_DATA LS_PURCHASE_DATA.
APPEND LS_VENDOR TO LT_VENDOR.
LS_MASTER_DATA-VENDORS LT_VENDOR[].

VMD_EI_API=>INITIALIZE).
VMD_EI_API=>LOCKIV_LIFNR LS_VENDOR-HEADER-OBJECT_INSTANCE-LIFNR ).

CALL METHOD VMD_EI_API=>MAINTAIN_BAPI
  EXPORTING
    IV_TEST_RUN              SPACE
*   IV_COLLECT_MESSAGES      = SPACE
    IS_MASTER_DATA           LS_MASTER_DATA
  IMPORTING
    ES_MASTER_DATA_CORRECT   LS_MASTER_DATA_CORRECT
    ES_MESSAGE_CORRECT       LS_MESSAGE_CORRECT
    ES_MASTER_DATA_DEFECTIVE LS_MASTER_DATA_DEFECTIVE
    ES_MESSAGE_DEFECTIVE     LS_MESSAGE_DEFECTIVE.



IF LS_MESSAGE_DEFECTIVE IS INITIAL.
  BREAK-POINT.
  COMMIT WORK.
ELSE.
  BREAK-POINT.
ENDIF.

VMD_EI_API=>UNLOCKIV_LIFNR LS_VENDOR-HEADER-OBJECT_INSTANCE-LIFNR ).

没有评论:

发表评论

Customer Characteristic

  Characteristic Descriptions are stored in the table - CABNT - Language - SPRAS - Characteristic description - ATBEZ Characteristic Values ...