Creating a Subfile



Sample code:
Display file source:                 PUISAMPLES/QDDSSRC(GRID001D)
RPGLE source:                      PUISAMPLES/QRPGLESRC(GRID001R)

Subfiles are lists of items.  They are created using grid widgets in Profound UI.  To create a simple subfile, follow these steps:

  1. Create the grid

    Drag a new subfile grid widget on the canvas.

  2. Create columns

    You can add or remove columns by using the plus and minus icons on the right side of the grid.


  3. Size Columns

    You can resize columns by dragging the column’s vertical border from side to side.


  4. Set headings

    Double-click into each column’s heading to modify the heading text and formatting.




    Alternatively, if the subfile in your application does not need headings, set the has header property to false.


  5. Add subfile fields

    To add fields to the subfile, drag and drop other widgets into the first row of the subfile and then bind them to RPG fields.  For example, to output the Product Id, drag the Dynamic Output Field widget into the first row of the Product Id column.




    The column will be highlighted, right before you drop the element.  Once the element is dropped, it will repeat to all rows within the subfile.




    Now, bind the value property to the appropriate RPG field.  This can be done by double-clicking the widget.

    Note: In addition to output fields, most other widgets can also belong in a subfile, including action elements like buttons and hyperlinks, and input elements like checkboxes and dropdowns.

  6. Set up number of visible rows

    You can add or remove visible rows by selecting the plus and minus icons at the bottom of the grid.


  7. Control alignment

    Field alignment can be controlled through the widget’s text align property, which can be accessed in the Properties Window once the widget is selected or by using the Formatting section of the Edit toolbar in the Ribbon.  For output fields, you must ensure that the element has a predefined width.  This can be accomplished by resizing the element horizontally or setting the width property manually in the Properties Window.

  8. Setting the clear subfile indicator

    The grid component contains a number of properties that allow you to control it through server-side RPG coding.  One critical property is clear subfile, the equivalent of the CLRSFL keyword from traditional green-screen programming.  It is conventional to clear the subfile before loading it with data.  To accomplish this, bind the clear subfile property to an indicator field.  Then, in your RPG code, set the indicator and write the subfile control record to clear the subfile.

  9. Setting record format names

    Before utilizing the grid in your RPG code, you must set record format names for the subfile and for the screen that contains the subfile, which is referred to as the subfile control record.

    To set the subfile record format, select the grid, and modify its record format name property.

    To set the subfile control record format, click the canvas to select screen properties, and then set the record format name property.

    These changes will be reflected in the Record Format List in the top right area of the visual designer.

  10. Writing the RPG

    The RPG code to load the subfile with data may look as follows:

    // Program: GRID001R // Type: RPGLE // Description: Simple Subfile Example. // // Copyright (c) Profound Logic Software, Inc. All rights reserved. H DFTACTGRP(*NO) FGRID001D CF E WORKSTN SFILE(GRIDSFL1: RRN) F HANDLER('PROFOUNDUI(HANDLER)') FPRODUCTSP IF E K DISK D RRN S 5S 0 /Free Dou btnExit = *On; SetLL *LoVal PRODUCTS; Read PRODUCTS; Dow NOT %EOF; RRN +=1; If PSPEC <> 'Y' AND PSPEC <> 'y'; PSPEC = ''; EndIf; Write GRIDSFL1; Read PRODUCTS; EndDo; ExFmt GRIDCTL1; EndDo; *InLr = *On; /End-Free



  11. Equivalent PHP code would look as follows:

<?php // initialize view $view = '/profoundui/userdata/dspf/prodinqd.json'; // read product records $options = array('i5_lib' => 'PUISAMPLES', 'i5_naming' => DB2_I5_NAMING_ON); $conn = db2_connect('', '', '', $options); $query = "SELECT * FROM PRODUCTSP"; $stmt = db2_prepare($conn, $query); $grid = array(); if (db2_execute($stmt)) { while($row = db2_fetch_assoc($stmt)) { // the following statement populates the grid array_push($grid, array('PRODID' => $row['PRID'], 'PRODNAME' => $row['PNAME'])); // Note: if grid fields were named identically to database fields, then a simpe statement like this can be used: // array_push($grid, $row); } } db2_close($conn); // Output the screen $data['PRODSFL'] = $grid; $output = array('data' => $data, 'view' => $view, 'screen' => 'PRODCTL'); echo json_encode($output); ?>