cancel
Showing results for 
Search instead for 
Did you mean: 

file to multiple target directory (PI70)

Former Member
0 Kudos

Hello,

i want to read the file name and then from the file name i have to get the COUNTRY name which is my target directory name.

my input file name is like TestFile_20100903_sale_Mexico_ZDELV_1234_46.txt

so from above file name the country code is Mexico...so the file will go to target directory/folder Mexico.

if the country name from file came as India then file will be placed in a target folder India

i worte the following UDF in Mapping. now the problem with this code is it is using Substring to get Country name from file. but in my case it is not possible....i have to search (index) based on "_" in file name.

can you please help me to chage the code like to get the country name from the above file name.

all file names starts with " TestFile_20100903_sale * " means my file names are like

TestFile_20100903_sale_Mexico_ZDELV_1234_46.txt

TestFile_20100903_sale_India_ZDELV_1234_46.txt

TestFile_20100903_sale_china_ZDELV_1234_46.txt

TestFile_20100903_sale_southafrica_ZDELV_1234_46.txt

So you can take Index based on "ZDELV" or "_" from file name.

my UDF code:

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

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

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

String temp = conf.get(key1);

String src_filname = temp.substring(24,6); //This is used to get the last two digit value from the file name

String tar_dir = "//sap"src_filename"/";

conf.put(key,tar_dir);

return "";

Thanks in advance...SARAN

Accepted Solutions (1)

Accepted Solutions (1)

rodrigoalejandro_pertierr
Active Contributor
0 Kudos

hi

what you can do once you get the file name ussing the Dinamyc configuration is:

1) take in mind that this string is fix "TestFile_20100903_sale".

2)also this string (i think as youer examples) "ZDELV_1234_46.txt "

3)So you can get the Length of the filename

4) do a substring and get this value (MexicoZDELV_1234_46.txt )

5) substract the length of the main string less the length of this string (TestFile_20100903_sale)

6) calculate the length of "ZDELV_1234_46.txt ".

7)rest the value of point 5 to 6

😎 do a substring of "MexicoZDELV_1234_46.txt " ussing the value of point 7 wich tell you the length of the country

Now if this value "ZDELV_1234_46.txt" is not fix you can

9)do until point 4 and point 6. later make an indexOf("_")--> MexicoZDELV_1234_46.txt --> now at this point you will know the length of the country because thispoint calculate the index of the first _ (MexicoZDELV_) --> for Example the index Of return 12

10)do a substring substracting those positions (ZDELV_) -->a.substring(0, (12-5));where 5 -->ZDELV_

hope Helps

Rodrigo P-.

Edited by: Rodrigo Alejandro Pertierra on Sep 3, 2010 11:03 AM

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi Saran

my UDF code:

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

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

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

String temp = conf.get(key1);

String src_filname = temp.substring(24,6); //This is used to get the last two digit value from the file name

String tar_dir = "//sap"src_filename"/";

conf.put(key,tar_dir);

return "";

Pls. tyr with this is a small change to get the country name.


 String src_filname = a.substring(23,a.indexOf("_",23));

Former Member
0 Kudos

Try this

Former Member
0 Kudos

Try to split the file name by '_' into one string array and read the 4th element of the array.

Regards,

Nayan