Skip to Content
0
Former Member
Mar 29, 2012 at 06:04 AM

Not able to set materials while creating a sales order through BAPI CRM_ORDER_MAINTAIN

30 Views

Hi All,

My scenario is to create a sales order . Im passing the necessary data like material code , qty and header level data.

The issue is the transaction is being generated with out the item level details.

Foll is my code snippet .

WA_SCHEDLINES-QUANTITY = WA_CC_INPUT-QTY1 .

WA_SCHEDLINES-MODE = 'A'.

APPEND WA_SCHEDLINES TO IT_SCHEDLINES.

CLEAR WA_SCHEDLINES.





* WA_SCHEDLIN_I-REF_GUID = CRMD_ORDERADM_I-GUID.

WA_SCHEDLIN_I-REF_HANDLE = '0000000001'.

WA_SCHEDLIN_I-MODE = 'A'.

WA_SCHEDLIN_I-SCHEDLINES = IT_SCHEDLINES[] .

INSERT WA_SCHEDLIN_I INTO TABLE IT_SCHEDLIN_I.

CLEAR WA_SCHEDLIN_I .



IF WA_CC_INPUT-QTY2 NE '' .

REFRESH :IT_SCHEDLINES[].

WA_SCHEDLINES-QUANTITY = WA_CC_INPUT-QTY2 .

WA_SCHEDLINES-MODE = 'A'.

APPEND WA_SCHEDLINES TO IT_SCHEDLINES.

CLEAR WA_SCHEDLINES.





* WA_SCHEDLIN_I-REF_GUID = CRMD_ORDERADM_I-GUID.

WA_SCHEDLIN_I-REF_HANDLE = '0000000002'.

WA_SCHEDLIN_I-MODE = 'A'.

WA_SCHEDLIN_I-SCHEDLINES = IT_SCHEDLINES[] .

INSERT WA_SCHEDLIN_I INTO TABLE IT_SCHEDLIN_I.

CLEAR WA_SCHEDLIN_I .

ENDIF.







WA_CT_ORDERADM_I-HANDLE = '0000000001'.

WA_CT_ORDERADM_I-HEADER = WA_DOC_FLOW-OBJKEY_B.

* WA_CT_ORDERADM_I-GUID = CRMD_ORDERADM_I-GUID.

* WA_CT_ORDERADM_I-PRODUCT = CRMD_ORDERADM_I-PRODUCT.

WA_CT_ORDERADM_I-ORDERED_PROD =

WA_CC_INPUT-MAT1.

* WA_CT_ORDERADM_I-DESCRIPTION = CRMD_ORDERADM_I-DESCRIPTION.

* WA_CT_ORDERADM_I-ITM_TYPE = 'ZCMP'.

WA_CT_ORDERADM_I-MODE = 'A'.

INSERT WA_CT_ORDERADM_I INTO TABLE IT_CT_ORDERADM_I.

CLEAR WA_CT_ORDERADM_I .



IF WA_CC_INPUT-MAT2 NE ''.

WA_CT_ORDERADM_I-HANDLE = '0000000002'.

WA_CT_ORDERADM_I-HEADER = WA_DOC_FLOW-OBJKEY_B.

* WA_CT_ORDERADM_I-GUID = CRMD_ORDERADM_I-GUID.

* WA_CT_ORDERADM_I-PRODUCT = CRMD_ORDERADM_I-PRODUCT.

WA_CT_ORDERADM_I-ORDERED_PROD =

WA_CC_INPUT-MAT2.

* WA_CT_ORDERADM_I-DESCRIPTION = CRMD_ORDERADM_I-DESCRIPTION.

* WA_CT_ORDERADM_I-ITM_TYPE = 'ZCMP'.

WA_CT_ORDERADM_I-MODE = 'A'.

INSERT WA_CT_ORDERADM_I INTO TABLE IT_CT_ORDERADM_I.

CLEAR WA_CT_ORDERADM_I .

ENDIF.



REFRESH: IT_FIELD_NAMES[].

WA_FIELD_NAMES-FIELDNAME = 'MODE'.

APPEND WA_FIELD_NAMES TO IT_FIELD_NAMES.

WA_FIELD_NAMES-FIELDNAME = 'ORDERED_PROD'.

APPEND WA_FIELD_NAMES TO IT_FIELD_NAMES.

CLEAR: WA_FIELD_NAMES .



WA_CT_INPUT_FIELDS-REF_HANDLE = '0000000001'.

* WA_CT_INPUT_FIELDS-REF_GUID = CRMD_ORDERADM_I-GUID.

* WA_CT_INPUT_FIELDS-REF_KIND = 'A'.

WA_CT_INPUT_FIELDS-OBJECTNAME = 'ORDERADM_I'.

WA_CT_INPUT_FIELDS-FIELD_NAMES = IT_FIELD_NAMES.

INSERT WA_CT_INPUT_FIELDS INTO TABLE IT_CT_INPUT_FIELDS.

CLEAR:WA_CT_INPUT_FIELDS .



IF WA_CC_INPUT-QTY2 NE ''.

REFRESH: IT_FIELD_NAMES[].

WA_FIELD_NAMES-FIELDNAME = 'MODE'.

APPEND WA_FIELD_NAMES TO IT_FIELD_NAMES.

WA_FIELD_NAMES-FIELDNAME = 'ORDERED_PROD'.

APPEND WA_FIELD_NAMES TO IT_FIELD_NAMES.

CLEAR: WA_FIELD_NAMES .



WA_CT_INPUT_FIELDS-REF_HANDLE = '0000000002'.

* WA_CT_INPUT_FIELDS-REF_GUID = CRMD_ORDERADM_I-GUID.

* WA_CT_INPUT_FIELDS-REF_KIND = 'B'.

WA_CT_INPUT_FIELDS-OBJECTNAME = 'ORDERADM_I'.

WA_CT_INPUT_FIELDS-FIELD_NAMES = IT_FIELD_NAMES.

INSERT WA_CT_INPUT_FIELDS INTO TABLE IT_CT_INPUT_FIELDS.

CLEAR:WA_CT_INPUT_FIELDS .



ENDIF.



REFRESH: IT_FIELD_NAMES[].

WA_FIELD_NAMES-FIELDNAME = 'LOGICAL_KEY'.

APPEND WA_FIELD_NAMES TO IT_FIELD_NAMES.

WA_FIELD_NAMES-FIELDNAME = 'QUANTITY'.

APPEND WA_FIELD_NAMES TO IT_FIELD_NAMES.

CLEAR: WA_FIELD_NAMES .





WA_CT_INPUT_FIELDS-REF_HANDLE = '0000000001'.

* WA_CT_INPUT_FIELDS-REF_GUID = CRMD_ORDERADM_I-GUID.

WA_CT_INPUT_FIELDS-REF_KIND = 'B'.

WA_CT_INPUT_FIELDS-OBJECTNAME = 'SCHEDLIN'.

WA_CT_INPUT_FIELDS-LOGICAL_KEY = '00000000000000000000000000000000'.

WA_CT_INPUT_FIELDS-FIELD_NAMES = IT_FIELD_NAMES.

INSERT WA_CT_INPUT_FIELDS INTO TABLE IT_CT_INPUT_FIELDS.

CLEAR:WA_CT_INPUT_FIELDS .



IF WA_CC_INPUT-QTY2 NE ''.

REFRESH: IT_FIELD_NAMES[].

WA_FIELD_NAMES-FIELDNAME = 'LOGICAL_KEY'.

APPEND WA_FIELD_NAMES TO IT_FIELD_NAMES.

WA_FIELD_NAMES-FIELDNAME = 'QUANTITY'.

APPEND WA_FIELD_NAMES TO IT_FIELD_NAMES.

CLEAR: WA_FIELD_NAMES .





WA_CT_INPUT_FIELDS-REF_HANDLE = '0000000002'.

* WA_CT_INPUT_FIELDS-REF_GUID = CRMD_ORDERADM_I-GUID.

WA_CT_INPUT_FIELDS-REF_KIND = 'B'.

WA_CT_INPUT_FIELDS-OBJECTNAME = 'SCHEDLIN'.

WA_CT_INPUT_FIELDS-LOGICAL_KEY = '00000000000000000000000000000000'.

WA_CT_INPUT_FIELDS-FIELD_NAMES = IT_FIELD_NAMES.

INSERT WA_CT_INPUT_FIELDS INTO TABLE IT_CT_INPUT_FIELDS.

CLEAR:WA_CT_INPUT_FIELDS .



ENDIF.



WA_CT_INPUT_FIELDS-REF_HANDLE = '0000000001'.

* WA_CT_INPUT_FIELDS-REF_GUID = CRMD_ORDERADM_I-GUID.

WA_CT_INPUT_FIELDS-REF_KIND = 'B'.

WA_CT_INPUT_FIELDS-OBJECTNAME = 'SCHEDLIN_I'.

* WA_CT_INPUT_FIELDS-LOGICAL_KEY = '00000000000000000000000000000000'.

* WA_CT_INPUT_FIELDS-FIELD_NAMES = IT_FIELD_NAMES.

INSERT WA_CT_INPUT_FIELDS INTO TABLE IT_CT_INPUT_FIELDS.

CLEAR:WA_CT_INPUT_FIELDS .



IF WA_CC_INPUT-QTY2 NE ''.

WA_CT_INPUT_FIELDS-REF_HANDLE = '0000000002'.

* WA_CT_INPUT_FIELDS-REF_GUID = CRMD_ORDERADM_I-GUID.

WA_CT_INPUT_FIELDS-REF_KIND = 'B'.

WA_CT_INPUT_FIELDS-OBJECTNAME = 'SCHEDLIN_I'.

* WA_CT_INPUT_FIELDS-LOGICAL_KEY = '00000000000000000000000000000000'.

* WA_CT_INPUT_FIELDS-FIELD_NAMES = IT_FIELD_NAMES.

INSERT WA_CT_INPUT_FIELDS INTO TABLE IT_CT_INPUT_FIELDS.

CLEAR:WA_CT_INPUT_FIELDS .

ENDIF.



WA_PRICING-REF_HANDLE = '0000000001'.

WA_PRICING-REF_KIND = 'B'.

APPEND WA_PRICING TO IT_PRICING.

CLEAR WA_PRICING.



IF WA_CC_INPUT-QTY2 NE ''.

WA_PRICING-REF_HANDLE = '0000000002'.

WA_PRICING-REF_KIND = 'B'.

APPEND WA_PRICING TO IT_PRICING.

CLEAR WA_PRICING.

ENDIF.



CALL FUNCTION 'CRM_ORDER_MAINTAIN'

EXPORTING

* IT_STATUS = IT_STATUS_ORDER

* IT_SALES = IT_SALES

* IT_PRIDOC = IT_PRIDOC

IT_PRICING = IT_PRICING

IT_SCHEDLIN_I = IT_SCHEDLIN_I

* IT_TEXT = IT_REMARKS

CHANGING

* CT_ORDERADM_H = IT_CT_ORDERADM_H

CT_ORDERADM_I = IT_CT_ORDERADM_I

CT_INPUT_FIELDS = IT_CT_INPUT_FIELDS

EXCEPTIONS

ERROR_OCCURRED = 1

DOCUMENT_LOCKED = 2

NO_CHANGE_ALLOWED = 3

NO_AUTHORITY = 4

OTHERS = 5.

Can you point out what im missing .

Your help would be truly appreciated and rewarded.

Regds,

Navin Chettiar