Creating a text file output from ABAP
Hi
I'm trying to create a comma delimited text file by using ABAP code
Could someone please help me with my coding in the following areas or is there better coding to do it:
1)Is there a way to move the entire Customer file KNA1 into my text file instead of doing it field by field.
2)How can I do the comma seperation correctly?
REPORT ZTEXTFILE.
data: lt_kna1 type table of kna1.
data: ls_kna1 type kna1.
data: lv_filename type string value 'ztest.txt'.
select * from kna1 into table lt_kna1.
open dataset lv_filename for output in text mode encoding default.
IF sy-subrc <> 0.
WRITE :/ 'ERROR'.
EXIT.
ENDIF.
loop at lt_kna1 into ls_kna1.
transfer ls_kna1-kunnr to lv_filename.
transfer ';' to lv_filename.
transfer ls_kna1-name1 to lv_filename.
transfer ';' to lv_filename.
endloop.
close dataset lv_filename.
WRITE :/ 'DONE'.
Many thanks
Gerhard
REPORT ZTEXTFILE.
data: lt_kna1 type table of kna1,
ls_kna1 type kna1,
lv_filename type string value 'ztest.txt',
lv_file type string.
select * from kna1 into table lt_kna1.
open dataset lv_filename for output in text mode encoding default.
IF sy-subrc ne 0.
WRITE :/ 'ERROR'.
EXIT.
else
loop at lt_kna1 into ls_kna1.
CONCATENATE ls_kna1-kunnr ls_kna1-name1 into lv_file separated by ','.
transfer lv_file to lv_lilename.
clear lv_file.
endloop.
close dataset lv_filename.
endif.
WRITE :/ 'DONE'.
Try this out, should do the trick. Also, may i suggest not using '*' in your select statement and fetch data only for the fields you wish to have in your text file after filtering using a where Claus. It would greatly improve performance.
Edited by: AJ Nayak on Feb 9, 2012 11:05 AM
Similar Messages
-
Create a text file output from within a procedure
I can output to a file from within SQL+ using the spool command but how do I do this from within a procedure?
I have got a table called ABC and want to output columns A and B to a new text file based on variables pased through when the procedure is run, the name of the text file should be generated from a sequence?
Any info appreciated.
Cheers
CliffHi,
U can use UTL_File Package, But the only constraint is it will write the file only on the server m/c and not on the client m/c.
Regards
Gaurav -
How to create a text file from jsp?
In JSP, what is the command to create a text file and dump a variable in it?
You mean StringBuffer?
-
HOw to create a text file in the given path and delete it after the use?
Hi all,
I am trying to create a text file at the given path and delete the created file after the use.
I am using following code.:
import java.io.*;
// write binary data as characters
public class RanIO {
public static void main(String f[])
// First illustrate append
String lineSep = "\n";
try {
File temp= new File("C:/Ash","cute.txt");
boolean ch=temp.createNewFile();
if(ch)
System.out.println("file created");
else
System.out.println("file Not created");
//writing to file
/* PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("cute.txt",true)));
p.print("Emp NO");
p.close();*/
// Open fileWriter in append mode
FileWriter fos = new FileWriter(temp, true);
BufferedWriter bw = new BufferedWriter(fos);
PrintWriter pw = new PrintWriter(fos);
double d=550;
// lineSep = System.getProperty("line.separator");
pw.print("Hello");
//pw.print( lineSep );
pw.print( d );
pw.close();
boolean det=temp.delete();
if(det)
System.out.println("File deleted");
else
System.out.println("File not deleted");
} catch (IOException ioe)
System.out.println( "Append IO error:" + ioe );
My problem:
1)
I am not able to write to the file. I want to know, where i am going wrong.
It is giving error message like
"Canot resolve Symbol: temp,"
But, FileWriter Constructor should accept a File type parameter.
here temp is a file parameter.
If i am not using file=new file();
i can't delete the file after the use. i.e if i use
PrintWriter p = new PrintWriter(new BufferedWriter(new FileWriter("cute.txt",true)));
how can i delete cute.txt after the use?
2)
I am not able to write to the text file. file is created but, a blank file.
"Hello" is not written into the text file.
can anyone help me in this regard
Thanks in advance
AshviniThank you Ram,
But, i want to create a text file in Append mode.
for that i used
FileWriter fos = new FileWriter(temp,true); But, it is not accepting FileWriter constructor in
this format. if i use
FileWriter fos = new
FileWriter("c:/ash/cute.txt",true); it works fine. !!!!!Here's the javadoc
public FileWriter(File file,
boolean append)
throws IOExceptionConstructs a FileWriter object given a File object. If the second argument is true, then bytes will be written to the end of the file rather than the beginning.
Parameters:
file - a File object to write to
append - if true, then bytes will be written to the end of the file rather than the beginning
Throws:
IOException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason
Since:
1.4
Are you using jdk.13 or lower ?
>
ONe more doubt, Does flush method deletes a file?
if not, then i need to use
File temp=new File("c:/ash/cute.txt");
FileWriter fos = new FileWriter(temp,true); //which
is again a problem
if(temp.delete())
out.println("File is deleted");
}I don't know whether i am taking it wrong ! or
anything wrong with my coding ! but, after creating
and writing data into a text file. I must delete it
as it contains confidential informations.
Regards,
Thanks.'flush' writes to a file immediately. Else you should explicitly call 'flush' to write contents from buffer to underlying source.
javadoc again
PrintWriter
public PrintWriter(Writer out,
boolean autoFlush)Create a new PrintWriter.
Parameters:
out - A character-output stream
autoFlush - A boolean; if true, the println, printf, or format methods will flush the output buffer
cheers,
ram.
Question; What do you gain by opening a file, writing to it and deleting it in the same program ? -
How to print PDF file content from ABAP in background?
Hi,
Is it possible to print PDF file content from ABAP in background?
I have some PDF content which I need to print it, these PDF files are generated outside the SAP.
Please have you any suggestions?
Thank you
Tomas<b><u>Solution:</u></b><br>
<br>
The target output device must support PDF print, this is only one limitation.<br>
<br>
REPORT z_print_pdf.
TYPE-POOLS: abap, srmgs.
PARAMETERS: p_prnds LIKE tsp01-rqdest OBLIGATORY DEFAULT 'LOCL',
p_fname TYPE file_table-filename OBLIGATORY LOWER CASE,
p_ncopi TYPE rspocopies OBLIGATORY DEFAULT '1',
p_immed AS CHECKBOX.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_fname.
DATA: lv_rc TYPE i,
lv_filter TYPE string.
DATA: lt_files TYPE filetable.
FIELD-SYMBOLS: <fs_file> LIKE LINE OF lt_files.
CONCATENATE 'PDF (*.pdf)|*.pdf|' cl_gui_frontend_services=>filetype_all INTO lv_filter.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
file_filter = lv_filter
CHANGING
file_table = lt_files
rc = lv_rc
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0 AND lv_rc EQ 0.
MESSAGE 'Error' TYPE 'E' DISPLAY LIKE 'S'.
ENDIF.
READ TABLE lt_files ASSIGNING <fs_file> INDEX 1.
IF sy-subrc EQ 0.
p_fname = <fs_file>-filename.
ENDIF.
AT SELECTION-SCREEN.
DATA: lv_name TYPE string,
lv_result TYPE boolean.
lv_name = p_fname.
CALL METHOD cl_gui_frontend_services=>file_exist
EXPORTING
file = lv_name
RECEIVING
result = lv_result
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
MESSAGE 'Bad file!' TYPE 'E' DISPLAY LIKE 'S'.
ENDIF.
IF lv_result NE abap_true.
MESSAGE 'Bad file!' TYPE 'E' DISPLAY LIKE 'S'.
ENDIF.
START-OF-SELECTION.
END-OF-SELECTION.
PERFORM process.
FORM process.
DATA: lv_name TYPE string,
lv_size TYPE i,
lv_data TYPE xstring,
lv_retcode TYPE i.
DATA: lt_file TYPE srmgs_bin_content.
lv_name = p_fname.
CALL METHOD cl_gui_frontend_services=>gui_upload
EXPORTING
filename = lv_name
filetype = 'BIN'
IMPORTING
filelength = lv_size
CHANGING
data_tab = lt_file
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
MESSAGE 'Read file error!' TYPE 'E' DISPLAY LIKE 'S'.
ENDIF.
CALL FUNCTION 'SCMS_BINARY_TO_XSTRING'
EXPORTING
input_length = lv_size
IMPORTING
buffer = lv_data
TABLES
binary_tab = lt_file
EXCEPTIONS
failed = 1
OTHERS = 2.
IF sy-subrc NE 0.
MESSAGE 'Binary conversion error!' TYPE 'E' DISPLAY LIKE 'S'.
ENDIF.
PERFORM print USING p_prnds lv_data CHANGING lv_retcode.
IF lv_retcode EQ 0.
WRITE: / 'Print OK' COLOR COL_POSITIVE.
ELSE.
WRITE: / 'Print ERROR' COLOR COL_NEGATIVE.
ENDIF.
ENDFORM. " PROCESS
FORM print USING iv_prndst TYPE rspopname
iv_content TYPE xstring
CHANGING ev_retcode TYPE i.
DATA: lv_handle TYPE sy-tabix,
lv_spoolid TYPE rspoid,
lv_partname TYPE adspart,
lv_globaldir TYPE text1024,
lv_dstfile TYPE text1024,
lv_filesize TYPE i,
lv_pages TYPE i.
CLEAR: ev_retcode.
CALL FUNCTION 'ADS_SR_OPEN'
EXPORTING
dest = iv_prndst
doctype = 'ADSP'
copies = p_ncopi
immediate_print = p_immed
auto_delete = 'X'
IMPORTING
handle = lv_handle
spoolid = lv_spoolid
partname = lv_partname
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
ev_retcode = 4.
RETURN.
ENDIF.
CALL FUNCTION 'ADS_GET_PATH'
IMPORTING
ads_path = lv_globaldir.
CONCATENATE lv_globaldir '/' lv_partname '.pdf' INTO lv_dstfile.
OPEN DATASET lv_dstfile FOR OUTPUT IN BINARY MODE.
IF sy-subrc NE 0.
ev_retcode = 4.
RETURN.
ENDIF.
TRANSFER iv_content TO lv_dstfile.
IF sy-subrc NE 0.
ev_retcode = 4.
RETURN.
ENDIF.
CLOSE DATASET lv_dstfile.
IF sy-subrc NE 0.
ev_retcode = 4.
RETURN.
ENDIF.
CALL FUNCTION 'ZBAP_RM_PDF_GET_PAGES'
EXPORTING
iv_content = iv_content
IMPORTING
ev_pages = lv_pages.
lv_filesize = XSTRLEN( iv_content ).
CALL FUNCTION 'ADS_SR_CONFIRM'
EXPORTING
handle = lv_handle
partname = lv_partname
size = lv_filesize
pages = lv_pages
no_pdf = ' '
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
ev_retcode = 4.
RETURN.
ENDIF.
CALL FUNCTION 'ADS_SR_CLOSE'
EXPORTING
handle = lv_handle
EXCEPTIONS
OTHERS = 1.
IF sy-subrc NE 0.
ev_retcode = 4.
RETURN.
ENDIF.
ENDFORM. " PRINT -
Not able to create a text file in Client Machine using Forms 10g
Hi - I'm mot able to create a text file in Client Machine using Forms 10g. I'm getting error when system executes the bolded line.(i.e. CLIENT_TEXT_IO.FOPEN). During run-time system is throwing "ORA-06508: PL/SQL: could not find program unit being called".
I had attached webutil.pll in the form.
Please advise me.
DECLARE
l_Temp CLIENT_TEXT_IO.FILE_TYPE;
LC$Name Varchar2(100) ;
LC$Fic Varchar2(100) ;
LN$Lines Pls_integer := 0 ;
LC$Line Varchar2(4000) ;
Cursor C_CUR Is
Select * From TEST_TEXTIO where rownum <= 50;
BEGIN
LC$Name := 'tmp_file.txt' ;
LC$Fic := 'c:\temp\tmp_file.txt';
Begin
l_temp := CLIENT_TEXT_IO.FOPEN( 'C:\temp\tmp_file.txt', 'W');
Exception
when others then
message( 'OPEN FILE ERROR ' || LC$Fic ||sqlerrm );
display_error;
raise form_trigger_failure;
End ;
-- Write the lines --
For Cur In C_CUR Loop
LC$Line := Cur.CODE || ' -> ' || Cur.COL1 || ',' || Cur.COL2 || ',' || Cur.Col3 ;
CLIENT_TEXT_IO.PUT_LINE( LF$File, LC$Line ) ;
LN$Lines := C_CUR%ROWCOUNT ;
End loop ;
-- Close the file --
CLIENT_TEXT_IO.FCLOSE( LF$File ) ;
Exception
When others Then
message('err='||sqlerrm);message(' ');
display_error;
CLIENT_TEXT_IO.FCLOSE( LF$File ) ;
Raise ;
END;
Thanks.
ArunHi ,
i have one Question though its not related to thos question if some could help me it will be really helpful,
i have created one program to import and export excel to forms vice versa, if the form is attached with webutil its working fine am using ole2.but i have a new idea if i add this program in menu, it can be used for all the forms attched to that menu, i made program also, but problem am facing right now is if the form is not attched with webutil it will not work so is there possiblity to share my webutil from one form to another form ,so i will keep one form as a interface form in that webutil will be attched ,i can share that webutil to all other forms so that all the forms no need to attach webutil again
if its possible means please suggest some ideas -
"Import from Text File" & "Upload from Clipboard" icon not appearng in F110
Hi Experts,
While making the payment to the vendors through TN F110, in "PARAMETER" screen just next to 'STATUS' screen, there is a vendor field for selection in range and just ahead of this there is an icon for multiple vendor selection ( Bold arrow mark ). If I click on that multiple vender selection icon ( on bold arrow mark ), an another screen opens for multiple selection for vendors. In this screen 'Enter, Copy, Delete etc' icons are appearing at the bottom of the screen but "Import from Text File" & "Upload from Clipboard" icon are not appearing there.
Can you please let me know how to bring that icons there?
Points would be awarded.
Rgds,
ShaileshHi Ravi,
I have not yet created anything and have just entered the parameter. In the multiple screen for vendors there are 5 fields for individual and 5 for range selection. Even you can put more than five range selections or individual selections by clicking on the page button but there I am not finding these two icons.
Can you please check at your end and let me know if you are getting or what to do to bring those two icons in F110.
Rgds,
Shailesh -
How can I add a "Create New Text File" contextual menu?
Hi,
I'd like to add a "Create New Text File" contextual item. I found the "new text file" action in Automator, but I don't really know where to go from there... I want it to work on the desktop and in finder...
ThanksSee:
Mac OS X Automation,
Automated Workflow Tips,
Introduction to Automator tutorial, and
a four-parter on Automation in Snow Leopard by Sal Saghoian:
Snow Leopard Services,
Services for iPhoto,
Safari and WebKit integration, and
Installing and using services.
Finally,
Developing AppleScript Applications and
Apple's Automator Developer Documentation -
How to create a text file with data.
Hi,
I am writing java code for testing an application, some times test can failed in some cases, I want to display an error message in text file. To that I written the code as like,
BufferedWriter bout;
bout =new BufferedWriter(new FileWriter("test.txt"));
String str=Your input data is not match with pattern
bout.write(str);but here it is creating a text file test without any data in it.
Can any body help that to execute the program properly
Regards
Bunttysabre150 wrote:
JoachimSauer wrote:
You didn't close your BufferedWriter. Since it's buffered it probably didn't write anything to the underlying file.
Generally you must close every Writer/OutputStream that you no longer use or it won't be written reliably.It's not quite as simple as that. If you have a chain of Writers / OutputStreams then you only have to close() the outer most one since each is responsible for closing any Writer/OutputStream that it wraps. If you do decide to close them individually (a bad idea but people do do it) then you MUST close them starting from the outer most one and working to the most inner one or you will not guarantee to flush any buffered content.Of course. I might have used a misleading phrasing here. What I meant is "Every time you are done with a Writer, you must close it" and not "You must close *every* Writer that you used". Thanks for the clarification. -
Create new text file in UTF-8 format by default
I'm working a lot with UTF-8 text files and mainly in this format. It's becoming annoying when I have to manually save every text file as UTF-8. After several trial-and-errors, I've made up a procedure that I've put in a blog. I think I could share
it here for those who need it. Hope it helps.
http://instrumenti-meliora.blogspot.com/2014/04/create-new-text-file-in-utf-8-format-by.htmlYou've made a procedure?
Are you sure you didn't :
Didn't what?
https://www.google.com/#q=change+notepad+default+encoding
Well, I'm not sure what you want me to see, but your search keywords do
NOT make sense. You do note change *Notepad* default encoding. What you can change is a
TEXT file's default encoding.
Well, of course, if you have access to Notepad source code and you're able to change it and re-compile again, then you could really say you change Notepad's "default encoding", which I suppose would mean "default encoding every time we save".
Why wouldn't you just provide a link (or some attribution) to the top result
http://answers.microsoft.com/en-us/windows/forum/windows_7-windows_programs/default-utf-8-encoding-for-new-notepad-documents/525f0ae7-121e-4eac-a6c2-cfe6b498712c
or a link to watch this done on youtube?
http://www.youtube.com/watch?v=GnL6smxQE9k
The title of that forum post and Youtube video is a non-sense. New
"Notepad" document? Come on! That's apparently how a newbie think what it is and it's very likely he has not a clue what it is and what he is doing. And what if I don't use Notepad to create such file? If I
use UltraEdit, then mine should be "UltraEdit" document and that should be different from Notepad document, correct? LOL
The fact that you're able to find this video would also mean you're thinking like him in that the file is really called Notepad document LOL
For your information, that's called a text file (or document if you prefer this prettier term). It's also called plain text file.
Now, let's see the content of both links:
First of all, why did they tell people to create a new text file somewhere and then
COPY it to template folder? That's really so dumb
LOL Isn't it more intelligent to create such file directly INSIDE the folder?
Secondly, their procedures are not foolproof. What if the Windows directory is not c:\windows? They should tell people to open %Systemroot%\ShellNew instead. I suppose they don't even know how this folder is called because
nowhere is the term "template folder" ever mentioned.
Thirdly, what if that folder doesn't work for unknown reason (which might happen in XP)? Did they give any hint to a "failover" folder? No, they didn't. But I do in my procedure.
Fourthly, they are saying as if the file name has to be "TXTUTF-8.txt", but actually we can call it whatever we like. But smart people would have figured this out at the end.
5 (I'd stop saying fifthly and so on LOL) I'm not sure it's necessary (or recommended) to change "fSavePageSettings" & "fSaveWindowPositions" DWORD values for Notepad as "advised" in that answer.
As a side-note, I don't know what
http://www.pc1news.com/saving-changes-to-notepad-configuration-1216.html is supposed to give but when I open this, I got some uTorrent warning. Really seems like some malware webpage which tries to deceive people!
I actually searched how a (generic) new file is created and started from there.
So, maybe next time when you want to criticize or discredit somebody else, try to be more expert first? ;) -
What is the fastest as well as less memory intensive way to create large files.
Current State
I have an application where I am reading the database and processing the information (formatting it) and using some third party API to add the information and then finally save as text file. The problem is since its third party API and we do not have any control on that and it takes very long time to generate the files
Future state
I want to build the file generator which will read from the database and then process/format the information one by one. Now I have following options.
1) Add the processed information in a StringBuffer line by line and at the end of it create a file from the StringBuffer and save it.
2) Create a custom object with different ArrayLists and keep on adding the processed lines into appropriate lists and at the end of it while saving it to a file read the custom object and save it as a file.
3) Create a file at the start of it and then keep on adding and flushing the lines one by one and at the end of it close the file.
For handling files I was thinking of using PrintWriter. I am talking about the text files anyware from 50 KB to 20 MB.
I have performance concerns as well as memory issues. So I want a balanced solution so that I am able to handle both.Use a BufferedWriter to write each line/entry/record as you process it.
Don't do any special flushing() (unless you need special transactional properties in which case you need a lot more than simple flush() calls). -
How to create a text file or XML file and add content through code into it...
Hi Everyone,
How to create a text file and add content through the code to the text file eform javascript ......orelse can we create a text file in life cycle designer...
Else say how to create a new XML file through the code and how some content like Example "Hello World".You can create a text file as a file attachment (data object) using the doc.createDataObject and doc.setDataObjectContents:
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.450.html
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.528.html
You can then export the file with the doc.exportDataObject method:
http://livedocs.adobe.com/acrobat_sdk/9.1/Acrobat9_1_HTMLHelp/JS_API_AcroJS.88.463.html
This won't work with Reader if it hasn't been given the file attachment usage right with LiveCycle Reader Extensions. -
I was given an assingment, but have no idea where to begin. The assingment is to create a text file using notepad with all of my digital inputs and some how make those imputs show up on my digital indicators on my control pannel.
When it was explained to me it didn't sound to hard of a task, I have no LabVIEW experience and the tutortial sucks.StevenD: FYI, I did NOT give you the one star rating. I would never do that!
StevenD wrote:
Ow. Someone is grumpy today.
Well, this is an assignment, so it is probably homework.
Why else would anyone give HIM such an assigment, after all he has no LabVIEW experience and the tutorials are too hard for him?
This would make no sense unless all of it was just covered in class!
This is not a free homework service with instant gratification.
OK! Let's do it step by step. I assume you already have a VI with the digital indicators.
"...but have no idea where to begin".
open notepad.
decide on a format, possibly one line per indicator.
type the document.
close notepad.
open LabVIEW.
Open the existing VI with all the indicators.
(are you still following?)
look at the diagram.
Who made the program?
Does the code make sense so far?
Is it a statemachine or just a bunch of crisscrossed wires?
Where do you want to add the file read?
How should the file be read (after pressing a read button, at the start of the program ,etc.)
See how far you get!
Message Edited by altenbach on 06-24-2008 11:23 AM
LabVIEW Champion . Do more with less code and in less time . -
Function upload text file or from clipboard in Bex with BI 70
Will it be possbile to use the function to upload data in from a text file or from clipboard with BI 70?
With older BW versions it was possible to fill a variable with lists.
Can someone help where I can find information about this issue?
Best Regards, TinaWill it be possbile to use the function to upload data in from a text file or from clipboard with BI 70?
With older BW versions it was possible to fill a variable with lists.
Can someone help where I can find information about this issue?
Best Regards, Tina -
hi
can anyone tell me how to create a number of text file using a different variable in java.the exact definition is like this "different variables are stored in a text file and each time it has to open this file, take these as their file name and create a text file"new File(thevariable)
Maybe you are looking for
-
What is the best way to get the applications, pictures, music, data, etc from my iBook G4 to my MacBook Pro. I currently back up my entire system to an external hard drive. So do I install that to the new MacBook, use a flash drive, other options. Th
-
Hi, I was just about to push the "Check Out Now" button on a black MacBook when I decided to visit the Discussions area- now I'm wondering if I should hit that check out button at all. It seems like these MacBooks are having more than a few problems,
-
Generic delta; When R/3 record deleted.
Hi all Please tell me What will happen to the BW record when the record in R/3 add-on table is deleted and the data is retrieved by generic delta. (1)At the beginning. R/3 BW 20051124000001 100$ -> 20051124000001 100$
-
Editing ''Titles'' of Events in library, BLACK? How do i change this?
Hi there Mac friends. When Editing the name of an event in the event library, the text turns blue. This i expect. But when choosing to edit one letter or word within the event name, the text background turns dark grey. This is very hard to see black
-
Last year, When I decided to upgrade my Lombard to Tiger, I looked around and found the Tiger CD's on Apple Rescue for a great price. When I wanted to get a second copy for my Wallstreet, Apple Rescue was no longer to be found. My question is: Do I h