0% found this document useful (0 votes)
9 views23 pages

Batch Data Communication/Conversion

Uploaded by

akhilak8010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views23 pages

Batch Data Communication/Conversion

Uploaded by

akhilak8010
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 23

BDC

BATCH DATA COMMUNICATION/CONVERSION


 This is to transfer data from non-sap(legacy) system to
sap r/3 system( sap db)

 .txt—(upload)-----itab----(bdc)-----sap db

 Files are of 2 types :

 1.Sequential Files(Datasets) : These are stored in the


Application Server.

 2.Local Files(Flat files) : These are stored in the


Presentation Server(client).
Handling sequential files
 These are Handled by following commands :

 OPEN DATASET <DATASET NAME> FOR <OUTPUT/INPUT> IN


<TEXT MODE/BINARY MODE>

 CLOSE DATASET <DATASET NAME>

 READ DATASET <DATASET NAME>

 DELETE DATASET <DATASET NAME>

 TRANSFER <field string>


 REPORT ZSEQ1_8PM.

TYPES : BEGIN OF TY_KNA1,


KUNNR TYPE KNA1-KUNNR,
LAND1 TYPE KNA1-LAND1,
NAME1 TYPE KNA1-NAME1,
ORT01 TYPE KNA1-ORT01,
END OF TY_KNA1.

DATA : IT_KNA1 TYPE TABLE OF TY_KNA1,


WA_KNA1 TYPE TY_KNA1.

SELECT KUNNR NAME1 ORT01 LAND1 FROM KNA1 INTO TABLE IT_KNA1 UP TO 10 ROWS.

DATA : FNAME(60) TYPE C VALUE 'MYFILE7.TXT'.

OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.

LOOP AT IT_KNA1 INTO WA_KNA1.


TRANSFER WA_KNA1 TO FNAME.
ENDLOOP.

CLOSE DATASET FNAME.


 REPORT ZSEQ2_8PM.

TYPES : BEGIN OF TY_READ,


KUNNR TYPE KNA1-KUNNR,
LAND1 TYPE KNA1-LAND1,
NAME1 TYPE KNA1-NAME1,
ORT01 TYPE KNA1-ORT01,
END OF TY_READ.

DATA : IT_READ TYPE TABLE OF TY_READ,


WA_READ TYPE TY_READ.

DATA : FNAME(60) TYPE C VALUE 'MYFILE7.TXT'.

OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT.

DO.
READ DATASET FNAME INTO WA_READ.
IF SY-SUBRC <> 0.
EXIT.
ENDIF.
WRITE :/ WA_READ-KUNNR,WA_READ-NAME1,WA_READ-ORT01,WA_READ-LAND1.
ENDDO.

CLOSE DATASET FNAME.


Handling Local files
 these are handled by using following FUNCTIONS.

 UPLOAD (OR) WS_UPLOAD (OR) GUI_UPLOAD :


 these are used to transfer data from flat file to
 internal table.

 DOWNLOAD (OR) WS_DOWNLOAD (OR) GUI_DOWNLOAD:


 these are used to transfer data from internal table to flat file.
 The difference between UPLOAD and WS_UPLOAD&GUI_UPLOAD is,

 In UPLOAD FILENAME,FILETYPE can be given at run time,


 but where as in WS_UPLOAD&GUI_UPLOAD FILENAME and
FILETYPE must be specified.

 same difference for DOWNLOAD and


WS_DOWNLOAD&GUI_DOWNLOAD.
 REPORT ZUP_9AM.

TYPES : BEGIN OF TY_FILE,


CNO(10) TYPE C,
CNAME(20) TYPE C,
END OF TY_FILE.

DATA : IT_FILE TYPE TABLE OF TY_FILE,


WA_FILE TYPE TY_FILE.

CALL FUNCTION 'UPLOAD'


* EXPORTING
* CODEPAGE =''
* FILENAME =''
* FILETYPE =''
TABLES
DATA_TAB = IT_FILE.

LOOP AT IT_FILE INTO WA_FILE.


WRITE :/ WA_FILE-CNO,WA_FILE-CNAME.
ENDLOOP.
 REPORT ZUP_9AM.

TYPES : BEGIN OF TY_FILE,


CNO(10) TYPE C,
CNAME(20) TYPE C,
END OF TY_FILE.

DATA : IT_FILE TYPE TABLE OF TY_FILE,


WA_FILE TYPE TY_FILE.

CALL FUNCTION 'GUI_UPLOAD'


EXPORTING
FILENAME = 'C:\Users\Hello\Desktop\CC.TXT'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'T'

TABLES
DATA_TAB = IT_FILE.

LOOP AT IT_FILE INTO WA_FILE.


WRITE :/ WA_FILE-CNO,WA_FILE-CNAME.
ENDLOOP.
 BDC can be run in 2 methods :

 1.SESSION METHOD

 2.CALL TRANSACTION METHOD


Session method
 In this method the data is transferred through sessions.

 there are 3 functions provided by sap to run this session method.

 i.BDC_OPEN_GROUP -->here the session is created.


 ii.BDC_INSERT ------>here the data is transferred to session.
 iii.BDC_CLOSE_GROUP-->here the session is closed.

 until unless the session is processed the data will not be updated in the
database.

 to process the session t.code SM35.


 CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
 CLIENT = SY-MANDT
GROUP = 'SESS9'
TYPES : BEGIN OF TY_FILE, USER = SY-UNAME .
CNO(10) TYPE C,
LOOP AT IT_FILE INTO WA_FILE.
CNAME(20) TYPE C, PERFORM BDCDATA.
END OF TY_FILE.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
DATA : IT_FILE TYPE TABLE OF TY_FILE, TCODE = 'ZTT10'
WA_FILE TYPE TY_FILE. TABLES
DYNPROTAB = IT_BDCDATA.
DATA : IT_BDCDATA TYPE TABLE OF BDCDATA, REFRESH IT_BDCDATA.
WA_BDCDATA TYPE BDCDATA. ENDLOOP.

CALL FUNCTION 'BDC_CLOSE_GROUP'.


CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:\Users\Hello\ FORM BDCDATA .

Desktop\CC.TXT' WA_BDCDATA-PROGRAM = 'ZTRAN10'.


FILETYPE = 'ASC' WA_BDCDATA-DYNPRO = '0100'.
WA_BDCDATA-DYNBEGIN = 'X'.
HAS_FIELD_SEPARATOR = 'T'
APPEND WA_BDCDATA TO IT_BDCDATA.
* CLEAR WA_BDCDATA.
TABLES
WA_BDCDATA-FNAM = 'WA_KNA1-KUNNR'.
DATA_TAB = IT_FILE . WA_BDCDATA-FVAL = WA_FILE-CNO.
APPEND WA_BDCDATA TO IT_BDCDATA.
IF SY-SUBRC <> 0. CLEAR WA_BDCDATA.
WRITE :/ 'FILE NOT UPLOADED'. WA_BDCDATA-FNAM = 'WA_KNA1-NAME1'.
ELSE. WA_BDCDATA-FVAL = WA_FILE-CNAME.
WRITE :/ 'FILE UPLOADED'. APPEND WA_BDCDATA TO IT_BDCDATA.
CLEAR WA_BDCDATA.
ENDIF.
ENDFORM.
Call transaction method
 session method is 2 step procedure but call transaction does both the steps
online right one after another.

 CALL TRANSACTION <T.CODE> USING <BDCDATA> MODE


<A/N/E> UPDATE <S/A> MESSAGES INTO <MSG.TAB>.

 MSG.TAB is created by using structure BDCMSGCOLL.

 BDCMSGCOLL is for error handling.


LOOP AT IT_FILE INTO WA_FILE.
PERFORM BDCDATA.

CALL TRANSACTION 'ZTT10' USING IT_BDCDATA MODE 'A' UPDATE


'S'.
 TYPES : BEGIN OF TY_FILE,
CNO(10) TYPE C, REFRESH IT_BDCDATA.
CNAME(20) TYPE C, ENDLOOP.
END OF TY_FILE.

DATA : IT_FILE TYPE TABLE OF TY_FILE, *&---------------------------------------------------------------------*


WA_FILE TYPE TY_FILE. *& Form BDCDATA
*&---------------------------------------------------------------------*
DATA : IT_BDCDATA TYPE TABLE OF BDCDATA, * text
WA_BDCDATA TYPE BDCDATA. *----------------------------------------------------------------------*
* --> p1 text
CALL FUNCTION 'GUI_UPLOAD' * <-- p2 text
EXPORTING *----------------------------------------------------------------------*
FILENAME = 'C:\Users\Hello\Desktop\CC.TXT' FORM BDCDATA .
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'T' WA_BDCDATA-PROGRAM = 'ZTRAN10'.
* WA_BDCDATA-DYNPRO = '0100'.
TABLES WA_BDCDATA-DYNBEGIN = 'X'.
DATA_TAB = IT_FILE . APPEND WA_BDCDATA TO IT_BDCDATA.
CLEAR WA_BDCDATA.
IF SY-SUBRC <> 0.
WRITE :/ 'FILE NOT UPLOADED'. WA_BDCDATA-FNAM = 'WA_KNA1-KUNNR'.
ELSE. WA_BDCDATA-FVAL = WA_FILE-CNO.
WRITE :/ 'FILE UPLOADED'. APPEND WA_BDCDATA TO IT_BDCDATA.
ENDIF. CLEAR WA_BDCDATA.

WA_BDCDATA-FNAM = 'WA_KNA1-NAME1'.
WA_BDCDATA-FVAL = WA_FILE-CNAME.
APPEND WA_BDCDATA TO IT_BDCDATA.
CLEAR WA_BDCDATA.

ENDFORM.
 MODE :

 A--All screens
 N--No screens
 E--Error screens

 UPDATE :

 A--Async
 S--Sync
Diff d/w call transaction and session method

 Session method:

 1.It can process any number of transactions at a time.


 2.In this error log(file) is generated to handle errors.
 3.It is slower
 4.After processing session through ‘’SM35’ the DB get
updated .
 5.It is suitable the flat file contains the huge amount of data.
 6. Background scheduling is possible in session method.
 7.It is synchronous Database update
 Call transaction:
 1.It can process only one transaction at a time.
 2.In this we handle errors manually.
 3.It is faster
 4.can update the database immediately
 5.It is suitable if the flat file contains less amount of

data.
 6.Background scheduling is not possible in call

transaction.
 7.It is synchronous / asynchronous Database update
Recording method
 This is an advanced method to run BDC.

 TCODE: SHDB

 We can run recording in session as well as in call


transaction methods
 report ZRECORD9
no standard page heading line-size 255.

include bdcrecx1.
DATA : BEGIN OF LINE,
parameters: dataset(132) lower case. STR(60),
*** DO NOT CHANGE - the generated data section - DO NOT CHAN END OF LINE.
GE ***
* DATA : IT_LINE TYPE TABLE OF LINE ,
*** Generated data section with specific formatting - DO NOT CHANGE WA_LINE TYPE LINE.
***
data: begin of record, *** End generated data section ***
* data element: MATNR
MATNR_001(018), start-of-selection.
* data element: MBRSH
MBRSH_002(001), CALL FUNCTION 'GUI_UPLOAD'
* data element: MTART EXPORTING
MTART_003(004), FILENAME = 'C:\Users\Hello\Desktop\MM01.TXT'
* data element: XFELD FILETYPE = 'ASC'
KZSEL_01_004(001),
* data element: XFELD TABLES
KZSEL_02_005(001), DATA_TAB = IT_LINE.
* data element: MAKTX
MAKTX_006(040),
* data element: MEINS LOOP AT IT_LINE INTO LINE.
MEINS_007(003), SPLIT LINE-STR AT ',' INTO RECORD-MATNR_001 RECORD-MBRSH_002 RECORD-
* data element: MTPOS_MARA MTART_003 RECORD-KZSEL_01_004
MTPOS_MARA_008(004), RECORD-KZSEL_02_005 RECORD-MAKTX_006 RECORD-MEINS_007 RECORD-
* data element: MAKTX MTPOS_MARA_008 RECORD-MAKTX_009.
MAKTX_009(040), ENDLOOP.
end of record.

DATA : IT_RECORD TYPE TABLE OF RECORD,


WA_RECORD TYPE RECORD.

*perform open_dataset using dataset.


perform open_group. perform bdc_field using 'MAKT-MAKTX'
record-MAKTX_006.
*do. perform bdc_field using 'BDC_CURSOR'
'MARA-MEINS'.
*read dataset dataset into record. perform bdc_field using 'MARA-MEINS'
if sy-subrc <> 0. exit. endif. record-MEINS_007.
LOOP AT IT_LINE INTO WA_LINE. perform bdc_field using 'MARA-MTPOS_MARA'
perform bdc_dynpro using 'SAPLMGMM' '0060'. record-MTPOS_MARA_008.
perform bdc_field using 'BDC_CURSOR' perform bdc_dynpro using 'SAPLMGMM' '4004'.
'RMMG1-MATNR'. perform bdc_field using 'BDC_OKCODE'
perform bdc_field using 'BDC_OKCODE' '/00'.
'=AUSW'. perform bdc_field using 'BDC_CURSOR'
perform bdc_field using 'RMMG1-MATNR' 'MAKT-MAKTX'.
record-MATNR_001. perform bdc_field using 'MAKT-MAKTX'
perform bdc_field using 'RMMG1-MBRSH' record-MAKTX_009.
record-MBRSH_002. perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'RMMG1-MTART' perform bdc_field using 'BDC_OKCODE'
record-MTART_003. '=YES'.
perform bdc_dynpro using 'SAPLMGMM' '0070'. perform bdc_transaction using 'MM01'.
perform bdc_field using 'BDC_CURSOR'
'MSICHTAUSW-DYTXT(02)'. *enddo.
perform bdc_field using 'BDC_OKCODE' REFRESH IT_LINE.
'=ENTR'. ENDLOOP.
perform bdc_field using 'MSICHTAUSW-KZSEL(01)'
record-KZSEL_01_004. perform close_group.
perform bdc_field using 'MSICHTAUSW-KZSEL(02)' *perform close_dataset using dataset.
record-KZSEL_02_005.
perform bdc_dynpro using 'SAPLMGMM' '4004'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
Error handling in Call transaction
method
 FORMAT_MESSAGE is the function module used to handle
the errors.

The input for the above fm is,


1.message id
2.message number
3.language
4.message1
5.message2
6.message3
7. message4
 The call transaction method pass the success or failure
information into bdcmsgcoll internal table.
Some of the fields in bdcmsgcoll internal table.
Msgid  messageid
Msgno  message no
Msgv1 message 1
Msgv2  message 2
Msgv3  message 3
Msgv4  message 4
 the bdc program the error are download into text file .

 based on the errors the end user once again prepare the
flat file and upload the data until no error downloaded.

You might also like