on 11-23-2011 1:37 PM
Hi All,
I have a requirement whereby the last occuring carriage return in a file, produced from a receiver communication channel, should be removed in order for the file produced to be successfully integrated into the target system.
Currently
Line 1 CR
Line 2 CR
Line 3 CR
<- Cursor pointing on new line
Should be:
Line 1 CR
Line 2 CR
Line 3
Line.endSeparator = 'nl'
I have tried isolating the last line in the mapping with the hope of changing the 'LastLine.endSeparator' but in vain; still a carriage return present.
I was wandering whether a shell script might exist for doing this?!? Or Xslt Mapping? Or custom file receiver adapter?
Would anyone have any idea?
Thanks in advance.
Vincent
1. are you using variable substitution? Why is that cr return coming? Ideally this happens when you use var substitution so its better to use ASMA and dynamic conf.
2. Another alternative is to write a simple module to remove that line feed or an unix script.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
1. are you using variable substitution? Why is that cr return coming? Ideally this happens when you use var substitution so its better to use ASMA and dynamic conf.
2. Another alternative is to write a simple module to remove that line feed or an unix script.
Hi,
I am not using variable substitution. I don't see any use of variable substitution in that case as I am not changing the content of the filename, but its content. I.e. Only the last line.
I have put CR to represent carriage return. the "endSeparator" function gives a carriage return by default.
I think that the second option might solve the issue. Would it mean adding a module to the "Module" tab of the communication channel?
I have implemented a VBScript that can do the trick and I am wandering whether this logic could be applied in a module and added to the Module tab of the communication channel. Please advise?!?
Thanks in advance.
Hi Vincent,
I don't think you can use a module for this requirement because any module will execute before the work that happens as part of the file adapter. That means that you would have to read the file from an FTP location or NFS and remove the last carriage return if you went the module route. That being said an OS level shell script would be much simpler than all of that.
Regards,
Ryan Crosby
Hi Ryan,
I agree with you point of view. The file would need to be read (from the FTP server in my case) and the carriage return on the last line spotted and removed.
Thus, an OS level shell script would seem more appropriate.
Now, I would need to find out how to write this!
Any clue please?
Best regards,
Vincent
Hi,
if I'm not wrong, according to me you have this carriage return, because your PI create the file in a windows file server, whereas your legacy should be on a Unix server, which does not like this carriage return (CR), but prefer to have end of line (LF).
Here a [link with some intrusctiions|http://www.computing.net/answers/programming/remove-carriage-return-at-file-end/17101.html], and with google, I'm sure you will find more.
Regards
mickael
Hi All,
Here is a clue I got in VBScript for removing the carriage return from the last line of the file:
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\Test.txt", ForReading)
strFile = objFile.ReadAll
objFile.Close
intLength = Len(strFile)
strEnd = Right(strFile, 2)
If strEnd = vbCrLf Then
strFile = Left(strFile, intLength - 2)
Set objFile = objFSO.OpenTextFile("C:\Documents and Settings\Test.txt", ForWriting)
objFile.Write strFile
objFile.Close
End If
I still need to build an OS shell script for that. Can someone help please???
Also, I would like to specify a directory only and the code would apply to the file being produced in that directory.
Hi Vincent,
I checked this out and writing a shell script to connect to an FTP site and download the file for modification is a little
tricky because if it requires a username and password it expects keyboard input (there's a way around this supposedly but it didn't work for me). I could definitely do this with a shell script if I were to write a .jar file to do the file downloading & manipulation and then put the file back on the FTP site.
Regards,
Ryan Crosby
Hi Vincent,
If the operating system of target system is windows based, then by default '\r' and '\n' will be at end of each line within a file. This will be inserted automatically when a file is saved in any folder of the target system. You have provided a sample VB code to remove the newline and carriage feed in your post. Just do one checking on the file size and content after new file is written. You will find if the contents of both the file are same, their sizes are also same, but since you removed last two characters, the file size should have been reduced by 2 bytes, but this does not happen, as the operating system automatically inserts the EOL characters, once you save the file. Hence a batch file written to remove last two bytes won't work in this case.
To tackle this problem I would suggest two steps
1. Ensure in last message mapping, no new line or carriage return is inserted in the last line.
2. In the receiver file adapter go to Define Processing Parameters------->File Type as "binary" instead of text.
Hope this solves your problem.
Regards
Anupam
hi Vincent,
by searching another topic (adapter module), I found this help [Adding Code Example from Adapter Development to Module Processor |http://help.sap.com/saphelp_nwpi711/helpdata/en/96/f04142099eb76be10000000a155106/content.htm], under which we can read:
The example module provided by SAP converts the character that indicates the end of a line in Microsoft Windows, CarriageReturn+LineFeed (CRLF), to the character that indicates the end of a line in Unix, LineFeed (LF), or the other way around..
module name SAP XI Sample/ConvertCRLFfromToLF
...
.
I let you to read complety this short page, but it seems your needs could be acheive easily. (could be)
Mickael
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.