09-04-2006 4:37 AM
Hi All.
By default, SAP inserts an end-of-line character when transferring data to the "dataset". we do not want the empty line at the end.
Here is my code :
OPEN DATASET file_path FOR OUTPUT IN BINARY MODE
ENCODING DEFAULT
WITH SMART LINEFEED
MESSAGE msg.
IF sy-subrc = 0.
LOOP AT itab INTO wa.
l_off = STRLEN( wa ).
TRANSFER wa TO file_path LENGTH l_off NO END OF LINE.
ENDLOOP.
CLOSE DATASET file_path.
ELSE.
" Error that file_not_opened.
ENDIF.
As you see, I have tried all possible ways : Opening in binary format, text format, writing with length specification, no end of line - but a blank line is always coming at the end.
Any clues?
Thanks in adv.
Samant
09-04-2006 5:03 AM
Hi,
Try the following code :
data : l_string type string.
OPEN DATASET file_path FOR OUTPUT IN BINARY MODE
ENCODING DEFAULT
WITH SMART LINEFEED
MESSAGE msg.
IF sy-subrc = 0.
LOOP AT itab INTO wa.
concatenate wa l_string into l_string
separated by `09`.
ENDLOOP.
TRANSFER l_string TO file_path.
CLOSE DATASET file_path.
ELSE.
" Error that file_not_opened.
ENDIF.
Best regards,
Prashant
09-04-2006 5:03 AM
Hi,
Try the following code :
data : l_string type string.
OPEN DATASET file_path FOR OUTPUT IN BINARY MODE
ENCODING DEFAULT
WITH SMART LINEFEED
MESSAGE msg.
IF sy-subrc = 0.
LOOP AT itab INTO wa.
concatenate wa l_string into l_string
separated by `09`.
ENDLOOP.
TRANSFER l_string TO file_path.
CLOSE DATASET file_path.
ELSE.
" Error that file_not_opened.
ENDIF.
Best regards,
Prashant
09-04-2006 9:56 AM
Solved it. Actually no problem in the code. I was using CG3Y to download file to local pc from app server, and i was transferring in ASC format due to which an additional line break was being inserted.
Thanks anyway for all your inputs.
Points awarded.
09-04-2006 5:27 AM
Hi !
You'll have to open it in TEXT MODE ... otherwise
you will not have a CF/LF at the end of any line.
Single CR/LF at the End-Of-File ?!?
It may help the check you "wa" if it's not initial...
Regards
Rainer
Some points would be nive if that helped a bit.
09-04-2006 6:32 AM
HI samant,
1. Probaby there might be some minor
mistake in your code.
2. Other wise BINARY mode
is the only way of making such file
without the line feed character.
regards,
amit m.
09-04-2006 6:58 AM
Rainer, Prashant -> i think u misunderstood my requirements. I DO NOT want carriage return. It is being appended by default which we don't want because the file will be used to do a CRC Checksum type of thing and because of the carriage return, the checksum is coming wrong.
amit : That's the exact code I am using. Can you tell me where is it wrong? You can test it yourself. Itab can be like this:
DATA : BEGIN OF itab OCCURS 0 ,
text(140),
END OF itab.
APPEND 'test1234' TO itab.
then the remaining code which i pasted before.
Thanks again.
09-04-2006 8:00 AM
Hi Samant,
Here is the program, i have tested it and its working fine.
REPORT ztest1 .
DATA : BEGIN OF itab OCCURS 0 ,
text(140),
END OF itab.
DATA : wa TYPE itab,
file_path TYPE rlgrap-filename VALUE '/tmp/zt.txt',
l_off TYPE i.
APPEND 'test1234' TO itab.
APPEND 'abcdefghijklmnopqrstuvwxyz' TO itab.
APPEND 'test1234' TO itab.
OPEN DATASET file_path FOR APPENDING IN BINARY MODE.
ENCODING DEFAULT
WITH SMART LINEFEED
*MESSAGE msg.
IF sy-subrc = 0.
LOOP AT itab INTO wa.
l_off = strlen( wa ).
TRANSFER wa TO file_path LENGTH l_off.
ENDLOOP.
CLOSE DATASET file_path.
ELSE." Error that file_not_opened.
ENDIF.
Best regards,
Prashant
08-11-2021 4:34 PM
Hi Samant,
I am facing similar issue like the check sum value is coming wrong !
File has to be in text mode in out case , still end of the line we are getting CR/LF and which is giving wrong checksum.
Will someone help me on this.
Regards,
Srini