Skip to Content
author's profile photo Former Member
Former Member

BAPI_SALESORDER_CREATEFROMDAT2 and modifying materials configuration

Hi. I used the BAPI_SALES_ORDER_CREATEFROMDAT2 to create a sales order with materials configuration. It's work nice.

But now I'm trying to update/insert some characteristics.

When I create the order I used this code:

  • Solo posicion de material configurable

CLEAR wa_product.

wa_product-itm_number = '000010'.

wa_product-po_itm_no = '000010'.

wa_product-material = 'CYP'.

wa_product-plant = 'M014'.

wa_product-item_categ = 'ZPCP'.

wa_product-po_method = 'SC'.

wa_product-sales_dist = 'Z00001'.

wa_product-sales_unit = 'ST'.

APPEND wa_product TO gt_product.

CLEAR wa_cfg_cfg.

wa_cfg_cfg-posex = '000010'.

wa_cfg_cfg-config_id = '000001'.

wa_cfg_cfg-root_id = '00000001'.

APPEND wa_cfg_cfg TO gt_cfg_cfg.

CLEAR wa_cfg_cfg.

wa_cfg_cfg-posex = '000010'.

wa_cfg_cfg-config_id = '000001'.

wa_cfg_cfg-root_id = '00000002'.

APPEND wa_cfg_cfg TO gt_cfg_cfg.

  • order_cfg_values

CLEAR wa_cfg_val.

wa_cfg_val-config_id = '000001'.

wa_cfg_val-inst_id = '00000001'.

wa_cfg_val-charc = 'CYP_CARROC_PINTURA'.

wa_cfg_val-value = 'PA10'.

APPEND wa_cfg_val TO gt_cfg_val.

CLEAR wa_cfg_val.

wa_cfg_val-config_id = '000001'.

wa_cfg_val-inst_id = '00000001'.

wa_cfg_val-charc = 'CYP_CARROC_PINTURA'.

wa_cfg_val-value = 'PA20'.

APPEND wa_cfg_val TO gt_cfg_val.

I' using this code trying to update de sales order

wa_header-doc_type = 'ZBPL'.

wa_header1x-updateflag = 'U'.

wa_header1x-doc_type = 'X'.

CLEAR wa_product.

wa_product-itm_number = '000010'.

wa_product-po_itm_no = '000010'.

APPEND wa_product TO gt_product.

CLEAR wa_product1.

wa_product1-itm_number = '000010'.

wa_product1-updateflag = 'U'.

APPEND wa_product1 TO gt_product1.

CLEAR wa_cfg_cfg.

wa_cfg_cfg-posex = '000010'.

wa_cfg_cfg-config_id = '000001'.

wa_cfg_cfg-root_id = '00000003'.

APPEND wa_cfg_cfg TO gt_cfg_cfg.

CLEAR wa_cfg_val.

wa_cfg_val-config_id = '000001'.

wa_cfg_val-inst_id = '00000001'.

wa_cfg_val-value = 'PA30'.

APPEND wa_cfg_val TO gt_cfg_val.

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

salesdocumentin = '0000082891'

order_header_in = wa_header

order_header_inx = wa_header1x

TABLES

return = gt_return

order_items_in = gt_product

order_items_inx = gt_product1

order_partners = gt_partner

order_cfgs_ref = gt_cfg_cfg

order_cfgs_value = gt_cfg_val.

But it's doesn't work.

Some body have an idea???

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Jan 27, 2008 at 12:29 AM

    Hi Diego,

    The BIG problem is that if you want to update a sales order you cannot use createfromdat2 you have to use the salesorderchange BAPI... be careful to fill the appropiate values for the INX parameters to change the values you want.

    Cya,

    Dimas Salazar

    Caracas-Venezuela

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 27, 2008 at 06:20 AM

    Hi Helfer, check this code.

    REPORT Z_SALES_ORDER_CHANGE

    NO STANDARD PAGE HEADING

    LINE-SIZE 132

    LINE-COUNT 65(0)

    MESSAGE-ID ZZ.

    TABLES: VBAP.

    DATA:

    V_FILEIN(90) TYPE C,

    V_RECIN TYPE I,

    V_RECVBAP TYPE I,

    V_RECORDER TYPE I,

    V_VBELN LIKE VBAP-VBELN,

    ORDERHEADERINX LIKE BAPISDH1X.

    DATA: BEGIN OF I_ORDERS OCCURS 0,

    VBELN LIKE VBAK-VBELN,

    POSNR LIKE VBAP-POSNR,

    BRGEW(18) TYPE C,

    VOLUM(18) TYPE C,

    END OF I_ORDERS.

    DATA: BEGIN OF I_OUTPUT OCCURS 0,

    VBELN LIKE VBAK-VBELN,

    POSNR LIKE VBAP-POSNR,

    • GEWEI LIKE VBAP-GEWEI,

    BRGEW LIKE VBAP-BRGEW,

    VOLUM LIKE VBAP-VOLUM,

    CKWGT TYPE C,

    CKVOL TYPE C,

    END OF I_OUTPUT.

    DATA: BEGIN OF ORDERITEMIN OCCURS 0.

    INCLUDE STRUCTURE BAPISDITM.

    DATA: END OF ORDERITEMIN.

    DATA: BEGIN OF ORDERITEMINX OCCURS 0.

    INCLUDE STRUCTURE BAPISDITMX.

    DATA: END OF ORDERITEMINX.

    DATA: BEGIN OF RETURN OCCURS 0.

    INCLUDE STRUCTURE BAPIRET2.

    DATA: END OF RETURN.

    DATA: BEGIN OF BAPIRETURN OCCURS 0.

    INCLUDE STRUCTURE BAPIRET2.

    DATA: END OF BAPIRETURN.

    PARAMETERS:

    P_PATH(45) TYPE C DEFAULT '/usr/users/ftpsapom/' LOWER CASE,

    P_FNAME(32) TYPE C DEFAULT '/sweetjo.txt' LOWER CASE.

    START-OF-SELECTION.

    • CONCATENATE PATH AND FILE NAME INTO ONE VARIABLE

    CONCATENATE P_PATH P_FNAME INTO V_FILEIN.

    • OPEN DATASET

    IF V_FILEIN IS INITIAL.

    MESSAGE E002 WITH 'FILE' V_FILEIN 'DOES NOT CONTAIN ANY DATA!'.

    • & & & &

    ELSE.

    OPEN DATASET V_FILEIN

    FOR INPUT

    IN TEXT MODE.

    IF SY-SUBRC = 0.

    • READ DATASET

    DO.

    READ DATASET V_FILEIN INTO I_ORDERS.

    IF SY-SUBRC = 0.

    APPEND I_ORDERS.

    ELSE.

    EXIT.

    ENDIF.

    ENDDO.

    • CLOSE DATASET

    CLOSE DATASET V_FILEIN.

    IF SY-SUBRC <> 0.

    MESSAGE E002 WITH 'ERROR - CLOSING' V_FILEIN.

    • & & & &

    ENDIF.

    ELSE.

    MESSAGE E002 WITH 'ERROR - COULD NOT OPEN' V_FILEIN.

    • & & & &

    ENDIF.

    ENDIF.

    • SORT AND REMOVE DUPLICATES FROM I_ORDERS

    SORT I_ORDERS BY VBELN POSNR.

    DELETE ADJACENT DUPLICATES FROM I_ORDERS.

    • POPULATE I_OUTPUT

    LOOP AT I_ORDERS.

    SHIFT I_ORDERS-POSNR LEFT DELETING LEADING SPACE.

    CONCATENATE '0' I_ORDERS-POSNR INTO I_ORDERS-POSNR.

    SELECT SINGLE BRGEW VOLUM

    FROM VBAP

    INTO (VBAP-BRGEW, VBAP-VOLUM)

    WHERE VBELN = I_ORDERS-VBELN

    AND POSNR = I_ORDERS-POSNR.

    IF SY-SUBRC = 0.

    IF VBAP-BRGEW = 0.

    I_OUTPUT-CKWGT = 'X'.

    ENDIF.

    IF VBAP-VOLUM = 0.

    I_OUTPUT-CKVOL = 'X'.

    ENDIF.

    I_OUTPUT-VBELN = I_ORDERS-VBELN.

    I_OUTPUT-POSNR = I_ORDERS-POSNR.

    • I_OUTPUT-GEWEI = 'ST'.

    I_OUTPUT-BRGEW = I_ORDERS-BRGEW.

    I_OUTPUT-VOLUM = I_ORDERS-VOLUM.

    APPEND I_OUTPUT.

    CLEAR: I_OUTPUT.

    ENDIF.

    V_RECIN = V_RECIN + 1.

    ENDLOOP.

    • POPULATE BAPI DATA AND RUN BAPI

    CLEAR: ORDERHEADERINX, ORDERITEMIN, ORDERITEMINX,

    RETURN, BAPIRETURN.

    REFRESH: ORDERITEMIN, ORDERITEMINX, RETURN, BAPIRETURN.

    ORDERHEADERINX-UPDATEFLAG = 'U'.

    LOOP AT I_OUTPUT WHERE CKWGT = 'X' OR CKVOL = 'X'.

    V_RECVBAP = V_RECVBAP + 1.

    IF I_OUTPUT-VBELN <> V_VBELN AND SY-TABIX <> 1.

    V_RECORDER = V_RECORDER + 1.

    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

    EXPORTING

    SALESDOCUMENT = V_VBELN

    ORDER_HEADER_INX = ORDERHEADERINX

    TABLES

    RETURN = RETURN

    ORDER_ITEM_IN = ORDERITEMIN

    ORDER_ITEM_INX = ORDERITEMINX.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'

    IMPORTING

    RETURN = BAPIRETURN.

    • WRITE OUT RETURN

    LOOP AT RETURN.

    WRITE: / RETURN.

    ENDLOOP.

    WRITE: / BAPIRETURN.

    SKIP.

    CLEAR: ORDERITEMIN, ORDERITEMINX,

    RETURN, BAPIRETURN.

    REFRESH: ORDERITEMIN, ORDERITEMINX, RETURN, BAPIRETURN.

    ENDIF.

    ORDERITEMIN-ITM_NUMBER = I_OUTPUT-POSNR.

    • ORDERITEMIN-UNTOF_WGHT = I_OUTPUT-GEWEI.

    IF NOT I_OUTPUT-CKWGT IS INITIAL.

    ORDERITEMIN-GROSS_WGHT = I_OUTPUT-BRGEW.

    ORDERITEMINX-GROSS_WGHT = 'X'.

    ENDIF.

    IF NOT I_OUTPUT-CKVOL IS INITIAL.

    ORDERITEMIN-VOLUME = I_OUTPUT-VOLUM.

    ORDERITEMINX-VOLUME = 'X'.

    ENDIF.

    APPEND ORDERITEMIN.

    ORDERITEMINX-ITM_NUMBER = I_OUTPUT-POSNR.

    • ORDERITEMINX-UNTOF_WGHT = 'X'.

    ORDERITEMINX-UPDATEFLAG = 'U'.

    APPEND ORDERITEMINX.

    V_VBELN = I_OUTPUT-VBELN.

    ENDLOOP.

    • RUN BAPI ON LAST ORDER

    IF NOT ORDERITEMIN IS INITIAL.

    V_RECORDER = V_RECORDER + 1.

    CALL FUNCTION 'BAPI_SALESORDER_CHANGE'

    EXPORTING

    SALESDOCUMENT = V_VBELN

    ORDER_HEADER_INX = ORDERHEADERINX

    TABLES

    RETURN = RETURN

    ORDER_ITEM_IN = ORDERITEMIN

    ORDER_ITEM_INX = ORDERITEMINX.

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'

    IMPORTING

    RETURN = BAPIRETURN.

    • WRITE OUT RETURN

    LOOP AT RETURN.

    WRITE: / RETURN.

    ENDLOOP.

    WRITE: / BAPIRETURN.

    SKIP.

    ENDIF.

    • WRITE OUT RECORD COUNT FROM FILE

    WRITE: / 'RECORD COUNT FROM FILE ', V_RECIN.

    SKIP.

    • WRITE OUT RECORD COUNT FROM FILE

    WRITE: / 'RECORD COUNT OF LINES TO CHANGE ', V_RECVBAP.

    SKIP.

    • WRITE OUT RECORD COUNT FROM FILE

    WRITE: / 'RECORD COUNT OF ORDERS TO CHANGE ', V_RECORDER.

    SKIP.

    • TOP OF PAGE

    TOP-OF-PAGE.

    WRITE:/1(5) TEXT-H01, 6(8) SY-DATUM MM/DD/YY,

    100(8) TEXT-H02, 126(8) SY-PAGNO.

    WRITE:/1(5) TEXT-H03, 6(8) SY-UZEIT USING EDIT MASK '__:__:__',

    20(77) TEXT-H04,

    100(8) TEXT-H05, 108(25) SY-REPID.

    WRITE:/1(6) TEXT-H06, 8(12) SY-UNAME,

    20(4) TEXT-H07, 25(32) SY-HOST,

    100(13) TEXT-H08, 121(8) SY-SYSID,

    129 '/', 130(3) SY-MANDT.

    ULINE.

    SKIP.

    kindly reward if found helpful.

    cheers,

    Hema.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 27, 2008 at 07:12 PM

    Thanks friend, but my problems is that I need to add a new characteristics that belong to a material configurations.

    That's the model:

    Position 10. Materials Configuration: CYP, characteristics PA10; PA20.

    Position 20. Materials 900000000

    I need to add a new characteristics as PA30 in Position 10 on Material Configuration CYP, not as an item position 30.

    Please help me.!

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 28, 2008 at 02:42 AM

    Hi,

    BAPI_SALESORDER_CREATEFROMDAT2 is used to create a new sales order, but not for changing.

    Use FM : BAPI_SALESORDER_CHANGE to change the characterstic of existing salesorder.

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.