Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Bapi Sales Order Create

Former Member
0 Kudos

Hello,

I am using BAPI_SALESORDER_CREATEFROMDAT2 to create sales order. The system is configured to automatically generate the item numbers. I can create an order alright for simple materials.

For this I am populating both Line items and Schedule Line item structures - ORDER_ITEMS_IN and ORDER_SCHEDULES_IN respectively, without passing the line item number(ITM_NUMBER field).

The problem is when I create an order which has a KIT as a line item.

So SAP explodes the Kit correctly, but the quantity information goes all wrong for the subsequent lines after the kit. Hence order does not get correctly created.

Any hints on how to solev this? I want to create the order with Kit and simple materials and without provising the line item numbers.

1 REPLY 1

Former Member
0 Kudos

hello,

Please check the following code in case its a bill of material

FORM CHECK_SALES_BOM TABLES ORDER_ITEMS_IN STRUCTURE BAPIITEMIN

ORDER_PARTNERS STRUCTURE ZBAPISHIP1.

CLEAR FLAG_CANCEL_CREATE.

CLEAR V_LINES1.

LOOP AT ORDER_ITEMS_IN.

V_ITM_NUMBER = ORDER_ITEMS_IN-ITM_NUMBER.

  • ORDER_ITEMS_IN-PO_ITM_NO = ORDER_ITEMS_IN-ITM_NUMBER. " DEVK942749

ORDER_ITEMS_IN-ITM_NUMBER = 10 * SY-TABIX + 10 * V_LINES1.

MODIFY ORDER_ITEMS_IN.

LOOP AT ORDER_PARTNERS WHERE ITEM_NUMB = V_ITM_NUMBER.

ORDER_PARTNERS-ITEM_NUMB = ORDER_ITEMS_IN-ITM_NUMBER.

MODIFY ORDER_PARTNERS.

ENDLOOP.

SELECT SINGLE KNUMH FROM KOTD001 INTO KOTD001-KNUMH

WHERE KAPPL = 'V'

AND KSCHL = 'A001'

AND MATWA = ORDER_ITEMS_IN-MATERIAL

AND DATBI GE SY-DATUM

AND DATAB LE SY-DATUM.

IF SY-SUBRC = 0.

SELECT SINGLE SMATN FROM KONDD INTO KONDD-SMATN

WHERE KNUMH = KOTD001-KNUMH.

ORDER_ITEMS_IN-MATERIAL = KONDD-SMATN.

ELSE.

ORDER_ITEMS_IN-MATERIAL = ORDER_ITEMS_IN-MATERIAL.

ENDIF.

CLEAR V_WERKS.

SELECT SINGLE DWERK MTPOS INTO (V_WERKS, MVKE-MTPOS) FROM MVKE

WHERE MATNR = ORDER_ITEMS_IN-MATERIAL

AND VKORG = WWW_ORDER_HEADER_EXP-VKORG

AND VTWEG = WWW_ORDER_HEADER_EXP-VTWEG.

IF MVKE-MTPOS EQ 'LUMF' OR MVKE-MTPOS EQ 'ZLUM'.

READ TABLE ORDER_PARTNERS WITH KEY ITEM_NUMB = V_ITM_NUMBER

PARTN_ROLE = 'WE'.

REFRESH : DA_MASTB,

DA_STKOB,

DA_STZUB.

CALL FUNCTION 'CS_ALT_SELECT_MAT'

EXPORTING

  • ALL = ' '

CAPID = 'SD01'

DATUV = SY-DATUM

  • DIALF = ' '

  • LOSGR = 0

MATNR = ORDER_ITEMS_IN-MATERIAL

  • NOTAB = 'X'

  • NRFDC = ' '

  • STLAL = ' '

  • STLAN = ' '

  • VPRIO = ' '

WERKS = V_WERKS

TABLES

MASTB_WA = DA_MASTB

STKOB_WA = DA_STKOB

STZUB_WA = DA_STZUB

EXCEPTIONS

ALT_NOT_FOUND = 1

BOM_NOT_ACTIVE = 2

BOM_NOT_FOUND = 3

CALL_INVALID = 4

NO_ALT_FOUND = 5

NO_BOM_FOUND = 6

OTHERS = 7.

READ TABLE DA_MASTB INDEX 1.

IF SY-SUBRC = 0.

CALL FUNCTION 'CS_BOM_EXPL_MAT_V2'

EXPORTING

CAPID = 'SD01'

DATUV = SY-DATUM

EMENG = 1

MEHRS = 'X'

MTNRV = ORDER_ITEMS_IN-MATERIAL

RNDKZ = '2'

STLAL = '01'

WERKS = V_WERKS

IMPORTING

TOPMAT = CSTMAT

TABLES

STB = TSTB

  • MATCAT =

EXCEPTIONS

ALT_NOT_FOUND = 1

CALL_INVALID = 2

MATERIAL_NOT_FOUND = 3

MISSING_AUTHORIZATION = 4

NO_BOM_FOUND = 5

NO_PLANT_DATA = 6

NO_SUITABLE_BOM_FOUND = 7

OTHERS = 8.

DESCRIBE TABLE TSTB LINES V_LINES.

ENDIF.

V_LINES1 = V_LINES + V_LINES1 .

CLEAR V_LINES.

ENDIF.

ENDLOOP.

hope this will help you.

Reward points if it helps

regards,

krishna