2007 Jul 11 8:35 AM
2007 Jul 11 8:51 AM
HI Raviteja
Syntax for C.T: call transaction 'TCODE' using BDCDATA mode 'A/E/N' update 'S/A/L' .
In session Method, We have Three function modules.
bdc_open_group,
bdc_insert,
bdc_clode_group. We have to pass parameters to this function modules
Thanks
Saradhi
2007 Jul 11 8:54 AM
SESSION METHOD
- It is one of the BDC techniques for uploading legacy data into SAP
- The data is transferring from the internal table to database table
through sessions.
- Data along with its action is stored in session.
- When the program has finished generating the session, you can run
the session to execute the transaction.
- Unless session is processed, the data is not transferred to
database tables.
- The following Function Modules are used in the session method.
1. BDC_OPEN_GROUP (Used to create the session)
Import Parameters :
USER - User Name
CLIENT - Client
GROUP - Name of the session
HOLD - The date when you want to process the session
KEEP - X retain session even after processing it
' ' - Delete the session after processing.
2. BDC_INSERT (Data is transferred to session)
Import Parameters :
TCODE - Transaction code
DYNPROTAB BDCDATA table
3. BDC_CLOSE_GROUP (Used to close a session)
- Processing Steps
1. Generate the batch input session using function module
BDC_OPEN_GROUP.
2. The proceed as follows for each transaction that the session
contains:
a. In the BDCDATA structure, enter the value for all screens
and fields that must be processed in the transaction.
b. Use BDC_INSERT to transfer the transaction and the BDCDATA
structure to the session.
3. Close the batch input session with BDC_CLOSE_GROUP.
4. Start to process the generated session in T.Code SM35.
WT IS CALL TRANSACTION METHOD? WT IS SYNTAX/PROCEDURE?
CALL TRANSACTION :
1. It is compatible for small amount of data only.
2. It process the data Synchronously. i.e., The data is updated
at the time of execution.
3. It updates data both Synchronously and Asynchronously. When
we use Synchronous mode, it always verify all the data updated
successfully in the database.
When we use Asynchronous mode, the system can not wait till
all the data updated in the database.
4. It can handle only one application at a time.
5. It does not have Log file, we need to design logfile explicitly
using BDCMSGCOLL stucture.
Syntax :
CALL TRANSACTION <T.Code> USING <BDCTAB> MODE <A/N/E> UPDATE <S/A>
MESSAGES INTO <BDCMSGCOLL Int.Table>
Parameter 1 : Transaction Code
Parameter 2 : It is name of BDCDATA table.
Parameter 3 : Specifying Mode in which you execute transaction.
A - All screen mode. All the screen of transaction
are displayed.
N - No screen mode. No screen is displayed when you
execute the transaction.
E - Error screen. Only those screens are displayed
where you have error record.
Parameter 4 : Specifying Update type by which data base table is
updated.
S - It is for Synchronous update in which if you
change data for one table then all the relacted
tables gets updated. And then sy-subrc is returned
i.e., sy-subrc is returned for once and all.
A - It is for Asynchronous update, when you change
data of one table, the sy-subrc is returned. And
then updation of other affected tables takes place
If system fails to update other tables still
sy-subrc returned is 0.
Parameter 5 : When you update database table, operation is either
successful or unsuccessful or operation is successful
with some warning. These messages are stored in
internal table which you specify along with MESSAGE
statement. This internal table should be declared like
BDCMSGCOLL structure.
Steps for CALL TRANSACTION Method :
1. Interanal table for the data (structure similler to local file)
2. BDCTAB like BDCDATA.
3. Use UPLOAD/WS_UPLOAD/GUI_UPLOAD or DATASETS for upload data from
local file to internal table (i.e. ITAB).
4. LOOP at Itab.
Populate BDCTAB table.
CALL TRANSACTION <T.Code> USING <BDCTAB> MODE <A/N/E>
UPDATE <S/A> MESSAGES INTO <BDCMSGCOLL Int.Table>
Refresh BDCTAB.
ENDLOOP.
Please rewards point ....if you feel that answer is satisfying....
regards...
Abhay.
2007 Jul 11 8:59 AM
Check oout this sample program ...
REPORT ztest_report
NO STANDARD PAGE HEADING
LINE-SIZE 255
MESSAGE-ID ZRASH.
************************************************************************
* Internal Table Declarations *
************************************************************************
*--Internal Table for Data Uploading.
DATA : BEGIN OF IT_FFCUST OCCURS 0,
KUNNR(10),
BUKRS(4),
KTOKD(4),
ANRED(15),
NAME1(35),
SORTL(10),
STRAS(35),
ORT01(35),
PSTLZ(10),
LAND1(3),
SPRAS(2),
AKONT(10),
END OF IT_FFCUST.
*--Internal Table to Store Error Records.
DATA : BEGIN OF IT_ERRCUST OCCURS 0,
KUNNR(10),
EMSG(255),
END OF IT_ERRCUST.
*--Internal Table to Store Successful Records.
DATA : BEGIN OF IT_SUCCUST OCCURS 0,
KUNNR(10),
SMSG(255),
END OF IT_SUCCUST.
*--Internal Table for Storing the BDC data.
DATA : IT_CUSTBDC LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
*--Internal Table for storing the messages.
DATA : IT_CUSTMSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
DATA : V_FLAG1(1) VALUE ' ',
"Flag used for opening session.
V_TLINES LIKE SY-TABIX,
"For storing total records processed.
V_ELINES LIKE SY-TABIX,
"For storing the no of error records.
V_SLINES LIKE SY-TABIX.
"For storing the no of success records.
************************************************************************
* Selection screen *
************************************************************************
SELECTION-SCREEN BEGIN OF BLOCK B1.
PARAMETERS : V_FNAME LIKE RLGRAP-FILENAME,
V_SESNAM LIKE RLGRAP-FILENAME.
SELECTION-SCREEN END OF BLOCK B1.
************************************************************************
* Start-of-selection *
************************************************************************
START-OF-SELECTION.
*-- Form to upload flatfile data into the internal table.
PERFORM FORM_UPLOADFF.
************************************************************************
* TOP-OF-PAGE *
************************************************************************
TOP-OF-PAGE.
WRITE:/ 'Details of the error and success records for the transaction'
.
ULINE.
SKIP.
************************************************************************
* End of Selection *
************************************************************************
END-OF-SELECTION.
*-- Form to Generate a BDC from the Uploaded Internal table
PERFORM FORM_BDCGENERATE.
*--To write the totals and the session name.
PERFORM FORM_WRITEOP.
*&---------------------------------------------------------------------*
*& Form form_uploadff
*&---------------------------------------------------------------------*
* Form to upload flatfile data into the internal table.
*----------------------------------------------------------------------*
FORM FORM_UPLOADFF .
*--Variable to change the type of the parameter file name.
DATA : LV_FILE TYPE STRING.
LV_FILE = V_FNAME.
*--Function to upload the flat file to the internal table.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = LV_FILE
* FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
* HEADER_LENGTH = 0
* READ_BY_LINE = 'X'
* DAT_MODE = ' '
* IMPORTING
* FILELENGTH =
* HEADER =
TABLES
DATA_TAB = IT_FFCUST
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.
*--Deleting the headings from the internal table.
DELETE IT_FFCUST INDEX 1.
*--Getting the total number of records uploaded.
DESCRIBE TABLE IT_FFCUST LINES V_TLINES.
ENDIF.
ENDFORM. " form_uploadff
*&---------------------------------------------------------------------*
*& Form Form_bdcgenerate
*&---------------------------------------------------------------------*
* Form to Generate a BDC from the Uploaded Internal table
*----------------------------------------------------------------------*
FORM FORM_BDCGENERATE .
*--Generating the BDC table for the fields of the internal table.
LOOP AT IT_FFCUST.
PERFORM POPULATEBDC USING :
'X' 'SAPMF02D' '0105',
' ' 'BDC_OKCODE' '/00' ,
' ' 'RF02D-KUNNR' IT_FFCUST-KUNNR,
' ' 'RF02D-BUKRS' IT_FFCUST-BUKRS,
' ' 'RF02D-KTOKD' IT_FFCUST-KTOKD,
'X' 'SAPMF02D' '0110' ,
' ' 'BDC_OKCODE' '/00',
' ' 'KNA1-ANRED' IT_FFCUST-ANRED,
' ' 'KNA1-NAME1' IT_FFCUST-NAME1,
' ' 'KNA1-SORTL' IT_FFCUST-SORTL,
' ' 'KNA1-STRAS' IT_FFCUST-STRAS,
' ' 'KNA1-ORT01' IT_FFCUST-ORT01,
' ' 'KNA1-PSTLZ' IT_FFCUST-PSTLZ,
' ' 'KNA1-LAND1' IT_FFCUST-LAND1,
' ' 'KNA1-SPRAS' IT_FFCUST-SPRAS,
'X' 'SAPMFO2D' '0120',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0125',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0130',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0340',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0360',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPMF02D' '0210',
' ' 'KNB1-AKONT' IT_FFCUST-AKONT,
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0215',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0220',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02D' '0230',
' ' 'BDC_OKCODE' '=UPDA'.
*--Calling the transaction 'fd01'.
CALL TRANSACTION 'FD01' USING IT_CUSTBDC MODE 'N' UPDATE 'S'
MESSAGES INTO IT_CUSTMSG.
IF SY-SUBRC <> 0.
*--Populating the error records internal table.
IT_ERRCUST-KUNNR = IT_FFCUST-KUNNR.
APPEND IT_ERRCUST.
CLEAR IT_ERRCUST.
*--Opening a session if there is an error record.
IF V_FLAG1 = ' '.
PERFORM FORM_OPENSESSION.
V_FLAG1 = 'X'.
ENDIF.
*--Inserting the error records into already open session.
IF V_FLAG1 = 'X'.
PERFORM FORM_INSERT.
ENDIF.
*--Populating the Success records internal table.
ELSE.
IT_SUCCUST-KUNNR = IT_FFCUST-KUNNR.
APPEND IT_SUCCUST.
CLEAR IT_SUCCUST.
ENDIF.
*--Displaying the messages.
IF NOT IT_CUSTMSG[] IS INITIAL.
PERFORM FORM_FORMATMSG.
ENDIF.
*--Clearing the message and bdc tables.
CLEAR : IT_CUSTBDC[],IT_CUSTMSG[].
ENDLOOP.
*--Getting the total no of error records.
DESCRIBE TABLE IT_ERRCUST LINES V_ELINES.
*--Getting the total no of successful records.
DESCRIBE TABLE IT_SUCCUST LINES V_SLINES.
*--Closing the session only if it is open.
IF V_FLAG1 = 'X'.
PERFORM FORM_CLOSESESS.
ENDIF.
ENDFORM. " Form_bdcgenerate
*&---------------------------------------------------------------------*
*& Form populatebdc
*&---------------------------------------------------------------------*
* FOrm to Populate the BDC table.
*----------------------------------------------------------------------*
FORM POPULATEBDC USING VALUE(P_0178)
VALUE(P_0179)
VALUE(P_0180).
IF P_0178 = 'X'.
IT_CUSTBDC-PROGRAM = P_0179.
IT_CUSTBDC-DYNPRO = P_0180.
IT_CUSTBDC-DYNBEGIN = 'X'.
ELSE.
IT_CUSTBDC-FNAM = P_0179.
IT_CUSTBDC-FVAL = P_0180.
ENDIF.
APPEND IT_CUSTBDC.
CLEAR IT_CUSTBDC.
ENDFORM. " populatebdc
*&---------------------------------------------------------------------*
*& Form FORM_OPENSESSION
*&---------------------------------------------------------------------*
* Form to Open a session.
*----------------------------------------------------------------------*
FORM FORM_OPENSESSION .
*--Variable to convert the given session name into reqd type.
DATA : LV_SESNAM(12).
LV_SESNAM = V_SESNAM.
*--Opening a session.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
CLIENT = SY-MANDT
GROUP = LV_SESNAM
HOLDDATE = '20040805'
KEEP = 'X'
USER = SY-UNAME
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.
WRITE 😕 'Session not open'.
ENDIF.
ENDFORM. " FORM_OPENSESSION
*&---------------------------------------------------------------------*
*& Form FORM_INSERT
*&---------------------------------------------------------------------*
* fORM TO INSERT ERROR RECOED INTO A SESSION.
*----------------------------------------------------------------------*
FORM FORM_INSERT .
*--Inserting the record into session.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
TCODE = 'FD01'
* POST_LOCAL = NOVBLOCAL
* PRINTING = NOPRINT
* SIMUBATCH = ' '
* CTUPARAMS = ' '
TABLES
DYNPROTAB = IT_CUSTBDC
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.
WRITE 😕 'Unable to insert the record'.
ENDIF.
ENDFORM. " FORM_INSERT
*&---------------------------------------------------------------------*
*& Form FORM_CLOSESESS
*&---------------------------------------------------------------------*
* Form to Close the Open Session.
*----------------------------------------------------------------------*
FORM FORM_CLOSESESS .
CALL FUNCTION 'BDC_CLOSE_GROUP'
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
ENDIF.
ENDFORM. " FORM_CLOSESESS
*&---------------------------------------------------------------------*
*& Form FORM_FORMATMSG
*&---------------------------------------------------------------------*
* Form to format messages.
*----------------------------------------------------------------------*
FORM FORM_FORMATMSG .
*--Var to store the formatted msg.
DATA : LV_MSG(255).
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = SY-LANGU
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = LV_MSG
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
IF SY-SUBRC = 0.
WRITE 😕 LV_MSG.
ENDIF.
ULINE.
ENDFORM. " FORM_FORMATMSG
*&---------------------------------------------------------------------*
*& Form form_writeop
*&---------------------------------------------------------------------*
* To write the totals and the session name.
*----------------------------------------------------------------------*
FORM FORM_WRITEOP .
WRITE 😕 'Total Records Uploaded :',V_TLINES,
/ 'No of Error Records :',V_ELINES,
/ 'No of Success Records :',V_SLINES,
/ 'Name of the Session :',V_SESNAM.
ULINE.
ENDFORM. " form_writeop
2007 Jul 11 4:49 PM
hi,
<b>CALL TRANSACTION:</b>
<b>syntax:</b>
CALL TRANSACTION < name > USING <bdcdata>
MODE <a/n/e>
UPDATE <s/a/l>
MESSAGES INTO <bdcmsgcoll>.
we can process CALL TRANSACTION in three different modes...
A----> display all screens.( user interaction is required)
N----> no display all. ( no useraction is required)
E-----> error display all. ( user action is required only when error record occurs)
we can update data in three modes.
L----->local updation. (obsolete)
S----> synchronous.
A----> asynchronous.
in call transaction we can explicitly provide the logic for handling error record for that we create a table of type BDCMSGCOLL.
in the above syntax we pass error records into bdcmsgcoll tables using MESSAGES INTO statement.
<b>SESSION</b>:
in session metho we use few function modules..
<b>BDC_OPEN_GROUP</b>
Use the BDC_OPEN_GROUP function module to create a new session.
CALL FUNCTION 'BDC_OPEN_GROUP'
exporting
client = < client> "sy-mandt
group = < session name>
user = <user name> "sy-uname
CLIENT
Client in which the session is to be processed.
GROUP
Name of the session that is to be created. May be up to 12 characters long.
USER
Authorizations user for background processing
<b>BDC_INSERT</b>
Use the BDC_INSERT function module to add a transaction to a batch input session. You specify the transaction that is to be started in the call to BDC_INSERT. You must provide a BDCDATA structure that contains all of the data required to process the transaction completely.
CALL FUNCTION 'BDC_INSERT'
exporting
tcode = <transaction name>
tables
dynprotab = <bdcdata>
TCODE
The code of the transaction that is to be run.
DYNPROTAB
The BDCDATA structure that contains the data that is to be processed by the transaction.
<b>BDC_CLOSE_GROUP</b>
Use the BDC_CLOSE_GROUP function module to close a session after you have inserted all of your batch input data into it. Once a session is closed, it can be processed.
BDC_CLOSE_GROUP needs no parameters. It automatically closes the session that is currently open in your program.
regards,
Ashok Reddy