5 Replies Latest reply on Sep 18, 2020 1:11 PM by Asmita Kesarwani

    Scenario on SetMaxVariable

    priyank Pant New Member

      Hi, i am using a set max variable which is setting the value to25 in a flow. There are 3 files used. But i want the max variable to be reset when the filename changes. Can this be done during the same session run ?

        • 1. Re: Scenario on SetMaxVariable
          priyank Pant New Member

          I need the setmaxvariable value to be reset to 0 when the file name changes

          • 2. Re: Scenario on SetMaxVariable
            Nico Heinze Guru

            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.

             

            1. 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.
            2. In the workflow, you set up an Assignment task before this session; in this Assignment task, set $$WF_INIT_VALUE to 0.
            3. 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.
            4. Also hand over $$WF_INIT_VALUE to $$FINAL_RECNO (the mapping variable).
            5. 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).
            6. Forward v_current_recno to an output port o_current_recno.
            7. After this EXP, set up an Aggregator with o_current_recno as its only input port.
            8. In this AGG, set up one outport port o_final_recno of type Integer with this expression:
            9.     SetMaxVariable( $$FINAL_RECNO, Last( o_current_recno))
            10. 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.
            11. Don't forget to hand over $$FINAL_RECNO to $$WF_NEXT_VALUE in the post-session success assignment.

             

            Regards,

            Nico

            • 3. Re: Scenario on SetMaxVariable
              Asmita Kesarwani Guru

              Refer the below Guide to learn more on :

              SETMAXVARIABLE

               

              In case if you want to reset the value, you can try to delete the persistent values in the Mapping.

               

              Hope this helps.

               

              Thanks,

              Asmita

              • 4. Re: Scenario on SetMaxVariable
                Nico Heinze Guru

                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.

                 

                Regards,

                Nico

                • 5. Re: Scenario on SetMaxVariable
                  Asmita Kesarwani Guru

                  Thank you Nico.

                   

                  Yes that means you will have to edit the mapping. One may try to use the pre-session variable.

                   

                  Thanks,

                  Asmita