2008 May 02 3:42 PM
HI gurus,
please send sample recoding procedure for call transaction.
kindly help me.
HI gurus,
please send sample recoding procedure for call transaction.
kindly help me.
2008 May 02 3:48 PM
1) prerequiste,, is that you msut be able to use a transaction for which you want to do the BDC. For example, you must know how to create a sales order using VA01 transaction.
2) Go to transaction SHDB
3) Give the name of the transaction for which you want to do the BDC.
4) Go ahead and create the recording(GIve a name for your recording).
5) select your recording and click on the button in SHDB transaction itself, to create a BDC program for your recording.
6) Do minor twaeking to the generated code, if it doesn't fit your requirement.
Regards,
Ravi Kanth Talagana
2008 May 02 4:09 PM
hi,
i want step by step procedure.
And my requirement is data should upload from flat flle to
internal table .
regards,
saritha.
2008 May 02 5:09 PM
Depending on the source i.e presentation or application server upload the data into an internal table.
for presentation server use function module gui_upload.
for application server use open dataset statement.
loop at the internal table which receives the uploaded data and split values depending on the separator into the internal table format.
Indranil
Award points if helpful
2008 May 02 5:29 PM
Hi
goto SHDB transaction create a new recording for the particular transaction...save the recording and select the program and click the tab PROGRAM ...u wil get all the recording in program and select transfer from recording.save the program ...and then u wil get the code in se38...
depending upon u r requirement and what are the feilds u have filled in transaction....create a internal table......and by using call transaction upload the data from flat file....
here is a sample program for xk01 transaction.....
TYPES : BEGIN OF st_vendor,
ktokk TYPE rf02k-ktokk, "account group
anred TYPE lfa1-anred, "title
name1 TYPE lfa1-name1, "vendor name
sortl TYPE lfa1-sortl, "search term
pstlz TYPE lfa1-pstlz, "postal code
land1 TYPE lfa1-land1, "country
banks TYPE lfbk-banks,
bankl TYPE lfbk-bankl, "bank key
bankn TYPE lfbk-bankn, "account number
END OF st_vendor.
TYPES : BEGIN OF st_success,
lifnr TYPE lfa1-lifnr, "vendor number
name TYPE lfa1-name1, "vendor name
END OF st_success.
TYPES: BEGIN OF st_error,
linno TYPE i, "line number
message TYPE string, "error message
END OF st_error.
----
INTERNAL TABLE DECLARATIONS
WORK AREA DECLARATIONS
----
DATA : it_vendor TYPE STANDARD TABLE OF st_vendor,
wa_vendor TYPE st_vendor,
it_success TYPE STANDARD TABLE OF st_success,
wa_success TYPE st_success,
it_error TYPE STANDARD TABLE OF st_error,
wa_error TYPE st_error,
it_bdcdata LIKE bdcdata OCCURS 0 WITH HEADER LINE,
it_message LIKE bdcmsgcoll OCCURS 0 WITH HEADER LINE.
----
DATA DECLARATION
----
DATA : v_file TYPE string,
v_tcode(4) VALUE 'XK01',
v_index LIKE sy-tabix,
v_totalrec TYPE i,
v_errrec TYPE i,
v_succrec TYPE i.
----
SELECTION SCREEN
----
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
PARAMETERS: p_file TYPE rlgrap-filename.
SELECTION-SCREEN END OF BLOCK b1.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-010.
PARAMETERS p_mode LIKE ctu_params-dismode DEFAULT 'N' .
"A: show all dynpros
"E: show dynpro on error only
"N: do not display dynpro
PARAMETERS p_update LIKE ctu_params-updmode DEFAULT 'S'.
"S: synchronously
"A: asynchronously
SELECTION-SCREEN END OF BLOCK b2.
SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-011.
PARAMETERS : p_group(12) DEFAULT '50871'. "group name for error session
SELECTION-SCREEN END OF BLOCK b3.
----
AT SELECTION SCREEN ON VALUE-REQUEST
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
field_name = ' '
IMPORTING
file_name = p_file.
----
START-OF-SELECTION
----
START-OF-SELECTION.
v_file = p_file.
*gui upload
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_file
filetype = 'ASC'
has_field_separator = 'X'
TABLES
data_tab = it_vendor
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.
*loadind data into it_bdcdata
LOOP AT it_vendor INTO wa_vendor.
v_index = sy-tabix.
PERFORM load_bdcdata.
----
CALL TRANSACTION
----
CALL TRANSACTION v_tcode USING it_bdcdata
MODE p_mode
UPDATE p_update
MESSAGES INTO it_message.
*reading success
IF sy-subrc = 0.
READ TABLE it_message WITH KEY msgtyp = 'S'.
IF sy-subrc = 0.
wa_success-lifnr = it_message-msgv1.
wa_success-name = wa_vendor-name1.
APPEND wa_success TO it_success.
ENDIF.
ELSE.
*reading errors
READ TABLE it_message WITH KEY msgtyp = 'E'.
IF sy-subrc = 0.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
id = sy-msgid
no = it_message-msgnr
v1 = it_message-msgv1
v2 = it_message-msgv2
v3 = it_message-msgv3
v4 = it_message-msgv4
IMPORTING
msg = wa_error-message.
wa_error-linno = v_index.
APPEND wa_error TO it_error.
CLEAR wa_error.
ENDIF.
*session opening
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = p_group
holddate = sy-datum
keep = 'X'
user = sy-uname.
*inserting into session
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = 'XK01'
TABLES
dynprotab = it_bdcdata.
*closing session
CALL FUNCTION 'BDC_CLOSE_GROUP'.
ENDIF.
CLEAR: it_bdcdata, it_message.
REFRESH: it_bdcdata, it_message.
ENDLOOP.
----
SUMMARY DISPLAY
----
DESCRIBE TABLE it_vendor LINES v_totalrec.
DESCRIBE TABLE it_error LINES v_errrec.
v_succrec = v_totalrec - v_errrec .
WRITE : /1 text-004 COLOR 1.
WRITE : /2 'Total Records Processed :', 25 v_totalrec,
/2 'Error Records :', 25 v_errrec,
/2 'Successful Records :', 25 v_succrec.
SKIP 2.
WRITE : /1 text-005 COLOR 1.
LOOP AT it_error INTO wa_error.
WRITE:/2 wa_error-linno,
wa_error-message.
ENDLOOP.
SKIP 2.
WRITE : /1 text-009 COLOR 1.
ULINE AT : /2(46).
WRITE :/2 sy-vline ,(10) 'VENDOR NUM' , 15 sy-vline , 17 'VENDOR NAME' , 47 sy-vline.
ULINE AT : /2(46).
LOOP AT it_success INTO wa_success.
WRITE:/2 sy-vline , wa_success-lifnr, 15 sy-vline , 17 wa_success-name , 47 sy-vline.
ENDLOOP.
ULINE AT : /2(46).
&----
*& Form append_bdcdata
&----
FORM append_bdcdata USING p_flag p_fname p_fval.
CLEAR it_bdcdata.
IF p_flag = 'X'.
it_bdcdata-program = p_fname.
it_bdcdata-dynpro = p_fval.
it_bdcdata-dynbegin = 'X'.
APPEND it_bdcdata.
ELSEIF NOT p_fval IS INITIAL.
it_bdcdata-fnam = p_fname.
it_bdcdata-fval = p_fval.
APPEND it_bdcdata.
ENDIF.
ENDFORM. "append_bdcdata
&----
*& Form load_bdcdata
&----
FORM load_bdcdata .
PERFORM append_bdcdata USING : 'X' 'SAPMF02K' '0100',
' ' 'BDC_OKCODE' '/00',
' ' 'RF02K-KTOKK' wa_vendor-ktokk,
'X' 'SAPMF02K' '0110',
' ' 'BDC_OKCODE' '/00',
' ' 'LFA1-ANRED' wa_vendor-anred,
' ' 'LFA1-NAME1' wa_vendor-name1,
' ' 'LFA1-SORTL' wa_vendor-sortl,
' ' 'LFA1-PSTLZ' wa_vendor-pstlz,
' ' 'LFA1-LAND1' wa_vendor-land1,
'X' 'SAPMF02K' '0120',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02K' '0130',
' ' 'BDC_OKCODE' '=ENTR',
' ' 'LFBK-BANKS(01)' wa_vendor-banks,
' ' 'LFBK-BANKL(01)' wa_vendor-bankl,
' ' 'LFBK-BANKN(01)' wa_vendor-bankn,
'X' 'SAPMF02K' '0130',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPLSPO1' '0300',
' ' 'BDC_OKCODE' '=YES'.
ENDFORM. " load_bdcdata
2008 May 02 3:49 PM
Here is the procedure for recording with screen shots :
http://www.sapdevelopment.co.uk/bdc/bdc_recording.htmReward If helpful.
Edited by: Rock on May 2, 2008 4:59 PM
2008 May 02 6:48 PM
hi check this .....
https://www.sdn.sap.com/irj/sdn/wiki?path=/display/snippets/new%2bpage
this is the code for call transaction in different modes....
report zmppc018 no standard page heading
line-size 120
line-count 55
message-id zz.
Constants
constants : c_x type c value 'X'," Dynbegin
c_tcode type tstc-tcode value 'CA22'," Transaction Code
c_r(1) type c value 'R'," Task List type
c_O(1) type c value 'O',
c_fh(2) type c value 'FH'.
Variables
data : v_lines_in_xcel like sy-tabix,
v_matnr(18) type c, " Material Number
v_PLNNR like mapl-plnnr," Group
V_DATE(8) type c," System date
v_date1(4) type c,
v_date2(2) type c,
v_date3(2) type c,
V_COUNT TYPE I." Count
Internal table for BDCDATA Structure
data : begin of itab_bdc_tab occurs 0.
include structure bdcdata.
data : end of itab_bdc_tab.
Internal table for File
data : begin of t_file occurs 0,
matnr(18) type c, " Material #
werks(4) type c, " Plant
plnal(2) type n, " Group Counter
vornr(4) type n, " Op #
equnr(18) type c, " PRT Material #
steuf(4) type c, " Control Key
mgvgw(6) type n, " Qty
mgeinh(3) type c, " Qty Unit
end of t_file.
Internal table for Error Log
data : begin of i_error occurs 0,
matnr like mara-matnr,
werks like marc-werks,
vornr like plpo-vornr,
plnnr like plpo-plnnr,
text(90) type c,
end of i_error.
Selection-screen
selection-screen : begin of block blk with frame.
selection-screen: skip 1.
parameters : p_file like rlgrap-filename obligatory,
P_mode type c obligatory Default 'N'.
selection-screen : skip 1.
selection-screen : end of block blk.
at selection-screen on value-request for p_file.
F4 value for Input file
perform filename_get.
main processing
start-of-selection.
To get the data from file to Internal table
perform getdata_fromfile.
loop at t_file.
fill in bdc-data for Routing maintenance screens
perform bdc_build_script.
insert the bdc script as a BDC transaction
perform bdc_submit_transaction.
endloop.
top-of-page.
call function 'Z_HEADER'
EXPORTING
FLEX_TEXT1 =
FLEX_TEXT2 =
FLEX_TEXT3 =
.
skip 1.
write:/2 'Material #',24 'Plant',32 'Group',44 'Op #',
53 'Status Message'.
skip 1.
&----
*& Form filename_get
&----
F4 Value for Input File parameter
-
FORM filename_get.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
DEF_PATH = 'C:Temp '
MASK = ',.,..'
MODE = 'O'
TITLE = 'Select File '(007)
IMPORTING
FILENAME = p_file
EXCEPTIONS
INV_WINSYS = 1
NO_BATCH = 2
SELECTION_CANCEL = 3
SELECTION_ERROR = 4
OTHERS = 5.
ENDFORM. " filename_get
&----
*& Form getdata_fromfile
&----
text
-
FORM getdata_fromfile.
CALL FUNCTION 'WS_UPLOAD'
EXPORTING
FILENAME = p_file
FILETYPE = 'DAT'
TABLES
DATA_TAB = t_file
EXCEPTIONS
CONVERSION_ERROR = 1
FILE_OPEN_ERROR = 2
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
UNKNOWN_ERROR = 6
INVALID_TABLE_WIDTH = 7
GUI_REFUSE_FILETRANSFER = 8
CUSTOMER_ERROR = 9
OTHERS = 10.
if sy-subrc eq 0.
sort t_file by matnr werks plnal vornr .
clear v_lines_in_xcel.
describe table t_file lines v_lines_in_xcel.
if v_lines_in_xcel is initial.
write: / 'No data in input file'.
stop.
endif.
else.
write:/ 'Error reading input file'.
stop.
endif.
ENDFORM. " getdata_fromfile
&----
*& Form bdc_build_script
&----
BDC Script
-
FORM bdc_build_script.
Get the material number from tables ZMSMI_FERR_RAW,
ZMSMI_SNAP_RAW and ZMSMI_SIMP_RAW
perform get_matnr.
Screen 1010.
perform bdc_screen using 'SAPLCPDI' '1010'.
perform bdc_field using 'BDC_OKCODE' '=VOUE'.
perform bdc_field using 'RC27M-MATNR' SPACE .
perform bdc_field using 'RC27M-WERKS' SPACE.
perform bdc_field using 'RC271-VBELN' SPACE.
perform bdc_field using 'RC271-POSNR' SPACE.
perform bdc_field using 'RC271-PSPNR' SPACE.
Clear v_plnnr.
Get the Group from MAPL Table
select single plnnr from mapl
into v_plnnr
where matnr = t_file-matnr
and werks = t_file-werks
and loekz = space
and plnty = c_r
and plnal = t_file-plnal.
perform bdc_field using 'RC271-PLNNR' v_plnnr.
Current date
MOVE SY-DATUM TO V_DATE.
perform get_date.
perform bdc_field using 'RC271-STTAG' V_DATE.
perform bdc_field using 'RC271-PLNAL' t_file-plnal.
Screen 5400
perform bdc_screen using 'SAPLCPDI' '5400'.
perform bdc_field using 'BDC_OKCODE' '=OSEA'.
Screen 1010
perform bdc_screen using 'SAPLCP02' '1010'.
perform bdc_field using 'BDC_OKCODE' '=ENT1'.
perform bdc_field using 'RC27H-VORNR' T_FILE-VORNR.
Screen 5400
perform bdc_screen using 'SAPLCPDI' '5400'.
perform bdc_field using 'BDC_OKCODE' '=FHUE'.
perform bdc_field using 'RC27X-FLG_SEL(01)' C_X.
Get the no of records from PLAS,PLPO and PLFH Tables
perform get_count.
Screen 0200
IF V_COUNT = 0.
perform bdc_screen using 'SAPLCFDI' '0200'.
perform bdc_field using 'BDC_OKCODE' '/EFIM'.
ELSEif v_count > 0.
Screen 0100
perform bdc_screen using 'SAPLCFDI' '0100'.
perform bdc_field using 'BDC_OKCODE' '/EFIM'.
ENDIF.
Screen 0230
perform bdc_screen using 'SAPLCFDI' '0200'.
perform bdc_field using 'BDC_OKCODE' '=BACK'.
perform bdc_field using 'PLFHD-MATNR' T_FILE-EQUNR.
perform bdc_field using 'PLFHD-STEUF' T_FILE-STEUF.
perform bdc_field using 'PLFHD-MGVGW' T_FILE-mgvgw.
perform bdc_field using 'PLFHD-MGEINH' T_FILE-MGEINH.
Screen 0100
perform bdc_screen using 'SAPLCFDI' '0100'.
perform bdc_field using 'BDC_OKCODE' '=BU'.
ENDFORM. " bdc_build_script
&----
*& Form get_matnr
&----
Get the material number from tables ZMSMI_FERR_RAW,
ZMSMI_SNAP_RAW and ZMSMI_SIMP_RAW
-
FORM get_matnr.
clear v_matnr.
case t_file-werks.
when '0101'.
select single cmatnr from zmsmi_simp_raw
into v_matnr where matnr = t_file-matnr.
if not v_matnr is initial.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.
when '0103'.
select single cmatnr from zmsmi_ferr_raw
into v_matnr where matnr = t_file-matnr.
if not v_matnr is initial.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.
when '0102' or '0110' or '0111' or '0112' or '0113'
or '0114' or '0115' or '0116' or '0117'.
select single cmatnr from zmsmi_snap_raw
into v_matnr where matnr = t_file-matnr.
if not v_matnr is initial.
clear t_file-matnr.
t_file-matnr = v_matnr.
endif.
endcase.
ENDFORM. " get_matnr
&----
*& Form bdc_screen
&----
BDC Script for Screen fields
-
-->P_PROG Program name
-->P_SCRN Screen Number
-
FORM bdc_screen USING p_prog
p_scrn.
clear itab_bdc_tab.
itab_bdc_tab-program = p_prog.
itab_bdc_tab-dynpro = p_scrn.
itab_bdc_tab-dynbegin = c_x.
append itab_bdc_tab.
ENDFORM. " bdc_screen
&----
*& Form bdc_field
&----
BDC Script for Screen fileds
-
-->P_NAM Field name
-->P_VAL Field value
-
FORM bdc_field USING p_nam
p_val.
clear itab_bdc_tab.
itab_bdc_tab-fnam = p_nam.
itab_bdc_tab-fval = p_val.
append itab_bdc_tab.
ENDFORM. " bdc_field
&----
*& Form bdc_submit_transaction
&----
BDC_INSERT Function Module
-
FORM bdc_submit_transaction.
call transaction c_tcode using itab_bdc_tab
mode p_mode update 'S'.
refresh itab_bdc_tab.
CALL FUNCTION 'FORMAT_MESSAGE'
EXPORTING
ID = SY-MSGID
LANG = '-E'
NO = SY-MSGNO
V1 = SY-MSGV1
V2 = SY-MSGV2
V3 = SY-MSGV3
V4 = SY-MSGV4
IMPORTING
MSG = i_error-text
EXCEPTIONS
NOT_FOUND = 1
OTHERS = 2.
i_error-matnr = t_file-matnr.
i_error-werks = t_file-werks.
i_error-plnnr = v_plnnr.
i_error-vornr = t_file-vornr.
append i_error.
clear i_error.
clear t_file.
ENDFORM. " bdc_submit_transaction
&----
*& Form get_date
&----
Converted date as per CA22 Transaction
-
FORM get_date.
clear : v_date,
v_date1,
v_date2,
v_date3.
v_date1 = sy-datum+0(4).
v_date2 = sy-datum+4(2).
v_date3 = sy-datum+6(2).
concatenate v_date2 v_date3 v_date1 into v_date.
ENDFORM. " get_date
&----
*& Form get_count
&----
text
-
FORM get_count.
clear v_count.
select count(*) into v_count
from plas as a inner join plpo as b on aplnty = bplnty
and aplnnr = bplnnr
and aplnkn = bplnkn
inner join plfh as c on cplnty = aplnty
and cplnnr = aplnnr
and cplnal = aplnal
and cplnfl = aplnfl
and cplnkn = bplnkn
where a~plnty = c_r
and a~plnnr = v_plnnr
and a~plnal = t_file-plnal
and c~objct = c_O
and a~loekz = space
and b~vornr = t_file-vornr
and c~objty = c_fh
and c~loekz = space.
ENDFORM. " get_count
end-of-selection.
Displaying Error Log
loop at i_error.
write:/2 i_error-matnr,24 i_error-werks,32 i_error-plnnr,
44 i_error-vornr,50 '-', 53 i_error-text.
endloop.
regards,
venkat
2008 May 03 12:02 PM
Hi Saritha,
Check below steps.
First thing is u will not be doing recording by uploading the file. Recording will be done manually to put the logic in ur program
1. Open transaction SHDB. Press New recording button in tool bar.
2. Give Recording name and transaction name. Press enter.
3. Now it will take u to the transaction initial screen.
4. fill in all the details in the transaction. Finally press save.
5. Make sure that u are using right test case for recording. If u record with wrong test data then it will create hevoc in ur program.
6. Now u will come back to recording screen with all the details entered in the transaction.
7. Now write ur program for BDC. U have to populate ur bdcdata internal table in the same order as they appear after recording.
8. For uploading flat file u can use somany FMs like GUI_UPLOAD.
9. After getting the data into internal table follow below skeliton.
10.
LOOP AT itab INTO wa_tab.
REFRESH: i_bdcdata[], i_messages[].
Above statement is the common mistake which all of us does(We will miss this statement). So take care of this.
Populate BDCDATA internal table.
CALL TRANSACTION...
Display error log if any
ENDLOOP.
Hope it is clear now.
Thanks,
Vinod.