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

Dynamic file naming!!

Hi All,

I am working on IDOC to file scenario where file is IDOC XML file i.e I need to write the IDOC in XML file and send.

Now the naming convention of target file need to be like SAPIT_I_ITHRINT001_4279_20150225122158.XML where 4279 is counter starting form 1 and increase by one when next file is written on target folder and 20150225122158 is time stamp yyyymmddHHmmss.

Now this is File with NFS adapter so even if I use variable substitution, how can I ensure that the counter_timestamp should nor reflect in result XML file.

Please suggest.

Regards,

Sachi

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Posted on May 15, 2015 at 12:47 PM

    Hi Sachi,

    "how can I ensure that the counter_timestamp should nor reflect in result XML file."

    Just don't select the add time-stamp check box. It will not get added.

    I hope you are taking care of generating the counter and time-stamp through variable substitution.

    Alternatively you can very well use java/UDF to set the file name dynamically.

    thanks and regards,

    Praveen T

    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 15, 2015 at 01:00 PM
    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 18, 2015 at 06:36 AM

    Hi Guys,

    I have used below method to achieve my requirement:

    The code for getFilename is:

    //Generate File Name

    try

    {

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

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

    //Update the ASMA File Adapter attribute

    conf.put(key,fileName);

    }

    catch (Exception e)

    {

    //raise an exception if the update fails

    String exception = e.toString();

    return exception;

    }

    //return the status

    return dummy;

    Now the issue is that for every run my counter shows the value as 1 and does not increase for next run.

    The requirement is the counter should increase by one for every run, so at the time of second run when file is place the filename should have counter value as SAPIT_I_ITHRINT001_2_20150225122158.XML and

    for third run when third file is placed on target folder the file name must be SAPIT_I_ITHRINT001_3_20150225122158.XML and so on.

    How can I achieve this counter requirement??

    Regards,

    Sachi


    Capture.JPG (35.0 kB)
    Add a comment
    10|10000 characters needed characters exceeded

    • Hi Dubey,

      You need to store the counter. You can follow Dilip approximation, or to do a RFC/File/JDBC lookup to store/retrieve the value, but you have to take into account the possibility of access concurrently to that data. I would do a RFC that works with a Z table, and in the RFC i would control the simultaneously access with enque/deque function over the table, and to develop a DO iteration while the table is blocked until that will be released.

      Regards.

  • Posted on May 18, 2015 at 12:38 PM

    Hi,

    As everyone answered above, you have to store this counter value somewhere and retreive it accordingly.

    One option could be Mehra's answer by using script.

    Another would be, Use java mapping, store this counter in a file in PI AL11 directory. Each time you run the mapping , retreive it from that file, increase the counter and overwite the existing file. Of course you have to place the file with initial value and maintain it properly.

    Sample code:

    import java.io.FileInputStream;

    import java.io.FileOutputStream;

    import java.io.InputStream;

    import java.io.OutputStream;

    public class streamTest {

    public static void main(String[] args) {

    try{

    //input strean to read the file

    InputStream fis=new FileInputStream("D:/counter.txt");

    //reading file

    int i;

    String counter="";

    while((i=fis.read())!=-1)

    {

    // converts integer to character and adding to counter string

    counter=counter+(char)i;

    }

    //Form your file name here

    String fileName="myfile_"+counter+".txt";

    System.out.println(fileName);

    OutputStream fos=new FileOutputStream ("D:/counter.txt");

    //increasing counter

    int count=Integer.parseInt(counter);

    count=count+1;

    counter=Integer.toString(count);

    //writing new counter

    fos.write(counter.getBytes());

    }

    catch(Exception e)

    {

    e.printStackTrace();

    }

    }

    }

    Result: 1st run: myfile_1.txt

    2nd run: myfile_2.txt

    ......

    Regards,

    Ambuj

    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.