Application Development and Automation 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: 
Read only

coping scheduling agreement

Former Member
0 Likes
631

Hi,

I am creating scheduling agreement from scheduling agreement using BAPI_SALESORDER_CREATEFROMDAT2. What are the fields to be passed? I am passing schedule line information, but it is not getting copied.

Useful answers will be rewarded.

Regards,

Tanmay

Hi,

I am creating scheduling agreement from scheduling agreement using BAPI_SALESORDER_CREATEFROMDAT2. What are the fields to be passed? I am passing schedule line information, but it is not getting copied.

Useful answers will be rewarded.

Regards,

Tanmay

2 REPLIES 2
Read only

Former Member
0 Likes
562

You need to pass values to BAPISCHDL

See the example program :

data: ifile1(200) occurs 0 with header line,

userial_number(10),

uauart like vbak-auart value 'TA',

uvtweg like vbak-vtweg value '01',

uspart like vbak-spart value '01',

umatnr like vbap-matnr,

p_vbeln like bapivbeln-vbeln,

s_return like bapiret2 occurs 0 with header line,

izvariantmap like zvariantmap occurs 0 with header line,

variant_ind,

uindex type i.

  • BAPI structure declarations

data: s_header like bapisdhd1,

s_item_in like bapisditm occurs 0 with header line,

s_partner like bapiparnr occurs 0 with header line,

s_schedule_in like bapischdl occurs 0 with header line.

data: begin of ifile2 occurs 0,

serial_number(10), "User name

auart like vbak-auart, "Order type

vkorg like vbak-vkorg, "Sales org

vtweg like vbak-vtweg, "Distribution Ch.

spart like vbak-spart, "Division

kunnr like kna1-kunnr, "Customer

vdatu like sy-datum, "Requested delivery date

lifsk like vbak-lifsk, "Delivery Block

faksk like vbak-faksk, "Billing block

kvgr1 like vbak-kvgr1, "Delivery Model

kvgr2 like vbak-kvgr2, "Delivery Zone

delco like vbkd-delco, "Delivery Time.

matnr like vbap-matnr, "Material number

werks like vbap-werks, "Plant

menge(15), "Quantity

uom like bapiitemin-sales_unit, "Sales UOM

variant_config, "Variant Config Indicator

steak_ind,

char_code(2), "Characteristic Name

char_value(40). "Characteristic Value

data: end of ifile2.

data: ifile3 like ifile2,

S_BAPICUVAL LIKE BAPICUVAL OCCURS 0 WITH HEADER LINE,

S_BAPICUCFG LIKE BAPICUCFG OCCURS 0 WITH HEADER LINE,

S_BAPICUINS LIKE BAPICUINS OCCURS 0 WITH HEADER LINE.

parameters: p_file(128).

select * from zvariantmap into table izvariantmap.

CALL FUNCTION 'UPLOAD'

EXPORTING

FILENAME = p_file

FILETYPE = 'DAT'

TABLES

DATA_TAB = ifile2

EXCEPTIONS

CONVERSION_ERROR = 1

INVALID_TABLE_WIDTH = 2

INVALID_TYPE = 3

NO_BATCH = 4

UNKNOWN_ERROR = 5

GUI_REFUSE_FILETRANSFER = 6

OTHERS = 7.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

loop at ifile2.

uindex = sy-tabix.

if ifile2-serial_number is initial.

ifile2-serial_number = userial_number.

else.

userial_number = ifile2-serial_number.

endif.

if ifile2-auart is initial.

ifile2-auart = uauart.

endif.

if ifile2-vkorg is initial.

ifile2-vkorg = '0001'.

endif.

if ifile2-vtweg is initial.

ifile2-vtweg = uvtweg.

endif.

if ifile2-spart is initial.

ifile2-spart = uspart.

endif.

if ifile2-werks is initial.

ifile2-werks = '1000'.

endif.

modify ifile2 index uindex.

endloop.

loop at ifile2.

ifile3 = ifile2.

at new serial_number.

refresh: s_item_in,

s_partner,

s_schedule_in.

clear: s_item_in,

s_partner,

s_schedule_in.

sy-subrc = 0.

s_header-purch_no_c = ifile3-serial_number.

s_header-doc_type = ifile3-auart.

if s_header-doc_type = 'OR'.

s_header-doc_type = 'TA'.

endif.

if not ( ifile3-vkorg is initial ).

unpack ifile3-vkorg to ifile3-vkorg.

endif.

if not ( ifile3-vtweg is initial ).

unpack ifile3-vtweg to ifile3-vtweg.

endif.

if not ( ifile3-spart is initial ).

unpack ifile3-spart to ifile3-spart.

endif.

s_header-sales_org = ifile3-vkorg.

s_header-distr_chan = ifile3-vtweg.

s_header-division = ifile3-spart.

if not ( ifile3-lifsk is initial ).

s_header-dlv_block = ifile3-lifsk.

unpack s_header-dlv_block to s_header-dlv_block.

endif.

if not ( ifile3-faksk is initial ).

s_header-bill_block = ifile3-faksk.

unpack s_header-bill_block to s_header-bill_block.

endif.

if not ( ifile3-kvgr1 is initial ).

s_header-cust_grp1 = ifile3-kvgr1.

unpack s_header-cust_grp1 to s_header-cust_grp1.

else.

s_header-cust_grp1 = '003'.

endif.

if not ( ifile3-kvgr2 is initial ).

s_header-cust_grp2 = ifile3-kvgr2.

unpack s_header-cust_grp2 to s_header-cust_grp2.

endif.

if not ( ifile3-delco is initial ).

s_header-dlv_time = ifile3-delco.

unpack s_header-dlv_time to s_header-dlv_time.

endif.

s_header-req_date_h = ifile3-vdatu.

s_partner-partn_role = 'AG'.

s_partner-partn_numb = ifile3-kunnr.

unpack s_partner-partn_numb to s_partner-partn_numb.

append s_partner.

refresh: s_bapicucfg,

s_bapicuins,

s_bapicuval.

clear: s_bapicucfg,

s_bapicuins,

s_bapicuval,

variant_ind.

endat.

  • Build sales order detail

if not ( ifile2-matnr is initial ).

s_item_in-material = ifile2-matnr.

s_item_in-itm_number = s_item_in-itm_number + 10.

unpack s_item_in-material to s_item_in-material.

if not ( ifile2-uom is initial ).

s_item_in-sales_unit = ifile2-uom.

else.

clear s_item_in-sales_unit.

endif.

translate s_item_in-sales_unit to upper case.

s_item_in-po_itm_no = s_item_in-po_itm_no + 10.

unpack s_item_in-po_itm_no to s_item_in-po_itm_no.

s_item_in-plant = ifile2-werks.

append s_item_in.

s_schedule_in-itm_number = s_item_in-itm_number.

s_schedule_in-req_qty = ifile2-menge.

s_schedule_in-req_qty = s_schedule_in-req_qty. " * 1000.

append s_schedule_in.

if ifile2-variant_config = 'X'.

s_bapicucfg-posex = s_bapicucfg-posex + 10.

s_bapicucfg-config_id = s_bapicucfg-config_id + 10.

s_bapicucfg-root_id = s_bapicucfg-root_id + 1.

unpack: s_bapicucfg-posex to s_bapicucfg-posex,

s_bapicucfg-config_id to s_bapicucfg-config_id,

s_bapicucfg-root_id to s_bapicucfg-root_id.

append s_bapicucfg.

s_bapicuins-config_id = s_bapicucfg-config_id.

s_bapicuins-inst_id = s_bapicucfg-root_id.

s_bapicuins-obj_type = 'MARA'.

s_bapicuins-obj_key = s_item_in-material.

s_bapicuins-quantity = s_schedule_in-req_qty.

append s_bapicuins.

variant_ind = 'X'.

if ifile2-steak_ind = 'X'.

s_bapicuval-config_id = s_bapicucfg-config_id.

s_bapicuval-inst_id = s_bapicuins-inst_id.

read table izvariantmap with key code =

s_item_in-sales_unit+0(1).

if sy-subrc = 0.

s_bapicuval-charc = izvariantmap-name.

if s_item_in-sales_unit+2(1) <> space.

concatenate s_item_in-sales_unit+1(1) '.'

s_item_in-sales_unit+2(1) ' INCH' into

s_bapicuval-value.

else.

concatenate s_item_in-sales_unit+1(1) ' INCH' into

s_bapicuval-value.

endif.

append s_bapicuval.

endif.

read table izvariantmap with key code = 'Q'.

s_bapicuval-charc = izvariantmap-name.

s_bapicuval-value = ifile2-menge.

append s_bapicuval.

endif.

endif.

endif.

if variant_ind = 'X' and not ( ifile2-char_code is initial ).

s_bapicuval-config_id = s_bapicucfg-config_id.

s_bapicuval-inst_id = s_bapicuins-inst_id.

read table izvariantmap with key code = ifile2-char_code.

if sy-subrc = 0.

if izvariantmap-code = 'T'.

concatenate ifile2-char_value ' INCH' into ifile2-char_value.

endif.

s_bapicuval-charc = izvariantmap-name.

s_bapicuval-value = ifile2-char_value.

append s_bapicuval.

endif.

endif.

at end of serial_number.

  • Create sales order

CALL FUNCTION 'BAPI_SALESORDER_CREATEFROMDAT2'

EXPORTING

ORDER_HEADER_IN = s_header

IMPORTING

SALESDOCUMENT = p_vbeln

TABLES

RETURN = s_return

ORDER_ITEMS_IN = s_item_in

ORDER_PARTNERS = s_partner

ORDER_SCHEDULES_IN = s_schedule_in

ORDER_CFGS_REF = s_bapicucfg

ORDER_CFGS_INST = s_bapicuins

ORDER_CFGS_VALUE = s_bapicuval.

if s_return-type = 'E'.

write:/ 'Order not created for serial number',

30 ifile2-serial_number,

45 s_return-message.

else.

write:/ 'Order created for serial number', 30 ifile2-serial_number

, 'is ', p_vbeln.

endif.

call function 'BAPI_TRANSACTION_COMMIT'.

endat.

endloop.

Read only

Former Member
0 Likes
562

Hi,

look at the Function module IDOC_INPUT_SALESORDER_CREATEFR, In this one the fucntion module BAPI_SALESORDER_CREATEFROMDAT2 has been called, look at the FM to know the fields which are mandatory

http://abap.wikiprog.com/w/index.php?title=BAPI_SALESORDER_CREATEFROMDAT2&printable=yes

Regards

Sudheer