*&---------------------------------------------------------------------*
*&      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.

 REFRESH: i_itm, i_itmx, i_ret.
 CLEAR: i_hdr, i_hdrx.
 i_hdr-sd_doc_cat  = 'C'.
 i_hdrx-updateflag = 'U'.

 SELECT * FROM vbap
  WHERE vbeln = i_listado-vbeln.

   i_itm-itm_number = vbap-posnr.
   i_itm-reason_rej = 'Z1'.

   i_itmx-updateflag = 'U'.
   i_itmx-itm_number = vbap-posnr.
   i_itmx-reason_rej = 'X'.

   APPEND i_itm.
   APPEND i_itmx.
 ENDSELECT.

 CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
   EXPORTING
     salesdocument     = i_listado-vbeln
     order_header_in   = i_hdr
     order_header_inx  = i_hdrx
     behave_when_error = 'P'
   TABLES
     return            = i_ret
     order_item_in     = i_itm
     order_item_inx    = i_itmx.

ENDFORM.                    " rechazar

Ejemplo
REPORT ZEGGY_ORDER_CHANGE_TEST MESSAGE-ID 38.

*----------------------------------------------------------------------*
* 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.

*----------------------------------------------------------------------*
* START-OF-SELECTION Event                                             *
*----------------------------------------------------------------------*
START-OF-SELECTION.

    "---------------------------------------------------
    " 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.

    "----------------------------------------------
    " Initialize internal tables.
    "----------------------------------------------
    REFRESH: I_ITM, I_ITMX, I_SCHED, I_SCHEDX, I_RET.
    CLEAR:   I_ITM, I_ITMX, I_SCHED, I_SCHEDX, I_RET.

    "----------------------------------------------
    " Fill required ORDER_HEADER_IN data.
    "----------------------------------------------
    I_HDR-SD_DOC_CAT  = 'C'.
    I_HDRX-UPDATEFLAG = 'U'.

    "----------------------------------------------
    " Fill required ORDER_ITEM_IN data.
    "----------------------------------------------
    IF R_ITEM = 'X' OR R_BOTH = 'X'.

       I_ITM-ITM_NUMBER = P_POSNR.
       I_ITM-TARGET_QTY = P_ITMQTY.

       I_ITMX-UPDATEFLAG = 'U'.
       I_ITMX-ITM_NUMBER = P_POSNR.
       I_ITMX-TARGET_QTY = 'X'.

       APPEND I_ITM.
       APPEND I_ITMX.
    ENDIF.

    "----------------------------------------------
    " Fill required SCHEDULE_LINES data.
    "----------------------------------------------
    IF R_SCHD = 'X' OR R_BOTH = 'X'.

       I_SCHED-ITM_NUMBER = P_POSNR.
       I_SCHED-SCHED_LINE = P_ETENR.
       I_SCHED-REQ_QTY    = P_REQQTY.

       I_SCHEDX-UPDATEFLAG = 'U'.
       I_SCHEDX-ITM_NUMBER = P_POSNR.
       I_SCHEDX-SCHED_LINE = P_ETENR.
       I_SCHEDX-REQ_QTY    = 'X'.

       APPEND I_SCHED.
       APPEND I_SCHEDX.
    ENDIF.

    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
         EXPORTING
                  SALESDOCUMENT     = P_VBELN
                  ORDER_HEADER_IN   = I_HDR
                  ORDER_HEADER_INX  = I_HDRX
                  BEHAVE_WHEN_ERROR = 'P'
         TABLES
                  RETURN            = I_RET
                  ORDER_ITEM_IN     = I_ITM
                  ORDER_ITEM_INX    = I_ITMX
                  SCHEDULE_LINES    = I_SCHED
                  SCHEDULE_LINESX   = I_SCHEDX.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'.

*end of program ZEGGY_ORDER_CHANGE_TEST.
 来源:http://sap4.com/wiki/index.php?title=BAPI_SALESORDER_CHANGE