09-22-2008 4:03 PM
Hello!
I'm using the following line in my program to write a row from an itab to a file:
OPEN DATASET gv_outbfile FOR OUTPUT IN TEXT MODE ENCODING NON-UNICODE MESSAGE lv_errmsg.
When I download the file to my PC I notice that there's only a LF (0A) character at the end of the line. My functional guy wants a CR/LF pair at the end of each row so it will display properly in Notepad. How can I get the CRLF on the end of each row?
09-22-2008 4:38 PM
You need to check addition LINEFEED & SET in open dataset
DATA: file TYPE string VALUE 'test1.dat',
pos TYPE i,
text TYPE string.
OPEN DATASET file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED.
TRANSFER: 'Line1' TO file,
'Line2' TO file,
'Line3' TO file.
SET DATASET file POSITION 0.
READ DATASET file INTO text.
SET DATASET file POSITION END OF FILE.
TRANSFER: 'Line4' TO file,
'Line5' TO file,
'Line6' TO file.
CLOSE DATASET file.
a®
09-22-2008 4:15 PM
Hi,
CONCATENATE
'Username'
'Password'
'First Name'
'Last Name'
'Group Code'
'Location'
'Email'
'PersonnelNumber'
'DepartmentName'
'EVP'
'EVP-1'
'Function'
cl_abap_char_utilities=>CR_LF
INTO lv_str
This statement will give you a carriage return at the end of line.
There are more attributes in the class CL_ABAP_CHAR_UTILITIES like Line feed, Tab etc etc.
Amandeep
09-22-2008 4:27 PM
I'm getting the CRLF alright but now the file is truncated. It's supposed to be exactly 195 (each row is).
So, I added LENGTH 195 to the TRANSFER statement and re-ran. This causes the text to wrap in Notepad.
09-22-2008 4:30 PM
Try to open dataset in binary mode and transfer each line with crlf at the end
09-22-2008 4:38 PM
You need to check addition LINEFEED & SET in open dataset
DATA: file TYPE string VALUE 'test1.dat',
pos TYPE i,
text TYPE string.
OPEN DATASET file FOR OUTPUT IN TEXT MODE
ENCODING DEFAULT
WITH SMART LINEFEED.
TRANSFER: 'Line1' TO file,
'Line2' TO file,
'Line3' TO file.
SET DATASET file POSITION 0.
READ DATASET file INTO text.
SET DATASET file POSITION END OF FILE.
TRANSFER: 'Line4' TO file,
'Line5' TO file,
'Line6' TO file.
CLOSE DATASET file.
a®
09-22-2008 4:47 PM
I also found WITH WINDOWS LINEFEED which seems to work just fine. Any caveats with that one that you know of?
09-22-2008 4:51 PM