‎2007 Sep 20 12:34 PM
hi all,
I want the contents from the file which is in application server , to be put into the work area fields, but only the first field gets populated, rest remain blank.
the txt file is tab separated.
Here is my sample code.
DO.
READ DATASET fname INTO wa_string.
IF sy-subrc <> 0.
EXIT.
ENDIF.
SPLIT wa_string AT con_tab INTO wa_matstr-matnr wa_matstr-desc
wa_matstr-uom.
MOVE-CORRESPONDING wa_matstr TO wa_mat.
APPEND wa_mat TO i_mat.
ENDDO.con_ab is declared as CONSTANTS: con_tab TYPE x VALUE '09'.
I am working on 4.0B, and wa_string is declared as DATA: wa_string(255) TYPE c.
<b>wa_matstr-desc wa_matstr-uom.</b>---- These two fields remain blank.
<b>Points will be rewarded</b>
Message was edited by:
Runal Singh
‎2007 Sep 20 12:42 PM
Hi,
Try declaring the delimiter as of type CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
i.e, CONSTANTS: con_tab TYPE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
Hope this resolves your issue.
Regards,
Dilli
‎2007 Sep 20 12:38 PM
Hi,
How u opend the Dataset in Text mode/Binary mode.
try to open in Text MODE if u have used Binary mode.
Open dataset <dataset> for INPUT in TEXT MODE ENCODING DEFAULT.
Rvert back if any issues,
Rewrad with points if helpful.
Regards,
Naveen
‎2007 Sep 20 12:40 PM
Try
SPLIT wa_string AT cl_abap_char_utilities=>horizontal_tab INTO wa_matstr-matnr wa_matstr-desc
‎2007 Sep 20 12:40 PM
Hi Runal,
You can directly specify the tab instead of any con_tab.
See this code. It splits and gives the output.
REPORT ZSCRATCHPAD1 .
data : test type string.
data : test1 type string,
test2 type string.
data : loc type int2.
test = 'TEST STRING'.
write :/5 test.
split test at ' ' into test1 test2.
write :/5 test1,/5 test2.
The TEST& STRING are separated by the TAB only directly from Keyboard ( what i meant is its internally taken as tab and not as equivalent spaces ...tats all)..ok.
Try..this seems simple and it works here on 4.6c.Chek in u r system and
Please reward points if useful.
‎2007 Sep 20 12:40 PM
Hi Runal,
Invoke the debugger and check whether wa_matstr is getting populated or not..
Regards,
Sai
‎2007 Sep 20 12:42 PM
Hi,
Try declaring the delimiter as of type CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
i.e, CONSTANTS: con_tab TYPE CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
Hope this resolves your issue.
Regards,
Dilli
‎2007 Sep 20 12:45 PM
CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB.
This gives an error, I am on version 4.0 B. So that wont work, this version of sap is not unicode enabled.
The dataset is opened in text mode.
In debugging mode the wa_matstr is getting poplated with only the 1 st field.
and wa_string gets populated with the data from file properly.
‎2007 Sep 20 1:26 PM
Try doing this:
TYPES:
abap_char1(1) type c.
DATA:
constants HORIZONTAL_TAB type ABAP_CHAR1
value %_HORIZONTAL_TAB.
SPLIT wa_string AT HORIZONTAL_TAB INTO wa_matstr-matnr wa_matstr-desc
Message was edited by:
Aaron Morden
‎2007 Sep 20 1:51 PM
I get an error saying <b>%_HORIZONTAL_TAB</b> is not recognized It is neither in one of the specified tables nor defined by a "DATA" statement..
‎2007 Sep 20 4:42 PM
Running out of ideas, but try this:
data: tab type x value '09'.
SPLIT wa_string AT tab INTO wa_matstr-matnr wa_matstr-desc
‎2007 Sep 21 6:16 AM
‎2007 Sep 21 6:20 AM
Hi Runal ,
Please try using the into table addition with the command split. e.g.
SPLIT V_STRING AT V_DELIMIT INTO TABLE ITAB
here itab will be an internal table of type char , you can specify the length as per your requirement.e.g.
TYPES: BEGIN OF ITAB_TYPE,
WORD(40),
END OF ITAB_TYPE.
Hope this helps.
Regards
Arun
‎2007 Sep 20 12:44 PM
hi
Create an intenal table with exactly the same structure like data in the file and use FM: UPLOAD or
FM: GUI_UPLOAD or
CALL METHOD cl_gui_frontend_services=>gui_upload
Here is the example Program
&----
*& Report ZUPLOADTAB *
*& *
&----
*& Example of Uploading tab delimited file *
*& *
&----
REPORT zuploadtab .
PARAMETERS: p_infile LIKE rlgrap-filename
OBLIGATORY DEFAULT '/usr/sap/'..
*DATA: ld_file LIKE rlgrap-filename.
DATA: gd_file type string.
*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.
*Internal table to upload data into
DATA: BEGIN OF it_datatab OCCURS 0,
row(500) TYPE c,
END OF it_datatab.
*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.
************************************************************************
*AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_INFILE.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR P_infile.
CALL FUNCTION 'WS_FILENAME_GET'
EXPORTING
def_filename = p_infile
mask = ',*.txt.'
mode = 'O'
title = 'Upload File'(078)
IMPORTING
filename = p_infile
EXCEPTIONS
inv_winsys = 1
no_batch = 2
selection_cancel = 3
selection_error = 4
OTHERS = 5.
************************************************************************
*START-OF-SELECTION
START-OF-SELECTION.
gd_file = p_infile.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gd_file
has_field_separator = 'X' "file is TAB delimited
TABLES
data_tab = it_record
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 NE 0.
write: 'Error ', sy-subrc, 'returned from GUI_UPLOAD FM'.
skip.
endif.
Alternative method, where by you split fields at each TAB after you
have returned the data. No point unless you dont have access to
GUI_UPLOAD but just included for information
*
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = gd_file
filetype = 'ASC'
TABLES
data_tab = it_datatab "ITBL_IN_RECORD[]
EXCEPTIONS
file_open_error = 1
OTHERS = 2.
IF sy-subrc NE 0.
ELSE.
LOOP AT it_datatab.
CLEAR: wa_string, wa_uploadtxt.
wa_string = it_datatab.
SPLIT wa_string AT con_tab INTO wa_uploadtxt-name1
wa_uploadtxt-name2
wa_uploadtxt-age.
MOVE-CORRESPONDING wa_uploadtxt TO wa_record.
APPEND wa_record TO it_record.
ENDLOOP.
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.
thanks,
reward if helpful...