Bapi sales order change-urgent

Hi ;
Please find below the code which I couldnt update sales data although I updated structures : BAPE_VBAP    BAPE_VBAPX.  I want to change abgru field on vbap.and return contains no error messages
*&      Form  USE_BAPI
      text
-->  p1        text
<--  p2        text
FORM use_bapi .
  DATA: salesdocument TYPE bapivbeln-vbeln,
        return        TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
  REFRESH return.
  CLEAR : gs_exsi,
          gt_extensionin, gt_extensionin[],
          gs_exsx,
          gs_order_header_in,gs_order_header_inx,
          gv_salesdocument,
          gt_order_item_in,gt_order_item_in[],
          gt_order_item_inx, gt_order_item_inx[],
          gt_schedule_lines, gt_schedule_lines[],
          gt_schedule_linesx, gt_schedule_linesx[],
          gt_return, gt_return[].
  LOOP AT i_vbap WHERE abgru IS INITIAL.
       DELETE i_vbap.
  ENDLOOP.
LOOP AT i_vbap.
    PERFORM  fill_bapi_data.
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
      EXPORTING
        salesdocument    = i_vbap-vbeln
        order_header_in  = gs_order_header_in
        order_header_inx = gs_order_header_inx
      TABLES
        return           = gt_return
        order_item_in    = gt_order_item_in
        order_item_inx   = gt_order_item_inx
        schedule_lines   = gt_schedule_lines
        schedule_linesx  = gt_schedule_linesx
        extensionin      = gt_extensionin.
    READ TABLE gt_return WITH KEY type = 'E'.
    IF sy-subrc NE 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      LOOP AT gt_return.
        gt_return_all-log_nmb = ''.
        gt_return_all-doc_nmb = i_vbap-vbeln.
        gt_return_all-itm_nmb = i_vbap-posnr.
        gt_return_all-log_dsc = gt_return-message.
        APPEND gt_return_all.
      ENDLOOP.
    ENDIF.
  ENDLOOP.
ENDFORM. " use_bapi.
*&      Form  fill_bapi_data
FORM fill_bapi_data.
  gv_salesdocument = i_vbap-vbeln.
  gs_exsi-vbeln    = i_vbap-vbeln.
  gs_exsi-posnr    = i_vbap-posnr.
  gs_exsi-abgru    = p_reason.
  gt_extensionin-structure = 'BAPE_VBAP'.
  gt_extensionin-valuepart1 = gs_exsi.
  APPEND gt_extensionin.
  gs_exsx-vbeln = i_vbap-vbeln.
  gs_exsx-posnr = i_vbap-posnr.
  gs_exsx-abgru = p_reason.
  gt_extensionin-structure = 'BAPE_VBAPX'.
  gt_extensionin-valuepart1 = gs_exsx.
  APPEND gt_extensionin.
  gs_order_header_inx-updateflag = 'U'.
  gt_order_item_in-itm_number  = i_vbap-posnr.
  APPEND gt_order_item_in.
  gt_order_item_inx-itm_number = i_vbap-posnr.
  gt_order_item_inx-updateflag = 'U'.
  APPEND gt_order_item_inx.
Message was edited by:
        yanut

Hi ;
Please find below the code which I couldnt update sales data although I updated structures : BAPE_VBAP    BAPE_VBAPX.  I want to change abgru field on vbap.and return contains no error messages
*&      Form  USE_BAPI
      text
-->  p1        text
<--  p2        text
FORM use_bapi .
  DATA: salesdocument TYPE bapivbeln-vbeln,
        return        TYPE bapiret2 OCCURS 0 WITH HEADER LINE.
  REFRESH return.
  CLEAR : gs_exsi,
          gt_extensionin, gt_extensionin[],
          gs_exsx,
          gs_order_header_in,gs_order_header_inx,
          gv_salesdocument,
          gt_order_item_in,gt_order_item_in[],
          gt_order_item_inx, gt_order_item_inx[],
          gt_schedule_lines, gt_schedule_lines[],
          gt_schedule_linesx, gt_schedule_linesx[],
          gt_return, gt_return[].
  LOOP AT i_vbap WHERE abgru IS INITIAL.
       DELETE i_vbap.
  ENDLOOP.
LOOP AT i_vbap.
    PERFORM  fill_bapi_data.
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
      EXPORTING
        salesdocument    = i_vbap-vbeln
        order_header_in  = gs_order_header_in
        order_header_inx = gs_order_header_inx
      TABLES
        return           = gt_return
        order_item_in    = gt_order_item_in
        order_item_inx   = gt_order_item_inx
        schedule_lines   = gt_schedule_lines
        schedule_linesx  = gt_schedule_linesx
        extensionin      = gt_extensionin.
    READ TABLE gt_return WITH KEY type = 'E'.
    IF sy-subrc NE 0.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ELSE.
      CALL FUNCTION 'BAPI_TRANSACTION_ROLLBACK'.
      LOOP AT gt_return.
        gt_return_all-log_nmb = ''.
        gt_return_all-doc_nmb = i_vbap-vbeln.
        gt_return_all-itm_nmb = i_vbap-posnr.
        gt_return_all-log_dsc = gt_return-message.
        APPEND gt_return_all.
      ENDLOOP.
    ENDIF.
  ENDLOOP.
ENDFORM. " use_bapi.
*&      Form  fill_bapi_data
FORM fill_bapi_data.
  gv_salesdocument = i_vbap-vbeln.
  gs_exsi-vbeln    = i_vbap-vbeln.
  gs_exsi-posnr    = i_vbap-posnr.
  gs_exsi-abgru    = p_reason.
  gt_extensionin-structure = 'BAPE_VBAP'.
  gt_extensionin-valuepart1 = gs_exsi.
  APPEND gt_extensionin.
  gs_exsx-vbeln = i_vbap-vbeln.
  gs_exsx-posnr = i_vbap-posnr.
  gs_exsx-abgru = p_reason.
  gt_extensionin-structure = 'BAPE_VBAPX'.
  gt_extensionin-valuepart1 = gs_exsx.
  APPEND gt_extensionin.
  gs_order_header_inx-updateflag = 'U'.
  gt_order_item_in-itm_number  = i_vbap-posnr.
  APPEND gt_order_item_in.
  gt_order_item_inx-itm_number = i_vbap-posnr.
  gt_order_item_inx-updateflag = 'U'.
  APPEND gt_order_item_inx.
Message was edited by:
        yanut

Similar Messages

  • Updating a child of a BOM material using bapi sales order change

    Hi, Appreciate your thoughts on the following issue..
    We have a batch program which uses a bapi sales order change and updates the plant at the line items of the sales order. when this plant is assigned.. if any of the line item is a BOM item, it explodes and the data from the parent ( like payment terms, fixed val date ) should get copied to the child items same as the parent. This is happening fine if manual mode using va01 and va02 but when plant is updated using bapi the childs are not getting the data from the parent ( which comes through config )...
    Appreciate your inputs and any additional information to be passed to the bapi for the BOM materials to get the same config data as parent to the child when exploded...
    Thanks and will reward helpful answers..

    Hi, Appreciate your thoughts on the following issue..
    We have a batch program which uses a bapi sales order change and updates the plant at the line items of the sales order. when this plant is assigned.. if any of the line item is a BOM item, it explodes and the data from the parent ( like payment terms, fixed val date ) should get copied to the child items same as the parent. This is happening fine if manual mode using va01 and va02 but when plant is updated using bapi the childs are not getting the data from the parent ( which comes through config )...
    Appreciate your inputs and any additional information to be passed to the bapi for the BOM materials to get the same config data as parent to the child when exploded...
    Thanks and will reward helpful answers..

  • BAPI SALES ORDER CHANGE CUSTOM FIELD

    Hello Gurus,
    I am trying to update a custom field for sales order. The field name is zfield1 in vbak. The field is added to vbakkom, vbakkomx, vbakkoz, vbakkozx, BAPE_VBAK, BAPE_VBAKX. I guess i need to use the EXTENSIONIN table to populate this field's values to change it with the BAPI. But I not sure exactly how to populate the fields. Can someone tell me how exactly i need to do this?
    Also the documentation says fill Extensionin this way.
    STRUCTURE VALUEPART1 1234561234567890123
    BAPE_VBAP 0000004711000020 XYZ
    BAPE_VBAPX 0000004711000020 X
    What is the 1234561234567890123? Is it a field?
    Thanks,
    KB

    Hi,
    Check this example..I am updating the VBAP field..Instead you can replace it for VBAK..
    PARAMETERS: P_VBELN TYPE VBAK-VBELN.
    DATA: T_LINE LIKE BAPISDITM OCCURS 0 WITH HEADER LINE.
    DATA: T_LINEX LIKE BAPISDITMX OCCURS 0 WITH HEADER LINE.
    DATA: T_EXTEN LIKE BAPIPAREX OCCURS 0 WITH HEADER LINE.
    DATA: T_RETURN LIKE BAPIRET2 OCCURS 0 WITH HEADER LINE.
    DATA: BAPE_VBAP LIKE BAPE_VBAP.
    DATA: BAPE_VBAPX LIKE BAPE_VBAPX.
    DATA: ORDER_HEADERX LIKE BAPISDH1X.
    ORDER_HEADERX-UPDATEFLAG = 'U'.
    T_LINE-ITM_NUMBER = '000010'.
    APPEND T_LINE.
    T_LINEX-ITM_NUMBER = '000010'.
    T_LINEX-UPDATEFLAG = 'U'.
    APPEND T_LINEX.
    BAPE_VBAP-VBELN = P_VBELN.
    BAPE_VBAP-POSNR = '000010'.
    <b>BAPE_VBAP-<b>YYFREETEXT</b> = '02'.</b>
    T_EXTEN-STRUCTURE = 'BAPE_VBAP'.
    T_EXTEN+30 = BAPE_VBAP.
    APPEND T_EXTEN.
    BAPE_VBAPX-VBELN = P_VBELN.
    BAPE_VBAPX-POSNR = '000010'.
    <b>BAPE_VBAPX-YYFREETEXT = 'X'.</b>
    T_EXTEN-STRUCTURE = 'BAPE_VBAPX'.
    T_EXTEN+30 = BAPE_VBAPX.
    APPEND T_EXTEN.
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
    EXPORTING
    salesdocument = p_vbeln
    order_header_inx = ORDER_HEADERX
    tables
    return = T_RETURN
    ORDER_ITEM_IN = T_LINE
    ORDER_ITEM_INX = T_LINEX
    EXTENSIONIN = T_EXTEN.
    COMMIT WORK.
    Thanks,
    Naren

  • BAPI Sales Order Change

    Hi Guys,
    Does any one know what the structure LOGIC_SWITCH field in the BAPI_SALESORDER_CHANGE is used for?
    we are trying to get the changes of delivery date at the header get reflected onto the schedule lines at item level.we cannot use the schedule line structures at line item as the legacy system we interface with wont provide us with line items.is there a way thru the BAPI that a change in the header delivery date gets reflected onto schedule line date at line item?
    Thanks

    I guess it is used while calculating data for Schedule Lines.
    Check this code in fm SD_SALES_ITEM_MAINTAIN which is called in this BAPI
    Menge (RV45A-KWMENG) temporaer fuer Konfiguration
      if logic_switch-scheduling = chara.
        read table fxvbepkom index 1 into ls_vbepkom.
        if sy-subrc = 0.
          perform rv45a-kwmeng_fuellen(sapfv45p) using ls_vbepkom-wmeng.
        endif.
      else.
        perform rv45a-kwmeng_fuellen(sapfv45p) using fvbepkom-wmeng.
      endif.
    As per the code, if schedulling flag is set to 'A', it will read Schedule line details and pass the same to Quantity processing perform. It may not give a clear picture though, but you can keep a break poitn and populate A in schedulling field and check result in debug mode.

  • Sale Order change BAPI - Storage loc not updated

    Hi Everybody,
    Iam using "BAPI_SALESORDER_CHANGE", to change the sale order items.
    First iam calling above bapi with switch B, for new pricing & then second time for material change.
    When i change any material number, it is getting updated correctly.
    But the storage location, even though iam passing in the bapi it is not updated, & is blank - updation flag is also passed.
    When i execute sale order change again it is updated - ie, for any material change for first bapi call, storage loc is not updated - for 2nd bapi call storage loc is updation - for same input in both the cases.
    Is there any way to update the storage loc is first call of sales order change bapi.
    Below is the parameters iam passing in bapi :
    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
        EXPORTING
          SALESDOCUMENT      = LS_SALESDOCUMENT
          ORDER_HEADER_IN    = LT_HEADER_IN
          ORDER_HEADER_INX   = LT_HEADER_X
        TABLES
          RETURN                            = LT_RETURN
          ORDER_ITEM_IN               = LT_ITEMS
          ORDER_ITEM_INX             = LT_ITEM_X
          ORDER_CFGS_REF          = LT_CFGS_REF
          ORDER_CFGS_INST         =  LT_PARTS
          ORDER_CFGS_VALUE     = LT_VALUES
          ORDER_CFGS_BLOB        = LT_CUBLOB
          ORDER_CFGS_VK            = LT_CUVK
          ORDER_CFGS_REFINST   = LT_CUREF
          SCHEDULE_LINES            = LT_SCHEDULE_L
          SCHEDULE_LINESX         = LT_SCHEDULE_X
          ORDER_TEXT                   = LT_TEXT
          CONDITIONS_IN                = LT_CONDITION_L
          CONDITIONS_INX              = LT_CONDITION_X.
    Any help is appreciated.
    Regards,
    Nagarajan.J

    Hi,
    Storage location is updated only when same sale order bapi is called another time with required details.
    rgs,
    Nagarajan J

  • Calling a Sales Order Change BAPI in a Sales Order Exit

    Functional Requirement:
    While creating a Sales Order with Reference to another Sales Order, on saving the new sales order, change something in the referenced sales order.
    I am trying to achieve the same by doing the following:
    In the standard SAP user exit called during saving the new sales order USEREXIT_SAVE_DOCUMENT I am calling the BAPI BAPI_SALESORDER_CHANGE on the referenced Sales Order.
    However the BAPI is unable to change the other sales order giving an error Enter the document number. I am specifying the Document Number while calling the BAPI, so I know that is not the error.
    I just wish to know whether it is technically possible to call a BAPI to update another Sales Order while we are currently saving one Sales Order.

    Hi Girish,
    If it works correctly when run seperately and you are sure the data passed into the BAPI is exactly the same then it may be something like table locks or similar causing your original problems...
    What about packaging up your working Z program into a custom function module and calling that from within USEREXIT_SAVE_DOCUMENT as a seperate task (IN NEW TASK) and building in a slight delay of say 5 seconds at the start of your code?
    I'll be honest, this isn't an ideal solution but might be sufficient to resolve your issues.  I'd be inclined to see if you could just run your Z program as a background process every 5 minutes or so to capture any changes and perform updates but if this is a no no from your functional people I'm not sure what else to suggest sorry.  I've never personally had to update a document from within the save routine of another document so can't give any advice based on my own experiences sorry.
    Gareth.

  • Extending sales order change BAPI and updating custom fields

    Hi
    i added 3 new fields into VA01/02/03 screen.i added at the header level in the additional data tab B area and appended them in VBAK table.
    i want to change these values using sales order change BAPI.i added the fields in the structure VBAKKOZ,VBAKKOZX,BAPE_VBAK,BAPE_VBAKX.
    may i know what else i need to do?should i move them anywhere with in the code or does the bapi take those values automatically using EXTENSIONIN structure?
    also can some one send me code to actually check if bapi is changing my values?
    if poss tell me how should i populate values into BAPI.

    After adding field in structures VBAKKOZ,VBAKKOZX,BAPE_VBAK,BAPE_VBAKX, create pair of name-value pair extensiot structure and value.
    Fill values as follows :
    Data :   ls_parex  TYPE  bapiparex,
                lt_parex  TYPE STANDARD TABLE OF  bapiparex.
    ls_parex-structure = 'BAPE_VBAK'.
    ls_parex-valuepart1+0(10) = Sales order no
    ls_parex-valuepart1+10(XX) = somevalue.  <---- Value for custom field no 1
    ls_parex-valuepart1+XX(XX) = somevalue.  <---- Value for custom field no 2
    APPEND ls_parex TO lt_parex  .
    clear ls_parex.
    ls_parex-structure = 'BAPE_VBAKX'.
    ls_parex-valuepart1+0(10) = Sales order no
    ls_parex-valuepart1+10(1) = 'X'. <--- checkbox mark for custom field no 1
    ls_parex-valuepart1+11(1) = 'X'. <--- checkbox mark for custom field no 2
    APPEND ls_parex TO lt_parex.
    Same pair for VBAKKOZ & VBAKKOZX
    Updating custom fields
      CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
        EXPORTING
          salesdocument    = Sales order number
          order_header_inx = 'U'   <--- U for update
        TABLES
          extensionin      = lt_parex[].
    Edited by: nkarwa on Oct 25, 2010 12:39 PM

  • BAPI_SALESORDER_SIMULATE can be used in case of Sales Order Change?

    Hi All,
    I'm using FM 'BAPI_SALESORDER_CHANGE' to update sales order.
    It's working fine even multiful item (delete, add, changing item).
    But I need to give simulated information to SAP portal before changing Sales order.
    This 'BAPI_SALESORDER_SIMULATE' FM looks like for creating new Sales Order.
    Is there any other simulation BAPI FM for Sales order change?
    Thanks.

    Hi,
    You can use
    BAPI_ORDER_CHANGE_STATUS_GET   Change status for order                                                  
    BAPI_SALESORDER_CHANGE         Sales Order: Change Sales Order                                          
    Thanks
    Sarada

  • Error in JCo while connecting BAPI SALES ORDER.

    package com.sap;
    import com.sap.mw.jco.JCO;
    import com.sap.mw.jco.JCO.Exception;
    import com.sapportals.portal.prt.component.AbstractPortalComponent;
    import com.sapportals.portal.prt.component.IPortalComponentRequest;
    import com.sapportals.portal.prt.component.IPortalComponentResponse;
    public class DirectBAPI extends AbstractPortalComponent
        public void doContent(IPortalComponentRequest request,   
             IPortalComponentResponse response)
                 JCO.Client mConnection;
                  JCO.Repository mRep;
          response.write("Connecting..........");
        try
                                    // Change the logon information to your own system/user
       mConnection =  JCO.createClient("<client number>",  "<user Id>",  "password",                             
              null,                 // language
         "application server number",                "<system no..>");       
               response.write("Reached");
             mConnection.connect();                // connecting JCo...
    mRep = new JCO.Repository("SAPJCo", mConnection);   //use JCo    Repository....
         response.write("Connected Succesfully");
        //response.write( mConnection.getAttributes() );
       // mConnection.disconnect();
    catch (Exception ex)
         ex.printStackTrace();
           response.write(ex.getMessage());
       JCO.Function function = null;
       JCO.FunctionTemplate ftp = null;        
       JCO.Table codes = null;
    try
             ftp = mRep.getFunctionTemplate();
             function = ftp.getFunction();
             function = this.createFunction("BAPI_SALESORDER_GETSTATUS");   
                                             // Accessing SALES_ORDER_GETSTATUS.
             if (function == null)
                 response.write("BAPI_COMPANYCODE_GETLIST"  +  " not found in SAP.");
       catch (Exception exx)
          response.write(exx.getmessage() );
       In the above code while while connecting to the BAPI SALES ORDER GET_STATUS an error is coming for JCO connection for the JCo Repository.
    The method createFunction() is undefined for the type of Project.
    plz guide how to rectify this so as to connect BAPI SALES ORDER thru JCo connection.
    Thanx in advance.
    Regards:
    Hanif

    Hi,
    The below Code is helpful for Calling BAPI's Using JCO .
    public class TestJCO {
         JCO.Client mConnection;
          JCO.Repository mRepository;
          public TestJCO() {
            try {
               // Change the logon information to your own system/user
    //           mConnection =
    //             JCO.createClient("800", // SAP client
    //                "USERID",           // userid
    //                "password",               // password
    //                null,                 // language
    //                "appserver hostname",         // application server host name
    //                "00");                // system number
              mConnection =
                JCO.createClient("002", // SAP client
                   "userid",           // userid
                   "password",               // password
                   null,                 // language
                   "app server host name",         // application server host name
                   "00");                // system number
               mConnection.connect();
               mRepository = new JCO.Repository("companyname", mConnection);
            catch (Exception ex) {
               ex.printStackTrace();
               System.exit(1);
            JCO.Function function = null;
            JCO.Table codes = null;
            try {
               function = this.createFunction("BAPI_COMPANYCODE_GETLIST");
               if (function == null) {
                 System.out.println("BAPI_COMPANYCODE_GETLIST" +
                                         " not found in SAP.");
                 System.exit(1);
               mConnection.execute(function);
               JCO.Structure returnStructure =
                 function.getExportParameterList().getStructure("RETURN");
               if (! (returnStructure.getString("TYPE").equals("") ||
                        returnStructure.getString("TYPE").equals("S")) ) {
                 System.out.println(returnStructure.getString("MESSAGE"));
                 System.exit(1);
               codes =
                 function.getTableParameterList().getTable("COMPANYCODE_LIST");
               for (int i = 0; i < codes.getNumRows(); i++) {
                 codes.setRow(i);
                 System.out.println(codes.getString("COMP_CODE") + '\t' +
                                         codes.getString("COMP_NAME"));
            catch (Exception ex) {
               ex.printStackTrace();
               System.exit(1);
            try {
               codes.firstRow();
               for (int i = 0; i < codes.getNumRows(); i++, codes.nextRow()) {
                 function = this.createFunction("BAPI_COMPANYCODE_GETDETAIL");
                 if (function == null) {
                    System.out.println("BAPI_COMPANYCODE_GETDETAIL" +
                                            " not found in SAP.");
                    System.exit(1);
                 function.getImportParameterList().
                    setValue(codes.getString("COMP_CODE"), "COMPANYCODEID");
                 function.getExportParameterList().setActive(false, "COMPANYCODE_ADDRESS");
                 mConnection.execute(function);
                 JCO.Structure returnStructure =
                    function.getExportParameterList().getStructure("RETURN");
                 if (! (returnStructure.getString("TYPE").equals("") ||
                          returnStructure.getString("TYPE").equals("S") ||
                          returnStructure.getString("TYPE").equals("W")) ) {
                    System.out.println(returnStructure.getString("MESSAGE"));
                 JCO.Structure detail =
                    function.getExportParameterList().
                    getStructure("COMPANYCODE_DETAIL");
                 System.out.println(detail.getString("COMP_CODE") + '\t' +
                                         detail.getString("COUNTRY") + '\t' +
                                         detail.getString("CITY"));
            catch (Exception ex) {
               ex.printStackTrace();
               System.exit(1);
            mConnection.disconnect();
          public JCO.Function createFunction(String name) throws Exception {
            try {
               IFunctionTemplate ft = mRepository.getFunctionTemplate(name.toUpperCase());
               if (ft == null)
                 return null;
               return ft.getFunction();
            catch (Exception ex) {
               throw new Exception("Problem retrieving JCO.Function object.");
         public static void main(String[] args) {
              TestJCO app = new TestJCO();
    Please Check your code with above code.
    Thanks,
    SubbaRao Chinta

  • BAPI Sales order create with reference

    Hi
    I need to use BAPI to create sales order with reference to Quantity Contract. The line item material quantity would be less than or equal to quantity contract quantity.
    Sales order needs to be created with new quantity.
    Quantity contract quantity change needs to be maintained.
    Document flow needs to be maintained.
    Is any one aware if this is possible using BAPI_SALESORDER_CREATEFROMDAT2. If yes, how?
    Any insights would be highly appreciated.

    Hi Maninder,
    The BAPI does not allow the Pricing Conditions to be sourced from the Contract. I debugged the BAPI and it uses a piece of code (don't recall which subroutine though) from SAPMV45A which is relevant for dialog processing where it reads from the VBAP and *VBAP structures. Well this structure is only populated when you are using the Front End transaction (VA41, VA42, etc). Because this structure is empty, pricing conditions do not flow across.
    Here is a little prototype program I whipped up to test my method of creating a Sales order and then changing the Sales Order:
    REPORT  ypat_salesorder_create LINE-SIZE 256.
    * This program will create a ZOC Sales Order with Reference to Contract
    * 20000720 / 10. This will be done via BAPI. There are 2 BAPi calls,
    * BAPI_SALESORDER_CREATEFROMDAT2 and BAPI_SALESORDER_CHANGE. We need to
    * perform 2 BAPI calls as the BAPI to create the Sales Order does not
    * bring across the Pricing Conditions properly. To get around this we
    * create the Order with reference to the Contract, then we get the
    * related Pricing Conditions from the COntract and then update the newly
    * created Order.
    * Constants
    CONSTANTS: c_contract  LIKE vbak-vbeln VALUE '0020000720',
               c_item      LIKE vbap-posnr VALUE '000010'.
    * Structures
    * Structure to hold BAPI Header
    DATA: st_bapisdhd1   LIKE bapisdhd1.
    * Internal Tables
    * Sales Order Create BAPI Return Messages
    DATA: tbl_return     TYPE STANDARD TABLE OF bapiret2
                         WITH HEADER LINE.
    * Sales Order BAPI Line Item
    DATA: tbl_bapisditm  TYPE STANDARD TABLE OF bapisditm
                         WITH HEADER LINE.
    * Sales Order BAPI Line Item
    DATA: tbl_bapisditmx  TYPE STANDARD TABLE OF bapisditmx
                         WITH HEADER LINE.
    * Sales Order BAPI Pricing Conditions
    DATA: tbl_bapicond   TYPE STANDARD TABLE OF bapicond
                         WITH HEADER LINE.
    * Sales Order BAPI Partner Functions
    DATA: tbl_bapiparnr  TYPE STANDARD TABLE OF bapiparnr
                         WITH HEADER LINE.
    * Sales Order BAPI Schedule Lines
    DATA: tbl_bapischdl  TYPE STANDARD TABLE OF bapischdl
                         WITH HEADER LINE.
    * Sales Order BAPI Schedule Lines
    DATA: tbl_bapischdlx TYPE STANDARD TABLE OF bapischdlx
                         WITH HEADER LINE.
    * Sales Order BAPI Pricing Conditions
    DATA: tbl_bapicondx    TYPE STANDARD TABLE OF bapicondx
                           WITH HEADER LINE.
    * Customer Enhancement for VBAK, VBAP, VBEP
    DATA: tbl_bapiparex    TYPE STANDARD TABLE OF bapiparex
                           WITH HEADER LINE.
    * Table to hold BAPI Detail Conditions
    DATA: tbl_bapisdcond   TYPE STANDARD TABLE OF bapisdcond
                           WITH HEADER LINE.
    * Table to hold Return Messages from Sales Order Change BAPI
    DATA: tbl_return_chg  TYPE STANDARD TABLE OF bapiret2
                          WITH HEADER LINE.
    * Variables
    DATA: g_vbeln_created   LIKE vbak-vbeln,
          g_valid_contract  TYPE c,
          g_cont_price_date TYPE d.
    * Start of Selection
    START-OF-SELECTION.
      PERFORM validate_contract.
      PERFORM create_sales_ord.
      PERFORM update_sales_ord.
    * End of Selection
    END-OF-SELECTION.
      PERFORM write_output_report.
    * Subroutines
    *&      Form  create_sales_ord
    *       Create the Sales Order
    FORM create_sales_ord .
      PERFORM populate_bapi_tables.
      PERFORM call_create_sales_ord_bapi.
    ENDFORM.                    " create_sales_ord
    *&      Form  populate_bapi_tables
    *       Fill up the BAPI Tables
    FORM populate_bapi_tables .
      PERFORM populate_bapi_header.
      PERFORM build_bapi_partners.
      PERFORM build_bapi_items.
      PERFORM build_bapi_sched_lines.
    ENDFORM.                    " populate_bapi_tables
    *&      Form  populate_bapi_header
    *       Build BAPI Header Details
    FORM populate_bapi_header .
      CLEAR st_bapisdhd1.
      st_bapisdhd1-doc_type     = 'ZOC'.         "Order type
      st_bapisdhd1-sales_org    = '026'.         "Sales Org
      st_bapisdhd1-distr_chan   = '00'.          "Dist Channel
      st_bapisdhd1-division     = '00'.          "Division
      st_bapisdhd1-purch_no_c   = 'Cust Po No'.  "Cust PO No
      st_bapisdhd1-name         = 'Orderer'.     "Name of Orderer
      st_bapisdhd1-ord_reason   = ''.            "Order Reason
      st_bapisdhd1-sales_off    = '3001'.        "Sales Office
      st_bapisdhd1-sales_grp    = '301'.         "Market Area
      IF g_valid_contract = 'X'.
        st_bapisdhd1-price_date = g_cont_price_date.
      ENDIF.
    ENDFORM.                    " populate_bapi_header
    *&      Form  build_bapi_partners
    *       Build BAPI Partner Functions
    FORM build_bapi_partners .
      CLEAR tbl_bapiparnr.
      tbl_bapiparnr-partn_role   = 'AG'.
      tbl_bapiparnr-partn_numb   = '0000100750'.
      APPEND tbl_bapiparnr.
      CLEAR tbl_bapiparnr.
      tbl_bapiparnr-partn_role   = 'WE'.
      tbl_bapiparnr-partn_numb   = '0000504472'.
      APPEND tbl_bapiparnr.
    ENDFORM.                    " build_bapi_partners
    *&      Form  build_bapi_items
    *       Build The BAPI Line Items
    FORM build_bapi_items .
      DATA: l_matnr LIKE mara-matnr.
      CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'
        EXPORTING
          input  = '10000072'
        IMPORTING
          output = l_matnr.
      CLEAR tbl_bapisditm.
      tbl_bapisditm-itm_number  = c_item.
      IF g_valid_contract = 'X'.
        tbl_bapisditm-ref_doc     = c_contract.
        tbl_bapisditm-ref_doc_it  = c_item.
        tbl_bapisditm-ref_doc_ca  = 'G'.       "Contract
      ENDIF.
      tbl_bapisditm-material    = l_matnr.
      tbl_bapisditm-plant       = '3012'.
      tbl_bapisditm-target_qty  = '5.000'.
      tbl_bapisditm-target_qu   = 'M3'.
      tbl_bapisditm-item_categ  = 'ZZOC'.
      tbl_bapisditm-sales_dist  = '301'.
      tbl_bapisditm-dlv_prio    = '02'.
      tbl_bapisditm-prc_group5  = '080'.
      tbl_bapisditm-cust_mat35  = 'kdmat'.
      tbl_bapisditm-route       = 'TESYS'.
      tbl_bapisditm-usage_ind   = 'CIV'.
      APPEND tbl_bapisditm.
      CLEAR tbl_bapisditmx.
      tbl_bapisditmx-itm_number = c_item.
      tbl_bapisditmx-ref_doc    = 'X'.
      tbl_bapisditmx-ref_doc_it = 'X'.
      tbl_bapisditmx-ref_doc_ca = 'X'.
      tbl_bapisditmx-material   = 'X'.
      tbl_bapisditmx-updateflag = 'I'.
      tbl_bapisditmx-plant      = 'X'.
      tbl_bapisditmx-target_qty = 'X'.
      tbl_bapisditmx-target_qu  = 'X'.
      tbl_bapisditmx-item_categ = 'X'.
      tbl_bapisditmx-sales_dist = 'X'.
      tbl_bapisditmx-dlv_prio   = 'X'.
      tbl_bapisditmx-prc_group5 = 'X'.
      tbl_bapisditmx-cust_mat35 = 'X'.
      tbl_bapisditmx-usage_ind  = 'X'.
      tbl_bapisditmx-route      = 'X'.
      APPEND tbl_bapisditmx.
    ENDFORM.                    " build_bapi_items
    *&      Form  build_bapi_sched_lines
    *       Build the BAPI Schedule Lines
    FORM build_bapi_sched_lines .
      CLEAR tbl_bapischdl.
      tbl_bapischdl-itm_number  = c_item.
      tbl_bapischdl-req_qty     = '1'.
      tbl_bapischdl-req_date    = sy-datum.
      APPEND tbl_bapischdl.
    ENDFORM.                    " build_bapi_sched_lines
    *&      Form  build_bapi_conditions
    *       Pull the BAPI Pricing Conditions from the Contract
    FORM build_bapi_conditions .
      LOOP AT tbl_bapisdcond.
        CLEAR tbl_bapicond.
        MOVE-CORRESPONDING tbl_bapisdcond TO tbl_bapicond.
        APPEND tbl_bapicond.
        CLEAR tbl_bapicondx.
        tbl_bapicondx-itm_number = tbl_bapicond-itm_number.
        tbl_bapicondx-cond_st_no = tbl_bapicond-cond_st_no.
        tbl_bapicondx-cond_count = tbl_bapicond-cond_count.
        tbl_bapicondx-cond_type  = tbl_bapicond-cond_type.
        tbl_bapicondx-updateflag = 'I'.
        tbl_bapicondx-cond_value = 'X'.
        tbl_bapicondx-currency   = 'X'.
        tbl_bapicondx-cond_unit  = 'X'.
        tbl_bapicondx-cond_p_unt = 'X'.
        tbl_bapicondx-varcond    = tbl_bapicond-varcond.
        APPEND tbl_bapicondx.
      ENDLOOP.
    ENDFORM.                    " build_bapi_conditions
    *&      Form  call_create_sales_ord_bapi
    *       Call the Sales Order Create BAPI
    FORM call_create_sales_ord_bapi .
      CLEAR g_vbeln_created.
      CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'
        EXPORTING
          order_header_in    = st_bapisdhd1
        IMPORTING
          salesdocument      = g_vbeln_created
        TABLES
          return             = tbl_return
          order_items_in     = tbl_bapisditm
          order_items_inx    = tbl_bapisditmx
          order_partners     = tbl_bapiparnr
          order_schedules_in = tbl_bapischdl.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDFORM.                    " call_create_sales_ord_bapi
    *&      Form  update_sales_ord
    *       Update the newly created Sales Order with the Pricing Conditions
    *       from the Contract
    FORM update_sales_ord .
      CHECK g_valid_contract EQ 'X'.
      PERFORM get_contract_details.
      PERFORM build_bapi_conditions.
      PERFORM call_change_sales_ord_bapi.
    ENDFORM.                    " update_sales_ord
    *&      Form  get_contract_details
    *       Get Contract Details
    FORM get_contract_details .
    * Need to manually get the relevant Pricing Conditions as the BAPI
    * BAPISDORDER_GETDETAILEDLIST causes problems when we call the BAPI
    * BAPI_SALESORDER_CREATEFROMDAT2 and BAPI_SALESORDER_CHANGE (I think
    * this is due to the fact that these BAPIs belong to the same Function
    * Group and there must be some common structures that are not cleared
    * causing us all sorts of grief when we try and call the next BAPI)
      DATA: tbl_konv TYPE STANDARD TABLE OF konv WITH HEADER LINE.
      DATA: tbl_komv TYPE STANDARD TABLE OF komv WITH HEADER LINE.
      DATA: tbl_vbak TYPE STANDARD TABLE OF vbak WITH HEADER LINE.
    * Pricing Condition Master
      DATA: BEGIN OF tbl_t685a OCCURS 0,
              kschl     LIKE t685a-kschl,
              kaend_wrt LIKE t685a-kaend_wrt,
            END OF tbl_t685a.
      SELECT *
             INTO TABLE tbl_vbak
             FROM vbak
             WHERE vbeln = c_contract.
      READ TABLE tbl_vbak INDEX 1.
      SELECT *
             INTO TABLE tbl_konv
             FROM konv
             WHERE knumv = tbl_vbak-knumv AND
                   kposn = c_item.
      CHECK sy-subrc EQ 0.
    * We now need to make sure we only bring across the Condition Types that
    * are EDITABLE. If we bring across non editable conditions (such as
    * 'ZPR1') the Change Sales Order BAPI will fail
      SELECT kschl kaend_wrt
             INTO TABLE tbl_t685a
             FROM t685a
             FOR ALL ENTRIES IN tbl_konv
             WHERE kappl     EQ 'V'             AND  "Sales
                   kschl     EQ tbl_konv-kschl  AND
                   kaend_wrt EQ 'X'             AND  "Value is Editable
                   kmanu     NE 'D'.                 "Process manually
    * Prepare for Binary Search
      SORT tbl_t685a BY kschl.
      LOOP AT tbl_konv.
        READ TABLE tbl_t685a WITH KEY kschl = tbl_konv-kschl BINARY SEARCH.
        IF sy-subrc EQ 0.
          MOVE-CORRESPONDING tbl_konv TO tbl_komv.
          APPEND tbl_komv.
        ENDIF.
      ENDLOOP.
      CHECK NOT tbl_komv[] IS INITIAL.
    * Map KOMV into the more BAPI friendly BAPISDCOND structure
      CALL FUNCTION 'MAP_INT_TO_EXT_STRUCTURE'
        TABLES
          fxvbak        = tbl_vbak
          fxkomv        = tbl_komv
          fxbapikomv    = tbl_bapisdcond
        EXCEPTIONS
          entry_missing = 1
          OTHERS        = 2.
    ENDFORM.                    " get_contract_details
    *&      Form  call_change_sales_ord_bapi
    *       Call the Change Sales Order BAPI
    FORM call_change_sales_ord_bapi .
      DATA: st_head_chg      LIKE bapisdh1x,
            st_logic_switch  TYPE bapisdls.
      CHECK NOT g_vbeln_created IS INITIAL.
      CHECK g_valid_contract EQ 'X'.
      st_head_chg-updateflag     = 'U'.
      st_logic_switch-cond_handl = 'X'.
      CALL FUNCTION 'BAPI_SALESORDER_CHANGE'
        EXPORTING
          salesdocument    = g_vbeln_created
          order_header_inx = st_head_chg
          logic_switch     = st_logic_switch
        TABLES
          return           = tbl_return_chg
          conditions_in    = tbl_bapicond
          conditions_inx   = tbl_bapicondx.
      CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
        EXPORTING
          wait = 'X'.
    ENDFORM.                    " call_change_sales_ord_bapi
    *&      Form  write_output_report
    *       Produce Output Report
    FORM write_output_report .
      IF NOT g_vbeln_created IS INITIAL.
        WRITE:/ 'Success! Sales Order', g_vbeln_created, 'was created!'.
      ELSE.
        WRITE:/ 'Failure! Sales Order was not created!'.
      ENDIF.
      SKIP.
      WRITE:/ 'Sales Order Create Log'.
      LOOP AT tbl_return.
        WRITE:/ tbl_return-type, tbl_return-id, tbl_return-number,
                tbl_return-message.
      ENDLOOP.
      SKIP.
      WRITE:/ 'Sales Order Change Log'.
      LOOP AT tbl_return_chg.
        WRITE:/ tbl_return_chg-type, tbl_return_chg-id,
                tbl_return_chg-number, tbl_return_chg-message.
      ENDLOOP.
    ENDFORM.                    " write_output_report
    *&      Form  validate_contract
    *       Make sure that the Contract is Valid
    FORM validate_contract .
      DATA: l_gueen  LIKE vbak-gueen,
            l_prsdt  LIKE vbkd-prsdt.
      SELECT SINGLE  vbak~gueen vbkd~prsdt
             INTO (l_gueen, l_prsdt)
             FROM vbak
             INNER JOIN vbkd
             ON vbak~vbeln = vbkd~vbeln
             WHERE vbak~vbeln = c_contract AND
                   vbkd~posnr = '000000'.
      IF sy-datum LE l_gueen.
    * Contract is valid! Set Order Price Date
        g_valid_contract  = 'X'.
        g_cont_price_date = l_prsdt.
      ENDIF.
    ENDFORM.                    " validate_contract
    Hope this helps.
    Cheers,
    Pat.

  • Report for Sales Order Change History   CDPOS and CDHDR

    How to take a report of the data for the Sales Order Change history for a particular period of time. It is required to take a report of all the Sales Orders for which the basic price has been changed. Please let me know the procedure. I could not get the data from the table CDPOS and CDHDR
    Helpful answer would be rewarded.
    Regards
    Praveen

    Dear Praveen Kumar
    Have you tried with VBAP where sale order details at item level would be stored.
    Moreover, to my knowledge, there won't be any changes as for as pricing is concerned at sale order level but there is at billing level.  Normally, any price increase / decrease would reflect in billing.  So why dont you to table join through SQVI VBAP (for sale order details) and VBRP (for billing details) so that you can compare the selling price in sale order with billing. 
    Thanks
    G. Lakshmipathi

  • Sale Order changes View

    Dear Guru's
    Is there any T-Code for verifying Sale Order changes (Step wise), as in my company Invoices are generated with lot of changes which not matching with Sale Order conditions. So I would like to moniter the Sale Order conditions changes. Kindly help me out.
    Thanks in advance

    Hi
    Sales order changes can be seen in the report only if the changes are made by any user(userid). If your problem is with changes in pricing conditons...then before comparing the sales orders and invoices, I advise you to check the copy controls and the price type used in the copy controls. If the price type selected is to redetermine the pricing, then you should check the validity of the conditon records. Sometimes, the conditon records may be different during sales order creation and invoice creation.
    Thanks,
    Ravi

  • Sales Orders Change Log question

    Hi All,
    I am currently working on a project that involves querying SAP Database to get custom reports via web browser, I've made a lot of advances and most of the site is ready but I'm missing just one item that I hope you could help me.
    Thing is I am working with the Sales Order change log and the problem comes one a user deletes a row. If I go to the change log inside SAP and see the differences a new record will be shown saying that row X was deleted and
    if I go to the database (ADOC and ADO1 tables) I don't have a way to see wich row was deleted.
    My way of doing this is to check for the number of rows on the current state of the sales order and check the same on the previous instance of the SO and see if a line was deleted. Then I would have to check row by row between instances what rows are there and what row is missing and store that info. I think this kind of approach will definitively kill the server.
    I was wondering if some one can give me a hint about how to approach this problem. Does any body know how SAP works on this area?
    I'm working with SAP2005A and SQL Server 2005 Standard Edition.
    Any help is greatly appreciated.
    Thanks!
    Alejandro.-

    Hola Alejandro,
    Thanks for your answer, as I see it I'm doing exactly what you proposed but the problem comes with the following scenarios:
    a.- If I post a new SO with two lines I will have on the ADO1 table two records with the values 0 and 1 for each line respectively but if I delete the item on LineNum = 1 and then I add a new item, this last item will be also created with LineNum value = 1. This is not a complicated thing to do but the problem comes when the user is used to work with SOs with several items at detail level and is used to add and erase lines once in a while and as I see it it's very difficult for me to track those specific changes. There's also the fact that on the Log table a new instance is created every time the user hits the update button regardless if a modification was actually made or not. I mean I would know that a line was deleted or added but I would have to start comparing each field on each line of a sales order with it's previous instance to check what was actually added/deleted and I'm afraid that this may affect the server performance. I know that SAP does this without affecting to much the system resources and that is what I'm trying to find.
    I forgot the other scenario I was considering he he I will post again as soon as I remember it but I hope I'm explaining this ok (I'm not very good at explaining...) If not let me know and I'll try to explain again.
    I'm also working on trying to get another approach to see what comes up...
    Thanks for checking this thread, your answers are helpful.
    Regards.

  • Authorization at Sales Order Change (Item level)

    Hello Experts,
    Is there any standard authorization object at sales order for adding new items? As I want to restrict some users to add new item lines at sales order change ( VA02 )
    Regards,
    Amr

    Hello,
    How can I use this object V_VBAK_AAT to disallow users to add
    some item lines from VA02 but users can change any other functions
    at the sales order (e.g. update pricing conditions)?
    As I see on this object V_VBAK_AAT, If I revoked ACTVT = 02 'Change',
    It will revoke all change functions from users.
    I think the best solution for your requirment would be to seek the help of Basis folk to create a new User ID which would be having access to Change mode of Sales Order (VA02). Then you can restrict addition of Material line item with the help of Technical consultant by putting up code in following User exit.The logic in the code will be addition of Material line item will be restricted if the User Name is the newly created one...
    1:- MV45AFZB -- USEREXIT_CHECK_VBAP
    2:- MV45AFZZ -- USEREXIT_MOVE_FIELD_TO_VBAP
    3:- MV45AFZZ -- USEREXIT_SAVE_DOCUMENT_PREPARE
    Regards,
    Sarthak
    PS : On information note, you can refer the t-code SU24 to see the standard authorization object for change mode of Sales Order.

  • Billing Block removal not updated in the sales order change log

    Hi Gurus,
    A specific Billing Block is automatically assigned to the sales document header (VBAK-FAKSK) when the net value of the sales order is negative. This is an order related billing.
    Sometimes the Billing block is getting released automatically and the Negative Invoice is getting created in the Background job run for creating the invoices. When we check the sales order, the Billing block is not existing and the removal of the billing block is not recorded in the Change Log of the sales order.In the CDHDR table also there are no details about the release of the billing block.
    This is happening only occassionally. When I tried to replicate the issue, the system is not allowing me to create the invoice as long as the billing block is there in the sales order and if I remove the block, it is recorded in the sales order change log.
    My doubt is.,
    1. How the billing block is getting released automatically?
    2. Even if the block is released,  why it is not recorded in the Change Log of the sales order?
    Looking forward your for suggestions and solutions.
    Thanks,
    Ravi

    Hi
    Did u check in sales doc. details screen.There u can block for billing.

Maybe you are looking for

  • HELP!! My 8830 won't place calls.

     I activated my 8830 World Edition yesterday. I can use the interent, email, and text messaging, but i cannot place or receive phone calls. Everytime i try to place a call i get the error: Sorry, Only emergency calls can be placed. has anyone had thi

  • Read multiple axis status

    The problem is the slowness of some commands in Labview 8.2 (winxp and PXI-8105 controller) I am trying to control the speed of a three axis robot  using a PXI-7350 motion controller, but I need to update very fastly the control loop (1-2ms) I found

  • IPhoto photos come up black

    When I import photos from my camera or phone to iPhoto, some of the photos come up black and I am only able to view them if I look at them through the editing feature. Please help!!

  • Get Images from URL's with slight difference?

    Does anyone know how I can download an image referenced in a web page? Get Image URLS from webpage doesn't work, because it is referenced in an unusual way: <input type="image" name="theImage" src="http://www.mysite.co.uk.uk/myservlets/myServlet?reqt

  • HT1414 Things that i downloading the first time it not working now why is that

    Things that i downloading the first time it not working now why is that