Vous êtes sur la page 1sur 4

Generate a sequence based on session run date.

This question has been Answered.

Vidya Nagaraj Mar 28, 2017 10:00 AM


Hi All,

I have a requirement to send a file. The filename contains a Sequence number (start value=001) which is
increment by 1 each time a file is sent within a day(say: if it is sent 3 time on the same day the nnn value of
filename would be 001,002,003). The sequence has to RESET for the files sent the next day(start value=001,
inc by 1).

The possible solution i can think of is to declare a parameter variable to store the session_run count(seq) and
use it further in the Expression transformation to compute the seq based on the condition. But i'm not sure how
to proceed. Can you please guide?

Filename: ABCD.EFnnn.YYYYMMDD.HHMMSS
eg: ABCD.EF001.20170328.111840
ABCD.EF002.20170329.125500

where,
ABCD.EF = static, will pass it as a string.
nnn = sequence number
YYYYMMDD = date of file generated, TO_CHAR(SYSDATE,'YYYYMMDD')
HHMMSS = timestamp of file generate, TO_CHAR(SYSDATE,'HHMMSS')

o_filename = 'ABCD.EF'||nnn||'.'||YYYYMMDD||'.'||HHMMSS

Nico Heinze Mar 28, 2017 10:41 AM (in response to Vidya Nagaraj)
It would be good to know whether this mapping will be used in one workflow only or whether it may be used
in n mappings. The best (safest / only possible) strategy to implement this "running number per day" depends
on this info.

Furthermore, will the workflow(s) run continuously? Or will it/they run n number of times per day?
And if there may be e.g. two workflows running in parallel executing this mapping, is it necessary to keep the
running number unique per workflow? Or must this running number be shared between the workflows?

Regards,
Nico
o
o Like Show 0 Likes(0)
o Actions
 2. Re: Generate a sequence based on session run date.

Vidya Nagaraj Mar 28, 2017 10:50 AM (in response to Nico Heinze)
Thank for responding back.
This mapping will be used in only 1 workflow.

The job will be scheduled to run twice a month. During this time, it may run multiple times say 3 to 4 times a
day. Hope this details helps....

Thanks.
o
o Like Show 0 Likes(0)
o Actions
 Correct Answer3. Re: Generate a sequence based on session run date.

Nico Heinze Mar 29, 2017 2:39 AM (in response to Vidya Nagaraj)
Hi Vidya,

yes, that does help a lot.

So here's my approach.
As you need to keep track of when this workflow ran for the last time, it makes sense to keep this "last run
day" in a mapping variable. However, dealing with mapping variables (in particular with their initial value
during a mapping run) isn't too easy, so I prefer using a mapping parameter (to hand over the last run date as a
mapping parameter to the mapping) and a mapping variable (to hand over the start day of the current mapping
run to the workflow) plus a persistent workflow variable which keeps this current run day for the next
workflow run.
This means:
1. The workflow hands over the day of the last workflow run to the mapping as a mapping parameter.
2. The workflow will compare this "last run day" to the current day and deal with the running number of the file
per day (we'll come to that later).
3. At the end of the session run the mapping will hand over the start day of this session back to the workflow
variable.
These steps are repeated for the next workflow run. This way the mapping can always safely identify whether
it's currently running for the first time on that day or whether that's a next run during that day.

The same principle holds true for the current file number:
4. The last file number produced during the previous run is handed over from the workflow to this
session as a mapping parameter.
5. Based on the last run day and the current day the mapping can now identify whether it has to increase the
running file number by one (namely if the mapping already has been executed earlier that same day) or
whether the file number has to be reset to 1 (because it's the first run on a new day).

For this approach I need the following mapping parameters:


 $$LAST_FILE_NUMBER (integer, holding the last file number created during the previous session
run),
 $$PREV_START_DATE (string(8), holding the date of the previous session run in format
YYYYMMDD).
Then I need the following mapping variables (which are used to hand over the final values to the workflow
variables):
 $$NEXT_START_VALUE (integer, default value is 0, that's the maximum file number produced
today),
 $$CURRENT_START_DATE (string(8), holding the date when the session started in format
YYYYMMDD).
Then I need of course two persistent workflow variables:
 $$WF_LAST_FILE_NUMBER (integer, that's the maximum file number produced today),
 $$WF_PREV_START_DATE (string, holding the date when the session started in format
YYYYMMDD).

I hope this makes the principle clear. Otherwise please ask.

Regards,
Nico
 HELPFUL

 Like Show 2 Likes(2)
 Actions
 4. Re: Generate a sequence based on session run date.

Vidya Nagaraj Mar 30, 2017 11:59 AM (in response to Nico Heinze)
Appreciate your help Nico!!

I'm not so familiar working on parameters but your explanation helped me clear basics and built the solution
for it. I was able to set the mapping variables ($$NEXT_START_VALUE, $$CURRENT_START_DATE)
and populate the sequence number but i'm missing a link to connect/pass the values of a mapping_varaible to
parameter,thus the condition on resetting seq (if the date change RESET the counter) ain't working.

This is how i approached.

1. Created 2 Parameters($$LAST_FILE_NUMBER, $$PREV_START_DATE)


2. Created 2 mapping_variabls($$NEXT_START_VALUE, $$CURRENT_START_DATE),
3. and 2 persistent Wf_variable($$WF_LAST_FILE_NUMBER, $$WF_PREV_START_DATE)
4. Include a logic in expression to check on the date and compare with SYSDATE. if it does not
match(v_LAST_RUN_DATE = 0) then increment $$NEXT_START_VALUE or else just
increment
sequence(LAST_FILE_NUMBER )

5. set the mapping_variable.

Please let me know where i'm going wrong.

thanks,
Vidya.

 Like Show 0 Likes(0)
 Actions
 5. Re: Generate a sequence based on session run date.
NEERAJ RATHORE Mar 30, 2017 12:59 PM (in response to Vidya Nagaraj)
Hi Vidya

As Nico has mentioned use YYYYMMDD format for holding the date of the previous session run in all
the variables and parameters . As I can see you are using time stamp format and comparing
previous start date and current start date but it will not work because hr min sec will change during
multiple run on same day and it will reset the file number counter to 1 every time.

Thanks
Neeraj
 HELPFUL

 Like Show 1 Like(1)
 Actions
 6. Re: Generate a sequence based on session run date.

Vidya Nagaraj Apr 3, 2017 11:48 AM (in response to NEERAJ RATHORE)


oh Shoot!! Corrected!! I'm now able to generate the sequence which increments for daily load and reset it if
date changes.

Thank you Nico Heinze and Neeraj. Appreciate your help !!


Vous aimerez peut-être aussi