BAPI_SALESORDER_CREATEFROMDAT2 - Pricing
Hello.
I create a Sales Order with reference to a contract by using function module BAPI_SALESORDER_CREATEFROMDAT2.
Now I want to take over the Pricing Coditions from the contract independent the amount (target_qty).
I play a lot with the import parameter logic_switch from the function module. As well I fill the conditions tables for bapi different.
Maybe my coding could help you.
I want to know what i have to do for the takeover of the contract conditions.
FUNCTION z_block_hours.
""Local Interface:
*" IMPORTING
*" REFERENCE(I_WQMSM) LIKE WQMSM STRUCTURE WQMSM
*" REFERENCE(I_VIQMEL) LIKE VIQMEL STRUCTURE VIQMEL
*" EXPORTING
*" VALUE(E_SUBRC) LIKE SY-SUBRC
*" TABLES
*" E_PROTOCOL STRUCTURE RQEVP
DATA: lv_contract TYPE vbeln_va,
ls_order_view TYPE order_view,
ls_partner TYPE bapiparnr,
ls_header_bapi TYPE bapisdhd1,
ls_headerx_bapi TYPE bapisdhd1x,
ls_headerx_ch TYPE BAPISDH1x,
ls_item TYPE bapisditm,
ls_itemx TYPE bapisditmx,
ls_schedule_bapi TYPE bapischdl,
ls_schedulex_bapi TYPE bapischdlx,
ls_condition TYPE bapicond,
ls_condx_bapi TYPE bapicondx,
ls_logic TYPE bapisdls,
ls_header TYPE bapi2080_nothdre,
lt_sales_order TYPE STANDARD TABLE OF sales_key,
lt_header TYPE STANDARD TABLE OF bapisdhd,
lt_item TYPE STANDARD TABLE OF bapisdit,
lt_item_bapi TYPE STANDARD TABLE OF bapisditm,
lt_itemx_bapi TYPE STANDARD TABLE OF bapisditmx,
lt_partner TYPE STANDARD TABLE OF bapisdpart,
lt_condition TYPE STANDARD TABLE OF bapisdcond,
lt_cond_head TYPE STANDARD TABLE OF bapicondhd,
lt_cond_item TYPE STANDARD TABLE OF bapicondit,
lt_cond_bapi TYPE STANDARD TABLE OF bapicond,
lt_condx_bapi TYPE STANDARD TABLE OF bapicondx,
lt_partner_bapi TYPE STANDARD TABLE OF bapiparnr,
lt_schedule_bapi TYPE STANDARD TABLE OF bapischdl,
lt_schedulex_bapi TYPE STANDARD TABLE OF bapischdlx,
lt_return TYPE STANDARD TABLE OF bapiret2.
FIELD-SYMBOLS: <ls_partner> TYPE bapisdpart,
<ls_header> TYPE bapisdhd,
<ls_item> TYPE bapisdit,
<ls_cond> TYPE bapisdcond,
<ls_cond_bapi> TYPE bapicond.
CHECK: i_viqmel-qmart EQ gc_not_type
AND i_wqmsm-aeknz EQ gc_insert.
"get contract
SELECT SINGLE kdauf
FROM viaufkst
INTO lv_contract
WHERE aufnr EQ i_viqmel-aufnr.
IF lv_contract IS INITIAL.
MESSAGE s005(zanx_blockhour).
EXIT.
ENDIF.
CALL SCREEN 0100 STARTING AT 10 5.
APPEND lv_contract TO lt_sales_order.
"Select which information is need
ls_order_view-header = ls_order_view-item
= ls_order_view-partner
= ls_order_view-sdcond
= gc_true.
"Select information from contract
CALL FUNCTION 'BAPISDORDER_GETDETAILEDLIST'
EXPORTING
i_bapi_view = ls_order_view
TABLES
sales_documents = lt_sales_order
order_headers_out = lt_header
order_items_out = lt_item
order_partners_out = lt_partner
order_conditions_out = lt_condition
order_cond_head = lt_cond_head
order_cond_item = lt_cond_item.
"Partner
LOOP AT lt_partner
ASSIGNING <ls_partner>.
MOVE-CORRESPONDING <ls_partner> TO ls_partner.
ls_partner-partn_numb = <ls_partner>-customer.
IF ls_partner-partn_numb IS INITIAL.
ls_partner-partn_numb = <ls_partner>-contact.
ENDIF.
APPEND ls_partner TO lt_partner_bapi.
ENDLOOP.
"Header
READ TABLE lt_header
INDEX 1
ASSIGNING <ls_header>.
MOVE-CORRESPONDING <ls_header> TO ls_header_bapi.
ls_header_bapi-ref_doc = lv_contract.
ls_header_bapi-refdoctype = <ls_header>-sd_doc_cat.
ls_header_bapi-refdoc_cat = <ls_header>-sd_doc_cat.
ls_header_bapi-refobjtype = gc_objtype.
ls_header_bapi-refobjkey = gc_objkey.
ls_header_bapi-doc_type = gc_doctype.
ls_header_bapi-req_date_h = sy-datum.
ls_header_bapi-purch_no_c = <ls_header>-purch_no.
ls_header_bapi-notif_no = i_viqmel-qmnum.
ls_header_bapi-bill_block = gc_bill_block.
CLEAR ls_header_bapi-wbs_elem.
ls_headerx_bapi-doc_type = ls_headerx_bapi-sales_org
= ls_headerx_bapi-distr_chan
= ls_headerx_bapi-division
= ls_headerx_bapi-bill_date
= ls_headerx_bapi-req_date_h
= ls_headerx_bapi-price_date
= ls_headerx_bapi-ref_doc
= ls_headerx_bapi-refdoc_cat
= ls_headerx_bapi-sd_doc_cat
= ls_headerx_bapi-currency
= ls_headerx_bapi-bill_block
= gc_true.
"item
READ TABLE lt_item
ASSIGNING <ls_item>
INDEX 1.
ls_item-refobjtype = gc_objtype.
ls_item-refobjkey = gc_objkey.
ls_item-ref_doc = lv_contract.
ls_item-ref_doc_it = 1.
ls_item-ref_doc_ca = <ls_header>-sd_doc_cat.
ls_item-material = <ls_item>-material.
ls_item-reason_rej = gc_abgru.
"ls_schedule_bapi-req_qty = gv_quan.
ls_schedule_bapi-req_qty = <ls_item>-target_qty.
ls_item-itm_number = ls_itemx-itm_number
= ls_schedule_bapi-itm_number
= ls_schedulex_bapi-itm_number
= 1.
CLEAR: ls_item-item_categ,
ls_item-wbs_elem.
ls_itemx-target_qty = ls_itemx-material
= ls_itemx-short_text
= ls_itemx-sales_unit
= ls_itemx-refobjtype
= ls_itemx-refobjkey
= ls_itemx-ref_doc
= ls_itemx-ref_doc_it
= ls_itemx-ref_doc_ca
= ls_schedulex_bapi-req_qty
= ls_itemx-target_qu
= ls_itemx-reason_rej
= gc_true.
APPEND: ls_item TO lt_item_bapi,
ls_itemx TO lt_itemx_bapi,
ls_schedule_bapi TO lt_schedule_bapi,
ls_schedulex_bapi TO lt_schedulex_bapi.
LOOP AT lt_condition
ASSIGNING <ls_cond>.
ls_condition-itm_number = <ls_cond>-condit_no.
MOVE-CORRESPONDING <ls_cond> TO ls_condition.
+ AT FIRST.+*
+ ls_condition-calctypcon = gc_pricing.+*
+ ls_condition-cond_p_unt = <ls_item>-target_qty.+*
+ ENDAT.+*
*"ls_condition-condvalue = ls_condition-conbaseval * <ls_item>-target_qty.*
APPEND ls_condition TO lt_cond_bapi.
ENDLOOP.
DELETE lt_cond_bapi
WHERE condclass IS INITIAL
OR groupcond IS NOT INITIAL.
LOOP AT lt_cond_bapi
ASSIGNING <ls_cond_bapi>.
ls_condx_bapi-itm_number = <ls_cond_bapi>-itm_number.
ls_condx_bapi-cond_st_no = <ls_cond_bapi>-cond_st_no.
ls_condx_bapi-cond_type = <ls_cond_bapi>-cond_type.
ls_condx_bapi-updateflag = gc_update.
ls_condx_bapi-cond_value = ls_condx_bapi-currency
= gc_true.
APPEND ls_condx_bapi TO lt_condx_bapi.
ENDLOOP.
ls_logic-pricing = gc_pricing. | 'G'
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = ls_header_bapi
order_header_inx = ls_headerx_bapi
logic_switch = ls_logic
IMPORTING
salesdocument = ls_header-sales_ord
TABLES
return = lt_return
order_items_in = lt_item_bapi
order_items_inx = lt_itemx_bapi
order_partners = lt_partner_bapi
order_schedules_in = lt_schedule_bapi
order_schedules_inx = lt_schedulex_bapi
order_conditions_in = lt_cond_bapi
order_conditions_inx = lt_condx_bapi.
READ TABLE lt_return
WITH KEY type = gc_error
TRANSPORTING NO FIELDS.
IF sy-subrc <> 0.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = gc_true.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ENDIF.
ENDFUNCTION.
Thanks for help,
Andrea
News: Now I know that VBAP-VBELV is missing/isn't set. I search know for the suitable parameter for BAPI.
Any ideas?
Greetz.
Edited by: Andrea Salzwedel on Aug 7, 2008 8:38 PM
Hi all.
I forgot to apply the conditions. This and the setting of the correct pricing indicator in parameter LOGIC_SWITCH solved the problem.
Thanks a lot
Salzi
Similar Messages
-
Pricing conditions in BAPI_SALESORDER_CREATEFROMDAT2
hi all,
The Pricing conditions I pass in to the bapi BAPI_SALESORDER_CREATEFROMDAT2 are not picked up for my item.
I'm filling in the
wa_kbetr-itm_number = 'ZRSS'.
wa_kbetr-cond_value = wa_sourcedata-kbetr1.
APPEND wa_kbetr TO it_kbetr.
wa_kbetr-itm_number = 'ZOTB'.
wa_kbetr-cond_value = wa_sourcedata-kbetr2.
APPEND wa_kbetr TO it_kbetr.
fields of the ORDER_CONDITIONS_IN table.
iam getting the error as " Condition is missing in pricing procedure A V ZPCNOT"
I'd appreciate any suggestions.In that check the condition type which u r passing to BAPI is assinged to u r sales org,Dis channel & division combination.
In it not maintianed then this error will come.
No, that's not true...That transaction is for pricing procedure determination by sales area, dcoument indicator and customer indicator but the lack of a condition type there does not trigger this error, ESPECIALLY not 2 different Z-conditions... -
Hi Guys
I need to create a BAPI to create sales orders coming in through a web service from an external system, for normal materials all works well, but for variant config materials the pricing is not happening, like the way it does when I manually create an order, I don't want to manually pass the pricing condition in BAPICOND as I want the BAPI to dynamically determine the conditions from the access sequence.
While debugging VA01 I found that the control goes to the 'PRICING' function module twice, ones for the main material , and next for all its config materials, the second time it calls the 'PRICING' fm with pricing type 'O'. Here it selects the price for all the variant materials and loads into an internal table vkomv and displays in VA01 the variant materials that we select while creating the order, but in the case of the BAPI call, the control is going only to the 'PRICING' fm call for the header.
I have passed 'V' in the application parameter and the variant material in the varcond parameter of the BAPICOND structure.
Any idea what I might be missing ??
Thanks
SameerSolved by reading the following OSS notes
562124 Configuration change via
549563 BAPI: Filling the configuration structures
567348 – Fill configuration via BAPI -
Prevent SO create in BAPI_SALESORDER_CREATEFROMDAT2 if pricing incomplete
Am using BAPI_SALESORDER_CREATEFROMDAT2 to create sale order. I need to prevent the sales order
from being created, if PR00 or like condition does not exist for any material. I have set the required parameters for incompletion procedure (PRSOK etc).
I am unable to save the order when I manually try to create through VA01. But when I use the
above BAPI, the order is saved even when the net value for the material is zero.
Any pointers appreciated.
Thanks,
vinoth.Technically, why don't you check the condition "I need to prevent the sales order
from being created, if PR00 or like condition does not exist for any material." before calling the BAPI.
If the condition fails, do not call BAPI and display message else execute.
If it is related something functional then you may have to handle it in function module.
Regards,
Sharath -
Not able to create sales order using BAPI - BAPI_SALESORDER_CREATEFROMDAT2
Hi Experts,
I am not able to create sales order . I am using BAPI - BAPI_SALESORDER_CREATEFROMDAT2
to create sales order .I am passing external sales order number to the parameter
SALESDOCUMENTIN.
I am getting following error.
"524 |Only quantity 1 EA is allowed (Item 00001"
Here EA is UOM(Unit of measurement).
Below is the sample program through which i am trying to create the sales order.
*& Report ZSDC_SALES_TEST
report zsdc_sales_test.
*DATA: wa_bapi_header TYPE bapisdhd1.
Include Name - ZSDC_SALES_ORD_UPLOAD_TOP
Program Name - ZSDC_SALES_ORD_UPLOAD_1393
Program Title - Include for Data Declaration and selection screen
Created by - Lalitha W
Created on - 18-Nov-2008
Object ID - SD_C_1393_SALES_ORDER_UPLOAD
Request Id - SD3K905579
Description - This is a common INCLUDE for data declarations and
*selection screen details.
HISTORY
Date |Developer |Req by | Description |Reference ID
| | | |
| | | |
TYPE-POOLS
*TYPE-POOLS: truxs, abap, slis.
TABLES
*TABLES: t100.
TYPES
types:begin of ty_header,
auart(4) type c, " Sales Order Type
vkorg(4) type c, " Sales Organization
vtweg(2) type c, " Distrubution Channel
spart(2) type c, " Division
kunnr_1(10) type c, " Sold to Party
kunnr_2(10) type c, " Ship to Party
augru(3) type c, " Order Reason
bstkd(35) type c, " PO Number
bstdk(10) type c, " PO Date
ketdat(10) type c, " Required Delivery Date
zterm(4) type c, " Payment Terms
inco1(3) type c, " Inco Terms -1
inco2(28) type c, " Inco Terms -2
prsdt(10) type c, " pricing date
waerk(5) type c, " Document Currency
vkbur(4) type c, " Sales Office
vkgrp(3) type c, " Sales group
pltyp(2) type c, " Price List type
kdgrp(2) type c, " Customer Group
bstkd_e(35) type c, " Ship-to-party PO number
submi(10) type c, " Collective Number
bname(35) type c, " Name
ihrez(12) type c, " Your Reference
kschl_1(4) type c, " Condition Type
kbetr_1(11) type c, " Amount
kschl_2(4) type c, " Condition Type
kbetr_2(11) type c, " Amount
kschl_3(4) type c, " Condition Type
kbetr_3(11) type c, " Amount
partner_1(25) TYPE c, " Partner(Bill To Party Number)
partner_2(25) TYPE c, " Partner(Payer Number)
partner_3(25) TYPE c, " Partner(Sales Responsible Number)
partner_4(25) TYPE c, " Partner(Order admin)
partner_5(25) TYPE c, " Partner(Contact person)
partner_1(10) type c, " Partner(Bill To Party Number)
partner_2(10) type c, " Partner(Payer Number)
partner_3(10) type c, " Partner(Sales Responsible Number)
partner_4(10) type c, " Partner(Order admin)
partner_5(10) type c, " Partner(Contact person)
tdspras_1(2) type c,
text_1(500) type c, " Text Before Items Z012
tdspras_2(2) type c,
text_2(500) type c, " Invocie Up Z034
tdspras_3(2) type c,
text_3(500) type c, " Invocie Down Z035
tdspras_4(2) type c,
text_4(500) type c, " Customer Reference Continue Z018
tdspras_5(2) type c,
text_5(500) type c, " Dispatch Marks/ Order Z019
tdspras_6(2) type c,
text_6(500) type c, " Ordered By Z003
tdspras_7(2) type c,
text_7(500) type c, " Sales Parameters Z002
kvgr1(3) type c, " Industry
kvgr2(3) type c, " customer BU
end of ty_header.
types: begin of ty_item,
bstkd(35) type c, " PO Number
bstdk(10) type c, " PO Date
bstkd_e(35) type c, " Ship-to-party PO number
posnr(6) type c, " POSTION NUMBER
matnr(18) type c, " Material Number
kwmeng(18) type c, " Order Quantity
pstyv(4) type c, " Sales doc. item categ
kursk(18) type c, " EXCHANGE RATE****
ffprf(8) type c, " DIP PROFILE
werks(4) type c, " Delivering Plant
vstel(4) type c, " SHIPPING POINT
lgort(4) type c, " STORAGE LOCATION
route(6) type c, " Route
kurrf(18) type c, " EXCHANGE RATE-FI
ntgew(18) type c, " Net Weight
brgew(18) type c, " Gross Weight
gewei(3) type c, " Weight Unit
prctr(10) type c, " profit center
abgrs(6) type c, " RESULT ANALYSIS KEY
kalsm_k(4) type c, " COSTING SHEET
kschl_1(4) type c, " Condition Type
kbetr_1(11) type c, " Amount
kschl_2(4) type c, " Condition Type
kbetr_2(11) type c, " Amount
kschl_3(4) type c, " Condition Type
kbetr_3(11) type c, " Amount
text_1(500) type c, " material Text 0001
tdspras_1(1) type c,
text_2(500) type c, " Pr Text 9001
tdspras_2(1) type c,
end of ty_item.
types: begin of ty_schedule_line,
bstkd(35) type c, "PO number
bstdk(10) type c, "PO date
bstkd_e(35) type c, "Ship-to-party PO number
posnr(6) type c, "sales doc.Item
etdat(10) type c, "Schedule line date
wmeng(2) type c, "Order Quantity
end of ty_schedule_line.
types: begin of ty_err ,
auart(4) type c, " Sales Order Type
vkorg(4) type c, " Sales Organization
vtweg(2) type c, " Distrubution Channel
spart(2) type c, " Division
kunnr_1(10) type c, " Sold to Party
kunnr_2(10) type c, " Ship to Party
augru(3) type c, " Order Reason
bstkd(35) type c, " PO Number
bstdk(10) type c, " PO Date
ketdat(10) type c, " Required Delivery Date
zterm(4) type c, " Payment Terms
inco1(3) type c, " Inco Terms -1
inco2(28) type c, " Inco Terms -2
prsdt(10) type c, " pricing date
waerk(5) type c, " Document Currency
vkbur(2) type c, " Sales Office
vkgrp(3) type c, " Sales group
pltyp(2) type c, " Price List type
kdgrp(2) type c, " Customer Group
bstkd_e(35) type c, " Ship-to-party PO number
submi(10) type c, " Collective Number
bname(35) type c, " Name
ihrez(12) type c, " Your Reference
kschl_1(4) type c, " Condition Type
kbetr_1(11) type c, " Amount
kschl_2(4) type c, " Condition Type
kbetr_2(11) type c, " Amount
kschl_3(4) type c, " Condition Type
kbetr_3(11) type c, " Amount
partner_1(25) type c, " Partner(Bill To Party Number)
partner_2(25) type c, " Partner(Payer Number)
partner_3(25) type c, " Partner(Sales Responsible Number)
partner_4(25) type c, " Partner(Order admin)
partner_5(25) type c, " Partner(Contact person)
tdspras_1(2) type c,
text_1(500) type c, " Text Before Items Z012
tdspras_2(2) type c,
text_2(500) type c, " Invocie Up Z034
tdspras_3(2) type c,
text_3(500) type c, " Invocie Down Z035
tdspras_4(2) type c,
text_4(500) type c, " Customer Reference Continue Z018
tdspras_5(2) type c,
text_5(500) type c, " Dispatch Marks/ Order Z019
tdspras_6(2) type c,
text_6(500) type c, " Ordered By Z003
tdspras_7(2) type c,
text_7(500) type c, " Sales Parameters Z002
kvgr1(3) type c, " Industry
kvgr2(3) type c, " customer BU
message(600) type c,
end of ty_err.
types: begin of ty_t685a,
kschl type kschl,
krech type krech,
end of ty_t685a.
INTERNAL TABLES
***header
data: g_krech_1(4) type c, " Calculation type for condition
g_krech_2(4) type c, " Calculation type for condition
g_krech_3(4) type c. " Calculation type for condition
g_krech_4(4) TYPE c, " Calculation type for condition
g_krech_5(4) TYPE c, " Calculation type for condition
g_krech_6(4) TYPE c, " Calculation type for condition
g_krech_7(4) TYPE c, " Calculation type for condition
g_krech_8(4) TYPE c, " Calculation type for condition
g_krech_9(4) TYPE c, " Calculation type for condition
g_krech_10(4) TYPE c, " Calculation type for condition
g_krech_11(4) TYPE c, " Calculation type for condition
g_krech_12(4) TYPE c, " Calculation type for condition
g_krech_13(4) TYPE c, " Calculation type for condition
g_krech_14(4) TYPE c, " Calculation type for condition
g_krech_15(4) TYPE c, " Calculation type for condition
g_krech_16(4) TYPE c, " Calculation type for condition
g_krech_17(4) TYPE c, " Calculation type for condition
g_krech_18(4) TYPE c, " Calculation type for condition
g_krech_19(4) TYPE c, " Calculation type for condition
g_krech_20(4) TYPE c. " Calculation type for condition
Items
data: g_krech_item_1(4) type c, " Calculation type for condition
g_krech_item_2(4) type c, " Calculation type for condition
g_krech_item_3(4) type c. " Calculation type for condition
g_krech_item_4(4) TYPE c, " Calculation type for condition
g_krech_item_5(4) TYPE c, " Calculation type for condition
g_krech_item_6(4) TYPE c, " Calculation type for condition
g_krech_item_7(4) TYPE c, " Calculation type for condition
g_krech_item_8(4) TYPE c, " Calculation type for condition
g_krech_item_9(4) TYPE c, " Calculation type for condition
g_krech_item_10(4) TYPE c, " Calculation type for condition
g_krech_item_11(4) TYPE c, " Calculation type for condition
g_krech_item_12(4) TYPE c, " Calculation type for condition
g_krech_item_13(4) TYPE c, " Calculation type for condition
g_krech_item_14(4) TYPE c, " Calculation type for condition
g_krech_item_15(4) TYPE c, " Calculation type for condition
g_krech_item_16(4) TYPE c. " Calculation type for condition
data: it_t685a type standard table of ty_t685a.
data: wa_bapi_header type bapisdhd1,
wa_bapi_headerx TYPE bapisdhd1x,
it_bapi_item type table of bapisditm,
it_bapi_itemx TYPE TABLE OF bapisditmx,
it_bapi_cond type table of bapicond,
it_bapi_condx TYPE TABLE OF bapicondx,
it_bapi_partner type table of bapiparnr,
it_bapi_shdl type table of bapischdl,
it_bapi_shdlx TYPE TABLE OF bapischdlx,
it_bapi_order_text type TABLE OF BAPISDTEXT,
it_bapireturn type table of bapiret2.
data: wa_bapi_item like line of it_bapi_item,
wa_bapi_itemx LIKE LINE OF it_bapi_itemx,
wa_bapi_cond like line of it_bapi_cond,
wa_bapi_condx LIKE LINE OF it_bapi_condx,
wa_bapi_partner like line of it_bapi_partner,
wa_bapi_shdl like line of it_bapi_shdl,
wa_bapi_shdlx LIKE LINE OF it_bapi_shdlx,
wa_bapi_order_text like LINE OF it_bapi_order_text,
wa_bapireturn like line of it_bapireturn.
*DATA: zmode(1) VALUE 'N'.
data: it_header type standard table of ty_header.
*DATA: it_temp_header TYPE STANDARD TABLE OF ty_header.
data: it_item type standard table of ty_item.
*DATA: it_temp_item TYPE STANDARD TABLE OF ty_item.
data: it_err type standard table of ty_err.
data: it_fline1 type standard table of tline,
wa_fline1 type tline.
data: it_thead1 type thead.
data: it_fline2 type standard table of tline,
wa_fline2 type tline.
data: it_thead2 type thead.
data: it_fline3 type standard table of tline,
wa_fline3 type tline.
data: it_thead3 type thead.
data: it_fline4 type standard table of tline,
wa_fline4 type tline.
data: it_thead4 type thead.
data: it_fline5 type standard table of tline,
wa_fline5 type tline.
data: it_thead5 type thead.
data: wa_header like line of it_header,
wa_item like line of it_item,
wa_err type ty_err,
wa_bill LIKE LINE OF it_bill,
wa_bill1 LIKE LINE OF it_bill,
wa_iterr like line of it_err,
wa_t685a like line of it_t685a.
wa_bill_item TYPE ty_bill_item.
data: it_schedule_line type standard table of ty_schedule_line,
wa_schedule_line type ty_schedule_line.
data: sales_order_no type bapivbeln-vbeln.
data: ext_sales_order_no type bapivbeln-vbeln.
Variable to be used to separate the fields which are concatenated by a
runtime character
*DATA: g_tabchar(1) TYPE c VALUE cl_abap_char_utilities=>horizontal_tab.
*DATA: wa_truxs_t_text_data TYPE truxs_t_text_data.
*DATA: g_filename TYPE string,
g_path TYPE string,
g_fullpath TYPE string,
g_user_action TYPE i,
g_file_encoding TYPE abap_encoding.
*DATA : g_text(8192),
data : g_mstring1(100) type c,
g_mstring2(100) type c,
g_mstring3(100) type c,
g_mstring4(100) type c,
g_mstring5(100) type c.
data: g_count1 type ebelp,
g_str_count1(6) type c.
data: g_count type ebelp,
g_str_count(6) type c.
*DATA: f_subrc LIKE sy-subrc,
f_subrc1 LIKE sy-subrc,
f_error(500) TYPE c,
item1(27) TYPE c,
item2(27) TYPE c,
item3(27) TYPE c,
item4(27) TYPE c,
i TYPE ekpo-ebelp.
*DATA: g_billplan_header TYPE c,
g_billplan_item TYPE c.
data : g_external_so type vbak-vbeln. "SO
SELECTION-SCREEN
selection-screen begin of block frame1 with frame title text-001 .
parameters:p_file1 type rlgrap-filename, "OBLIGATORY, "Header data.
p_file2 type rlgrap-filename, "OBLIGATORY, "Item Data.
p_file3 type rlgrap-filename, "Schedule line.
p_file4 type rlgrap-filename ."OBLIGATORY. "Error file.
selection-screen end of block frame1.
start-of-selection.
wa_bapi_header-doc_type = 'Z0MX'. "order type
wa_bapi_header-sales_org = '0130'."sales org
wa_bapi_header-distr_chan = '13'. "distr channel
wa_bapi_header-division = '13'. "division
Old code from copied program
wa_bapi_header-purch_no_s = wa_header-kunnr_2. " Ship to party
New code as required in Finland project
We are using to Header ->Order Tab -> Ship to Party -> Purchase order no (BSTKD_E) to store Old legacy SO number
wa_bapi_header-purch_no_s = 'MX100443'. "External SO i.e Old legacey SO number
wa_bapi_header-ref_1_s = '0000666666'. "Sold to party
wa_bapi_header-ord_reason = wa_header-augru.
wa_bapi_header-purch_no_c = 'ddr1234'. " PO number
wa_bapi_header-purch_date = sy-datum. " PO date
wa_bapi_header-req_date_h = sy-datum. " Required Delivery Date
wa_bapi_header-pmnttrms = '01'. " Payment Terms
wa_bapi_header-incoterms1 = wa_header-inco1.
wa_bapi_header-incoterms2 = wa_header-inco2.
wa_bapi_header-price_date = wa_header-prsdt. " Pricing date
wa_bapi_header-currency = wa_header-waerk. " Document Currency
wa_bapi_header-sales_grp = wa_header-vkgrp. " Sales group
wa_bapi_header-price_list = wa_header-pltyp. " Price list type
wa_bapi_header-cust_group = wa_header-kdgrp. " Cust Group
wa_bapi_header-ship_type = wa_header-vsart. " Shipping Type
wa_bapi_header-purch_no_s = wa_header-bstkd_e. " Ship-to-party po number
wa_bapi_header-collect_no = wa_header-submi. " Collective No.
wa_bapi_header-name = wa_header-bname. " Name
wa_bapi_header-ref_1 = wa_header-ihrez. " Your Reference
wa_bapi_header-cust_grp1 = wa_header-kvgr1. " Industry
wa_bapi_header-cust_grp2 = wa_header-kvgr2. " Customer BU
*ENDFORM. " f_header
IF wa_header-partner_1 IS NOT INITIAL.
wa_bapi_partner-partn_role = 'AG'.
wa_bapi_partner-partn_numb = '0000666666'.
wa_bapi_partner-itm_number = '000000'.
append wa_bapi_partner to it_bapi_partner.
clear wa_bapi_partner.
ENDIF.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = wa_header-partner_2
importing
output = wa_header-partner_2.
IF wa_header-partner_2 IS NOT INITIAL.
wa_bapi_partner-partn_role = 'WE'.
wa_bapi_partner-partn_numb = '0000666666'.
wa_bapi_partner-itm_number = '000000'.
append wa_bapi_partner to it_bapi_partner.
clear wa_bapi_partner.
ENDIF.
perform f_item.
data : order_items_inx type table of bapisditmx with header line.
order_items_inx-material = 'X'. "
order_items_inx-target_qty = 'X'. "
order_items_inx-comp_quant = 'X'. "
order_items_inx-trgqty_den = 'X'.
order_items_inx-rnddlv_qty = 'X'.
order_items_inx-updateflag = 'I'.
order_items_inx-target_qu = 'X'.
order_items_inx-plant = 'X'. "
append order_items_inx.
call function 'BAPI_SALESORDER_CREATEFROMDAT2'
exporting
salesdocumentin = 'MX11111152'
order_header_in = wa_bapi_header
order_header_inx = wa_bapi_headerx
importing
salesdocument = sales_order_no
tables
return = it_bapireturn
order_items_in = it_bapi_item
order_items_inx = order_items_inx
order_partners = it_bapi_partner
order_conditions_in = it_bapi_cond.
if sy-subrc is initial.
commit work.
endif.
*& Form f_item
text
form f_item .
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = wa_item-posnr
importing
output = wa_item-posnr.
wa_item-posnr = '000010'.
IF sy-subrc EQ 0. "IS INITIAL.
move wa_item-posnr to g_str_count."commented out by shakti
ENDIF.
wa_bapi_item-itm_number = wa_item-posnr. " Line item
WA_BAPI_ITEM-PO_ITM_NO = WA_ITEM-EBELP.
wa_bapi_item-division = wa_item-spart.
wa_bapi_item-purch_no_c = 'ddr1234'. " po number
wa_bapi_item-purch_date = sy-datum. " po date
wa_bapi_item-purch_no_s = 'MX11111112'. " Ship-to-party po number
wa_item-matnr = 'MAXIMO_SERVICE'.
call function 'CONVERSION_EXIT_MATN1_INPUT'
exporting
input = wa_item-matnr
importing
output = wa_item-matnr
exceptions
length_error = 1
others = 2.
if sy-subrc is initial.
wa_bapi_item-material = wa_item-matnr. "material
endif.
wa_bapi_item-target_qty = '1'. " Order qty
wa_bapi_item-comp_quant = '1'.
wa_bapi_item-target_qu = 'EA'.
wa_bapi_item-fixed_quan = '1'.
wa_bapi_item-comp_quant = wa_item-kwmeng.
wa_bapi_item-trgqty_den = '1'.
wa_bapi_item-rnddlv_qty = wa_item-kwmeng.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_item-ps_psp_pnr
IMPORTING
output = wa_item-ps_psp_pnr.
IF sy-subrc = 0.
wa_bapi_item-wbs_elem = wa_item-ps_psp_pnr.
ENDIF.
wa_bapi_item-item_categ = 'ZMAX'.
wa_bapi_item-ex_rate_fi = wa_item-kurrf.
wa_bapi_item-dli_profil = wa_item-ffprf. " Dynamic item processor profile
wa_bapi_item-route = wa_item-route. " route
wa_bapi_item-exchg_rate = wa_item-kursk.
wa_bapi_item-plant = '2090'. " Plant
wa_bapi_item-ship_point = 'FN11'. " Shipping point
wa_bapi_item-store_loc = wa_item-lgort. " stg loc
REPLACE ALL OCCURRENCES OF ',' IN wa_item-ntgew WITH '.'.
REPLACE ALL OCCURRENCES OF ',' IN wa_item-brgew WITH '.'.
wa_bapi_item-net_weight = wa_item-ntgew. "
wa_bapi_item-gross_wght = wa_item-brgew. "
call function 'CONVERSION_EXIT_CUNIT_INPUT'
exporting
input = wa_item-gewei
language = sy-langu
importing
output = wa_item-gewei.
EXCEPTIONS
unit_not_found = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
wa_bapi_item-untof_wght = 'KG'. " weight unit
replace all occurrences of ',' in wa_item-kursk with '.'.
replace all occurrences of ',' in wa_item-kurrf with '.'.
wa_bapi_item-profit_ctr = wa_item-prctr. " Profit center
wa_bapi_item-resanalkey = wa_item-abgrs. " RESULT ANALYSIS KEY
wa_bapi_item-cstg_sheet = wa_item-kalsm_k. " COSTING SHEET
append wa_bapi_item to it_bapi_item.
endform. " f_item
Thanks & regards,
Chetansee the following to create sales order:-
*& Report ZSALESORDER
*&DEVELOPED BY JANI KRUPA 4.10.2008
REPORT ZSALESORDER.
Parameters
Sales document type
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text FOR FIELD p_auart.
PARAMETERS: p_auart TYPE auart OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Sales organization
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text1 FOR FIELD p_vkorg.
PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Distribution channel
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text2 FOR FIELD p_vtweg.
PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Division.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text3 FOR FIELD p_spart.
PARAMETERS: p_spart TYPE spart OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SKIP 1.
Sold-to
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text4 FOR FIELD p_sold.
PARAMETERS: p_sold TYPE kunnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Ship-to
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text5 FOR FIELD p_ship.
PARAMETERS: p_ship TYPE kunnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.
SKIP 1.
Material
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text6 FOR FIELD p_matnr.
PARAMETERS: p_matnr TYPE matnr OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Quantity.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text7 FOR FIELD p_menge.
PARAMETERS: p_menge TYPE kwmeng OBLIGATORY.
SELECTION-SCREEN END OF LINE.
Plant
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text9 FOR FIELD p_plant.
PARAMETERS: p_plant TYPE werks_d .
SELECTION-SCREEN END OF LINE.
Complete Deliver
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(20) v_text10 FOR FIELD p_autlf.
PARAMETERS: p_autlf TYPE autlf DEFAULT 'X'.
SELECTION-SCREEN END OF LINE.
Data declarations.
DATA: v_vbeln LIKE vbak-vbeln.
DATA: header LIKE bapisdhead1.
DATA: headerx LIKE bapisdhead1x.
DATA: item LIKE bapisditem OCCURS 0 WITH HEADER LINE.
DATA: itemx LIKE bapisditemx OCCURS 0 WITH HEADER LINE.
DATA: partner LIKE bapipartnr OCCURS 0 WITH HEADER LINE.
DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.
DATA: lt_schedules_inx TYPE STANDARD TABLE OF bapischdlx
WITH HEADER LINE.
DATA: lt_schedules_in TYPE STANDARD TABLE OF bapischdl
WITH HEADER LINE.
DATA: lt_schedules_ink TYPE STANDARD TABLE OF bapisdhead1
WITH HEADER LINE.
Initialization.
INITIALIZATION.
v_text = 'Order type'.
v_text1 = 'Sales Org'.
v_text2 = 'Distribution channel'.
v_text3 = 'Division'.
v_text4 = 'Sold-to'.
v_text5 = 'Ship-to'.
v_text6 = 'Material'.
v_text7 = 'Quantity'.
v_text9 = 'Plant'.
v_text10 = 'Complete delivery'.
Start-of-selection.
START-OF-SELECTION.
Header data
Sales document type
header-doc_type = p_auart.
headerx-doc_type = 'X'.
Sales organization
header-sales_org = p_vkorg.
headerx-sales_org = 'X'.
Distribution channel
header-distr_chan = p_vtweg.
headerx-distr_chan = 'X'.
Division
header-division = p_spart.
headerx-division = 'X'.
headerx-updateflag = 'I'.
*Complete delivery
header-COMPL_DLV = p_autlf.
header-COMPL_DLV = 'X'.
Partner data
Sold to
partner-partn_role = 'AG'.
partner-partn_numb = p_sold.
APPEND partner.
Ship to
partner-partn_role = 'WE'.
partner-partn_numb = p_ship.
APPEND partner.
ITEM DATA
itemx-updateflag = 'I'.
Line item number.
item-itm_number = '000010'.
itemx-itm_number = 'X'.
Material
item-material = p_matnr.
itemx-material = 'X'.
Plant
item-plant = p_plant.
itemx-plant = 'X'.
Quantity
item-target_qty = p_menge.
itemx-target_qty = 'X'.
item category
itemx-ITEM_CATEG = 'X'.
APPEND item.
APPEND itemx.
ITEM DATA
itemx-updateflag = 'I'.
Line item number.
item-itm_number = '000020'.
itemx-itm_number = 'X'.
Material
item-material = p_matnr.
itemx-material = 'X'.
Plant
item-plant = p_plant.
itemx-plant = 'X'.
Quantity
item-target_qty = p_menge.
itemx-target_qty = 'X'.
APPEND item.
APPEND itemx.
Fill schedule lines
lt_schedules_in-itm_number = '000010'.
lt_schedules_in-sched_line = '0001'.
lt_schedules_in-req_qty = p_menge.
APPEND lt_schedules_in.
Fill schedule line flags
lt_schedules_inx-itm_number = '000010'.
lt_schedules_inx-sched_line = '0001'.
lt_schedules_inx-updateflag = 'X'.
lt_schedules_inx-req_qty = 'X'.
APPEND lt_schedules_inx.
Fill schedule lines
lt_schedules_in-itm_number = '000020'.
lt_schedules_in-sched_line = '0001'.
lt_schedules_in-req_qty = p_menge.
APPEND lt_schedules_in.
Fill schedule line flags
lt_schedules_inx-itm_number = '000020'.
lt_schedules_inx-sched_line = '0001'.
lt_schedules_inx-updateflag = 'X'.
lt_schedules_inx-req_qty = 'X'.
APPEND lt_schedules_inx.
Call the BAPI to create the sales order.
CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'
EXPORTING
sales_header_in = header
sales_header_inx = headerx
IMPORTING
salesdocument_ex = v_vbeln
TABLES
return = return
sales_items_in = item
sales_items_inx = itemx
sales_schedules_in = lt_schedules_in
sales_schedules_inx = lt_schedules_inx
sales_partners = partner.
Check the return table.
LOOP AT return WHERE type = 'E' OR type = 'A'.
EXIT.
ENDLOOP.
IF sy-subrc = 0.
WRITE: / 'Error in creating document'.
ELSE.
Commit the work.
COMMIT WORK AND WAIT.
WRITE: / 'Document ', v_vbeln, ' created'.
ENDIF. -
Pricing problem in sales order creation
Hi friends,
My requirement is to create sales order with ref to contract i am using 'BAPI_SALESORDER_CREATEFROMDAT2' , and I am extracting data from konv table to get price through condition record , but i am getting 4 messages
(S) SALES_HEADER_IN has been processed successfully
(E) Condition PR00 is not allowed as header condition
(W) The sales document is not yet complete: Edit data
(E) Sales document was not changed
and i am not getting pricing for created sales order document.
please help.
regards,
Sravani.hi
ZK01 Company Selling Price - 21.86 INR 1 BT - 2360.41 INR for 108 BT( your statement)
This is wrong 21.86 x 108 = 2360.88 and not 2360.41 as written by you
so the calculation of the system is correct
21.86 x 108 =2360.88
1.41 x 108 =153.28
So total 23.27 x 108 = 2513.16 (also 2360.88 +152.28 also is equal to 2513.16 )
you can check in calculator
If ZK01 is showing a wrong vaule 2360.41 instead of correct 2360.88 in your case then you need to check the configuration of that condition type
The subtoatal valuew hich you have written is also wrong because of ZK01
Problem lies in ZK01 check the other controls and rounding profile etc of ZK01 in V/06
Regards
Raja -
Changing PSTYV in sales order with BAPI_SALESORDER_CREATEFROMDAT2
hi all,
I'm having this trouble...
we are creating a Sales Order from PI calling directly the BAPI_SALESORDER_CREATEFROMDAT2...
but, theres a field than I have to change... the PSTYV must be TANN when the VBAP-NETWR is 0.
I've used the MV45AFZZ program for the exit... but no in the move_field_to_vbap ('cause it doesn't work form me), I used this one:
FORM USEREXIT_SAVE_DOCUMENT_PREPARE.
data: l_tabix type i VALUE 0.
if xvbak-AUART = 'ZCO'.
loop at xvbap.
add 1 to l_tabix.
if xvbap-netwr EQ 0.
xvbap-PSTYV = 'TANN'.
modify xvbap index l_tabix TRANSPORTING pstyv .
endif.
endloop.
endif.
ENDFORM.
and with this, when the sales order is created, my PSTYV field if NETWR = 0, now is TANN.... but this is NOT the solution 'cause I can't make an Invoice... I have an incompletion LOG....
but, if I change the field manually appears a message: New pricing carried out ( Message no. V1209 ).
and with this... I fix the problem.... but, you can see than I need it automatically....
so I think, than with my exit, I'm only changing the PSTYV value, but no all the changes than this need...
thanks in advance...
Regards..Apart from that and also
ORDER_ITEMS_IN-ITEM_CATEG = " Value here
ORDER_ITEMS_INX-ITEM_CATEG = " Value here
a® -
Quantity update into sales order using BAPI_SALESORDER_CREATEFROMDAT2
Hi All,
I am able to create a sales order using the BAPI "BAPI_SALESORDER_CREATEFROMDAT2".
But even after assinging the Target_quntity and the Target_quantity_units, the values are not getting updated into the Sales order, but the sales order gets created .
Did anyone of you had a similare problem, how was it solved.
cold some one please help me out on this.
RegardsHi
I had used below code (using <b>BAPI_SALESORDER_CREATEFROMDAT1</b>)..but never faced any problem.. you can try the same...
Regards,
Raj
REPORT z_sd_salesorder_create
NO STANDARD PAGE HEADING
LINE-SIZE 150
MESSAGE-ID zz.
S T R U C T U R E D E C L A R A T I O N S *
TYPES: BEGIN OF x_ppl,
ppl_order(18), " ppl Orderno
auart(4), " Sales Doc Type
vkorg(4), " Sales Organization
vtweg(2), " Distribution Channel
spart(2), " Division
div(3), " Division
kunnr(10), " Sold-to Party
date(10), " Doc Dt
matnr(18), " Item Matnr#
uom(3), " UOM
qty(15), " Qty
kschl(4), " Pricing condiiton type
kbetr(11), " Rate
END OF x_ppl.
TYPES: BEGIN OF x_file,
loc(30), " Location
div(3), " Division
ppl_order(18), " ppl Orderno
kunnr(10), " Sold-to Party
date(10), " Doc Dt
matnr(20), " Item Matnr#
qty(15), " Qty
uom(3), " UOM
kbetr(11), " Rate
discount(5), " Discount
END OF x_file.
TYPES: BEGIN OF x_output,
ppl_order(18), " ppl Orderno
mesg(130), " Mesg Success/Error
END OF x_output.
TYPES: BEGIN OF x_werks,
name2(30), " Location
werks TYPE werks_ext, " Plant
END OF x_werks.
TYPES: BEGIN OF x_info,
vkorg TYPE vkorg , " Sales org
vtweg TYPE vtweg, " Dist channel
werks TYPE werks_ext," Plant
spart TYPE spart, " Storage Loc
END OF x_info.
TYPES: BEGIN OF x_material,
ppl_prdid(20), " ppl Prd id
matnr TYPE matnr, " Material (SAP)
END OF x_material.
I N T E R N A L T A B L E D E C L A R A T I O N S *
DATA: it_file TYPE STANDARD TABLE OF x_file WITH HEADER LINE." File Data
DATA: it_data TYPE STANDARD TABLE OF x_ppl WITH HEADER LINE." ppl File
DATA: it_out TYPE STANDARD TABLE OF x_output WITH HEADER LINE. " Outcome
DATA: it_werks TYPE STANDARD TABLE OF x_werks WITH HEADER LINE. " Plant
DATA: it_info TYPE STANDARD TABLE OF x_info WITH HEADER LINE. " Othr Info
DATA: it_matnr TYPE STANDARD TABLE OF x_material WITH HEADER LINE. " Material Info
DATA: it_item TYPE STANDARD TABLE OF bapiitemin WITH HEADER LINE. "Order Itm data
DATA: it_partner TYPE STANDARD TABLE OF bapipartnr WITH HEADER LINE. "Order Partner data
V A R I A B L E S D E C L A R A T I O N S *
DATA : v_correct TYPE i,
v_error TYPE i,
v_total TYPE i,
v_return LIKE bapireturn1,
v_index LIKE sy-tabix.
*- Return values
DATA: it_orderh TYPE bapisdhead, "Order Hdr data
order TYPE bapivbeln-vbeln,
soldto TYPE bapisoldto,
shipto TYPE bapishipto,
return TYPE bapireturn1.
DATA: hdate TYPE sy-datum.
U S E R I N P U T S S C R E E N *
SELECTION-SCREEN: BEGIN OF BLOCK blk01 WITH FRAME TITLE text-t01.
PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY. " File name
SELECTION-SCREEN END OF BLOCK blk01.
S E L E C T I O N S C R E E N *
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_file.
S t a r t o f S e l e c t i o n *
START-OF-SELECTION.
PERFORM get_upload.
PERFORM validate_data. " Validate the data
PERFORM data_swap. " Prepare the data for processing
IF NOT it_data[] IS INITIAL.
PERFORM get_update. " Create SalesOrders
ELSE.
MESSAGE i001(zz) WITH text-001.
STOP.
ENDIF.
E n d o f S e l e c t i o n *
END-OF-SELECTION.
IF NOT it_data[] IS INITIAL.
PERFORM get_write.
ENDIF.
*& Form get_file
Get File name
FORM get_file .
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
EXPORTING
program_name = syst-repid
mask = '*'
CHANGING
file_name = p_file
EXCEPTIONS
mask_too_long = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDFORM. " get_file
*& Form get_upload
to upload the file
FORM get_upload .
DATA l_file TYPE string.
CLEAR: it_file, it_file[].
l_file = p_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = l_file
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = it_file
EXCEPTIONS
file_open_error = 1
file_read_error = 2
no_batch = 3
gui_refuse_filetransfer = 4
invalid_type = 5
no_authority = 6
unknown_error = 7
bad_data_format = 8
header_not_allowed = 9
separator_not_allowed = 10
header_too_long = 11
unknown_dp_error = 12
access_denied = 13
dp_out_of_memory = 14
disk_full = 15
dp_timeout = 16
OTHERS = 17.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ELSEIF sy-subrc = 0.
SORT it_file BY loc ppl_order.
ENDIF.
ENDFORM. " get_upload
*& Form get_update
Creating mapping Data in Z table
FORM get_update .
DATA: l_itemno(2) TYPE n,
l_partner TYPE parvw,
l_kunnr TYPE kunnr,
l_matnr TYPE matnr,
l_mesg TYPE string,
l_kbetr TYPE p DECIMALS 2.
DATA: l_in_qty LIKE vbap-zmeng,
l_meins LIKE mara-meins,
l_qty LIKE vbap-zmeng.
CLEAR: v_correct, v_error, v_total.
SORT it_data BY ppl_order.
LOOP AT it_data.
CLEAR v_index.
v_index = sy-tabix.
*- New SalesOrder
AT NEW ppl_order.
READ TABLE it_data INDEX v_index.
CLEAR: it_orderh, it_item, it_partner,
order, soldto, shipto, return,
it_item[], it_partner[].
v_total = v_total + 1. "Increment Total SalesOrders counter
CLEAR l_itemno.
l_itemno = '10'.
*- Covert date fields into Internal format
CALL FUNCTION 'CONVERT_DATE_TO_INTERN_FORMAT'
EXPORTING
datum = it_data-date
dtype = 'DATS'
IMPORTING
idate = it_data-date.
*- Populate SalesOrder header data.
CALL FUNCTION 'CONVERSION_EXIT_AUART_INPUT'
EXPORTING
input = it_data-auart
IMPORTING
output = it_data-auart.
it_orderh-doc_type = it_data-auart.
it_orderh-sales_org = it_data-vkorg.
it_orderh-distr_chan = it_data-vtweg.
it_orderh-division = it_data-spart.
it_orderh-purch_no = 'DEPOT'.
it_orderh-price_date = it_data-date. "Doc Dt
it_orderh-req_date_h = it_data-date. "Del.Dt
it_orderh-purch_no_s = it_data-ppl_order.
*- Partner data
CLEAR: l_partner, l_kunnr.
*- Convert Partner type into internal format
l_partner = 'SP'. "SoldTo Party
CALL FUNCTION 'CONVERSION_EXIT_PARVW_INPUT'
EXPORTING
input = l_partner
IMPORTING
output = l_partner.
*- Convert Customer into internal format
l_kunnr = it_data-kunnr.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = l_kunnr
IMPORTING
output = l_kunnr.
it_partner-partn_role = l_partner.
it_partner-partn_numb = l_kunnr.
APPEND it_partner.
CLEAR it_partner.
ENDAT.
*- Item data
it_item-itm_number = l_itemno.
*- Convert material number into internal format
CLEAR l_matnr.
l_matnr = it_data-matnr.
CALL FUNCTION 'CONVERSION_EXIT_MATN1_INPUT'
EXPORTING
input = l_matnr
IMPORTING
output = l_matnr
EXCEPTIONS
length_error = 1
OTHERS = 2.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
it_item-material = l_matnr.
*- Call FM to get new qty based on SAP UOM
CLEAR: l_meins, l_qty, l_in_qty.
l_in_qty = it_data-qty.
CALL FUNCTION 'Z_GET_QTY_FROM_UOM'
EXPORTING
matnr = it_item-material
in_meins = it_data-uom
in_qty = l_in_qty
IMPORTING
out_meins = l_meins
quantity = l_qty.
IF sy-subrc = 0.
it_data-qty = l_qty.
it_data-uom = l_meins.
ENDIF.
it_data-qty = it_data-qty * 1000.
it_item-req_qty = it_data-qty.
it_item-sales_unit = it_data-uom.
it_item-req_date = it_data-date.
*- Pricing data
it_item-cond_type = it_data-kschl. "Pricing condition
CLEAR l_kbetr.
l_kbetr = it_data-kbetr / 10. "Price (Rate)
it_item-cond_value = l_kbetr.
APPEND it_item.
CLEAR it_item.
*- Increment Item counter.
l_itemno = l_itemno + 10.
*- At end of SalesOrder
AT END OF ppl_order.
READ TABLE it_data INDEX v_index.
*- Call the BAPI for SalesOrder creation
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT1'
EXPORTING
order_header_in = it_orderh
IMPORTING
salesdocument = order
sold_to_party = soldto
ship_to_party = shipto
return = return
TABLES
order_items_in = it_item
order_partners = it_partner.
IF sy-subrc = 0.
COMMIT WORK.
ENDIF.
v_return = return+0(1).
IF v_return = 'E'.
v_error = v_error + 1.
CLEAR l_mesg.
l_mesg = return.
CONDENSE l_mesg.
ELSE.
v_correct = v_correct + 1.
CLEAR l_mesg.
CONCATENATE 'Salesorder'(007) order 'successfully created.'(008)
INTO l_mesg SEPARATED BY space.
CONDENSE l_mesg.
ENDIF.
*- Populate the output table
CLEAR it_out.
it_out-ppl_order = it_data-ppl_order.
it_out-mesg = l_mesg.
APPEND it_out.
CLEAR it_out.
ENDAT.
ENDLOOP.
ENDFORM. " get_update
*& Form get_write
Write the results
FORM get_write .
WRITE:/ 'Total Number of Records :'(002), v_total COLOR 1.
WRITE:/ 'Total Correct Records :'(003), v_correct COLOR 3.
WRITE:/ 'Total Error Records :'(004), v_error COLOR 6.
SKIP 3.
IF NOT it_out[] IS INITIAL.
WRITE:/5 'ppl Order #'(005),
28 'Message'(006).
ENDIF.
SKIP 1.
LOOP AT it_out.
WRITE:/5 it_out-ppl_order,
28 it_out-mesg.
ENDLOOP.
ENDFORM. " get_write
*& Form validate_data
Validate the data
FORM validate_data .
DATA: l_bstkde TYPE bstkd_e.
LOOP AT it_file.
SELECT bstkd_e INTO l_bstkde
UP TO 1 ROWS
FROM vbkd
WHERE bstkd_e = it_file-ppl_order.
ENDSELECT.
IF sy-subrc = 0. " This ppl Order is already been created in SAP, so delete record
DELETE it_file.
ENDIF.
ENDLOOP.
SORT it_file BY ppl_order.
ENDFORM. " validate_data
*& Form data_swap
Prepare the data for processing
FORM data_swap .
CLEAR: it_werks, it_info, it_matnr, it_data,
it_werks[], it_info[], it_matnr[], it_data[].
IF NOT it_file[] IS INITIAL.
*- Get the plant from location
SELECT name2
werks
INTO CORRESPONDING FIELDS OF TABLE it_werks
FROM t001w FOR ALL ENTRIES IN it_file
WHERE name2 = it_file-loc.
IF sy-subrc = 0.
SORT it_werks BY name2 werks.
*- Get the Sales Org, Division and Distribution Channel
IF NOT it_werks[] IS INITIAL.
SELECT vkorg
vtweg
werks
INTO CORRESPONDING FIELDS OF TABLE it_info
FROM tvkwz FOR ALL ENTRIES IN it_werks
WHERE werks = it_werks-werks.
IF sy-subrc = 0.
LOOP AT it_info.
it_info-spart = '99'.
MODIFY it_info INDEX sy-tabix.
ENDLOOP.
SORT it_info BY vkorg vtweg werks.
ENDIF.
ENDIF.
ENDIF.
*- Get material from ppl material
SELECT ppl_prdid
matnr
FROM zppl_master
INTO TABLE it_matnr FOR ALL ENTRIES IN it_file
WHERE ppl_prdid = it_file-matnr.
IF sy-subrc = 0.
SORT it_matnr BY ppl_prdid matnr.
ENDIF.
ENDIF.
*- Update the data in it_data
LOOP AT it_file.
CLEAR it_data.
it_data-auart = 'OR'.
it_data-auart = 'OR'. " CHANGED BY Jo ON 3103005
READ TABLE it_werks WITH KEY name2 = it_file-loc BINARY SEARCH.
IF sy-subrc = 0.
READ TABLE it_info WITH KEY werks = it_werks-werks BINARY SEARCH.
IF sy-subrc = 0.
it_data-vkorg = it_info-vkorg.
it_data-vtweg = it_info-vtweg.
ENDIF.
ENDIF.
*- Material
READ TABLE it_matnr WITH KEY ppl_prdid = it_file-matnr BINARY SEARCH.
IF sy-subrc = 0.
it_data-matnr = it_matnr-matnr.
ENDIF.
it_data-ppl_order = it_file-ppl_order.
it_data-date = it_file-date.
CONCATENATE it_file-kunnr it_file-loc+1(2) INTO it_data-kunnr.
it_data-qty = it_file-qty.
it_data-uom = it_file-uom.
it_data-kbetr = it_file-kbetr.
*- Pricing condition
it_data-kschl = 'PR00'.
CASE it_file-div.
WHEN 'BRN'.
it_data-div = '04'.
WHEN 'GEN'.
it_data-div = '03'.
WHEN 'IVF'.
it_data-div = '02'.
WHEN 'OPH'.
it_data-div = '01'.
ENDCASE.
it_data-spart = it_data-div.
APPEND it_data.
CLEAR it_data.
ENDLOOP.
ENDFORM. " data_swap -
Using BAPI_SALESORDER_CREATEFROMDAT2
Hi! I would like to ask if anyone has sample code of a working call to the bapi BAPI_SALESORDER_CREATEFROMDAT2?
I've tried it and I've been able to create a sales order, however I have troubles with repeating items in Conditions.
Tried changing LOGIC_SWITCH-PRICING to all the values and somehow, still can't get the right price.
I'm running SAP ECC 6.0 (if it helps
Thanks!
Nevermind.
Found the answer at this thread:
BAPI_SALESORDER_CHANGE update conditions
He's right, it DOES work!
As posted by Ruong Tran:
Hi guys,
To update an existing pricing condition, you need to set the logic_switch field COND_HANDL = 'X'. This will not create a new entry but update the existing one, trust me, I've tried this and it works.
Ruong
Message was edited by: Alexandra CoHI Alexandra
You are right. Please check the below thread on the same topic.
Re: How to change pricing Conditions in Sales order in change sales order bapi
Kind Regards
Eswar -
BAPI_SALESORDER_CREATEFROMDAT2 to replace VA01, KBETR and NETWR
Please help me..
I am using BAPI_SALESORDER_CREATEFROMDAT2 for creating sales order for replace VA01,
can you please tell me in which field the amount KBETR (of items) is to be populated.
i thing that i will populate COND_VALUE in ORDER_CONDITIONS_IN with field kbetr but I don't know what will I populate field COND_TYPE ? the same problem I have with net value (NETWR).
Would you explain me what I will populate fields in differents fields of this BAPI ?
or give me an example of thisHi,
You have to populate the quantity in the ORDER_SCHEDULES_IN and ORDER_SCHEDULES_INX. The price should and will get determined based on the pricing procedure conditions.
DATA : order_schedule TYPE TABLE OF bapischdl,
wa_order_schedule TYPE bapischdl,
order_schedulex TYPE TABLE OF bapischdlx,
wa_order_schedulex TYPE bapischdlx.
wa_order_schedule-itm_number = '0010'. ( Same item number from ORDER_ITEMS_IN )
wa_order_schedule-sched_line = '0001'. ( Corresponds to VBEP-ETENR )
wa_order_schedule-req_qty = quantity ( Quantity you have to pass )
APPEND wa_order_schedule TO order_schedule.
wa_order_schedulex-itm_number = '0010'. ( Same item number from ORDER_ITEMS_IN )
wa_order_schedulex-sched_line = '0001'. ( Corresponds to wa_order_schedule-sched_line )
wa_order_schedulex-updateflag = 'I'.
wa_order_schedulex-req_qty = 'X'.
APPEND wa_order_schedulex TO order_schedulex.
Hope it helps
Sujay -
BAPI_SALESORDER_CREATEFROMDAT2 conditions
Hi gurus!
I'm using BAPI_SALESORDER_CREATEFROMDAT2 to create SO document and need to pass SOME prices.
Searched the forum, but none of the solutions is right for me.
This is me test scenery: one order with two items. One has price (ZPVP) and the other doesn't. ZPVP condition is pre-set and it can be entered manually.
What I need is to override the value of condition ZPVP.
When I set BAPISDLS-PRICING = 'G' and BAPISDLS-COND_HANDL = 'X' : condition ZPVP is deleted for both items;
When I set BAPISDLS-PRICING = 'G' and BAPISDLS-COND_HANDL = ' ' : Condition ZPVP is filled with the value that I pass; Condition ZPVP is deleted if I don't pass any value;
When I set BAPISDLS-PRICING = 'C' and BAPISDLS-COND_HANDL = ' ':Duplicates condition ZPVP in the item where I pass the value; Item where no value is passed is OK (pre-set);
When I set BAPISDLS-PRICING = 'C' and BAPISDLS-COND_HANDL = 'X': The condition value that I pass to the BAPI is ignored. Both items are filled with pre-set value for condition ZPVP.
Can someone help?
Thanks in advance!
Carlos ConstantinoHi,
I think you need to pass the entire condition value instead of dividing by 10.
Instead of:
t_bapicond-cond_value = t_konv-kbetr / 10.
Use:
t_bapicond-cond_value = t_konv-kbetr.
Within include program L2032FXX, form move_condition_out, there is some special code for krech = 'A' that divides condition value by 10 for you. Here is the standard code:
if www_ex_konvkom-krech = 'A'. "prozentual ?
bapi_ex_konvkom-cond_value = www_ex_konvkom-kbetr / 10.
endif.
If that does not work for you, then take a look in include program L2032FXX, form move_condition_out to see some additional special handling for krech = 'A' that may or may not end up affecting your condition value results.
case www_ex_konvkom-krech.
when 'A' or 'H' or 'I'.
bapi_ex_konvkom-conbaseval =
www_ex_konvkom-kawrt.
if not www_ex_konvkom-kawrt is initial and
not da_waer is initial.
clear bapi_ex_konvkom-conbaseval.
call function 'BAPI_CURRENCY_CONV_TO_EXTERN_9'
exporting
currency = da_waer
amount_internal = www_ex_konvkom-kawrt
importing
amount_external = bapi_ex_konvkom-conbaseval.
endif.
when others.
bapi_ex_konvkom-conbaseval =
www_ex_konvkom-kawrt / 10.
endcase.
Regards,
James Gaddis -
Hi,
with sapnwrfc packet from Piers Harding (v0.31) I try to create a salesorder within a perl script.
Without using table ORDER_CONDITIONS_IN my salesorder is created successfull in SAP.
Now I want to commit pricing information. Therefor I used ORDER_CONDITIONS_IN with syntax:
$rc->ORDER_CONDITIONS_IN([{'COND_P_UNT'=>'1', 'CURRENCY'=>'EUR', 'COND_TYPE'=>'PR00', 'ITM_NUMBER'=>'000010', 'COND_VALUE'=>'22'}]);
SAP returned an error: BCD_BADDATA
So I thought something wrong with COND_P_UNT or COND_VALUE because these have to be BCD packed values.
Now I tried something like
pack("H*", "22")
for COND_VALUE and so on. But without success.
Some values I commited in table ORDER_ITEMS_IN are marked as BCD but I have to send them in "plain" text, no pack function to call...
So, did you have any idea for solving my problem?
Is it possible that another (incomplete) table is responsible for my problem?
Or do you think the reason is dedicated to table ORDER_CONDITIONS_IN?
Any help or suggestion appreciated!
Regards,
PatrickHi David,
yes, I tried it in your given syntax.
Here my actual code but with seperatly build arrays.
I had to restructure beacause of many loops.... But finally thats what I did.
Lines marked with '#!' are specific and have to be adapted to your system.
Uncommenting the line where populating ORDER_CONDITIONS_IN produces the error.
use Data::Dumper;
use sapnwrfc;
my @orderHeaderIn;
my @orderPartners;
my @orderItemsIn;
my @orderSchedulesIn;
my @orderCfgsInst;
my @orderConditionsIn;
$orderHeaderIn->{DOC_TYPE} = 'ZRAS'; #!
$orderHeaderIn->{SALES_ORG} = '055'; #!
$orderHeaderIn->{DISTR_CHAN} = '01'; #!
$orderHeaderIn->{DIVISION} = 'IE'; #!
$orderHeaderIn->{REQ_DATE_H} = '20101231';
$orderPartners->[0]{PARTN_NUMB} = '0000008759'; #!
$orderPartners->[0]{PARTN_ROLE} = 'AG'; #!
$orderItemsIn->[0]{ITM_NUMBER} = '000010';
$orderItemsIn->[0]{PLANT} = '0551'; #!
$orderItemsIn->[0]{MATERIAL} = '000000000000368388'; #!
$orderItemsIn->[0]{ORDERID} = '000552551003'; #!
$orderItemsIn->[0]{PURCH_DATE} = '20101030';
$orderItemsIn->[0]{TARGET_VAL} = '22';
$orderItemsIn->[0]{BILL_DATE} = '20101030';
$orderItemsIn->[0]{TARGET_QTY} = '22';
$orderSchedulesIn->[0]{ITM_NUMBER} = '000010';
$orderSchedulesIn->[0]{REQ_QTY} = '22';
$orderCfgsInst->[0]{QUANTITY_UNIT} = 'STZ'; #!
$orderConditionsIn->[0]{ITM_NUMBER} = '000010';
$orderConditionsIn->[0]{COND_VALUE} = '22';
$orderConditionsIn->[0]{CURRENCY} = 'EUR';
$orderConditionsIn->[0]{COND_P_UNT} = '1';
$orderConditionsIn->[0]{COND_TYPE} = 'PR00'; #!
SAPNW::Rfc->load_config('path_to_sap.yml'); #!
my $con = SAPNW::Rfc->rfc_connect;
my $rd = $con->function_lookup("BAPI_SALESORDER_CREATEFROMDAT2");
my $rc = $rd->create_function_call;
$rc->ORDER_HEADER_IN($orderHeaderIn);
$rc->ORDER_PARTNERS($orderPartners);
$rc->ORDER_ITEMS_IN($orderItemsIn);
$rc->ORDER_SCHEDULES_IN($orderSchedulesIn);
$rc->ORDER_CFGS_INST($orderCfgsInst);
#$rc->ORDER_CONDITIONS_IN($orderConditionsIn);
$rc->invoke;
print "salesdocument: ".$rc->SALESDOCUMENT."\n";
print "RetVal: ".Dumper(@{$rc->RETURN})."\n";
$rd = $con->function_lookup("BAPI_TRANSACTION_COMMIT");
$rc = $rd->create_function_call;
$rc->WAIT("x");
$rc->invoke;
$con->disconnect;
I already set trace to 1 in sap.yml. Now I will try with a higher value.
Thanks for that hint. -
BAPI_SALESORDER_CREATEFROMDAT2 doesn't work for header Condition
Hi, All
I'm trying to create a sales order using BAPI_SALESORDER_CREATEFROMDAT2.
It doesn't work to create a heder condition.(HB00)
After BAPI, I check KONV data, HB00 data is broken.
KONV-STUNR and KONV-ZAEHK is blank.
but item condtion data is OK. no problem.
I don't know why.
my code is below.
If you have any idea, please let me know.
IW_LOGIC_SWITCH-PRICING = 'G'
CLEAR IW_CONDITIONS.
IW_CONDITIONS-ITM_NUMBER = '000000'.
IW_CONDITIONS-COND_COUNT = '01'.
IW_CONDITIONS-COND_TYPE = 'HB00'.
IW_CONDITIONS-COND_VALUE = W_VALUE.
IW_CONDITIONS-CURRENCY = W_WAERK.
IW_CONDITIONS-CONDCOINHD = '01'.
APPEND IW_CONDITIONS TO IT_CONDITIONS.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN = IW_HEADER
LOGIC_SWITCH = IW_LOGIC_SWITCH
IMPORTING
SALESDOCUMENT = W_SALEDOC
TABLES
RETURN = IT_RETURN
ORDER_ITEMS_IN = IT_ITEMS
ORDER_PARTNERS = IT_PARTNERS
ORDER_SCHEDULES_IN = IT_SCHEDULES
ORDER_CONDITIONS_IN = IT_CONDITIONS
ORDER_TEXT = IT_TEXT
EXTENSIONIN = IT_EXTENSIONIN
PARTNERADDRESSES = IT_PARTNERADDRESSES.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.
Regards,
Rie.check the following link
Re: BAPI_SALESORDER_CREATEFROMDAT2 how to set condition type value as zero (0).
L_ORDER_PARTNERS-PARTN_ROLE = 'AG'.
L_ORDER_PARTNERS-PARTN_NUMB =
RECORD-KUNNR_1.
APPEND L_ORDER_PARTNERS TO
LI_ORDER_PARTNERS.
L_ORDER_PARTNERS-PARTN_ROLE = 'WE'.
L_ORDER_PARTNERS-PARTN_NUMB =
RECORD-KUNNR_2.
APPEND L_ORDER_PARTNERS TO
LI_ORDER_PARTNERS.
* Build order header
CLEAR: L_ORDER_HEADER_INX,
L_ORDER_HEADER_IN.
* Update flag
L_ORDER_HEADER_INX-UPDATEFLAG = 'I'.
* Sales document type
L_ORDER_HEADER_IN-DOC_TYPE =
RECORD-AUART.
L_ORDER_HEADER_INX-DOC_TYPE = 'X'.
* Sales organization
L_ORDER_HEADER_IN-SALES_ORG = RECORD-VKORG.
L_ORDER_HEADER_INX-SALES_ORG = 'X'.
* Distribution channel
L_ORDER_HEADER_IN-DISTR_CHAN = RECORD-VTWEG.
L_ORDER_HEADER_INX-DISTR_CHAN = 'X'.
* Division
L_ORDER_HEADER_IN-DIVISION = RECORD-SPART.
L_ORDER_HEADER_INX-DIVISION = 'X'.
* Sales Office
L_ORDER_HEADER_IN-SALES_OFF = RECORD-VKBUR.
L_ORDER_HEADER_INX-SALES_OFF = 'X'.
* Sales Group
L_ORDER_HEADER_IN-SALES_GRP = RECORD-VKGRP.
L_ORDER_HEADER_INX-SALES_GRP = 'X'.
* Purchase order
L_ORDER_HEADER_IN-PURCH_NO_C = RECORD-BSTNK.
L_ORDER_HEADER_INX-PURCH_NO_C = 'X'.
* Purchase order Date
L_ORDER_HEADER_IN-PURCH_DATE =
RECORD-BSTDK.
L_ORDER_HEADER_INX-PURCH_DATE = 'X'.
* Payment Terms
L_ORDER_HEADER_IN-PMNTTRMS = RECORD-ZTERM.
L_ORDER_HEADER_INX-PMNTTRMS = 'X'.
* Incoterm1
L_ORDER_HEADER_IN-INCOTERMS1 = RECORD-INCO1.
L_ORDER_HEADER_INX-INCOTERMS1 = 'X'.
* Incoterm2
L_ORDER_HEADER_IN-INCOTERMS2 = RECORD-INCO2.
L_ORDER_HEADER_INX-INCOTERMS2 = 'X'.
* Customer Group
L_ORDER_HEADER_IN-CUSGROUP = RECORD-KDGRP.
L_ORDER_HEADER_INX-CUSGROUP = 'X'.
ENDIF.
* Build order item(s)
CLEAR: L_ORDER_ITEMS_INX, L_ORDER_ITEMS_IN.
L_ORDER_ITEMS_IN-ITM_NUMBER = INO.
L_ORDER_ITEMS_INX-ITM_NUMBER = INO.
L_ORDER_ITEMS_IN-MATERIAL = RECORD-MABNR.
L_ORDER_ITEMS_INX-MATERIAL = 'X'.
L_ORDER_ITEMS_IN-PLANT = RECORD-WERKS.
L_ORDER_ITEMS_INX-PLANT = 'X'.
L_ORDER_ITEMS_IN-SALES_UNIT = RECORD-VRKME.
L_ORDER_ITEMS_INX-SALES_UNIT = 'X'.
L_ORDER_ITEMS_IN-WBS_ELEM = RECORD-PS_POSID.
L_ORDER_ITEMS_INX-WBS_ELEM = 'X'.
APPEND L_ORDER_ITEMS_IN TO LI_ORDER_ITEMS_IN.
L_ORDER_ITEMS_INX-UPDATEFLAG = 'I'.
APPEND L_ORDER_ITEMS_INX TO
LI_ORDER_ITEMS_INX.
* Build Schedule lines... Order Quantity
CLEAR: L_ORDER_SCHEDULES_IN,
L_ORDER_SCHEDULES_INX.
L_ORDER_SCHEDULES_IN-ITM_NUMBER = INO.
L_ORDER_SCHEDULES_INX-ITM_NUMBER = INO.
L_ORDER_SCHEDULES_IN-REQ_QTY = RECORD-KWMENG.
L_ORDER_SCHEDULES_INX-REQ_QTY = 'X'.
L_ORDER_SCHEDULES_INX-UPDATEFLAG = 'X'.
APPEND L_ORDER_SCHEDULES_IN TO
LI_ORDER_SCHEDULES_IN.
APPEND L_ORDER_SCHEDULES_INX TO
LI_ORDER_SCHEDULES_INX.
* Build Conditions
CLEAR: L_ORDER_CONDITIONS_IN,
L_ORDER_CONDITIONS_INX.
L_ORDER_CONDITIONS_IN-ITM_NUMBER = INO.
L_ORDER_CONDITIONS_IN-COND_COUNT = '01'.
L_ORDER_CONDITIONS_IN-COND_TYPE =
RECORD-KSCHL_1.
L_ORDER_CONDITIONS_IN-COND_VALUE =
RECORD-KBETR_1.
IF RECORD-KSCHL_1 = 'PR00'.
L_ORDER_CONDITIONS_IN-COND_VALUE =
L_ORDER_CONDITIONS_IN-COND_VALUE
/ 10.
ENDIF.
L_ORDER_CONDITIONS_INX-ITM_NUMBER = INO.
L_ORDER_CONDITIONS_INX-COND_COUNT = '01'.
L_ORDER_CONDITIONS_INX-COND_TYPE =
RECORD-KSCHL_1.
L_ORDER_CONDITIONS_INX-UPDATEFLAG = 'X'.
L_ORDER_CONDITIONS_INX-COND_VALUE = 'X'.
APPEND L_ORDER_CONDITIONS_IN TO
LI_ORDER_CONDITIONS_IN.
APPEND L_ORDER_CONDITIONS_INX TO
LI_ORDER_CONDITIONS_INX.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
ORDER_HEADER_IN =L_ORDER_HEADER_IN
ORDER_HEADER_INX = L_ORDER_HEADER_INX
IMPORTING
SALESDOCUMENT = L_VBELN
TABLES
RETURN = LI_RETURN
ORDER_ITEMS_IN =
LI_ORDER_ITEMS_IN
ORDER_ITEMS_INX =
LI_ORDER_ITEMS_INX
ORDER_PARTNERS =
LI_ORDER_PARTNERS
ORDER_SCHEDULES_IN =
LI_ORDER_SCHEDULES_IN
ORDER_SCHEDULES_INX =
LI_ORDER_SCHEDULES_INX
ORDER_CONDITIONS_IN =
LI_ORDER_CONDITIONS_IN
ORDER_CONDITIONS_INX =
LI_ORDER_CONDITIONS_INX
END-OF-SELECTION -
BAPI_SALESORDER_CREATEFROMDAT2 - Problem with price
Hi
I'm trying to create a Sales Document with the BAPI_SALESORDER_CREATEFROMDAT2 with SE37, i don't know what is missing, because it gives me the order number but when i call the BAPI_TRANSACTION_COMMIT, it doesn't create the document, the result of the BAPI_SALESORDER_CREATEFROMDAT2 is next:
S V4233SALES_HEADER_IN has been processed successfully
S V4233SALES_ITEM_IN has been processed successfully
W V1555The sales document is not yet complete: Edit data
S V1311Pedido Nacional 0000281711 has been saved
I feel the problem is in the parameters i'm sending, because i'm creating a sales order with VA01, and when debugging the BAPI and VA01, comparing table XVBAP at BAPI and VA01, i have difference at XVBAP-KWMENG and XVBAP-NETWR, at the BAPI'S table i don't have data, and at the VA01 transaction i have it, i give the parameters i'm sending so maybe somebody can help me.
<b>ORDER_HEADER_IN</b>
DOC_TYPE
SALES_ORG
DISTR_CHAN
DIVISION
REQ_DATE_H
PURCH_DATE
INCOTERMS1
PMNTTRMS
PRICE_DATE
PURCH_NO_C
<b>ORDER_ITEMS_IN</b>
MATERIAL
PLANT
TARGET_QTY
TARGET_QU
INCOTERMS1
ROUTE
<b>ORDER_PARTNERS</b>
PARTN_ROLE
PARTN_NUMB
And that's all.
Thanks
Best Regards.
Soraya CervantesSoraya,
You need to pass in the Pricing COnditions via the ORDER_CONDITIONS_IN and ORDER_CONDITIONS_INX parameters.
eg.
tbl_bapicond-itm_number = '000010'.
tbl_bapicond-cond_type = 'ZP01'.
tbl_bapicond-cond_value = '100'.
append tbl_bapicond.
tbl_bapicondx-itm_number = '000010'.
tbl_bapicondx-cond_type = 'ZP01'.
tbl_bapicondx-update_flag = 'U'.
tbl_bapicondx-cond_value = 'X'.
append tbl_bapicondx.
Hope this helps.
Cheers,
Pat.
PS. Kindly assign Reward Points to the posts you find helpful. -
Bapi_salesorder_createfromdat2 problem with filling Configuration values
Hi All,
I am trying to create a sales order using "bapi_salesorder_createfromdat2". Good part is I am able to create the sales order with item details, schedule line info and partners. However the BAPI did not fill the characteristic values.
Here I am giving the code snippet and request you to help me in identifying what I am missing or where i am doing wrong.
we checked in config and the material has perfectly configured for characteristics.
LOOP AT it_soitem_dtls INTO lwa_soitem_dtls.
wa_soitem_dtls = lwa_soitem_dtls.
lv_posnr = lv_posnr + 10.
lv_configid = lv_configid + 1.
CONDENSE lv_configid.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = lv_configid
IMPORTING
output = lv_configid.
* Fill the Item Configuration Characteristics
wa_order_cfgs_ref-posex = lv_posnr.
wa_order_cfgs_ref-config_id = wa_curef_out-config_id.
wa_order_cfgs_ref-root_id = wa_curef_out-inst_id.
APPEND wa_order_cfgs_ref TO it_order_cfgs_ref.
wa_order_cfgs_inst-config_id = wa_cuinst_out-config_id. "lv_configid.
wa_order_cfgs_inst-inst_id = wa_cuinst_out-inst_id.
wa_order_cfgs_inst-obj_type = 'MARA'.
wa_order_cfgs_inst-class_type = '300'.
wa_order_cfgs_inst-obj_key = wa_soitem_dtls-material.
wa_order_cfgs_inst-quantity = wa_soitem_dtls-qty * 1000.
CONDENSE wa_order_cfgs_inst-quantity.
wa_order_cfgs_inst-quantity_unit = 'KG'.
wa_order_cfgs_inst-complete = 'T'.
wa_order_cfgs_inst-consistent = 'T'.
wa_order_cfgs_inst-persist_id_type = 'G'.
APPEND wa_order_cfgs_inst TO it_order_cfgs_inst.
wa_order_cfgs_part_of-config_id = wa_cuinst_out-config_id. "lv_configid.
wa_order_cfgs_part_of-parent_id = wa_cuinst_out-inst_id.
wa_order_cfgs_part_of-inst_id = '00000001'.
wa_order_cfgs_part_of-obj_type = 'MARA'.
wa_order_cfgs_part_of-class_type = '300'.
wa_order_cfgs_part_of-obj_key = wa_soitem_dtls-material.
APPEND wa_order_cfgs_part_of TO it_order_cfgs_part_of.
wa_curef_in-posex = wa_soitem_dtls-contractitem. "lv_posnr.
wa_curef_in-config_id = wa_cuinst_out-config_id. "lv_configid.
wa_curef_in-inst_id = wa_cuinst_out-inst_id.
APPEND wa_curef_in TO it_curef_in.
wa_order_cfgs_value-config_id = p_configid.
wa_order_cfgs_value-inst_id = p_instanceid.
wa_order_cfgs_value-charc = p_char.
wa_order_cfgs_value-value = p_val.
APPEND wa_order_cfgs_value TO it_order_cfgs_value.
ENDLOOP.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = wa_so_header_in
convert = 'X'
IMPORTING
salesdocument = gv_vbeln
TABLES
return = it_return
order_items_in = it_order_item_in
order_schedules_in = it_order_schedules_in
order_partners = it_so_partners
order_cfgs_ref = it_order_cfgs_ref
order_cfgs_inst = it_order_cfgs_inst
order_cfgs_part_of = it_order_cfgs_part_of
order_cfgs_value = it_order_cfgs_value
order_cfgs_refinst = it_curef_in
order_text = it_so_texts.
* Roll back LUW if any error returned by BAPI otherwise commit
READ TABLE it_return WITH KEY type = 'E'
TRANSPORTING NO FIELDS.
IF sy-subrc = 0.
CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
ELSE.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = c_x.
ENDIF.
Thanks in advance for all your help.
Rgds,
Lakshmi
Please use code tags to make your code easier to read
Edited by: Rob Burbank on Dec 6, 2010 2:31 PMSoraya,
You need to pass in the Pricing COnditions via the ORDER_CONDITIONS_IN and ORDER_CONDITIONS_INX parameters.
eg.
tbl_bapicond-itm_number = '000010'.
tbl_bapicond-cond_type = 'ZP01'.
tbl_bapicond-cond_value = '100'.
append tbl_bapicond.
tbl_bapicondx-itm_number = '000010'.
tbl_bapicondx-cond_type = 'ZP01'.
tbl_bapicondx-update_flag = 'U'.
tbl_bapicondx-cond_value = 'X'.
append tbl_bapicondx.
Hope this helps.
Cheers,
Pat.
PS. Kindly assign Reward Points to the posts you find helpful.
Maybe you are looking for
-
Calculation in an add instance
I am trying to use an if statement in an addinstance of an interactive form. Based on the results of one field in the addinstance, I want to sum a different field from the add instance. So, the customer can add any number of rows and choose from a
-
This is really frusterating... It was gifted to me and if i knew updating to i07 would be such a pain i wouldnt have gone through with this! So if the pereson is either jailed or deceased what is the next option???? I know its for better security, bu
-
Is it possible to rotate video horiz/vert?
As a photographer, I frequently turn my camera vertically to shoot. Well, the new camera has video capabilities, and I did the same thing without thinking. Is there a way to rotate the video clip the way photos can be rotated? I have checked QTPro an
-
Missing web connectivity buttons in version 4.5
Tried re install but the Web Connectivity buttons don't show up, except for the Slide show and URL link ?? Thanks in advance RLM
-
Java Webservice Falut handling
I have one java class which I am exposing as webservice by using webservice annotation. I am able to pass the input and get the output normally, but incase of any error I need to pass two strings:faultdetails,faultmessage through the fault calss. So