Cmd_ei_api= maintain_bapi

Hi All;
I am trying to write a test program to use this method.  I almost have it working but I am getting an error message that I am missing critical partner functions.  I have tried adding the Partner Functions to the Sales Data component but keep getting an error when attaching the "Functions" table to this component.  Below is my sample program.  It is based on other examples in this forms.  Any ideas?
report zcreate_customer.
data: wa_header          type cmds_ei_header,
      wa_central_data    type cmds_ei_vmd_central_data,
      wa_central_datax   type cmds_ei_vmd_central_data_xflag,
      wa_address         type bapiad1vl,
      wa_addressx        type bapiad1vlx,
      wa_tax_ind_st      type cmds_ei_tax_ind,
      wa_tax_ind         type cmds_ei_cmd_tax_ind,
      wa_bankdetail_st   type cvis_ei_cvi_bankdetail,
      wa_bankdetail      type cvis_ei_bankdetail,
      wa_company_code_st type cmds_ei_company,
      wa_company_code    type cmds_ei_cmd_company,
      wa_functions_st    type cmds_ei_functions,
      wa_functions_t     type CMDS_EI_FUNCTIONS_T,
      wa_functions       type cmds_ei_cmd_functions,
      wa_sales_data_st   type cmds_ei_sales,
      wa_sales_data      type cmds_ei_cmd_sales,
      wa_customer        type cmds_ei_extern,
      wa_customers       type cmds_ei_main,
      wa_correct         type cmds_ei_main,
      wa_defective       type cmds_ei_main,
      wa_mes_correct     type cvis_message,
      wa_mes_error       type cvis_message.
constants: c_update type c value 'M',
           c_insert type c value 'I'.
start-of-selection.
* A "customer" is made up of 4 Main Sections
*    1. HEADER
*    2. CENTRAL_DATA
*    3. COMPANY_DATA
*    4  SALES_DATA
  free: wa_customer, wa_company_code_st, wa_customer.
  wa_address-name       = 'CUSTOMER NAME'.
  wa_address-city       = 'CITY'.
  wa_address-postl_cod1 = '99999'.
  wa_address-street     = '1400 9TH ST W'.
  wa_address-country    = 'US'.
  wa_address-langu      = 'EN'.
  wa_address-region     = 'FL'.
  wa_address-sort1      = 'SORT1'.
  wa_address-sort2      = ''.
  wa_address-taxjurcode = 'FL0000000'.
* wa_address-time_zone = 'UTC-6'.
* Assign address data directly
  wa_customer-central_data-address-postal-data = wa_address.
  wa_customer-central_data-address-postal-datax = wa_addressx.
* Account account group directly
  wa_customer-central_data-central-data-ktokd = 'Z001'.
*  wa_customer-central_data-central-datax-ktokd = 'X'.
  wa_company_code_st-task           = c_insert.
  wa_company_code_st-data_key-bukrs = '1000'.
  wa_company_code_st-data-zuawa     = '009'.
  wa_company_code_st-data-akont     = '0000121000'.
  wa_company_code_st-data-zwels     = 'ACDETY'.
  wa_company_code_st-data-zterm     = 'Z000'.
  wa_company_code_st-data-zgrup     = '02'.
  wa_company_code_st-data-xausz     = '2'.
  wa_company_code_st-data-xzver     = 'X'.
  append wa_company_code_st to wa_company_code-company.
Continued...
Edited by: kishan P on Nov 3, 2010 8:13 AM
Edited by: kishan P on Nov 3, 2010 8:15 AM

Part II
  wa_sales_data_st-task             = c_insert.
  wa_sales_data_st-data_key-vkorg   = '1000'.
  wa_sales_data_st-data_key-vtweg   = '10'.
  wa_sales_data_st-data_key-spart   = '10'.
  wa_sales_data_st-data-kalks       = '1'.
  wa_sales_data_st-data-inco1       = 'FOB'.
  wa_sales_data_st-data-inco2       = 'Free on board'.
  wa_sales_data_st-data-antlf       = '9'.
  wa_sales_data_st-data-kzazu       = 'X'.
  wa_sales_data_st-data-vsbed       = '01'.
  wa_sales_data_st-data-waers       = 'USD'.
  wa_sales_data_st-data-ktgrd       = '01'.
  wa_sales_data_st-data-zterm       = 'Z000'.
*  wa_sales_data_st-functions-functions-data_key-parvw = 'SP'.
  wa_functions_st-data_key-parvw    = 'SP'.
  wa_functions_st-data_key-parza    = '000'.
  append wa_functions_st to wa_functions_t.
  wa_functions_st-data_key-parvw    = 'BP'.
  wa_functions_st-data_key-parza    = '000'.
  append wa_functions_st to wa_functions_t.
  wa_functions_st-data_key-parvw    = 'PY'.
  wa_functions_st-data_key-parza    = '000'.
  append wa_functions_st to wa_functions_t.
  wa_functions_st-data_key-parvw    = 'SH'.
  wa_functions_st-data_key-parza    = '000'.
  append wa_functions_st to wa_functions_t.
*  wa_functions = wa_functions_t.
*  wa_sales_data_st-functions        = wa_functions.
  append wa_sales_data_st to wa_sales_data-sales.
  wa_customer-header-object_instance-kunnr = ''.
  wa_customer-header-object_task = c_insert.
  wa_customer-company_data = wa_company_code.
  wa_customer-sales_data   = wa_sales_data.
  append wa_customer to wa_customers-customers.
  call method cmd_ei_api=>maintain_bapi
    EXPORTING
      iv_test_run         = 'X'
      iv_collect_messages = 'X'
      is_master_data      = wa_customers
    IMPORTING
      es_master_data_correct   = wa_correct
      es_message_correct       = wa_mes_correct
      es_master_data_defective = wa_defective
      es_message_defective     = wa_mes_error.
  if wa_mes_error-is_error is initial.
    commit work.
  endif.

Similar Messages

  • Change Customer Master using CMD_EI_API MAINTAIN_BAPI Method

    Hi Experts,
    I am using CMD_EI_API=>MAINTAIN_BAPI method for Creating Customer through Custom program. The Creation of Customer Master is working fine.
    I have another requirement i need to perform the following for the Customer Change
    1 . Delete all Phone , Fax and SMTP entries from the table and create a new entries for Customer.
    2 . Delete a Contact Person based on the information from the legacy system.
    I am facing problem in the above two issues
    ADR2, ADR3 and ADR6 entries are retrieved for customer.
    this values are populated and passed to the method with Task as 'D' - delete.
    there is no error message  from the Method. when i call commit statement
    1 . the address details are not getting deleted in the tables
    2. if a contact person is deleted then i am getting a short dump while commit.
    Please help me if you know the details of MAINTAIN_BAPI method whic can be used for the Deletion purpose.
    Thanks,
    Shrikanth R

    Hi Experts
    I'm having the same problem it looks like the method maintain_bapi does not commit the new values, I debuged it and found a call to a badi lr_badi_update but I could not find information about it.
    Any help will be appreciate
    Leo

  • Method CMD_EI_API= MAINTAIN_BAPI to update KNVI tax data

    Hi Experts,
    I am using method CMD_EI_API=>MAINTAIN_BAPI to create/update customer. I could not find the parameters/fields in the deep structure to update KNVI data. Please suggest the solution.
    Regards,
    Ashok

    Dear Ashok,
    possibly structure CMDS_EI_TAX_IND_KEY
    Greetings
    Winfried

  • Method CMD_EI_API MAINTAIN_BAPI fails on missing KNVK-NAME1

    Hi experts. I'm trying to create a new contact for a customer using CMD_EI_API method MAINTAIN_BAPI and I'm getting a message saying "KNVK-NAME1: Plausibility check failed". I've set up the structure and tables reference with type cmds_ei_extern. The mapping within the method finds my values and maps correctly to the internal address structure  (using ADDRESS_TYPE_1). I've also tried using ADDRESS_TYPE_2 and ADDRESS_TYPE_3 with the same results. The error occurs when checking the new KNVK record in method STRUC_KNVK_PLAUSIBILITY_CHECK and I suspect that I'm missing some required data that is preventing the record from be created correctly. Any ideas.
    ...thanks in advance

    Hi
    At first, for the contact you should maintain ADDRESS_TYPE_3 structure.
    Lastname is mandatory.
    This should solves your trouble
    As a general help for filling that complex structure, you could run method GET_DATA of class CMD_EI_API_EXTRACT for an existing customer.
    Regards
    Alain

  • Authority Check in Class Interface CMD_EI_API

    I am using the class CMD_EL_API in order to create new customer.
    The class is working very well, but there is a problem.
    Not all the users that are going to utilize this aplicacion can have access to XD01 and XD02 and the class check the authorization on these transactions. 
    Error:
             You are not authorized to use Transaction  XD01.
    Already it was given them access to all the objects of the XD01 and XD02 but continues marking the same error. 
    It wold be able someone to indicate me that can be done.
    Thank you
    Blanca Segovia

    Hi
    This is a small program to start with this method. I hope you serve
    report  zcreate_cliente.
    data: wa_company_code_st type cmds_ei_company,
    wa_company_code type cmds_ei_cmd_company,
    wa_customer type cmds_ei_extern,
    wa_customers type cmds_ei_main,
    wa_address type bapiad1vl,
    wa_addressx type bapiad1vlx,
    wa_central_data type cmds_ei_vmd_central_data,
    wa_central_datax type cmds_ei_vmd_central_data_xflag,
    wa_error type cvis_message.
    constants c_update type c value 'M'.
    start-of-selection.
      free: wa_customer, wa_company_code_st, wa_customer.
      wa_company_code_st-task = c_update.
      wa_company_code_st-data_key-bukrs = 'A105'.
      wa_address-name = 'Nombre Cliente'.
      wa_address-country = 'MX'.
      wa_address-langu = 'E'.
      wa_address-time_zone = 'UTC-6'.
      wa_customer-central_data-address-postal-data = wa_address.
      wa_customer-central_data-address-postal-datax = wa_addressx.
      wa_customer-central_data-central-data-ktokd = '0200'.
      wa_customer-central_data-central-datax-ktokd = 'X'.
      append wa_company_code_st to wa_company_code-company.
      wa_customer-header-object_instance-kunnr = '0300002832'.
      wa_customer-header-object_task = c_update.
      wa_customer-company_data = wa_company_code.
      append wa_customer to wa_customers-customers.
      call method cmd_ei_api=>maintain_bapi
      exporting
      is_master_data = wa_customers
      importing
       es_message_correct = wa_error.
      if wa_error-is_error is initial.
        commit work.
      endif.
    Regards,
    Blanca Segovia

  • Create Contact Person via BAPI / CMD_EI_API (TCode VAP1)

    Hi everybody,
    I have to develop a function module, which has to be called from an external application (java). This function module should, create contact persons for customers (like Transaction VAP1 does).
    I did not find any function module or bapi for this, but I found class CMD_EI_API, which seems to possibly help me. Unfortunately, there is no documentation for this class.
    Could anyone help me getting the contact person's addresses into the system? Just hustle me into the right direction and I will walk by myself
    Thank you very much
    Ralf
    Edit: The contact persons addresses have to be maintained for existing customers.
    Edited by: Ralf Wenzel on Feb 21, 2012 12:19 PM

    I have this working.  I wrote a wrapper BAPI.  If inserting a new contact, you need to get a new partner number otherwise it won't work.  There is extra code in this function module that you can remove.  I left it as I used the logic for other customer update BAPIs.
    FUNCTION Z_CUSTOMER_CONTACT.
    *"*"Local Interface:
    *"  IMPORTING
    *"     VALUE(CUST) LIKE  ZCUSTOMER STRUCTURE  ZCUSTOMER
    *"     VALUE(TESTFLAG) LIKE  WDL_FLAG-XFLAG DEFAULT ' '
    *"     VALUE(FBAPI) TYPE  CHAR01 OPTIONAL
    *"     VALUE(CONTACT) LIKE  ZCONTACT STRUCTURE  ZCONTACT
    *"  EXPORTING
    *"     VALUE(CUSTOMERNO) LIKE  BAPIKNA103-CUSTOMER
    *"     VALUE(RETURN) LIKE  BAPIRETURN1 STRUCTURE  BAPIRETURN1
    *"  EXCEPTIONS
    *"      CLIENT_ERROR
    *"      KNA1_INCOMPLETE
    *"      KNB1_INCOMPLETE
    *"      KNB5_INCOMPLETE
    *"      KNVV_INCOMPLETE
    *"      KUNNR_NOT_UNIQUE
    *"      SALES_AREA_NOT_UNIQUE
    *"      SALES_AREA_NOT_VALID
    *"      INSERT_UPDATE_CONFLICT
    *"      NUMBER_ASSIGNMENT_ERROR
    *"      NUMBER_NOT_IN_RANGE
    *"      NUMBER_RANGE_NOT_EXTERN
    *"      NUMBER_RANGE_NOT_INTERN
    *"      ACCOUNT_GROUP_NOT_VALID
    *"      PARNR_INVALID
    *"      BANK_ADDRESS_INVALID
    *"      TAX_DATA_NOT_VALID
    *"      NO_AUTHORITY
    *"      COMPANY_CODE_NOT_UNIQUE
    *"      DUNNING_DATA_NOT_VALID
    *"      KNB1_REFERENCE_INVALID
    *"      CAM_ERROR
       data: wa_header          type cmds_ei_header,
             wa_central_data    type cmds_ei_vmd_central_data,
             wa_central_datax   type cmds_ei_vmd_central_data_xflag,
             wa_address         type bapiad1vl,
             wa_addressx        type bapiad1vlx,
             wa_contact_addr    type bapiad3vl,
             wa_contact_addrx   type BAPIAD3VLX,
             wa_tax_ind_st      type cmds_ei_tax_ind,
             wa_tax_ind         type cmds_ei_cmd_tax_ind,
             wa_bankdetail_st   type cvis_ei_cvi_bankdetail,
             wa_bankdetail      type cvis_ei_bankdetail,
             wa_company_code_st type cmds_ei_company,
             wa_company_code    type cmds_ei_cmd_company,
             wa_functions_st    type cmds_ei_functions,
             wa_functions       type cmds_ei_cmd_functions,
             wa_tcontact        type CVIS_EI_PHONE,
             wa_phone_st        type CVIS_EI_PHONE_STR,
             wa_phone           type CVIS_EI_CVI_PHONE,
             wa_fcontact        type CVIS_EI_FAX,
             wa_fax_st          type CVIS_EI_FAX_STR,
             wa_fax             type CVIS_EI_CVI_FAX,
             wa_econtact        type CVIS_EI_SMTP,
             wa_smtp_st         type CVIS_EI_SMTP_STR,
             wa_smtp            type CVIS_EI_CVI_SMTP,
             wa_sales_data_st   type cmds_ei_sales,
             wa_sales_data      type cmds_ei_cmd_sales,
             wa_customer        type cmds_ei_extern,
             wa_cust_created    type cmds_ei_extern,
             is_customers       type cmds_ei_main,
             es_customers       type cmds_ei_main,
             wa_correct         type cmds_ei_main,
             wa_defective       type cmds_ei_main,
             wa_mes_correct     type cvis_message,
             wa_mes_error       type cvis_message,
             it_contacts        type cmds_ei_contacts_t,
             wa_contacts        type CMDS_EI_CONTACTS,
             messages           type BAPIRET2_T.
       FIELD-SYMBOLS: <bapiret2> type BAPIRET2.
       DATA: STATUS TYPE CHAR20,
             PARNR  LIKE KNVK-PARNR.
       constants: FILLCHAR VALUE '/',
                  gc_objtype_customer TYPE mds_ctrl_object VALUE 'CUSTOMER',
                  gc_insert           TYPE c VALUE 'I',
                  gc_delete           TYPE c VALUE 'D',
                  gc_current_state    TYPE c VALUE 'C',
                  gc_update           TYPE c VALUE 'U',
                  gc_true             TYPE c VALUE 'X',
                  gc_false            TYPE c VALUE ' '.
       include fbgenmac.
    * generate data record
       fbgenmac 'Z_CUSTOMER_CONTACT'.
    * Clear memory variables - needed if run in Test mode
    * Initialization
       CALL METHOD cmd_ei_api=>initialize.
       wa_customer-header-object_instance-kunnr = cust-kunnr.
       wa_customer-header-object_task           = gc_update.
       append wa_customer to is_customers-customers.
       call method CMD_EI_API_EXTRACT=>get_data
         EXPORTING
           is_master_data = is_customers
         IMPORTING
           es_master_data = es_customers
           es_error       = wa_mes_error.
       IF wa_mes_error-is_error is initial.
         STATUS = 'OK'.
         LOOP at es_customers-customers into wa_cust_created.
           wa_company_code = wa_cust_created-company_data.
           IF STATUS = 'OK' and wa_mes_error-is_error is INITIAL.
    *      is_customers = es_customers.
             free: wa_customer, wa_company_code_st,
                   wa_company_code, wa_address, wa_sales_data_st,
                   wa_contacts, wa_contact_addr,
                   wa_sales_data, wa_tax_ind_st, wa_functions,
                   wa_functions_st, wa_correct, wa_mes_correct,
                   wa_defective, wa_mes_error, wa_cust_created,
                   wa_tcontact, wa_phone_st, wa_phone,
                   wa_fcontact, wa_fax_st, wa_fax, wa_econtact,
                   wa_smtp_st, wa_smtp.
             FREE: is_customers.
             IF CONTACT-FIRSTNAME IS NOT INITIAL.
               CALL FUNCTION 'NUMBER_GET_NEXT'
                 EXPORTING
                   nr_range_nr                   = 'AP'
                   object                        = 'PARTNER'
                   QUANTITY                      = '1'
                   SUBOBJECT                     = ' '
    *           TOYEAR                        = '0000'
    **          IGNORE_BUFFER                 = ' '
                 IMPORTING
                   NUMBER                        = PARNR
    *           QUANTITY                      =
    *           RETURNCODE                    =
                EXCEPTIONS
                   INTERVAL_NOT_FOUND            = 1
                   NUMBER_RANGE_NOT_INTERN       = 2
                   OBJECT_NOT_FOUND              = 3
                   QUANTITY_IS_0                 = 4
                   QUANTITY_IS_NOT_1             = 5
                   INTERVAL_OVERFLOW             = 6
                   BUFFER_OVERFLOW               = 7
                   OTHERS                        = 8.
               IF SY-SUBRC = 0.
    * Add partner type 20
                 wa_contacts-task           = gc_insert.
                 wa_contacts-data_key-parnr = PARNR.
                 wa_contacts-data-pafkt     = '20'.
                 wa_contacts-datax-pafkt    = 'X'.
    *        wa_contacts-address_type_1 = ''.
    *        wa_contacts-address_type_2 = ''.
    *        wa_contact_addr-fullname   = CUST-NAME.
                 wa_contact_addr-firstname  = CONTACT-FIRSTNAME.
                 wa_contact_addrx-firstname = 'X'.
                 wa_contact_addr-lastname   = CONTACT-LASTNAME.
                 wa_contact_addrx-lastname  = 'X'.
    * Assign address data directly
                 wa_contacts-address_type_3-task  = gc_insert.
                 wa_contacts-address_type_3-postal-data  = wa_contact_addr.
                 wa_contacts-address_type_3-postal-datax = wa_contact_addrx.
    * e-mail address
                 wa_econtact-task = gc_insert.
                 wa_econtact-data-std_no = 'X'.
                 wa_econtact-data-e_mail = CONTACT-E_MAIL.
    *        wa_econtact-datax-std_no = 'X'.
    *        wa_econtact-datax-e_mail = 'X'.
                 wa_smtp-current_state = ' '.
                 wa_smtp_st-contact = wa_econtact.
                 append wa_smtp_st to wa_smtp-smtp.
                 wa_contacts-address_type_3-communication-smtp = wa_smtp.
    *        wa_contacts-contact_texts  = ''.
                 append wa_contacts to it_contacts.
               ENDIF.
               CALL FUNCTION 'NUMBER_GET_NEXT'
                 EXPORTING
                   nr_range_nr                   = 'AP'
                   object                        = 'PARTNER'
                   QUANTITY                      = '1'
                   SUBOBJECT                     = ' '
    *           TOYEAR                        = '0000'
    **          IGNORE_BUFFER                 = ' '
                 IMPORTING
                   NUMBER                        = PARNR
    *           QUANTITY                      =
    *           RETURNCODE                    =
                EXCEPTIONS
                   INTERVAL_NOT_FOUND            = 1
                   NUMBER_RANGE_NOT_INTERN       = 2
                   OBJECT_NOT_FOUND              = 3
                   QUANTITY_IS_0                 = 4
                   QUANTITY_IS_NOT_1             = 5
                   INTERVAL_OVERFLOW             = 6
                   BUFFER_OVERFLOW               = 7
                   OTHERS                        = 8.
               IF SY-SUBRC = 0.
    * Add partner type 30
                 wa_contacts-data_key-parnr = parnr.
                 wa_contacts-data-pafkt     = '30'.
                 append wa_contacts to it_contacts.
               ENDIF.
    * Assign contacts to customer structure
               wa_customer-central_data-contact-contacts = it_contacts.
    * Set object_task to modify
               wa_customer-header-object_instance-kunnr = cust-kunnr.
               wa_customer-header-object_task = gc_update.
               append wa_customer to is_customers-customers.
               IF FBAPI = 'X'.
    * MAINTAIN_BAPI seems to now work.  Fills in table addr_appl_to_int used in function module
    * ADDR_MEMORY_SAVE line 631.  It should be blank.
                 call method cmd_ei_api=>maintain_bapi
                   EXPORTING
                     iv_test_run              = TESTFLAG
                     iv_collect_messages      = 'X'
                     is_master_data           = is_customers
                   IMPORTING
                     es_master_data_correct   = wa_correct
                     es_message_correct       = wa_mes_correct
                     es_master_data_defective = wa_defective
                     es_message_defective     = wa_mes_error.
               ELSE.
                 call method cmd_ei_api=>maintain
                   EXPORTING
                     iv_test_run    = TESTFLAG
                     is_master_data = is_customers
                   IMPORTING
                     es_error       = wa_mes_error.
               ENDIF.
               IF wa_mes_error-is_error is initial.
                 if testflag <> 'X'.
                   commit work and wait.
                   LOOP at wa_correct-customers into wa_cust_created.
                     CUSTOMERNO = wa_cust_created-header-object_instance-kunnr.
                     SY-MSGID = 'F2'.
                     SY-MSGNO = '056'.     " Failure
                     SY-MSGV1 = ''.
                     SY-MSGV2 = ''.
                     SY-MSGV3 = ''.
                     SY-MSGV4 = ''.
                     CALL FUNCTION 'BALW_BAPIRETURN_GET1'
                       EXPORTING
                         TYPE       = 'E'
                         CL         = SY-MSGID
                         NUMBER     = SY-MSGNO
                         PAR1       = SY-MSGV1
                         PAR2       = SY-MSGV2
                         PAR3       = SY-MSGV3
                         PAR4       = SY-MSGV4
    *               LOG_NO     = ' '
    *               LOG_MSG_NO = ' '
                       IMPORTING
                         BAPIRETURN = RETURN.
                   ENDLOOP.
                   CALL FUNCTION 'ADDR_MEMORY_CLEAR'
                     EXPORTING
                       force              = 'X'
                     EXCEPTIONS
                       unsaved_data_exist = 1
                       internal_error     = 2
                       others             = 3.
                 ELSE.
                   ROLLBACK WORK.
                   LOOP at wa_correct-customers into wa_cust_created.
                     CUSTOMERNO = wa_cust_created-header-object_instance-kunnr.
                     SY-MSGID = 'F2'.
                     SY-MSGNO = '035'.
                     SY-MSGV1 = ''.
                     SY-MSGV2 = ''.
                     SY-MSGV3 = ''.
                     SY-MSGV4 = ''.
                     CALL FUNCTION 'BALW_BAPIRETURN_GET1'
                       EXPORTING
                         TYPE       = 'E'
                         CL         = SY-MSGID
                         NUMBER     = SY-MSGNO
                         PAR1       = SY-MSGV1
                         PAR2       = SY-MSGV2
                         PAR3       = SY-MSGV3
                         PAR4       = SY-MSGV4
    *               LOG_NO     = ' '
    *               LOG_MSG_NO = ' '
                       IMPORTING
                         BAPIRETURN = RETURN.
                   ENDLOOP.
                   CALL FUNCTION 'ADDR_MEMORY_CLEAR'
                     EXPORTING
                       force              = 'X'
                     EXCEPTIONS
                       unsaved_data_exist = 1
                       internal_error     = 2
                       others             = 3.
                 ENDIF.
               ELSE.
                 messages = wa_mes_error-messages.
                 LOOP at wa_mes_error-messages assigning <bapiret2>.
                   CUSTOMERNO = CUST-KUNNR.
                   CALL FUNCTION 'BALW_BAPIRETURN_GET1'
                     EXPORTING
                       TYPE       = <bapiret2>-type
                       CL         = <bapiret2>-id
                       NUMBER     = <bapiret2>-number
                       PAR1       = <bapiret2>-message_v1
                       PAR2       = <bapiret2>-message_v2
                       PAR3       = <bapiret2>-message_v3
                       PAR4       = <bapiret2>-message_v4
    *         LOG_NO     = ' '
    *         LOG_MSG_NO = ' '
                     IMPORTING
                       BAPIRETURN = RETURN.
                 ENDLOOP.
               ENDIF.
             ELSE.
               CUSTOMERNO = CUST-KUNNR.
               SY-MSGID = 'F2'.
               SY-MSGNO = '152'.     " Failure
               SY-MSGV1 = CUST-KUNNR.
               SY-MSGV2 = CUST-BUKRS.
               SY-MSGV3 = ''.
               SY-MSGV4 = ''.
               CALL FUNCTION 'BALW_BAPIRETURN_GET1'
                 EXPORTING
                   TYPE       = 'E'
                   CL         = SY-MSGID
                   NUMBER     = SY-MSGNO
                   PAR1       = SY-MSGV1
                   PAR2       = SY-MSGV2
                   PAR3       = SY-MSGV3
                   PAR4       = SY-MSGV4
    *         LOG_NO     = ' '
    *         LOG_MSG_NO = ' '
                 IMPORTING
                   BAPIRETURN = RETURN.
             ENDIF.
           ENDIF.
         ENDLOOP.
       ELSE.
         CUSTOMERNO = CUST-KUNNR.
         SY-MSGID = 'F2'.
         SY-MSGNO = '077'.     " Failure
         SY-MSGV1 = CUST-NAME.
         SY-MSGV2 = ''.
         SY-MSGV3 = ''.
         SY-MSGV4 = ''.
         CALL FUNCTION 'BALW_BAPIRETURN_GET1'
           EXPORTING
             TYPE       = 'E'
             CL         = SY-MSGID
             NUMBER     = SY-MSGNO
             PAR1       = SY-MSGV1
             PAR2       = SY-MSGV2
             PAR3       = SY-MSGV3
             PAR4       = SY-MSGV4
    *         LOG_NO     = ' '
    *         LOG_MSG_NO = ' '
           IMPORTING
             BAPIRETURN = RETURN.
       ENDIF.
    ENDFUNCTION.

  • Create customer date trough class cmd_ei_api - error in test run

    Hi all,
    I try to use class cmd_ei_api to create customer. It works fine but one thing is strange.
    When I pass data with test run and customer is in a group with internal nummering system icrease number every time when i run program. Customer is not created ( that is good) but the assigned nummer is lost.
    I tried to use method maintain_bapi and maintain.Problem occurs every time.
    Do you have the same problem?  Do you know solution of this problem?
    regards,
    JG
    SAMPLE CODE:
    report zcreate_customer.
    data: wa_header          type cmds_ei_header,
          wa_central_data    type cmds_ei_vmd_central_data,
          wa_central_datax   type cmds_ei_vmd_central_data_xflag,
          wa_address         type bapiad1vl,
          wa_addressx        type bapiad1vlx,
          wa_tax_ind_st      type cmds_ei_tax_ind,
          wa_tax_ind         type cmds_ei_cmd_tax_ind,
          wa_bankdetail_st   type cvis_ei_cvi_bankdetail,
          wa_bankdetail      type cvis_ei_bankdetail,
          wa_company_code_st type cmds_ei_company,
          wa_company_code    type cmds_ei_cmd_company,
          wa_functions_st    type cmds_ei_functions,
          wa_functions_t     type CMDS_EI_FUNCTIONS_T,
          wa_functions       type cmds_ei_cmd_functions,
          wa_sales_data_st   type cmds_ei_sales,
          wa_sales_data      type cmds_ei_cmd_sales,
          wa_customer        type cmds_ei_extern,
          wa_customers       type cmds_ei_main,
          wa_correct         type cmds_ei_main,
          wa_defective       type cmds_ei_main,
          wa_mes_correct     type cvis_message,
          wa_mes_error       type cvis_message.
    constants: c_update type c value 'M',
               c_insert type c value 'I'.
    PARAMETERS: p_test type c as CHECKBOX DEFAULT 'X'.
    start-of-selection.
      free: wa_customer, wa_company_code_st, wa_customer.
      wa_address-name       = 'CUSTOMER NAME'.
      wa_address-city       = 'CITY'.
      wa_address-postl_cod1 = '28-500'.
      wa_address-street     = '1400 9TH ST W'.
      wa_address-country    = 'PL'.
      wa_address-langu      = 'L'.
    wa_address-region     = 'FL'.
      wa_address-sort1      = 'SORT1'.
      wa_address-sort2      = 'Sort2'.
    Assign address data directly
      wa_customer-central_data-address-postal-data = wa_address.
      wa_addressx-name       = 'X'.
      wa_addressx-city       = 'X'.
      wa_addressx-postl_cod1 = 'X'.
      wa_addressx-street     = 'X'.
      wa_addressx-country    = 'X'.
      wa_addressx-langu      = 'X'.
      wa_addressx-region     = 'X'.
      wa_addressx-sort1      = 'X'.
      wa_addressx-sort2      = 'X'.
    wa_customer-central_data-address-postal-datax = wa_addressx.
      wa_customer-central_data-central-data-ktokd = 'OKRA'.
      wa_customer-central_data-central-data-STCD1 = '8291004247'.
      wa_company_code_st-task           = c_insert.
      wa_company_code_st-data_key-bukrs = '1000'.
      wa_company_code_st-data-zuawa     = '009'.
      wa_company_code_st-data-akont     = '0000201100'.
      append wa_company_code_st to wa_company_code-company.
      append wa_customer to wa_customers-customers.
      call method cmd_ei_api=>maintain_bapi
        EXPORTING
          iv_test_run         = p_test
          iv_collect_messages = 'X'
          is_master_data      = wa_customers
        IMPORTING
          es_master_data_correct   = wa_correct
          es_message_correct       = wa_mes_correct
          es_master_data_defective = wa_defective
          es_message_defective     = wa_mes_error.
      if wa_mes_error-is_error is initial and p_test is INITIAL.
        commit work AND WAIT.
      else.
        ROLLBACK work.
      endif.

    Hi experts, I am using cmd_ei_api to create customer. Each time when I create the customer, for the customer number KUNNR, first the method picks a new number from number range, if I don't supply one in program. Then it makes the necessary checks on customer data. If data check is success, customer is created and everything is okay. But if the check is failed, no customer gets created in the Data base, but the picked number is lost forever. Is there a way to avoid this?
          The same happens, even when I ran it in Test Mode(iv_test_run = 'X'). A number is lost irrespective of whether the test run is success or not.
          I tried supplying the customer number via the program. I this case also, I had to get a number from the Number Range and supply. As the Method validates whether the supplied number belongs to the right number range, I cannot use any dummy number(not even for a Test run). Also it validates whether a customer exists in KNA1 with the supplied number.
          As a work around, now I am supplying the last number of the number range for the test run(which I have hard coded ~not a good practice!!). If this runs error free, I will pick a new number and creates the customer.
    regards,
    anish
    sample code...
    *-- Fill customer parameters to lwa_master_data
    lwa_customer-header-object_instance-kunnr  = '99999'.
    * *** ~~
    *-- Test Run with dummy customer no. for data check
        IF lwa_master_data IS NOT INITIAL.
           CALL METHOD cmd_ei_api=>maintain
             EXPORTING
               iv_test_run    = 'X'
               is_master_data = lwa_master_data
             IMPORTING
               es_error       = lwa_es_error.
    *-- Create customer if Test Run Succeeds.
          IF lwa_es_error is INITIAL.
    *-- Get new Customer Number
           CALL METHOD cmd_ei_api=>get_number
             EXPORTING
               iv_ktokd = as_customer-ktokd
             IMPORTING
               ev_kunnr = lv_kunnr
               es_error = lwa_getno_msg.
           IF lv_kunnr is NOT INITIAL.
    *-- Supply new customer number
             CLEAR: lwa_master_data, lt_customer.
             lwa_customer-header-object_instance-kunnr = lv_kunnr.
             APPEND lwa_customer TO lt_customer.
             CLEAR lwa_customer.
             lwa_master_data-customers = lt_customer.
    *-- Initialize Global and Current Customer Buffer
             CALL METHOD cmd_ei_api=>initialize.
    *-- Create Customer
             CALL METHOD cmd_ei_api=>maintain
               EXPORTING
                 iv_test_run    = ''
                 is_master_data = lwa_master_data
               IMPORTING
                 es_error       = lwa_es_error.
    *-- Proceed if no error with customer creation
             IF lwa_es_error is INITIAL.
    * ******************* * ******************* ~~

  • CMD_EI_API usage for maintaining AR customers

    We are able to successfully create customers for AR using the CMD_EI_API=>maintain_bapi method. However we are having trouble updating existing customers with new addresses or bank information. Is there any limitation on what fields can be updated on the customer master using this interface ? In most scenarios, no errors and no updates are occurring.
    regards
    Sandesh Ghawghawe

    Hi Sandesh,
    for sure there are limitation with that API.
    But the description of your difficulty does not look like related to such limitation.
    Maybe the bank. Within the newest EhP releases, the Bank functionality has been enhanced with the support of the bank account without number (related to IBAN).
    Maintenance of standard customer bank account should be supported properly.
    One of the common issue with this API is when you forget to maitain the DATAX structure accordingly to the DATA structure.
    As a result, nothing gets maintained.
    Maybe this is your trouble.
    Don't forget also the COMMIT or BAPI_COMMIT
    BR
    Alain

  • Populating the table ISJPHIERARCHY (Invoice Summary for Japan)

    Hi All,
    I have a requirement, where  need to update the table ISJPHIERARCHY , which is the invoice summary for Japan table.
    Can you please let me know if there is  any BADI, Function module to updating this table at the time of Customer Creation.
    I am able to create a customer using the API CMD_EI_API=>maintain_bapi.
    However , I could not find a suitable method/badi to populate the invoice sumamry.
    <removed by moderator> any help will be highly appreciated <removed by moderator>.
    Thanks,
    Sandeep
    Edited by: Thomas Zloch on Aug 4, 2011 12:57 PM

    Hi Paul,
    Thank you so much for taking an interest.
    My problem might seem stupid to all the advanced users - but I had to start somewhere.
    After reading pretty much all the posts and help-files I’m more confused then ever …
    Well then, here we go.
    I attached my form and for better understanding what it will later look like a sample data file.
    I do appreciate and eagerly await any tips, hints, help, sample code and what ever I can get.
    Thanks again
    Jixin
    (just to be safe the second pdf should include the sample data ...)

  • Method MAINTAIN_BAPI of CMD_EI_API does not populate Tcode 'BP'

    Hello SAP Experts,
    We are using method MAINTAIN_BAPI of Class CMD_EI_API to create Customer in ECC using SAP Portal through a form.
    When the Customer Details are added on the Form in the Portal and the Form is submitted, the MAINTAIN_BAPI method is called and the relevant structures used in it are populated.
    The Customer gets created appropriately in ECC(verified through Tcode XD03) and Entries are populated in the various Customer (KN*) Database tables in ECC.
    But when the Customer is displayed using Tcode 'BP' , its details are not displayed.
    In other words, although the Customer thus created can be seen using Tcode 'BP', its data in the various sections for eg. the Address Section are not populated in this Transaction.
    However, after this if any change is made to the newly created Customer in XD02, like updating the Customer Name, the Customer Details miraculously show up when the Customer is displayed again using the BP Transaction code.
    Please advise what is missing here. Thanks in advance for your help.
    Best Regards,
    Damian

    Hi Damian,
    I realise this is quite an old thread, but did you ever figure out what was causing the issue?  I'm currently facing a very similar issue.
    Thanks.
    Regards,
    Tammie

  • Creation of Customer master using CLASS( 'MAINTAIN_BAPI')..

    I am creating customer master by class 'MAINTAIN_BAPI'.  So all fields are sucessfully created except the field 'Remarks / Comments' on customer..Please suggest for the same as far as posiible..
    << Moderator message - Everyone's problem is important. But the answers in the forum are provided by volunteers. Please do not ask for help quickly. >>
    Edited by: Rob Burbank on Jul 18, 2011 10:06 AM

    Hi Yogesh,
    Hi,
    sorry to reply after the message closure.
    Maybe you will read it.
    SD_CUSTOMER_MAINTAIN_ALL is used in standard during the maintenance of a consumer using the standard customer master data transaction XD01 & XD02.
    It is not intended to be used out of the transaction and in no case it should be used out of its original context. Due to the specificity of the function module, out of the original context we may face limitations and data inconsistencies.
    For the maintenance of customers, there is NO BAPI and NO direct function module.
    There are some functions modules like the one above where the name is looking nice. But these should not be used.
    BAPI_CUSTOMER_CREATEFROMDATA1 is part of them. This one uses SD_CUSTOMER_MAINTAIN_ALL, so the above remark is still valid. Moreover, this BAPI is to be used only from process  SAP Product Catalog. Out of it and due to its limitation, a lot of troubles are expected.
    Sorry.
    Below ECC 2005 (6.00), the only solution was batch input and DEBMAS idocs. See [note 384462|https://service.sap.com/sap/support/notes/384462]
    Starting with ECC 2005 (6.00) and above: a synchronisation tool has been introduce. See class CMD_EI_API and VMD_EI_API
    Hope this helps.
    BR
    Alain

  • Need A Code For CMD_EI_API

    Hi All,
    I used the class CMD_EI_API and method MAINTAIN_BAPI in my report to create a customer master data (data uploaded from the excelsheet which is  already has the customer number ) ,its not showing any messages and not even updating the table if anybody has the code ,kindly reply .
    Thanks in advance .
    Regards,
    Jyoti
    Edited by: Jyotigkk on Sep 15, 2010 4:19 PM
    Edited by: Jyotigkk on Sep 15, 2010 4:32 PM

    You should use a commit work after the method.
    Please read the method documentation once.
    it says
    The system only processes the data if the data records have been entered completely and correctly
    If you do not create the first data record correctly, the system cannot create the following data records

  • Create Customer SD_CUSTOMER_MAINTAIN_ALL or CMD_EI_API

    Hi,
    I'm trying to create a function that makes it possible to create customers like in XD01.
    I read in the forum that the function module SD_CUSTOMER_MAINTAIN_ALL shouldn't be used for that.
    Is that correct?
    I read also that I should use the Class CMD_EI_API with method MAINTAIN_BAPI. But when I try to create a customer I get the error: Mandatory partner role is missing for sales area 0003 01 05
    Does anybody knwo what I'm missing in here?
    Best regards,
    Dennis

    Dennis Junker wrote:>
    > Hi,
    >
    > thanks for the reply. I found the mandantory partner functions and tried to add them.
    > but I got now some other errors regarding invalid partners.
    > I think the settings getting picked up by T770D regarding to the Account Group.
    >
    > But it is weird that I also get errors now with some "Requiered" Date Fields that can be left blank in XD01.
    >
    > The BAPI "BAPI_CUSTOMER_CREATEFROMDATA" doesn't support me with enough input I have to add and SD_CUSTOMER_MAINTAIN_ALL does not do any checks at all. But as CMD_EI_API causes a lot of trouble I might still go for the bapi and do reimplement the important checks myself.
    >
    > Or is there any better way to create the customers. The endpurpose is a small Web Dynpro application with just a few of the feilds from XD01.
    Customer creation is always a pain in the neck when it comes to do that in background. You need to pass all the required fields to BAPI .
    Let me tell you about the checks.... you can implement the BADI to do checks for you instead of doing on your own.
    Yes, you need to pass the account group like is it one time cusotmer or there are some entries in table T077D (KNA1-KTOKD).
    Let me know if you need any further help on this.

  • CMD_EI_API usage together with KNVV append

    Hello,
    I am trying to use class CMD_EI_API for customer maintenance, especially updating the sales view.
    I don't find a way to pass data to a KNVV append fields .
    Is this a known limitation or does anybody know a workround .
    P.S. Working with SD_CUSTOMER_MAINTAIN_ALL seems to meet this requirement.
    Regards
    Wolfgang Schildmann

    Hello Wolfgang,
    Despite the name SD_CUSTOMER_MAINTAIN_ALL should not be used directly.     
    It is only used from the main transaction for maintenance of consumers     
    and within some very specific processes.                                   
    Unfortunately, we do not have any BAPI for such maintenance.               
    There exists some BAPIs but they are designed for very specific            
    maintenance processes.                                                     
    Please look at note 384462. There you will find what is available.         
    This is mainly batch-input processing and ALE.                                                                               
    Alternatively, as you already mentioned you may look at class CMD_EI_API and methods MAITAIN,       
    MAINTAIN_BAPI, and MAINTAIN_DIRECT_INPUT.                                  
    This is supported class and you can fully maintain customer master         
    data.                                                                      
    Please note that it is only available starting with release ECC 2005.      
    I hope I was able to help you.
    Kind regards,
    Zsuzsanna

  • CMD_EI_API and ENQUEUE_EXKNA1 fail to block customer

    <p>Dear SAP gurus and fellow programmers,</p>
    <p>I have been exploring how to block customers by examining the code that is executed in transaction XD02. I have been able to block and unblock customers using an ABAP objects class, CMD_EI_API, but only when I execute it directly from transaction SE24. If I call the method from my own code, the client does not block or unblock. I've checked my code, and it is identical to the code in several standard transactions.</p>
    <p>Note: I can't sucessfully block the customer for "all company codes". I can block it sucessfully for orders, delivery, billing and sales.</p>
    <p>I gave up in this approach and decided to uses the ENQUEUE_EXKNA1 and DEQUEUE_EXKNA1 functions. Once again, if I run the XD02 transaction, the block/unblock succeeds. If I run it from my own function module, even though the code was directly copied from the standard tranasction, it fails. I know the ENQUEUE and DEQUEUE functions are executed by XD02, because I set breakpoints on them to learn how they work.</p>
    <p>Here is my code, copied from SAPs: </p>
    DATA: lv_msgtext(72),<br>
             ls_bapiret2      TYPE bapiret2,<br>
             lv_user          TYPE symsgv,<br>
             ls_syst          TYPE syst,<br>
             ls_error         TYPE cvis_message,<br>
             lv_in_lock_table TYPE boolean,<br>
             lb_badi_lock     TYPE REF TO cmd_additional_locks.<br>
    <br>
    <br>
    * Initialize exporting parameter<br>
      CLEAR:<br>
        ls_error.<br>
    <br>
    * Check internal table gt_lock_kunnr whether KUNNR is locked<br>
      CALL METHOD cmd_ei_api=>get_lock<br>
        EXPORTING<br>
          iv_kunnr         = p_kunnr<br>
        IMPORTING<br>
          ev_in_lock_table = lv_in_lock_table.<br>
    <br>
    * KUNNR is locked already, back to caller<br>
      IF lv_in_lock_table = 'X'.<br>
        RETURN.<br>
      ENDIF.<br>
    <br>
    * KUNNR is not locked, try to lock......<br>
      CALL FUNCTION 'ENQUEUE_EXKNA1'<br>
        EXPORTING<br>
          mode_kna1      = 'E' "mode_kna1<br>
          mandt          = sy-mandt<br>
          kunnr          = p_kunnr<br>
          x_kunnr        = space "x_kunnr<br>
          _scope         = 2 "_scope<br>
          _wait          = space "_wait<br>
          _collect       = space "_collect<br>
        EXCEPTIONS<br>
          foreign_lock   = 1<br>
          system_failure = 2<br>
          OTHERS         = 99.<br>
    <br>
    *------- save system variables in structure ls_syst -------------------<br>
      ls_syst = sy.<br>
    <br>
      CASE sy-subrc.<br>
        WHEN 0.<br>
    *     do nothing<br>
        WHEN 1.<br>
          lv_user = sy-msgv1.<br>
          ls_error-is_error = 'X'.<br>
          MESSAGE e042(f2) WITH p_kunnr lv_user INTO lv_msgtext.<br>
          ls_bapiret2 = cvi_ei_api=>tool_fill_bapiret2( ).<br>
          APPEND ls_bapiret2 TO ls_error-messages.<br>
    *------- fill system variables with original values -------------------<br>
          sy = ls_syst.                                       "#EC WRITE_OK<br>
          IF sy-msgid IS NOT INITIAL.<br>
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno<br>
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msgtext.<br>
            ls_bapiret2 = cvi_ei_api=>tool_fill_bapiret2( ).<br>
            APPEND ls_bapiret2 TO ls_error-messages.<br>
          ENDIF.<br>
          RAISE foreign_lock.<br>
        WHEN 2.<br>
          ls_error-is_error = 'X'.<br>
          MESSAGE e038(f2) INTO lv_msgtext.<br>
          ls_bapiret2 = cvi_ei_api=>tool_fill_bapiret2( ).<br>
          APPEND ls_bapiret2 TO ls_error-messages.<br>
    *------- fill system variables with original values -------------------<br>
          sy = ls_syst.                                       "#EC WRITE_OK<br>
          IF sy-msgid IS NOT INITIAL.<br>
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno<br>
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msgtext.<br>
            ls_bapiret2 = cvi_ei_api=>tool_fill_bapiret2( ).<br>
            APPEND ls_bapiret2 TO ls_error-messages.<br>
          ENDIF.<br>
          RAISE system_failure.<br>
        WHEN OTHERS.<br>
          ls_error-is_error = 'X'.<br>
          MESSAGE e001(cmd_api) INTO lv_msgtext.<br>
          ls_bapiret2 = cvi_ei_api=>tool_fill_bapiret2( ).<br>
          APPEND ls_bapiret2 TO ls_error-messages.<br>
          RETURN.<br>
      ENDCASE.<br>
    <br>
    * try to lock only if there are no errors....<br>
    * set lock with BADI cmd_additional_lock<br>
    <br>
      GET BADI lb_badi_lock.<br>
    * call method lock BADI CMD_ADDITIONAL_LOCKS<br>
      CALL BADI lb_badi_lock->lock<br>
        EXPORTING<br>
          iv_kunnr = p_kunnr<br>
        CHANGING<br>
          cs_error = ls_error.<br>
    <br>
    * remove customer-proprietary lock in case of error<br>
      IF ls_error-is_error =  'X'.<br>
        CALL FUNCTION 'DEQUEUE_EXKNA1'<br>
          EXPORTING<br>
            kunnr = p_kunnr.<br>
        raise FOREIGN_LOCK.<br>
      ENDIF.<br>
    <br>
    * add successfully locked customer number<br>
      CALL METHOD cmd_ei_api=>set_lock<br>
        EXPORTING<br>
          iv_kunnr = p_kunnr.<br>
    <br>
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'<br>
    Edited by: Aaron Ortiz on Sep 8, 2009 5:16 PM
    Edited by: Rob Burbank on Sep 8, 2009 11:26 AM

    <p>Dear SAP gurus and fellow programmers,</p>
    <p>I have been exploring how to block customers by examining the code that is executed in transaction XD02. I have been able to block and unblock customers using an ABAP objects class, CMD_EI_API, but only when I execute it directly from transaction SE24. If I call the method from my own code, the client does not block or unblock. I've checked my code, and it is identical to the code in several standard transactions.</p>
    <p>Note: I can't sucessfully block the customer for "all company codes". I can block it sucessfully for orders, delivery, billing and sales.</p>
    <p>I gave up in this approach and decided to uses the ENQUEUE_EXKNA1 and DEQUEUE_EXKNA1 functions. Once again, if I run the XD02 transaction, the block/unblock succeeds. If I run it from my own function module, even though the code was directly copied from the standard tranasction, it fails. I know the ENQUEUE and DEQUEUE functions are executed by XD02, because I set breakpoints on them to learn how they work.</p>
    <p>Here is my code, copied from SAPs: </p>
    DATA: lv_msgtext(72),<br>
             ls_bapiret2      TYPE bapiret2,<br>
             lv_user          TYPE symsgv,<br>
             ls_syst          TYPE syst,<br>
             ls_error         TYPE cvis_message,<br>
             lv_in_lock_table TYPE boolean,<br>
             lb_badi_lock     TYPE REF TO cmd_additional_locks.<br>
    <br>
    <br>
    * Initialize exporting parameter<br>
      CLEAR:<br>
        ls_error.<br>
    <br>
    * Check internal table gt_lock_kunnr whether KUNNR is locked<br>
      CALL METHOD cmd_ei_api=>get_lock<br>
        EXPORTING<br>
          iv_kunnr         = p_kunnr<br>
        IMPORTING<br>
          ev_in_lock_table = lv_in_lock_table.<br>
    <br>
    * KUNNR is locked already, back to caller<br>
      IF lv_in_lock_table = 'X'.<br>
        RETURN.<br>
      ENDIF.<br>
    <br>
    * KUNNR is not locked, try to lock......<br>
      CALL FUNCTION 'ENQUEUE_EXKNA1'<br>
        EXPORTING<br>
          mode_kna1      = 'E' "mode_kna1<br>
          mandt          = sy-mandt<br>
          kunnr          = p_kunnr<br>
          x_kunnr        = space "x_kunnr<br>
          _scope         = 2 "_scope<br>
          _wait          = space "_wait<br>
          _collect       = space "_collect<br>
        EXCEPTIONS<br>
          foreign_lock   = 1<br>
          system_failure = 2<br>
          OTHERS         = 99.<br>
    <br>
    *------- save system variables in structure ls_syst -------------------<br>
      ls_syst = sy.<br>
    <br>
      CASE sy-subrc.<br>
        WHEN 0.<br>
    *     do nothing<br>
        WHEN 1.<br>
          lv_user = sy-msgv1.<br>
          ls_error-is_error = 'X'.<br>
          MESSAGE e042(f2) WITH p_kunnr lv_user INTO lv_msgtext.<br>
          ls_bapiret2 = cvi_ei_api=>tool_fill_bapiret2( ).<br>
          APPEND ls_bapiret2 TO ls_error-messages.<br>
    *------- fill system variables with original values -------------------<br>
          sy = ls_syst.                                       "#EC WRITE_OK<br>
          IF sy-msgid IS NOT INITIAL.<br>
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno<br>
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msgtext.<br>
            ls_bapiret2 = cvi_ei_api=>tool_fill_bapiret2( ).<br>
            APPEND ls_bapiret2 TO ls_error-messages.<br>
          ENDIF.<br>
          RAISE foreign_lock.<br>
        WHEN 2.<br>
          ls_error-is_error = 'X'.<br>
          MESSAGE e038(f2) INTO lv_msgtext.<br>
          ls_bapiret2 = cvi_ei_api=>tool_fill_bapiret2( ).<br>
          APPEND ls_bapiret2 TO ls_error-messages.<br>
    *------- fill system variables with original values -------------------<br>
          sy = ls_syst.                                       "#EC WRITE_OK<br>
          IF sy-msgid IS NOT INITIAL.<br>
            MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno<br>
            WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4 INTO lv_msgtext.<br>
            ls_bapiret2 = cvi_ei_api=>tool_fill_bapiret2( ).<br>
            APPEND ls_bapiret2 TO ls_error-messages.<br>
          ENDIF.<br>
          RAISE system_failure.<br>
        WHEN OTHERS.<br>
          ls_error-is_error = 'X'.<br>
          MESSAGE e001(cmd_api) INTO lv_msgtext.<br>
          ls_bapiret2 = cvi_ei_api=>tool_fill_bapiret2( ).<br>
          APPEND ls_bapiret2 TO ls_error-messages.<br>
          RETURN.<br>
      ENDCASE.<br>
    <br>
    * try to lock only if there are no errors....<br>
    * set lock with BADI cmd_additional_lock<br>
    <br>
      GET BADI lb_badi_lock.<br>
    * call method lock BADI CMD_ADDITIONAL_LOCKS<br>
      CALL BADI lb_badi_lock->lock<br>
        EXPORTING<br>
          iv_kunnr = p_kunnr<br>
        CHANGING<br>
          cs_error = ls_error.<br>
    <br>
    * remove customer-proprietary lock in case of error<br>
      IF ls_error-is_error =  'X'.<br>
        CALL FUNCTION 'DEQUEUE_EXKNA1'<br>
          EXPORTING<br>
            kunnr = p_kunnr.<br>
        raise FOREIGN_LOCK.<br>
      ENDIF.<br>
    <br>
    * add successfully locked customer number<br>
      CALL METHOD cmd_ei_api=>set_lock<br>
        EXPORTING<br>
          iv_kunnr = p_kunnr.<br>
    <br>
    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'<br>
    Edited by: Aaron Ortiz on Sep 8, 2009 5:16 PM
    Edited by: Rob Burbank on Sep 8, 2009 11:26 AM

Maybe you are looking for