Read Dataset Line by line
hi,
I have a text file in application server which is formed line by line. Each line has variable length. How can i use the open dataset to put the data line by line to internal table??
Regards,
Kit
open dataset <dsname> for input in text mode encoding default.
do.
read dataset <dsname> into v_rec.
if sy-subrc = 0.
<ur code>
endif.
endo.
Here<b> text mode</b> reads the content line by line...
Also check the below link.
http://help.sap.com/saphelp_nw04/helpdata/en/79/c554a0b3dc11d5993800508b6b8b11/content.htm
Regards,
Maha
Similar Messages
-
Upload read dataset only one line
hi all
i have a problem, i want to upload a file from applikation server. When i want to read dataset into a xstring field,
it read only the first line not all why?
here is my code
type-pools dset.
data lf_filename type string value '/opt/interface/indtrans/d58_sst/integrale/output/PLU.plu'.
data lf_line type xstring.
data lf_str_line type string.
data lf_hex_code type swxmlcont.
data lt_attr type dset_attributes.
start-of-selection.
open dataset lf_filename for input in binary mode.
do.
read dataset lf_filename into lf_line.
if sy-subrc <> 0.
exit.
else.
* get dataset lf_filename attributes lt_attr.
append lf_line to lf_hex_code.
endif.
enddo.
close dataset lf_filename.
thx abap_begin....that to be functional, but when i read with the file with cl_gui_frontend_services=>gui_upload with file Typ "BIN"
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
FILENAME = l_filename
FILETYPE = 'BIN'
* HAS_FIELD_SEPARATOR = SPACE
* HEADER_LENGTH = 0
IMPORTING
FILELENGTH = l_size
* HEADER =
CHANGING
data_tab = lt_data
EXCEPTIONS
FILE_OPEN_ERROR = c_not_found
FILE_READ_ERROR = 3
INVALID_TYPE = 4
NO_BATCH = 5
GUI_REFUSE_FILETRANSFER = 7
others = 99.
i becam a other result then, when i read with
open dataset lf_filename for input in binary mode.
why?
Now i have a idea, i read the file value in text mode and save this in an internal table.
Then make the loop over table, and convert the value in identical princple such as cl_gui_frontend_services=>gui_upload with the filetype "BIN".
I dont' know, how you do this?
thx abap_begin -
Reading a dataset line by line
I have a datset with header items and the remaining line items . I have managed to read the header in a structure with a single READ DATASET.... phrase . For the first line item i have again written the READ DATASET statement and managed to get the contents in an internal table of a different structure. How can i get the remaing line items of similar structure in an internal table using a loop???
You read the dataset by doing a DO loop, the system will know to read each line by line, when the READ fails, that means there is no more lines to read and the EXIT statement will make the program come out of the loop.
Do.
read dataset ds into xstr.
if sy-subrc <> 0.
exit.
endif.
* Here check which kind of line you have just read
* whether it is a header, or line item and append
* to the correct internal table.
Enddo.
Regards,
Rich Heilman -
Error on line read dataset p_zfile into it_int
hi while executing this below code..
open dataset p_zfile for input in text mode ENCODING DEFAULT.
if sy-subrc = 0.
v_one = 1.
do.
v_no = v_no + 1.
*read dataset pzfile into it_record*_ this is giving short dump as below
code to read file
end do
short dump
the following error is being prompted
CONVT_CODEPAGE
CX_SY_CONVERSION_CODEPAGE
A character set conversion is not possible.
At the conversion of a text from codepage '4110' to codepage '4103':
- a character was found that cannot be displayed in one of the two
codepages;
- or it was detected that this conversion is not supported
where
it_record is type infile_struct,
and infile_struct is as below
types: begin of infile_struct,
data(1150) type c,
end of infile_struct.
and p_zfile is used in fm call file_get_nam
please suggest this code is working fine in 4.6 c not upgraded to SAP ECC 6.0 this error is occuring in the code
regarda
arorahere is code
open dataset p_infile for input in text mode ENCODING DEFAULT.
f sy-subrc = 0.
v_one = 1.
do.
v_no = v_no + 1.
read dataset p_infile into in_record. if sy-subrc = 0. here dump is occuring at last record i deleted the last record in the file but again the dump comes on last record only when all records are read and finally when the cursor come to read dataset statement last time
if v_no <> v_one.
split in_record at v_tab into wa_record-idno
wa_record-stonumber
wa_record-stolineno
wa_record-sched_line
wa_record-pur_group
wa_record-frmplant
wa_record-frmstglocatin
wa_record-toplant
wa_record-tostglocation
wa_record-material
wa_record-matdesc
wa_record-quantity
wa_record-dockdate
wa_record-splinst1
wa_record-splinst2
wa_record-splinst3
wa_record-splinst4
wa_record-delete
wa_record-block. -
Hi,
I'm transferring data through an ABAP program to a file in background. The data is transferred ok, but the whole data gets inserted in the file as a single line.
I'm using the commands: OPEN DATASET file FOR OUTPUT IN TEXT MODE and all its variants ENCODING, LINEFEED, etc and also try ending my row data with CL_ABAP_CHAR_UTILITIES constants for end of lines (it is takes as Text and gets concatenated in the row).
Is there any way in which the data in the file writes in the new lines instead of one line?
Thanks & regardsHey Sebastien,
While transferring data, You should do it in a loop and endloop. And then close the dataset. Also I always recommend you to take a Field in the ITAB with some Flag or some Name like Tabnam so that you can always play with the data as you want.
Example : if you are transferring QMEL table data make sure your structure will be like mentioned below.
TYPES : BEGIN OF ty_qmel,
qmnum TYPE qmel-qmnum, "NOTIFICATION NUMBER
qmart TYPE qmel-qmart, "NOTIFICATION TYPE
tabname TYPE char10, "TABLE NAME FOR IDENTIFICATION-----> This makes you to identify which table data it is.
END OF ty_qmel,
Then While reading the data transfered from one system A(Data transferred from) to another system B(reading the Transfered data). It will be easy if you do like this.
OPEN DATASET file FOR INPUT IN TEXT MODE ENCODING DEFAULT MESSAGE gv_mes IGNORING CONVERSION ERRORS.
DO.
READ DATASET file INTO gv_string.
If sy-subrc = 0.
IF gv_string CS 'QMEL'. -
> Note you can always Identity which table data it is
CALL METHOD cl_abap_container_utilities=>read_container_c
EXPORTING
im_container = gv_string
IMPORTING
ex_value = wa_qmel
EXCEPTIONS
illegal_parameter_type = 1
OTHERS = 2.
APPEND wa_qmel TO it_qmel.
Endif.
Else.
Exit
Endif.
ENDDO.
CLOSE DATASET file.
Hope this helps,
Regards,
Bhargav. -
BAPI to read and change schedule lines in APO
Hello experts,
We want to firm schedule lines inside the firm zone of the APO procurement scheduling agreements with a daily job. For this we are trying to use BAPI BAPI_POSRVAPS_GETLIST3 and BAPI_POSRVAPS_SAVEMULTI3. The getlist one does not return schedule lines, it returns purchase orders and purchase requisitions. Are these the right bapis to read and change schedule lines in APO? or is there anyother one we can use?
Thanks and regards,
ErgulHi,
You can use the below code to read the schedule lines.
Checking a session exists
CALL FUNCTION '/SAPAPO/RRP_SIMSESSION_GET'
IMPORTING
ev_simsession = gv_sims
es_gen_params = gv_params.
If not create a new session and read it
IF gv_sims IS INITIAL.
CALL FUNCTION '/SAPAPO/RRP_SIMSESSION_CREATE'
IMPORTING
ev_simsession = gv_sims.
CALL FUNCTION '/SAPAPO/RRP_SIMSESSION_GET'
IMPORTING
ev_simsession = gv_sims
es_gen_params = gv_params.
g_cre_chk = 'X'.
ENDIF.
CALL FUNCTION '/SAPAPO/CMDS_TPSRC_GET'
EXPORTING
iv_ebeln = p_l_t_acknh_ebeln
iv_ebelp = p_l_t_acknh_ebelp
TABLES
et_tpsrc_all = lt_tpsrc
EXCEPTIONS
matid_not_found = 1
locfrom_not_found = 2
locto_not_found = 3
scheduling_agreement_not_found = 4
error_selecting_schedagreement = 5
OTHERS = 6.
IF sy-subrc = 0.
reading the scheduling agreement records
READ TABLE lt_tpsrc INTO ls_tpsrc INDEX 1.
CALL FUNCTION '/SAPAPO/PWB_BZQID_GET_ORDER'
EXPORTING
iv_simid = '000'
iv_bzqid = ls_tpsrc-bzqid
IMPORTING
ev_ordid = lv_iordid
EXCEPTIONS
lc_connect_failed = 1
no_elements = 2
unit_conversion_failed = 3
OTHERS = 4.
IF sy-subrc = 0.
CALL FUNCTION '/SAPAPO/PWB_GET_RELATED_ORDERS'
EXPORTING
iv_ordid = lv_iordid
iv_order_type = '16'
iv_simid = '000'
IMPORTING
ev_ordid = lv_eordid
EXCEPTIONS
order_not_found = 1
lc_connect_failed = 2
no_elements = 3
OTHERS = 4.
IF sy-subrc = 0.
APPEND lv_eordid TO lt_ordid.
CALL FUNCTION '/SAPAPO/DM_PO_READ'
EXPORTING
iv_simsession = gv_sims
is_gen_params = gv_params
it_ordid = lt_ordid
IMPORTING
et_schedule = p_lt_sched
EXCEPTIONS
lc_connect_failed = 1
lc_com_error = 2
lc_appl_error = 3
OTHERS = 4.
ENDIF.
ENDIF.
ENDIF.
Use '/SAPAPO/CMDS_SNP_MM_ORD_MODIFY' function module to change the schedule lines (Pass '16' to iv_order_type parameter).
Let me know if u have any issues.
Regards,
Siva. -
Text file: reading char one at a time line by line
I need to read an external .txt file, one character at a time, line by line, and compare each character in order to do various things. The problem is that when I use the Buffered Reader I have only readLine() method and others to work with, but none that actually read a character at a time, and line by line. The program has to read a character, then move to the next one and read it, and so on. Then move to the next line, and read the first character, and so on. I am working with chars not Strings. Could you please help me with this problem?
InputStreamReader can read a single char.
InputStreamReader isr = new InputStreamReader(InputStream in);
isr.read(); will return 1 character from "in". -
I want to read the contents of a file to a text item line by line dynamical
I have created a timer
tm_id := FIND_TIMER('LOG_READING_TIMER');
If Id_Null(tm_id)
then
tm_id := create_timer('LOG_READING_TIMER', 1000, REPEAT);
else
set_timer (tm_id, 1000, REPEAT);
end if;
/* executed the shell script on application server */
host(v_command,no_screen);
and used below code for reading a file in when timer expired
DECLARE
v_file_name := '/home/log.txt' /* log created during running shell script */
BEGIN
v_infile := Text_IO.Fopen(v_file_name , 'r');
loop
Text_IO.Get_Line(v_infile,v_linebuf);
:CONTROL.item:= :CONTROL.item||v_linebuf||chr(10);
end loop;
WHEN no_data_found THEN
Text_IO.Fclose(v_infile);
delete_timer('LOG_TIMER');
END
I want to read a log file which is created while runnning shell script line by line
dynamically
Above code is reading the log filebut all the lines are shown at once.
I have to display
each line on the text item
and the next line line by line
Can anyone help me how to achieve this.
Thanks,
in advanceIn when-button-pressed trigger
I have called a shell script on application server using host command
HOST('Path of script',NO_SCREEN);
Shell script writes some set of statements to log file on application server
Problem is to read the log file on to the multiline text item each line simultaneosly
while running the script.
Below is the procedure i have written to achieve this but below code is writing all the lines at once
after entire complete execution of shell script.
for example
shell script writes tolog file:
1. 'Loading of tables';
then loads the data
2. 'emailing data';
3. ...
4. ...
Below code writes
all the 4 lines at once
I want to see in frontend what is going on while running the script
by reading the log file data line by line
WHEN-BUTTON-PRESSED
tm_id := FIND_TIMER('LOG_READING_TIMER');
If Id_Null(tm_id)
then
tm_id := create_timer('LOG_READING_TIMER', 1000, REPEAT);
else
set_timer (tm_id, 1000, REPEAT);
end if;
/* executed the shell script on application server */
host(v_command,no_screen);
WHEN-TIMER-EXPIRED
and used below code for reading a file in when timer expired
DECLARE
v_file_name := '/home/log.txt' /* log created during running shell script */
BEGIN
v_infile := Text_IO.Fopen(v_file_name , 'r');
loop
Text_IO.Get_Line(v_infile,v_linebuf);
:CONTROL.item:= :CONTROL.item||v_linebuf||chr(10);
end loop;
WHEN no_data_found THEN
Text_IO.Fclose(v_infile);
delete_timer('LOG_TIMER');
END
While running the script on application server
I want to see the data from log file simulataneously on to the form when the data is written on to the log file
Please let me know if you need more details.
Thanks,
in advance -
How to read line by line in GUI_UPLOAD for long line?
Hi,
when i read a file use GUI_UPLOAD line by line, i can't get a whole line maybe for the restrained line size in the function. can i set the max line size by myself ? so i can read a whole line.
if not, i just image maybe i can set the read mode to a ' stream file', and then i read N(line size ) characters each time, but how shoulld i do ?
thanks!Hi,
In abap output length is 255 charcters only
so you can see 255 char only in your internal table but internal table contains all the data.
so if you want to see or print remaining data better to use wa_itab+255(255) to print other data .
i hope this is helpful to u..
reward if needful -
How to read from a file line by line
Hi
I am new to using LabView and was wondering how I could read data from a text file one line at a time and display this data one line at a time as well. I tried looking through the Reading from Text File . vi example but that just seems to be reading and displaying everything together.
Thanks
-KaranHi
My aim is to read text line by line and to then go ahead and display the last 8 reaad lines of code to give the impression of text falling down a screen. I tested the first while loop and that seemed to work fine. However, when I encounter an EOF, I would like the text already read to keep making its way down the screen and keep inputting NULL characters into the array to simulate the effect of the text falling down the screen which is why I created the second while loop. I tried to input the NULL characters using a box for ENUM constants. However, I kept getting an error saying the data types do not match. What would I need to do? For the display I plan on putting indicators next to the 8 places where the text would be stored which I have not done so far.
I am also attaching a copy of the error.
Thanks
-Karan
Attachments:
DisplayText.vi 40 KB
Error.JPG 89 KB
PictureOfBlock.JPG 120 KB -
Hi
Could somebody tell me how to read file line by line ? Namely my input file I want to read look as follow:
AAA 1, 1
12 222 12
AAA 2, 2
11 122 11
My output file should look as follow:
1, 1, 12
1, 1 222
1, 1, 12
2, 2, 11
2, 2, 122
2, 2, 11
I think the lines need to be stored in ArrayList, then I would like those lines to write to csv file, but how on read I can construct such output file? This is my code for reading file
public ArrayList readFile(String filename)
try
BufferedReader in = new BufferedReader(new FileReader(filename));
ArrayList list = new ArrayList();
String lineS = null;
while (in.ready())
if ((lineS = in.readLine()).startsWith("")){
String[] line = in.readLine().trim().split("\\s+");
list.add(Integer.valueOf(line[0]));
list.add(Integer.valueOf(line[1]));
list.add(Integer.valueOf(line[2]));
in.close();
return list;
catch (Exception e)
e.printStackTrace();
return null;
ThanksThe rules for the conversion from input to the desired output are:
1. For each of the line with string take 2 integers for example 1, 1 from AAA 1, 1
2. Then repeat 1, 1 for each next number not containing any string, so if the line after AAA, 1, 1 has 12, 222, 12 then the output will look as follow
1, 1, 12
1, 1 222
1, 1, 12
3. Repeat the process (the pattern is the same 1 line with string 1 line with numbers)
Actually I am not sure how to perform that logic for such conversion as for now I am only able to list only the numbers but I have a problem to add numbers from the line having string in it.
STOP!
You should NOT be writing code if you are 'not sure how to perform that logic'.
You are getting ahead of yourself.
There is NOTHING to gain by trying to code a solution before you know what algorothm you need. Big mistake.
Should I use list or maybe if the patter for lines is the same array will be more sufficient?
NEITHER ONE!
Those are 'solutions' used to implelment an algorothm.
You do NOT yet know what algorithm you need to use so how can you possibly write code to implement the unknown?
How to perform logic to get the numbers from line having string and for the next lines having only numbers in order to structure it into desired output?
THAT is the question your thread subject should have.
Until you get the answer to it don't write any code,.
Do NOT try to automate what you can't do manually.
Write down, on paper or use an editor, the step by step 'logic' you need and walk through that logic from beginning to end until the 'logic' works and produces the correct result.
You just now have started to do that when you listed those rules above.
But you left some things out. Expand on that list of 'rules' and provide a little more example data. TPD has given you a good example. Reread what they said.
Did you notice they start by talking about 'tasks': what each task does and the order the tasks need to be performed.
That 'task list' has NOTHING to do with Java, C, or any other language: it is identifying the problem/algorithm. Until you have that coding is premature. -
How to read a file line by line in UTL
Hi All,
DECLARE
fileID UTL_FILE.FILE_TYPE;
strbuffer VARCHAR2(100);
BEGIN
fileID := UTL_FILE.FOPEN ('DR', 'New.txt', 'R');
UTL_FILE.GET_LINE (fileID, strbuffer);
dbms_output.put_line(strbuffer);
END;
By this program I can read only first line of the file. I want to read the file line by line.
Thanks
Suniltry this
DECLARE
fileID UTL_FILE.FILE_TYPE;
strbuffer VARCHAR2(100);
BEGIN
fileID := UTL_FILE.FOPEN ('DR', 'New.txt', 'R');
if utl_file.is_open(fileID) THEN
loop
UTL_FILE.GET_LINE (fileID, strbuffer);
dbms_output.put_line(strbuffer);
if strbuffer IS NULL THEN
exit;
end if;
end loop;
end if;
END;note: untested. -
Powershell read CSV file line by line and only first header
I have a CSV file, which reads like this:
read, book
read1, book1
read2, book2
I want to read only the first value, before comma one line at time,
meaning first time it will be
read
read1
read2
no headers and i want to pass that value to a variable for a if condition.
I have script it read line by line but it reads both values before coma and after line by line, so instead of having three values i'm ending with 6 values.
$file = Import-CSV c:\script\server.csv
$file | ForEach-Object {
foreach ($property in $_.PSObject.Properties)
$property.Name
$property.Value
#replace = $property.ValueIf you can work with headers then do so as it will make your life easier.
with a csv file called server.csv like this:
headername1, headername2
read, book
read1, book1,
read2, book2
and this bit of code
$file = Import-CSV c:\script\server.csv
#output to host, file or directly pipe the command above.
foreach($cell in $file.headername1){ if($cell -eq $something){ }}
will evaluate the content of each cell to $something.
This is because Powershell will grab the first row and claim that as a header name.
So whatever you put in cell A1 in excell will end up as name of the first collumn and its corresponding property (e.g. $file.A1 oor $file.headername1 if you will). -
What is the best way to read a file line by line?
Hello, everyone!
I want to read a file line by line, i.e. each time, a line of a text file is read and stored as a String object and the String object will be manipulated (parsed) later.
I have found that FileInputStream does not have a function which is responsible for reading a line each time from a text file. Anyone have good suggestions?
Best regards,
GeorgeI always use the following example.. mayb that would help you as well
File fid = new File(fileName);
if (fid.exists())
fr = new FileReader(fid);
br = new BufferedReader(fr);
while((txtstr= br.readLine()) != null)
} -
Read the file line by line from upload
Hi Guys,
Need help... I creating a web application that has a upload capability. What I want to do is this...
I want to upload a file (but not save it). What I'm going to do is just read the file line by line and save these data to the database. How can I do this? (BTW, I'm using struts (FormFile)).
Please guide me please!
Thanks.i think u should obtain a inputstream from request object and then save it to the database using BLOB object.
Maybe you are looking for
-
Why is selected text in the Twitter search box not highlighted?
Selected text in the Twitter search box is not highlighted. It should be highlighted. So far as I've noticed, this is the only place where my system doesn't highlight text properly. I can't find any references to this problem with the Twitter search
-
SAP Script Form - manual / guide
Hi Experts, I want to modify a SAPScript form where I want to insert a field at the right hand side of a line. For the tag column , I put 'IL' just follow the previous line. the line begins like this: ,,,,,,,,&field& (is doesn't go to right end), bu
-
Updating A child Table As Administrator
Hello Eevryone, I read a post here http://forums.adobe.com/thread/463635. And i first off want to commend you guys on your awesome contribution to novices like me. I understand the technique presented here but I have a different problem though. I hav
-
Hi all, what is ABAP Workflow?? How is program it for abap programming? now i am doing first time in workflow.. send me workflow materials and details of workflow? workflow program.. reply me soon, thx, s.suresh
-
Hello, I was wondering if it's possible to link to an image that's on a webserver and not on a local machine. So without downloading the image first. Kind regards, Michel