09-23-2008 6:24 AM
Hi All,
I need to create a BDC program for the creation of purchase orders using tcode ME21n.
I have Header data & Item data to upload while creating the purchase order.
How to handle the uploading of header data & item data.
How should we code the program & how the flatfile should be designed.
Regards,
Sudhir
09-23-2008 7:14 AM
hi
I suggest you go with the BAPI_PO_Create1. Performing BDC for an Enjoy transaction is not SAP recommended standard practice.
It will cause lot of problems with the screen flow looping in the table.
I had this problem,so later on moved to BAPI.
Just read the documentation of the BAPI in SE37, you will get a clear idea of the fields and how u should structure the flat file.
Regards,
Vishwa.
09-23-2008 7:29 AM
Hi,
OK..But i need to create purchase orders using BDC only...can you provide me the info which i asked for ME21.
Regards,
Sudhir
09-23-2008 7:35 AM
Hi
Here I am giving you a sample code..where we need to create PO's from Z table...
Regarding the structure of the flat file, it is purely based on the client and the functional team.. they will know better which fields are to be filled. So, you have to sit with the functional guy and do the recording using SHDB tcode and then decide with the flat file.
*&---------------------------------------------------------------------*
*& Report ZZPO_BDC
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
REPORT ZZPO_BDC no standard page heading line-size 255.
tables: zzpo_staging.
DATA id type string..
DATA: fnam(20) type c,
matnr type bstmg.
data: quan(13) type c,
netpr(15) type c,
qty(13) type c,
gp(15) type c.
DATA idx type string.
data: i_bdcdata like bdcdata occurs 1 with header line,
i_msg like bdcmsgcoll occurs 1 with header line.
DATA W_STR type string.
DATA: IT_STAGING TYPE STANDARD TABLE OF ZZPO_STAGING WITH HEADER LINE,
ti_staging type standard table of zzpo_staging with header line,
KT_STAGING TYPE STANDARD TABLE OF ZZPO_STAGING WITH HEADER LINE.
*
*CALL FUNCTION 'BDC_OPEN_GROUP'
* EXPORTING
* CLIENT = SY-MANDT
* DEST = 'zzpo'
* GROUP = 'zzpo'
** HOLDDATE = FILLER8
* KEEP = 'X'
* USER = sy-uname
** RECORD = FILLER1
** PROG = SY-CPROG
** DCPFM = '%'
** DATFM = '%'
** IMPORTING
** QID =
** EXCEPTIONS
** CLIENT_INVALID = 1
** DESTINATION_INVALID = 2
** GROUP_INVALID = 3
** GROUP_IS_LOCKED = 4
** HOLDDATE_INVALID = 5
** INTERNAL_ERROR = 6
** QUEUE_ERROR = 7
** RUNNING = 8
** SYSTEM_LOCK_ERROR = 9
** USER_INVALID = 10
** OTHERS = 11
* .
*IF SY-SUBRC <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
start-of-selection.
*perform open_group.
SELECT * FROM ZZPO_STAGING INTO TABLE IT_STAGING.
select * from zzpo_staging into table ti_staging.
SELECT * fROM ZZPO_STAGING INTO TABLE KT_sTAGING.
delete adjacent duplicates from it_staging comparing vendor docdate.
loop at IT_STAGING.
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'
IT_STAGING-vendor.
perform bdc_field using 'RM06E-BSART'
'NB'.
perform bdc_field using 'RM06E-BEDAT'
IT_STAGING-docdate.
perform bdc_field using 'EKKO-EKORG'
IT_STAGING-purorg.
perform bdc_field using 'EKKO-EKGRP'
IT_STAGING-purgrp.
perform bdc_field using 'RM06E-LPEIN'
'T'.
* endloop.
perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-EPSTP(01)'.
perform bdc_field using 'BDC_OKCODE'
'=DETA'.
perform bdc_dynpro using 'SAPMM06E' '0120'.
perform bdc_field using 'BDC_CURSOR'
'EKPO-WERKS(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
move 1 to id.
*
loop at TI_STAGING WHERE VENDOR = IT_STAGING-VENDOR AND DOCDATE = IT_STAGING-DOCDATE.
concatenate 'RM06E-EPSTP(0' id ')' into fnam.
perform bdc_field using fnam TI_STAGING-itmcategory.
concatenate 'EKPO-KNTTP(0' id ')' into fnam.
perform bdc_field using fnam TI_STAGING-accassignment.
concatenate 'EKPO-EMATN(0' id ')' into fnam.
perform bdc_field using fnam TI_STAGING-material.
concatenate 'EKPO-TXZ01(0' id ')' into fnam.
perform bdc_field using fnam TI_STAGING-shortxt.
quan = ti_staging-poqty.
concatenate 'EKPO-MENGE(0' id ')' into fnam.
perform bdc_field using fnam quan.
concatenate 'RM06E-EEIND(0' id ')' into fnam.
perform bdc_field using fnam TI_STAGING-deliverydate.
netpr = ti_staging-netpr.
concatenate 'EKPO-NETPR(0' id ')' into fnam.
perform bdc_field using fnam netpr.
concatenate 'EKPO-MATKL(0' id ')' into fnam.
perform bdc_field using fnam TI_STAGING-mategroup.
concatenate 'EKPO-WERKS(0' id ')' into fnam.
perform bdc_field using fnam TI_STAGING-plant.
ID = ID + 1.
*
ENDLOOP.
*
* perform bdc_dynpro using 'SAPMM06E' '0111'.
* perform bdc_field using 'BDC_CURSOR'
* 'EKPO-MENGE'.
* perform bdc_field using 'BDC_OKCODE'
* '/00'.
*perform bdc_field using 'EKPO-KNTTP'
* 'N'.
*perform bdc_field using 'EKPO-TXZ01'
* 'Office Supplies'.
*perform bdc_field using 'EKPO-MENGE'
* '2'.
* perform bdc_field using 'EKPO-SPINF'
* 'B'.
* perform bdc_field using 'EKPO-BPUMN'
* '1'.
* perform bdc_field using 'EKPO-BPUMZ'
* '1'.
* perform bdc_field using 'EKPO-PRSDR'
* 'X'.
*perform bdc_field using 'RM06E-EEIND'
* '06/24/2008'.
*perform bdc_field using 'RM06E-LPEIN'
* 'D'.
* perform bdc_field using 'EKPO-WEPOS'
* 'X'.
* perform bdc_field using 'EKPO-REPOS'
* 'X'.
loop at TI_STAGING where vendor = it_staging-vendor and docdate = it_staging-docdate.
perform bdc_dynpro using 'SAPMM06E' '0511'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
perform bdc_field using 'EKKN-SAKTO'
TI_STAGING-glaccount.
perform bdc_field using 'BDC_CURSOR'
'DKACB-FMORE'.
perform bdc_field using 'DKACB-FMORE'
'X'.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_CURSOR'
'COBL-VORNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
perform bdc_field using 'COBL-NPLNR'
TI_STAGING-networkid.
perform bdc_field using 'COBL-VORNR'
TI_STAGING-activity.
* perform bdc_dynpro using 'SAPMM06E' '0120'.
* perform bdc_field using 'BDC_CURSOR'
* 'RM06E-EPSTP(02)'.
* perform bdc_field using 'BDC_OKCODE'
* '=DETA'.
* perform bdc_field using 'RM06E-EBELP'
* '10'.
*
* perform bdc_dynpro using 'SAPMM06E' '0120'.
* perform bdc_field using 'BDC_CURSOR'
* 'EKPO-WERKS(02)'.
* perform bdc_field using 'BDC_OKCODE'
* '/00'.
* perform bdc_field using 'RM06E-EBELP'
* '10'.
*perform bdc_field using 'RM06E-EPSTP(02)'
* 'd'.
*perform bdc_field using 'EKPO-KNTTP(02)'
* 'n'.
*perform bdc_field using 'EKPO-TXZ01(02)'
* 'adage artwork'.
*perform bdc_field using 'EKPO-MENGE(02)'
* ' 1'.
*perform bdc_field using 'RM06E-EEIND(02)'
* '06242008'.
*perform bdc_field using 'EKPO-MATKL(02)'
* 'm1'.
*perform bdc_field using 'EKPO-WERKS(02)'
* 'a001'.
* perform bdc_field using 'BDC_OKCODE'
* '/00'.
*
*
perform bdc_dynpro using 'SAPMM06E' '0111'.
perform bdc_field using 'BDC_CURSOR'
'EKPO-MENGE'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
* perform bdc_field using 'EKPO-MATKL'
* 'M1'.
* perform bdc_field using 'EKPO-TXZ01'
* wa_jtab-j4.
* perform bdc_field using 'EKPO-PRSDR'
* 'X'.
* perform bdc_field using 'RM06E-EEIND'
* wa_jtab-j6.
*
*
perform bdc_field using 'RM06E-LPEIN'
'D'.
perform bdc_field using 'EKPO-WEPOS'
'X'.
perform bdc_field using 'EKPO-UEBTK'
'X'.
perform bdc_field using 'EKPO-WEBRE'
'X'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
move 1 to idx.
perform bdc_dynpro using 'SAPLMLSP' '0200'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RM11P-HEADTEXT'
'adage'.
perform bdc_field using 'BDC_CURSOR' 'ESLL-TBTWR(01)'.
perform bdc_field using 'RM11P-NEW_ROW'
'10'.
* concatenate 'ESLL-KTEXT1(0' idx ')' into fnaml.
* perform bdc_field using fnaml wa_ktab-k1.
*
* concatenate 'ESLL-MENGE(0' idx ')' into fnaml.
* perform bdc_field using fnaml wa_ktab-k2.
*
* concatenate 'ESLL-MEINS(0' idx ')' into fnaml.
* perform bdc_field using fnaml wa_ktab-k3.
*
* concatenate 'ESLL-TBTWR(0' idx ')' into fnaml.
* perform bdc_field using fnaml wa_ktab-k4.
*
* IDX = IDX + 1.
* loop at KT_STAGING where vendor = it_staging-vendor and docdate = it_staging-docdate and itmcategory is not initial.
IF TI_STAGING-ITMCATEGORY IS NOT INITIAL.
qty = ti_staging-serqty.
gp = ti_staging-sergrossprice.
perform bdc_field using 'ESLL-KTEXT1(01)' TI_STAGING-sertext.
perform bdc_field using 'ESLL-MENGE(01)' qty.
perform bdc_field using 'ESLL-MEINS(01)' TI_STAGING-seruom.
perform bdc_field using 'ESLL-TBTWR(01)' gp.
* endloop.
* move 1 to cnt.
*
* loop at KT_STAGING WHERE VENDOR = IT_STAGING-VENDOR AND DOCDATE = IT_STAGING-DOCDATE and itmcategory is not initial.
perform bdc_dynpro using 'SAPLMLSK' '0200'.
perform bdc_field using 'BDC_CURSOR'
'RM11K-VORNR(01)'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'VRTKZ1'
'X'.
* concatenate 'ESKN-SAKTO(0' IDX ')' into fnamk.
* perform bdc_field using fnam wa_ktab-k5.
*
* concatenate 'ESKN-NPLNR(0' IDX ')' into fnamk.
* perform bdc_field using fnam wa_ktab-k6.
*
* concatenate 'RM11K-VORNR(0' IDX ')' into fnamk.
* perform bdc_field using fnam wa_ktab-k7.
* cnt = cnt + 1.
PERFORM BDC_FIELD USING 'ESKN-SAKTO(01)' TI_STAGING-serglaccount.
PERFORM BDC_FIELD USING 'ESKN-NPLNR(01)' TI_STAGING-sernetwork.
PERFORM BDC_FIELD USING 'RM11K-VORNR(01)' TI_STAGING-seractivity.
* endloop.
perform bdc_dynpro using 'SAPLKACB' '0002'.
perform bdc_field using 'BDC_CURSOR'
'COBL-NPLNR'.
perform bdc_field using 'BDC_OKCODE'
'=ENTE'.
perform bdc_field using 'COBL-NPLNR'
kt_STAGING-sernetwork.
perform bdc_field using 'COBL-VORNR'
kt_STAGING-seractivity.
perform bdc_dynpro using 'SAPLMLSK' '0200'.
perform bdc_field using 'BDC_CURSOR'
'ESLL-INTROW'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'VRTKZ1'
'X'.
perform bdc_dynpro using 'SAPMM06E' '0200'.
perform bdc_field using 'BDC_CURSOR'
'RM06E-EBELP'.
perform bdc_field using 'BDC_OKCODE'
'=BACK'.
perform bdc_dynpro using 'SAPLMLSP' '0200'.
perform bdc_field using 'BDC_OKCODE'
'=SAV'.
ELSE.
perform bdc_dynpro using 'SAPMM06E' '0100'.
perform bdc_field using 'BDC_OKCODE'
'=SAV'.
ENDIF.
endloop.
*perform bdc_field using 'RM11P-HEADTEXT'
* 'adage artwork'.
* perform bdc_field using 'BDC_CURSOR'
* 'ESLL-KTEXT1(01)'.
*perform bdc_field using 'RM11P-NEW_ROW'
* '10'.
*perform bdc_transaction using 'ME21'.
CALL TRANSACTION 'ME21' USING I_BDCDATA MODE 'A' messages into i_msg.
*clear: kt_staging,ti_staging,it_staging,i_bdcdata.
endloop.
*
* CALL FUNCTION 'BDC_INSERT'
* EXPORTING
* TCODE = 'ME21'
** POST_LOCAL = NOVBLOCAL
** PRINTING = NOPRINT
** SIMUBATCH = ' '
** CTUPARAMS = ' '
* TABLES
* DYNPROTAB = I_BDCDATA
** EXCEPTIONS
** INTERNAL_ERROR = 1
** NOT_OPEN = 2
** QUEUE_ERROR = 3
** TCODE_INVALID = 4
** PRINTING_INVALID = 5
** POSTING_INVALID = 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.
*-------------------------------------------------------------------------------------------*
*Using Call Transaction Statement Call the transaction in back ground mode/fore ground mode
*-------------------------------------------------------------------------------------------*
*
LOOP AT I_MSG.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = I_MSG-MSGID
LANG = SY-LANGU
NO = I_MSG-MSGNR
V1 = I_MSG-MSGV1
V2 = I_MSG-MSGV2
V3 = I_MSG-MSGV3
V4 = I_MSG-MSGV4
IMPORTING
MSG = W_STR
* EXCEPTIONS
* NOT_FOUND = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WRITE:/ i_msg-msgnr,w_str.
endloop.
*
* CALL FUNCTION 'BDC_CLOSE_GROUP'.
*** EXCEPTIONS
*** NOT_OPEN = 1
*** QUEUE_ERROR = 2
*** OTHERS = 3
** .
** IF SY-SUBRC <> 0.
*** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
** ENDIF.
**
**
*perform close_group.
*----------------------------------------------------------------------*
* Start new screen *
*----------------------------------------------------------------------*
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR I_BDCDATA.
I_BDCDATA-PROGRAM = PROGRAM.
I_BDCDATA-DYNPRO = DYNPRO.
I_BDCDATA-DYNBEGIN = 'X'.
APPEND I_BDCDATA.
ENDFORM. "BDC_DYNPRO
*----------------------------------------------------------------------*
* Insert field *
*----------------------------------------------------------------------*
FORM BDC_FIELD USING FNAM FVAL.
* IF FVAL <> SPACE.
CLEAR I_BDCDATA.
I_BDCDATA-FNAM = FNAM.
I_BDCDATA-FVAL = FVAL.
APPEND I_BDCDATA.
* ENDIF.
ENDFORM. "BDC_FIELD
09-23-2008 9:45 AM
09-23-2008 9:55 AM
Hi Vishwa,
I am not able to understand your answer.Can you be a bit clear.
09-23-2008 9:59 AM
Hi
Just select ur question is answered...if u got useful answers... After getting replies on the question, everybody is advise to close their post immediately..