‎2008 Jan 09 6:07 AM
Hi to all
I'm new to BDC Progaram
can u tell me how to write a
BDC program to upload purchase order data from legacy system.
‎2008 Jan 09 10:14 AM
Hi Viswanath,
First i will explain the procedure step by step and will send a sample code plz check it once ok..And also i will attach a flat file at the end of SAMPLE CODE CHECK IT ONCE OK..
Steps:
1.Bulid an internal table first according to ur flat file fields.
2.select the flat file by using PARAMETER.
3.And assign that file path to GUI_UPLOAD function module.
4.Call BDC_OPEN_GROUP is used to open the session.
5.loop that flat file data and palce BDC_INSERT funtion module in that loop for uploading data into database table
6.After loop call BDC_CLOSE_GROUP to close the session.
SAMPLE CODE:
REPORT ybdc_session_mm01 NO STANDARD PAGE HEADING LINE-SIZE 255.
-
Global Structure for BDC Data
-
DATA: it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
-
Internal Table
-
DATA: BEGIN OF itab OCCURS 0,
mbrsh LIKE rmmg1-mbrsh,
mtart LIKE rmmg1-mtart,
maktx LIKE makt-maktx,
meins LIKE mara-meins,
END OF itab.
-
Upload the flat file
-
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename =
'C:\Documents and Settings\Compaq_Owner\Desktop\satish\mm01.txt'
filetype = 'ASC'
has_field_separator = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = itab.
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF sy-subrc 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
-
Session Method Starts
BDC_OPEN_GROUP
-
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
DEST = FILLER8
GROUP = 'ychinnu'
HOLDDATE = FILLER8
KEEP = 'X'
USER = SY-UNAME
RECORD = FILLER1
PROG = SY-CPROG
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.
-
Create BDCDATA Structure
-
*include bdcrecx1.
START-OF-SELECTION.
PERFORM open_group.
loop at itab.
PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RMMG1-MTART'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RMMG1-MBRSH'
itab-mbrsh.
PERFORM bdc_field USING 'RMMG1-MTART'
itab-mtart.
-
After enterning MBRSH,MTART we press enter
-
PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'. "press Enter
PERFORM bdc_field USING 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
-
View selection (Basic data1)
-
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'"view selection
'X'.
-
Select Tick Mark (ok)
-
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BU'.
PERFORM bdc_field USING 'MAKT-MAKTX'
itab-maktx.
PERFORM bdc_field USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM bdc_field USING 'MARA-MEINS'
itab-meins.
-
Finally after filling the data we save the data.
-
PERFORM bdc_field USING 'MARA-MTPOS_MARA' "For saving
'NORM'.
PERFORM bdc_transaction USING 'MM01'.
*
PERFORM close_group.
-
BDC_INSERT
-
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
POST_LOCAL = NOVBLOCAL
PRINTING = NOPRINT
SIMUBATCH = ' '
CTUPARAMS = ' '
TABLES
dynprotab = it_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.
-
Refresh BDCDATA
-
refresh it_bdcdata.
endloop.
-
Closing BDC Group
-
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.
-
Start new screen *
-
FORM bdc_dynpro USING program dynpro.
CLEAR it_bdcdata.
it_bdcdata-program = program.
it_bdcdata-dynpro = dynpro.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
ENDFORM. "BDC_DYNPRO
-
Insert field *
-
FORM bdc_field USING fnam fval.
IF FVAL NODATA.
CLEAR it_bdcdata.
it_bdcdata-fnam = fnam.
it_bdcdata-fval = fval.
APPEND it_bdcdata.
ENDIF.
ENDFORM. "BDC_FIELD
-
Flat File
-
*M FERT IRON KG
*M ROH STEEL KG
*M HALB IRON KG
-
Award points if helpful.
Kiran Kumar.G.A
‎2008 Jan 09 8:45 AM
Hi, this may help you.
by using some of functionModules like
in both AS,PS we have to create internal table
1)UP-LOAD
2)DOWN-LOAD these are used if the data is in Presentation
Server
3)READ-DATASET
4)TRANSFER these are used if the data is in Application
Server
(Or)
By using Manualprogramming
like BDCDATA structure
there we have fields like program,dynpro,dynbegin,fname,fval
Regards
Madhu
‎2008 Jan 09 8:48 AM
Check the links below:
http://abapliveinfo.blogspot.com/2007/12/uploading-material-master-data-using_28.html
http://www.allinterview.com/showanswers/23650.html
http://www.sap-img.com/abap/learning-bdc-programming.htm
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/home/bdc&;
http://www.sap-img.com/abap/learning-bdc-programming.htm
http://www.sapdevelopment.co.uk/bdc/bdchome.htm
http://www.sap-img.com/abap/difference-between-batch-input-and-call-transaction-in-bdc.htm
http://help.sap.com/saphelp_47x200/helpdata/en/69/c250684ba111d189750000e8322d00/frameset.htm
http://www.sapbrain.com/TUTORIALS/TECHNICAL/BDC_tutorial.html
Regards.
‎2008 Jan 09 10:14 AM
Hi Viswanath,
First i will explain the procedure step by step and will send a sample code plz check it once ok..And also i will attach a flat file at the end of SAMPLE CODE CHECK IT ONCE OK..
Steps:
1.Bulid an internal table first according to ur flat file fields.
2.select the flat file by using PARAMETER.
3.And assign that file path to GUI_UPLOAD function module.
4.Call BDC_OPEN_GROUP is used to open the session.
5.loop that flat file data and palce BDC_INSERT funtion module in that loop for uploading data into database table
6.After loop call BDC_CLOSE_GROUP to close the session.
SAMPLE CODE:
REPORT ybdc_session_mm01 NO STANDARD PAGE HEADING LINE-SIZE 255.
-
Global Structure for BDC Data
-
DATA: it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE.
-
Internal Table
-
DATA: BEGIN OF itab OCCURS 0,
mbrsh LIKE rmmg1-mbrsh,
mtart LIKE rmmg1-mtart,
maktx LIKE makt-maktx,
meins LIKE mara-meins,
END OF itab.
-
Upload the flat file
-
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename =
'C:\Documents and Settings\Compaq_Owner\Desktop\satish\mm01.txt'
filetype = 'ASC'
has_field_separator = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
IMPORTING
FILELENGTH =
HEADER =
TABLES
data_tab = itab.
EXCEPTIONS
FILE_OPEN_ERROR = 1
FILE_READ_ERROR = 2
NO_BATCH = 3
GUI_REFUSE_FILETRANSFER = 4
INVALID_TYPE = 5
NO_AUTHORITY = 6
UNKNOWN_ERROR = 7
BAD_DATA_FORMAT = 8
HEADER_NOT_ALLOWED = 9
SEPARATOR_NOT_ALLOWED = 10
HEADER_TOO_LONG = 11
UNKNOWN_DP_ERROR = 12
ACCESS_DENIED = 13
DP_OUT_OF_MEMORY = 14
DISK_FULL = 15
DP_TIMEOUT = 16
OTHERS = 17
.
IF sy-subrc 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
-
Session Method Starts
BDC_OPEN_GROUP
-
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
DEST = FILLER8
GROUP = 'ychinnu'
HOLDDATE = FILLER8
KEEP = 'X'
USER = SY-UNAME
RECORD = FILLER1
PROG = SY-CPROG
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.
-
Create BDCDATA Structure
-
*include bdcrecx1.
START-OF-SELECTION.
PERFORM open_group.
loop at itab.
PERFORM bdc_dynpro USING 'SAPLMGMM' '0060'.
PERFORM bdc_field USING 'BDC_CURSOR'
'RMMG1-MTART'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'RMMG1-MBRSH'
itab-mbrsh.
PERFORM bdc_field USING 'RMMG1-MTART'
itab-mtart.
-
After enterning MBRSH,MTART we press enter
-
PERFORM bdc_dynpro USING 'SAPLMGMM' '0070'. "press Enter
PERFORM bdc_field USING 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(01)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=ENTR'.
-
View selection (Basic data1)
-
PERFORM bdc_field USING 'MSICHTAUSW-KZSEL(01)'"view selection
'X'.
-
Select Tick Mark (ok)
-
PERFORM bdc_dynpro USING 'SAPLMGMM' '4004'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BU'.
PERFORM bdc_field USING 'MAKT-MAKTX'
itab-maktx.
PERFORM bdc_field USING 'BDC_CURSOR'
'MARA-MEINS'.
PERFORM bdc_field USING 'MARA-MEINS'
itab-meins.
-
Finally after filling the data we save the data.
-
PERFORM bdc_field USING 'MARA-MTPOS_MARA' "For saving
'NORM'.
PERFORM bdc_transaction USING 'MM01'.
*
PERFORM close_group.
-
BDC_INSERT
-
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'MM01'
POST_LOCAL = NOVBLOCAL
PRINTING = NOPRINT
SIMUBATCH = ' '
CTUPARAMS = ' '
TABLES
dynprotab = it_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.
-
Refresh BDCDATA
-
refresh it_bdcdata.
endloop.
-
Closing BDC Group
-
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.
-
Start new screen *
-
FORM bdc_dynpro USING program dynpro.
CLEAR it_bdcdata.
it_bdcdata-program = program.
it_bdcdata-dynpro = dynpro.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
ENDFORM. "BDC_DYNPRO
-
Insert field *
-
FORM bdc_field USING fnam fval.
IF FVAL NODATA.
CLEAR it_bdcdata.
it_bdcdata-fnam = fnam.
it_bdcdata-fval = fval.
APPEND it_bdcdata.
ENDIF.
ENDFORM. "BDC_FIELD
-
Flat File
-
*M FERT IRON KG
*M ROH STEEL KG
*M HALB IRON KG
-
Award points if helpful.
Kiran Kumar.G.A
‎2008 Jan 09 12:24 PM
This is the process how to write a converasion program...
1.Recording using SHDB.
( First record by giving some sample record to your transaction.later save that recording)
2.Later u press Shift+F5 or you can press program button on the Toolbar.
3.U can generate a program by 1.Reading from a file
2.Transfer from recording
4.A program will be generated.
5.later u can make little modifications with that and use it foe Call transaction or Session method.
In the program..
1.u need to have internal tables to collect data into from flat file.
2.u need to have one more internal table of structure BDCDATA to pass data to your transaction.
3.u need to use GUI_UPLOAD (for text files) and ALSM_EXCEL_TO_INTERNAL_TABLE (for excel files) to upload data from flat file to internal tables.
(Flat file may be text file or Excel file)
4.later based on your processyou should proceed.
if session..
1.BDC_OPEN_GROUP (For creating session)
2.BDC_INSERT (Processing data )
3.BDC_CLOSE_GROUP (closing session)
if you don't use BDC_CLOSE_GROUP, session will not be created..
if call transaction..
just populate BDCDATA table and at the end write this statement
CALL TRANSACTION 'transaction codes' USING BDCDATA MODE 'A/E/N' update 'S/A' messages into BDCMSGCOLL.