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 Co
HI 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
Similar Messages
-
Order schedule lines not created using BAPI_SALESORDER_CREATEFROMDAT2
Hi experts,
I am creating sales order using BAPI_SALESORDER_CREATEFROMDAT2. I want to update the Order quantity in VBAP-KWMENG.I got the information from SDN when including the Schedule line in BAPI 'BAPI_SALESORDER_CREATEFROMDAT2 '.
I tried by using Update flag = 'I'.I am not able to update, what are the values to be passed and how to update the field.
Is there any other way..Please suggest me..
Thanks&Regards,
Karthik.Hi, In the BAPI if you look at the tables parameter you will find ORDER_ITEMS_IN and ORDER_ITEMS_INX as well as ORDER_SCHEDULES_IN and ORDER_SCHEDULES_INX. To update KWMENG you will have to pass that value to ORDER_ITEMS_IN-TARGET_QTY and update the same in the table ORDER_ITEMS_INX (ORDER_ITEMS_INX-TARGET_QTY) with 'X'.
For updating schedule line go for ORDER_SCHEDULES_IN-SCHED_LINE and update X for the same in ORDER_SCHEDULES_INX.
Try looking into the following code, I am filling in both the Item data as well as the Schedule line data.
loop at t_mdata into fs_mdata.
fs_item-itm_number = fs_mdata-posnr.
fs_itemx-itm_number = c_flag.
fs_item-material = fs_mdata-matnr.
fs_itemx-material = c_flag.
fs_item-target_qty = fs_mdata-kwmeng.
fs_itemx-target_qty = c_flag.
fs_item-item_categ = fs_mdata-pstyv.
fs_itemx-item_categ = c_flag.
fs_itemx-updateflag = c_flag.
APPEND fs_item TO t_item.
APPEND fs_itemx TO t_itemx.
fs_sline-ITM_NUMBER = fs_mdata-posnr.
fs_slinex-ITM_NUMBER = c_flag.
fs_sline-SCHED_LINE = c_sline.
fs_slinex-SCHED_LINE = c_flag.
fs_sline-REQ_QTY = fs_mdata-kwmeng.
fs_slinex-REQ_QTY = c_flag.
APPEND fs_sline TO t_sline.
APPEND fs_slinex TO t_slinex.
endloop. " Loop t_mdata
c_flag contains 'X'.
fs_item is of structure ORDER_ITEMS_IN.
fs_sline is of structure ORDER_SCHEDULES_IN. -
Quantity is not updating while using BAPI_SALESORDER_CREATEFROMDAT2
Hi all,
i am Creating Sales Order using BAPI_SALESORDER_CREATEFROMDAT2 BAPI,
Here i am passing all required fields. Sales order also created, but in the created order; quantiy value is updating as 0 only. Even though i passed the value.(BAPISDITM-ARGET_QTY)
My bapi is returning...
SALES_HEADER_IN has been processed successfully
SALES_ITEM_IN has been processed successfully
The sales document is not yet complete: Edit data
Standard Order 12323 has been saved
Help me to solve it.
Thanks
RegardsYou cannot update quantinty from that field
use the REQ_QTY field in ORDER_SCHEDULES_IN
and set its corresponding flag in ORDER_SCHEDULES_INX to X
It will work -
Error when creating sales order using BAPI_SALESORDER_CREATEFROMDAT2
Hello!
I am using BAPI_SALESORDER_CREATEFROMDAT2 for creating the Sales order. But I have a problem when Iu2019m trying to create configuration. I think that parameter order_items_in-material should be generated before calling BAPI described above. I try to use order_items_in-mat_entrd, but BAPI return error message id = V1, number = 320 (No item category available (Table T184 ZAPC TEXT )).
Help me please, How I can solve this problem?<P><STRONG>FUNCTION Z_SD_GET_TEH_COST.<BR>"----<BR>" IMPORTING<BR>" REFERENCE(IS_COST_ORDER) TYPE ZWCLIF_COST_ORDER<BR>" EXPORTING<BR>" REFERENCE(EV_KBETR) TYPE KBETR<BR>"----
</STRONG></P>
<P><STRONG> DEFINE fill_prizn.<BR> IF is_cost_order-&1 IS NOT INITIAL.<BR> CLEAR: ls_cfgs_value-charc,<BR> ls_cfgs_value-value.<BR> ls_cfgs_value-charc = &2.<BR> ls_cfgs_value-value = is_cost_order-&1.<BR>* ls_cfgs_value-valcode = '1'.<BR> APPEND ls_cfgs_value TO lt_cfgs_value.<BR> ENDIF.<BR> END-OF-DEFINITION.</STRONG></P>
<P><STRONG>DATA: ls_header_in TYPE bapisdhd1,<BR> ls_header_inx TYPE bapisdhd1x,</STRONG></P>
<P><STRONG> lt_partners TYPE TABLE OF bapiparnr,<BR> ls_partners TYPE bapiparnr,</STRONG></P>
<P><STRONG> lt_items_in TYPE TABLE OF bapisditm,<BR> lt_items_inx TYPE TABLE OF bapisditmx,</STRONG></P>
<P><STRONG> ls_items_in TYPE bapisditm,<BR> ls_items_inx TYPE bapisditmx,</STRONG></P>
<P><STRONG> ls_cfgs_ref TYPE bapicucfg,<BR> lt_cfgs_ref TYPE TABLE OF bapicucfg,</STRONG></P>
<P><STRONG> lt_cfgs_value TYPE TABLE OF bapicuval,<BR> ls_cfgs_value TYPE bapicuval,</STRONG></P>
<P><STRONG> lt_schedules_in TYPE TABLE OF bapischdl,<BR> ls_schedules_in TYPE bapischdl,</STRONG></P>
<P><STRONG> lt_schedules_inx TYPE TABLE OF bapischdlx,<BR> ls_schedules_inx TYPE bapischdlx,</STRONG></P>
<P><STRONG> lt_cfgs_inst TYPE TABLE OF bapicuins,<BR> ls_cfgs_inst TYPE bapicuins,<BR> lt_cfgs_partof TYPE TABLE OF bapicuprt,<BR> ls_cfgs_partof TYPE bapicuprt,</STRONG></P>
<P><STRONG> lv_vbeln TYPE bapivbeln-vbeln,<BR> lt_return TYPE TABLE OF bapiret2.</STRONG></P>
<P><STRONG>* fill header<BR> ls_header_in-doc_type = 'ZAPC'.<BR> ls_header_in-sales_org = is_cost_order-vkorg.<BR> ls_header_in-distr_chan = is_cost_order-vtweg.<BR> ls_header_in-division = '01'.<BR> ls_header_in-sales_off = '1011'.</STRONG></P>
<P><STRONG> ls_header_inx-updateflag = 'I'.<BR> ls_header_inx-doc_type = 'X'.<BR> ls_header_inx-sales_org = 'X'.<BR> ls_header_inx-distr_chan = 'X'.<BR> ls_header_inx-division = 'X'.<BR> ls_header_inx-sales_off = 'X'.</STRONG></P>
<P><STRONG>* fill partners<BR> ls_partners-partn_role = 'AG'.<BR> ls_partners-partn_numb = '1000000031'. " фиктивный заказчик<BR> APPEND ls_partners TO lt_partners.</STRONG></P>
<P><STRONG>* ls_items_in-material = is_cost_order-matnr.<BR> ls_items_in-mat_entrd = is_cost_order-matnr.<BR> ls_items_in-target_qty = '1'.<BR> ls_items_in-itm_number = '000001'.<BR> ls_items_in-po_itm_no = '000001'.<BR> ls_items_in-item_categ = 'ZCRM'.<BR> SELECT SINGLE meins INTO ls_items_in-target_qu<BR> FROM mara<BR> WHERE matnr = is_cost_order-matnr.<BR> APPEND ls_items_in TO lt_items_in.</STRONG></P>
<P><STRONG> ls_items_inx-itm_number = '000001'.<BR> ls_items_inx-item_categ = 'X'.<BR> ls_items_inx-po_itm_no = 'X'.<BR>* ls_items_inx-material = 'X'.<BR> ls_items_inx-mat_entrd = 'X'.<BR> ls_items_inx-target_qty = 'X'.<BR> ls_items_inx-target_qu = 'X'.<BR> ls_items_inx-updateflag = 'I'.<BR> APPEND ls_items_inx TO lt_items_inx.</STRONG></P>
<P><STRONG>* fill configuration<BR> ls_cfgs_ref-posex = '000001'.<BR> ls_cfgs_ref-config_id = '000001'.<BR> ls_cfgs_ref-root_id = '00000001'.<BR> APPEND ls_cfgs_ref TO lt_cfgs_ref.</STRONG></P>
<P><STRONG> ls_cfgs_value-config_id = '000001'.<BR> ls_cfgs_value-inst_id = '00000001'.</STRONG></P>
<P><STRONG> fill_prizn kod_prod 'KOD_PROD'.<BR> fill_prizn tlot_min 'TLOT_MIN'.<BR> fill_prizn tlot_max 'TLOT_MAX'.<BR> fill_prizn shot_min 'SHOT_MIN'.<BR> fill_prizn shot_max 'SHOT_MAX'.<BR> fill_prizn dlot_min 'DLOT_MIN'.<BR> fill_prizn dlot_max 'DLOT_MAX'.<BR> fill_prizn marka 'MARKA'.<BR> fill_prizn stndrt_marka 'STNDRT_MARKA'.<BR> fill_prizn stndrt_prod 'STNDRT_PROD'.<BR> fill_prizn tprk 'TPRK'.<BR> fill_prizn grot 'GROT'.<BR> fill_prizn vityazhka 'VITYAZHKA'.<BR> fill_prizn krom 'KROM'.<BR> fill_prizn chisl_st_pokr 'CHISL_ST_POKR'.<BR> fill_prizn kls_tol_pokr 'KLS_TOL_POKR'.<BR> fill_prizn proch_izg_t_lic_max 'PROCH_IZG_T_LIC_MAX'.<BR> fill_prizn priz_zasch_pov 'PRIZ_ZASCH_POV'.<BR> fill_prizn vid_pokr 'VID_POKR'.<BR> fill_prizn mark_pokr 'MARK_POKR'.<BR> fill_prizn mat_pokr_lic 'MAT_POKR_LIC'.<BR> fill_prizn plsk 'PLSK'.<BR> fill_prizn vid_postavki 'VID_POSTAVKI'.<BR> fill_prizn dressir 'DRESSIR'.<BR> fill_prizn travl 'TRAVL'.<BR> fill_prizn fsfr_min 'FSFR_MIN'.<BR> fill_prizn fsfr_max 'FSFR_MAX'.<BR> fill_prizn krmn_min 'KRMN_MIN'.<BR> fill_prizn krmn_max 'KRMN_MAX'.<BR> fill_prizn mrgn_min 'MRGN_MIN'.<BR> fill_prizn mrgn_max 'MRGN_MAX'.<BR> fill_prizn almn_min 'ALMN_MIN'.<BR> fill_prizn almn_max 'ALMN_MAX'.<BR> fill_prizn cugl_min 'CUGL_MIN'.<BR> fill_prizn cugl_max 'CUGL_MAX'.</STRONG></P>
<P><STRONG> ls_schedules_in-itm_number = '000001'.<BR>* ls_schedules_in-req_date = sy-datum.<BR> ls_schedules_in-sched_line = '0001'.<BR> ls_schedules_in-req_qty = '1'.<BR> APPEND ls_schedules_in TO lt_schedules_in.</STRONG></P>
<P><STRONG> ls_schedules_inx-itm_number = '000001'.<BR> ls_schedules_inx-sched_line = '0001'.<BR>* ls_schedules_inx-req_date = 'X'.<BR> ls_schedules_inx-req_qty = 'X'.<BR> ls_schedules_inx-updateflag = 'I'.<BR> APPEND ls_schedules_inx TO lt_schedules_inx.</STRONG></P>
<P><STRONG> ls_cfgs_partof-parent_id = '00000001'.<BR> ls_cfgs_partof-inst_id = '00000001'.<BR> ls_cfgs_partof-class_type = '300'.<BR> ls_cfgs_partof-obj_type = 'MARA'.<BR> ls_cfgs_partof-obj_key = is_cost_order-matnr.<BR> APPEND ls_cfgs_partof TO lt_cfgs_partof.</STRONG></P>
<P><STRONG> ls_cfgs_inst-config_id = '000001'.<BR> ls_cfgs_inst-inst_id = '00000001'.<BR> ls_cfgs_inst-obj_type = 'MARA'.<BR> ls_cfgs_inst-class_type = '300'.<BR> ls_cfgs_inst-obj_key = is_cost_order-matnr.<BR> APPEND ls_cfgs_inst TO lt_cfgs_inst.</STRONG></P>
<P><STRONG> CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'<BR> EXPORTING<BR> order_header_in = ls_header_in<BR> order_header_inx = ls_header_inx<BR>* testrun =<BR> IMPORTING<BR> salesdocument = lv_vbeln<BR> TABLES<BR> return = lt_return<BR> order_items_in = lt_items_in<BR> order_items_inx = lt_items_inx<BR> order_partners = lt_partners<BR> order_schedules_in = lt_schedules_in<BR> order_schedules_inx = lt_schedules_inx<BR> order_cfgs_ref = lt_cfgs_ref<BR> order_cfgs_inst = lt_cfgs_inst<BR> order_cfgs_part_of = lt_cfgs_partof<BR> order_cfgs_value = lt_cfgs_value<BR> .</STRONG></P>
<P><STRONG> READ TABLE lt_return TRANSPORTING NO FIELDS WITH KEY type = 'E'.<BR> IF sy-subrc = 0.<BR> CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'<BR> .<BR> ELSE.<BR> CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'<BR> EXPORTING<BR> wait = 'X'<BR> .<BR> ENDIF.</STRONG></P>
<P><STRONG>ENDFUNCTION.</STRONG></P>
<P><STRONG></STRONG> </P>
<P><STRONG></STRONG> </P> -
Hi when I use BAPI_SALESORDER_CREATEFROMDAT2 order quantity is empty (missing also in the inclompent log in VA03)
why ? what should be also set ? thanks a lot !
I set this data:
ls_order_header_in-doc_type = 'TA'.
ls_order_header_in-sales_org = '1000'.
ls_order_header_in-distr_chan = '01'.
ls_order_header_in-division = '01'.
ls_order_header_in-PURCH_NO_C = 'test'.
ls_order_partners-partn_role = 'AG'.
ls_order_partners-partn_numb = 'CH10'.
APPEND ls_order_partners TO lt_order_partners.
ls_order_item_in-material = 'S-000'.
APPEND ls_order_item_in TO lt_order_item_in.
ls_order_cfgs_value-charc = 'S001'.
ls_order_cfgs_value-value = '1'.
APPEND ls_order_cfgs_value TO lt_order_cfgs_value.
ls_order_cfgs_value-charc = 'S002'.
ls_order_cfgs_value-value = '1'.
APPEND ls_order_cfgs_value TO lt_order_cfgs_value.
ls_order_cfgs_value-charc = 'S002'.
ls_order_cfgs_value-value = '2'.
APPEND ls_order_cfgs_value TO lt_order_cfgs_value.
ls_order_cfgs_value-charc = 'S003'.
ls_order_cfgs_value-value = '1'.
APPEND ls_order_cfgs_value TO lt_order_cfgs_value.
ls_order_cfgs_value-charc = 'S003'.
ls_order_cfgs_value-value = '3'.
APPEND ls_order_cfgs_value TO lt_order_cfgs_value.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
* SALESDOCUMENTIN =
order_header_in = ls_order_header_in
* ORDER_HEADER_INX =
* SENDER =
* BINARY_RELATIONSHIPTYPE =
* INT_NUMBER_ASSIGNMENT =
* BEHAVE_WHEN_ERROR =
* LOGIC_SWITCH =
* TESTRUN =
* CONVERT = ' '
* IMPORTING
* SALESDOCUMENT =
TABLES
return = lt_return
order_items_in = lt_order_item_in
* ORDER_ITEMS_INX =
order_partners = lt_order_partners
* ORDER_SCHEDULES_IN =
* ORDER_SCHEDULES_INX =
* ORDER_CONDITIONS_IN =
* ORDER_CONDITIONS_INX =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
order_cfgs_value = lt_order_cfgs_value.
* ORDER_CFGS_BLOB =
* ORDER_CFGS_VK =
* ORDER_CFGS_REFINST =
* ORDER_CCARD =
* ORDER_TEXT =
* ORDER_KEYS =
* EXTENSIONIN =
* PARTNERADDRESSES =
* NFMETALLITMS =
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'We use the same BAPI to process Web orders into SAP. You have to have a corresponding ORDER_SCHEDULES_IN entry with matching ITM_NUMBER for every ORDER_ITEMS_IN entry. Within ORDER_SCHEDULES_IN is where you put the quantity. Should be stored in REQ_QTY. We had to fill ITM_NUMBER and SCHED_LINE with the line number value in order to make it work. Remember to fill in your corresponding X-structure fields as well.
hope this helps,
Chad -
Salesorder created using BAPI_SALESORDER_CREATEFROMDAT2 not visible in VBAK
Hi Experts,
I created sales order using BAPI_SALESORDER_CREATEFROMDAT2, further salesorder ID was also indicated after creation.
But the same order ID is not visible in SD standard table VBAK.
Pls guide me to a valid standard CREATE BAPI for Sales order.
Regards,
Romi MalikHi Romi,
If you created a document through BAPI and it does not appear in the database afterwards, the logical conclusion is that ...
No it wasn't really created
With BAPIs for sales order data loading, there is no automatic COMMIT! (check SAP notes).
You need to add the call to BAPI BAPI_TRANSACTION_COMMIT to save to DB.
Regards,
Franck -
How to add new line item to SO using BAPI_SALESORDER_CREATEFROMDAT2
Hi,
I have sales order A with 1 line item, now i want to add new line item with material x and quantity y to the existing sales order A
using BAPI_SALESORDER_CREATEFROMDAT2.
Line item no for new line item should be generated by SAP internally.Please let me know the mandatory parameters to be passed to the BAPI to fulfill the requirement.
DATA: order_header TYPE bapisdhd1,
order_inx TYPE bapisdhd1x,
partners TYPE TABLE OF bapiparnr,
wa_partners TYPE bapiparnr.
CLEAR: salesdocument,order_header_inx,wa_in, wa_inx.
REFRESH: item_in, item_inx.
salesdocument = wa_vbup-vbeln.
order_header_inx-updateflag = 'X'.
wa_in-itm_number = ' '.
wa_in-material = p_nmatnr.
wa_in-target_qty = gv_menge - gv_wemng.
APPEND wa_in TO item_in.
wa_inx-itm_number = ' '.
wa_inx-updateflag = 'U'.
wa_inx-target_qty = 'X'.
APPEND wa_inx TO item_inx.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
salesdocumentin = salesdocument
order_header_in = order_header
order_header_inx = order_inx
IMPORTING
salesdocument = salesdocument
TABLES
return = return
order_items_in = item_in
order_items_inx = item_inx
order_partners = partners.
Thanks
BhuvanaHello,
You can use FM: BAPI_SALESORDER_CHANGE with update indicator I (insert)
call function 'BAPI_SALESORDER_CHANGE'
exporting
salesdocument = l_vbeln
order_header_inx = l_wa_order_header_inx
simulation = l_simulation
tables
return = l_i_return
order_item_in = l_i_order_item
order_item_inx = l_i_order_item_inx
partners = l_i_partners
schedule_lines = l_i_schedule_lines
schedule_linesx = l_i_schedule_linesx
extensionin = l_i_extensionin.
Thanks
Subhankar -
How to upload a data using BAPI_SALESORDER_CREATEFROMDAT2 without using LSM
Hi,
I want to upload a data from an input file on the presentation server using BAPI_SALESORDER_CREATEFROMDAT2 first uploading the data and then creating sales orders out of it.
I will be highly obliged if anyone can guide me with it.
I have tried the same using LSMW got succeeded in posting the idocs correctly and now I want to do it without using LSMW. The main intention of not using LSMW is that after creating sales orders, I want to display the messages related to number of sales order created, Number of records uploaded, Number of records.Hi
BAPI_SALESORDER_CREATEFROMDAT2
Text
Sales order: Create Sales Order
Functionality
You can use this method to create sales orders.
You must enter at least sales order header data (via ORDER_HEADER_IN structure) and partner data (via the ORDER_PARTNERS table) as input parameters.
Enter the item data via the ORDER_ITEMS_IN table. You can allocate item numbers manually, by filling in the relevant fields, or the system does it, according to the settings for Customizing, by leaving the relevant fields blank.
If you have configurable items, you must enter the configuration data in the ORDER_CFGS_REF, ORDER_CFGS_INST, ORDER_CFGS_PART_OF and ORDER_CFGS_VALUE tables.
Credit cards can be transferred via the BAPICCARD structure, on the one hand, data for card identification, on the other, data for a transaction which has taken place in an external system.
Once you have created the sales order successfully, you will receive the document number (SALESDOCUMENT field). Any errors that may occur will be announced via the RETURN parameter.
If no sales area has been created in the sales order header, then the system creates the sales area from the sold-to party or ship-to party, who has been entered in the partner table. If a clear sales area cannot be created, you will receive a system message, and the sales order will not be created.
Notes
1. Mandatory entries:
ORDER_HEADER_IN : DOC_TYPE Sales document type
SALES_ORG Sales organization
DISTR_CHAN Distribution channel
DIVISION Division
ORDER_PARTNERS..: PARTN_ROLE Partner role, SP sold-to party
PARTN_NUMB Customer number
ORDER_ITEMS_IN..: MATERIAL Material number
2. Ship-to party:
If no ship-to party is entered, use the following: Ship-to party =
sold-to party.
3. Commit control:
The BAPI does not have a database commit. This means that the relevant application must leave the commit, in order that can be carried out on on the database. The BAPI BAPI_TRANSACTION_COMMIT is available for this.
4. German key words:
The following key words must be entered in German, independantly of
the logon language:
DOC_TYPE Sales document type, for example: TA for standard order
PARTN_ROLE Partner role, for example: WE for ship-to party
Further Information
You can find further information in the OSS. The note 93091 contains general information on the BAPIs in SD.
Parameters
SALESDOCUMENTIN
ORDER_HEADER_IN
ORDER_HEADER_INX
SENDER
BINARY_RELATIONSHIPTYPE
INT_NUMBER_ASSIGNMENT
BEHAVE_WHEN_ERROR
LOGIC_SWITCH
TESTRUN
CONVERT
SALESDOCUMENT
RETURN
ORDER_ITEMS_IN
ORDER_ITEMS_INX
ORDER_PARTNERS
ORDER_SCHEDULES_IN
ORDER_SCHEDULES_INX
ORDER_CONDITIONS_IN
ORDER_CONDITIONS_INX
ORDER_CFGS_REF
ORDER_CFGS_INST
ORDER_CFGS_PART_OF
ORDER_CFGS_VALUE
ORDER_CFGS_BLOB
ORDER_CFGS_VK
ORDER_CFGS_REFINST
ORDER_CCARD
ORDER_TEXT
ORDER_KEYS
EXTENSIONIN
PARTNERADDRESSES
Regards
Raj -
Use BAPI_SALESORDER_CREATEFROMDAT2 with delivery date in Header
Hi all,
In my current project I try to use BAPI_SALESORDER_CREATEFROMDAT2 to create the SO ,
I can create the SO without setting delivery date in header.
but after I set the delivery date like following, the error message occured. Could someone help me?
ORDER_HEADER_IN-REQ_DATE_H = '20110330'
ORDER_HEADER_IN-DATE_TYPE = '1'
I try to add the requirment delivery date in schedule line ,but fail too.
ORDER_SCHEDULES_IN-REQ_DATE = '20110405'
ORDER_SCHEDULES_IN-DATE_TYPE = '1'Nothing special,
TYPE: e
ID: V4
NUMBER: 219
MESSAGE :Sales document was not changed
I try to see the log in ST22 too. but nothing in there.
I also try to use BAPI_SALESORDER_SIMULATE to generat SO ITEM to fill
the ORDER_ITEMS_IN (after some data formate translated) but, still got the same result.
My codes in VS as following:
when without delivery date setting, the SO is OK, So I belive the data transport is fine.
The promble is mainly occur in BAPI.
IRfcFunction function = repo.CreateFunction("ZCMT_RFC_SO_CREATE2");
//importing parameter
IRfcStructure salehd = function.GetStructure("ORDER_HEADER_IN");
IRfcStructure salehdx = function.GetStructure("ORDER_HEADER_INX");
//Tables
IRfcTable returntable = function.GetTable("RETURN");
IRfcTable item = function.GetTable("ORDER_ITEMS_IN");
IRfcTable itemx = function.GetTable("ORDER_ITEMS_INX");
IRfcTable partner = function.GetTable("ORDER_PARTNERS");
IRfcTable schedule = function.GetTable("ORDER_SCHEDULES_IN");
IRfcTable schedulex = function.GetTable("ORDER_SCHEDULES_INX");
//IRfcTable condition = function.GetTable("ORDER_CONDITIONS_IN"); //commented
//IRfcTable conditionx = function.GetTable("ORDER_CONDITIONS_INX"); //commented
//* Build order header
salehd.SetValue("DOC_TYPE", "ZOR");
salehd.SetValue("SALES_ORG", "2011");
salehd.SetValue("DISTR_CHAN", "01");
salehd.SetValue("DIVISION","00");
salehd.SetValue("REQ_DATE_H", "20110412");
salehd.SetValue("DATE_TYPE", "1");
salehd.SetValue("PURCH_NO_C", "test");
salehd.SetValue("PRICE_DATE", "20110331");
salehd.SetValue("PMNTTRMS", "0002");
salehdx.SetValue("UPDATEFLAG", "I");
salehdx.SetValue("DOC_TYPE","X");
salehdx.SetValue("SALES_ORG","X");
salehdx.SetValue("DISTR_CHAN","X");
salehdx.SetValue("DIVISION","X");
salehdx.SetValue("REQ_DATE_H", "X");
salehdx.SetValue("DATE_TYPE", "X");
salehdx.SetValue("PURCH_NO_C", "X");
salehdx.SetValue("PRICE_DATE", "X");
salehdx.SetValue("PMNTTRMS", "X");
//* Build order item(s) - Only 1 is used in this example
item.Append();
item[0].SetValue("ITM_NUMBER", "000010");
item[0].SetValue("MATERIAL", "HMS690C-T002-A1");
item[0].SetValue("PLANT", "2011");
item[0].SetValue("TARGET_QTY", "3.000");
item[0].SetValue("SALES_UNIT", "PCS");
itemx.Append();
itemx[0].SetValue("UPDATEFLAG", "I");
itemx[0].SetValue("ITM_NUMBER", "000000");
itemx[0].SetValue("MATERIAL", "X");
itemx[0].SetValue("PLANT", "X");
itemx[0].SetValue("STORE_LOC", "X");
itemx[0].SetValue("TARGET_QTY", "X");
itemx[0].SetValue("SALES_UNIT", "X");
schedule.Append();
schedule[0].SetValue("ITM_NUMBER", "000010");
schedule[0].SetValue("SCHED_LINE", "0001");
schedule[0].SetValue("REQ_QTY", "3.000");
schedule[0].SetValue("REQ_DATE", "20110331");
schedule[0].SetValue("DATE_TYPE", "1");
schedulex.Append();
schedulex[0].SetValue("UPDATEFLAG", "I");
schedulex[0].SetValue("ITM_NUMBER", "000010");
schedulex[0].SetValue("SCHED_LINE", "0001");
schedulex[0].SetValue("REQ_QTY", "X");
schedulex[0].SetValue("REQ_DATE", "X");
schedulex[0].SetValue("DATE_TYPE", "X");
//* Build partner information
partner.Append(2);
partner[0].SetValue("PARTN_ROLE", "AG");
partner[0].SetValue("PARTN_NUMB", "C10006");
partner[1].SetValue("PARTN_ROLE", "WE");
partner[1].SetValue("PARTN_NUMB", "C10006"); -
Configuartion data is not populated using BAPI_SALESORDER_CREATEFROMDAT2
Hi All,
I am using BAPI_SALESORDER_CREATEFROMDAT2 to create the sales order and to add the characteristics for my material in the configuration.
my code for configuration to BaPI
w_order_cfgs_ref-posex = '000010'.
w_order_cfgs_ref-config_id = '1'.
w_order_cfgs_ref-root_id = '00000001'.
w_order_cfgs_ref-complete = 'T'.
w_order_cfgs_ref-consistent = 'T'.
w_order_cfgs_ref-sce = '1'.
w_order_cfgs_ref-kbname = w_sdsales_sap-matnr.
w_order_cfgs_ref-kbversion = '1'.
append w_order_cfgs_ref to i_order_cfgs_ref.
INSTANCE
w_order_cfgs_inst-config_id = '1'.
w_order_cfgs_inst-inst_id = '00000001' .
w_order_cfgs_inst-obj_type = 'MARA'.
w_order_cfgs_inst-class_type = '300'.
w_order_cfgs_inst-complete = 'T'.
w_order_cfgs_inst-consistent = 'T'.
w_order_cfgs_inst-OBJ_TYPE = .
w_order_cfgs_inst-obj_key = w_sdsales_sap-matnr.
append w_order_cfgs_inst to i_order_cfgs_inst.
w_order_cfgs_part_of-config_id = '1'.
w_order_cfgs_part_of-inst_id = '00000001' ..
w_order_cfgs_part_of-obj_type = 'MARA'.
w_order_cfgs_part_of-class_type = '300' .
w_order_cfgs_part_of-obj_key = w_sdsales_sap-matnr .
append w_order_cfgs_part_of to i_order_cfgs_part_of.
*characteristics value
w_order_cfgs_value-config_id = '2'.
w_order_cfgs_value-inst_id = '00000001'.
w_order_cfgs_value-charc = 'VC_MODEL'(025).
w_order_cfgs_value-value = w_sdsales_sap-model.
w_order_cfgs_value-valcode = '1'.
append w_order_cfgs_value to i_order_cfgs_value.
It is creating sales order but configuration data is not getting populated in the sales order item.
Please advise me
Thanks in adv
sangeethahi see this
SAP Note number 774346 -
Clear WBS field in sales order using bapi_salesorder_createfromdat2.
Hi,
Situation is this, I have a sales order, where the WBS element in the line item is populated. I want to clear that field to blank and save the sales order.
When I try to do that using the bapi_salesorder_createfromdat2, it says that it is successful, but when I go back to the sales order and see that field is still populated and not cleared. But the same field if I clear it through VA02 it works fine.
Header level update flag is set as 'U'.
I have tried setting up 'D' 'U' and 'I' for the update flag for the line item. Still no luck.
Given below is the sample code, did anybody else also faced the same issue.
Data Section.
data : sal_t_in type standard table of BAPISDHD1,
sal_s_in like line of sal_t_in.
*data : sal_t_in type standard table of BAPISDH1,
* sal_s_in like line of sal_t_in.
data : ret_t type standard table of bapiret2,
ret_s like line of ret_t.
data : partner_t type standard table of bapiparnr,
partner_s like line of partner_t.
data : item_t type standard table of bapisditm,
item_s like line of item_t.
data : item_t_inx type standard table of BAPISDITMX,
item_s_inx like line of item_t_inx.
data : schdl_t type standard table of BAPISCHDL,
schdl_s like line of schdl_t.
data : schdl_t_inx type standard table of BAPISCHDLX,
schdl_s_inx like line of schdl_t_inx.
data : ord_view type order_view.
data : sal_t_key type standard table of sales_key,
sal_s_key like line of sal_t_key.
data : ord_t_hdr type standard table of bapisdhd,
ord_s_hdr like line of ord_t_hdr.
data : ord_t_itm type standard table of bapisdit,
ord_s_itm like line of ord_t_itm.
data : hdr_inx type BAPISDHD1X.
data : hdr2_inx type BAPISDH1X.
data : qty type DZMENG.
data : logic_switch type BAPISDLS.
data : sd_doc_out type BAPIVBELN-VBELN.
data : sd_hdr_out type BAPISDHD.
data : sd_hdr_stat type BAPISDHDST.
Logic Section.
sal_s_in-doc_type = 'ZOR'.
hdr_inx-updateflag = 'U'.
ord_view-header = 'X'.
ord_view-item = 'X'.
sal_s_key-vbeln = '0000001067'.
append sal_s_key to sal_t_key.
call function 'BAPISDORDER_GETDETAILEDLIST'
exporting
i_bapi_view = ord_view
* I_MEMORY_READ =
tables
sales_documents = sal_t_key
ORDER_HEADERS_OUT = ord_t_hdr
ORDER_ITEMS_OUT = ord_t_itm
* ORDER_SCHEDULES_OUT =
* ORDER_BUSINESS_OUT =
* ORDER_PARTNERS_OUT =
* ORDER_ADDRESS_OUT =
* ORDER_STATUSHEADERS_OUT =
* ORDER_STATUSITEMS_OUT =
* ORDER_CONDITIONS_OUT =
* ORDER_COND_HEAD =
* ORDER_COND_ITEM =
* ORDER_COND_QTY_SCALE =
* ORDER_COND_VAL_SCALE =
* ORDER_CONTRACTS_OUT =
* ORDER_TEXTHEADERS_OUT =
* ORDER_TEXTLINES_OUT =
* ORDER_FLOWS_OUT =
* ORDER_CFGS_CUREFS_OUT =
* ORDER_CFGS_CUCFGS_OUT =
* ORDER_CFGS_CUINS_OUT =
* ORDER_CFGS_CUPRTS_OUT =
* ORDER_CFGS_CUVALS_OUT =
* ORDER_CFGS_CUBLBS_OUT =
* ORDER_CFGS_CUVKS_OUT =
* ORDER_BILLINGPLANS_OUT =
* ORDER_BILLINGDATES_OUT =
* ORDER_CREDITCARDS_OUT =
* EXTENSIONOUT =
loop at ord_t_itm into ord_s_itm.
move-corresponding ord_s_itm to item_s.
call function 'CONVERSION_EXIT_ABPSP_OUTPUT'
exporting
input = item_s-WBS_ELEM
IMPORTING
OUTPUT = item_s-WBS_ELEM
*move space to item_s-WBS_ELEM.
append item_s to item_t.
endloop.
clear item_s_inx.
item_s_inx-updateflag = 'D'.
item_s_inx-wbs_elem = 'X'.
append item_s_inx to item_t_inx.
call function 'BAPI_SALESORDER_CREATEFROMDAT2'
exporting
SALESDOCUMENTIN = '0000001067'
order_header_in = sal_s_in
ORDER_HEADER_INX = hdr_inx
* SENDER =
* BINARY_RELATIONSHIPTYPE =
* INT_NUMBER_ASSIGNMENT =
* BEHAVE_WHEN_ERROR =
* LOGIC_SWITCH =
* TESTRUN =
* CONVERT = ' '
* IMPORTING
* SALESDOCUMENT =
tables
RETURN = ret_t
ORDER_ITEMS_IN = item_t
ORDER_ITEMS_INX = item_t_inx
order_partners = partner_t
* ORDER_SCHEDULES_IN =
* ORDER_SCHEDULES_INX =
* ORDER_CONDITIONS_IN =
* ORDER_CONDITIONS_INX =
* ORDER_CFGS_REF =
* ORDER_CFGS_INST =
* ORDER_CFGS_PART_OF =
* ORDER_CFGS_VALUE =
* ORDER_CFGS_BLOB =
* ORDER_CFGS_VK =
* ORDER_CFGS_REFINST =
* ORDER_CCARD =
* ORDER_TEXT =
* ORDER_KEYS =
* EXTENSIONIN =
* PARTNERADDRESSES =
call function 'BAPI_TRANSACTION_COMMIT'
* EXPORTING
* WAIT =
* IMPORTING
* RETURN =
Result I get when I execute is
S V4 233 SALES_HEADER_IN has been processed successfully VBAKKOM
S V4 233 SALES_ITEM_IN has been processed successfully VBAPKOM 000001
S V1 311 Standard order 1067 has been saved Standard order 1067
Which means it says it save successfully..but data is not changed.
Any Ideas??
Thanks and Regards,
Mahesh.Hi,
The problem is fixed. The item inx table I was not passing the item number field, so the bapi was not knowing which line item to update.
It was a stupid overlook on my part.
Thanks and Regards,
Mahesh. -
Error in sales order creation using BAPI_SALESORDER_CREATEFROMDAT2
Hi all,
Pl look into below code :
Here order is getting created , however ship to party and sold to party shows the same value.
*& Report ZSD_SALEORDCRE
report zsd_saleordcre.
Order header:*
- Order type: OR Important you must use the german code TA*
- Sales org: 1000*
- Distrb. chan.: 10*
- Division: 00*
- Sold to party: 1032*
- Ship to party: 1032*
- Purch order: DG-19970626-3*
Order item:*
- Material: P-100*
- Qty: 1*
data:
Order partners*
li_order_partners type standard table of bapiparnr,
l_order_partners like bapiparnr,
Structures for order header*
l_order_header_in like bapisdhd1,
l_order_header_inx like bapisdhd1x,
Tables for order items*
li_order_items_in type standard table of bapisditm,
l_order_items_in like bapisditm,
li_order_items_inx type standard table of bapisditmx,
l_order_items_inx like bapisditmx,
schedules*
li_order_schedules_in type standard table of bapischdl,
l_order_schedules_in like bapischdl,
li_order_schedules_inx type standard table of bapischdl,
l_order_schedules_inx like bapischdl,
Return table from bapi call*
li_return type standard table of bapiret2,
l_return type bapiret2,
Sales document number*
l_vbeln like bapivbeln-vbeln,
Error flag*
l_errflag(1) type c.
start-of-selection.
Build partner information*
clear l_order_partners.
l_order_partners-partn_role = 'WE'. "Remember German codes !
l_order_partners-partn_numb = '0000000101'.
append l_order_partners to li_order_partners.
l_order_partners-partn_role = 'SP'. "Remember German codes !
l_order_partners-partn_numb = '0000000107'.
append l_order_partners to li_order_partners.
Build order header*
Update flag*
l_order_header_inx-updateflag = 'I'.
Sales document type*
l_order_header_in-doc_type = 'ZOD2'. "Remember German codes !
l_order_header_inx-doc_type = 'X'.
Sales organization*
l_order_header_in-sales_org = '1100'.
l_order_header_inx-sales_org = 'X'.
Distribution channel*
l_order_header_in-distr_chan = '20'.
l_order_header_inx-distr_chan = 'X'.
Division*
l_order_header_in-division = '10'.
l_order_header_inx-division = 'X'.
Purchase order*
l_order_header_in-purch_no_c = 'DG-19970626-300'.
l_order_header_inx-purch_no_c = 'X'.
l_order_header_in-purch_date = '20090817'.
l_order_header_inx-purch_date = 'X'.
Build order item(s) - Only 1 is used in this example*
l_order_items_in-itm_number = '10'.
l_order_items_inx-itm_number = 'X'.
l_order_items_in-material = '29019501AA'.
l_order_items_inx-material = 'X'.
l_order_items_in-plant = 'WH03'.
l_order_items_inx-plant = 'X'.
append l_order_items_in to li_order_items_in.
l_order_items_in-itm_number = '20'.
l_order_items_inx-itm_number = 'X'.
l_order_items_in-material = '29066641'.
call function 'CONVERSION_EXIT_ALPHA_INPUT'
exporting
input = l_order_items_in-material
importing
output = l_order_items_in-material.
l_order_items_inx-material = 'X'.
l_order_items_in-plant = 'WH03'.
l_order_items_inx-plant = '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.
l_order_schedules_in-itm_number = '10'.
l_order_schedules_in-req_qty = '10.00'.
append l_order_schedules_in to li_order_schedules_in.
l_order_schedules_in-itm_number = '20'.
l_order_schedules_in-req_qty = '20.00'.
append l_order_schedules_in to li_order_schedules_in.
CALL Bapi*
call function 'BAPI_SALESORDER_CREATEFROMDAT2'
exporting
order_header_in = l_order_header_in
order_header_inx = l_order_header_inx
testrun = ' '
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.*
end-of-selection.
Check and write Return table*
clear l_errflag.
write: / 'Sales dcoument: ', l_vbeln.
loop at li_return into l_return.
write: / l_return-type, l_return-message(50).
if l_return-type = 'E'.
l_errflag = 'X'.
endif.
endloop.
No errors - Commit*
if l_errflag is initial.
call function 'BAPI_TRANSACTION_COMMIT'.
endif.
What could be problem ?
Pl help
Regards
NagarajanHi,
Go through this sample code
LOOP AT t_salesorder INTO wa_salesorder.
t_header-sales_org = wa_salesorder-vkorg.
t_header-distr_chan = wa_salesorder-vtweg.
t_header-division = wa_salesorder-spart.
t_header-doc_type = wa_salesorder-auart.
APPEND t_header.
t_headerx-sales_org = 'X'.
t_headerx-distr_chan = 'X'.
t_headerx-division = 'X'.
t_headerx-doc_type = 'X'.
APPEND t_headerx.
t_itemx-material = 'X'.
t_itemx-target_qty = 'X'.
APPEND t_itemx.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_salesorder-kunnr
IMPORTING
output = wa_alpha-kunnr.
wa_partner-partn_role = 'AG'.
wa_partner-partn_numb = wa_alpha-kunnr.
APPEND wa_partner TO t_partner.
CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
EXPORTING
input = wa_salesorder-kunnr1
IMPORTING
output = wa_alpha-kunnr1.
wa_partner-partn_role = 'WE'.
wa_partner-partn_numb = wa_alpha-kunnr1.
APPEND wa_partner TO t_partner.
wa_item-po_itm_no = wa_salesorder-bstnk.
wa_item-itm_number = wa_salesorder-posnr.
wa_item-material = wa_salesorder-matnr.
wa_item-target_qty = wa_salesorder-kwmeng.
APPEND wa_item TO t_item.
CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
EXPORTING
order_header_in = t_header
order_header_inx = t_headerx
IMPORTING
salesdocument = gv_doc_no
TABLES
return = t_return
order_items_in = t_item[]
order_items_inx = t_itemx
order_partners = t_partner[].
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'
IMPORTING
return = t_return.
ENDLOOP.
Please paste only the portion of your code that gives you trouble. -
Creating Sales Order using BAPI_SALESORDER_CREATEFROMDAT2
Hi All,
I am having problem while creating a SO using the BAPI_SALESORDER_CREATEFROMDAT2, Its returning sales documnet type is not defined. I used to get the error to speciy the ship to party or sold party earlier that has been resloved now I am getting the above specifed error.
Please help me its very urgent
Thanks,
SumaHi Suma
While populating data for Sales Order Creation, populate PARTNER table with Sold-To or Ship-To as per you business process.
Minimum two fields are to the fields for this structure:PARTN_ROLE , PARTN_NUMB
PARTN_ROLE ---> " Partner Role, which specifies the partner type i.e Sold-To, Ship-To, Bill-To ...
ARTN_NUMB ---> " Customer Number
Regards
Eswar -
Error in Creating Sales Order Using BAPI_SALESORDER_CREATEFROMDAT2
Hi Everyone,
We have a requirement to create sales order from flat file using BAPI. Everything was working well until we encounter a customer with credit control limit setup.
Using the partners table for BAPi, the sold to customer is enter at header level, and we have this requirement to add the payer at item level. This is where the error is occuring. Upon debugging, I found out that the customer has a credit limit setup at FD33, and has a record found in KNKK, which is giving the error "Credit limit customer differs from credit limit customer in header".
However, duting manual creation of sales order via VA01, this error is not encountered.
Any ideas or suggesstions on how we can move forward with SO creation using BAPI with customers where credit management is setup?
Thanks,
LouisseIf thats not working..
try BAPI_SALESORDER_CREATEFROMDAT2
If BAPI is not working. try creating a bdc for the same if there's not error on trying from VA01 -
Problem when creating a sales order using BAPI_SALESORDER_CREATEFROMDAT2
Hello All,
I am working on a requirement where i need to create a new sales order from old sales order (Not all the items of the old sales order are to be copied) i am doing this by getting the data using BAPISDORDER_GETDETAILEDLIST to get the old sales order details and send them to BAPI_SALESORDER_CREATEFROMDAT2.
My problem is that i when i send the condition also the system in addition to the conditions sent to the BAPI is also automatically proposing the condition types . So the final result is that the sales order ends up having the condition types twice .
For example VPRS AZWR are visible twice in the sales order.
Any inputs to solve the problem will be definitely rewarded.
Thanks in advance.
Regards,
Sowmya.Hello All,
I am working on a requirement where i need to create a new sales order from old sales order (Not all the items of the old sales order are to be copied) i am doing this by getting the data using BAPISDORDER_GETDETAILEDLIST to get the old sales order details and send them to BAPI_SALESORDER_CREATEFROMDAT2.
My problem is that i when i send the condition also the system in addition to the conditions sent to the BAPI is also automatically proposing the condition types . So the final result is that the sales order ends up having the condition types twice .
For example VPRS AZWR are visible twice in the sales order.
Any inputs to solve the problem will be definitely rewarded.
Thanks in advance.
Regards,
Sowmya. -
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
Maybe you are looking for
-
IW21 - Default values into Activities table on Creation of Notification
Hi, Can anyone suggest a way to default values in to the first line of the Activities table (VIQMMA) on the Additional Information tab when creating a notification? Some fields would be dependant on the entry in the field VIQMFE-OTGRP on the Header t
-
hi gurus how can we capture and post the excise without po plz let me know the steps plz help answers will be rewarded
-
IPad 2 doesn't change orientation when rotated..
I bought an iPad 2 the day it came out, and it worked flawlessly until I updated to 4.3.2. Now if I want to change the screen orientation, I have to turn the screen off, put the iPad in the desired position, then unlock it again. I have the switch se
-
Hello All, I didnt get proper doc for this. Why we have Custom tab in RTMT tool (Check attachment), is that to configure new alerts apart from predefined alerts in RTMT. If yes, please let me know how to add new alerts in RTMT under custom tab. -Mura
-
VISA runtime with installshi​eld
How can I include VISA runtime install with my Visual c++ (Install Shield) installer? Instead of asking user to execute VISA RT installer seperately. Appl: Win32 platform Tools: Component Works++ w/VISA for RS-232 Serial Comm.