2008 Feb 28 4:46 AM
hi,
plz tell the step-wise procedure to create the bdc program using transaction method with simple example.
regards
surender
hi,
plz tell the step-wise procedure to create the bdc program using transaction method with simple example.
regards
surender
2008 Feb 28 4:53 AM
hi,
refer to the following example
TABLES: EORD.
PARAMETERS : p_file TYPE rlgrap-filename.
TYPES: BEGIN OF ty_itab,
matnr TYPE matnr,
werks TYPE werks,
vdatu TYPE EORD-vdatu,
bdatu TYPE bdatu,
lifnr TYPE lifnr,
ekorg TYPE ekorg,
END OF ty_itab.
TYPES : BEGIN OF ty_file,
file(200) TYPE c,
END OF ty_file.
TYPES : BEGIN OF ty_success,
text(250) TYPE c,
END OF ty_success.
TYPES : tt_file TYPE STANDARD TABLE OF ty_file,
tt_success TYPE STANDARD TABLE OF ty_success,
tt_itab TYPE STANDARD TABLE OF ty_itab.
DATA : it_file TYPE tt_file,
itab TYPE tt_itab,
it_success TYPE tt_success,
wa_success TYPE ty_success,
wa_file TYPE ty_file,
wa_itab TYPE ty_itab,
g_open TYPE c.
**********************************BDC DECLARATIONS******************
TYPES :tt_bdcdata TYPE STANDARD TABLE OF bdcdata, " table type for the bdcdata
tt_bdcmess TYPE STANDARD TABLE OF bdcmsgcoll. " table type for the BDC Messages
DATA : it_bdcdata TYPE tt_bdcdata,
it_bdcmess TYPE tt_bdcmess,
it_bdcmess1 TYPE tt_bdcmess,
wa_bdcdata TYPE bdcdata,
wa_bdcmess TYPE bdcmsgcoll,
wa_bdcmess1 TYPE bdcmsgcoll.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
PERFORM get_f4 CHANGING p_file.
AT SELECTION-SCREEN.
IF P_FILE IS NOT INITIAL.
PERFORM validate_file USING p_file.
ELSE.
MESSAGE I001(0) WITH' Please enter file name'.
ENDIF.
START-OF-SELECTION.
PERFORM upload_file USING p_file.
PERFORM get_data USING it_file
CHANGING itab.
PERFORM bdc_transaction.
*include bdcrecx1.
END-OF-SELECTION.
PERFORM write_messages.
----
Start new screen *
----
FORM bdc_dynpro USING program dynpro.
CLEAR WA_bdcdata.
wa_bdcdata-program = program.
wa_bdcdata-dynpro = dynpro.
wa_bdcdata-dynbegin = 'X'.
APPEND WA_bdcdata TO IT_BDCDATA.
ENDFORM. "bdc_dynpro
----
Insert field *
----
FORM bdc_field USING fnam fval.
IF fval <> nodata.
CLEAR WA_bdcdata.
wa_bdcdata-fnam = fnam.
wa_bdcdata-fval = fval.
APPEND WA_bdcdata TO IT_BDCDATA.
ENDIF.
ENDFORM. "bdc_field
&----
*& Form GET_F4
&----
text
----
<--P_P_FILE text
----
FORM get_f4 CHANGING pv_file TYPE rlgrap-filename.
DATA : l_file TYPE ibipparms-path.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
FIELD_NAME = ' '
IMPORTING
file_name = l_file.
pv_file = l_file.
.
ENDFORM. " GET_F4
&----
*& Form VALIDATE_FILE
&----
text
----
-->P_P_FILE text
----
form VALIDATE_FILE using file type c.
DATA: l_result TYPE c ,
l_file(128) TYPE c ,
lv_dir TYPE i,
l_dir TYPE c.
CALL FUNCTION 'TMP_GUI_GET_FILE_EXIST'
EXPORTING
fname = file
IMPORTING
EXIST = l_result
ISDIR = l_dir
FILESIZE = lv_dir
EXCEPTIONS
FILEINFO_ERROR = 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.
IF l_result IS INITIAL.
MESSAGE e000(01) WITH ' file is not vaild'.
ENDIF.
endform. " VALIDATE_FILE
&----
*& Form UPLOAD_FILE
&----
text
----
-->P_P_FILE text
----
form UPLOAD_FILE using g_file TYPE rlgrap-filename.
DATA : lv_file TYPE string.
lv_file = g_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = lv_file
FILETYPE = 'ASC'
tables
data_tab = it_file
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.
endform. " UPLOAD_FILE
&----
*& Form GET_DATA
&----
text
----
-->P_IT_FILE text
<--P_IT_MARA text
----
form GET_DATA using l_file TYPE tt_file
changing l_itab TYPE tt_itab.
DATA : lwa_file TYPE ty_file,
lwa_itab TYPE ty_itab.
LOOP AT l_file INTO lwa_file.
lwa_itab-matnr = lwa_file+0(18).
lwa_itab-werks = lwa_file+18(4).
lwa_itab-vdatu = lwa_file+22(8).
lwa_itab-bdatu = lwa_file+30(8).
lwa_itab-lifnr = lwa_file+38(10).
lwa_itab-ekorg = lwa_file+48(4).
APPEND lwa_itab TO itab.
ENDLOOP.
endform. " GET_DATA
&----
*& Form BDC_TRANSACTION
&----
text
----
--> p1 text
<-- p2 text
----
form BDC_TRANSACTION .
LOOP AT itab INTO wa_itab.
PERFORM open_group.
PERFORM bdc_dynpro USING 'SAPLMEOR' '0200'.
PERFORM bdc_field USING 'BDC_CURSOR'
'EORD-MATNR'.
PERFORM bdc_field USING 'BDC_OKCODE'
'/00'.
PERFORM bdc_field USING 'EORD-MATNR'
wa_itab-matnr.
PERFORM bdc_field USING 'EORD-WERKS'
wa_itab-werks.
PERFORM bdc_dynpro USING 'SAPLMEOR' '0205'.
PERFORM bdc_field USING 'BDC_CURSOR'
'EORD-EKORG(02)'.
PERFORM bdc_field USING 'BDC_OKCODE'
'=BU'.
PERFORM bdc_field USING 'EORD-VDATU(02)'
wa_itab-vdatu.
PERFORM bdc_field USING 'EORD-BDATU(02)'
wa_itab-bdatu.
PERFORM bdc_field USING 'EORD-LIFNR(02)'
wa_itab-lifnr.
PERFORM bdc_field USING 'EORD-EKORG(02)'
wa_itab-ekorg.
PERFORM bdc_transaction USING 'ME01'.
*
PERFORM close_group.
call transaction 'ME01' using it_bdcdata
mode 'A'
update 'S'
messages into it_bdcmesS.
perform get_messages.
refresh :it_bdcdata,
it_bdcmess.
CLEAR : wa_ITAB, wa_bdcdata, wa_bdcmess.
endloop.
endform. " BDC_TRANSACTION
&----
*& Form GET_MESSAGES
&----
text
----
--> p1 text
<-- p2 text
----
form GET_MESSAGES .
DATA : lwa_messages TYPE char480.
LOOP AT it_bdcmess INTO wa_bdcmess WHERE msgtyp = 'S'.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = WA_BDCMESS-MSGID
LANG = '-D'
NO = WA_BDCMESS-MSGNR
V1 = WA_BDCMESS-MSGV1
V2 = WA_BDCMESS-MSGV2
V3 = WA_BDCMESS-MSGV3
V4 = WA_BDCMESS-MSGV4
IMPORTING
MSG = LWA_MESSAGES
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.
wa_success-text = lwa_messages.
APPEND wa_success TO it_success.
CLEAR wa_bdcmess.
ENDLOOP.
endform. " GET_MESSAGES
&----
*& Form WRITE_MESSAGES
&----
text
----
--> p1 text
<-- p2 text
----
form WRITE_MESSAGES .
LOOP AT it_success INTO wa_success.
WRITE : / wa_success-text.
ENDLOOP.
endform. " WRITE_MESSAGES
regards,
sreelakshmi.
2008 Feb 28 4:58 AM
hi,
This is a simple step by step procrdure, follow this,
BDC CALL TRANSACTION METHOD:
-
Since we cannot modify the error record using direct input method, we go for call transaction method. Here, we create a screen to populate error records in input fields and from the screen, we can modify the error records and then insert into database table.
Steps to be followed in Call Transaction MEthod:
-
1. Analyze the flat file.
2. Create a screen for database table fields using MPP. Create a Transaction code for the screen.
3. Write the following code in SE38 editor:
DATA : BEGIN OF ITAB OCCURS 0,
STR(255),
END OF ITAB.
CALL FUNCTION 'UPLOAD'
EXPORTING
FILENAME = 'C:\KNA.TXT'
FILETYPE = 'ASC'
TABLES
DATA_TAB = ITAB.
DATA ITAB1 LIKE KNA1 OCCURS 0 WITH HEADER LINE.
DATA JTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
LOOP AT ITAB.
SPLIT ITAB-STR AT ',' INTO ITAB1-KUNNR ITAB1-NAME1 ITAB1-ORT01
ITAB1-LAND1.
APPEND ITAB1.
ENDLOOP.
LOOP AT ITAB1.
PERFORM PROGINFO USING 'SAPMZCALLTRANSACTION' '100'.
PERFORM FLDINFO USING 'KARTHIK-KUNNR' ITAB1-KUNNR.
PERFORM FLDINFO USING 'KARTHIK-NAME1' ITAB1-NAME1.
PERFORM FLDINFO USING 'KARTHIK-ORT01' ITAB1-ORT01.
PERFORM FLDINFO USING 'KARTHIK-LAND1' ITAB1-LAND1.
CALL TRANSACTION 'ZCALLTRANS' USING JTAB.
ENDLOOP.
FORM PROGINFO USING PROGNAME SCRNUM.
CLEAR JTAB.
REFRESH JTAB.
JTAB-PROGRAM = PROGNAME.
JTAB-DYNPRO = SCRNUM.
JTAB-DYNBEGIN = 'X'.
APPEND JTAB.
ENDFORM.
FORM FLDINFO USING FLDNAME FLDVALUE.
CLEAR JTAB.
JTAB-FNAM = FLDNAME.
JTAB-FVAL = FLDVALUE.
APPEND JTAB.
ENDFORM.
Save -> Activate -> Execute.
In the above code,
BDCDATA is a structure used to populate the internal table records into the screen fields. The BDCDATA structure has following components:
PROGRAM - Holds the name of MPP program where the screen is created.
DYNPRO - Holds the screen number where the internal fields to be populated.
DYNBEGIN - Used to initiate the screen when the program is executed. The default value to be specified is 'X'.
FNAM - Specifies input field name in the screen where the data is to be populated.
FVAL - Specifies from which internal table field, the data should be passed to the screen field.
'CALL TRANSACTION' statement is used to call the screen created to populate error records.
SYNTAX:
-
CALL TRANSACTION <Tcode> USING <BDCDATA_itab> MODE <mode> UPDATE <update>.
MODE: This is used to specify which mode to be followed when calling transaction. The types of mode are:
A - Display the screen.
E - Display only error records from the flat file.
N - Background processing.
UPDATE: This is used to specify the update task of records in the database table. The types of update tasks are:
A - Asynchronous update
S - Synchronous update
L - Local update
Advantages of CALL TRANSACTION:
-
Error records can be modified.
This method can be used in support projects.
Hop this helps u.
Regards,
Arunsri
2008 Feb 28 8:55 AM
HAI,
WHEN I AM EXECUTE THIS PROGRAM, ONLY BDC MESSAGE INFORMATION SHOULD BE DISPLAYED. WHAT ABOUT INTERNAL TABLES RECORDS.?THEY CANNOT DEPICT IN THE SCREEN OF PARTICULAR TRANSACTION ' YSC6'.
REGARDS
SURENDER
2008 Feb 28 5:01 AM
Hi,
Call transaction is mainly used when you want to update the database using a single transaction , you can also update the database in asynchronous mode,
Steps for call Transaction method:
The first step is to identify the screens of the transaction that the program will process.
Next step is to write a program to build the BDC table that will be used to submit the data to SAP.
The final step is to submit the BDC table to the system in single transaction by the CALL TRANSACTION command.
Syntax: Call Transaction <tcode> using <I_BDCData
> mode 'N' / 'A' / 'E' Update Synchronous / Asynchronous.
Regards,
kavitha.
2008 Feb 28 5:03 AM
Hi,
BDC CALL TRANSACTION:
-
DATA : BEGIN OF ITAB OCCURS 0,
STR(255),
END OF ITAB.
DATA ITAB1 LIKE KNA1 OCCURS 0 WITH HEADER LINE.
DATA JTAB LIKE BDCDATA OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'UPLOAD'
EXPORTING
FILENAME = 'C:\KARTHIK.TXT'
FILETYPE = 'ASC'
TABLES
DATA_TAB = ITAB.
LOOP AT ITAB.
SPLIT ITAB-STR AT ',' INTO ITAB1-KUNNR ITAB1-NAME1 ITAB1-ORT01
ITAB1-LAND1.
APPEND ITAB1.
ENDLOOP.
LOOP AT ITAB1.
PERFORM PROGINFO USING 'SAPMYCALLTRANSACTION' '400'.
PERFORM FLDINFO USING 'WA-KUNNR' ITAB1-KUNNR.
PERFORM FLDINFO USING 'WA-NAME1' ITAB1-NAME1.
PERFORM FLDINFO USING 'WA-ORT01' ITAB1-ORT01.
PERFORM FLDINFO USING 'WA-LAND1' ITAB1-LAND1.
CALL TRANSACTION 'YCALLTRANS' USING JTAB.
ENDLOOP.
FORM PROGINFO USING PROGNAME SCRNUM.
CLEAR JTAB.
REFRESH JTAB.
JTAB-PROGRAM = PROGNAME.
JTAB-DYNPRO = SCRNUM.
JTAB-DYNBEGIN = 'X'.
APPEND JTAB.
ENDFORM.
FORM FLDINFO USING FLDNAME FLDVALUE.
CLEAR JTAB.
JTAB-FNAM = FLDNAME.
JTAB-FVAL = FLDVALUE.
APPEND JTAB.
ENDFORM.
CLEAR statement is used to delete the contents of the header line of internal table.
REFRESH statement is used to delete the contents of the body area of internal table.
FREE statement is used to delete the internal table after the program is closed.
DELETE statement is used to delete some particular contents of the internal table.
SYNTAX:
-
CALL TRANSACTION <Tcode> USING <bdcdata_itab> MODE <mode> UPDATE <task>.
Tcode is the name of the transaction code which contains screen to display error records.
bdcdata_itab is an internal table which is created for BDCDATA structure.
mode specifies the type of mode for processing. There are three types as follows:
A - Foreground processing
E - Errors only
N - Background processing
When 'N' is used, a predefined structure called BDCMSGCOLL should be used to collect the messages triggered during background processing.
Syntax:
DATA KTAB LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE.
CALL TRANSACTION 'YCALLTRANS' USING JTAB MODE 'N' MESSAGES INTO KTAB.
Update specifies the task of updating records into database table.
A - Asynchronous update - A return value is generated only after updating all the records in related tables.
S - Synchronous update - A return value is generated for each record updation in related tables inside the database.
Regards,
Priya.
2008 Feb 28 5:06 AM
Hi,
it may help u.
Code used to create BDC:
&----
*& Report ZBDC_EXAMPLE *
*& *
&----
*& Example BDC program, which updates net price of item 00010 of a *
*& particular Purchase order(EBELN). *
*& *
&----
REPORT ZBDC_EXAMPLE NO STANDARD PAGE HEADING
LINE-SIZE 132.
*----
Data declaration
TABLES: ekko, ekpo.
TYPES: BEGIN OF t_ekko,
ebeln TYPE ekko-ebeln,
waers TYPE ekko-waers,
netpr TYPE ekpo-netpr,
err_msg(73) TYPE c,
END OF t_ekko.
DATA: it_ekko TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_ekko TYPE t_ekko,
it_error TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_error TYPE t_ekko,
it_success TYPE STANDARD TABLE OF t_ekko INITIAL SIZE 0,
wa_success TYPE t_ekko.
DATA: w_textout LIKE t100-text.
DATA: gd_update TYPE i,
gd_lines TYPE i.
*Used to store BDC data
DATA: BEGIN OF bdc_tab OCCURS 0.
INCLUDE STRUCTURE bdcdata.
DATA: END OF bdc_tab.
*Used to stores error information from CALL TRANSACTION Function Module
DATA: BEGIN OF messtab OCCURS 0.
INCLUDE STRUCTURE bdcmsgcoll.
DATA: END OF messtab.
*----
*Screen declaration
SELECTION-SCREEN BEGIN OF BLOCK block1 WITH FRAME
TITLE text-001. "Purchase order Num
SELECT-OPTIONS: so_ebeln FOR ekko-ebeln OBLIGATORY.
SELECTION-SCREEN END OF BLOCK block1.
SELECTION-SCREEN BEGIN OF BLOCK block2 WITH FRAME
TITLE text-002. "New NETPR value
PARAMETERS: p_newpr(14) TYPE c obligatory. "LIKE ekpo-netpr.
SELECTION-SCREEN END OF BLOCK block2.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
Retrieve data from Purchase order table(EKKO)
SELECT ekkoebeln ekkowaers ekpo~netpr
INTO TABLE it_ekko
FROM ekko AS ekko INNER JOIN ekpo AS ekpo
ON ekpoebeln EQ ekkoebeln
WHERE ekko~ebeln IN so_ebeln AND
ekpo~ebelp EQ '10'.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
Check data has been retrieved ready for processing
DESCRIBE TABLE it_ekko LINES gd_lines.
IF gd_lines LE 0.
Display message if no data has been retrieved
MESSAGE i003(zp) WITH 'No Records Found'(001).
LEAVE TO SCREEN 0.
ELSE.
Update Customer master data (instalment text)
LOOP AT it_ekko INTO wa_ekko.
PERFORM bdc_update.
ENDLOOP.
Display message confirming number of records updated
IF gd_update GT 1.
MESSAGE i003(zp) WITH gd_update 'Records updated'(002).
ELSE.
MESSAGE i003(zp) WITH gd_update 'Record updated'(003).
ENDIF.
Display Success Report
**********************
Check Success table
DESCRIBE TABLE it_success LINES gd_lines.
IF gd_lines GT 0.
Display result report column headings
PERFORM display_column_headings.
Display result report
PERFORM display_report.
ENDIF.
Display Error Report
********************
Check errors table
DESCRIBE TABLE it_error LINES gd_lines.
If errors exist then display errors report
IF gd_lines GT 0.
Display errors report
PERFORM display_error_headings.
PERFORM display_error_report.
ENDIF.
ENDIF.
&----
*& Form DISPLAY_COLUMN_HEADINGS
&----
Display column headings
----
FORM display_column_headings.
WRITE:2 ' Success Report '(014) COLOR COL_POSITIVE.
SKIP.
WRITE:2 'The following records updated successfully:'(013).
WRITE:/ sy-uline(42).
FORMAT COLOR COL_HEADING.
WRITE:/ sy-vline,
(10) 'Purchase Order'(004), sy-vline,
(11) 'Old Netpr'(005), sy-vline,
(11) 'New Netpr'(006), sy-vline.
WRITE:/ sy-uline(42).
ENDFORM. " DISPLAY_COLUMN_HEADINGS
&----
*& Form BDC_UPDATE
&----
Populate BDC table and call transaction ME22
----
FORM bdc_update.
PERFORM dynpro USING:
'X' 'SAPMM06E' '0105',
' ' 'BDC_CURSOR' 'RM06E-BSTNR',
' ' 'RM06E-BSTNR' wa_ekko-ebeln,
' ' 'BDC_OKCODE' '/00', "OK code
'X' 'SAPMM06E' '0120',
' ' 'BDC_CURSOR' 'EKPO-NETPR(01)',
' ' 'EKPO-NETPR(01)' p_newpr,
' ' 'BDC_OKCODE' '=BU'. "OK code
Call transaction to update customer instalment text
CALL TRANSACTION 'ME22' USING bdc_tab MODE 'N' UPDATE 'S'
MESSAGES INTO messtab.
Check if update was succesful
IF sy-subrc EQ 0.
ADD 1 TO gd_update.
APPEND wa_ekko TO it_success.
ELSE.
Retrieve error messages displayed during BDC update
LOOP AT messtab WHERE msgtyp = 'E'.
Builds actual message based on info returned from Call transaction
CALL FUNCTION 'MESSAGE_TEXT_BUILD'
EXPORTING
msgid = messtab-msgid
msgnr = messtab-msgnr
msgv1 = messtab-msgv1
msgv2 = messtab-msgv2
msgv3 = messtab-msgv3
msgv4 = messtab-msgv4
IMPORTING
message_text_output = w_textout.
ENDLOOP.
Build error table ready for output
wa_error = wa_ekko.
wa_error-err_msg = w_textout.
APPEND wa_error TO it_error.
CLEAR: wa_error.
ENDIF.
Clear bdc date table
CLEAR: bdc_tab.
REFRESH: bdc_tab.
ENDFORM. " BDC_UPDATE
----
FORM DYNPRO *
----
stores values to bdc table *
----
--> DYNBEGIN *
--> NAME *
--> VALUE *
----
FORM dynpro USING dynbegin name value.
IF dynbegin = 'X'.
CLEAR bdc_tab.
MOVE: name TO bdc_tab-program,
value TO bdc_tab-dynpro,
'X' TO bdc_tab-dynbegin.
APPEND bdc_tab.
ELSE.
CLEAR bdc_tab.
MOVE: name TO bdc_tab-fnam,
value TO bdc_tab-fval.
APPEND bdc_tab.
ENDIF.
ENDFORM. " DYNPRO
&----
*& Form DISPLAY_REPORT
&----
Display Report
----
FORM display_report.
FORMAT COLOR COL_NORMAL.
Loop at data table
LOOP AT it_success INTO wa_success.
WRITE:/ sy-vline,
(10) wa_success-ebeln, sy-vline,
(11) wa_success-netpr CURRENCY wa_success-waers, sy-vline,
(11) p_newpr, sy-vline.
CLEAR: wa_success.
ENDLOOP.
WRITE:/ sy-uline(42).
REFRESH: it_success.
FORMAT COLOR COL_BACKGROUND.
ENDFORM. " DISPLAY_REPORT
&----
*& Form DISPLAY_ERROR_REPORT
&----
Display error report data
----
FORM display_error_report.
LOOP AT it_error INTO wa_error.
WRITE:/ sy-vline,
(10) wa_error-ebeln, sy-vline,
(11) wa_error-netpr CURRENCY wa_error-waers, sy-vline,
(73) wa_error-err_msg, sy-vline.
ENDLOOP.
WRITE:/ sy-uline(104).
REFRESH: it_error.
ENDFORM. " DISPLAY_ERROR_REPORT
&----
*& Form DISPLAY_ERROR_HEADINGS
&----
Display error report headings
----
FORM display_error_headings.
SKIP.
WRITE:2 ' Error Report '(007) COLOR COL_NEGATIVE.
SKIP.
WRITE:2 'The following records failed during update:'(008).
WRITE:/ sy-uline(104).
FORMAT COLOR COL_HEADING.
WRITE:/ sy-vline,
(10) 'Purchase Order'(009), sy-vline,
(11) 'Netpr'(010), sy-vline,
(73) 'Error Message'(012), sy-vline.
WRITE:/ sy-uline(104).
FORMAT COLOR COL_NORMAL.
ENDFORM. " DISPLAY_ERROR_HEADINGS
Cheers,
vasavi.
kindly reward if helpful.
2008 Feb 28 5:11 AM
Hi,
Call transaction is mainly used when you want to update the database using a single transaction , you can also update the database in asynchronous mode,
Steps for call Transaction method:
The first step is to identify the screens of the transaction that the program will process.
Next step is to write a program to build the BDC table that will be used to submit the data to SAP.
The final step is to submit the BDC table to the system in single transaction by the CALL TRANSACTION command.
i am sending you the sample program you have only change the itab . replace the recording .
eport ZBDC_ANU
no standard page heading line-size 255.
*include bdcrecx1.
*
*start-of-selection.
*
*perform open_group.
*==============================
DATA : L_INDEX TYPE I,
CTR TYPE I VALUE 0,
L_MSTRING(480).
DATA: bdcdata TYPE STANDARD TABLE OF bdcdata WITH HEADER LINE.
DATA: messtab TYPE STANDARD TABLE OF bdcmsgcoll WITH HEADER LINE.
DATA: BEGIN OF L_INTERN OCCURS 0.
INCLUDE STRUCTURE ALSMEX_TABLINE.
DATA: END OF L_INTERN.
types : begin of itab1 ,
vendor like RF02K-LIFNR ,
sortl like lfa1-sortl ,
end of itab1 .
DATA : ITAB TYPE STANDARD TABLE OF ITAB1 WITH HEADER LINE.
SELECTION-SCREEN BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
PARAMETERS: fILE LIKE RLGRAP-FILENAME
DEFAULT '' OBLIGATORY. " File Name
SELECTION-SCREEN END OF BLOCK B1.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR FILE.
CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
*EXPORTING
PROGRAM_NAME = SYST-REPID
DYNPRO_NUMBER = SYST-DYNNR
FIELD_NAME = ' '
STATIC = '.XLS '
MASK = ' '
CHANGING
file_name = FILE
EXCEPTIONS
MASK_TOO_LONG = 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.
start-of-selection.
PERFORM UPLOAD_FILE TABLES ITAB
USING FILE.
LOOP AT ITAB.
clear: bdcdata , bdcdata[].
*==============================
perform bdc_dynpro using 'SAPMF02K' '0106'.
perform bdc_field using 'BDC_CURSOR'
'RF02K-D0110'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02K-LIFNR'
itab-vendor.
perform bdc_field using 'RF02K-BUKRS'
'VRL'.
perform bdc_field using 'RF02K-D0110'
'X'.
perform bdc_dynpro using 'SAPMF02K' '0110'.
perform bdc_field using 'BDC_CURSOR'
itab-SORTL.
perform bdc_field using 'BDC_OKCODE'
'/00'.
***perform bdc_field using 'LFA1-NAME1'
'INNER MONGOLIA LINHE XINDU'.
***perform bdc_field using 'LFA1-SORTL'
'TEST'.
***perform bdc_field using 'LFA1-NAME2'
'ECONOMIC & TRADING LTD CO'.
***perform bdc_field using 'LFA1-ORT01'
'YIWU'.
***perform bdc_field using 'LFA1-PSTLZ'
'111111'.
***perform bdc_field using 'LFA1-LAND1'
'IN'.
***perform bdc_field using 'LFA1-REGIO'
'30'.
perform bdc_dynpro using 'SAPLSPO1' '0300'.
perform bdc_field using 'BDC_OKCODE'
'=YES'.
CALL TRANSACTION 'FK02' USING BDCDATA MODE 'A' MESSAGES INTO MESSTAB .
PERFORM TRAP_MESSAGES .
*perform bdc_transaction using 'FK02'.
endloop .
*perform close_group.
*====================================================
&----
FORM BDC_DYNPRO
&----
FORM BDC_DYNPRO USING PROGRAM DYNPRO.
CLEAR BDCDATA.
BDCDATA-PROGRAM = PROGRAM.
BDCDATA-DYNPRO = DYNPRO.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
ENDFORM.
&----
FORM BDC_FIELD
&----
FORM BDC_FIELD USING FNAM FVAL.
CLEAR BDCDATA.
BDCDATA-FNAM = FNAM.
BDCDATA-FVAL = FVAL.
APPEND BDCDATA.
ENDFORM.
&----
*& Form UPLOAD_FILE
&----
form UPLOAD_FILE tables p_it_tab
using p_file.
FIELD-SYMBOLS : <FS>.
CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = FILE
i_begin_col = '1'
i_begin_row = '2'
i_end_col = '256'
i_end_row = '10000'
tables
intern = L_INTERN
EXCEPTIONS
INCONSISTENT_PARAMETERS = 1
UPLOAD_OLE = 2
OTHERS = 3
.
IF sy-subrc NE 0.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE : / 'File Error'.
EXIT.
ENDIF.
IF L_INTERN[] IS INITIAL.
FORMAT COLOR COL_BACKGROUND INTENSIFIED.
WRITE : / 'No Data Uploaded'.
EXIT.
ELSE.
SORT L_INTERN BY ROW COL.
LOOP AT L_INTERN.
MOVE L_INTERN-COL TO L_INDEX.
ASSIGN COMPONENT L_INDEX OF STRUCTURE p_IT_TAB TO <FS>.
MOVE L_INTERN-VALUE TO <FS>.
AT END OF ROW.
APPEND p_IT_TAB.
CLEAR p_IT_TAB.
ENDAT.
ENDLOOP.
ENDIF.
endform.
&----
*& Form TRAP_MESSAGES
&----
form TRAP_MESSAGES .
data: line type i value 0.
ctr = ctr + 1.
describe table messtab lines line.
READ TABLE MESSTAB INDEX line.
IF MESSTAB-MSGTYP = 'S'.
CONCATENATE 'Document' MESSTAB-MSGV1 'posted' into L_MSTRING separated
by space.
WRITE:/5 CTR , L_MSTRING(150).
else.
CONCATENATE 'Document not posted. Field ' messtab-FLDNAME into
L_MSTRING separated by space.
WRITE:/5 CTR , L_MSTRING(150).
ENDIF.
clear: messtab , messtab[].
reward if helpfull
2008 Feb 28 5:20 AM
BDC is used to transfer data from SAP to SAP systems or from a non-SAP system to SAP system. It is used to transfer a large amount of data that is available in electronic form.
SAP offers two methods for Batch Data Communication:
(1)Classical Method:
In this method, the data that is read by the BDC program from a sequential data set file is stored in a batch input session. To run the transactions in this session, you need to execute the session.
This method uses the function modules BDC_OPEN_GROUP, BDC_INSERT and BDC_CLOSE_GROUP to generate the sessions. The important aspects of this method are:
Asynchronous processing
(ii) Transfers data for multiple transactions.
(iii) A batch input processing log is generated for each session.
(iv) Synchronous database update.ie: During processing, no transaction is started until the previous transaction has been written to the database
(v) Can transfer large amount of data.
The BDC_OPEN_GROUP function module is used to create a new session.
Once you have created a session, then you can insert batch input data into it with BDC_INSERT.
The BDC_INSERT function module is used 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. The code of the transaction to be run is provided in the TCODE export parameter.
The BDC_CLOSE_GROUP function module is used to close a session after you have inserted all of your batch input data into it. BDC_CLOSE_GROUP needs no parameters. It automatically closes the session that is currently open in your program.
CALL FUNCTION BDC_CLOSE_GROUP
EXCEPTIONS
NOT_OPEN = 1
QUEUE_ERROR = 2
Once a session is closed, it can be processed. This is done by using the transaction code SM35
The mode of execution of the session can be chosen by the user as background or foreground
Using ABAP Statement CALL TRANSACTION USING:
This method offers faster processing of data than the batch input sessions. In this method BDC uses the ABAP statement CALL TRANSACTION USING to run a transaction.BDC does not create a session in this method. The important aspects of this method are:
Synchronous processing
(ii) Transfers data for a single transaction.
(iii) No batch input processing log is generated. Errors need to be handled explicitly.
(iv) Both synchronous and asynchronous update of the database possible.The program specifies the update type.
(v) Transfer small amount of data.
Both the above methods needs a common data structure for storing the data and instructions for SAP transactions. This structure is defined in the directory as BDCDATA.
DATA: BEGIN OF <BDC Table> OCCURS <Occurs Parameter>.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF <BDC Table>.
This BDCDATA structure can contain data for one transaction at a time.
BDCDATA:
Field Name Type Length Description
PROGRAM char 8 BDC Module Pool
DYNPRO Numc 4 BDC DynPro number
DYNBEGIN char 1 BDC Starting a Dynpro
FNAM char 35 Field name
FVAL char 80 Field Value
To transfer the data from non-SAP to SAP system you will have to write an ABAP program that will export the data to a sequential data set file. The data in this file should be stored in a format acceptable to SAP batch input program.
To transfer data from an SAP system to another SAP system, RFC can be used.
The choice of the two methods for BDC depends on the situation:
Restarting capability and detailed logging are supported by the batch input management transactions in the classical method.Usually, we use session method in real time as we can transfer large amount of data from the internal table to the database.Moreover, if errors occur, processing will not proceed until the session is corrected.
CALL TRANSACTION USING offers faster processing if you want your batch input to be done in the time slot available. But however it offers less support for error recovery and management of batch input. Call transactions are good if it is needed to handle the return messages in the code and then act accordingly. Thus, if you create a sales order using call transaction method, and as soon as you get the success message with a sales order number, you want to do something else, then a call transaction is useful.
Advantages and Disadvantages of Classical Method:-
The advantage of Batch Input method is that you will have all the error messages and the data for each transaction held persistently.You dont have to code anything for processing them or writing the log.
But at the same time, the same feature can be disadvantageous if you need to react to an error or if there are too many errors to manually correct in a session. Since the sessions are created in the program and its execution is done separately, you loose the trackability of such transactions.
Advantages and Disadvantages of CALL TRANSACTION USING method:-
Call transaction immediately gives you messages back and you can react to it in your program. But the disadvantage is that, if you have several hundreds of transactions to run, running them from within the program can be resource crunching affair. It will hamper the system performance and you cannot really distribute the load.
The following section describes a sample BDC program. This program is used to enter the employee details which include the employee name and employee number into a database table.
The employee details (which include the employee name and employee number) of several employees are stored in a text file, emp.txt with the details separated by tab (character X).
A dialog program is written which accepts the employee name and employee number and then inserts them into the database table-ZEMP_DETAILS.This dialog module is executed with the transaction code ztrn1.
An internal table ITAB_EMP_DETAILS is created which has the same structure as the database table ZEMP_DETAILS.The employee data present in the text file, emp.txt is populated into the internal table ITAB_EMP_DETAILS by calling the function module GUI_UPLOAD .The file path is specified in the Filename Export parameter.
You can upload file from the presentation server (user's PC) or the application server. The Presentation Server (often called the client) is the one with which the user interacts. Application Servers contain the complete business process logic of R/3 applications. It is like an "execution environment" where one can run application code, typically involving the business logic for things like reports or batch processing.
If you are loading from presentation server use the function module GUI_UPLOAD.
(ii) If you are loading from application server:
OPEN DATASET
READ DATASET
CLOSE DATASET commands can be used.
(Eg OPEN DATASET dsn FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc <> 0.
EXIT.
ENDIF.
READ DATASET dsn INTO rec.
WHILE sy-subrc <> 0.
WRITE / rec. READ DATASET dsn INTO rec.
ENDWHILE.
CLOSE DATASET dsn.
Note that you can't use BDC in background mode if you are loading file from presentation server. So it is always recommended to load file from application server. The reasons to have a file in application server are:
Security- No one can change your file data
(ii) If it is available in presentation server we can not access in the network, if it is at application server, we can access it from any place.
1. A recording of the transaction ztrn1 is made using the transaction SM35.Save the recording
2. Then create a BDCDATA structure. Then fill the structure with data using the call transaction method. Build the structure line by line using MOVE and APPEND statements. Before building each line CLEAR the header line of the internal table.
The first record for each screen must contain information that identifies the screen: program name, screen name and Start of Screen Indicator. This information is recorded in the PROGRAM, DYNPRO and DYNBEGIN fields.
BDCDATA-PROGRAM = Z_TEST_BDC.
BDCDATA-DYNPRO = 0100.
BDCDATA-DYNBEGIN = 'X'.
APPEND BDCDATA.
Then the FNAM and FVAL fields have to be set .The FNAM field identifies the target field by its table and field names. FVAL specifies the value that is to be entered.
To position the cursor on a particular field you must use the special cursor field.
BDCDATA-FNAM = BDC_CURSOR.
BDCDATA-FVAL = EMPNO1.
APPEND BDCDATA.
The Command field is identified by a special name in batch input, BDC_OKCODE.This name is constant and always identifies the command field.
BDCDATA-FNAM = BDC_OKCODE.
BDCDATA-FVAL = OK1.
APPEND BDCDATA.
Some screen fields need multiple values one on each line. To provide values to one of these loop fields, an explicit line index should be used. This is shown in the below example.
BDCDATA-FNAM = fieldname (5).
BDCDATA-FVAL = value.
Similarly, to position the cursor on a loop field you must again use an index.
BDCDATA-FNAM = BDC_CURSOR.
BDCDATA-FVAL = fieldx (4).
REPORT ZTESTBDC. .
DATA: BEGIN OF G_BDCDATA OCCURS 100.
INCLUDE STRUCTURE BDCDATA.
DATA: END OF G_BDCDATA.
DATA: ITAB_EMP_DETAILS TYPE STANDARD TABLE OF ZEMP_DETAILS WITH HEADER LINE.
*Call the subroutine to upload the data into an internal table
PERFORM GUI_UPLOAD.
LOOP AT ITAB_EMP_DETAILS.
CLEAR G_BDCDATA.
Perform bdc_dynpro using 'ZTESTBDC' '0100'.
Perform bdc_field using 'BDC_CURSOR'
'EMPNAME1'.
Perform bdc_field using 'BDC_OKCODE'
'=OK1'.
Perform bdc_field using 'EMPNAME1'
ITAB_EMP_DETAILS-EMP_NAME.
Perform bdc_field using 'EMPNO1'
ITAB_EMP_DETAILS-EMP_NUMBER.
Perform bdc_dynpro using 'Z_TEST_BDC' '0100'.
Perform bdc_field using 'BDC_CURSOR'
'EMPNAME1'.
Perform bdc_field using 'BDC_OKCODE'
'=EXIT1'.
CALL TRANSACTION ZTRN1 USING G_BDCDATA MODE 'N'.
ENDLOOP.
&----
*& Form GUI_UPLOAD
This subroutine is used to upload the data from the text file into
an internal table
----
Form GUI_UPLOAD.
CALL FUNCTION 'GUI_UPLOAD'
Exporting
Filename = 'C: \EMP.txt'
has_field_separator = 'X'
Tables
data_tab = ITAB_EMP_DETAILS
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.
Endform. " GUI_UPLOAD
Form bdc_field using fnam fval.
Clear G_bdcdata.
G_bdcdata-fnam = fnam.
G_bdcdata-fval = fval.
Append G_bdcdata.
Endform.
Form bdc_dynpro using program dynpro.
Clear G_bdcdata.
G_bdcdata-program = program.
G_bdcdata-dynpro = dynpro.
G_bdcdata-dynbegin = 'X'.
Append G_bdcdata.
Endform.
3.
In call transaction this needs to be handled explicitly using the structure BDCMSGCOLL.You can declare an internal table to trap the messages with the type BDCMSGCOLL.
CALL TRANSACTION ZTRN1
USING <BDC DATA table name>
MESSAGES INTO <BDCMSGCOLL table name>.
The BDCMSGCOLL does not have the messages text. It has only the message type, number and message parameters. The database table T100 stores all the messages. Read the dictionary table T100 FOR ALL ENTRIES in BDCMSGCOLL.The error messages have type E. Ignore other types of messages.
2008 Feb 28 5:41 AM
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
-
2008 Mar 12 10:31 AM
Hi, this may be helpful for u.
BDC recording
Tran code SM35
Select "Recording"
Select "New Recording"
Enter a name in Recording Field
Enter MM03 in Transactoin Code
Select Start Recording
Enter your material Number
Hit "Enter" key
Select your views
Hit "Enter" key
Green Arrow (PF3) out until you get to Transaction recorder
SAVE
Green Arrow (PF3)
Select your recording
Select Program button
Enter a name for you program
Select "Transfer from recording"
and then the Green Check
Fill in Title etc
then Source code Button
This will generate a program that if run by itself will mimic your session.
You will need to select the parts of it and parts of the include into your program with field filled in. Put the pieces into your orginal code. Use the Call Transaction option in the generated program to see the fields you will need.
This process can take some practice to get used to.
regards,
chaitanya
2008 Mar 12 12:16 PM
Hi surendar,
There are two methods in which you can execute the call transaction method such as manual and automatic. In the manual method you have to write the code for each and every screen sequences. Also its time consuming. But in automatic method you can record the screen sequence as in a well manner. Then you can derive a program with the result of the recording. The following steps will help you by some means.
Steps,
1. Go to SHDB transaction.
2. Record the screen sequences with the values.
3. Finally with the recording click the program button in the Transaction recorder screen by selecting your recording name.
4. Give the new program name and select the option 'Transaction from recording'.
5. The code will be generated automatically with the desired screen sequences. Then pass your values from the internal table into the desired screen field values.
The following code will help you.
REPORT ZCA01BDC NO STANDARD PAGE HEADING LINE-SIZE 255.
DATA: BEGIN OF ITAB OCCURS 0,
MATNR LIKE RC27M-MATNR,
WERKS LIKE RC27M-WERKS,
PLNAL LIKE PLKOD-PLNAL,
VERWE LIKE PLKOD-VERWE,
STATU LIKE PLKOD-STATU,
LOSVN(16), " LIKE PLKOD-LOSVN,
ARBPL LIKE PLPOD-ARBPL,
STEUS LIKE PLPOD-STEUS,
LTXA1 LIKE PLPOD-LTXA1,
BMSCH(16), " LIKE PLPOD-BMSCH,
MEINH(3)," LIKE PLPOD-MEINH,
VGW01(9)," LIKE PLPOD-VGW01,
VGE01 LIKE PLPOD-VGE01,
VGW02(9)," LIKE PLPOD-VGW02,
VGE02 LIKE PLPOD-VGE02,
VGW03(9), "LIKE PLPOD-VGW03,
VGE03 LIKE PLPOD-VGE04,
VGW04(9)," LIKE PLPOD-VGE04,
VGE04 LIKE PLPOD-VGE04,
END OF ITAB.
INCLUDE ZBDC_DYNPFLD.
DATA: I_MSG LIKE BDCMSGCOLL OCCURS 0 WITH HEADER LINE .
PARAMETERS: CHK AS CHECKBOX.
DATA: ARBPL(16),
STEUS(16),
LTXA1(16),
BMSCH(16),
MEINH(16),
VGW01(16),
VGE01(16),
VGW02(16),
VGE02(16),
VGW03(16),
VGE03(16),
VGW04(16),
VGE04(16).
DATA: VAL(01) TYPE N VALUE 01,
DATE1(10) TYPE C,
CNT(10), " LIKE RC27X-ENTRY_ACT,
CNT1(3),
ITAB1 LIKE ITAB OCCURS 0 WITH HEADER LINE,
WA LIKE ITAB.
START-OF-SELECTION.
IF CHK = 'X'.
CALL FUNCTION 'UPLOAD'
EXPORTING
FILENAME = 'C:\ITAB.TXT'
FILETYPE = 'DAT'
TABLES
DATA_TAB = ITAB
EXCEPTIONS
CONVERSION_ERROR = 1
INVALID_TABLE_WIDTH = 2
INVALID_TYPE = 3
NO_BATCH = 4
UNKNOWN_ERROR = 5
GUI_REFUSE_FILETRANSFER = 6
OTHERS = 7.
SORT ITAB BY MATNR WERKS.
ITAB1[] = ITAB[].
LOOP AT ITAB.
CLEAR WA.
MOVE-CORRESPONDING ITAB TO WA.
CLEAR BDC_DATA.
REFRESH BDC_DATA.
AT NEW MATNR.
PERFORM BDC_DYNPRO USING 'SAPLCPDI' '1010'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RC27M-MATNR'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'RC27M-MATNR'
WA-MATNR.
PERFORM BDC_FIELD USING 'RC27M-WERKS'
WA-WERKS.
PERFORM BDC_DYNPRO USING 'SAPLCPDA' '1200'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
PERFORM BDC_FIELD USING 'PLKOD-PLNAL'
WA-PLNAL.
PERFORM BDC_FIELD USING 'PLKOD-WERKS'
WA-WERKS.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'PLKOD-LOSVN'.
PERFORM BDC_FIELD USING 'PLKOD-VERWE'
WA-VERWE.
PERFORM BDC_FIELD USING 'PLKOD-STATU'
WA-STATU.
PERFORM BDC_FIELD USING 'PLKOD-LOSVN'
WA-LOSVN.
PERFORM BDC_FIELD USING 'PLKOD-LOSBS'
'99,999,999'.
PERFORM BDC_FIELD USING 'PLKOD-PLNME'
'NOS'.
PERFORM BDC_DYNPRO USING 'SAPLCPDA' '1200'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=VOUE'.
ENDAT.
PERFORM BDC_DYNPRO USING 'SAPLCPDI' '1400'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'PLPOD-LTXA1(01)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
CLEAR : CNT,CNT1.
CNT = CNT + 1.
LOOP AT ITAB1 WHERE MATNR = ITAB-MATNR.
CNT1 = CNT1 + 1.
IF CNT1 = 1.
VAL = '01'.
ELSEIF CNT1 > 1.
VAL = '02'.
ENDIF.
CONCATENATE: 'PLPOD-ARBPL(' VAL ')' INTO ARBPL,
'PLPOD-STEUS(' VAL ')' INTO STEUS,
'PLPOD-LTXA1(' VAL ')' INTO LTXA1,
'PLPOD-BMSCH(' VAL ')' INTO BMSCH,
'PLPOD-MEINH(' VAL ')' INTO MEINH,
'PLPOD-VGW01(' VAL ')' INTO VGW01,
'PLPOD-VGe01(' VAL ')' INTO VGE01,
'PLPOD-VGW02(' VAL ')' INTO VGW02,
'PLPOD-VGe02(' VAL ')' INTO VGE02,
'PLPOD-VGW03(' VAL ')' INTO VGW03,
'PLPOD-VGe03(' VAL ')' INTO VGE03,
'PLPOD-VGW04(' VAL ')' INTO VGW04,
'PLPOD-VGe04(' VAL ')' INTO VGE04.
PERFORM BDC_FIELD USING ARBPL ITAB1-ARBPL.
PERFORM BDC_FIELD USING STEUS ITAB1-STEUS.
PERFORM BDC_FIELD USING LTXA1 ITAB1-LTXA1.
PERFORM BDC_FIELD USING BMSCH ITAB1-BMSCH.
PERFORM BDC_FIELD USING MEINH ITAB1-MEINH.
PERFORM BDC_FIELD USING VGW01 ITAB1-VGW01.
PERFORM BDC_FIELD USING VGE01 ITAB1-VGE01.
PERFORM BDC_FIELD USING VGW02 ITAB1-VGW02.
PERFORM BDC_FIELD USING VGE02 ITAB1-VGE02.
PERFORM BDC_FIELD USING VGW03 ITAB1-VGW03.
PERFORM BDC_FIELD USING VGE03 ITAB1-VGE03.
PERFORM BDC_FIELD USING VGW04 ITAB1-VGW04.
PERFORM BDC_FIELD USING VGE04 ITAB1-VGE04.
PERFORM BDC_FIELD USING 'RC27X-ENTRY_ACT'
CNT1.
IF SY-TABIX >= 2.
PERFORM BDC_DYNPRO USING 'SAPLCPDI' '1400'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RC27X-ENTRY_ACT'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=EINF'.
CNT = CNT + 1.
PERFORM BDC_FIELD USING 'RC27X-ENTRY_ACT'
CNT1.
PERFORM BDC_DYNPRO USING 'SAPLCPDI' '1400'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'PLPOD-LTXA1(02)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'/00'.
ENDIF.
AT LAST.
PERFORM BDC_DYNPRO USING 'SAPLCPDI' '1400'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RC27X-ENTRY_ACT'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=MATA'.
PERFORM BDC_FIELD USING 'RC27X-ENTRY_ACT'
CNT1.
PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0300'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=NO'.
PERFORM BDC_DYNPRO USING 'SAPLCPDI' '1000'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'RC27X-ENTRY_ACT'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=BU'.
PERFORM BDC_FIELD USING 'RC27X-ENTRY_ACT'
CNT1.
PERFORM BDC_DYNPRO USING 'SAPLCPDI' '1400'.
PERFORM BDC_FIELD USING 'BDC_CURSOR'
'PLPOD-UVORN(02)'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=END'.
PERFORM BDC_FIELD USING 'RC27X-ENTRY_ACT'
cnt1.
PERFORM BDC_DYNPRO USING 'SAPLSPO1' '0100'.
PERFORM BDC_FIELD USING 'BDC_OKCODE'
'=NO'.
ENDAT.
CLEAR ITAB1.
ENDLOOP.
CALL TRANSACTION 'CA01' USING BDC_DATA UPDATE 'A'
MODE 'A'
MESSAGES INTO I_MSG.
IF SY-SUBRC NE 0.
PERFORM ERROR_MSG.
CLEAR BDC_DATA.
REFRESH BDC_DATA.
ENDIF.
ENDLOOP.
ENDIF.
&----
*& Form ERROR_MSG
&----
text
----
--> p1 text
<-- p2 text
----
FORM ERROR_MSG .
DATA: ERR_MSG(250).
READ TABLE I_MSG WITH KEY MSGTYP = 'E'.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = 'EN'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = ERR_MSG
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:'ERROR MESSAGE', ERR_MSG.
CLEAR:I_MSG.
REFRESH: I_MSG.
ENDFORM. " ERROR_MSG
2008 Mar 12 12:24 PM
hi ,
please look into the code this is for customer creation using call transaction.
types : begin of ty_kna1,
kunnr type kna1-kunnr,
ktokd type kna1-ktokd,
name1 type kna1-name1,
sortl type kna1-sortl,
ort01 type kna1-ort01,
pstlz type kna1-pstlz,
land1 type kna1-land1,
spras type kna1-spras,
end of ty_kna1.
data : i_kna1 type table of ty_kna1,
w_kna1 type ty_kna1.
data : w_bdcdata type bdcdata,
i_bdcdata type table of bdcdata.
CALL FUNCTION 'GUI_UPLOAD
EXPORTING
FILENAME = 'c:\customer.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = I_KNA1
.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
loop at i_kna1 into w_kna1.
perform bdc_dynpro using 'SAPMF02D' '0100'.
perform bdc_field using 'BDC_CURSOR'
'RF02D-KTOKD'.
perform bdc_field using 'BDC_OKCODE'
'/00'.
perform bdc_field using 'RF02D-KUNNR'
w_kna1-kunnr.
perform bdc_field using 'RF02D-KTOKD'
w_kna1-KTOKD.
perform bdc_dynpro using 'SAPMF02D' '0110'.
perform bdc_field using 'BDC_CURSOR'
'KNA1-SPRAS'.
perform bdc_field using 'BDC_OKCODE'
'=UPDA'.
perform bdc_field using 'KNA1-NAME1'
w_kna1-NAME1.
perform bdc_field using 'KNA1-SORTL'
w_kna1-SORTL.
perform bdc_field using 'KNA1-ORT01'
w_kna1-ORT01.
perform bdc_field using 'KNA1-PSTLZ'
w_kna1-PSTLZ.
perform bdc_field using 'KNA1-LAND1'
w_kna1-LAND1.
perform bdc_field using 'KNA1-SPRAS'
w_kna1-SPRAS.
perform bdc_transaction using 'XD01'.
endloop.
&----
*& Form bdc_dynpro
*&----
text
----
-->P_0099 text
-->P_0100 text
----
FORM bdc_dynpro USING VALUE(P_0099)‏
VALUE(P_0100).
CLEAR w_BDCDATA.
w_BDCDATA-PROGRAM = P_0099.
w_BDCDATA-DYNPRO = P_0100.
w_BDCDATA-DYNBEGIN = 'X'.
APPEND w_bdcdata to i_bdcdata.
ENDFORM. " bdc_dynpro
&----
*& Form bdc_field
&----
text
----
-->P_0098 text
-->P_0099 text
----
FORM bdc_field USING VALUE(P_0098)‏
VALUE(P_0099).
CLEAR w_BDCDATA.
w_BDCDATA-FNAM = P_0098.
w_BDCDATA-FVAL = P_0099.
APPEND w_BDCDATA to i_bdcdata.
ENDFORM. " bdc_field
&----
*& Form bdc_transaction
&----
text
----
-->P_0169 text
----
FORM bdc_transaction USING VALUE(P_0169).
CALL TRANSACTION P_0169 USING i_BDCDATA
MODE 'A'
UPDATE 'S'.
"MESSAGES INTO MESSTAB.
ENDFORM. " bdc_transaction
Thanks,
Swapna.
| User | Count |
|---|---|
| 6 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |