I have a job which runs for a company code. I have ‘n’ number of company codes, for that to run I can use a while loop. If I want to run only for 5 different company codes, which may vary, how can I create a logic for such condition.
You mean to do like if you have 20 company codes to run, you would want to limit the number of runs to be 5 at any time? If so then add an counter variable and increment inside the WHILE Loop Workflow.
If I understood wrong then please elaborate on your requirement
Thanks for your reply Ganesh, I should have an option to enter 5 different company codes, for eg: there are 20 company codes from 1 to 20, I would like to run only 5, 12, 17 ,19,20 numbered company codes i.e some random ones. Is that possible to do that?
I believe this can be done. My thought is to set up a global var that will encompass delimited company code values (5|12|17|19|20); also set up a global var with the number of iterations (in this case 5). These values can be entered into the var via the DSMC (execute/global vars) sort of like an unprompted prompt. In your code parse the company values for each iteration.
I hope this helps; if I’m too vague ask and I will elaborate.
Are you familar with the Data Services Management Console? When you execute a job, just above the execute button and substitution parameters at the bottom of the page, there is a link called Global Variables. Open this link and you will see all of the global variables that belong to the job being executed. It is here that you would enter the delimited company values and the number of iterations (providing the global variables have been previously created).
In your code, before the while loop extract the first value from the global company value into a company variable (use a substring algorythm) used to determine the company to be processed. Iterate through the loop using the number of iterations variable and a loop counter to count the iterations as they happen (loop exit strategy). After the first iteration has completed extract the second company number to be processed from within the loop using the same substring algorythm as before, increment the loop counter, etcetera.
Taking the example above, of needing to run for 5 out of 20 possible codes, let’s say they’re numbered 1 - 20.
How are you going to determine which 5 codes to run for? Are they held in a table/file somewhere?
Assuming you can establish which 5 codes you need, I’d write the 5 codes i needed to a table that has 2 fields, company_code and processed_flag.
At the start of the job set all processed flags to 0.
Next, populate a global variable with the value returned from selecting the min company_code where processed flag = 1, but wrap it in an nvl function, something like this.
$G_loop_var = sql(‘ds_my_ds’,‘select nvl(min(company_code),99) from job_control where processed_flag = 0’);
in the loop, set it to loop while $G_loop_var doesn’t equal 99, hence it will stop once it returns a null from the job_control table.
Remember at the end of the loop to add a script that sets the processed flag to 1 after you’ve processed that company code.