SAP ABAP - Create Vendor Master Using VMD_EI_API
*&---------------------------------------------------------------------*
*& Report ZVENDOR_CREATE
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZVENDOR_CREATE.
*----------------------------------------------------------------------*
* CLASS LCL_DATA DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS LCL_DATA DEFINITION.
PUBLIC SECTION.
METHODS: CONSTRUCTOR
IMPORTING
I_CCODE TYPE BUKRS
I_KTOKK TYPE KTOKK
I_AKONT TYPE AKONT
I_NAME TYPE AD_NAME1,
CREATE_VENDOR_DATA
EXPORTING
E_LIFNR TYPE LIFNR.
PRIVATE SECTION.
METHODS: PREPARE_DATA
RETURNING VALUE(RE_FLAG) TYPE I.
* Data Declarations
DATA: GS_VMDS_EXTERN TYPE VMDS_EI_MAIN,
GS_SUCC_MESSAGES TYPE CVIS_MESSAGE,
GS_VMDS_ERROR TYPE VMDS_EI_MAIN,
GS_ERR_MESSAGES TYPE CVIS_MESSAGE,
GS_VMDS_SUCC TYPE VMDS_EI_MAIN,
GV_KTOKK TYPE KTOKK,
GV_CCODE TYPE BUKRS,
GV_AKONT TYPE AKONT,
GV_NAME TYPE NAME1.
ENDCLASS. "lcl_data
*———————————————————————-*
* CLASS lcl_data IMPLEMENTATION
*———————————————————————-*
*
*———————————————————————-*
CLASS LCL_DATA IMPLEMENTATION.
METHOD CONSTRUCTOR.
ME->GV_CCODE = I_CCODE.
ME->GV_KTOKK = I_KTOKK.
ME->GV_AKONT = I_AKONT.
ME->GV_NAME = I_NAME.
ENDMETHOD. "constructor
METHOD PREPARE_DATA.
* Local Data Declaration
DATA: LT_CONTACTS TYPE VMDS_EI_CONTACTS_T,
LS_CONTACTS TYPE VMDS_EI_CONTACTS,
LT_VENDORS TYPE VMDS_EI_EXTERN_T,
LS_VENDORS TYPE VMDS_EI_EXTERN,
LS_ADDRESS TYPE CVIS_EI_ADDRESS1,
LT_BANK TYPE CVIS_EI_BANKDETAIL_T,
LS_BANK TYPE CVIS_EI_CVI_BANKDETAIL,
LT_COMPANY TYPE VMDS_EI_COMPANY_T,
LS_COMPANY TYPE VMDS_EI_COMPANY,
LS_COMPANY_DATA TYPE VMDS_EI_VMD_COMPANY,
LS_PURCHAS_DATA TYPE VMDS_EI_VMD_PURCHASING,
LT_PURCHASING TYPE VMDS_EI_PURCHASING_T,
LS_PURCHASING TYPE VMDS_EI_PURCHASING,
LT_PURCH_FUNC TYPE VMDS_EI_FUNCTIONS_T,
LS_PURCH_FUNC TYPE VMDS_EI_FUNCTIONS,
LS_MESSAGE TYPE CVIS_MESSAGE,
LV_CONTACTID TYPE BAPICONTACT_01-CONTACT.
CLEAR GS_VMDS_EXTERN.
CALL METHOD VMD_EI_API=>GET_NUMBER
EXPORTING
IV_KTOKK = GV_KTOKK
IMPORTING
EV_LIFNR = LS_VENDORS-HEADER-OBJECT_INSTANCE-LIFNR
ES_ERROR = LS_MESSAGE.
LS_VENDORS-HEADER-OBJECT_TASK = 'I'. " I = Create, U = Change
LS_ADDRESS-POSTAL-DATA-NAME = GV_NAME.
LS_ADDRESS-POSTAL-DATA-STREET = 'COBA AJA ALAMAT yes'.
LS_ADDRESS-POSTAL-DATA-POSTL_COD1 = '12345'.
LS_ADDRESS-POSTAL-DATA-COUNTRY = 'ID'.
LS_ADDRESS-POSTAL-DATA-SORT1 = GV_NAME.
LS_ADDRESS-POSTAL-DATA-LANGU = SY-LANGU.
LS_ADDRESS-POSTAL-DATAX-NAME = 'X'.
LS_ADDRESS-POSTAL-DATAX-STREET = 'X'.
LS_ADDRESS-POSTAL-DATAX-POSTL_COD1 = 'X'.
LS_ADDRESS-POSTAL-DATAX-SORT1 = 'X'.
LS_ADDRESS-POSTAL-DATAX-COUNTRY = 'X'.
LS_ADDRESS-POSTAL-DATAX-LANGU = 'X'.
LS_ADDRESS-TASK = 'I'.
LS_VENDORS-CENTRAL_DATA-ADDRESS = LS_ADDRESS.
REFRESH LT_BANK[].
CLEAR LS_BANK.
LS_BANK-TASK = 'I'.
LS_BANK-DATA_KEY-BANKS = 'ID'.
LS_BANK-DATA_KEY-BANKL = '000002'.
LS_BANK-DATA_KEY-BANKN = '352842132'.
LS_BANK-DATA-KOINH = 'BRI'.
LS_BANK-DATAX-KOINH = 'X'.
APPEND LS_BANK TO LT_BANK.
CLEAR LS_BANK.
LS_BANK-TASK = 'I'.
LS_BANK-DATA_KEY-BANKS = 'ID'.
LS_BANK-DATA_KEY-BANKL = '000003'.
LS_BANK-DATA_KEY-BANKN = '93037890'.
LS_BANK-DATA-KOINH = 'MANDIRI'.
LS_BANK-DATAX-KOINH = 'X'.
APPEND LS_BANK TO LT_BANK.
LS_VENDORS-CENTRAL_DATA-BANKDETAIL-BANKDETAILS = LT_BANK[].
* Contact Person
REFRESH: LT_CONTACTS[].
* CLEAR LS_CONTACTS.
* LS_CONTACTS-TASK = 'U'.
* LS_CONTACTS-ADDRESS_TYPE_3-TASK = 'U'.
*
** Specify how many Contact Person numbers are to be obtained
** This will simply provide us a contact person number
** NOTE: If the note 1749700 is present in the system, then the contact person number can be left empty
* CALL FUNCTION 'BAPI_PARTNEREMPLOYEE_GETINTNUM'
* EXPORTING
* QUANTITY = '1'
* IMPORTING
* CONTACTID = LV_CONTACTID.
*
* LS_CONTACTS-DATA_KEY-PARNR = LV_CONTACTID. "Contact Person Number
** Set the Name for Contact person
* LS_CONTACTS-ADDRESS_TYPE_3-POSTAL-DATA-FULLNAME = 'JOHN DOE'.
* LS_CONTACTS-ADDRESS_TYPE_3-POSTAL-DATA-FIRSTNAME = 'JOHN'.
* LS_CONTACTS-ADDRESS_TYPE_3-POSTAL-DATA-LASTNAME = 'DOE'.
* APPEND LS_CONTACTS TO LT_CONTACTS.
*
** Set the Contact Person details for the Vendor
* LS_VENDORS-CENTRAL_DATA-CONTACT-CONTACTS = LT_CONTACTS[].
* Set the Account Group
LS_VENDORS-CENTRAL_DATA-CENTRAL-DATA-KTOKK = GV_KTOKK.
LS_VENDORS-CENTRAL_DATA-CENTRAL-DATA-STCD1 = 'VAT 1'.
LS_VENDORS-CENTRAL_DATA-CENTRAL-DATAX-KTOKK = 'X'.
LS_VENDORS-CENTRAL_DATA-CENTRAL-DATAX-STCD1 = 'X'.
* Company Code and GL Account Data
REFRESH: LT_COMPANY[].
CLEAR LS_COMPANY.
LS_COMPANY-TASK = 'I'.
LS_COMPANY-DATA_KEY-BUKRS = GV_CCODE.
LS_COMPANY-DATA-AKONT = GV_AKONT.
LS_COMPANY-DATA-FDGRV = 'A1'.
LS_COMPANY-DATA-ZTERM = '0001'.
LS_COMPANY-DATAX-AKONT = 'X'.
LS_COMPANY-DATAX-FDGRV = 'X'.
LS_COMPANY-DATAX-ZTERM = 'X'.
APPEND LS_COMPANY TO LT_COMPANY.
CLEAR LS_COMPANY.
LS_COMPANY-TASK = 'I'.
LS_COMPANY-DATA_KEY-BUKRS = '3000'.
LS_COMPANY-DATA-AKONT = GV_AKONT.
LS_COMPANY-DATA-FDGRV = 'A1'.
LS_COMPANY-DATA-ZTERM = '0001'.
LS_COMPANY-DATAX-AKONT = 'X'.
LS_COMPANY-DATAX-FDGRV = 'X'.
LS_COMPANY-DATAX-ZTERM = 'X'.
APPEND LS_COMPANY TO LT_COMPANY.
LS_VENDORS-COMPANY_DATA-COMPANY = LT_COMPANY[].
* Purchasing Data
REFRESH: LT_PURCHASING[],
LT_PURCH_FUNC[].
CLEAR LS_PURCHASING.
LS_PURCHASING-TASK = 'I'.
LS_PURCHASING-DATA_KEY-EKORG = '3000'.
LS_PURCHASING-DATA-KALSK = '01'.
LS_PURCHASING-DATA-WEBRE = 'X'.
LS_PURCHASING-DATAX-KALSK = 'X'.
LS_PURCHASING-DATAX-WEBRE = 'X'.
APPEND LS_PURCHASING TO LT_PURCHASING.
CLEAR LS_PURCHASING.
LS_PURCHASING-TASK = 'I'.
LS_PURCHASING-DATA_KEY-EKORG = '1000'.
LS_PURCHASING-DATA-WAERS = 'IDR'.
LS_PURCHASING-DATA-KALSK = '01'.
LS_PURCHASING-DATA-WEBRE = 'X'.
LS_PURCHASING-DATAX-WAERS = 'X'.
LS_PURCHASING-DATAX-KALSK = 'X'.
LS_PURCHASING-DATAX-WEBRE = 'X'.
APPEND LS_PURCHASING TO LT_PURCHASING.
* CLEAR LS_PURCH_FUNC.
* LS_PURCH_FUNC-TASK = 'I'.
* LS_PURCH_FUNC-DATA_KEY-PARVW = 'BA'.
* LS_PURCH_FUNC-DATA-PARTNER = LS_VENDORS-HEADER-OBJECT_INSTANCE-LIFNR.
* LS_PURCH_FUNC-DATAX-PARTNER = 'X'.
* APPEND LS_PURCH_FUNC TO LT_PURCH_FUNC[].
*
** Invoicing Party
* CLEAR LS_PURCH_FUNC.
* LS_PURCH_FUNC-TASK = 'I'.
* LS_PURCH_FUNC-DATA_KEY-PARVW = 'RS'.
* LS_PURCH_FUNC-DATA-PARTNER = LS_VENDORS-HEADER-OBJECT_INSTANCE-LIFNR.
* LS_PURCH_FUNC-DATAX-PARTNER = 'X'.
* APPEND LS_PURCH_FUNC TO LT_PURCH_FUNC[].
*
** Vendor
* CLEAR LS_PURCH_FUNC.
* LS_PURCH_FUNC-TASK = 'I'.
* LS_PURCH_FUNC-DATA_KEY-PARVW = 'LF'.
* LS_PURCH_FUNC-DATA-PARTNER = LS_VENDORS-HEADER-OBJECT_INSTANCE-LIFNR.
* LS_PURCH_FUNC-DATAX-PARTNER = 'X'.
* APPEND LS_PURCH_FUNC TO LT_PURCH_FUNC[].
*
** Set the Purchasing Data – Partner functions
* LS_PURCHASING-FUNCTIONS-FUNCTIONS = LT_PURCH_FUNC[].
* APPEND LS_PURCHASING TO LT_PURCHASING.
* Set the Purchasing Data
LS_VENDORS-PURCHASING_DATA-PURCHASING = LT_PURCHASING[].
APPEND LS_VENDORS TO LT_VENDORS.
GS_VMDS_EXTERN-VENDORS = LT_VENDORS[].
ENDMETHOD.
METHOD CREATE_VENDOR_DATA.
DATA: LV_RETURN TYPE I.
LV_RETURN = ME->PREPARE_DATA( ).
IF LV_RETURN IS NOT INITIAL.
EXIT.
ENDIF.
VMD_EI_API=>INITIALIZE( ).
CALL METHOD VMD_EI_API=>MAINTAIN_BAPI
EXPORTING
IS_MASTER_DATA = GS_VMDS_EXTERN
IMPORTING
ES_MASTER_DATA_CORRECT = GS_VMDS_SUCC
ES_MESSAGE_CORRECT = GS_SUCC_MESSAGES
ES_MASTER_DATA_DEFECTIVE = GS_VMDS_ERROR
ES_MESSAGE_DEFECTIVE = GS_ERR_MESSAGES.
IF GS_ERR_MESSAGES-IS_ERROR IS INITIAL.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDMETHOD.
ENDCLASS.
SELECTION-SCREEN BEGIN OF BLOCK TB1.
PARAMETERS: P_CCODE TYPE BUKRS,
P_AKONT TYPE AKONT,
P_KTOKK TYPE KTOKK,
P_NAME TYPE AD_NAME1.
SELECTION-SCREEN END OF BLOCK TB1.
DATA: LO_DATA TYPE REF TO LCL_DATA,
GV_LIFNR TYPE LIFNR.
START-OF-SELECTION.
CREATE OBJECT LO_DATA
EXPORTING
I_CCODE = P_CCODE
I_AKONT = P_AKONT
I_KTOKK = P_KTOKK
I_NAME = P_NAME.
CALL METHOD LO_DATA->CREATE_VENDOR_DATA
IMPORTING
E_LIFNR = GV_LIFNR.
WRITE GV_LIFNR.
Comments
Post a Comment