08/29/2016 13:07 p.m.
Just a heads up for those copying and pasting these examples; there is a syntax error.
You'll see in the MvEval lines of code: EXPR". Should be EXPR = "....
|
When combined with the -C (compatibility) compiler flag, MvFOREACH generates code that will run on any engine version 5.00 or newer, using runtime engine version checks to either call these functions or emulate their behavior. Attributes
* Only the ITERATOR and ARRAY elements are required. When COUNT is specified, FIRST, NEXT, and LAST must be omitted. When COUNT is omitted, FIRST, NEXT, and LAST may be used together in any combination. When NEXT is used the expression must increment the INDEX. Examples:This example use <MvFOREACH> in it simplest form to output a number list of orders. The functions miva_array_min() and miva_array_max() are called internally to determine the first and last elements to efficiently traverse sparse arrays. Example:<MvFOREACH ITERATOR = "l.item" ARRAY = "l.orders" INDEX = "l.pos"> <MvEVAL EXPR = "{ l.pos }">. <MvEVAL EXPR = "{ l.item:Fname }"> <MvEVAL EXPR = "{ l.item:Lname }"><br> </MvFOREACH> This variation limits output to 25 items by using the COUNT attribute. It assumes no array elements are empty and the number of items is known. Remember you can not use COUNT with FIRST, NEXT and LAST. Example:<MvASSIGN NAME = "l.items_per_page" VALUE = "{ 25 }"> <MvFOREACH ITERATOR = "l.item" ARRAY = "l.orders" INDEX = "l.pos" COUNT = "{ l.items_per_page }"> <MvEVAL EXPR = "{ l.pos }">. <MvEVAL EXPR = "{ l.item:Fname }"> <MvEVAL EXPR = "{ l.item:Lname }"><br> </MvFOREACH> This example works exactly the same but allows you to control the loop more precisely by specifying parameters. Example:<MvASSIGN NAME="l.items_per_page" VALUE="{ 25 }"> <MvFOREACH ITERATOR = "l.item" ARRAY = "l.orders" INDEX = "l.pos" FIRST = "{ 1 }" NEXT = "{ l.pos + 1 }" LAST = "{ l.items_per_page }"> <MvEVAL EXPR = "{ l.pos }">. <MvEVAL EXPR = "{ l.item:Fname }"> <MvEVAL EXPR = "{ l.item:Lname }"><br> </MvFOREACH> By incrementing the variable g.page_num the next page of 25 items in the array can be output. Example:<MvASSIGN NAME="g.page_num" VALUE="{ g.page_num + 1 }"> <MvASSIGN NAME="l.items_per_page" VALUE="{ 25 }"> <MvASSIGN NAME="l.first" VALUE="{ ((g.page_num - 1) * l.items_per_page) + 1 }"> <MvASSIGN NAME="l.last" VALUE="{ l.first + l.items_per_page - 1 }"> <MvFOREACH ITERATOR = "l.item" ARRAY = "l.orders" INDEX = "l.pos" FIRST = "{ l.first }" NEXT = "{ l.pos + 1 }" LAST = "{ l.last }"> <MvEVAL EXPR = "{ l.pos }">. <MvEVAL EXPR = "{ l.item:Fname }"> <MvEVAL EXPR = "{ l.item:Lname }"><br> </MvFOREACH> This example loops through the orders array skipping any "test orders" by using <MvFOREACHCONTINUE> or exiting the loop if an error occurs by using <MvFOREACHSTOP>. Example:<MvFOREACH ITERATOR = "l.item" ARRAY = "l.orders" INDEX = "l.pos" COUNT = "{ 100 }"> <MvCOMMENT> filter out any test orders </MvCOMMENT> <MvIF EXPR="{ 'test order' IN l.item:fname }"> <MvFOREACHCONTINUE> </MvIF> <MvCOMMENT> If this field is empty display an error and exit the loop. </MvCOMMENT> <MvIF EXPR="{ ISNULL l.item:code }"> <MvEVAL EXPR="{ 'Error in order number ' $ l.item:id $ '. code not found.' }"> <MvFOREACHSTOP> </MvIF> </MvFOREACH>
User Annotations:
MvFOREACH
Scott Shepard
: ids at, southbound d0t com
08/29/2016 13:07 p.m. Just a heads up for those copying and pasting these examples; there is a syntax error.
|