Skip to Content
0

Add message content to Filename in my scenario in HCI

Jul 24, 2017 at 03:24 PM

427

avatar image

Hi Experts,

Our scenario is IDoc to File [SFTP - CSV File] where IDoc structure to be converted to CSV file which works well. Now our requirement is to generate filename with IDoc number which is present in the input payload to HCI & my scenario is working fine with "Append Timestamp" option but could not generate File name with IDoc number present in it.

Screen shot of my iFlow:

1. Message mapping to transform to required structure.

2. Converter to convert XML to CSV.

3. Content Modifiers to add the required header value to body that got generated by previous step.

I used "Append Timestamp" option in receiver channel to generate filename , Now my requirement is generate filename that should contain IDoc number [from source payload].

My input file look like below:

Input file screen shot :

I followed Shivaram blog [https://blogs.sap.com/2016/07/10/sap-hcp-is-sap-hci-dynamic-configuration-for-sftp-adapter/] but getting confused where to use Content Modifier as suggested by Shivaram in my scenario.Please guide me to achieve this requirement.

Thanks,

Ramu.

iflow.jpg (47.4 kB)
snip.jpg (56.7 kB)
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

4 Answers

Best Answer
Sriprasad Shivaram Bhat Jul 24, 2017 at 05:30 PM
0

Hello Ramu,

You must use your content modifier which sets the file name before your mapping (Where you are getting IDOc XML with field DOCNUM).

Regards,

Sriprasad Shivaram Bhat

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Shivaram,

Thank you for your reply.

I followed your blog https://blogs.sap.com/2016/07/10/sap-hcp-is-sap-hci-dynamic-configuration-for-sftp-adapter/ and created iFlow as suggested but it is not creating any file on target SFTP folder. Please find screen shots of iFLow, 1st Content Modifier [to create Filename with IDoc number in it] & receiver channel properties maintained by leaving Directory & FileName as blank.

iFlow snippet: [Content Modifier used before mapping step]

1st Content Modifier Header properties to generate FileName with IDoc Number:

Receiver channel snippet:

But no File is created in Folder " /Test/output/ ".Kindly help me to achieve this requirement.

Thanks,

Ramu.

iflow.jpg (68.6 kB)
0
Srinivas Sistu Jul 24, 2017 at 03:35 PM
0

try using the content modifier before the mapping step. get the IDOC number and save it as a header / property. Hope this helps.

Share
10 |10000 characters needed characters left characters exceeded
Ramu G Jul 25, 2017 at 06:26 AM
0

Hi Shivaram,

File is getting generated but only IDoc number value is not getting appended to FileName as defined in Content Modifier.

Say for I have defined CamelFileName expression as "Invoice_${header.IDoc}.xml" only FileName is genrated as "Invoice_.xml" but something like "Invoice_000000000234321.xml" , Kindly help to resolve my issue.

Thanks,

Ramu.

Show 5 Share
10 |10000 characters needed characters left characters exceeded

Hello Ramu,

As per my understanding issue is with your XPATH since the input message contains Namespace mapping XPATH mentioned in Content Modifier is not able to retrieve any values.

XPATH you have entered will be returning value as

<DOCNUM xmlns="urn:sap-com:document:sap:idoc:soap:messages">206245</DOCNUM>

so your xpath will not be able to find out value associated with DOCNUM. Next thing will come into picture why dont we use namespace mapping and then try to retrieve the value, unfortunately it wont work because namespace mapping requires to be in format xmlns:K=test.com but in IDOC we have xmlns="urn:sap-com:document:sap:idoc:soap:messages" placeholder K is missing which will result in error[ ERROR: Enter a valid collaboration namespace mapping. E.g, xmlns:test=http://sapcd.com/test ]

Possible solutions:

1) Have to content modifier after Message Mapping where you will not be having namespace issue and then try to set the DOCNUM to filename ( or relevant field in your target message ).

2)Remove namespace using XSLT mapping before mapping and then try to set the DOCNUM and dynamic filename.

Regards,

Sriprasad Shivaram Bhat

0

Hi Shivaram,

Ultimately my requirement is to generate unique filename, hence we preferred option of appending IDoc number to filename to make it unique but unfortunately it is not working here since the target structure do not contain field which can be used to populate IDoc number else your 1st solution as suggested above would have worked here.

" 1) Have to content modifier after Message Mapping where you will not be having namespace issue and then try to set the DOCNUM to filename ( or relevant field in your target message ). "

The above option in bold will work but problem is we do not have field which can hold IDoc number. And also Target structure do not have unique field values [even combination of one or more target fields that can make file name unique here]. The target system people are not ready to add the additional field which can hold IDoc number.

Going to second solution, can you please guide me elaborately on how to use XSLT mapping in HCI and also logic to achieve that.

Thanks a ton in advance!

-Ramu.

0

Hello Ramu,

Instead of XSLT go with Script which will help you.

import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;

def Message processData(Message message) {
	def body = message.getBody();
	body = body.substring(body.indexOf('\n')+1);
        body="<PEXR2002>"+body
	message.setBody(body)
	return message;
}

Regards,

Sriprasad Shivaram Bhat

0
Sriprasad Shivaram Bhat

Hi Shivaram,

Above script is not removing namespace I guess, what I did is like I created iFlow with only above script but it generated different file when I open the file .xml file generated it shows like below screen shot:

Can you please help on this.

Thanks,

Ramu.

file.jpg (20.1 kB)
0
Sriprasad Shivaram Bhat

Hello Shivaram,

Issue resolved after doing some changes in script code.

Thank you very much for your time to help me to resolve this!

-Ramu.

0
Ramu G Jul 25, 2017 at 07:11 AM
0

Hi Shivaram,

In Content Modifier I defined Value of CamelFileName as Sample_${header.Var1}.xml like in below snippet :

But file is getting generated as below snippet:

File name is generated as "Sample_${header.Var1}.xml' rather than like eg: Sample_000000234385.xml . Kindly help to resolve.

Thanks,

Ramu.


cm1.jpg (38.8 kB)
file.jpg (16.5 kB)
Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Ramu,

Use file:name instead.

Thanks,
Apu

0

Hi Apu,

Issue resolved after script, can you elaborate more on how to use file:name ?

Thanks!

-Ramu.

0