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

BAPI to create sale order

hi all,

i now need to have a excel up load program to create sale order. i used the BAPI FM - BAPI_SALESORDER_CREATEFROMDAT2 for this. however, i have to populate one of the field, in the sale order un der VA01 screen > under item data > account assignment --> Profit segment .

i need to populate the product and region under profit center, however, this is a customize session for COPA, if not mistaken. can i use the BAPI above to do so, or i need to code for my own? how am i going to code it? can some one help? i am new to BAPI stuff...

very thanks

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

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

    Hi Lee, check this.

    Check this example of creating a sales order and for creating delivery...and PGI

    ************SALES ORDER INPUT CREATION.

    PARAMETERS: p_auart TYPE auart OBLIGATORY.

    PARAMETERS: p_vkorg TYPE vkorg OBLIGATORY.

    PARAMETERS: p_vtweg TYPE vtweg OBLIGATORY.

    PARAMETERS: p_spart TYPE vtweg OBLIGATORY.

    PARAMETERS: p_sold TYPE kunnr OBLIGATORY.

    PARAMETERS: p_ship TYPE kunnr OBLIGATORY.

    *ITEM

    PARAMETERS: p_matnr TYPE matnr OBLIGATORY.

    PARAMETERS: p_menge TYPE kwmeng OBLIGATORY.

    PARAMETERS: p_plant TYPE werks_d OBLIGATORY.

    PARAMETERS: p_itcat TYPE pstyv OBLIGATORY.

    • DATA DECLARATIONS.

    DATA: v_vbeln LIKE vbak-vbeln.

    DATA: header LIKE bapisdhead1.

    DATA: headerx LIKE bapisdhead1x.

    DATA: item LIKE bapisditem OCCURS 0 WITH HEADER LINE.

    DATA: itemx LIKE bapisditemx OCCURS 0 WITH HEADER LINE.

    DATA: partner LIKE bapipartnr OCCURS 0 WITH HEADER LINE.

    DATA: return LIKE bapiret2 OCCURS 0 WITH HEADER LINE.

    DATA: lt_schedules_inx TYPE STANDARD TABLE OF bapischdlx

    WITH HEADER LINE.

    DATA: lt_schedules_in TYPE STANDARD TABLE OF bapischdl

    WITH HEADER LINE.

    • HEADER DATA

    header-doc_type = p_auart.

    headerx-doc_type = 'X'.

    header-sales_org = p_vkorg.

    headerx-sales_org = 'X'.

    header-distr_chan = p_vtweg.

    headerx-distr_chan = 'X'.

    header-division = p_spart.

    headerx-division = 'X'.

    headerx-updateflag = 'I'.

    • PARTNER DATA

    partner-partn_role = 'AG'.

    partner-partn_numb = p_sold.

    APPEND partner.

    partner-partn_role = 'WE'.

    partner-partn_numb = p_ship.

    APPEND partner.

    • ITEM DATA

    itemx-updateflag = 'I'.

    item-itm_number = '000010'.

    itemx-itm_number = 'X'.

    item-material = p_matnr.

    itemx-material = 'X'.

    item-plant = p_plant.

    itemx-plant = 'X'.

    item-target_qty = p_menge.

    itemx-target_qty = 'X'.

    item-target_qu = 'EA'.

    itemx-target_qu = 'X'.

    item-item_categ = p_itcat.

    itemx-item_categ = 'X'.

    APPEND item.

    APPEND itemx.

    • Fill schedule lines

    lt_schedules_in-itm_number = '000010'.

    lt_schedules_in-sched_line = '0001'.

    lt_schedules_in-req_qty = p_menge.

    APPEND lt_schedules_in.

    • Fill schedule line flags

    lt_schedules_inx-itm_number = '000010'.

    lt_schedules_inx-sched_line = '0001'.

    lt_schedules_inx-updateflag = 'X'.

    lt_schedules_inx-req_qty = 'X'.

    APPEND lt_schedules_inx.

    • Call the BAPI

    CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'

    EXPORTING

    sales_header_in = header

    sales_header_inx = headerx

    IMPORTING

    salesdocument_ex = v_vbeln

    TABLES

    return = return

    sales_items_in = item

    sales_items_inx = itemx

    sales_schedules_in = lt_schedules_in

    sales_schedules_inx = lt_schedules_inx

    sales_partners = partner.

    • Check the return table.

    LOOP AT return WHERE type = 'E' OR type = 'A'.

    EXIT.

    ENDLOOP.

    IF sy-subrc = 0.

    WRITE: / 'Error in creating document'.

    ELSE.

    COMMIT WORK AND WAIT.

    WRITE: / 'Document ', v_vbeln, ' created'.

    ENDIF.

    ************DELIVERY CREATION.

    DATA: BEGIN OF t_vbap OCCURS 0,

    vbeln LIKE vbap-vbeln,

    posnr LIKE vbap-posnr,

    zmeng LIKE vbap-kwmeng,

    matnr LIKE vbap-matnr,

    werks LIKE vbap-werks,

    END OF t_vbap.

    DATA: t_request TYPE STANDARD TABLE OF bapideliciousrequest

    WITH HEADER LINE.

    DATA: t_created TYPE STANDARD TABLE OF bapideliciouscreateditems

    WITH HEADER LINE.

    DATA: t_return TYPE STANDARD TABLE OF bapiret2 WITH HEADER LINE.

    SELECT vbeln posnr zmeng matnr werks

    INTO TABLE t_vbap

    FROM vbap

    WHERE vbeln = v_vbeln.

    LOOP AT t_vbap.

    t_request-document_numb = t_vbap-vbeln.

    t_request-document_item = t_vbap-posnr.

    t_request-quantity_sales_uom = t_vbap-zmeng.

    t_request-quantity_base__uom = t_vbap-zmeng.

    t_request-id = 1.

    t_request-document_type = 'A'.

    t_request-delivery_date = sy-datum.

    t_request-material = t_vbap-matnr.

    t_request-plant = t_vbap-werks.

    t_request-date = sy-datum.

    t_request-goods_issue_date = sy-datum.

    t_request-goods_issue_time = sy-uzeit.

    APPEND t_request.

    ENDLOOP.

    CALL FUNCTION 'BAPI_DELIVERYPROCESSING_EXEC'

    TABLES

    request = t_request

    createditems = t_created

    return = t_return.

    READ TABLE t_return WITH KEY type = 'E'.

    IF sy-subrc = 0.

    MESSAGE e208(00) WITH 'Delivery creation error'.

    ENDIF.

    COMMIT WORK.

    *

    ************Post goods issue.

    READ TABLE t_created INDEX 1.

    DATA: vbkok_wa TYPE vbkok.

    vbkok_wa-vbeln_vl = t_created-document_numb.

    vbkok_wa-wabuc = 'X'.

    DATA: v_error.

    CALL FUNCTION 'WS_DELIVERY_UPDATE'

    EXPORTING

    vbkok_wa = vbkok_wa

    delivery = t_created-document_numb

    IMPORTING

    ef_error_in_goods_issue_0 = v_error.

    COMMIT WORK.

    cheers,

    Hema.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2008 at 03:03 AM

    Hi Lee, also check this to change sales order.

    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 foud helpful.

    cheers.

    Hema.

    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member

      hi,

      very thanks for this. but i have done all this. i were able to create a normal sale order correctly without any problem. just that i need to populate the field i mentioned above, but i got no idea how to do so, cause that part is customized for COPA. so i am asking how can i do so here...

  • author's profile photo Former Member
    Former Member
    Posted on Jan 18, 2008 at 03:22 AM

    Hi Lee, the go with COPA instead of BAPI.

    Basically COPA- Profitability Analysis enables you to evaluate market segments, which can be classified according to products, customers, orders or any combination of these, or strategic business units, such as sales organizations or business areas, with respect to your company's profit or contribution margin.

    The aim of COPA system is to provide your sales, marketing, product management and corporate planning departments with information to support internal accounting and decision-making.

    Costing based COPA requires :

    1. Define - CHAR & VALUE FIELDS

    2. Assign the new CHAR & VALUE FIELDS to OPERATING CONCERN

    3. Maintain the Characteristic values

    4. Define the Characteristic Derivation

    5. Define & Assign the Valuation Stratagy (for assiging the Costing sheet and value field for transfer the product cost information & also to assing the plan versions)

    6. Define & Assign the Costing keys - product / material type

    7. Assign the value fields to each cost component - use the same CCS which is used for material valuation - point of valuation depends on the client requirement

    8. In the step - Flow of actual values (condition type assignments both in SD & MM side hv to maintain to flow the values to VALUE FIELDS)

    9. Also includes the OKB9 assignments in case of FI flow

    10. Reporting .

    cheers,

    Hema.

    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.