2007 Apr 11 11:15 AM
Hi,
Please do let me know that
I am having a flat file with TAB as delimiter for 3 fields.
Let me know how to split these data into seperate fields into an internal table.
answer with Code given will be appreciated
promise to reward points
Mac
2007 Apr 11 11:23 AM
no need to split , use GUI_UPLOAD and give HAS_FIELD_SEPARATOR = 'X' , it will work
REPORT ZTEST.
DATA : BEGIN OF ITAB OCCURS 0,
FIELD1(10),
FIELD2(10),
FIELD3(10),
END OF ITAB.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:Documents and SettingschandrasekharjDesktoptest.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = ITAB.
LOOP AT ITAB.
WRITE : / ITAB-FIELD1 , ITAB-FIELD2 , ITAB-FIELD3.
ENDLOOP.
Hi,
Please do let me know that
I am having a flat file with TAB as delimiter for 3 fields.
Let me know how to split these data into seperate fields into an internal table.
answer with Code given will be appreciated
promise to reward points
Mac
2007 Apr 11 11:17 AM
DATA: str1 TYPE string,
str2 TYPE string,
str3 TYPE string,
itab TYPE TABLE OF string,
text TYPE string.
text = `What a drag it is getting old`.
SPLIT text AT space INTO: str1 str2 str3,
TABLE itab.
SPLIT text AT cl_abap_char_utilities=>horizontal_tab INTO: TABLE itab
2007 Apr 11 11:20 AM
Hi ,
The character '#' is a Horizontal tab ..
Those '#' are special characters to indicates new line or tab. You need to use the abap objects CL_ABAP_CHAR_UTILITIES to fix this issue.
define a constant..
constants :
C_HTAB value CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB. **<--Horizontal tab
loop at i_input.
split i_input at C_HTAB into i_finaltab-field1 i_input.
split i_input at C_HTAB into i_finaltab-field2 i_input.
split i_input at C_HTAB into i_finaltab-field3 i_input.
split i_input at C_HTAB into i_finaltab-field4 i_input.
append i_tab.
endloop.
Regards
Praveen
2007 Apr 11 11:20 AM
hi,
if you are in version less than 4.6C
follow the following steps.
1> upload the file using ws_upload
2>declare a variable v_hex type X value 09.
3> split the internal table at v_hex into the internal table with the 3 fields.
incase you are in higher version then
split at space.... rather than declaring a hexadecimal variable
regards,
Navneeth.K
2007 Apr 11 11:20 AM
Method1)
If you use the FM GUI_UPLOAD, then you have to pass the parameter
HAS_FIELD_SEPARATOR = 'X' . Then you will get the data in the corresponding columns automatically.
.
If you do not specify the has_field_separator = 'X', then your internal table wil have record with a string that is separated by tabs.
you have to use the following logic to separate them.
loop at itab.
split itab-data at CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB into itab1-field1 itab1-field2 itab1-field3.
append itab1.
clear itab1.
endloop.
Regards,
Ravi
2007 Apr 11 11:20 AM
Hi,
create ur internal table with 3 fields nad then use FM GUI_UPLOAD TO UPLOAD Tthese data in internal table
Regards,
Sonika
2007 Apr 11 11:23 AM
no need to split , use GUI_UPLOAD and give HAS_FIELD_SEPARATOR = 'X' , it will work
REPORT ZTEST.
DATA : BEGIN OF ITAB OCCURS 0,
FIELD1(10),
FIELD2(10),
FIELD3(10),
END OF ITAB.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'C:Documents and SettingschandrasekharjDesktoptest.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
TABLES
DATA_TAB = ITAB.
LOOP AT ITAB.
WRITE : / ITAB-FIELD1 , ITAB-FIELD2 , ITAB-FIELD3.
ENDLOOP.
2007 Apr 11 11:25 AM
hi,
here is the code to upload tab delimited file go through it
DATA:
BEGIN OF FS_FILE,
FIRST(40),
SECOND(40),
THIRD(40),
END OF FS_FILE.
DATA:
T_FILE LIKE
STANDARD TABLE
OF FS_FILE.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'D:\TEST\FILE.txt'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = T_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.
2007 Apr 11 11:25 AM
Hi,
Use <b>HAS_FIELD_SEPARATOR = 'X'</b> option of GUI_UPLOAD. This definately will solve your problem.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
FILENAME = 'spfli_pser2'
FILETYPE = 'ASC'
HAS_FIELD_SEPARATOR = 'X'
HEADER_LENGTH = 0
READ_BY_LINE = 'X'
DAT_MODE = ' '
CODEPAGE = ' '
IGNORE_CERR = ABAP_TRUE
REPLACEMENT = '#'
CHECK_BOM = ' '
VIRUS_SCAN_PROFILE =
IMPORTING
FILELENGTH =
HEADER =
TABLES
DATA_TAB = T_SPFLI
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.
Regards,
Sandhya
2007 Apr 11 11:26 AM
do this way....
table to place delimiter
DATA: BEGIN OF it_hex,
tab TYPE x,
END OF it_hex.
CONSTANTS: cns_09(2) TYPE n VALUE 09,
c_val1 TYPE c VALUE 'X',
g_deli(1) TYPE c.
ASSIGN g_deli TO <fs> TYPE c_val1.
it_hex-tab = cns_09.
<fs> = it_hex-tab.
loop at i_input.
split it_input at g_deli into it_final-field1 it_input.
split it_input at g_deli into it_final-field2 it_input.
split it_input at g_deli into it_final-field3 it_input.
append it_final.
endloop.
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |