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

BAPI_SALESORDER_CREATEFROMDAT2

Former Member
0 Likes
2,414

Dear All,

I am using BAPI_SALESORDER_CREATEFROMDAT2 to create the sales order, in this I am facing some issue can any one help me this to overcome this issue.

When I try to create the Sales order using the mentioned BAPI the Salses order number is getting created but the amount, the net price and Net value is getting as zero, as if I am passing cond type(ZPRT) and cond value(amount) in the condition stucrure it’s giving me the error like “Condition ZPRT is not allowed as header condition” sales order is not getting created but If comment condition structure then Sales order is getting created.

I have given the code which I have written please guide where I am going wrong. Please give me possible solution

CONSTANTS : c_set VALUE 'X',

c_max_items TYPE i VALUE '300',

  • c_cond_type LIKE bapiitemin-cond_type VALUE 'ZPRT',

c_cond_type LIKE BAPICOND-COND_TYPE VALUE 'ZPRT',

c_doc_type LIKE bapisdhead-doc_type VALUE 'ZRET',

c_sales_org LIKE bapisdhead-sales_org VALUE '2000',

c_distr_chan LIKE bapisdhead-distr_chan VALUE 'RT',

c_division LIKE bapisdhead-division VALUE 'ZZ',

c_partn_role LIKE bapipartnr-partn_role VALUE 'AG'.

&----


*& Form create_sales_orders

&----


  • Creating the Sales orders.

----


FORM create_sales_orders .

data: vamt type P decimals 3 .

*Local Data Declarations.

DATA : l_vbeln LIKE bapivbeln-vbeln,

  • lfl_return LIKE BAPIRET2, "bapireturn1

p_return_txt(100),

l_req_qty(14),

l_quan LIKE vbap-kwmeng,

l_date LIKE sy-datum,

l_fg VALUE 'X',

n_count TYPE i VALUE 0,

lfl_order_header_in LIKE BAPISDHD1 OCCURS 0 WITH HEADER LINE, "bapisdhead

order_header_inx like BAPISDHD1X OCCURS 0 WITH HEADER LINE,

lit_temp_upload LIKE vit_upload OCCURS 0 WITH HEADER LINE,

  • lit_order_items_in LIKE bapiitemin OCCURS 0 WITH HEADER LINE,

lit_order_items_in LIKE BAPISDITM OCCURS 0 WITH HEADER LINE,

lit_order_item_inx like BAPISDITMX occurs 0 with header line,

lfl_return LIKE bapiret2 OCCURS 1 WITH HEADER LINE,

lfl_cond_in like BAPICOND OCCURS 0 WITH HEADER LINE,

conditions_inx like bapicondx OCCURS 0 with header line, "BAPICONDX

li_order_schedules_in LIKE bapischdl OCCURS 1 WITH HEADER LINE,

lit_order_partners LIKE BAPIPARNR OCCURS 0 WITH HEADER LINE.

order_header_inx-updateflag = 'I'.

lfl_order_header_in-doc_type = c_doc_type. "ZRET

lfl_order_header_in-sales_org = c_sales_org. "2000

order_header_inx-SALES_ORG = 'X'.

lfl_order_header_in-distr_chan = c_distr_chan. "RT

order_header_inx-distr_chan = 'X'.

lfl_order_header_in-division = c_division."ZZ

order_header_inx-division = 'X'.

*Formatting the Data uploaded.

PERFORM format_data.

*Simulating the Sales Orders to be created.

IF NOT Px_TEST IS INITIAL.

PERFORM sales_order_simulate.

ENDIF.

sort vit_upload by kunnr po_no po_date.

*Performing the Actual Creation if the Test Flag is not set.

IF px_test IS INITIAL.

clear Vit_upload.

LOOP AT vit_upload.

*Counting the number of Line items.

n_count = n_count + 1.

  • ON CHANGE OF vit_upload-kunnr or vit_upload-po_no or vit_upload-po_date.

AT NEW kunnr.

l_fg = c_set.

ENDAT.

AT NEW PO_NO.

l_fg = c_set.

ENDAT.

AT NEW PO_DATE.

l_fg = c_set.

ENDAT.

  • endon.

*Populating the Sold-To Party.

IF NOT l_fg IS INITIAL.

REFRESH: lit_order_partners,

lit_order_items_in.

CLEAR: lfl_order_header_in-PURCH_NO_C, "purch_no

lfl_order_header_in-purch_date,

lit_order_partners,

lit_order_items_in.

lit_order_partners-partn_role = c_partn_role.

lit_order_partners-partn_numb = vit_upload-kunnr.

APPEND lit_order_partners. CLEAR lit_order_partners.

CLEAR l_fg.

ENDIF.

CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'

EXPORTING

date_external = vit_upload-po_date

IMPORTING

date_internal = l_date

EXCEPTIONS

date_external_is_invalid = 1

OTHERS = 2.

*Populating the Header Details.

lfl_order_header_in-PURCH_NO_C = vit_upload-po_no.

lfl_order_header_in-doc_date = l_date.

lfl_order_header_in-purch_date = l_date.

order_header_inx-PURCH_NO_C = 'X'.

order_header_inx-DOC_TYPE = 'X'.

append lfl_order_header_in.

APPEND order_header_inx.

*Populating the Item Details.

lit_order_item_inx-UPDATEFLAG = 'I'.

l_quan = vit_upload-quan.

l_req_qty = l_quan.

lit_order_items_in-material = vit_upload-matnr.

lit_order_item_inx-material = 'X'.

  • lit_order_items_in-PURCH_NO_C = vit_upload-po_no.

  • lit_order_items_in-PURCH_DATE = l_date.

lit_order_items_in-RNDDLV_QTY = l_req_qty.

lit_order_items_in-sales_unit = vit_upload-vrkme.

  • lit_order_items_in-PMNTTRMS = c_cond_type.

lit_order_items_in-PYMT_METH = c_cond_type.

  • lit_order_item_inx-PYMT_METH = 'X'.

lit_order_items_in-TARGET_VAL = vit_upload-amount / 10.

lit_order_item_inx-TARGET_VAL = 'X'.

lit_order_items_in-EXCHG_RATE = vit_upload-amount.

lit_order_item_inx-EXCHG_RATE = 'X'.

lit_order_items_in-EX_RATE_FI = vit_upload-amount.

lit_order_item_inx-EX_RATE_FI = 'X'.

lit_order_item_inx-SALES_UNIT = 'X'.

APPEND lit_order_items_in. CLEAR lit_order_items_in.

.

APPEND lit_order_item_inx. CLEAR lit_order_item_inx.

li_order_schedules_in-req_qty = l_req_qty.

append li_order_schedules_in.

  • appending condition type records.

lfl_cond_in-cond_type = c_cond_type.

vamt = vit_upload-amount / 10.

  • lfl_cond_in-CONDVALUE = vamt.

lfl_cond_in-cond_value = vamt.

lfl_cond_in-CURRENCY = 'AED'.

*CONDITIONS_INX-CONDVALUE = 'X'.

CONDITIONS_INX-UPDATEFLAG = ' '.

CONDITIONS_INX-COND_VALUE = 'X'.

*CONDITIONS_INX-COND_TYPE = C_cond_type.

CONDITIONS_INX-CURRENCY = 'X'.

append lfl_cond_in. CLEAR lfl_cond_in.

append conditions_inx.clear conditions_inx.

**

*

*Setting the Flag for a particular Sold-to Party.

AT END OF kunnr.

l_fg = c_set.

ENDAT.

AT END of PO_NO.

l_fg = c_set.

ENDAT.

AT END of PO_DATE.

l_fg = c_set.

ENDAT.

*

*Setting the Flag if the Count has reached the Maximum number.

IF n_count = c_max_items.

l_fg = c_set.

n_count = 0.

ENDIF.

IF NOT l_fg IS INITIAL.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

  • SALESDOCUMENTIN =

ORDER_HEADER_IN = lfl_order_header_in

ORDER_HEADER_INX = order_header_inx

  • SENDER =

  • BINARY_RELATIONSHIPTYPE =

  • INT_NUMBER_ASSIGNMENT =

  • BEHAVE_WHEN_ERROR =

  • LOGIC_SWITCH =

  • TESTRUN =

  • CONVERT = ' '

IMPORTING

SALESDOCUMENT = l_vbeln

TABLES

RETURN = lfl_return

ORDER_ITEMS_IN = lit_order_items_in

ORDER_ITEMS_INX = lit_order_item_inx

ORDER_PARTNERS = lit_order_partners

ORDER_SCHEDULES_IN = li_order_schedules_in

  • ORDER_SCHEDULES_INX =

ORDER_CONDITIONS_IN = lfl_cond_in

ORDER_CONDITIONS_INX = CONDITIONS_INX

*

  • PARTNERADDRESSES =

.

.

READ TABLE lfl_return WITH KEY type = 'E'.

IF sy-subrc = 0.

  • Update log

LOOP AT lfl_return .

lw_return-type = lfl_return-type.

lw_return-id = lfl_return-id.

lw_return-MESSAGE = lfl_return-message.

lw_return-number = lfl_return-number.

lw_return-message_v1 = lfl_return-message_v1.

lw_return-message_v2 = lfl_return-message_v2.

lw_return-message_v3 = lfl_return-message_v3.

lw_return-message_v4 = lfl_return-message_v4.

Append lw_return. "Level 2.

ENDLOOP.

else.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

IMPORTING

return = lfl_return.

vit_success-vbeln = l_vbeln.

vit_success-kunnr = vit_upload-kunnr.

APPEND vit_success.CLEAR vit_success.

ENDIF.

*

*Populating the Error Table in case of Errors.

IF l_vbeln IS INITIAL OR

lfl_return-type = 'E' OR

lfl_return-type = 'A'.

LOOP AT lit_order_items_in.

READ TABLE vit_error

WITH KEY kunnr = vit_upload-kunnr

bstnk = lfl_order_header_in-pURCH_NO_C "purch_no

bstdk = lfl_order_header_in-purch_date

matnr = lit_order_items_in-material.

IF sy-subrc <> 0.

vit_error-message = lfl_return-message.

vit_error-kunnr = vit_upload-kunnr.

vit_error-bstnk = lfl_order_header_in-PURCH_NO_C. "purch_no.

vit_error-bstdk = lfl_order_header_in-purch_date.

vit_error-matnr = lit_order_items_in-material.

vit_error-kwmeng = lit_order_items_in-TARGET_QTY. "req_qty.

vit_error-kwmeng = lit_order_items_in-TARGET_QTY / 1000.

vit_error-kbetr = lit_order_items_in-EX_RATE_FI * 10.

APPEND vit_error.CLEAR vit_error.

ENDIF.

ENDLOOP.

ELSE.

*Populating the Success Table in case Sales Order is Created.

vit_success-vbeln = l_vbeln.

vit_success-kunnr = vit_upload-kunnr.

APPEND vit_success.CLEAR vit_success.

ENDIF.

ENDIF.

ENDLOOP.

ENDIF.

ENDFORM. " create_sales_orders

2 REPLIES 2
Read only

Former Member
838

I have a pricing / incompletion problem with this BAPI. The incompletion procedure for the sales line item has the field VBAP-NETWR (Net value).

Now in a two line order, the second line has a defined list price. But we are passing the price directly from the BAPI itself. For the first line we see the line item created with manual PB00 price. The second line is also created but with both list and manual price and only manual price is active. This is what we want, no problems with this so far.

The problem is incompletion log shows net value missing for first line item which had only manual pricing. When users go to the order, change qty, press enter and reenter quantity; the problem disappears. The problem also disappears when they delete PB00 price,press enter and reenter PB00 price. But because of this incompletion log net value problem, the document cannot be processed further. I checked at table level and VBAP-NETWR is populated but still incompletion log shows no net value.

We have used or_logic_switch-cond_handl = 'X'.

Also

or_conditions_inx-itm_number = itm_number.

or_conditions_inx-cond_type = 'PB00'.

or_conditions_inx-updateflag = space.

or_conditions_inx-cond_value = 'X'.

or_conditions_inx-currency = 'X'.

append or_conditions_inx.

What is the problem here?

Read only

Former Member
0 Likes
838

Sorry double post.

Edited by: Andy S on Jan 8, 2009 5:40 PM