cancel
Showing results for 
Search instead for 
Did you mean: 

PDF file as IDoc Trigger

former_member187587
Contributor
0 Kudos

Hi guys,

I have this scenario ( a quite delusional one I must say) that I need to implement.

I have a PDF arriving to a folder (PDF content is not relevant).

I need to trigger on the Receiver side a DMS IDoc that will point to that PDF and add a few constant parameters to the IDoc Schema (Party number,file name,directory - all taken using Dynamic configuration).

After setting this scenario (even created a default input schema) I am getting an error during runtime where the PI Try to parse the file into the source XML.... (off course)

My question is : how do you suggest to implement such scenario?

Accepted Solutions (1)

Accepted Solutions (1)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Nimrod,

                  If you are using FCC, remove the same from file sender adapter. Now put a dummy source interface in the interface/operational mapping. The source XSD will be ignored by PI when scenario runs.

In the message mapping do all the assignment to the target XSD as I believe you have already done.

Once the file is picked up the mapping will get triggered and ignore the contents of the PDF file.

In this way you can avoid parsing of the contents of PDF file there by avoiding mapping exception.

Regards

Anupam

former_member187587
Contributor
0 Kudos

Hi Ghosh,

Channel is without FCC.

Can I perform mapping when a Dummy interface value is used in OM ?

How do you sugest to create a dummy interace.

Former Member
0 Kudos

Create an empty data type and message type, for instance data type:

Use this one to create your message type. You can use this as a dummy in your message mapping.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Nimrod,

               

Here are answers to your question

1) Can I perform mapping when a Dummy interface value is used in OM ?

ans) yes

2) How do you sugest to create a dummy interace?

ans) place the target XSD as the source also.  The target XSD can be used as source too. Only one thing you keep in mind in the mapping do not map any fields from source to target. I guess you are using UDF. Please direct the output of UDF to target fields but there should be no input to the UDF from the source XSD.

Regards

Anupam

former_member187587
Contributor
0 Kudos

Thanks Ghosh,

All my UDFs has no XSDs as inputs.

I did implemented your suggestion and has no mapping now between the Dummy SI and the Target IDoc.

(But the SI has a DT and MT....this is mandatory...)

Still getting some mapping errors. (will refresh cache and try again)

If you have some more ideas will be most welcome..

anupam_ghosh2
Active Contributor
0 Kudos

Hi Nimrod,

                  I have applied the technique in one of my articles http://wiki.sdn.sap.com/wiki/x/SQxeDw

There was a difference from your scenario. I was using java mapping instead of message mapping and all went fine. This problem is there because you are using message mapping and not java mapping.

From the error description it seems the method only works for java mapping. Here is what you can do. Instead of message mapping create a java mapping and populate the idoc. Check the code i wrote in my article. In the code I read the incomming file as series of bytes instead of using XML parser. You need to ignore the input file in your mapping and concentrate on generating the required output from java mapping instead of UDF.

Regards

Anupam  

former_member187587
Contributor
0 Kudos

So you sugest to create a JAVA mapping using Dom parser

to recieve the input. not through graphical mapping but rather using FileInputStream ?

In your code you specified a direct acccess to the folder where in my scenario the data is handled during mapping.... there must be a different handler for that.

I wounder if your solution will fit...

anupam_ghosh2
Active Contributor
0 Kudos

Hi Nimrod,

                  Single java mapping is enough to meet your requirements. The method making direct access to the folder is not being called by PI server at all. The method is useful when you test the code in local system. Could you please post your target XML structure.

Alternativley you can follow the code provided by Praveen below. In this case you need to create a new message type and data type. Then map those fields to idoc in the same operation mapping. The java mapping should be applied first followed by message mapping.

Regards

Anupam

Answers (1)

Answers (1)

former_member181985
Active Contributor
0 Kudos

Hi,

For me your requirement is not clear.

1. Is your scenario File Adapter (PDF) --> XI --> IDOC?

2. I hope your scenario does not require PDF content, rather it requires only Party number,file name,directory (all taken using Dynamic configuration) is required to map it to target IDOC structure. Is this correct?

3. From where you will get party number? will it be part of PDF file name/ PDF content??

- Praveen

former_member187587
Contributor
0 Kudos

Hi  Praveen,

1.yes, thisi s my scenrio.

2.no pdf parssign needed. PDF file is just a trigger.

3.Party number taken from SAP XI Party configuration object.

former_member181985
Active Contributor
0 Kudos

Hi Nimrod,

Create a message type structure for Sender file as below (attached image)

Have two mapping programs in operation/interface mapping

1. java mapping  (with below code)

2. graphical mapping (Map above mapping output to IDOC message structure)

JavaMapping Code:-

import com.sap.aii.mapping.api.StreamTransformation;

import com.sap.aii.mapping.api.*;

import java.io.*;

import java.util.*;

public class DCJM extends AbstractTransformation implements StreamTransformation

{

    private Map param;

    public DCJM(){  }

          public void setParameter (Map map)

          {

                    param = map;

                    if (param == null)

                              param = new HashMap();

          }

          public static void main(String args[])

          {

                    try

                    {

                              FileInputStream fin = new FileInputStream(args[0]);

                              FileOutputStream fout = new FileOutputStream(args[1]);

                              DCJM mapping = new DCJM();

                              mapping.execute(fin, fout);

                    }

                    catch (Exception e)

                    {

                              e.printStackTrace();

                    }

          }

          public void transform(TransformationInput tranIn, TransformationOutput tranOut) throws StreamTransformationException  

          {

            this.execute( (InputStream) tranIn.getInputPayload().getInputStream(), (OutputStream) tranOut.getOutputPayload().getOutputStream());             

          }  

    public void execute(InputStream inputstream, OutputStream outputstream)

    {

                    DynamicConfiguration conf = (DynamicConfiguration) param.get("DynamicConfiguration");

                    DynamicConfigurationKey KEY_FILENAME = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");

                    DynamicConfigurationKey KEY_DIRECTORY = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","Directory");

                    String payload = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:MT xmlns:ns0=\"your scenario namespace\""; //use your scenario namespace before compiling

                    payload = payload + "<FileName>" + conf.get(KEY_FILENAME) + "</FileName>";

                    payload = payload + "<FileDirectory>" + conf.get(KEY_DIRECTORY) + "</FileDirectory>";

                    payload = payload + "<PartyName>" + (String) param.get(StreamTransformationConstants.SENDER_PARTY) + "</PartyName>";

                    payload = payload + "</ns0:MT>";

                    try

                    {

                              outputstream.write(payload.getBytes());

                    }

                    catch(Exception e){          e.printStackTrace();}

    }

}

Message was edited by: Praveen Gujjeti