I need the setmaxvariable value to be reset to 0 when the file name changes
Nope. That's simply not how mapping variables work. They can either take the lowest value set during a session or the highest value set during a session. It is NOT possible to use them as an "increment" during one source file and reset them to 0 for the next source file.
What you want to achieve needs to be implemented via variable ports in an Expression transformation, I've done that often enough.
Of course you can initialise this variable port from a mapping variable when the session starts, and when the session is done you can hand over the final value of this variable port to a mapping variable, but that requires a bit of additional effort.
For this explanation I assume that your mapping variable is named $$FINAL_RECNO.
- Define two workflow variables of type Integer. Let's name them $$WF_NEXT_VALUE (value is persistent between workflow runs) and $$WF_INIT_VALUE (value is NOT persisted after workflow execution). Initialise both variables to 0.
- In the workflow, you set up an Assignment task before this session; in this Assignment task, set $$WF_INIT_VALUE to 0.
- In the session, define a pre-session variable assignment where you hand over $$WF_NEXT_VALUE to some mapping parameter $$NEXT_VALUE of type Integer.
- Also hand over $$WF_INIT_VALUE to $$FINAL_RECNO (the mapping variable).
- In the EXP you have to insert, make sure that you set the variable port (let's name it v_current_recno) from $$NEXT_VALUE when the session starts; for all other records either increment v_current_recno (if the currently processed input record belongs to the same input file as the previous record) or set it to 0 (in case of a new input file).
- Forward v_current_recno to an output port o_current_recno.
- After this EXP, set up an Aggregator with o_current_recno as its only input port.
- In this AGG, set up one outport port o_final_recno of type Integer with this expression:
- SetMaxVariable( $$FINAL_RECNO, Last( o_current_recno))
- Finally send this output port through a Filter with its condition set to FALSE and from there to a flat file target set to $PMTargetFileDir\NUL (a "bit bucket") under Windows resp. to /dev/null under Linux/Unix.
- Don't forget to hand over $$FINAL_RECNO to $$WF_NEXT_VALUE in the post-session success assignment.
But that would mean editing the mapping. And that's something that's usually not allowed in QA / PROD environments.
So the only "reasonable" way to reset mapping variables is through workflow variables in pre-session variable assignments.
Thank you Nico.
Yes that means you will have to edit the mapping. One may try to use the pre-session variable.