‎2008 Jul 30 12:19 PM
Hi all,
I am doing a BDC program using call transaction for me21n... when i am trying to take the data from flat file .. quantity and price are not
accepted from internal table but if i directly put the value in the program
its working fine....
can anybody suggest wat to do
Rajiv Kumar
‎2008 Jul 30 12:22 PM
hi,
use this program...
********************************************************************
REPORT ZMM_PO
LINE-SIZE 351
NO STANDARD PAGE HEADING
LINE-COUNT 65
MESSAGE-ID ZMSG.
********************************************************************
*BDC INCLUDE PROGRAM
********************************************************************
Include bdcrecx1.
********************************************************************
*INTERNAL TABLES AND STRUCTURES
********************************************************************
Data : Begin of it_po occurs 0,
Docu_No(10), "Document Number For Legacy System.
Vdr_No(10), "Vendor Number
doc_type(4), "Document type
track_number(10), "Tracking number
Docu_Date(10), "Document Date
Po_Org(4), "Purchasing Organization
Po_Group(3), "Purchasing Group
comp_code(4), "Company Code
Mat_Desc(40), "short text
Material(18), "Material Number
Quantity(16), "Purchase order quantity
Order_unit(3), "Order unit(UOM)
I_Cod(1), "Category of delivery date(For item)
Idelivery_Date(10), "Delivery Date(For item)
Netprice(13), "Net price in purchasing document
currency(5), "Currency Key
Price_Unit(5), "Price unit
Order_Priceunit(3), "Order Price Unit (UOM)
Material_Group(4), "Material group
Plant(4), "Plant
Sdelivery_Date(10), "Delivery Date(For Shedule)
Shld_Qty(16), "Shedule Quantity
Batch(10), "Batch
Storage_location(4), "Storage location
tax_code(2), "Tax code
sitem_no(5), "Item Number of Purchasing Document
S_Cod(1), "Category of delivery date(For Shedule)
Srd_Date(10), "Statistics relevent delivery date
Er_message(100), "Error message
End of it_po.
*Iternal table to get the error data
----
Data it_error like it_po occurs 0 with header line.
*Iternal table to find the error from the legacy data
----
Data : begin of it_erfind occurs 0,
Docu_No(10), "Legacy document number for error file
Er_message(100), "For Error Message
end of it_erfind.
*Variable Declartions
----
Data : temp(40),
item_count(2) type n,
schedule_count(2) type n,
wa like it_po,
g_message(200).
********************************************************************
*START-OF-SELECTION
********************************************************************
START-OF-SELECTION.
********************************************************************
*READING LEGACY FILE
********************************************************************
call function 'UPLOAD'
exporting
CODEPAGE = 'IBM'
FILENAME = ' '
FILETYPE = 'DAT'
tables
DATA_TAB = IT_PO
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.
write :/(50) 'Upload error!'.
check 1 = 2.
endif.
*Sort the internal table based on legacy doucment no and materail number
----
sort it_po by Docu_No Material.
perform open_group.
loop at it_po.
move-corresponding it_po to wa.
*To pass the header data based on the document using at new document no
----
AT NEW Docu_No.
clear item_count.
item_count = 1.
perform bdc_dynpro using 'SAPMM06E' '0100'.
perform bdc_field using 'BDC_CURSOR'
'EKKO-EKGRP'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EKKO-LIFNR'
wa-VDR_NO.
perform bdc_field using 'RM06E-BSART'
wa-doc_type.
perform bdc_field using 'RM06E-BEDAT'
wa-docu_date.
perform bdc_field using 'EKKO-EKORG'
wa-Po_Org.
perform bdc_field using 'EKKO-EKGRP'
wa-Po_Group.
ENDAT.
AT NEW material.
clear schedule_count.
schedule_count = 1.
*If the item exceed 14 then calling the next set of rows to proceed.
----
if item_count > 14.
clear item_count.
item_count = 2.
perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_OKCODE'
'=NP'.
endif.
perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_CURSOR'
'EKPO-MENGE(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
clear temp.
concatenate 'EKPO-EMATN(' item_count ')' into temp.
perform bdc_field using temp wa-material.
clear temp.
concatenate 'EKPO-MENGE(' item_count ')' into temp.
perform bdc_field using temp wa-quantity.
clear temp.
concatenate 'EKPO-MEINS(' item_count ')' into temp.
perform bdc_field using temp wa-Order_Unit.
clear temp.
concatenate 'RM06E-EEIND(' item_count ')' into temp.
perform bdc_field using temp wa-idelivery_date.
clear temp.
concatenate 'EKPO-NETPR(' item_count ')' into temp.
perform bdc_field using temp wa-netprice.
clear temp.
concatenate 'EKPO-BPRME(' item_count ')' into temp.
perform bdc_field using temp wa-Order_Priceunit.
clear temp.
concatenate 'EKPO-WERKS(' item_count ')' into temp.
perform bdc_field using temp wa-plant.
clear temp.
concatenate 'EKPO-LGORT(' item_count ')' into temp.
perform bdc_field using temp wa-storage_location.
clear temp.
concatenate 'RM06E-CHARG(' item_count ')' into temp.
perform bdc_field using temp wa-batch.
*For taxcode after selecting the concerned item
----
clear temp.
concatenate 'RM06E-TCSELFLAG(' item_count ')' into temp.
perform bdc_field using temp 'X'.
perform bdc_field using 'BDC_OKCODE'
'=DETA'.
perform bdc_dynpro using 'SAPMM06E' '0111'.
perform bdc_field using 'BDC_CURSOR'
'EKPO-MWSKZ'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EKPO-BEDNR'
wa-track_number.
perform bdc_field using 'EKPO-MWSKZ'
wa-tax_code.
clear temp.
concatenate 'EKPO-MWSKZ(' item_count ')' into temp.
perform bdc_field using temp wa-tax_code.
*To select the item leve to pass the schedule value
----
clear temp.
concatenate 'RM06E-TCSELFLAG(' item_count ')' into temp.
perform bdc_field using temp 'X'.
perform bdc_field using 'BDC_OKCODE'
'=ET'.
*increment to change the table control position for schedlue
----
item_count = item_count + 1.
ENDAT.
*To call the schedule screen only one time when schedul count = 1.
----
if schedule_count = 1.
perform bdc_dynpro using 'SAPMM06E' '1117'.
perform bdc_field using 'BDC_CURSOR'
'EKET-MENGE(02)'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
endif.
clear temp.
concatenate 'RM06E-EEIND(' schedule_count ')' into temp.
perform bdc_field using temp wa-sdelivery_date.
clear temp.
concatenate 'EKET-MENGE(' schedule_count ')' into temp.
perform bdc_field using temp wa-shld_qty.
*Increment to change the table control position for schedlue
----
schedule_count = schedule_count + 1.
AT END OF docu_no.
perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-BSTPO(01)'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'RM06E-EBELP'
'10'.
perform bdc_transaction using 'ME21'.
*To fetch the error message from the standard error table
----
SELECT SINGLE * FROM T100 WHERE SPRSL = 'E'
AND ARBGB = SY-MSGID
AND MSGNR = SY-MSGNO.
G_MESSAGE = T100-TEXT.
*subroutin to change the error message for every document number
----
PERFORM REPLACE_PARAMETERS USING SY-MSGV1 SY-MSGV2 SY-MSGV3
SY-MSGV4 CHANGING G_MESSAGE.
*Seggregate the error if the meg type is E.
----
if sy-msgty = 'E'.
it_erfind-docu_no = wa-docu_no .
it_erfind-er_message = G_MESSAGE.
append it_erfind.
endif.
ENDAT.
*Error Handling
----
AT LAST.
*To segregate the error
----
PERFORM segregate_error.
*To download the error from it_error internal table with err mesg
----
PERFORM error_download.
ENDAT.
endloop.
perform close_group.
*Subrotine to replace the parameters
----
FORM REPLACE_PARAMETERS USING P_PAR_1 P_PAR_2 P_PAR_3
P_PAR_4 CHANGING P_MESSAGE.
*erst mal pruefen, ob numerierte Parameter verwendet wurden
----
DO.
REPLACE '&1' WITH P_PAR_1 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&2' WITH P_PAR_2 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&3' WITH P_PAR_3 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&4' WITH P_PAR_4 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
*falls keine numerierten Parameter vorh., ersetzen wie gehabt
----
REPLACE '&' WITH P_PAR_1 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_2 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_3 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_4 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
*Subroutine to segregate the error data from the legacy data
----
FORM segregate_error.
loop at it_erfind.
loop at it_po where docu_no = it_erfind-docu_no.
move-corresponding it_po to it_error.
it_error-er_message = it_erfind-er_message.
append it_error.
endloop.
endloop.
ENDFORM.
*Subroutine to download the error data from the it_error table.
----
FORM error_download.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
CODEPAGE = 'IBM'
FILENAME = 'C:\ERROR\PO.TXT'
FILETYPE = 'DAT'
TABLES
DATA_TAB = IT_ERROR.
ENDFORM.
Rgds,
Paras
‎2008 Jul 30 12:22 PM
Hi,
I think while u r getting data from the internal table the splitting is not done properly.
‎2008 Jul 30 12:22 PM
hi,
use this program...
********************************************************************
REPORT ZMM_PO
LINE-SIZE 351
NO STANDARD PAGE HEADING
LINE-COUNT 65
MESSAGE-ID ZMSG.
********************************************************************
*BDC INCLUDE PROGRAM
********************************************************************
Include bdcrecx1.
********************************************************************
*INTERNAL TABLES AND STRUCTURES
********************************************************************
Data : Begin of it_po occurs 0,
Docu_No(10), "Document Number For Legacy System.
Vdr_No(10), "Vendor Number
doc_type(4), "Document type
track_number(10), "Tracking number
Docu_Date(10), "Document Date
Po_Org(4), "Purchasing Organization
Po_Group(3), "Purchasing Group
comp_code(4), "Company Code
Mat_Desc(40), "short text
Material(18), "Material Number
Quantity(16), "Purchase order quantity
Order_unit(3), "Order unit(UOM)
I_Cod(1), "Category of delivery date(For item)
Idelivery_Date(10), "Delivery Date(For item)
Netprice(13), "Net price in purchasing document
currency(5), "Currency Key
Price_Unit(5), "Price unit
Order_Priceunit(3), "Order Price Unit (UOM)
Material_Group(4), "Material group
Plant(4), "Plant
Sdelivery_Date(10), "Delivery Date(For Shedule)
Shld_Qty(16), "Shedule Quantity
Batch(10), "Batch
Storage_location(4), "Storage location
tax_code(2), "Tax code
sitem_no(5), "Item Number of Purchasing Document
S_Cod(1), "Category of delivery date(For Shedule)
Srd_Date(10), "Statistics relevent delivery date
Er_message(100), "Error message
End of it_po.
*Iternal table to get the error data
----
Data it_error like it_po occurs 0 with header line.
*Iternal table to find the error from the legacy data
----
Data : begin of it_erfind occurs 0,
Docu_No(10), "Legacy document number for error file
Er_message(100), "For Error Message
end of it_erfind.
*Variable Declartions
----
Data : temp(40),
item_count(2) type n,
schedule_count(2) type n,
wa like it_po,
g_message(200).
********************************************************************
*START-OF-SELECTION
********************************************************************
START-OF-SELECTION.
********************************************************************
*READING LEGACY FILE
********************************************************************
call function 'UPLOAD'
exporting
CODEPAGE = 'IBM'
FILENAME = ' '
FILETYPE = 'DAT'
tables
DATA_TAB = IT_PO
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.
write :/(50) 'Upload error!'.
check 1 = 2.
endif.
*Sort the internal table based on legacy doucment no and materail number
----
sort it_po by Docu_No Material.
perform open_group.
loop at it_po.
move-corresponding it_po to wa.
*To pass the header data based on the document using at new document no
----
AT NEW Docu_No.
clear item_count.
item_count = 1.
perform bdc_dynpro using 'SAPMM06E' '0100'.
perform bdc_field using 'BDC_CURSOR'
'EKKO-EKGRP'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EKKO-LIFNR'
wa-VDR_NO.
perform bdc_field using 'RM06E-BSART'
wa-doc_type.
perform bdc_field using 'RM06E-BEDAT'
wa-docu_date.
perform bdc_field using 'EKKO-EKORG'
wa-Po_Org.
perform bdc_field using 'EKKO-EKGRP'
wa-Po_Group.
ENDAT.
AT NEW material.
clear schedule_count.
schedule_count = 1.
*If the item exceed 14 then calling the next set of rows to proceed.
----
if item_count > 14.
clear item_count.
item_count = 2.
perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_OKCODE'
'=NP'.
endif.
perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_CURSOR'
'EKPO-MENGE(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
clear temp.
concatenate 'EKPO-EMATN(' item_count ')' into temp.
perform bdc_field using temp wa-material.
clear temp.
concatenate 'EKPO-MENGE(' item_count ')' into temp.
perform bdc_field using temp wa-quantity.
clear temp.
concatenate 'EKPO-MEINS(' item_count ')' into temp.
perform bdc_field using temp wa-Order_Unit.
clear temp.
concatenate 'RM06E-EEIND(' item_count ')' into temp.
perform bdc_field using temp wa-idelivery_date.
clear temp.
concatenate 'EKPO-NETPR(' item_count ')' into temp.
perform bdc_field using temp wa-netprice.
clear temp.
concatenate 'EKPO-BPRME(' item_count ')' into temp.
perform bdc_field using temp wa-Order_Priceunit.
clear temp.
concatenate 'EKPO-WERKS(' item_count ')' into temp.
perform bdc_field using temp wa-plant.
clear temp.
concatenate 'EKPO-LGORT(' item_count ')' into temp.
perform bdc_field using temp wa-storage_location.
clear temp.
concatenate 'RM06E-CHARG(' item_count ')' into temp.
perform bdc_field using temp wa-batch.
*For taxcode after selecting the concerned item
----
clear temp.
concatenate 'RM06E-TCSELFLAG(' item_count ')' into temp.
perform bdc_field using temp 'X'.
perform bdc_field using 'BDC_OKCODE'
'=DETA'.
perform bdc_dynpro using 'SAPMM06E' '0111'.
perform bdc_field using 'BDC_CURSOR'
'EKPO-MWSKZ'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'EKPO-BEDNR'
wa-track_number.
perform bdc_field using 'EKPO-MWSKZ'
wa-tax_code.
clear temp.
concatenate 'EKPO-MWSKZ(' item_count ')' into temp.
perform bdc_field using temp wa-tax_code.
*To select the item leve to pass the schedule value
----
clear temp.
concatenate 'RM06E-TCSELFLAG(' item_count ')' into temp.
perform bdc_field using temp 'X'.
perform bdc_field using 'BDC_OKCODE'
'=ET'.
*increment to change the table control position for schedlue
----
item_count = item_count + 1.
ENDAT.
*To call the schedule screen only one time when schedul count = 1.
----
if schedule_count = 1.
perform bdc_dynpro using 'SAPMM06E' '1117'.
perform bdc_field using 'BDC_CURSOR'
'EKET-MENGE(02)'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
endif.
clear temp.
concatenate 'RM06E-EEIND(' schedule_count ')' into temp.
perform bdc_field using temp wa-sdelivery_date.
clear temp.
concatenate 'EKET-MENGE(' schedule_count ')' into temp.
perform bdc_field using temp wa-shld_qty.
*Increment to change the table control position for schedlue
----
schedule_count = schedule_count + 1.
AT END OF docu_no.
perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-BSTPO(01)'.
perform bdc_field using 'BDC_OKCODE'
'=BU'.
perform bdc_field using 'RM06E-EBELP'
'10'.
perform bdc_transaction using 'ME21'.
*To fetch the error message from the standard error table
----
SELECT SINGLE * FROM T100 WHERE SPRSL = 'E'
AND ARBGB = SY-MSGID
AND MSGNR = SY-MSGNO.
G_MESSAGE = T100-TEXT.
*subroutin to change the error message for every document number
----
PERFORM REPLACE_PARAMETERS USING SY-MSGV1 SY-MSGV2 SY-MSGV3
SY-MSGV4 CHANGING G_MESSAGE.
*Seggregate the error if the meg type is E.
----
if sy-msgty = 'E'.
it_erfind-docu_no = wa-docu_no .
it_erfind-er_message = G_MESSAGE.
append it_erfind.
endif.
ENDAT.
*Error Handling
----
AT LAST.
*To segregate the error
----
PERFORM segregate_error.
*To download the error from it_error internal table with err mesg
----
PERFORM error_download.
ENDAT.
endloop.
perform close_group.
*Subrotine to replace the parameters
----
FORM REPLACE_PARAMETERS USING P_PAR_1 P_PAR_2 P_PAR_3
P_PAR_4 CHANGING P_MESSAGE.
*erst mal pruefen, ob numerierte Parameter verwendet wurden
----
DO.
REPLACE '&1' WITH P_PAR_1 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&2' WITH P_PAR_2 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&3' WITH P_PAR_3 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
DO.
REPLACE '&4' WITH P_PAR_4 INTO P_MESSAGE.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
ENDDO.
*falls keine numerierten Parameter vorh., ersetzen wie gehabt
----
REPLACE '&' WITH P_PAR_1 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_2 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_3 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
IF SY-SUBRC EQ 0.
REPLACE '&' WITH P_PAR_4 INTO P_MESSAGE.
CONDENSE P_MESSAGE.
ENDIF.
ENDIF.
ENDIF.
ENDFORM.
*Subroutine to segregate the error data from the legacy data
----
FORM segregate_error.
loop at it_erfind.
loop at it_po where docu_no = it_erfind-docu_no.
move-corresponding it_po to it_error.
it_error-er_message = it_erfind-er_message.
append it_error.
endloop.
endloop.
ENDFORM.
*Subroutine to download the error data from the it_error table.
----
FORM error_download.
CALL FUNCTION 'WS_DOWNLOAD'
EXPORTING
CODEPAGE = 'IBM'
FILENAME = 'C:\ERROR\PO.TXT'
FILETYPE = 'DAT'
TABLES
DATA_TAB = IT_ERROR.
ENDFORM.
Rgds,
Paras
‎2008 Jul 30 12:28 PM
hi,
thanks for reply..
actually i am creating a program for the RFC..
can this program help on that
‎2008 Jul 30 1:09 PM
hi ,
you use
BAPI_PO_CREATE1 Create Purchase Order
for this.
Rgds,
Paras
‎2008 Jul 30 12:23 PM
declare these two as chars in the internal table of the same length
‎2008 Jul 30 12:24 PM
Hi Rajiv,
In BDC u have to pass the currency and quantity fields to the character variables and then use them in ur BDC. This is because these are right alligned.
So when u populate the bdcdata first pass the quantity to a character variable , later use it to populate the bdcdata.
DATA: w_quantity(20) TYPE c.
LOOP AT itab into wa.
CLEAR w_quantity.
MOVE wa-quantity to w_quantity.
Use w_quantity to populate bdcdata instead of wa-quantity.
endloop.
Also avoid using BDC for anjoy transactions like ME21N, VL01N etc. We have BAPIs for this. Use them.
Thanks,
Vinod.
Edited by: Vinod Reddy Vemuru on Jul 30, 2008 4:55 PM
‎2008 Jul 30 1:22 PM
Hi Rajeev,
Define two character variables for quantity and Price...
Write your internaltable-quantity field to above respective variable.
data gv_quan(14).
e.g. write itab-quan to gv_quan.
Similarly for 2nd variable...
Try out this.....
Regards,
Kuldeep.