Im on the way creating waste selling on intranet. User will input material that will be sold, do some level approval and create sales order in SAP. Im using BAPI_SALESORDER_CREATEFROMDAT2 to create sales order. Test using the function is ok (sales document number diplayed). But when I try to display the SO via VA03, error ‘SD document xxx is not in the database or has been archived’ displayed.
Function test displaying sales order successfully created.
To handle this, we need to commit the transaction by running BAPI_TRANSACTION_COMMIT.
Sequence test on creating sales order and commit transaction:
On function module SE37, click menu Function Module > Test > Test sequence, input BAPI_SALESORDER_CREATEFROMDAT2 and BAPI_TRANSACTION_COMMIT, then run.
Example of abap program testing the function:
*&---------------------------------------------------------------------*
*& Report ZCREATESALESDOC *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZCREATESALESDOC .
DATA: order_header_in LIKE standard table of bapisdhd1 with header line.
DATA: order_items_in TYPE STANDARD TABLE OF bapisditm WITH HEADER LINE.
DATA: order_schedules_in
TYPE STANDARD TABLE OF bapischdl WITH HEADER LINE.
DATA: order_partners TYPE STANDARD TABLE OF bapiparnr WITH HEADER LINE.
DATA: return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
data: itemx like bapisditmx occurs 10 with header line.
order_header_in-doc_type = 'ZORL'.
order_header_in-sales_org = 'ID10'.
order_header_in-distr_chan = 'DC'.
order_header_in-division = '00'.
order_header_in-purch_date = sy-datum.
order_header_in-purch_no_c = 'BAPITEST'.
APPEND order_header_in.
order_partners-partn_role = 'AG'.
order_partners-partn_numb = '0000100080'.
APPEND order_partners.
order_partners-partn_role = 'WE'.
order_partners-partn_numb = '0000100082'.
APPEND order_partners.
*req deliv date, pricing date
*payment terms, incoterms
*add next line with more than one item
order_items_in-itm_number = '000010'.
order_items_in-material = 'LL0209AA'.
order_items_in-target_qty = '1000'.
order_items_in-target_qu = 'KG'.
order_items_in-sales_unit = 'KG'.
APPEND order_items_in.
order_schedules_in-itm_number = '000010'.
order_schedules_in-req_qty = '1000'.
APPEND order_schedules_in.
*Add following lines with more than one line
itemx-itm_number = '000010'.
itemx-updateflag = 'I'.
itemx-material = 'X'.
itemx-target_qty = 'X'.
append itemx.
*stop add more lines
REFRESH return.
*BREAK-POINT.
CALL FUNCTION 'SD_SALESDOCUMENT_CREATE'
EXPORTING
sales_header_in = order_header_in
TABLES
return = return
sales_items_in = order_items_in
sales_items_inx = itemx
sales_partners = order_partners
sales_schedules_in = order_schedules_in.
COMMIT WORK.
LOOP AT return.
WRITE: / return-message.
ENDLOOP.
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment