2019年9月4日星期三

BP Ceate Customer

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 'FLCU00'.

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   '0000999966'
    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.

*->ADD ROLE

  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 'FLCU01'
    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[].

*    CALL FUNCTION 'BAPI_BUPA_TAX_ADD'
*      EXPORTING
*        businesspartner = l_bpartner
*        taxtype         = 'CN0'
*        taxnumber       = ps_in-stceg
*      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.

*

DATALS_MASTER_DATA           TYPE CMDS_EI_MAIN,
      LS_MASTER_DATA_CORRECT   TYPE CMDS_EI_MAIN,
      LS_MESSAGE_CORRECT       TYPE CVIS_MESSAGE,
      LS_MASTER_DATA_DEFECTIVE TYPE CMDS_EI_MAIN,
      LS_MESSAGE_DEFECTIVE     TYPE CVIS_MESSAGE.
DATALT_CUSTOMERS  TYPE CMDS_EI_EXTERN_T,
      LS_CUSTOMER   TYPE CMDS_EI_EXTERN,
      LS_SALES_DATA TYPE CMDS_EI_CMD_SALES,
      LT_SALES      TYPE CMDS_EI_SALES_T,
      LS_SALES      TYPE CMDS_EI_SALES,
      LS_COMPANY    TYPE CMDS_EI_COMPANY,
      LT_FUNCTIONS  TYPE CMDS_EI_FUNCTIONS_T,
      LS_FUNCTION   TYPE CMDS_EI_FUNCTIONS.

REFRESH LT_FUNCTIONSLT_SALES.
CLEARLS_CUSTOMERLS_SALES_DATA.
LS_CUSTOMER-HEADER-OBJECT_INSTANCE-KUNNR L_BPARTNER.
LS_CUSTOMER-HEADER-OBJECT_TASK  'U'" I/U/D
LS_SALES_DATA-CURRENT_STATE SPACE.
LS_COMPANY-TASK                                'I'.
LS_COMPANY-DATA_KEY-BUKRS                      '1000'.
LS_COMPANY-DATA-AKONT                          =  '0001141000'.
LS_COMPANY-DATAX-AKONT                         =  'X'.
APPEND LS_COMPANY TO LS_CUSTOMER-COMPANY_DATA-COMPANY.

LS_SALES-TASK 'I' .
LS_SALES-DATA_KEY-VKORG '1000'.
LS_SALES-DATA_KEY-VTWEG '10'.
LS_SALES-DATA_KEY-SPART '10'.
LS_SALES-FUNCTIONS-CURRENT_STATE SPACE.
LS_SALES-DATA-WAERS 'JPY'.
LS_SALES-DATAX-WAERS 'X'.
CLEAR LS_FUNCTION.
LS_FUNCTION-TASK  'I'.
LS_FUNCTION-DATA_KEY-PARVW 'AG'.
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 'RE'.
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 'RG'.
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 'WE'.
LS_FUNCTION-DATA-PARTNER   L_BPARTNER.
*ls_function-datax-partner  = 'X'.
APPEND LS_FUNCTION TO LT_FUNCTIONS.

LS_SALES-FUNCTIONS-FUNCTIONS LT_FUNCTIONS[].
APPEND LS_SALES TO LT_SALES.

LS_SALES_DATA-SALES[]  LT_SALES[].
LS_CUSTOMER-SALES_DATA LS_SALES_DATA.
APPEND LS_CUSTOMER TO LT_CUSTOMERS.
LS_MASTER_DATA-CUSTOMERS LT_CUSTOMERS[].

CMD_EI_API=>INITIALIZE).
CMD_EI_API=>LOCKIV_KUNNR LS_CUSTOMER-HEADER-OBJECT_INSTANCE-KUNNR ).

CALL METHOD CMD_EI_API=>MAINTAIN_BAPI
  EXPORTING
    IV_TEST_RUN              SPACE
    IV_COLLECT_MESSAGES      'X'
    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.
CMD_EI_API=>UNLOCKIV_KUNNR LS_CUSTOMER-HEADER-OBJECT_INSTANCE-KUNNR ).

没有评论:

发表评论

Customer Characteristic

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