Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Creating New Customer - BAPI_CUSTOMER_CREATEFROMDATA1

andrewscott9
Participant
0 Likes
5,671

Hi there,

I am writing some code which uses the BAPI_CUSTOMER_CREATEFROMDATA1

to create a new customer.

However, when running the code I get the following error:

Internal error: Refe. customer does not exist in master record

Which suggests that the customer no I am passing to the BAPI does not exist.

But the customer number will not exist because I am trying to create it !

I'm obviously missing a step somewhere?

Any ideas anyone

Thanks

Andy

1 ACCEPTED SOLUTION
Read only

0 Likes
4,682

Hi Andy,

As per the SAP Note 390045 - Usage of BAPI_CUSTOMER_* of function group V02D, there is a danger that you will lose data if you use the FM BAPI_CUSTOMER_CREATEFROMDATA1 outside of SAP online store.

Instead of this FM, we have a method called as CMD_EI_API=>MAINTAIN_BAPI to create/ update a customer without any reference.

Using this method, you can create/ update the general data, company code data and Sales area data without any issues.

23 REPLIES 23
Read only

Former Member
0 Likes
4,682

Hi andy,

Please try to see FM'long text,and you will get more infomations.

Regards.

Read only

0 Likes
4,682

Thanks for the reply , but the long text is blank when I run the program in debug mode.

Andy

Read only

0 Likes
4,682

Hi andy,

The long text that i mentioned is import/export parameter's.


The usage of each  parameter was introduced in long text.

Regards.

Read only

Former Member
0 Likes
4,682

Hi Andy,

Did You try not passing PI_COPYREFERENCE structure ? This , I think , is reference customer to create new customer.

Best regards,

Shanmukh

Read only

0 Likes
4,682

Hi,

Yep using the copyref :

e.g. copyref-ref_custmr           = 'CRM1379345'.

Read only

0 Likes
4,682

Does this Customer exist ?

Read only

0 Likes
4,682

Hi ,

No the customer does not exist

Read only

0 Likes
4,682

Hi,

It will give error for obvious reasons. You're passing a reference customer to BAPI which is not even created.

BAPI is trying to create new customer by copying the reference customer passed by you. Hence the error.

Read only

0 Likes
4,682

Pass an existing customer as reference , so that the new customer is created copying appropriate fields from ref. customer.

Read only

0 Likes
4,682

Also, the new customer number will be generated and returned in exporting parameters of the BAPI.

Read only

0 Likes
4,682

Hi many thanks for the reply.

The problem I have got is that I need to pass into the BAPI the customer number

I need creating. In my example I need 'CRM1379345' creating.

I know you can do this via transaction XD01. There must be a way of doing the same

with the BAPI??

Thanks

Andy

Read only

0 Likes
4,682

Hi Andy,

Customer number is internally generated by SAP. Even in XD01, you pass all the required fields , like customer information and after saving SAP generates the Customer number for you. You cannot create a customer with predetermined Customer number.

Best regards,

Shanmukh

Read only

0 Likes
4,682

Hi,

Isn't this based on a 'customising setting' ?

Isn't it possible to activate 'external numbering' ?

I think you should check with a functional person.

I know this is possible for some objects, but I'm not 100% sure that this is the case for BP's

Regards,

Read only

0 Likes
4,683

Hi Andy,

As per the SAP Note 390045 - Usage of BAPI_CUSTOMER_* of function group V02D, there is a danger that you will lose data if you use the FM BAPI_CUSTOMER_CREATEFROMDATA1 outside of SAP online store.

Instead of this FM, we have a method called as CMD_EI_API=>MAINTAIN_BAPI to create/ update a customer without any reference.

Using this method, you can create/ update the general data, company code data and Sales area data without any issues.

Read only

0 Likes
4,682

I'm still a little confused with this.

One of our functional people has just created a customer in XD01 by entering the

the customer  'CRM1379345'. The one I was trying to create.

The transaction worked and the customer was created.

I should be able to replicate this in the BAPI ??

Thanks

Andy

Read only

0 Likes
4,682

Hi Andy,

Just Ask your functional Consultant weather Customer creation number range is Internal or External. If it is External which i don't think most company prefers , than you have to pass Customer number in Bapi and also you have to pass reference Customer Number in Bapi  (Note Reference Customer should be already created and exist in system) . If it is internal number range than no need to pass customer number in Bapi but you can pass reference customer number to create new customer by taking reference another customer.

Pass all mandatory parameters. For this you can use below documentation

Tcode : BAPI-> Tab Alphabetical -> Customer -> CreateFromData1 -> Documentation.

Hope this will help.

Regards,

Sagar

Read only

0 Likes
4,682

Many thanks for your reply Sagar, much appreciated.

I have just checked and we are using external number range.

So am I correct that I need to pass the ref cust i.e. BAPIKNA102-REF_CUSTMR which

is a customer previously created ?

And also pass the customer number in which I need created?

If this is the case I cant see where to pass the customer number that I need creating.

That make sense?

Read only

0 Likes
4,682

Hi Andy,

Yes you are right I just go through this bapi. It seems that to create the customer using bapi, you have to use internal number range. Because there is no option to pass external number range.

You can ask your functional consultant to do it ones and you can test it. If it will work then you might go with this approach.

Or if it is strict to use external number range then you can use BDC. It will be only approach.

Regards,

Sagar

Read only

Former Member
0 Likes
4,682

Hi Andy,

You can switch on logging for synchronous calls in PI ( I am assuming the QOS is BE in your case) and see if the request payload to the RFC adapter is getting framed correctly.

Read only

andrewscott9
Participant
0 Likes
4,682

Many thanks for the replies and suggestions.

I'm going down the route of creating a BDC session with my code. I couldn't find a solution

with the BAPI

Thanks

Andy

Read only

0 Likes
4,682

Hi Andy,

As is often the case with relatively straight forward questions here on SCN, you have managed to obtain a number of random and to some extent irrelevant answers, suggestions and comments, that have probably confused things a little.  Having read through this thread, here are some pertinent points IMHO that you should consider:-

  • The initial error was because you were passing a reference customer into the BAPI, which was then trying to copy it to create your new one.  As you confirmed later in the discussion, the reference customer you were specifying didn't actually exist and hence as a few people said this is the obvious answer to why you got the error.
  • You said you need to pass in the number of the customer - this is what is known as external numbering, i.e. SAP itself does not automatically generate a new number for each consecutive customer by using number-ranges.  As mentioned here, internal vs. external numbering is configurable against most SAP data objects.
  • Specifying the number of the new customer is NOT the same as specifying the number of a reference customer to copy.  If your system is set to use external numbering, you will have to specify the new customer number - whether you also choose to specify a reference customer to copy from is up to you.
  • Using BDC instead of BAPI is always a last resort - have you exhausted all options, by searching on SCN for BAPI to create a customer, or maybe have you just tried to run the BAPI's already mentioned by specifying the new customer number but NOT specifying a reference customer number to copy?  I've no personal experience with BAPI_CUSTOMER_CREATEFROMDATA1 however a quick glance suggests that it doesn't appear to have the option to add an external number, only copy from an existing reference customer so this doesn't sound like what you are trying to achieve.
  • As an aside, if you are looking for the logical BAPI that SAP suggests could be used for CRUD operations against business objects, it is always worth using the BOR (Business Object Repository) or transaction SWO1 to do some investigation.

Hope some of this helps,

G.

Read only

0 Likes
4,682

Hi Gareth,

Many thanks for your reply. I really appreciate your comments.

As usual with SCN like you say there are always some silly suggestions !!

I have used BDC before in the past with uploads of various kinds. I was just trying

out something different for a change but failed miserably.

As this is just a one off upload I couldn't afford to spend any more research on this so

I went with the tried and tested method. I have now got it working.

Thanks again

Andy

Read only

0 Likes
4,682

Don't forget that with the new SAPgui, BCD is not a 100% fullproof option either.

Some 'features' in the new releases are not supported by BCD.

So it always depends on the situation and requirements.

An addtional advantage of using a BAPI is that fact that, when for example customising is modified later on, the BAPI will remain working, while maybe the BCD needs to be adapted to handle the modified process (dynpro sequence)