on 02-13-2012 2:49 AM
Hello everyone,
Its a Mail to File scenario. There is no mapping involved in this scenario.
There is a XLS file coming as an attachment and this needs to be dropped in FTP server.
But there are 7 reports and i want to use only one communication channel.
So if the File name is A then it has to be renamed as B. If the file name is C then it has to be renamed as D.and so on ...
How to achieve this. ?
Regards,
Ravi
Dear Ravi
The best way is to use the Run Operating System Command after Message Processing.
If there are multiple files then write a script and execute it via Command Line:
the script should contain commands like mv A.xsl B.xsl
Sourabh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Could you please let me know what code needs to be written .
And how to put it in Run command .
pls refer beloe blogs:
http://forums.sdn.sap.com/thread.jspa?threadID=1776003&tstart=0
Dear Ravi
First of all this method can be utilized only when the files to be renamed are in PI server itself.
Lets say you want to rename A.XSL to B.XSL and C.XSL to D.XSL
Write a script (Save this file as renameFile.sh) and place it in the directrory which is mounted in PI server (you can find it using TCode AL11)
Script should be like this
#!/bin/sh
mv <path>/A.xsl <path>/B.xsl
mv <path>/C.xsl <path>/D.xsl
Now in your receiver file adaptor write following in Command LIne
/sh renameFile.sh
Hope this helps
Sourabh
Ravi,
Refer this blog for help on the ABAP renaming of files: http://forums.sdn.sap.com/thread.jspa?threadID=116104.
Once you have this sorted then create an event in your PI system via trans SM62. Now create a new background job in SM37 that points to the rename ABAP and that is activated once the PI event takes place.
Include the following in the "Run operating system command after message processing" in the Receiver Comms channel.
sapevt [event name] name=[PI system name. Like PID, PIP etc]
So, when PI places the file onto the server it records an event telling the operating system to do something. The job in SM37 will then only run after the event takes place and will rename your files to whatever you want. This way you have control over what is taking place and ikf you need to you can stop the rename ABAP from running if you need to and PI then does not to be touched.
Hope this helps. But please look at the other suggestions posted as these are all valid.
Regards
Mike G
Edited by: Michael Greer on Feb 13, 2012 10:04 PM
Correction for SAPEVT. HTTP tag not required and was added in error. SAPEVT EVENT_NAME NAME=PI SYTEM
You can use Java mapping to do that, use this mapping program in Operation mapping in your ID interface determination. Here is a sample code of it, You can use case statement to put your conditions.
public class RenameFile extends AbstractTransformation {
private static final DynamicConfigurationKey KEY_FILENAME =
DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
public void transform(TransformationInput in, TransformationOutput out)
throws StreamTransformationException {
String newFileName = null;
Date date = new Date(); // get the current date
SimpleDateFormat dateFormatter = new SimpleDateFormat ("yyyyMMddHHmmss"); // set the format for date
String dfmt = dateFormatter.format(date);
DynamicConfiguration conf = in.getDynamicConfiguration();
String oldFileName = conf.get(KEY_FILENAME); // filename is <store_ID>.txt
newFileName = dfmt + oldFileName; // Final file will have date in file name
String inData = convertStreamToString(in.getInputPayload().getInputStream());
String outData = inData;
try {
out.getOutputPayload().getOutputStream().write(outData.getBytes("UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
conf.put(KEY_FILENAME,newFileName);
}
public String convertStreamToString(InputStream in){
StringBuffer sb = new StringBuffer();
try
{
InputStreamReader isr = new InputStreamReader(in);
Reader reader =
new BufferedReader(isr);
int ch;
while((ch = in.read()) > -1) {
sb.append((char)ch);}
reader.close();
}
catch(Exception exception) { }
return sb.toString();
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
A simple ABAP would suffice then run it via the PI "Run Operating System Command After Message Processing" option.
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.