Skip to Content
author's profile photo Former Member
Former Member

file to file scenario

Hi All,

I am having file to file scenario in which i am having file name in the format of text_yyyymmdd.txt.

i want to read this file name and by separating the date in file name. please help me .

Add a comment
10|10000 characters needed characters exceeded

Related questions

4 Answers

  • Best Answer
    Posted on Dec 06, 2011 at 06:21 AM

    Hi,

    In sender communication channel use Adapter Specific Message Properties. Tick on this two options

    "set Adapter Specific Message Properties" and "Filename". Now you need this UDF, no need of any input parameter to the function

    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 s = conf.get(key);
    s=s.substring(s.indexOf("_")+1,s.indexOf("."));
    return s; 
    } 
    

    So if your filename is "PN001_20110709.txt" the UDF will separete the date part and in target field you will obtain "20110709".

    If you want the file name without the date then the UDF is as below

    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 s = conf.get(key);
    s=s.substring(0,s.indexOf("_"))+s.substring(s.indexOf('.'), s.length());
    return s; 
    } 
    

    So if your filename is "PN001_20110709.txt" the UDF will produce "PN001.txt".

    Regards

    Anupam

    Edited by: anupamsap on Dec 6, 2011 7:25 AM

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 06, 2011 at 05:55 AM

    Hi,

    1. Enable ASMA properties in sender file communication channel and Write a UDF using Dynamic Configuration and get the filename. Make use of this blog by michal

    https://blogs.sap.com/?p=41013 for achieving the same

    2. With the help of the code described, obtain the Dynamic configuration parameters where you get the file name.

    3. With the help of UDF extract the date from the file name.

    regards,

    ganesh.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 06, 2011 at 06:03 AM

    HI,

    file to file scenario

    I am having file to file scenario in which i am having file name in the format of text_yyyymmdd.txt.

    i want to read this file name and by separating the date in file name.

    that is possiable with ASMA in ADVAnced mode in Communication channels.

    In Sender and receiver communication channels -> in adavaned tab -> enabled USE ASMA -> Source file stamp .

    thats all.

    other wise you have to write simple udf: (text_yyyymmdd.txt.)

    source field(text) -> constant(_) ->concat -> udf -> constant(.txt)->concat -> target field.

    udf:

    String AddTimestamp(String var1, Container container) throws StreamTransformationException{

    String DATE_FORMAT_NOW = "yyyyMMddHHmmssSSS";

    Calendar cal = Calendar.getInstance();

    SimpleDateFormat sdf = new SimpleDateFormat(DATE_FORMAT_NOW);

    return sdf.format(cal.getTime());

    thanks,

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 06, 2011 at 10:47 AM

    Hi,

    Go to this below refer link you can acheive:

    [file to RFC scenario want to read file name;

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.