‎2007 Apr 23 8:46 AM
hi all,
can any body provide sample code for uploading data in transaction ac03 using call
transaction method.
thanks in advance.
siva
‎2007 Apr 23 8:49 AM
Use the batch input recorder, transaction SHDB, and record your transaction. From here you can generate program code for the relevant BDC program.
regards,
Hans
Please reward all helpful answers !!!!!
‎2007 Apr 23 9:18 AM
hi siva
first u need to create a recording and then code
a sample code
----
Program : ZMM_BDCP_VENDOR_AS01 *
Title : BDC for vendor Data Upload *
----
REPORT zmm_bdcp_customer_as01
NO STANDARD PAGE HEADING LINE-SIZE 255.
*-----Include Program for data declarations and subroutines
INCLUDE zsd_incl_vendor_as01.
----
START-OF-SELECTION *
----
START-OF-SELECTION.
*-----Uploading a file from the PC to the server
PERFORM data_upload .
*-----Loop for all records
LOOP AT it_struc1 INTO x_struc1.
*-----Filling the fields
PERFORM fill_bdc USING : 'X' 'SAPMF02K' '0100',
' ' 'BDC_OKCODE' '/00',
' ' 'RF02K-LIFNR' x_struc1-lifnr,
' ' 'RF02K-KTOKK' x_struc1-ktokk,
'X' 'SAPMF02K' '0110',
' ' 'BDC_OKCODE' '/00',
' ' 'LFA1-ANRED' x_struc1-anred,
' ' 'LFA1-NAME1' x_struc1-name1,
' ' 'LFA1-SORTL' x_struc1-sortl,
' ' 'LFA1-LAND1' x_struc1-land1,
'X' 'SAPMF02K' '0120',
' ' 'BDC_OKCODE' '/00',
'X' 'SAPMF02K' '0130',
' ' 'BDC_OKCODE' '=ENTR',
'X' 'SAPLSPO1' '0300',
' ' 'BDC_OKCODE' '=YES'.
*-----Start new transaction according to parameters
PERFORM bdc_transaction USING 'XK01'.
ENDLOOP.
----
END-OF-SELECTION *
----
END-OF-SELECTION.
*-----Printing all success messages
IF it_messtab1 IS NOT INITIAL.
WRITE:/ 'SUCCESS MESSAGES'.
LOOP AT it_messtab1 INTO x_messtab1.
WRITE 😕 x_messtab1-mstring.
ENDLOOP.
ENDIF.
SKIP 2.
*-----Printing all error messages
IF it_messtab2 IS NOT INITIAL.
WRITE:/ 'ERROR MESSAGES'.
LOOP AT it_messtab2 INTO x_messtab2.
CHECK x_messtab2-msgtyp = 'E'.
WRITE 😕 x_messtab2-mstring.
ENDLOOP.
ENDIF.
*-----Close batch input session
PERFORM close_group.
Include's Coding
----
Program : ZSD_INCL_VENDOR_AS01 *
Title : Include for ZSD_BDCP_VENDOR_AS01 *
----
*-----Table declaration
TABLES: t100.
----
Data definition
----
*-----Types Declaration
TYPES : BEGIN OF x_struc1,
lifnr TYPE rf02k-lifnr, "Vendor Account Number
ktokk TYPE rf02k-ktokk, "Vendor account group
anred TYPE lfa1-anred, "Title
name1 TYPE lfa1-name1, "Name 1
sortl TYPE lfa1-sortl, "Sort field
land1 TYPE lfa1-land1, "Country Key
END OF x_struc1,
BEGIN OF x_struc2,
msgtyp TYPE bdcmsgcoll-msgtyp,"Message Type
mstring TYPE string, "Message Text
END OF x_struc2.
*-----Internal table declaration
DATA : it_messtab TYPE TABLE OF bdcmsgcoll,
it_messtab1 TYPE TABLE OF x_struc2,
it_messtab2 TYPE TABLE OF x_struc2,
it_bdcdata TYPE TABLE OF bdcdata,
it_struc1 TYPE TABLE OF x_struc1,
*-----Work area declaration
x_bdcdata TYPE bdcdata,
x_struc1 TYPE x_struc1,
x_messtab TYPE bdcmsgcoll,
x_messtab1 TYPE x_struc2,
x_messtab2 TYPE x_struc2,
*-----flags declaration
fg_group_opened(1) TYPE c,
fg_e_group_opened TYPE c,
*-----local variable declaration
v_subrc TYPE sy-subrc,
v_mstring TYPE string,
v_fname TYPE string.
----
SELECTION-SCREEN declaration *
----
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS p_sesion RADIOBUTTON GROUP rb_c.
SELECTION-SCREEN COMMENT 3(20) text-s07 FOR FIELD p_sesion.
SELECTION-SCREEN POSITION 45.
PARAMETERS p_ctu RADIOBUTTON GROUP rb_c.
SELECTION-SCREEN COMMENT 48(20) text-s08 FOR FIELD p_ctu.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) text-s01 FOR FIELD p_group.
SELECTION-SCREEN POSITION 25.
PARAMETERS p_group(12).
SELECTION-SCREEN COMMENT 48(20) text-s05 FOR FIELD p_ctumod.
SELECTION-SCREEN POSITION 70.
PARAMETERS p_ctumod TYPE ctu_params-dismode DEFAULT 'N'.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) text-s03 FOR FIELD px_keep.
SELECTION-SCREEN POSITION 25.
PARAMETERS: px_keep AS CHECKBOX.
SELECTION-SCREEN COMMENT 48(20) text-s09 FOR FIELD p_e_grp.
SELECTION-SCREEN POSITION 70.
PARAMETERS p_e_grp(12).
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 51(17) text-s03 FOR FIELD px_e_kep.
SELECTION-SCREEN POSITION 70.
PARAMETERS: px_e_kep AS CHECKBOX.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 3(20) text-s11 FOR FIELD p_fname.
SELECTION-SCREEN POSITION 25.
PARAMETERS: p_fname(128) TYPE c.
SELECTION-SCREEN END OF LINE.
----
AT SELECTION-SCREEN *
----
AT SELECTION-SCREEN.
*-----Group must be filled for create session
IF p_sesion = 'X' AND
p_group = space.
MESSAGE e613(ms).
ENDIF.
----
AT SELECTION-SCREEN ON VALUE-REQUEST *
----
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
*-----Calling function for selecting the local file
CALL FUNCTION 'F4_FILENAME'
EXPORTING
program_name = syst-cprog
dynpro_number = syst-dynnr
IMPORTING
file_name = p_fname.
v_fname = p_fname.
--
FORM open_group.
*-----Open batchinput group
IF p_sesion = 'X'.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = p_group
user = sy-uname
keep = px_keep.
ENDIF.
ENDFORM. "OPEN_GROUP
--
FORM close_group.
*-----Close batch input session
IF p_sesion = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /(30) text-001.
ELSE.
IF fg_e_group_opened = 'X'.
CALL FUNCTION 'BDC_CLOSE_GROUP'.
WRITE: /.
WRITE: /(30) 'Error session created'(i01).
ENDIF.
ENDIF.
ENDFORM. "CLOSE_GROUP
--
FORM bdc_transaction USING tcode TYPE any.
*-----Batch input session
IF p_sesion = 'X'.
IF fg_group_opened = ' '.
*-----Open batch input session for adding transactions
PERFORM open_group.
fg_group_opened = 'X'.
ENDIF.
*-----Insert batch input transactions in batch input session
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = tcode
TABLES
dynprotab = it_bdcdata.
WRITE: / 'INSERT SUCCESSFULL'.
*-----Call transaction
ELSE.
REFRESH it_messtab.
CALL TRANSACTION tcode USING it_bdcdata
MODE p_ctumod
MESSAGES INTO it_messtab.
v_subrc = sy-subrc.
LOOP AT it_messtab INTO x_messtab.
SELECT SINGLE * FROM t100 WHERE sprsl = x_messtab-msgspra
AND arbgb = x_messtab-msgid
AND msgnr = x_messtab-msgnr.
IF sy-subrc = 0.
v_mstring = t100-text.
IF v_mstring CS '&1'.
REPLACE '&1' WITH x_messtab-msgv1 INTO v_mstring.
REPLACE '&2' WITH x_messtab-msgv2 INTO v_mstring.
REPLACE '&3' WITH x_messtab-msgv3 INTO v_mstring.
REPLACE '&4' WITH x_messtab-msgv4 INTO v_mstring.
ELSE.
REPLACE '&' WITH x_messtab-msgv1 INTO v_mstring.
REPLACE '&' WITH x_messtab-msgv2 INTO v_mstring.
REPLACE '&' WITH x_messtab-msgv3 INTO v_mstring.
REPLACE '&' WITH x_messtab-msgv4 INTO v_mstring.
ENDIF.
CONDENSE v_mstring.
*-----Determining of messages
CASE x_messtab-msgtyp.
WHEN 'S'.
x_messtab1-msgtyp = x_messtab-msgtyp.
x_messtab1-mstring = v_mstring.
APPEND x_messtab1 TO it_messtab1.
WHEN 'E'.
x_messtab2-msgtyp = x_messtab-msgtyp.
x_messtab2-mstring = v_mstring.
APPEND x_messtab2 TO it_messtab2.
ENDCASE.
ELSE.
WRITE: / x_messtab.
ENDIF.
ENDLOOP.
SKIP.
IF v_subrc <> 0 AND p_e_grp <> space.
IF fg_e_group_opened = ' '.
CALL FUNCTION 'BDC_OPEN_GROUP'
EXPORTING
client = sy-mandt
group = p_e_grp
user = sy-uname
keep = px_e_kep.
fg_e_group_opened = 'X'.
ENDIF.
CALL FUNCTION 'BDC_INSERT'
EXPORTING
tcode = tcode
TABLES
dynprotab = it_bdcdata.
ENDIF.
ENDIF.
REFRESH it_bdcdata.
ENDFORM. "BDC_TRANSACTION
--
FORM fill_bdc USING value(l_dynbegin) TYPE any
value(l_fname) TYPE any
value(l_value) TYPE any.
CLEAR : x_bdcdata.
IF l_dynbegin = 'X'.
x_bdcdata-dynbegin = 'X'.
x_bdcdata-program = l_fname.
x_bdcdata-dynpro = l_value.
ELSE.
x_bdcdata-fnam = l_fname.
x_bdcdata-fval = l_value.
ENDIF.
APPEND x_bdcdata TO it_bdcdata.
ENDFORM. " fill_bdc
--
FORM data_upload .
*-----loading a file from the PC to the server
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = v_fname
has_field_separator = 'X'
TABLES
data_tab = it_struc1
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. " data_upload
Regards,
navjot
reward if helpfull