Posted: Thu Sep 20, 2007 11:04 am Post subject: BAPI_SALESORDER_CHANGE
BAPI_SALESORDER_CHANGE - Sales order: Change Sales Order
Functionality
You can use this method to change or delete sales orders.
You can change header, item, schedule line and configuration data.
In general, note that you should:
- Only specify fields that should be changed
- Select these fields by entering an X in the checkboxes
- Enter a U in the UPDATEFLAG field
- Always specify key fields when changing the data, including in the checkboxes
- The configuration is an exception here. If this needs to be changed, you need to complete it again fully.
- Maintain quantities and dates in the schedule line data
- Possible UPDATEFLAGS:
U = change
D = delete
I = add
Code:
*&---------------------------------------------------------------------*
*& Form rechazar
*&---------------------------------------------------------------------*
FORM rechazar .
DATA: i_hdr TYPE bapisdh1,
i_hdrx TYPE bapisdh1x,
i_ret TYPE bapiret2 OCCURS 0 WITH HEADER LINE,
i_itm TYPE bapisditm OCCURS 0 WITH HEADER LINE,
i_itmx TYPE bapisditmx OCCURS 0 WITH HEADER LINE.
*----------------------------------------------------------------------*
* Selection Screen Definitions *
*----------------------------------------------------------------------*
PARAMETERS: P_VBELN TYPE VBAP-VBELN OBLIGATORY, "Order Number
P_POSNR TYPE VBAP-POSNR OBLIGATORY, "Order Item
P_ETENR TYPE VBEP-ETENR, "Schedule Line
P_ITMQTY TYPE BAPISDITM-TARGET_QTY, "Order Quantity
P_REQQTY TYPE BAPISCHDL-REQ_QTY. "Schedule Line Qty
SELECTION-SCREEN: SKIP.
PARAMETERS: R_SCHD RADIOBUTTON GROUP RAD, "Change Schedule Line Qty
R_ITEM RADIOBUTTON GROUP RAD, "Change Order Item Qty
R_BOTH RADIOBUTTON GROUP RAD. "Change Both Qtys
*----------------------------------------------------------------------*
* Internal Tables/Structures/Variables for calling BAPI. *
*----------------------------------------------------------------------*
DATA: I_HDR TYPE BAPISDH1,
I_HDRX TYPE BAPISDH1X,
I_RET TYPE BAPIRET2 OCCURS 0 WITH HEADER LINE.
DATA: BEGIN OF I_ITM OCCURS 10.
INCLUDE STRUCTURE BAPISDITM.
DATA: END OF I_ITM.
DATA: BEGIN OF I_ITMX OCCURS 10.
INCLUDE STRUCTURE BAPISDITMX.
DATA: END OF I_ITMX.
DATA: BEGIN OF I_SCHED OCCURS 10.
INCLUDE STRUCTURE BAPISCHDL.
DATA: END OF I_SCHED.
DATA: BEGIN OF I_SCHEDX OCCURS 10.
INCLUDE STRUCTURE BAPISCHDLX.
DATA: END OF I_SCHEDX.
"---------------------------------------------------
" Validate require selection screen criteria.
"---------------------------------------------------
IF R_BOTH = 'X'.
IF P_ETENR IS INITIAL OR
P_REQQTY IS INITIAL.
MESSAGE E000
WITH 'Enter a Schedule Line Number and Qty.'.
ENDIF.
IF P_ITMQTY IS INITIAL.
MESSAGE E000
WITH 'Enter an Order Item Quantity.'.
ENDIF.
ELSEIF R_SCHD = 'X'.
IF P_ETENR IS INITIAL OR
P_REQQTY IS INITIAL.
MESSAGE E000
WITH 'Enter a Schedule Line Number and Qty.'.
ENDIF.
ELSE.
IF P_ITMQTY IS INITIAL.
MESSAGE E000
WITH 'Enter an Order Item Quantity.'.
ENDIF.
ENDIF.
"----------------------------------------------
" Fill required ORDER_ITEM_IN data.
"----------------------------------------------
IF R_ITEM = 'X' OR R_BOTH = 'X'.
"----------------------------------------------
" Fill required SCHEDULE_LINES data.
"----------------------------------------------
IF R_SCHD = 'X' OR R_BOTH = 'X'.
Example: Source code for function module Z_IDOC_INPUT_GOODSENTRY
FUNCTION z_idoc_input_goodsentry .
*"----------------------------------------------------------------------
*"*"Global interface:
*" IMPORTING
*" VALUE(INPUT_METHOD) LIKE BDWFAP_PAR-INPUTMETHD
*" VALUE(MASS_PROCESSING) LIKE BDWFAP_PAR-MASS_PROC
*" EXPORTING
*" VALUE(WORKFLOW_RESULT) LIKE BDWF_PARAM-RESULT
*" VALUE(APPLICATION_VARIABLE) LIKE BDWF_PARAM-APPL_VAR
*" VALUE(IN_UPDATE_TASK) LIKE BDWFAP_PAR-UPDATETASK
*" VALUE(CALL_TRANSACTION_DONE) LIKE BDWFAP_PAR-CALLTRANS
*" TABLES
*" IDOC_CONTRL STRUCTURE EDIDC
*" IDOC_DATA STRUCTURE EDIDD
*" IDOC_STATUS STRUCTURE BDIDOCSTAT
*" RETURN_VARIABLES STRUCTURE BDWFRETVAR
*" SERIALIZATION_INFO STRUCTURE BDI_SER
*" EXCEPTIONS
*" WF_ERROR_PROCESS
*"----------------------------------------------------------------------
TABLES: ekko, ekpo, eban, ekkn, vbap, vbak, vbep.
DATA: xe1edp09 TYPE STANDARD TABLE OF e1edp09 WITH HEADER LINE.
DATA: goodsmvt_header LIKE bapi2017_gm_head_01.
DATA: goodsmvt_item TYPE STANDARD TABLE OF bapi2017_gm_item_create
WITH HEADER LINE.
DATA: return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.
* for the BAPI_SALESORDER_CHANGE --------------------------------------
DATA: order_header_in LIKE bapisdh1.
DATA: order_header_inx LIKE bapisdh1x.
DATA: schedule_lines
TYPE STANDARD TABLE OF bapischdl WITH HEADER LINE.
DATA: schedule_linesx
TYPE STANDARD TABLE OF bapischdlx WITH HEADER LINE.
TABLES: bapi2017_gm_head_ret. " IDoc: Document header date segment
CLEAR workflow_result.
*- Prfen, da alle IDOCs den richtigen Basis IDoc Typ haben ----------*
LOOP AT idoc_contrl.
IF idoc_contrl-idoctp(6) <> 'DESADV'.
MESSAGE ID 'E0' TYPE 'E' NUMBER '029'
WITH idoc_contrl-idoctp ' ' 'IDOC_INPUT_DESADV'
RAISING wf_error_process.
ENDIF.
ENDLOOP.
*- kein Zwischenbeleg gefunden ----------------------------------------*
IF idoc_contrl-docnum EQ space.
MESSAGE e770(e0) RAISING wf_error_process.
ENDIF.
*- Feststellen IDOC-Nummer - Weiterverarbeitung starten ---------------*
LOOP AT idoc_contrl.
REFRESH xe1edp09.
LOOP AT idoc_data WHERE docnum EQ idoc_contrl-docnum.
CASE idoc_data-segnam.
WHEN 'E1EDP09'. APPEND idoc_data-sdata TO xe1edp09.
ENDCASE.
*- Daten aus interner Tabelle in entsprechenden Strukturen merken -----*
ENDLOOP.
ENDLOOP.
CLEAR goodsmvt_header.
goodsmvt_header-pstng_date = sy-datum.
goodsmvt_header-doc_date = sy-datum.
LOOP AT xe1edp09.
ekpo-ebeln = xe1edp09-vbeln.
ekpo-ebelp = xe1edp09-posnr.
CLEAR idoc_status.
idoc_status-msgty = 'I'.
idoc_status-status = '62'.
idoc_status-msgid = '38'.
idoc_status-msgno = '000'.
SELECT * FROM ekpo WHERE ebeln EQ ekpo-ebeln
AND ebelp EQ ekpo-ebelp.
idoc_status-msgv1 = '... Purchase order found:'.
idoc_status-msgv2 = ekpo-ebeln.
idoc_status-msgv3 = ekpo-ebelp.
APPEND idoc_status.
SELECT * FROM ekko WHERE ebeln EQ ekpo-ebeln.
SELECT * FROM ekkn WHERE ebeln EQ ekpo-ebeln
AND ebelp EQ ekpo-ebelp.
SELECT * FROM vbap WHERE vbeln EQ ekkn-vbeln
AND posnr EQ ekkn-vbelp.
idoc_status-msgv1 = '... Sales order found:'.
idoc_status-msgv2 = vbap-vbeln.
idoc_status-msgv3 = vbap-posnr.
APPEND idoc_status.
ekpo-menge = xe1edp09-lfimg.
goodsmvt_header-ref_doc_no = 'Redboats'.
goodsmvt_item-material = vbap-matnr.
goodsmvt_item-plant = vbap-werks.
IF vbap-lgort IS INITIAL.
SELECT lgort INTO vbap-lgort UP TO 1 ROWS FROM t001l
WHERE werks EQ vbap-werks.
ENDSELECT.
ENDIF.
goodsmvt_item-stge_loc = vbap-lgort.
goodsmvt_item-move_type = '101'.
goodsmvt_item-vendor = ekko-lifnr.
goodsmvt_item-entry_qnt = ekpo-menge.
goodsmvt_item-entry_uom = 'EA'.
goodsmvt_item-po_number = ekpo-ebeln.
goodsmvt_item-po_item = ekpo-ebelp.
goodsmvt_item-mvt_ind = 'B'.
APPEND goodsmvt_item.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDSELECT.
ENDLOOP.
*--- Post if there is something to post -------------------------------
REFRESH return.
CLEAR bapi2017_gm_head_ret.
IF NOT goodsmvt_item[] IS INITIAL.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
* DESTINATION 'NONE'
EXPORTING
goodsmvt_header = goodsmvt_header
goodsmvt_code = '01'
IMPORTING
materialdocument = bapi2017_gm_head_ret-mat_doc
matdocumentyear = bapi2017_gm_head_ret-doc_year
TABLES
goodsmvt_item = goodsmvt_item
return = return.
ENDIF.
COMMIT WORK AND WAIT.
* break axel.
*-------------------------------------------------------------
idoc_status-docnum = idoc_contrl-docnum.
idoc_status-status = '62'.
LOOP AT return.
idoc_status-msgty = return-type.
idoc_status-msgid = return-id.
idoc_status-msgno = return-number.
idoc_status-msgv1 = return-message_v1.
idoc_status-msgv2 = return-message_v2.
idoc_status-msgv3 = return-message_v3.
idoc_status-msgv4 = return-message_v4.
APPEND idoc_status.
ENDLOOP.
*-------------------------------------------------------------
IF NOT bapi2017_gm_head_ret-mat_doc IS INITIAL
AND NOT vbap-vbeln IS INITIAL.
CLEAR order_header_in.
CLEAR order_header_inx.
order_header_in-dlv_block = space.
order_header_inx-dlv_block = 'X'.
order_header_inx-updateflag = 'U'.
*-- update schedule lines so that delivery can be created immediately
REFRESH: schedule_lines, schedule_linesx.
SELECT * FROM vbep WHERE posnr EQ vbap-posnr
AND vbeln EQ vbap-vbeln.
schedule_lines-itm_number = vbep-posnr.
schedule_lines-sched_line = vbep-etenr.
schedule_lines-tp_date = sy-datum.
schedule_lines-ms_date = sy-datum.
schedule_linesx-updateflag = 'U'.
schedule_linesx-itm_number = schedule_lines-itm_number.
schedule_linesx-sched_line = schedule_lines-sched_line.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG. SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG. Every effort is made to ensure content integrity. Use information on this site at your own risk.