‎2006 May 04 8:00 AM
The Flat file(.txt) has 5 fields separated by vertical bars(|). this fils has to be uploaded using the FM 'UPLOAD'.
Here the problem is, the internal table is not taking the individual field values, but it is taking the values of 2 or 3 fields into one field.
Kindly guide me on this.
I have also tried with 'ws_upload' and 'gui_upload'
eg. of flat file, given below,
500076|1003|01012005|31012005|8552000.00|8952000.00|22200|002|I
500076|1004|01012005|31012005|2690000.00|2748000.00|88900|003|I
‎2006 May 04 8:03 AM
Hi girish,
1. Exactly for this purpose,
i have developed an independent FORM
where we give inputs
a) file name (eg. abcd.txt)
b) separator (eg | in your case)
c) internal table (eg. t001)
2. It will provide the data
in proper format
(no matter what the separator)
(it can work with any kind of separator)
3. just copy paste in new program.
REPORT abc.
*----
*----
change your table declaration and file name
*----
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
PERFORM myupload TABLES t001 USING 'd:\t001.txt' '|'.
BREAK-POINT.
*----
in debug see t001
*----
INDEPENDENT FORM
*----
FORM myupload TABLES orgtab
USING filename separator.
*----
Data
DATA : BEGIN OF itab OCCURS 0,
myline(1000) TYPE c,
END OF itab.
DATA : extension(5) TYPE c.
DATA : name(100) TYPE c.
DATA : newfilename TYPE string.
*----
Step 1
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
TABLES
data_tab = itab.
*----
Step 2
LOOP AT itab.
REPLACE ALL OCCURRENCES OF separator IN itab-myline WITH
cl_abap_char_utilities=>horizontal_tab.
MODIFY itab.
ENDLOOP.
*----
Step 3
DATA : path LIKE pcfile-path.
path = filename.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = path
CHECK_DOS_FORMAT =
IMPORTING
DRIVE =
extension = extension
name = name
NAME_WITH_EXT =
PATH =
EXCEPTIONS
invalid_drive = 1
invalid_extension = 2
invalid_name = 3
invalid_path = 4
OTHERS = 5
.
*----
Step 4
newfilename = filename.
REPLACE name IN newfilename WITH 'temp'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = newfilename
TABLES
data_tab = itab
FIELDNAMES =
.
*----
Step 5
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = newfilename
has_field_separator = 'X'
TABLES
data_tab = orgtab.
ENDFORM. "myupload
3.
regards,
amit m.
‎2006 May 04 8:03 AM
Hi girish,
1. Exactly for this purpose,
i have developed an independent FORM
where we give inputs
a) file name (eg. abcd.txt)
b) separator (eg | in your case)
c) internal table (eg. t001)
2. It will provide the data
in proper format
(no matter what the separator)
(it can work with any kind of separator)
3. just copy paste in new program.
REPORT abc.
*----
*----
change your table declaration and file name
*----
DATA : t001 LIKE TABLE OF t001 WITH HEADER LINE.
PERFORM myupload TABLES t001 USING 'd:\t001.txt' '|'.
BREAK-POINT.
*----
in debug see t001
*----
INDEPENDENT FORM
*----
FORM myupload TABLES orgtab
USING filename separator.
*----
Data
DATA : BEGIN OF itab OCCURS 0,
myline(1000) TYPE c,
END OF itab.
DATA : extension(5) TYPE c.
DATA : name(100) TYPE c.
DATA : newfilename TYPE string.
*----
Step 1
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = filename
TABLES
data_tab = itab.
*----
Step 2
LOOP AT itab.
REPLACE ALL OCCURRENCES OF separator IN itab-myline WITH
cl_abap_char_utilities=>horizontal_tab.
MODIFY itab.
ENDLOOP.
*----
Step 3
DATA : path LIKE pcfile-path.
path = filename.
CALL FUNCTION 'PC_SPLIT_COMPLETE_FILENAME'
EXPORTING
complete_filename = path
CHECK_DOS_FORMAT =
IMPORTING
DRIVE =
extension = extension
name = name
NAME_WITH_EXT =
PATH =
EXCEPTIONS
invalid_drive = 1
invalid_extension = 2
invalid_name = 3
invalid_path = 4
OTHERS = 5
.
*----
Step 4
newfilename = filename.
REPLACE name IN newfilename WITH 'temp'.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
filename = newfilename
TABLES
data_tab = itab
FIELDNAMES =
.
*----
Step 5
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = newfilename
has_field_separator = 'X'
TABLES
data_tab = orgtab.
ENDFORM. "myupload
3.
regards,
amit m.
‎2006 May 04 1:08 PM
‎2006 May 04 8:03 AM
Hai girish
Check with filetype parameter in GUI_Upload
if it is ASC -- then give total field lenght
Thanks & regards
Sreenivasulu P
‎2006 May 04 8:04 AM
Hi Girish,
Upload is obsolete, try out GUI_UPLOAD n use has_field_separator = '|'.
Hope it helps,
Regards
‎2006 May 04 8:05 AM
use internal table
with single field of 255
The CONCATENATE statement combines two or more separate strings into one.
CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].
To split a character string into two or more smaller strings, use the SPLIT statement as follows:
SPLIT <c> AT <del> INTO <c1> ... <cn>.
The system searches the field <c> for the separator <del>. The parts before and after the separator are placed in the target fields <c1> ... <cn>.
and use GUI_upload
regards
vinod
‎2006 May 04 8:09 AM
Hi Girish,
did you pass the Parameter FIELD_SEPARATOR = 'X' to the Gui_Upload FM.
Regards
vijay
‎2006 May 04 8:13 AM
Hi Grish
Please see the length of fields of internal table.
Actually, your program is not able to know - till what point you want it to read data for a particular field.
Your fields in flat file must be seperated by suitable number of spaces (equal to internal table field length - (minus) actual length in text file.
e.g.
Internal table has follwoing fields:
A1 type char(4).
A2 type char(6).
A3 type Char(3).
and data in text file is:
ABC def GHI
Then it should be there as ABC followed by one space, then def followed by 3 spaces and so on.
Ragards
Ashish Jain