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: 

Need BDC program for ME21n

Former Member
0 Kudos

Hi All-

I was using BAPI(BAPI_PO_CREATE1) to create PO's for me21n...But if I have 10 records in my file, it is skiping few records from the internal table and it is creating for the rest of the records...If I take seperate file for the skipping records, it is creating again using the same BAPI...

Do we need to apply any OSS note for this problem....

So, instead of using BAPI, decided to use BDC for ME21n using Call transaction...If you have BDC program,can you please forward to me...

I will assgin points if anyone can help me out!!!!

Thanks,

Sony...

14 REPLIES 14

Former Member
0 Kudos

Hi,

You can't use BDC to work through ME21n as it is an enjoy transaction and hence the custom controls it uses won't work with BDC.

You'd be better figuring out why the BAPI is failing - have you debugged through to see why certain items are missing? Or does it pass back any messages in the return table.

Gareth.

0 Kudos

Gareth-

Thanks for your reply...If file have million of records, it is skipping few records and creating STO's(special type of PO) for rest of the records...In Return table returns that Item 0040 does not exist, but if it is exist in the file also.

But If I take skipped records into the file and process again, it is creating STO's....

I was really confuse on this....In my company they don't want to use ME21 but they want to use only ME21N..I need to update Header, Item and Schedule items...Will it be not possible using BDC also?

Please help me out....

Thanks,

Sony

0 Kudos

Hi,

Are you using the BAPI to create 1 PO at a time with multiple items? Your file must have 1 header with multiple items for each PO you are creating - this would be one BAPI call with a following commit work and wait statement (or BAPI_TRANSACTION_COMMIT as you are using.)

Is it skipping header rows from your file or random items on a PO document?

Gareth.

0 Kudos

Gareth-

I am taking first header record, Item records and Schedule details....and so on...

It is skipping header level data only and it is returning message that...

No Instance of object type Purchaseorder has been created. External refer

Document Contains no items

Item 00010 does not exist...But it is exist in the file...

Thanks,

Sony

0 Kudos

Ok, are yuo trying to create PO's referring to other documents already on the system? The message sounds like you are...

Try to call the function module in SE37 single test using the PO header, item and schedule data from your file and see if it works.

For what it is worth, I don't think the problem is with the looping or wait statements or anything, it is more likely to be with the data you are passing in. Other than performing a commit work and wait after each PO creation you shouldn't need to do any extra wait statements or ENQUE_SLEEP or anything like that...

Gareth.

0 Kudos

Hi Sony,

When the system returns an error "Item 00010 does not exist", it means that it is not there in the SYSTEM(For the referance PO Number). It is not telling that its not there in the file.

Can you show your code?

REgards,

Ravi

0 Kudos

If I take same data into the file and it is creating....I don't think it is problem with the data..Becasue we are going upgrade from 3.1 to ECC....We are extrating PO's from 3.1 and creating STO's in ECC 5.0....

Thanks,

Sony

0 Kudos

Sure...

FORM create_sto .

REFRESH: i_errpo, i_error.

CLEAR: w_header, i_errpo, i_error, v_success, v_error.

LOOP AT i_header_sa INTO w_header.

CLEAR: w_errpo, w_poheaderx, w_exppurchaseorder, w_expheader,

w_return, w_poitem, w_poitemx, w_poschedule, w_poschedulex,

i_return, w_poitem, w_poitemx, i_poschedule, i_poschedulex.

REFRESH: i_return, i_poitem, i_poitemx, i_poschedule, i_poschedulex.

*--Fill Header

w_poheader-po_number = w_header-ebeln.

w_poheader-doc_type = 'ZU'.

*--The supplying plant is mapped based on the recieving plant in from the ZCA_CONV_UTILITY.

  • The conversion is based on the new values of the recieving plant and storage location

v_value_old = w_header-bukrs.

PERFORM convert TABLES i_values

USING 'BUKRS'

v_value_old

CHANGING v_value_new.

w_poheader-comp_code = v_value_new(4).

w_poheader-pur_group = w_header-ekgrp.

CLEAR: v_value_old, v_value_new.

v_value_old = w_header-ekorg.

PERFORM convert TABLES i_values

USING 'EKORG'

v_value_old

CHANGING v_value_new.

WRITE w_header-aedat+4(2) TO v_po_date(2).

WRITE w_header-aedat6(2) TO v_po_date2(2).

WRITE w_header-aedat(4) TO v_po_date+4(4).

w_poheader-purch_org = v_value_new(4).

w_poheader-vendor = w_header-lifnr.

w_poheader-creat_date = v_po_date.

w_poheader-item_intvl = w_header-pincr.

w_poheader-langu = w_header-spras.

w_poheader-subitemint = w_header-upinc.

w_poheader-vper_start = w_header-kdatb.

w_poheader-vper_end = w_header-kdate.

w_poheader-warranty = w_header-gwldt.

w_poheader-ref_1 = w_header-ihrez.

w_poheader-sales_pers = w_header-verkf.

w_poheader-our_ref = w_header-unsez.

w_poheader-telephone = w_header-telf1.

w_poheaderx-po_number = 'X'.

w_poheaderx-doc_type = 'X'.

w_poheaderx-suppl_plnt = 'X'.

w_poheaderx-comp_code = 'X'.

w_poheaderx-pur_group = 'X'.

w_poheaderx-purch_org = 'X'.

w_poheaderx-vendor = 'X'.

w_poheaderx-creat_date = 'X'.

w_poheaderx-item_intvl = 'X'.

w_poheaderx-langu = 'X'.

w_poheaderx-subitemint = 'X'.

w_poheaderx-vper_start = 'X'.

w_poheaderx-vper_end = 'X'.

w_poheaderx-warranty = 'X'.

w_poheaderx-ref_1 = 'X'.

w_poheaderx-sales_pers = 'X'.

w_poheaderx-our_ref = 'X'.

w_poheaderx-telephone = 'X'.

CLEAR: w_item, v_poitem.

LOOP AT i_item INTO w_item WHERE ebeln EQ w_header-ebeln.

CLEAR: w_zmm_cordlog,

v_split,

w_matnr.

READ TABLE i_zmm_cordlog INTO w_zmm_cordlog WITH KEY ponumber = w_item-ebeln

poitem = w_item-ebelp.

IF sy-subrc EQ 0.

*--If file is processed earlier, rollback work.

IF NOT w_zmm_cordlog-mdoc561 IS INITIAL. "STO has to be processed for 561 Goods Mvmt

w_errortab-ponumber = w_item-ebeln.

w_errortab-poitem = w_item-ebelp.

w_errortab-message = text-051. "Process STO for 561 Goods Mvmt.

APPEND w_errortab TO i_errortab.

ADD 1 TO v_error.

CLEAR w_errortab.

PERFORM error_pos.

CONTINUE.

ELSE.

IF NOT w_zmm_cordlog-eccpo IS INITIAL. "STO already exists

w_errortab-ponumber = w_item-ebeln.

w_errortab-poitem = w_item-ebelp.

w_errortab-eccpo = w_zmm_cordlog-eccpo.

w_errortab-eccpoitem = w_zmm_cordlog-eccpoitem.

w_errortab-message = text-052. "STO already created, record skipped

APPEND w_errortab TO i_errortab.

ADD 1 TO v_error.

CLEAR w_errortab.

PERFORM error_pos.

CONTINUE.

ENDIF.

ENDIF.

ENDIF.

CLEAR w_mard.

SELECT SINGLE * FROM mard INTO w_mard

WHERE matnr EQ w_item-matnr

AND werks EQ w_item-werks

AND lgort EQ w_item-lgort.

IF sy-subrc <> 0.

w_itmerror-ponumber = w_item-ebeln.

w_itmerror-poitem = w_item-ebelp.

CONCATENATE w_item-matnr w_item-werks w_item-lgort text-044

INTO w_itmerror-message SEPARATED BY space.

APPEND w_itmerror TO i_itmerror.

ADD 1 TO v_error.

CONTINUE.

ENDIF.

*--Plant and Storage location conversion

CLEAR: v_value_old, i_values[], v_value_new.

CONCATENATE w_item-werks w_item-lgort INTO v_value_old.

PERFORM convert TABLES i_values

USING 'WERKSLGORT'

v_value_old

CHANGING v_value_new.

w_item-werks = v_value_new+0(4).

w_item-lgort = v_value_new+4(4).

*--The converted recieving plant will be the same as the supplying plant in the new system

  • and the supplying storage location would be OW01.

w_poheader-suppl_plnt = w_item-werks.

*--Fill item

w_poitem-po_item = w_item-ebelp.

w_poitem-material = w_item-matnr.

w_poitem-plant = w_item-werks.

w_poitem-stge_loc = w_item-lgort.

w_poitem-po_unit = w_item-meins.

PERFORM get_valuation_type USING w_item-matnr

w_item-werks

w_item-lgort

CHANGING w_poitem-val_type.

IF w_item-matnr CP '*-R'.

SPLIT w_item-matnr AT '-R' INTO w_item-matnr v_split.

ELSEIF w_item-matnr CP '*-D'.

SPLIT w_item-matnr AT '-D' INTO w_item-matnr v_split.

ENDIF.

SELECT SINGLE matnr INTO w_matnr

FROM mara

WHERE matnr = w_item-matnr.

IF sy-subrc NE 0.

w_errortab-ponumber = w_item-ebeln.

w_errortab-poitem = w_item-ebelp.

CONCATENATE w_item-matnr 'Does not exist in the MARC table'

INTO w_errortab-message.

ADD 1 TO v_error.

CONTINUE.

ENDIF.

w_poitem-matl_group = w_item-matkl.

w_poitem-item_cat = w_item-pstyp.

w_poitem-acctasscat = w_item-knttp.

w_poitem-reminder1 = w_item-mahn1.

w_poitem-conf_ctrl = w_item-bstae.

w_poitem-ackn_reqd = w_item-kzabs.

w_poitem-quantity = w_item-menge.

w_poitem-reminder2 = w_item-mahn2.

w_poitem-acknowl_no = w_item-labnr.

w_poitem-reminder3 = w_item-mahn3.

w_poitem-trackingno = w_item-bednr.

w_poitem-gr_pr_time = w_item-webaz.

w_poitem-under_dlv_tol = w_item-untto.

w_poitem-qual_insp = w_item-insmk.

w_poitem-over_dlv_tol = w_item-uebto.

w_poitem-unlimited_dlv = w_item-uebtk.

w_poitem-no_more_gr = w_item-elikz.

w_poitem-shipping = w_item-evers.

w_poitem-period_ind_expiration_date = ' '.

APPEND w_poitem TO i_poitem.

w_poitemx-po_item = w_poitem-po_item.

w_poitemx-po_itemx = 'X'.

w_poitemx-material = 'X'.

w_poitemx-plant = 'X'.

w_poitemx-stge_loc = 'X'.

w_poitemx-po_unit = 'X'.

w_poitemx-val_type = 'X'.

w_poitemx-matl_group = 'X'.

w_poitemx-item_cat = 'X'.

w_poitemx-acctasscat = 'X'.

w_poitemx-reminder1 = 'X'.

w_poitemx-conf_ctrl = 'X'.

w_poitemx-ackn_reqd = 'X'.

w_poitemx-quantity = 'X'.

w_poitemx-reminder2 = 'X'.

w_poitemx-acknowl_no = 'X'.

w_poitemx-reminder3 = 'X'.

w_poitemx-trackingno = 'X'.

w_poitemx-gr_pr_time = 'X'.

w_poitemx-under_dlv_tol = 'X'.

w_poitemx-qual_insp = 'X'.

w_poitemx-over_dlv_tol = 'X'.

w_poitemx-unlimited_dlv = 'X'.

w_poitemx-no_more_gr = 'X'.

w_poitemx-shipping = 'X'.

w_poitemx-period_ind_expiration_date = 'X'.

APPEND w_poitemx TO i_poitemx.

CLEAR w_poitemx.

CLEAR: w_slines, v_scheditem.

LOOP AT i_slines INTO w_slines WHERE ebeln EQ w_item-ebeln

AND ebelp EQ w_item-ebelp.

*--Fill Schedule lines for PO

w_poschedule-po_item = w_item-ebelp.

w_poschedule-sched_line = w_slines-etenr.

w_poschedule-del_datcat_ext = ' '.

w_poschedule-delivery_date = w_slines-eindt.

w_poschedule-quantity = w_slines-menge.

APPEND w_poschedule TO i_poschedule.

CLEAR w_poschedule.

w_poschedulex-po_item = w_item-ebelp.

w_poschedulex-sched_line = w_slines-etenr.

w_poschedulex-po_itemx = 'X'.

w_poschedulex-sched_linex = 'X'.

w_poschedulex-del_datcat_ext = 'X'.

w_poschedulex-delivery_date = 'X'.

w_poschedulex-quantity = 'X'.

APPEND w_poschedulex TO i_poschedulex.

CLEAR w_poschedulex.

CLEAR w_slines.

ENDLOOP.

CLEAR: w_poitem,

w_item.

ENDLOOP.

SORT: i_poitem, i_poitemx, i_poschedule, i_poschedulex.

*--If the import data to BAPI is empty, then raise a message to check the Material Error file for

  • any PO items which are skipped.

  • The PO in error is also moved to the error file for reprocessing.

IF w_poheader IS INITIAL OR

i_poitem[] IS INITIAL.

CLEAR: w_poheader, w_poheaderx, i_return[], i_poitem, i_poitem[].

CONTINUE.

ENDIF.

*--BAPI call for PO creation

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = w_poheader

poheaderx = w_poheaderx

testrun = p_test

IMPORTING

exppurchaseorder = w_exppurchaseorder

expheader = w_expheader

TABLES

return = i_return

poitem = i_poitem

poitemx = i_poitemx

poschedule = i_poschedule

poschedulex = i_poschedulex.

*--Commit the transaction if a success message is returned, else rollback work.

  • Update the legacy PO and items in the ZMM_CORDLOG table

IF NOT i_return[] IS INITIAL.

LOOP AT i_return INTO w_return.

*--Read the error messages

IF w_return-type = 'E'.

w_errortab-ponumber = w_header-ebeln.

w_errortab-doctype = w_poheader-doc_type.

w_errortab-supplplnt = w_poheader-suppl_plnt.

w_errortab-vendor = w_poheader-vendor.

w_errortab-eccpo = w_expheader-po_number.

w_errortab-message = w_return-message(73).

APPEND w_errortab TO i_errortab.

ADD 1 TO v_error.

ROLLBACK WORK.

ELSEIF w_return-type = 'S'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

EXCEPTIONS

OTHERS = 1.

IF sy-subrc EQ 0.

v_success = v_success + 1.

CLEAR w_poitem.

LOOP AT i_poitem INTO w_poitem.

w_zmm_cordlog-ponumber = w_poheader-po_number.

w_zmm_cordlog-poitem = w_poitem-po_item.

w_zmm_cordlog-doctype = w_poheader-doc_type.

w_zmm_cordlog-supplplnt = w_poheader-suppl_plnt.

w_zmm_cordlog-vendor = w_poheader-vendor.

w_zmm_cordlog-eccpo = w_poheader-po_number.

w_zmm_cordlog-eccpoitem = w_poitem-po_item.

w_zmm_cordlog-message = w_return-message(73).

MODIFY zmm_cordlog FROM w_zmm_cordlog. "Modify DB table

CLEAR w_zmm_cordlog.

w_errpo-ebeln = w_poheader-po_number.

w_errpo-ebelp = w_poitem-po_item.

APPEND w_errpo TO i_errpo.

CLEAR w_errpo.

ENDLOOP.

ENDIF.

ENDIF.

ENDLOOP.

CALL FUNCTION 'DEQUEUE_ALL'.

ENDIF.

CLEAR: w_header,

w_poheader,

w_poheaderx.

CALL FUNCTION 'DEQUEUE_ALL'.

ENDLOOP.

IF NOT i_errpo[] IS INITIAL.

*--Separate error records (all records for any PO in error).

PERFORM create_error_file TABLES i_header_sa.

*--Write data to Application Server

IF NOT i_error[] IS INITIAL.

OPEN DATASET p_error FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

MESSAGE e398 WITH text-023 space space space.

ENDIF.

LOOP AT i_error INTO w_error.

TRANSFER w_error TO p_error.

ENDLOOP.

ENDIF.

ENDIF.

COMMIT WORK.

ENDFORM. " create_sto

0 Kudos

plz look for added modification the code.

FORM create_sto .

REFRESH: i_errpo, i_error.

CLEAR: w_header, i_errpo, i_error, v_success, v_error.

LOOP AT i_header_sa INTO w_header.

CLEAR: w_errpo, w_poheaderx, w_exppurchaseorder, w_expheader,

w_return, w_poitem, w_poitemx, w_poschedule, w_poschedulex,

i_return, w_poitem, w_poitemx, i_poschedule, i_poschedulex.

REFRESH: i_return, i_poitem, i_poitemx, i_poschedule, i_poschedulex.

*--Fill Header

w_poheader-po_number = w_header-ebeln.

w_poheader-doc_type = 'ZU'.

*--The supplying plant is mapped based on the recieving plant in from the ZCA_CONV_UTILITY.

  • The conversion is based on the new values of the recieving plant and storage location

v_value_old = w_header-bukrs.

PERFORM convert TABLES i_values

USING 'BUKRS'

v_value_old

CHANGING v_value_new.

w_poheader-comp_code = v_value_new(4).

w_poheader-pur_group = w_header-ekgrp.

CLEAR: v_value_old, v_value_new.

v_value_old = w_header-ekorg.

PERFORM convert TABLES i_values

USING 'EKORG'

v_value_old

CHANGING v_value_new.

WRITE w_header-aedat+4(2) TO v_po_date(2).

WRITE w_header-aedat6(2) TO v_po_date2(2).

WRITE w_header-aedat(4) TO v_po_date+4(4).

w_poheader-purch_org = v_value_new(4).

w_poheader-vendor = w_header-lifnr.

w_poheader-creat_date = v_po_date.

w_poheader-item_intvl = w_header-pincr.

w_poheader-langu = w_header-spras.

w_poheader-subitemint = w_header-upinc.

w_poheader-vper_start = w_header-kdatb.

w_poheader-vper_end = w_header-kdate.

w_poheader-warranty = w_header-gwldt.

w_poheader-ref_1 = w_header-ihrez.

w_poheader-sales_pers = w_header-verkf.

w_poheader-our_ref = w_header-unsez.

w_poheader-telephone = w_header-telf1.

w_poheaderx-po_number = 'X'.

w_poheaderx-doc_type = 'X'.

w_poheaderx-suppl_plnt = 'X'.

w_poheaderx-comp_code = 'X'.

w_poheaderx-pur_group = 'X'.

w_poheaderx-purch_org = 'X'.

w_poheaderx-vendor = 'X'.

w_poheaderx-creat_date = 'X'.

w_poheaderx-item_intvl = 'X'.

w_poheaderx-langu = 'X'.

w_poheaderx-subitemint = 'X'.

w_poheaderx-vper_start = 'X'.

w_poheaderx-vper_end = 'X'.

w_poheaderx-warranty = 'X'.

w_poheaderx-ref_1 = 'X'.

w_poheaderx-sales_pers = 'X'.

w_poheaderx-our_ref = 'X'.

w_poheaderx-telephone = 'X'.

CLEAR: w_item, v_poitem.

LOOP AT i_item INTO w_item WHERE ebeln EQ w_header-ebeln.

CLEAR: w_zmm_cordlog,

v_split,

w_matnr.

READ TABLE i_zmm_cordlog INTO w_zmm_cordlog WITH KEY ponumber = w_item-ebeln

poitem = w_item-ebelp.

IF sy-subrc EQ 0.

*--If file is processed earlier, rollback work.

IF NOT w_zmm_cordlog-mdoc561 IS INITIAL. "STO has to be processed for 561 Goods Mvmt

w_errortab-ponumber = w_item-ebeln.

w_errortab-poitem = w_item-ebelp.

w_errortab-message = text-051. "Process STO for 561 Goods Mvmt.

APPEND w_errortab TO i_errortab.

ADD 1 TO v_error.

CLEAR w_errortab.

PERFORM error_pos.

CONTINUE.

ELSE.

IF NOT w_zmm_cordlog-eccpo IS INITIAL. "STO already exists

w_errortab-ponumber = w_item-ebeln.

w_errortab-poitem = w_item-ebelp.

w_errortab-eccpo = w_zmm_cordlog-eccpo.

w_errortab-eccpoitem = w_zmm_cordlog-eccpoitem.

w_errortab-message = text-052. "STO already created, record skipped

APPEND w_errortab TO i_errortab.

ADD 1 TO v_error.

CLEAR w_errortab.

PERFORM error_pos.

CONTINUE.

ENDIF.

ENDIF.

ENDIF.

CLEAR w_mard.

SELECT SINGLE * FROM mard INTO w_mard

WHERE matnr EQ w_item-matnr

AND werks EQ w_item-werks

AND lgort EQ w_item-lgort.

IF sy-subrc <> 0.

w_itmerror-ponumber = w_item-ebeln.

w_itmerror-poitem = w_item-ebelp.

CONCATENATE w_item-matnr w_item-werks w_item-lgort text-044

INTO w_itmerror-message SEPARATED BY space.

APPEND w_itmerror TO i_itmerror.

ADD 1 TO v_error.

CONTINUE.

ENDIF.

*--Plant and Storage location conversion

CLEAR: v_value_old, i_values[], v_value_new.

CONCATENATE w_item-werks w_item-lgort INTO v_value_old.

PERFORM convert TABLES i_values

USING 'WERKSLGORT'

v_value_old

CHANGING v_value_new.

w_item-werks = v_value_new+0(4).

w_item-lgort = v_value_new+4(4).

*--The converted recieving plant will be the same as the supplying plant in the new system

  • and the supplying storage location would be OW01.

w_poheader-suppl_plnt = w_item-werks.

*--Fill item

w_poitem-po_item = w_item-ebelp.

w_poitem-material = w_item-matnr.

w_poitem-plant = w_item-werks.

w_poitem-stge_loc = w_item-lgort.

w_poitem-po_unit = w_item-meins.

PERFORM get_valuation_type USING w_item-matnr

w_item-werks

w_item-lgort

CHANGING w_poitem-val_type.

IF w_item-matnr CP '*-R'.

SPLIT w_item-matnr AT '-R' INTO w_item-matnr v_split.

ELSEIF w_item-matnr CP '*-D'.

SPLIT w_item-matnr AT '-D' INTO w_item-matnr v_split.

ENDIF.

SELECT SINGLE matnr INTO w_matnr

FROM mara

WHERE matnr = w_item-matnr.

IF sy-subrc NE 0.

w_errortab-ponumber = w_item-ebeln.

w_errortab-poitem = w_item-ebelp.

CONCATENATE w_item-matnr 'Does not exist in the MARC table'

INTO w_errortab-message.

ADD 1 TO v_error.

CONTINUE.

ENDIF.

w_poitem-matl_group = w_item-matkl.

w_poitem-item_cat = w_item-pstyp.

w_poitem-acctasscat = w_item-knttp.

w_poitem-reminder1 = w_item-mahn1.

w_poitem-conf_ctrl = w_item-bstae.

w_poitem-ackn_reqd = w_item-kzabs.

w_poitem-quantity = w_item-menge.

w_poitem-reminder2 = w_item-mahn2.

w_poitem-acknowl_no = w_item-labnr.

w_poitem-reminder3 = w_item-mahn3.

w_poitem-trackingno = w_item-bednr.

w_poitem-gr_pr_time = w_item-webaz.

w_poitem-under_dlv_tol = w_item-untto.

w_poitem-qual_insp = w_item-insmk.

w_poitem-over_dlv_tol = w_item-uebto.

w_poitem-unlimited_dlv = w_item-uebtk.

w_poitem-no_more_gr = w_item-elikz.

w_poitem-shipping = w_item-evers.

w_poitem-period_ind_expiration_date = ' '.

APPEND w_poitem TO i_poitem.

w_poitemx-po_item = w_poitem-po_item.

w_poitemx-po_itemx = 'X'.

w_poitemx-material = 'X'.

w_poitemx-plant = 'X'.

w_poitemx-stge_loc = 'X'.

w_poitemx-po_unit = 'X'.

w_poitemx-val_type = 'X'.

w_poitemx-matl_group = 'X'.

w_poitemx-item_cat = 'X'.

w_poitemx-acctasscat = 'X'.

w_poitemx-reminder1 = 'X'.

w_poitemx-conf_ctrl = 'X'.

w_poitemx-ackn_reqd = 'X'.

w_poitemx-quantity = 'X'.

w_poitemx-reminder2 = 'X'.

w_poitemx-acknowl_no = 'X'.

w_poitemx-reminder3 = 'X'.

w_poitemx-trackingno = 'X'.

w_poitemx-gr_pr_time = 'X'.

w_poitemx-under_dlv_tol = 'X'.

w_poitemx-qual_insp = 'X'.

w_poitemx-over_dlv_tol = 'X'.

w_poitemx-unlimited_dlv = 'X'.

w_poitemx-no_more_gr = 'X'.

w_poitemx-shipping = 'X'.

w_poitemx-period_ind_expiration_date = 'X'.

APPEND w_poitemx TO i_poitemx.

CLEAR w_poitemx.

CLEAR: w_slines, v_scheditem.

LOOP AT i_slines INTO w_slines WHERE ebeln EQ w_item-ebeln

AND ebelp EQ w_item-ebelp.

*--Fill Schedule lines for PO

w_poschedule-po_item = w_item-ebelp.

w_poschedule-sched_line = w_slines-etenr.

w_poschedule-del_datcat_ext = ' '.

w_poschedule-delivery_date = w_slines-eindt.

w_poschedule-quantity = w_slines-menge.

APPEND w_poschedule TO i_poschedule.

CLEAR w_poschedule.

w_poschedulex-po_item = w_item-ebelp.

w_poschedulex-sched_line = w_slines-etenr.

w_poschedulex-po_itemx = 'X'.

w_poschedulex-sched_linex = 'X'.

w_poschedulex-del_datcat_ext = 'X'.

w_poschedulex-delivery_date = 'X'.

w_poschedulex-quantity = 'X'.

APPEND w_poschedulex TO i_poschedulex.

CLEAR w_poschedulex.

CLEAR w_slines.

ENDLOOP.

CLEAR: w_poitem,

w_item.

ENDLOOP.

SORT: i_poitem, i_poitemx, i_poschedule, i_poschedulex.

*--If the import data to BAPI is empty, then raise a message to check the Material Error file for

  • any PO items which are skipped.

  • The PO in error is also moved to the error file for reprocessing.

IF w_poheader IS INITIAL OR

i_poitem[] IS INITIAL.

CLEAR: w_poheader, w_poheaderx, i_return[], i_poitem, i_poitem[].

CONTINUE.

ENDIF.

*--BAPI call for PO creation

CALL FUNCTION 'BAPI_PO_CREATE1'

EXPORTING

poheader = w_poheader

poheaderx = w_poheaderx

testrun = p_test

IMPORTING

exppurchaseorder = w_exppurchaseorder

expheader = w_expheader

TABLES

return = i_return

poitem = i_poitem

poitemx = i_poitemx

poschedule = i_poschedule

poschedulex = i_poschedulex.

*--Commit the transaction if a success message is returned, else rollback work.

  • Update the legacy PO and items in the ZMM_CORDLOG table

*******************************************

start of modification

*******************************************

WAIT UP TO time SECONDS.

*************************************************

end of modification

*******************************************************

IF NOT i_return[] IS INITIAL.

LOOP AT i_return INTO w_return.

*--Read the error messages

IF w_return-type = 'E'.

w_errortab-ponumber = w_header-ebeln.

w_errortab-doctype = w_poheader-doc_type.

w_errortab-supplplnt = w_poheader-suppl_plnt.

w_errortab-vendor = w_poheader-vendor.

w_errortab-eccpo = w_expheader-po_number.

w_errortab-message = w_return-message(73).

APPEND w_errortab TO i_errortab.

ADD 1 TO v_error.

ROLLBACK WORK.

ELSEIF w_return-type = 'S'.

CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'

EXPORTING

wait = 'X'

EXCEPTIONS

OTHERS = 1.

IF sy-subrc EQ 0.

v_success = v_success + 1.

CLEAR w_poitem.

LOOP AT i_poitem INTO w_poitem.

w_zmm_cordlog-ponumber = w_poheader-po_number.

w_zmm_cordlog-poitem = w_poitem-po_item.

w_zmm_cordlog-doctype = w_poheader-doc_type.

w_zmm_cordlog-supplplnt = w_poheader-suppl_plnt.

w_zmm_cordlog-vendor = w_poheader-vendor.

w_zmm_cordlog-eccpo = w_poheader-po_number.

w_zmm_cordlog-eccpoitem = w_poitem-po_item.

w_zmm_cordlog-message = w_return-message(73).

MODIFY zmm_cordlog FROM w_zmm_cordlog. "Modify DB table

CLEAR w_zmm_cordlog.

w_errpo-ebeln = w_poheader-po_number.

w_errpo-ebelp = w_poitem-po_item.

APPEND w_errpo TO i_errpo.

CLEAR w_errpo.

ENDLOOP.

ENDIF.

ENDIF.

ENDLOOP.

CALL FUNCTION 'DEQUEUE_ALL'.

ENDIF.

CLEAR: w_header,

w_poheader,

w_poheaderx.

CALL FUNCTION 'DEQUEUE_ALL'.

ENDLOOP.

IF NOT i_errpo[] IS INITIAL.

*--Separate error records (all records for any PO in error).

PERFORM create_error_file TABLES i_header_sa.

*--Write data to Application Server

IF NOT i_error[] IS INITIAL.

OPEN DATASET p_error FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

IF sy-subrc NE 0.

MESSAGE e398 WITH text-023 space space space.

ENDIF.

LOOP AT i_error INTO w_error.

TRANSFER w_error TO p_error.

ENDLOOP.

ENDIF.

ENDIF.

COMMIT WORK.

ENDFORM. " create_sto

0 Kudos

My requirement is also almost same.

Instead of Shedule lines , i have to update the Confirmations for the item ?

How can i do this ? Because i think we dont have a parameter in the BAPI to pass these confirmations ?

Please help out.

former_member181962
Active Contributor
0 Kudos

Hi Sony,

ME21n is an senjoy transaction and you cannot do a BDC for such transactions.

Try to a BDC for ME21 instead.

If you know how to create a PO manually using the transaction, you have to do the same thing in a recording mode.

Go to SHDB transaction.

Record the transaction ME21 and generate a program out of the recording.

Modify the program according to your requirement if requuired.

But i think there must be a proble in the way you have coded for teh BAPI, for all i i know the BAPI is capable of doing everything that a transaction can do.

Regards,

Ravi

Former Member
0 Kudos

HI,

bdc on njoy transactions is not possible as far as my knowledge goes.

more over in ur case

u r saying tht some of the records are skipped.

this is bcoz loop-endloop routine runs at lightening speed where the commit work in the bapi takes time to update the database so, after commit work in the bapi or after that bapi plz includde a wait stmt so as to delay the loop (say 5 sec) there by allowing the database ti finish the updation and comeback and pick the next record.

hope this works

0 Kudos

Thanks Kare...But I was using wait = 'X' in the Commit Function module and also I am using DEQUEE_ALL function module also....But still it is not working...

Do you mean I need to use wait also after commit the Transaction?

Thanks,

Sony

former_member194669
Active Contributor
0 Kudos

Hi,

Try to use the following fm BAPI call


      call function 'ENQUE_SLEEP'
        exporting
          seconds = ntime.

May be this will help you.

aRs