The ‘while’ function in Turbo Integrator is used to repeat a set of instructions until a certain condition is met. #
This can be useful when you need to perform a task multiple times, such as importing data from multiple files or transforming data in a specific way. The while function works by evaluating a condition at the beginning of each iteration of the loop. If the condition is true, the instructions within the loop are executed. If the condition is false, the loop is exited, and the program continues with the next instruction.
To use the while function in Turbo Integrator, you first need to define the condition that will be evaluated at the beginning of each iteration of the loop. This can be done using a boolean expression, such as a comparison between two values or a logical operator. For example, you could use the while function to loop through the elements in a financial period dimension and process those in the current year. The condition for this loop could be something like “while there are elements in the dimension”. So, we may set the number of times we loop through this to the number of elements in the dimension:
vNumberOfElements = DimSiz(vDimension) ; vLoopCount = 1 ; While (vNumberOfElements > vLoopCount) ; End;
Once you have defined the condition for the while loop, you can then define the instructions that will be executed within the loop. These instructions can include any Turbo Integrator functions or commands, such as transforming data using a formula, or loading data into your planning model. The instructions within the loop will be executed repeatedly until the condition is false. Here if the year is ‘2025’ in the Financial Period element then the period e.g., ‘202501’, ‘202502’ etc. will be written to the ‘While Test’ subset of the ‘Financial Period’ dimension.
While (vNumberOfElements > vLoopCount); vDimensionElement = DimNm(‘Financial Period’, vLoopCount); IF(SubSt (vDimensionElement,1,4)@=’2025’); SubsetElementInsert (‘Financial Period’,’While Test’,vDimensionElement,1); ENDIF; vLoopCount = vLoopCount + 1; End;