Example: Creating a Customer Master Record via an IDoc 

A model VB project SENDIDOC.VBP for calling the BAPI_Customer_CreateFromData BAPI of the object type Customer ( KNA1 ) via an IDoc is stored in the ...\SAPforms\Samples directory. This method is used to create a customer master record in the R/3 System.

Process Flow

To use this example, you need to carry out the following steps:

  1. Generate an IDoc. Generating an IDoc
  2. Enter KNA1 as the BOR obejct and the method Createfromdata .

    Enter your message type: Customercreate

  3. Define the partner profile and port. Defining a Partner Profile and Port
  4. Enter Createcust in the Partner number field.

    Name your port Portcucr .

    Enter $Tmp (local object) as the development class.

  5. Start Visual Basic and load the SENDIDO.VBP project from the ...\SAPforms\Samples directory.

The IDoc structure is displayed in the top control. The form controls are shown in the table displayed in the bottom control. The binding is already defined and generated. The steps for Maintaining Plug-Ins and Opening a Structure and Defining and Generating a Binding, therefore, have been completed.

All of the segment attributes required to execute the BAPI are listed in the table below:

Name

Segment Attribute

Values

Name

E1BPKNA101000.NAME

Any

First name

E1BPKNA101000.FIRST_NAME

Any

Street

E1BPKNA101000.STREET

Any

Postal code

E1BPKNA101000.POSTL_CODE

5-digit number

City

E1BPKNA101000.CITY

Any

Reference customer

E1BPKNA102000.REF_CUSTMR

"*"

Country

E1BPKNA101000.COUNTRY

US"*"

Language

E1BPKNA101000.LANGU

US

Sales organization

E1BPKNA102000.SALESORG

"*"

Division

E1BPKNA102000.DIVISION

"*"

Distribution channel

E1BPKNA102000.DISTR_CHAN

"*"

Not all attributes are filled by the form. Instead, they are filled with initial values in the background by an import routine in VB code. These values are stored in the CUSTOMER.TXT file in the directories ..\SAPforms\Samples or ...\SAPforms\Forms. It is important that the file is in the same directory as the EXE file read for this purpose.

It concerns the data for state, reference customer sales organization, division and distribution channel ("*"). Except for state this data is system-specific and must be determined separately. In order for the example to work, you must maintain the appropriate data for your system in the file CUSTOMER.TXT . See also: Determining a Reference Customer.

Modify the VB code. Define and generate binding

This has already been done in our example.

  1. Test your form by choosing Run in Visual Basic or compile and start an EXE file.
  2. Enter meaningful data (see above) and choose Execute. You are then logged on to your R/3 System automatically. After a short period of time, the message sendidoc "The IDoc has been sent successfully" is displayed.

This means that the IDoc generated by the form was successfully sent to the R/3 System.