cancel
Showing results for 
Search instead for 
Did you mean: 

Idoc -> Multi-message -> File -> Counter issue

Former Member
0 Kudos

Hi Experts

I have developed an interface that sends an idoc to PI. Multimapping is used to create n number of files for each child segment in the idoc.

The customer requires a counter to be attached to every file like 001,002 and so on.

Due to this I have to write the file to a temporary location using NFS method (since it has the add counter option) and then have PI pick up this file and send it to the final ftp destination via a FTP communication channel.

This 2 step process is taking a lot of time and the customer is complaining.

I want to send the idoc to PI - multi-message split - file straight to FTP receiver.

How can I add a counter to the filename?

I have seen posts mentioning that the counter can be generated using RFC etc. , or UDF, but none of the options seem to work in multi-message scenario.

Please help.

Also I tried to do a performance analysis using SXMB_IFR => Detailed data aggregated option - but I keep on getting message 1 Messages found. More than one senders identified.

I have tried to make the search options as unique as possible but was unable to continue.

Any help is most appreciated.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi

Please can you explain how to do value mapping - do i require a value from source payload?

I havent done value mapping before.

I tried to do what has been mentioned in above example but only difference is I generated a filename using udf and sent it in the filename field (this is the second node in my target payload) - variable substitution uses this filename from target payload.

However I get only 1 file in the destination and then comm channel gives errors saying file already exists. I thought the date time stamp on the filename will keep on changing for very message created but that does not seem to happen.

Regards

ambrish_mishra
Active Contributor
0 Kudos

Hi Girish,

The document I shared was to give you an idea on achieving your requirement through variable substitution. this particular example in my document was around value mapping.

But you have to try and achieve the counter functionality by calling the RFC NUMBER_GET_NEXT (when the context of Message creation changes) as suggested by Harish.

I was going to suggest this and I see Harish forwarding you Shabarish's blog post.

So use both NUMBER_GET_NEXT and variable substitution if you have a non-XML output.

Ambrish

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi All

Almost there only with one small issue :-

I am getting an extra line in the target file - I have used the comm channel to trick PI to not write the record containing the file details. How do I remove the extra line

First thanks to all of you for giving various suggestions which started me thinking in a different direction.

I haven't yet gone the adapter module way since there are a lot of pre-requisites.

But I put into place a schema similar to what Indrajit suggested

I have then used the index function to generate the filecounter and write the data record and file details record to the file.

Further details of how I have tried to achieve this are below.

As suggested by Ambrish then I have used the fixedLengthTooShortHandling etc. on the communication channel to trick PI to not write the file details into the target file.

Also I have used variable substitution to generate the file name with counter.

The filename is generated by %file%%counter%.txt

Please could you tell me how to get rid of the extra line that is being written

ambrish_mishra
Active Contributor
0 Kudos

Hi Girish,

Some comments:

Problem with index function is again the same. It won't work beyond the execution of the message. So the files generated by one IDoc will have counter but next message will again start from initial value.

If you want the files to have incremental value across message execution, then you have to choose the FM(custom one).

Also provide screenshot of the data type and mapping. You have to define the data type in a way similar to what I suggested in my document.

Hope it helps!

Ambrish

Former Member
0 Kudos

Hi Girish

Your requirement can be solved in the below approach

1. In the target structure add one more field for sequence number.

Use global variable in the multi-mapping for populating the sequence. Write two udf one for setting the variable and one for reading the variable.

Map it with the top node

Map this with fileseq. So the output of mapping will be like this

Then in the content conversion ignore the field value fileseq as you dont need the sequence value in output file

Finally write a adapter module which will populate the file name including the sequnce number

sample code

 

try {
   InputStream inStream = xmlData.getInputStream();
  
   DocumentBuilderFactory tfactory = DocumentBuilderFactory
   .newInstance();

   DocumentBuilder tbuilder = tfactory.newDocumentBuilder();

   Document doc = tbuilder.parse(inStream);

   NodeList nlList = doc.getElementsByTagName(
     "fileseq").item(0).getChildNodes();

   Node nValue = (Node) nlList.item(0);

   String sName = nValue.getNodeValue();


   MessagePropertyKey mpk = new MessagePropertyKey("FileName",
     "http://sap.com/xi/XI/System/File");
  
   String outfile = "Test_File"+sName+".TXT";


   mes.setMessageProperty(mpk, outfile);

  
  

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

Final files will be like this

Former Member
0 Kudos

Hi Indrajit

I am new to adapter module development - please can you shed light on how I can develop this adapter module - is it like writing a UDF?

What are the tools used to write an adapter module?

Please guide me

Regards

Former Member
0 Kudos

Hi Girish

You can find the deatils in the following blog

http://scn.sap.com/docs/DOC-16229

former_member184720
Active Contributor
0 Kudos

Just to add - with this approach the counter will be set back to 1 for every new message.

ambrish_mishra
Active Contributor
0 Kudos

Hi,

I concur with Hareesh here. This approach won't serve Girish's requirement.

Girish - I suggest you use the FM/RFC approach with variable substitution. That should work.

Ambrish

ambrish_mishra
Active Contributor
0 Kudos

Hi Girish,

Have you tried variable substitution. Please refer below.

http://scn.sap.com/docs/DOC-41985

This will work for non-XML file output.

Hope it helps!

Ambrish