Window and Display Features


Repeating Fields

If you specify an operand for a field that is a multi-element matrix, the routines deal with the first value of the matrix. However, there is a special group option, REPEAT, that enables you to display and retrieve values from all the elements of a matrix. If the REPEAT option is specified, IML determines the maximum number of elements of any field-operand matrix, and then it repeats the group that number of times. If any field operand has fewer elements, the last element is repeated the required number of times (the last one becomes the data entered). Be sure to write your specifications so that the fields do not overlap. If the fields overlap, an error message results. Although the fields must be matrices, the positional operands are never treated as matrices.

The repeat feature can come in very handy in situations where you want to create a menu for a list of items. For example, suppose you want to build a restaurant billing system and you have stored the menu items and prices in the matrices ITEM and PRICE. You want to obtain the quantity ordered in a matrix called AMOUNT. Enter the following code:

    item={ "Hamburger", "Hot Dog", "Salad Bar", "Milk" };
    price={1.10 .90 1.95 .45};
    amount= repeat(0,nrow(item),1);
    window menu
    group=top
    #1 @2 "Item" @44 "Price" @54 "Amount"
    group=list
    / @2 item $10. @44 price 6.2 @54 amount 4.
    ;
    display menu.top, menu.list repeat;

This creates the following window:

   +-----Menu-----------------------------------------+
   +  Command --->                                    +
   +                                                  +
   +  Item                  Price   Amount            +
   +                                                  +
   +  Hamburger             1.10      0               +
   +  Hot Dog               0.90      0               +
   +  Salad Bar             1.95      0               +
   +  Milk                  0.45      0               +
   +                                                  +
   +------------------------------------------------- +