cancel
Showing results for 
Search instead for 
Did you mean: 

Output File Naming Convention

Former Member
0 Kudos

Hi PI Experts,

I have a requirement to do the following :

---Pick a pdf file from a location and deposit to another location.

Some roadblocks :

1) The target filename should be the same as the source file name.

2) The source file will always have .pdf extension in uppercase or lowercase. The outfile file should have .pdf extension in lowercase. Eg. the source file is <attach.PDF> or <attach.pdf>, the target file should always be <attach.pdf>

3) A timestamp should be attached between the filename and the extension with an underscore separating them. Eg. the source file is <attach.PDF>, the target file should be <attach_timestamp.pdf>

Summary : A file is deposited as <invoice.PDF>, the output file should be <invoice_timestamp.pdf>, a file is deposited as <invoice.pdf, the output file should be <invoice_timestamp.pdf>

Note : I am not using any mapping objects as this is a direct file pick and deposit scenario i.e nonexistent_interface.

Please advise on what is the suggested solution and how to perform this functions. As I am a beginner to PI, it would be great if you could provide a clear and easy to understand solution.

Thanks in advance.

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi,

If you want to do this without using ESR objects. You can try using the option of Running Operating system command After Message Processing in the processing tab of the Receiver channel. Write a shell script to rename the file and call it here.

I don't know if it is the best practice to use this method.

Regards,

Aravind

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Freddy Ng,

It is not possible in simple way. You can use Adapter module.

Regards,

Raghu_Vamsee

Edited by: Raghu Vamsee on Jan 30, 2011 11:14 AM

RaghuVamseedhar
Active Contributor
0 Kudos

Hi Freddy Ng,

I understand you want to name target file dynamically. Dynamic file name is possible using

1) Varaible substitution (but you don't have structure of payload, it is PDF)

2) Dynamic configuration, you have to use objects in ESR ,

_a)to use this one you need UDF, but there is no source structure, it is PDF.

_b)you have to write a Java Mapping. Follow below steps.

As input is not XML, we cannot use Graphical or XSLT mapping, so we have to use Java mapping.

Solution:

Step 1:- In Sender file channel, Advanced tab, select u201CSet Adapter-Specific Message Attributesu201D and u201CFile Nameu201D.

Step 2:- Create a Dummy Data type: <Root><Child1></Child1><Child2></Child2></Root> and then create a Message type. Create Inbound and Outbound Message Interfaces using above Message Type and then create a Operational mapping.

Step 3: Now, Implement Java Mapping (below).

Step 4:- In Receiver file channel, Advanced tab, select u201CSet Adapter-Specific Message Attributesu201D and u201CFile Nameu201D.

Regards,

Raghu_Vamsee

package com.image.file;

import com.sap.aii.mapping.api.*;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.*;

public class RenameTargetFile extends AbstractTransformation {

    public void transform(TransformationInput transformationInput, TransformationOutput transformationOutput) throws StreamTransformationException {
        OutputStream outputstream = null;
        try {
            //Read input payload and write the same to output payload.
            InputStream inputstream = transformationInput.getInputPayload().getInputStream();
            outputstream = transformationOutput.getOutputPayload().getOutputStream();
            byte[] b = new byte[inputstream.available()];
            inputstream.read(b);
            String inputFileContent = new String(b);
            outputstream.write(inputFileContent.getBytes());

            //Get all details from SOAP Header
            Map para = transformationInput.getInputHeader().getAll();
            //Get File name http://help.sap.com/javadocs/pi/SP3/xpi/com/sap/aii/mapping/api/DynamicConfiguration.html
            DynamicConfiguration conf = (DynamicConfiguration) para.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
            DynamicConfigurationKey keyFileName = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File", "FileName");
            String inputFileName = conf.get(keyFileName);
            
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy/MM/DD hh:mm:ss");
            
            String outputFileName = inputFileName.substring(0, inputFileName.indexOf(".")) + simpleDateFormat.format(new Date()) + ".pdf";
            conf.put(keyFileName, outputFileName);
        } catch (Exception exception) {
            exception.printStackTrace();
        }
    }
}

Former Member
0 Kudos

Guys,

Thank you for your replies.

Is it possible to bypass ESR ? I am not using any ESR objects at all. I am just using the IR scenario to pick and deposit a file.

Can variable substitution or only ASMA solve this problem ?

Thanks

former_member463616
Contributor
0 Kudos

Hi Freddy,

Basically xi would be process only xml.First thing, you have to convert your pdf files formats into xml fomats and process through SAP XI and again you have to convert the xml to PDF formats.

You can write Adapter Module for this. The below blog might be helpful to you.

/people/sap.user72/blog/2005/07/31/xi-read-data-from-pdf-file-in-sender-adapter

Regards,

Rajesh

sugata_bagchi2
Active Contributor
0 Kudos

Hi Freddy,

You can write a adapter module, there you can pass the file name to Dynamic Configuration key and for the timestamp part. concat the file name with current date ( JAVA Date functions).

you can try this way in your module -

Hashtable mp =(Hashtable) inputModuleData.getSupplementalData("module.parameters");

String fileName = (String) mp.get("FileName");

String[]arr= fileName.split("
.");

+ you must use two back slash (escape sequence) before . for splitting+

String extn=arr[1].toLowerCase();

Calendar cal = Calendar.getInstance();

long timestamp = cal.getTime();

String fileOut=arr[0]"_"timestamp"."extn;

then pass it to Dyncon-

msg.setMessageProperty("http://sap.com/xi/XI/System/File","Filename",fileOut);

Thanks

Sugata B Majumder