cancel
Showing results for 
Search instead for 
Did you mean: 

UDF to name a file based on number of files present on source side during each time

ramu_g4
Participant
0 Kudos

Hi Experts,

My requirement is like suppose if there is a file with 58 records it is getting split in to 12 individual files with 5 records each. Now in mapping level using UDF , we need to name the each file ending with number like here in this example there 12 files that got generated after splitting then UDF should name them  as file1, file2, .... file12 etc. & also counter should be reset to zero every day and start from beginning each day like if tomorrow there n number of files preset on source then they should named as file1, file2 ... filen. Is it possible by global container ? Kindly guide me with code sine I am new to this.

Thanks,

Ramu G.

Accepted Solutions (0)

Answers (3)

Answers (3)

anupam_ghosh2
Active Contributor
0 Kudos

Hi Ramu,

               Please furnish more details on the scenario.

1. Sample input and output file

2. are you using FCC in source

3. do you need fcc in receiver side.

4. format of source file and format of target file to be generated.

5. Is this NFS to NFS or involves FTP/SFTP.

Regards

Anupam

ramu_g4
Participant
0 Kudos

Hi Anupam,

Sorry for delay in my reply. Please find below answers.

1. Sample input and output file

- you can take any files with some sample DT as input & output file should have same content but filenames should have counter at end.

2. are you using FCC in source

No NFS used on source.

3. do you need fcc in receiver side.

No NFS used on target.

4. format of source file and format of target file to be generated.

.DAT would be source file format & .DAT would be target file format

5. Is this NFS to NFS or involves FTP/SFT

NFS to NFS interface.

Thanks,

Ramu.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Ramu,

                  is the input file xml or normal csv file .

Regards

Anupam

ramu_g4
Participant
0 Kudos

Dear Anupam,

Sorry the inputs I gave above are wrong, input channel is SFTP using FCC to convert to xml then in mapping I need UDF to name the files that are split to file1, file2, ...filen etc.

I mapped root node of source & target DT as below with UDF in between them.

Where UDF is used in b/w them, can you please guide me with code.

Thanks,

Ramu G.

anupam_ghosh2
Active Contributor
0 Kudos

Hi Ramu,

1. what is the receiver adapter/protocol? (NFS/FCC/FTP/SFTP)

2. what is the output file type ? xml/csv

3. sample output file produced

4. sample input file

all this info is required to suggest solution to this problem.

Regards

Anupam

ramu_g4
Participant
0 Kudos

Dear Anupam,

Sorry for delayed response.Please find the below answers.

1. what is the receiver adapter/protocol? (NFS/FCC/FTP/SFTP)

    It is NFS.

2. what is the output file type ? xml/csv

    xml

3. sample output file produced

    both input & output file content are one and same , in sender FCC the flat file is getting converted to xml and in mapping

    I am thinking to write an UDF involving global container & dynamic configuration for filename generation

    with counter & again reset it to zero every day using the similar logic in blog suggested by Evgeniy which is:

    

 

4. sample input file

  Please consider some input xml file with any fields where the input & output structures would be same, Just      need to increase the counter in filename using global container UDF.

Thanks,

Ramu G.

former_member182412
Active Contributor
0 Kudos

Hi Ramu,

Every day how many files you picked up from source directory?? is it only one file per day?? or multiple files per day?? I am asking from sender side not for receiver side.

Regards,

Praveen.

ramu_g4
Participant
0 Kudos

Dear Praveen,

Every day how many files you picked up from source directory??

- The count is varies from day to day & it is not constant.

is it only one file per day?? or multiple files per day??


- Multiple files per day.Suppose in a day sender channel is picking up "N" number of files which will have   different name but using UDF I need to name them depending on count like file1, file2, file3, .....fileN .


Next day/next time say there are "M" number of files then they should be named like file1, file2, .... fileM. Kindly suggest.


Thanks,

Ramu G.

former_member182412
Active Contributor
0 Kudos

Hi Ramu,

  • So if you receive First.txt (contains 10 records) from source then you need to create First1.txt, First2.txt
  • If you pickup Second.txt(contains 10 records) from source then you need create
    • Second1.txt, Second2.txt or
    • Second3.txt , Second4.txt because previous count ends at 2.

Regards,

Praveen.

ramu_g4
Participant
0 Kudos

Hi Praveen,

I could manage to split the file but here I just need to name the files according to number using UDF please forget about splitting depending on records count. I could manage to convert .txt to .xml by sender FCC.But my requirement is:

As you said if there are two files like First1.txt, First2.txt then they are converted to xml  in FCC but they need to named as file1.xml , file2.xml .

During second time , say if there are two files Second1.txt, Second2.txt then I need UDF where they can they should be named again as file1.xml , file2.xml but not file3.xml, file4.xml since they have ended with 2 last time.

Thanks,

Ramu G.

former_member182412
Active Contributor
0 Kudos

Hi Ramu,

  • So every time it starts from 1 to as many number of children's??
  • Which means if we pick up First.txt then need to create File1.xml, File2.xml
  • If we pickup another file Second.txt then we need to create File1.xml and File2.xml?? right??
  • If yes If the File1.xml and File2.xml already there in the target directory, do we need to overwrite or do we need to append the records to existing files? or do we need to create File3.xml, File4.xml??

Regards,

Praveen.

ramu_g4
Participant
0 Kudos

Hi Praveen,

  • So every time it starts from 1 to as many number of children's??

         - Yes, right.

  • Which means if we pick up First.txt then need to create File1.xml, File2.xml

        - We can append by timestamp or as you said we can create First1.xml, First2.xml.

  • If we pickup another file Second.txt then we need to create File1.xml and File2.xml?? right??

        - We can create Second1.xml, Second2.xml after picking from Second.txt.

  • If yes If the File1.xml and File2.xml already there in the target directory, do we need to overwrite or do we need to append the records to existing files? or do we need to create File3.xml, File4.xml??

        - We can create either First1.xml, First2.xml (or) Second1.xml, Second2.xml inorder to avoid

           duplicate files issue.


Kindly help me with UDF using global container & Dynamic configuration to achieve this.

Thanks,

Ramu G.

former_member182412
Active Contributor
0 Kudos

Hi Ramu,

You can create separate node to hold the file name and do the mapping for file name in message mapping as i shown in below blog.

Regards,

Praveen.

former_member190293
Active Contributor
0 Kudos

Hi Ramu!

Take a look at this blog record:

It describes approach that you could use as a base for your requirement.

Regards, Evgeniy.

ramu_g4
Participant
0 Kudos

Dear Experts,

Kindly help me on the above requirement, Thanks a ton in advance!

-Ramu G.