cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic Directory and File Naming in Receiver Adapter

Former Member
0 Kudos

Hi ..My Receiver file should Look like this.

COLCCYYMMDDHHMMSSLPMASTER___.tmp

1st 3 bytes: COL ( Sender File name is COLMASTER.txt)

Next 14 bytes is timestamp: CCYYMMHHMMSS

Next 1 byte: L ( constant Value )

Next 1 byte: P/Q/D (Production/QA/Dvlp.. Can we do this based on Sender Logical System ?)

Next 20 bytes ( Part of it comes from Sender file name and remaining fields should be filler with underscores )

Next 4 bytes ( .tmp)

After Iam done with writing this file in .tmp format I should change the file name to .txt format for further processing. Since File gets created dynamically how should I change Name from .tmp to .txt file?

Appreciate help and guidance with steps I neeed to follow to make this happen. Thanx again.

Accepted Solutions (1)

Accepted Solutions (1)

bhavesh_kantilal
Active Contributor
0 Kudos

Hi,

Why don't you try this code in an UDF with Adapter Sepecific Indentifiers?

<i>


String newfilename="";
DynamicConfiguration conf = (DynamicConfiguration) container.getTransformationParameters().get(StreamTransformationConstants.DYNAMIC_CONFIGURATION);
 
DynamicConfigurationKey key = DynamicConfigurationKey.create("http://sap.com/xi/XI/System/File","FileName");
// Get Sourcefilename
String oldfilename=conf.get(key);
//extract first 3 chars of source filename
newfilename=oldfilename.substring(0,2);
//get the date
java.text.SimpleDateFormat dateformat = new java.text.SimpleDateFormat( "yyyyMMdd" );
dateformat.format( new java.util.Date() );

//append source+date+L
newfilename=newfilename+dateformat+"L";

// determine if prod/ dev / qa 
map = container.getTransformationParameters();
senderService = (String) map.get("SenderService");
if(senderServcie.equald("Prod"){
newfilename=newfilename+"P";
}

// change to new file name
conf.put(key, newfilename+".tmp");

</i>

Regards,

Bhavesh

Answers (4)

Answers (4)

bhavesh_kantilal
Active Contributor
0 Kudos

Hi Ram,

One option~~

Use ADAPTER SPECIFIC INDENTIFIERS in both sender and recievr file adapter with the filename selected.

In this case, the filename of sender will be made the file name of the reciver.

Now, change the file name in the mapping in an UDF with the following code, and this will be used as the filename,

String newfilename="";

// Write the logic to get the new file name into this string.

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

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

conf.put(key, <b>newfilename</b>);

return  ""; 

Now, this filename in newfilename string will be used in the target filename.!!

Regards,

Bhavesh

Former Member
0 Kudos

Ram,

I dont think you will be able to go by the number of bytes while naming the file...but, you will be able to specify the name in one specific order.

-Sushumna

Former Member
0 Kudos

Hi,

This parameter of the file adapter:

<i>Put File

If the file is to be created on the server immediately, select Directly.

If the content is to be gathered in a temporary file first before the final file is put on the server, choose Use Temporary File.</i>

SAP generates it's own temeporary file name when it's writing the file if you have chosen that option. But when the file is completely written the file will be renames with the name specified by you in 'Filename'.

Regards

Vijaya

bhavesh_kantilal
Active Contributor
0 Kudos

Hi ram,

You can write a Script in your Receiver File adapter that will get executed after the file is generated and this will rename the file to .txt.

http://help.sap.com/saphelp_nw04/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/content.htm

See the section, RUN OS commands Before / After Porcessing.

Regards,

Bhavesh

Former Member
0 Kudos

Thanks for the reply. you gave me info how to rename file basically.

But How to generate file based on the Info I gave. I mean some chars of file name I have to derive from input file name and some are timestamp and some are based ons ending system etc etc. Please take a look again at my question. I really dont know how to generate file name based on these various parameters.

Basically whole file name I have to derive from various places ( Such as Input File name, Sending sytem, payload etc.. and I need to pad underscores as well )

Message was edited by: Ram Krish

Former Member
0 Kudos

Hi,

You will have to do this in Message mapping and then do variable substitution.

http://help.sap.com/saphelp_nw04/helpdata/en/bc/bb79d6061007419a081e58cbeaaf28/content.htm

Variable Substitution (Target Directory/File Name Scheme)

Regards

Vijaya

Former Member
0 Kudos

Hi Ram,

For the timestamp, you can use the option available in the receiver adapter "add timestamp". For sending system, etc...you will have to use the variable name option provided in the adapter...but then you will have to make sure that variables that you want are available in the payload.

Regards,

Sushumna

Former Member
0 Kudos

Hi Vijaya. Link was very helpful. I have following question.

I can use variable substitution from Message header. How can I get part of it for example in my case I need to put only one character( for example If sender system is Legacy_system I need to populate only first letter 'L')

Message was edited by: Ram Krish

Former Member
0 Kudos

Hi,

In mapping, write a UDF that retrieves Sender System.

UDF: getSenderService

map = container.getTransformationParameters();

senderService = (String) map.get("SenderService");

IF-getSenderServiceequalsLegacythen-"L"--Target

Here, you are checking if the UDF is returning Legacy, if so, Map, "L" to the Target node.

Similarly for the rest.

In the receiver adapter,enable variable substitution to get the value of this target node.

Regards,

Smitha.

Former Member
0 Kudos

Hi, Sender system Name is "Legacy_System' . I wont get this from payload to map to Target node. right?. Sender system Name will be in message header part.

Former Member
0 Kudos

Hi,

There are certain parameters like Sender Service and Receiver Service which are available at runtime.

The code I mentioned before, will try to retrieve the value from these variables.

In mapping editor, Test tab, you will find a parameter tab.

The list of variables specified there, are available at runtime.

Regards,

Smitha.