2009 Aug 23 7:43 AM
Dear ABAP Experts,
I have a internal table with line size of 2161 characters. On 2161 character I am putting CL_ABAP_CHAR_UTILITIES=>CR_LF, but when this file is downloaded in FTP server as extension TXT. Viewing the file in html format it shows a blank line after each record. I have tried putting only CR and only LF at 2161 character but still I am facing the same problem of getting a blank line in between each line.
I tried replacing CL_ABAP_CHAR_UTILITIES=>CR_LF with CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB but no luck.
Can someone suggest where I am going wrong.
Regards,
Vaibhav Patil.
I was just answering that maybe your program is correct (linefeed in unix is LF = 0A in ascii); in windows it's CRLF = 0D0A in ascii, but as you display the file in html (it's what you say), it's normal you see them as blanks instead of new lines.
2009 Aug 23 9:06 PM
html means that all carriage returns, tabs and blanks are considered as ... blanks (and several subsequent blanks as one blank)
So, if you have to view the file as html, you should add html tags for carriage returns (like pre, br, etc.)
2009 Aug 24 7:07 AM
Thanks for the reply.
But the user wants line feed of type UNIX not of WINDOWS.
So how do I achieve this in SAP. I tried the option of open dataset with UNIX linefeed option but still I get blank lines between each record. I tried the following sample so that i don't mess up with my actual code.
REPORT ZTEST11.
TYPES : BEGIN OF WA_RES1,
LINE(10) TYPE C,
END OF WA_RES1.
Data : str TYPE WA_RES1 OCCURS 0 WITH HEADER LINE.
DATA: USER(30) TYPE C,
PWD(30) TYPE C,
HOST(64) TYPE C,
CMD1(80) TYPE C,
CMD2(80) TYPE C,
CMD3(80) TYPE C,
CMD4(80) TYPE C,
DEST LIKE RFCDES-RFCDEST,
COMPRESS TYPE C VALUE 'N'.
DATA: HDL TYPE I,
KEY TYPE I VALUE 26101957,
SLEN TYPE I,
COMMAND_INDEX TYPE I.
DATA: BEGIN OF RESULT OCCURS 0,
LINE(300) TYPE C,
END OF RESULT.
DATA DOCID LIKE SYSUUID-C.
constants:
c15_crlf TYPE c VALUE cl_abap_char_utilities=>cr_lf.
DATA: LIST LIKE RESULT OCCURS 0 WITH HEADER LINE.
DATA: DATA LIKE RESULT OCCURS 0 WITH HEADER LINE.
DATA : IT_RES TYPE WA_RES1 OCCURS 100 WITH HEADER LINE.
DATA : WA_RES TYPE WA_RES1.
DATA: FNAME(60).
start-of-selection.
CLEAR STR.
str-LINE+0(7) = 'VAIBHAV'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(4) = 'TEST'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(8) = 'UNIVERSA'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(7) = 'VAIBHAV'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(4) = 'TEST'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(8) = 'UNIVERSA'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(7) = 'VAIBHAV'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(4) = 'TEST'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(8) = 'UNIVERSA'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(7) = 'VAIBHAV'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(4) = 'TEST'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(8) = 'UNIVERSA'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
CLEAR STR.
str-LINE+0(7) = 'VAIBHAV'.
STR-LINE+9(1) = c15_CRLF.
APPEND STR.
USER = 'ftpspcc'.
PWD = 'ftp4spcc'.
HOST = 'SPCC-SAPWEBDP'.
SLEN = STRLEN( PWD ).
CALL FUNCTION 'HTTP_SCRAMBLE'
EXPORTING
SOURCE = PWD
SOURCELEN = SLEN
KEY = KEY
IMPORTING
DESTINATION = PWD.
CLEAR : HDL.
CALL FUNCTION 'FTP_CONNECT'
EXPORTING
USER = USER
PASSWORD = PWD
HOST = HOST
RFC_DESTINATION = 'SAPFTP'
IMPORTING
HANDLE = HDL
EXCEPTIONS
NOT_CONNECTED = 1
OTHERS = 2.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CONCATENATE 'FILE' SY-UZEIT '.TXT' INTO DOCID.
CLEAR : CMD1, LIST.
REFRESH : LIST.
CMD1 = 'cd SPCCFTP/Panalpina_PO/'.
IF CMD1 NE ' '.
LIST-LINE = CMD1.
APPEND LIST.
ENDIF.
CALL FUNCTION 'FTP_COMMAND_LIST'
EXPORTING
HANDLE = HDL
TABLES
DATA = DATA
COMMANDS = LIST
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF SY-MANDT = '310' OR SY-MANDT = '510'.
CONCATENATE 'D:\usr\sap\put' 'FILE' SY-UZEIT '.TXT' INTO FNAME.
ENDIF.
OPEN DATASET FNAME FOR OUTPUT IN TEXT MODE ENCODING DEFAULT WITH UNIX LINEFEED.
IF SY-SUBRC = 0.
LOOP AT STR.
TRANSFER STR-LINE TO FNAME LENGTH 10.
ENDLOOP.
ENDIF.
CLOSE DATASET FNAME.
OPEN DATASET FNAME FOR INPUT IN TEXT MODE ENCODING DEFAULT WITH UNIX LINEFEED.
IF SY-SUBRC = 0.
DO.
READ DATASET FNAME INTO WA_RES. "LV_LINE is variable to hold line contents being read
IF SY-SUBRC EQ 0.
* TRANSFER WA_RES TO WA_RES LENGTH 10.
APPEND WA_RES TO IT_RES.
CLEAR WA_RES.
ELSE.
EXIT.
ENDIF.
ENDDO.
ENDIF.
CLOSE DATASET FNAME.
CALL FUNCTION 'FTP_R3_TO_SERVER'
EXPORTING
HANDLE = HDL
FNAME = DOCID
* BLOB_LENGTH = L_BLOB
CHARACTER_MODE = 'X'
TABLES
TEXT = IT_RES
EXCEPTIONS
TCPIP_ERROR = 1
COMMAND_ERROR = 2
DATA_ERROR = 3
OTHERS = 4.
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ELSE.
MESSAGE 'File successfully uploaded to FTP server.' TYPE 'S'.
ENDIF.
2009 Aug 24 8:14 AM
I was just answering that maybe your program is correct (linefeed in unix is LF = 0A in ascii); in windows it's CRLF = 0D0A in ascii, but as you display the file in html (it's what you say), it's normal you see them as blanks instead of new lines.
2009 Aug 24 9:20 AM
Ya its correct but what my partner is doing is he is downloading the file from FTP and opening in his UNIX system so he is not able to upload the file in his UNIX system as he can see a blank line after each record. Can we avoid these somehow?
Is the code something to do with OPEN dataset??
Regards.
2009 Aug 24 10:01 AM
I had not looked at your code. Because you open it in text mode, each line transferred is automatically ended with a line end character (SAP adds it). So you have 2 line feeds!
Please do not use CRLF (windows only).
2009 Aug 24 12:10 PM
Ok I got your clue. Suppose currently I am having 10 lines in my internal table for each record if we don't do append and at last we append the internal table then the data is coming correctly with no blank lines. But it can accept only a maximum of 65535 charcters. So here we will have problem.
Is there any way by which we remove the line end charcter that is added by SAP system for each APPEND statement.
2009 Aug 24 8:09 PM
I don't understand what you want to achieve. Why do you have 10 lines per record ? Why do you append one line for each field ? (I guess VAIBHAV, TEST, UNIVERSA, are the column names). If lines are 2161 characters wide, why don't you use a structure with fixed length columns ?
line = 2161 characters
TRANSFER line TO dataset "automatically ended with LF
line = other 2161 characters
TRANSFER line TO dataset "automatically ended with LF
etc.
2009 Aug 25 7:42 AM
You have been confused dear.
The 2161 character is my actual requirement. But as I am doing many permutation combinations in my program I so I have created another test program which I have pasted in the thread.
In my test program :-
constants:
c15_crlf TYPE c VALUE cl_abap_char_utilities=>cr_lf.
TYPES : BEGIN OF WA_RES1,
LINE(10) TYPE C,
END OF WA_RES1.
Data : str TYPE WA_RES1 OCCURS 0 WITH HEADER LINE.
str is my Internal table with following values.
str-LINE+0(4) = 'TEST'.
str-LINE+9(1) = c15_CRLF.
APPEND STR.
str-LINE+0(8) = 'UNIVERSA'.
str-LINE+9(1) = c15_CRLF.
APPEND STR.
str-LINE+0(7) = 'VAIBHAV'.
str-LINE+9(1) = c15_CRLF.
APPEND STR.
Now If I download this internal table in FTP server I get the data as
Output :-
TEST
UNIVERA
VAIBHAV
Blank lines after each record, so I manuplated this as you said that SAP puts a line end character after each line. And following was the result.
TYPES : BEGIN OF WA_RES1,
LINE(65535) TYPE C,
END OF WA_RES1.
Data : str TYPE WA_RES1 OCCURS 0 WITH HEADER LINE.
data : l_pos type i.
str was filled with data as follows :-
str-LINE+0(4) = 'TEST'.
str-LINE+9(1) = c15_CRLF.
l_pos = strlen( str-LINE ).
str-LINE+l_pos(8) = 'UNIVERSA'.
l_pos = strlen( str-LINE ).
l_pos = l_pos + 1.
str-LINE+l_pos(1) = c15_CRLF.
l_pos = strlen( str-LINE ).
str-LINE+0(7) = 'VAIBHAV'.
l_pos = strlen( str-LINE ).
l_pos = l_pos + 2.
str-LINE+l_pos(1) = c15_CRLF.
APPEND STR.
I did append at last for the whole internal table. So the output was as wanted without blank line in between each records, but the limit of characters is 65535. As you cannot know how much characters will be fetched for a single run.
Output :-
TEST
UNIVERA
VAIBHAV
So I was thinking is there any other way of appending the data for each line without the addition of SAP system's line end character for each append statement.
I think now you are very much clear.
Regards,
Vaibhav Patil.
2009 Aug 25 8:36 AM
okay but you DON'T need to manage the LFs by yourself. Why don't use just transfer line by line as I said above. The LFs will be automatically added, don't do it yourself. Why do you want to do "without the addition of SAP system's line end character" ?
| User | Count |
|---|---|
| 4 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |