This example creates a list box and fills it with the contents of a table:
DISPLAY LIST-BOX, LINES 5, SIZE 30, HANDLE IN BOX-1. PERFORM VARYING IDX FROM 1 BY 1 UNTIL IDX > TABLE-SIZE MODIFY BOX-1, ITEM-TO-ADD = TABLE-ITEM( IDX ) END-PERFORM.
The following Screen Section entry and accompanying code perform the same actions:
03 LIST-1, LIST-BOX, LINES 5, SIZE 30, VALUE SELECTED-ITEM, ITEM-TO-ADD = ADD-ITEM. PERFORM VARYING IDX FROM 1 BY 1 UNTIL IDX > TABLE- SIZE MOVE TABLE-ITEM( IDX ) TO ADD-ITEM DISPLAY LIST-1 END-PERFORM. MOVE SPACES TO ADD-ITEM.
The first time through this loop, the list box is created (if it has not already been created). Subsequent iterations of the loop modify the existing list box. Note the move of spaces to ADD-ITEM at the end. This ensures that future DISPLAYs of LIST-1 (or its parent group item) don't accidentally add another item to the list box.