on 08-18-2017 7:56 AM
Hi Gurus,
We need your help for the below requirement.We have a scenario IDOC to File.For each IDOC it should create the File with the seq no.
I have achieved the scenario using Java mapping as mentioned in the below blog
But i am facing an issue when the message stuck in SAP PI.Suppose at the target the latest file seq no is 12,and 13 seq no msg got stuck in SAP PI.When we reprocessed the message the seq no generated is 14 instead of 13.
I have checked the below link,but the code was missing.
https://blogs.sap.com/2014/06/30/generating-incremental-sequence-number-in-pi-per-message-id/
Could any one please provide code how to achieve the required result.
Regards,
Sahithi
Sahithi,
You may use the below code to generate counter . Reprocessing of same message is also taken care where counter doesn't get incremented.
And for avoiding issue with multi instance in PI/PO system i am using a common folder . You may change the folder if required but make sure it is common for all instance in your PI system.
1.Compile the below code in required JDK version and import into your namespace via Imported Archive.
2.Add this archive into your mapping and also add import statement.
3.Call it via UDF via 2 inputs : a.) Messsge ID b.)Some constant (Add your mapping name as constant)
In UDF call as :
return SetCounter.MsgID(msgid,Const);
Complete Code :
package com.sap.mapping.java;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
public class SetCounter
{
public static void main(String[] args)
{
String msgID= "123456";
String Const= "Map2";
System.out.println(SetCounter.MsgID(msgID,Const));
}
public static String MsgID(String msgid,String Const)
{
String U_Counter="";
Properties properties = new Properties();
File propertiesfile = new File("D:/usr/sap/MsgId.txt");
try
{
propertiesfile.createNewFile();
properties.load(new FileInputStream(propertiesfile));
}
catch (IOException e)
{
e.printStackTrace();
return "Error:File not read";
}
String number = properties.getProperty(msgid);
if (number == null)
{
number = "0";
String counter = String.valueOf(Integer.parseInt(number) + 1);
properties.setProperty(msgid, counter);
U_Counter= getCounter(Const,"ADD");
}
U_Counter= getCounter(Const,"GET");
try
{
properties.store(new FileOutputStream(propertiesfile), null);
} catch (IOException e) {
return "Error:File not updated";
}
return U_Counter;
}
public static String getCounter(String Const , String opr)
{
String counter = "";
Properties properties = new Properties();
File propertiesfile = new File("D:/usr/sap/Counter.txt");
try
{
propertiesfile.createNewFile();
properties.load(new FileInputStream(propertiesfile));
}
catch (IOException e)
{
e.printStackTrace();
return "Error:File not read";
}
String number = properties.getProperty(Const);
if (number == null)
{
number = "0";
counter = String.valueOf(Integer.parseInt(number) + 1);
properties.setProperty(Const, counter);
}
else
{
if(opr.equalsIgnoreCase("ADD"))
{
counter = String.valueOf(Integer.parseInt(number) + 1);
properties.setProperty(Const, counter);
}
else
{
counter = number;
}
}
try
{
properties.store(new FileOutputStream(propertiesfile), null);
} catch (IOException e) {
return "Error:File not updated";
}
return counter;
}
}
Br,
Manoj
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Sahithi!
Just at first sight: I would try to implement Adapter modules sequense consisting of two parts: first part is intended to read the current counter value from properties file and store it to Dynamic Configuration, the second, placed after standard adapter module - increments the counter. Thus, if the message is successfully sent to messaging system we increment the counter and the current counter is stored within the message, so, if the message is failed at any further step, we can resend it with the same counter. If the message fails at adapter processing level - it's no need to assign any counter for it since it hasn't entered the messaging system.
Regards, Evgeniy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sahithi,
The UDF codes are in the Screenshots in the same link,but I would suggest Its better to sequence number in IDOC(ABAP side) and map it in PI.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello Sahithi,
Check if the below doc helps
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.