cancel
Showing results for 
Search instead for 
Did you mean: 

File-File - Need to extract data from source file name???

Former Member
0 Kudos

Hello Experts,

I have a unique situation. In my file to file scenario, the source file name is of the format XYZ_yymmddHHMM.dat. there is field in the target file which has to filled with the date that is there in the file name of the source file (yymmdd). How can this be achieved? Normally we do the other way round using vaiable substitution where we can name a file depending on the value in any of the target field structure.

Please help.

Regards,

Yash

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

for the UDF use the context as Value.

public String GetFileName(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;

}

output of the above UDF

GetFileName->substring(4,10)->targetfield

Enable adapter specific attributes in the sender file communication channel and check file name.

Edited by: malini balasubramaniam on Jul 29, 2008 1:02 PM

Former Member
0 Kudos

Hello Mahesh / Chetan / Malini,

The solution looks fine and i understood it. the only query i have now is will the UDF have any input or will it be without nay input parameters?

Yash

Former Member
0 Kudos

No input parameters to the UDF. Map the output of UDF to substring function.

Edited by: malini balasubramaniam on Jul 29, 2008 1:08 PM

sunil_singh13
Active Contributor
0 Kudos

Hi Yash,

Input Required is container variable of Type Container which automatically comes when you select queue or context (you see 3 options when u creat UDF value, queue,context).

No other Input is required.

Thanks

Sunil Singh

Answers (3)

Answers (3)

sunil_singh13
Active Contributor
0 Kudos

Hello Yash,

You can access Adapter specific parameter (Like File Name)

and can perform the changes you wish to.

Use following code to extract file name

DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters()

.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

DynamicConfigurationKey key = DynamicConfigurationKey.create(

u201Chttp://sap.com/xi/XI/System/Fileu201D,

u201CFileNameu201D);

String valueOld = conf.get(key);

if (valueOld != null) {

}

In if (valueOld != null) part of above code you can perform subString Operation and output of this UDF can be given to any target field.

Reward Points IF Helpful

Thanks

Sunil Singh

Former Member
0 Kudos

Hello

This blog wil help you , solving your problem

Regard's

Chetan Ahuja

former_member859847
Active Contributor
0 Kudos

Hi,

please prepare the udf with the following code.

i mean, dynamic configuration concept.

where u get the file name, then use substring function to capture date from right side.

//write your code here

// getFileName User Defined Function

// function to create name of output file

String filename;

filename = strFile;

try {

// initialize DynamicConfiguration for create file with given name

DynamicConfiguration conf = (DynamicConfiguration) container

.getTransformationParameters()

.get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);

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

//create file with the specified name

conf.put(key, filename);

} catch (Exception ex) {

}

return filename;

warm regards

mahesh.

Former Member
0 Kudos

Hello Mahesh,

I have not used Dynamic configuration before and hence i am new to it. Can you please explain me in complete details as what i have to do, what would be the exact code of the udf, where will i use the UDF and what will be the input to it? If somehow i can get the souce file name in the mapping i can use substring to get the timestamp.

Thanks,

Yash

former_member859847
Active Contributor
0 Kudos

Hi,

you have set adapter speific attributes in file sender adapter.

like file name..etc details

then you can see file name in soap header message(in sxmb_moni).

from saop header, the UDF get the file name and written to one of the variable in the target.

for more information, please check help documenttation.

http://help.sap.com/saphelp_nw04/helpdata/en/e3/94007075cae04f930cc4c034e411e1/frameset.htm

warm regards

mahesh.