Application Development 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: 

create sales order using 'BAPI_SALESORDER_CREATEFROMDAT1'

Former Member
0 Kudos

Hi,

Here is the code below


*-------------------------Data Declaration-----------------------------*
DATA: st_bapisdhead LIKE bapisdhead, " Sales Order Header Data
      ta_bapiitemin LIKE bapiitemin OCCURS 0 WITH HEADER LINE, " Ln item
      ta_bapipartnr LIKE bapipartnr OCCURS 0 WITH HEADER LINE, " Partner
      d_bapireturn1 LIKE bapireturn1, " Bapi return msg
      d_vbeln LIKE bapivbeln-vbeln. " Sales Order Number

* Move the data to create sales order in the repective parameters------*
MOVE: 'TA' TO st_bapisdhead-doc_type, " Sales document type
      '15493' TO st_bapisdhead-purch_no_c,
      '00010' TO ta_bapiitemin-itm_number,
      'Y-351' TO ta_bapiitemin-material,
      '1100' TO ta_bapiitemin-plant,
      '1' TO ta_bapiitemin-req_qty,
      'AG' TO ta_bapipartnr-partn_role, " Sold to Party
      '0000007777' TO ta_bapipartnr-partn_numb.

* Append the internal tables-------------------------------------------*
APPEND ta_bapipartnr.
CLEAR ta_bapipartnr.
APPEND ta_bapiitemin.
CLEAR ta_bapiitemin.

* Move ship to party---------------------------------------------------*
MOVE: 'RG' TO ta_bapipartnr-partn_role, " Ship to party
      '0000007777' TO ta_bapipartnr-partn_numb.

* Append the internal tables-------------------------------------------*
APPEND ta_bapipartnr.
CLEAR ta_bapipartnr.


* Call the Bapi to create the sales order
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
EXPORTING
order_header_in = st_bapisdhead
* WITHOUT_COMMIT = ' '
* CONVERT_PARVW_AUART = ' '
IMPORTING
salesdocument = d_vbeln
* SOLD_TO_PARTY =
* SHIP_TO_PARTY =
* BILLING_PARTY =
return = d_bapireturn1
TABLES
order_items_in = ta_bapiitemin
order_partners = ta_bapipartnr
* ORDER_ITEMS_OUT =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CCARD =
* ORDER_CFGS_BLOB =
* ORDER_SCHEDULE_EX =
.

IF d_vbeln <> space.
  WRITE: 'Sales order No. ', d_vbeln.
ELSE.
  WRITE: 'No data'.
ENDIF.

Why there is no sales order had been created after running this report?

Thanks a lot.

Best Regards,

Stephanie

Edited by: Stephanie HE on Jul 21, 2008 12:17 PM

1 ACCEPTED SOLUTION

Former Member
0 Kudos

hi

run bapi

BAPI_BPCONTACT_SAVEFROMMEMORY

after 'BAPI_SALESORDER_CREATEFROMDAT1'

it will return sales activity number.

Regards

Aditya

13 REPLIES 13

Former Member
0 Kudos

hi,

use commit work command after calling bapi.

reward if helpful

0 Kudos

Hi, Khusro Habib

Thanks a lot.

I add COMMIT WORK after the calling BAPI, but after running it, still "no data".

Best Regards,

Stephanie

0 Kudos

Hi,

Have you checked the RETURN table to see if you are getting any error messages?

0 Kudos

Hi,

Did u checked the return table for any errors?

If there are any errors then order will not be created. Put a break point at this FM, After calling the BAPI check the return table. If no errors then do database commit.

Instead of COMMIT WORK call FM

BAPI_TRANSACTION_COMMIT.

Thanks,

Vinod.

Edited by: Vinod Reddy Vemuru on Jul 21, 2008 4:13 PM

Former Member
0 Kudos

hi

run bapi

BAPI_BPCONTACT_SAVEFROMMEMORY

after 'BAPI_SALESORDER_CREATEFROMDAT1'

it will return sales activity number.

Regards

Aditya

0 Kudos

Hi, Aditya

I run BAPI_BPCONTACT_SAVEFROMMEMORY after call BAPI_SALESORDER_CREATEFROMDAT1

The code is as follow:


DATA : it_bapi_vbka_boidref LIKE bapi_vbka_boidref OCCURS 0 WITH HEADER LINE,
           it_bapiret2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

CALL FUNCTION 'BAPI_BPCONTACT_SAVEFROMMEMORY'
  TABLES
    salesactivityidout = li_bapi_vbka_boidref
    return             = li_bapiret2.

Still no sales order has been created.

Is that because the syntax is wrong or any other reason?

Thanks a lot.

Best Regards,

Stephanie

Edited by: Stephanie HE on Jul 21, 2008 12:40 PM

0 Kudos

>

> Hi, Aditya

>

> I run BAPI_BPCONTACT_SAVEFROMMEMORY after call BAPI_SALESORDER_CREATEFROMDAT1

>

> The code is as follow:

>

>


> DATA : it_bapi_vbka_boidref LIKE bapi_vbka_boidref OCCURS 0 WITH HEADER LINE,
>            it_bapiret2 LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
> 
> CALL FUNCTION 'BAPI_BPCONTACT_SAVEFROMMEMORY'
>   TABLES
>     salesactivityidout = li_bapi_vbka_boidref
>     return             = li_bapiret2.
> 

>

> Still no sales order has been created.

>

> Is that because the syntax is wrong or any other reason?

>

> Thanks a lot.

>

> Best Regards,

> Stephanie

>

> Edited by: Stephanie HE on Jul 21, 2008 12:40 PM

Stephanie,

BAPI_BPCONTACT_SAVEFROMMEMORY has nothing to do with your problem - you don't need to call it after BAPI_SALESORDER_CREATE...

Usually you should call your BAPI to create the sales order then check the return table to see if any errors have occurred - if they haven't then you should call BAPI_TRANSACTION_COMMIT.

I'm guessing you have an error with your data somewhere that is stopping the document from being created.

Gareth.

0 Kudos

Stephanie,

BAPI_BPCONTACT_SAVEFROMMEMORY has nothing to do with your problem - you don't need to call it after BAPI_SALESORDER_CREATE...

Usually you should call your BAPI to create the sales order then check the return table to see if any errors have occurred - if they haven't then you should call BAPI_TRANSACTION_COMMIT.

I'm guessing you have an error with your data somewhere that is stopping the document from being created.

Gareth.

Hi, Gareth

Could you tell me how to check the return table?

Thanks a lot!

Best Regards,

Stephanie

0 Kudos

>

> Hi, Gareth

>

> Could you tell me how to check the return table?

>

> Thanks a lot!

>

> Best Regards,

> Stephanie

Hi,

The easiest way is to simply debug through the code and check the entry in the RETURN parameter after you have called the BAPI_SALESORDER_CREATE. I'm hoping there will be an entry in that parameter that might explain why your document is not saving.

One question, why are you using BAPI_SALESORDER_CREATEFROMDAT1 and not BAPI_SALESORDER_CREATEFROMDAT2 ?

Gareth.

0 Kudos

Hi,

The easiest way is to simply debug through the code and check the entry in the RETURN parameter after you have called the BAPI_SALESORDER_CREATE. I'm hoping there will be an entry in that parameter that might explain why your document is not saving.

One question, why are you using BAPI_SALESORDER_CREATEFROMDAT1 and not BAPI_SALESORDER_CREATEFROMDAT2 ?

Gareth.

Hi, Gareth

Thanks for your help, I got the error message from the RETURN parameter.

The code is not mine, I got it from internet, it using BAPI_SALESORDER_CREATEFROMDAT1, so what is the difference between these two?

Best Regards,

Stephanie

0 Kudos

Hi Stephanie,

Basically, it is just a newer, more up to date version of the same functionality. I'd recommend always using the latest version of a given BAPI if SAP have released newer versions.

Specifically to your problem, the newer version has a table for RETURN so you can get multiple errors (if they exist) in one call and not have to test the BAPI, fix one error, test again, fix again, etc... It also has a flag which enables you to save the document even if there are some errors which have also helped in your scenario.

I'd suggest replacing your call to version 1 with code to call the latest version.

Gareth.

Former Member
0 Kudos

Hi,

Uncommend this line --> Value give Space.

WITHOUT_COMMIT = ' '.

'10' TO st_bapisdhead-distr_chan,

'10' TO st_bapisdhead-division,

'AG1' TO st_bapisdhead-sales_grp,

'1902' TO st_bapisdhead-sales_off,

Add in header details.

And

loop at pe_return1.

write / return1-MESSAGE.

endloop.

Here u will get the return message.

Try this.......

Reward if useful.

Thanks,

Durai.V

Edited by: Durai V on Jul 21, 2008 12:40 PM

Former Member
0 Kudos

Hi

You have to run bapi

BAPI_BPCONTACT_SAVEFROMMEMORY

which returns you the document number

Aditya