Skip navigation
Contact Us
2667 Views 16 Replies Latest reply: Nov 27, 2012 9:04 PM by sasi ramesh RSS
lavan kumar Apprentice 169 posts since
Apr 13, 2011
Currently Being Moderated

Nov 20, 2012 12:21 AM

how to achieve this scenario....?

Hi Folks,

 

I need to get the month and date with the target for example file like below format

 

TARGET_FILE_MONTH_DATE.txt

 

my scenario is Operating system is Windows and

in my OUTPUT File i Need column Names like below

 

COLUMN STUDENT | COLUMN PARENT | COLUMN MOTHER | COULMN TEACHER

 

so for this kind of header format in out put target file i am using

PreSessionCommand

ECHO

COLUMN STUDENT | COLUMN PARENT | COLUMN MOTHER | COLUMN TEACHER

>D:/FOLDER_NAME/FILE PATH

 

AND ALSO giving same path and file name in both in Output Filename and File Directory

 

this is long process to me by manualy  to change date every month in both places can any one help me out in this scenario how to simplify this process.

 

 

 

Thanks in Advance

Lavan



  • Felix Ho Expert 342 posts since
    Aug 23, 2011
    Currently Being Moderated
    Nov 20, 2012 1:39 AM (in response to lavan kumar)
    how to achieve this scenario....?

    Hello,

     

    Can it help??? You can use ETL to provide date data and change the target file name.

     

    Link

    http://radhakrishnasarma.blogspot.hk/2008/08/how-to-generate-target-file-names.html

  • sasi ramesh Master 1,110 posts since
    Oct 2, 2010
    Currently Being Moderated
    Nov 20, 2012 1:46 AM (in response to lavan kumar)
    how to achieve this scenario....?

    Hi Lavan,

     

    You can achieve this using filename port in the target designer.

    To avoid changing the filename in Presession command.I suggest to hard code the header values and concanate with the first records inside the mapping or just enable output feild names in the header option.

     

    Regards

    Sasiramesh

      • sasi ramesh Master 1,110 posts since
        Oct 2, 2010
        Currently Being Moderated
        Nov 20, 2012 4:18 AM (in response to lavan kumar)
        how to achieve this scenario....?

        Hi Lavan,

         

        Create the following ports in the expression 

         

        column1 (input port)

        counter = counter+1 (variable port)

        Dummycolumn (output port) : IIF( counter=1, "COLUMN STUDENT | COLUMN PARENT | COLUMN MOTHER | COULMN TEACHER|" ||CHR(10) || Column1 ,Column1)

        column2 (I/O port)

        column3 (I/O port)

         

        Please let me know if you face any issues.

         

        Regards

        Sasiramesh

          • Felix Ho Expert 342 posts since
            Aug 23, 2011
            Currently Being Moderated
            Nov 20, 2012 6:28 PM (in response to lavan kumar)
            how to achieve this scenario....?

            Hi Lavan,

             

            Counter is a variable port. [Let's say it start with 0]

             

            For example you have 3 rows from the source:

            STUDENT |  TEACHER | Variable

            Peter     Mr. Robin         Counter = Counter +1 = 0 +1 = 1

            Mary     Mr. Robin         Counter = Counter +1 = 1 +1 = 2

            John     Mr. Robin         Counter = Counter +1 = 2 +1 = 3

             

             

            For Sasi's solution, he want to apply the hardcode field name in the counter row.

            So there is another dummy column output used with counter.

          • sasi ramesh Master 1,110 posts since
            Oct 2, 2010
            Currently Being Moderated
            Nov 21, 2012 12:02 AM (in response to lavan kumar)
            how to achieve this scenario....?

            Hi Lavan,

             

            When the mapping run every time ,Only for the initial records it will append the header ,for that i have created a counter .so it wont append the header values for all records.

             

             

            Input

            col1       col2       col3

            sasi       17522    5000

            ramesh   17521   3000

             

            In expression

            col1(i)   Counter (v)               dummyport                                                   col2              col3

            sasi          1                   first name| emp id|sal |\n  sasi                             17522            5000   

            ramesh    2                 ramesh                                                                17520                3000

             

             

            Regards

            Sasiramesh

  • Jaspreet Banga Expert 526 posts since
    Jun 14, 2011
    Currently Being Moderated
    Nov 21, 2012 7:50 PM (in response to lavan kumar)
    Re: how to achieve this scenario....?

    HI lavan,

     

    there can be another approach of automating the file creation process using unix , I mean the code will check weather the file exist for current month or not if it not exist it will create the new file with current month and current date

     

    This is how it will work.

     

    #!/bin/ksh
    cd /src_file/directory

    export crnt_mnth=$(date "+%m")
    export crnt_day=$(date "+%d")

    if [ ! -f file_name_$crnt_mnth* ]
    then
    touch file_name_$crnt_mnth"_"$crnt_day".txt"
    chmod 777 file_name_$crnt_mnth"_"$crnt_day".txt"
    fi

     

    the above script will check in your source directory if file exist or not, if the file does not exist it will create it, else it will come out with exit code as 0.

     

    Now regarding the pipe delimeter , you can directly chage this in properties of your flat file, in target designer pull your target file , go to itsproperties and  just give the delimeter as Pipe.

     

    Thanks,

    Jaspreet

  • Nagarjuna Reddy Kumbum Novice 72 posts since
    Aug 23, 2011
    Currently Being Moderated
    Nov 23, 2012 9:25 AM (in response to lavan kumar)
    Re: how to achieve this scenario....?

    Hi,

    from your question i get is like the file name changes every month/day and you want custom header inyour target flatfile.

     

    If i am correct then here is the solution:

     

    1. create an workflow variable with nstring data type.
    2. creat an assingment task and the assign the workflow variable created with the following expression:

    'D://FOLDER_NAME/TARGET_FILE_'|| TO_CHAR(SYSDATE,'MONTH') ||'_'|| TO_CHAR(SYSDATE,'DAY') ||'.txt'

     

    3. link this assignment taks before the session which needs this workflow variable in the workflow.

     

    4.. Give this workflow variable in the target filename of the session.

     

    5. for custom header go to the session properties of that session and for the attribute "Header options" set it to "Use header command Output" and set "Header command" attribute with the below script:

    ECHO

    "COLUMN STUDENT | COLUMN PARENT | COLUMN MOTHER | COLUMN TEACHER

     

    This methodology works fine on both UNIX and Windows hostings and without any scripting

     

    hope this might help you..

     

    Please let me know for any queries.

    -Nagarjuna

More Like This

  • Retrieving data ...

Bookmarked By (0)