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

BAPI_SALESORDER_CREATEFROMDAT2

Hi,

I am using BAPI_SALESORDER_CREATEFROMDAT2.

I use structure ORDER_ITEMS_IN to pass details of BOM header material and BOM components.

I use structure ORDER_SCHEDULES_IN to pass details of BOM header material and BOM components.

EG. BOM material (A), BOM components b,c,d

In ORDER_SCHEDULES_IN , I pass quantity of material A as 1 in ORDER_SCHEDULES_IN -req_qty.

When I pass quantity of A=1, b=1, c=1, d=1 , no sales order is created

When I pass only schedule line of header, namely A=1, sales order gets created with 4 line items, line item A has schedule line, b, c d, does not have schedule line but quantity gets displayed as 0.

Any pointers as to how to get BOM header + components in sales order.

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 28, 2008 at 04:47 AM

    Hai.

    Check the example.

    Check this sample program for creating delivery from a sales order.

    Give the sales order as input..

    PARAMETERS: p_vbeln LIKE vbak-vbeln.

    DATA: BEGIN OF t_vbap OCCURS 0,

    vbeln LIKE vbap-vbeln,

    posnr LIKE vbap-posnr,

    kwmeng 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 kwmeng matnr werks

    INTO TABLE t_vbap

    FROM vbap

    WHERE vbeln = p_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-kwmeng.

    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.

    READ TABLE t_created INDEX 1.

    WRITE: / 'Delivery - ', t_created-document_numb.

    Regards.

    Sowjanya.B.

    Add a comment
    10|10000 characters needed characters exceeded

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

    Hai.

    Chek this example code.

    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.

    Regards.

    Sowjanya.B

    Add a comment
    10|10000 characters needed characters exceeded

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

    Hi,, S V

    ----


    • Form salesdocu

    ----


    • This Subroutine is used to create Sales Order

    ----


    • -->P_HEADER Document Header Data

    • -->P_HEADERX Checkbox for Header Data

    • -->P_ITEM Item Data

    • -->P_ITEMX Item Data Checkboxes

    • -->P_LT_SCHEDULES_IN Schedule Line Data

    • -->P_LT_SCHEDULES_INX Checkbox Schedule Line Data

    • -->P_PARTNER text Document Partner

    • <--P_w_vbeln text Sales Document Number

    ----


    FORM create_sales_document changing P_HEADER like fs_header

    P_HEADERX like fs_headerx

    Pt_ITEM like t_item[]

    Pt_ITEMX like t_itemx[]

    P_LT_SCHEDULES_IN like t_schedules_in[]

    P_LT_SCHEDULES_INX like t_schedules_inx[]

    Pt_PARTNER like t_partner[]

    P_w_vbeln like w_vbeln.

    • This Perform is used to fill required data for Sales order creation

    perform sales_fill_data changing p_header

    p_headerx

    pt_item

    pt_itemx

    p_lt_schedules_in

    p_lt_schedules_inx

    pt_partner.

    CALL FUNCTION 'BAPI_SALESDOCU_CREATEFROMDATA1'

    EXPORTING

    sales_header_in = p_header

    sales_header_inx = p_headerx

    IMPORTING

    salesdocument_ex = p_w_vbeln

    TABLES

    return = t_return

    sales_items_in = pt_item

    sales_items_inx = pt_itemx

    sales_schedules_in = p_lt_schedules_in

    sales_schedules_inx = p_lt_schedules_inx

    sales_partners = pt_partner.

    perform commit_work.

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

    WRITE / return-message.

    EXIT.

    ENDLOOP.

    WRITE: / Text-003, p_w_vbeln.

    perform delivery_creation. " DELIVERY ORDER CREATION

    ENDFORM. " salesdocu

    ----


    • Form commit_work

    ----


    • To execute external commit *

    ----


    FORM commit_work .

    CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

    EXPORTING

    WAIT = 'X'

    .

    ENDFORM. " Commit_work

    include ycl_sales_order_header.

    plzz reward if it is useful....

    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.