cancel
Showing results for 
Search instead for 
Did you mean: 

file to idoc how to get file name at runtime

rohit_goel
Participant
0 Kudos

Hi Experts,

In my file to idoc scenario,

the requiremnt is like in mapping i have to give condition like if file name is name1 then one target filed is 40 and if file name is name2 then that target field is 60.

how can we achieve this ?

Regards,

rohit

Accepted Solutions (0)

Answers (4)

Answers (4)

Former Member
0 Kudos

Hi Rohit

mughdha is right but you can do it through graphical mapping easily

give condition in fix value under category conversion like this

1) source-> FIX VALUE ->if value is true then map FIX value

else nothing

double click on first FIX VALUE function and assign your input values for file (for ex 40 or 60,......) in the key field and in the value field assign TRUE

if this condition will be true the it willl map second FIX VALUE

else assign a constant with empty value

in second fix value assign values (for ex 40 or 60,......) which you have checked in first FIX VALUE function in key field and assign corresponding name which you required in the value field

hope this will solve your problem

Thanks

sandeep

if helpful reward points

Former Member
0 Kudos

Follow this blog to get filename in mapping

/people/michal.krawczyk2/blog/2005/11/10/xi-the-same-filename-from-a-sender-to-a-receiver-file-adapter--sp14

you can write UDF as

DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

String ourSourceFileName = conf.get(key);

//here check if ourSourceFileName = name1 then return 40 else return 60

map it to corresponding target field

rohit_goel
Participant
0 Kudos

hi Mugdha,

i have put this code in the UDF but what should be the input parameter for the UDf.

also when i tried to check this in message mapping test , its giving me run time exception.

RuntimeException in Message-Mapping transformation: Runtime exception during processing target field mapping /ns0:Messages/ns0:Message1/ORDERS05/IDOC/EDI_DC40/MANDT. The message is: Exception:[java.lang.NullPointerException] in class com.sap.xi.tf._MM_EDI_HospitalsToORDERS05_ method filename$[com.sap.aii.mappingtool.tf3.rt.Context@545f545f]

Regards,

Rohit

former_member859847
Active Contributor
0 Kudos

Hi,

The exception nullpointer is due to null value.

i hope that, the input value to the udf may be null value.

pls check the udf once again.

regards

mahesh.

rohit_goel
Participant
0 Kudos

my code is like this

public String filename(Container container){

DynamicConfiguration conf = (DynamicConfiguration)container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

String ourSourceFileName = conf.get(key);

return ourSourceFileName;

}

and in graphical mapping i did like this

UDF---->targetField

what else should be done..

Former Member
0 Kudos

as you have to return value depending on your file name..

dont return filename..

return the value as per comparison...

if filename = name1

return 60

else

return .....

put the syntax correct..it will work

rohit_goel
Participant
0 Kudos

actually i need file name in the output and then i have to use value mapping for some reason.

can we check output here in message mapping test ? because when i am testing i am getting runtime exception ?

i have also put my code in the previous post.

pls see and let me know what else to be done.

Former Member
0 Kudos

can we check output here in message mapping test ? because when i am testing i am getting runtime exception ?

-


>

you can test it runtime only as it is a dynamic configuration. Test the scenario end to end

Also you have to select adapter specific message attributes in sender file adapter as mentioned in the blog.

Former Member
0 Kudos

Hi rohit,

Chk dis link...

http://www.saptechnical.com/Tutorials/XI/Variable/substitution.htm

reward points if helpful....

PrashaNt

Former Member
0 Kudos

Hello Rohit,

R u talking about massage mapping?

Then u can try usingstandard FixValues function from Conversions category

Provided u knw source & target values at the time of development & it will not change afterward.

Thanks,

mahi

Former Member
0 Kudos

Hi,

Follow this links

/people/jayakrishnan.nair/blog/2005/06/20/dynamic-file-name-using-xi-30-sp12-part--i

/people/sravya.talanki2/blog/2005/08/11/solution-to-the-problem-encountered-using-variable-substitution-with-xi-sp12

/people/jayakrishnan.nair/blog/2005/06/28/dynamic-file-namexslt-mapping-with-java-enhancement-using-xi-30-sp12-part-ii

or

In the receiver determination we mention the condition according to our requirement.

Follow this link

http://www.saptechnical.com/Tutorials/XI/FileToIDoc/FiletoIDocScenario.htm

Edited by: Venkataramesh Boppana on May 21, 2008 3:52 PM