cancel
Showing results for 
Search instead for 
Did you mean: 

SAP PI : UDF : Scan IDoc for Date (Newest & Oldest) -

Former Member
0 Kudos

Hello Guru's.

I am unskilled in Java / XSLT and was hoping for direction on a mapping problem I have in SAP PI.

I want to scan through an IDOC - INVOIC01 and from segment E1EDP03 I want to determine the oldest date and the newest date that occurs in this recurring segment - In essence I want to determine the date range of all the items that appear in this IDoc.

This I subsequently want to use in naming the file.

The UDF (if necessary - Can this be achieved graphically???) for scanning and determining the date range is my main concern. I would be grateful to any of you if you could provide sample code for this.

My thanks to you all in advance.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

Your requirement is not clear.As per my understanding try as below.

Convert the string date (YYYYMMDDHHMMSS) to int using "Integer.parseInt(inputdate)"

Now sort it and pick the required values in the array.

>>For setting receiver file name use the below udf.

try {

String filename    = "";

DynamicConfiguration conf = (DynamicConfiguration) container

    .getTransformationParameters()

    .get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

filename = assaign ur output file name.

conf.put(key,filename);

return filename;//It is up to you

}

catch(Exception e)

{

     String exception = e.toString();

      return exception;

}

Regards

Venkat

Former Member
0 Kudos

Hey Venkat.

Thanks for that tip. I am trying to apply the following but it does not seem to write anything to the DynamicConfgurationSection at all... Can you take a look and suggest where I am going wrong please?

Former Member
0 Kudos

Hi Mike,

Along with udf you need to do some configs in receiver file adapter .

Go through below link for steps .Let me know if you struck with any issue.

https://scn.sap.com/thread/1712384

Regards

Venkat

gagandeep_batra
Active Contributor
0 Kudos

Hi Mike

As vekent said please check the following  screen shot:

Regards

Gagan

Former Member
0 Kudos

Thanks to you all -

Venkat / Gagaandeep - You both got me over the line in the end - Thank you very much for the help.

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Mike,

You can achieve it through graphical mapping.

Apply sort function on date field in the segment E1EDP03. Since sort function doesnt allow any context change in between so before applying sort function either use node function removeContext to remove context or change the parent segment of the date field to INVOIC01.

This would return sorted data with min value on top & max value on bottom.

Hope this would sort out your issue.

Regards,
Ashish

Former Member
0 Kudos

You can indeed use the sort function and then take the first value with a collapseContext and take the last value with a simple UDF with code ret.addValue(contextArray[contextArray.length-1]).

Former Member
0 Kudos

That was what I was looking for - Thanks Ashish - (And everyone else too!) - Can I expand on this slightly if I may please? I am doing the mapping as you suggest and it looks good in the Message Mapping Test Tool - However when I do an actual test from WE19 through PI I get an error:

"Values missing in queue context. Target XSD requires a value for this element, but the target-field mapping does not create one. Check whether the XML instance is valid for the source XSD, and whether the target-field mapping fulfils the requirement of the target XSD".

I have check the source XML in the MEssage being received into SAP PI and it has the values - However the mapping does not seem to be completing despite it looking good in the ESR:

Any ideas anyone?

Thanks in advance.

gagandeep_batra
Active Contributor
0 Kudos

Hi Mike,

did you test your mapping with same payload which is failing in moni?

if not then plz test first. error shows that there is missing of data? check once more and

one more thing did u  activate mapping  after changes also?

Regards

Gagan

Former Member
0 Kudos

Thanks  - It turned out to be a missing upper segment in the Idoc not mapped when in WE19 - Sorted now -

Thanks to everyone for the dig-out with this problem.

gagandeep_batra
Active Contributor
0 Kudos

Hi Mike,

If i am understand your requirement properly then i think you can achieve this using graphical mapping only,

try to first sort your input date field and then read first and last occurrence of output that is your require range i think....

Regards

GAgandeep