11-12-2007 5:42 AM
Hi All,
Can anybody tell me how to read the data from application server using TAB delimiter. How to write the logic.
It is urgent.
Regards,
Karthik.
11-12-2007 5:53 AM
Hi
ABAP code for uploading a TAB delimited file into an internal table. See code below for structures. The
code is base on uploading a simple txt file.
REPORT zuploadtab .
PARAMETERS: p_infile LIKE rlgrap-filename
OBLIGATORY DEFAULT '/usr/sap/'..
DATA: ld_file LIKE rlgrap-filename.
*Internal tabe to store upload data
TYPES: BEGIN OF t_record,
name1 like pa0002-VORNA,
name2 like pa0002-name2,
age type i,
END OF t_record.
DATA: it_record TYPE STANDARD TABLE OF t_record INITIAL SIZE 0,
wa_record TYPE t_record.
*Text version of data table
TYPES: begin of t_uploadtxt,
name1(10) type c,
name2(15) type c,
age(5) type c,
end of t_uploadtxt.
DATA: wa_uploadtxt TYPE t_uploadtxt.
*String value to data in initially.
DATA: wa_string(255) type c.
constants: con_tab TYPE x VALUE '09'.
*If you have Unicode check active in program attributes then you will
*need to declare constants as follows:
*class cl_abap_char_utilities definition load.
*constants:
* con_tab type c value cl_abap_char_utilities=>HORIZONTAL_TAB.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
ld_file = p_infile.
OPEN DATASET ld_file FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc NE 0.
ELSE.
DO.
CLEAR: wa_string, wa_uploadtxt.
READ DATASET ld_file INTO wa_string.
IF sy-subrc NE 0.
EXIT.
ELSE.
SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
wa_uploadtxt-name2
wa_uploadtxt-age.
MOVE-CORRESPONDING wa_uploadtxt TO wa_upload.
APPEND wa_upload TO it_record.
ENDIF.
ENDDO.
CLOSE DATASET ld_file.
ENDIF.
************************************************************************
*END-OF-SELECTION
END-OF-SELECTION.
*!! Text data is now contained within the internal table IT_RECORD
* Display report data for illustration purposes
loop at it_record into wa_record.
write:/ sy-vline,
(10) wa_record-name1, sy-vline,
(10) wa_record-name2, sy-vline,
(10) wa_record-age, sy-vline.
endloop.
Check this link
Regards
Pavan
11-12-2007 5:53 AM
Hi
check this sample code...
this is for uploading data into apllicn server
OPEN DATASET <file name> FOR {OUTPUT/INPUT/APPENDING}
IN {TEXT/BINARY} MODE
chk this program..
DATA: i_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.
OPEN DATASET i_file FOR INPUT IN TEXT MODE.
IF sy-subrc NE 0.
MESSAGE e999(za) WITH 'Error opening file' i_file.
ENDIF.
DO.
Reads each line of file individually
READ DATASET i_file INTO wa_datatab.
Perform processing here
.....
ENDDO.
Downloading files to SAP(Application Server)
Download internal table to Application server file(Unix)
DATA: e_file like rlgrap-filename value '/usr/sap/tmp/file.txt'.
open dataset e_file for output in text mode.
lOOP AT it_datatab......
transfer it_datatab to e_file.
ENDLOOP.
close dataset e_file.
You are going to want to do something like this.
report zrich_0001.
data: str type string.
data: begin of itab occurs 0,
fld1(10) type c,
fld2(10) type c,
fld3(10) type c,
end of itab.
data:
dsn(500) value '/usr/sap/TST/sys/test.txt'.
clear itab. refresh itab.
Read the data.
open dataset dsn for input in binary mode.
do.
read dataset dsn into str.
if sy-subrc = 0.
split str at ';' into itab-fld1 itab-fld2 itab-fld3.
append itab.
else.
exit.
endif.
enddo.
close dataset dsn.
Loop at itab.
write:/ itab-fld1, itab-fld2, itab-fld3.
endloop.
11-12-2007 6:02 AM
Hello Karthik
Read the DATASET into an itab (of TYPE TRUXS_T_TEXT_DATA; type-pool TRUXS) and convert it using function module <b>TEXT_CONVERT_TEX_TO_SAP</b>:
DATA:
lt_data TYPE truxs_t_text_data,
ls_record LIKE LINE OF lt_data,
lt_knb1 TYPE STANDARD TABLE OF knb1.
OPEN DATASET ...
DO.
READ DATASET ... INTO ls_record.
IF ( syst-subrc = 0 ).
APPEND ls_record TO lt_record.
ELSE.
EXIT. " leave DO loop
ENDIF.
ENDDO.
CALL FUNCTION 'TEXT_CONVERT_TEX_TO_SAP'
EXPORTING
I_FIELD_SEPERATOR = cl_abap_char_utilities=>HORIZONTAL_TAB
I_TAB_RAW_DATA = lt_data
TABLES
I_TAB_CONVERTED_DATA = lt_knb1. " structured itab (example)
Regards
Uwe