on 04-08-2011 12:01 PM
Hi folks,
How we can upload or download csv(comma separated vale) fles in web dynpro abap.in some forums i seen how we can upload or download files but i need file upload/download csv files
hi ,
create an attribute datasource of type xstring...and use the following code
TYPES :
BEGIN OF STR_ITAB,
AP_NUMBER(10) TYPE C,
SPAN(10) TYPE C,
TOWER_TYPE(10) TYPE C,
END OF STR_ITAB.
DATA : T_TABLE1 TYPE STANDARD TABLE OF STR_ITAB,
I_DATA TYPE STANDARD TABLE OF STRING,
* LO_ND_SFLIGHT TYPE REF TO IF_WD_CONTEXT_NODE,
* LO_EL_SFLIGHT TYPE REF TO IF_WD_CONTEXT_ELEMENT,
L_STRING TYPE STRING,
FS_TABLE TYPE STR_ITAB,
L_XSTRING TYPE XSTRING,
FIELDS TYPE STRING_TABLE,
LV_FIELD TYPE STRING.
DATA : T_TABLE TYPE IF_ZWD_KT_TOWERSCHDUL_V=>ELEMENTS_CTX_VN_DATA_TAB,
CTX_VN_DATA_TABLE TYPE IF_ZWD_KT_TOWERSCHDUL_V=>ELEMENTS_CTX_VN_DATA_TAB.
* get single attribute
WD_CONTEXT->GET_ATTRIBUTE( EXPORTING NAME = `DATASOURCE` IMPORTING VALUE = L_XSTRING ).
CALL FUNCTION 'HR_KR_XSTRING_TO_STRING'
EXPORTING
IN_XSTRING = L_XSTRING
IMPORTING
OUT_STRING = L_STRING.
SPLIT L_STRING AT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO TABLE I_DATA.
*SPLIT S_CONT AT CL_ABAP_CHAR_UTILITIES=> INTO TABLE S_TABLE.
FIELD-SYMBOLS: <WA_TABLE> LIKE LINE OF I_DATA.
REFRESH T_TABLE1.
CLEAR FS_TABLE.
DELETE I_DATA INDEX 1.
LOOP AT I_DATA ASSIGNING <WA_TABLE>.
* splits string on basis of tabs
SPLIT <WA_TABLE> AT ',' INTO
FS_TABLE-TOWER_TYPE
FS_TABLE-AP_NUMBER
FS_TABLE-SPAN.
APPEND FS_TABLE TO T_TABLE1.
* STR_ITAB-NUMBER_DIGITS.
* APPEND STR_ITAB TO ITAB.
ENDLOOP.
* Bind With table Element.
* LOOP AT i_data INTO l_string.
* SPLIT l_string AT cl_abap_char_utilities=>horizontal_tab INTO TABLE fields.
* READ TABLE fields INTO lv_field INDEX 1.
* fs_table-AP_NUMBER = lv_field.
* READ TABLE fields INTO lv_field INDEX 2.
* fs_table-SPAN = lv_field.
* APPEND fs_table TO t_table1.
* ENDLOOP.
* lo_nd_sflight = wd_context->get_child_node( 'CTX_VN_CTX_VN_CTX_VN_CTX_VN_DATA_TAB' ).
* lo_nd_sflight->bind_table( t_table1 ).
DATA LO_ND_CTX_VN_DATA_TAB TYPE REF TO IF_WD_CONTEXT_NODE.
DATA LO_EL_CTX_VN_DATA_TAB TYPE REF TO IF_WD_CONTEXT_ELEMENT.
DATA LS_CTX_VN_DATA_TAB TYPE WD_THIS->ELEMENT_CTX_VN_DATA_TAB.
* navigate from <CONTEXT> to <CTX_VN_CTX_VN_CTX_VN_CTX_VN_DATA_TAB> via lead selection
LO_ND_CTX_VN_DATA_TAB = WD_CONTEXT->GET_CHILD_NODE( NAME = WD_THIS->WDCTX_CTX_VN_DATA_TAB ).
LO_ND_CTX_VN_DATA_TAB->BIND_TABLE( T_TABLE1 ).
thanks and regards,
sahai.s
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The upload and download process is the same regardless of the file type or format. Is your question actually about upload/download or the processing of the CSV file on the application server once it has been uploaded?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
HI ravi
as thomas suggested
file uploading and downloading will be same whatever file type you use.
the only difference file type makes is how you are goign to read the data in the application.
if you are using the csv file to fill some internal table or something else.
means if you are using the data ..
then you need to write the code in the program for converting the xstring to string first
and then reading that string using some utility function and seprating the lines and then the fields using the sepration of comma
then use the data.
here is some smaple code for the same
DATA : conv TYPE REF TO CL_ABAP_CONV_IN_CE.
* Creates a Conversion Instance
CALL METHOD CL_ABAP_CONV_IN_CE=>CREATE
EXPORTING
INPUT = <variable having the xstring data>
ENCODING = 'UTF-8'
REPLACEMENT = '?'
IGNORE_CERR = ABAP_TRUE
RECEIVING
CONV = conv.
conv2->READ( importing data =<string data> ).
SPLIT <string data> AT CL_ABAP_CHAR_UTILITIES=>CR_LF INTO TABLE <int table>.
LOOP AT <int_table> ASSIGNING <WA_TABLE>.
* splits string on basis of tabs
SPLIT <wa_TABLE> AT ',' INTO
str_itab-field1 str_itab-field2 str_itab-field3.
APPEND STR_ITAB TO ITAB.
ENDLOOP.
" now itab contains the data of csv file.
thanks
sarbjeet singh
Hi Ravi,
Please go through this wiki...
http://wiki.sdn.sap.com/wiki/display/WDABAP/UploadandDownloadfilesinWebdynproABAP
Cheers,
Kris.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.