Samples

(click to open)

Quick Page Table of Contents

Scanning…

ezwindow System i Samples

Simple example (Open, Update/Get, Close)

This window was generated by RPG on V5R3 System i using ezwindow binary and rendered on my Linux PC using ssh -X my400. I also rendered the window on my Windows PC using cygwin with ssh -Y my400 (without using VNC). See ILE RPG, ILE c, perl, ksh and php sample code for this window on this page.

ezsimp.dspf: ezWindow Definition

  • File (PASE) or lib/file(mbr) (ILE)
    • EBCDIC for ILE RPG and ILE c in FREEWARE/QDDSSRC(EZSAMP)
    • ASCII for PASE perl, ksh, php, etc. in /home/freeware/ezsamp.dspf
# :tags must start at begin line
# to be correctly read by ezwindow    
# -------- Window definition -------
:start my_window title=GetBio exit_buttons=no \
typechk_rc=0 fg=Black bg=LightSteelBlue hide=yes
:ltr frame=yes
:text_entry_group input_fg=SlateBlue input_bg=LightGrey \
enter=exit(0)
Name:\length=40
Age: \length=2
:eltr
:ltr
:hot_button name=" Ok      "  rc=0 fg=ivory bg=DarkSlateBlue
:hot_button name=" Cancel  "  rc=4 fg=ivory bg=DarkSlateBlue
:eltr
:text id=msg fg=IndianRed lines=3
:stop

Note: The hide=yes feature will hide the window until a read/update is done on the window, so don’t be alarmed if you are stepping your RPG program through a debugger and ezWinOpen() does not open the window, just keep stepping to ezWinUpdGetDim(). Also if you are using the system debugger remember to add the initialize command ADDENVVAR ENVVAR(DISPLAY) VALUE(‘localhost:10.0′) (ssh -X my400) or ADDENVVAR ENVVAR(DISPLAY) VALUE(‘mypc:10.0′) (no encrypt to PC), so that ezwindow binary knows where to place the GUI screen.

ezsimpr.rpg: ILE RPG

  • Configuration (from 5250 screen)
    • ADDENVVAR ENVVAR(DISPLAY) VALUE(‘localhost:10.0′) (ssh -X my400)
    • ADDENVVAR ENVVAR(DISPLAY) VALUE(‘mypc:10.0′) (no encrypt to PC)
    • Call freeware/ezsimpr
     H AlwNull(*UsrCtl)
      /copy xgui10_h
     d wid             s             10i 0 inz(0)
     D rc              s             10i 0
     D def1            s               *
     D defonly         s               *
     D fields          s               *   dim(1000)
     D fieldsDim       c                   1000
     D upd             s             60a   inz(*blanks)
     D def2            s           1000a
     D name            s             60a   inz(*blanks)
     D age             s             60a   inz(*blanks)

      /free
       def1=ezWinLFM('freeware/qddssrc(ezsimp)'); // read window defs (EBCDIC)
       defonly=ezWinDef(def1:'my_window');        // parse single def
       wid=ezWinOpen(defonly);                    // Display window
       if (wid<0);
         *inlr = *on;                             // Open error; terminate
       endif;
       upd='msg text=" "';                        // Init msg blanks
       dou upd = *blanks;
         rc=ezWinUpdGetDim(wid:upd:
              %addr(fields):fieldsDim);           // Upd/Get user input
         if (rc=4);
           leave;                                 // Cancel button clicked
         endif;
         upd=*BLANKS;
         name=%trim(%str(fields(1)));             // copy results string #1
         age=%trim(%str(fields(2)));              // copy results string #2
         dealloc fields(1);                       // free result storage #1
         dealloc fields(2);                       // free result storage #2
         if (name=*BLANKS);                       // Error. ring bell
           upd='msg text="Please enter your name"; Window bell=yes';
         else;                                    // All OK, display data
           upd='msg text="Data is '+%trim(name)+' '+%trim(age)+'";';
         endif;
       enddo;

       dealloc defonly;
       dealloc def1;
       ezWinClose(wid);

       *inlr = *on;
      /end-free

ezsimpc.c: ILE C

  • Configuration (from 5250 screen)
    • ADDENVVAR ENVVAR(DISPLAY) VALUE(‘localhost:10.0′) (ssh -X my400)
    • ADDENVVAR ENVVAR(DISPLAY) VALUE(‘mypc:10.0′) (no encrypt to PC)
    • Call freeware/ezsimpc
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "xgui10_h"
int main(int argc, char * argv[]){
  int rc, wid;
  char buffer[60];
  char *def1, *defonly, *upd=(char *)&buffer;
  char *name, *age;
  char *fields[1000];
  int fieldsDim=1000;
  def1=ezWinLFM("freeware/qddssrc(ezsimp)"); /* read window (EBCDIC) */
  defonly=ezWinDef(def1,"my_window");        /* parse single def     */
  wid=ezWinOpen(defonly);                    /* Display window       */
  if (wid<0) {
    return -1;                               /* Open error; terminate*/
  }
  strcpy(upd,"msg text=\" \"");              /* Init msg blanks      */
  while(upd){
    rc=ezWinUpdGetDim(wid,upd,
         (char **)&fields,fieldsDim);        /* Upd/Get user input   */
    if (rc==4) {
      break;                                 /* Cancel button clicked*/
    }
    name=fields[0];                          /* name result string #1*/
    age=fields[1];                           /* age result string #2 */
    if (name[0]=='\0'){                      /* Error. ring bell */
      strcpy(upd,
        "msg text=\"Please enter your name\"; Window bell=yes");
    } else {                                 /* All OK, display data */
      sprintf(upd,
        "msg text=\"Data is %s %s\";",name,age);
    }
    free(fields[1]);                         /* free result store #1 */
    free(fields[2]);                         /* free result store #2 */
  }
  free(defonly);
  free(def1);
  ezWinClose(wid);
  return 0;
}

ezsimp.sh: PASE ksh

  • Configuration (from X enabled Linux or Windows or Mac)
    • ssh -X my400 (old version ssh)
    • ssh -Y my400 (old version ssh)
    • /home/freeware/ezsimp.sh
#!/bin/ksh
# ezwindow invocation starts a new PASE process
# adc 78588 78504 ksh ezsimp.sh
# adc 78590     1 ezwindow -Open my_window
# adc 78609 78588 ezwindow -Get 78590
wid=`ezwindow -Open my_window < $0`    # Display window
if ((wid < 0))
  then exit                            # Open error; terminate
fi
IFSsave=$IFS                           # internal field seperator (IFS)
while ((0 == 0))
do
  results=`ezwindow -Get $wid`         # Get user input
  rc=$?
  if ((rc == 4))
    then break                         # Cancel button clicked
  fi
  IFS=";"
  echo "$results"|read name age        # Parse results string on ';'
  IFS=$IFSsave
  if ((${#name} == 0))                 # Error. ring bell
  then
    update_str='msg text="Please enter your name"; Window bell=yes'
  else                                 # All OK, display data
    update_str='msg text="Data is '$name' '$age'";'
  fi
  ezwindow -Update $wid "$update_str"
done
ezwindow -Close $wid                   # Close window
exit

ezsimp.pl: PASE perl

  • Configuration (from X enabled Linux or Windows or Mac)
    • ssh -X my400 (old version ssh)
    • ssh -Y my400 (old version ssh)
    • /home/freeware/ezsimp.pl
#!/usr/bin/perl
# ezwindow invocation starts a new PASE process
# adc 78588 78504 perl ezsimp.pl
# adc 78590     1 ezwindow -Open my_window
# adc 78609 78588 ezwindow -Get 78590
chop($wid = `ezwindow -Open my_window < /home/freeware/ezsimp.dspf`); # Display window
if (($? >> 8) != 0)
  { exit;}                                    # Open error; terminate
$update_str = '';
while () {
  $results = `ezwindow -Get $wid`;            # Get user input
  $rc = ($? >> 8);
  if ($rc == 4)
    { last; }                                 # Cancel button clicked
  ($name, $age) = split( /;/, $results );     # Parse results string on ';'
  #-- Error. ring bell. --#
  if ($name eq '')
    { $update_str='msg text="Please enter your name"; Window bell=yes'; }
  #-- All OK; display data --#
  else 
    { $update_str='msg text="Data is '.$name.' '.$age.'";'; }
  system "ezwindow", '-Update', $wid, $update_str;
} # while()
system "ezwindow -Close $wid";                # Close window
exit;
__END__

ezsimp.php: PASE php

  • Configuration (from X enabled Linux or Windows or Mac)
    • ssh -X my400 (old version ssh)
    • ssh -Y my400 (old version ssh)
    • /home/freeware/ezsimp.php
#!/usr/local/Zend/Core/bin/php-cli
<?php
# ezwindow invocation starts a new PASE process
# adc 78588 78504 php-cli ezsimp.php
# adc 78590     1 ezwindow -Open my_window
# adc 78609 78588 ezwindow -Get 78590
include_once "ezrun.php";
ini_set("display_errors","1");
ERROR_REPORTING(E_ALL);
$wid=rtrim(`ezwindow -Open my_window < /home/freeware/ezsimp.dspf`); # Display window
if (($wid < 0)) exit();                            # Open error; terminate
while ($wid){
  $results= runExternal("ezwindow -Get $wid",$rc); # Get user input (ezrun.php)
  if ($rc == 4) break;                             # Cancel button clicked
  list($name,$age)=split("[;]",$results);          # Parse results string on ';'
  if (!$name){                                     # Error. ring bell
    $update_str ='msg text="Please enter your name";';
    $update_str.='Window bell=yes';
  }
  else {                                           # All OK, display data
    $update_str='msg text="Data is '.$name.' '.$age.'";';
  }
  `ezwindow -Update $wid '$update_str'`;
}
`ezwindow -Close $wid`;                            # Close window
?>

ezrun.php: (PHP include)

# Notes:
#   $results=`ezwindow -Get $wid`;
#   loses ezwindow return code (i.e. cancel button)
#   Try runExternal (ezrun.php):
#   http://us2.php.net/manual/en/function.shell-exec.php

function runExternal($cmd,&$code) {
  $descriptorspec = array(
      0 => array("pipe", "r"),  // stdin is a pipe that the child will read from
      1 => array("pipe", "w"),  // stdout is a pipe that the child will write to
      2 => array("pipe", "w")   // stderr is a file to write to
  );

  $pipes= array();
  $process = proc_open($cmd, $descriptorspec, $pipes);

  $output= "";

  if (!is_resource($process)) return false;

  #close child's input imidiately
  fclose($pipes[0]);

  stream_set_blocking($pipes[1],false);
  stream_set_blocking($pipes[2],false);

  $todo= array($pipes[1],$pipes[2]);

  while( true ) {
      $read= array();
      if( !feof($pipes[1]) ) $read[]= $pipes[1];
      if( !feof($pipes[2]) ) $read[]= $pipes[2];

      if (!$read) break;

      $ready= stream_select($read, $write=NULL, $ex= NULL, 2);

      if ($ready === false) {
          break; #should never happen - something died
      }

      foreach ($read as $r) {
          $s= fread($r,1024);
          $output.= $s;
      }
  }

  fclose($pipes[1]);
  fclose($pipes[2]);

  $code= proc_close($process);

  return $output;
}
?>

Multiple GUI windows (text, list, radio, etc.)

‘’These windows were generated by RPG on V5R3 System i using ezwindow binary and rendered on my Windows PC using cygwin with ssh -Y my400 (without using VNC).

ezgui.dspf: ezWindow Definition

  • File (PASE) or lib/file(mbr) (ILE)
    • EBCDIC for ILE RPG and ILE c in FREEWARE/QDDSSRC(EZGUI)
    • ASCII for PASE perl, ksh, php, etc. in /home/freeware/ezgui.dspf
# :tags must start at begin line
# to be correctly read by ezwindow    
# -------- Window definition -------
:start launch title=Launch exit_buttons=no \
typechk_rc=0 fg=Black bg=honeydew hide=yes
:ltr
:hot_button name=" Text    "  rc=5 fg=ivory bg=DarkSlateBlue
:hot_button name=" Menu    "  rc=6 fg=ivory bg=DarkSlateBlue
:hot_button name=" Entry   "  rc=7 fg=ivory bg=DarkSlateBlue
:hot_button name=" List    "  rc=8 fg=ivory bg=DarkSlateBlue
:eltr
:ltr
:hot_button name=" Option  "  rc=9 fg=ivory bg=DarkSlateBlue
:hot_button name=" Scroll  "  rc=10 fg=ivory bg=DarkSlateBlue
:hot_button name=" Radio   "  rc=11 fg=ivory bg=DarkSlateBlue
:eltr
:text id=EZmsg fg=IndianRed lines=3 bell=no
:ltr
:hot_button name=" Quit    "  rc=4 fg=ivory bg=DarkSlateBlue
:eltr
:stop
###################################################
:start text title="Text" exit_buttons=no \
typechk_rc=0 fg=Black bg=wheat hide=yes
:ltr
:hot_button name=" Ok      "  rc=0 fg=ivory bg=orange
:hot_button name=" Cancel  "  rc=4 fg=ivory bg=orange
:eltr
:text id=EZmsg fg=IndianRed bell=no


:stop
###################################################
###################################################
:start menu title="Menu" exit_buttons=no \
typechk_rc=0 fg=Black bg=LightYellow hide=yes
:menu_bar rc=25  fg=white bg=tomato
:pulldown File\\mnem=F
Open\\mnem=O
Save\\mnem=S
Exit\\mnem=E
:epulldown
:pulldown Help\\mnem=H
About\\mnem=A
:epulldown
:text id=EZmsg lines=3 fg=IndianRed bell=no
:stop
###################################################
###################################################
:start entry title="Entry" exit_buttons=no \
typechk_rc=0 fg=Black bg=MistyRose hide=yes
:text reflow=off
Enter stock symbol data.
:title text="Add..." id=scTitle fg=SlateBlue bg=Grey
:ltr frame=yes
:text_entry_group input_fg=SlateBlue input_bg=LightGrey \
enter=exit(0)
Symbol \max=10 id=sc3SYMB type=NONBLANK
Quantity \max=10 id=sc3QUAN type=WHOLE
Share Price \max=10 id=sc3PRICE type=NUMBER
Lot Nbr\max=10 id=sc3LOT type=WHOLE
Lot Date \max=10 id=sc3DATE comment=(yyyy-mm-dd) \
init="2008-07-04" 
:eltr
:ltr
:hot_button name=" Ok      "  rc=0 fg=ivory bg=MediumVioletRed
:hot_button name=" Cancel  "  rc=4 fg=ivory bg=MediumVioletRed
:eltr
:text id=EZmsg lines=3 fg=IndianRed bell=no
:stop
###################################################
###################################################
:start list title="list" exit_buttons=no \
typechk_rc=0 fg=Black bg=PaleGreen hide=yes
:text reflow=off
Select stock and press ok:
:list id=stockrecs lines=10 width=45 policy=m results=position \
fg=Black bg=MintCream
:ltr
:hot_button name=" Ok      "  rc=0 fg=white bg=ForestGreen
:hot_button name=" Cancel  "  rc=4 fg=white bg=ForestGreen
:eltr
:text id=EZmsg lines=3 fg=IndianRed bell=no
:stop
###################################################
###################################################
:start option title="option" exit_buttons=no \
typechk_rc=0 fg=Black bg=LightSeaGreen hide=yes
:options name="Languages:" default="RPG" \
fg=white bg=RoyalBlue
C
RPG\R
PHP\P
-sep-
Rexx
:ltr
:hot_button name=" Ok      "  rc=0 fg=white bg=DarkTurquoise
:hot_button name=" Cancel  "  rc=4 fg=white bg=DarkTurquoise
:eltr
:text id=EZmsg lines=3 fg=IndianRed bell=no
:stop
###################################################
###################################################
:start scroll title="scroll" exit_buttons=no \
typechk_rc=0 fg=Black bg=azure hide=yes
:scrolled_text id=words lines=10 editable=yes \
fg=White bg=PaleVioletRed
:ltr
:hot_button name=" Ok      "  rc=0 fg=white bg=DarkViolet
:hot_button name=" Cancel  "  rc=4 fg=white bg=DarkViolet
:eltr
:text id=EZmsg lines=3 fg=IndianRed bell=no
:stop
###################################################
###################################################
:start radio title="radio" exit_buttons=no \
typechk_rc=0 fg=Black bg=PaleTurquoise hide=yes
:radio_buttons columns=3 default="RPG" policy=m \
fg=Black bg=ivory
RPG
C
REXX
PHP
Ruby
PERL
:ltr
:hot_button name=" Ok      "  rc=0 fg=white bg=MediumAquamarine
:hot_button name=" Cancel  "  rc=4 fg=white bg=MediumAquamarine
:eltr
:text id=EZmsg lines=3 fg=IndianRed bell=no
:stop
###################################################


ezguir.rpg: ILE RPG

  • Configuration (from 5250 screen)
    • ADDENVVAR ENVVAR(DISPLAY) VALUE(‘localhost:10.0′) (ssh -X my400)
    • ADDENVVAR ENVVAR(DISPLAY) VALUE(‘mypc:10.0′) (no encrypt to PC)
    • Call freeware/ezguir
     H AlwNull(*UsrCtl)
      /copy xgui10_h
      *****************************************************
      * global variables
      *****************************************************
     D rc              s             10i 0 inz(0)
     D def             s               *
     D upd             s            200a   inz(*blanks)

      *****************************************************
      * subroutines
      *****************************************************
     D doPopUp         PR            10i 0
     D   start                       20A   VALUE
     D setLaunch       PR            10i 0
     D getLaunch       PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D setText         PR            10i 0
     D getText         PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D setMenu         PR            10i 0
     D getMenu         PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D setEntry        PR            10i 0
     D getEntry        PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D setList         PR            10i 0
     D getList         PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D setOption       PR            10i 0
     D getOption       PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D setScroll       PR            10i 0
     D getScroll       PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D setRadio        PR            10i 0
     D getRadio        PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

      *****************************************************
      * main(): RPG cycle.
      *****************************************************
      /free
       if (def=*NULL);
         def=ezWinLFM('freeware/qddssrc(ezgui)'); // read window defs
         if (def=*NULL);
           *inlr = *on;                           // read error; terminate
         endif;
       endif;
       select;
       when rc=4;                                 // Cancel button clicked
         dealloc def;                             // free definition
         *inlr = *on;
       when rc=5;                                 // text button clicked
         rc=doPopUp('text');
       when rc=6;                                 // menu button clicked
         rc=doPopUp('menu');
       when rc=7;                                 // entry button clicked
         rc=doPopUp('entry');
       when rc=8;                                 // list button clicked
         rc=doPopUp('list');
       when rc=9;                                 // option button clicked
         rc=doPopUp('option');
       when rc=10;                                // scroll button clicked
         rc=doPopUp('scroll');
       when rc=11;                                // radio button clicked
         rc=doPopUp('radio');
       other;                                     // default launcher
         rc=doPopUp('launch');                      
       endsl;
      /end-free

      *****************************************************
      * popup window
      *****************************************************
     P doPopUp         B
     D doPopUp         PI            10i 0
     D   start                       20A   VALUE

     D rc              s             10i 0 inz(0)
     d wid             s             10i 0 inz(0)
     D defonly         s               *
     D fields          s               *   dim(100)
     D fieldsDim       c                   100
      /free
       defonly=ezWinDef(def:%trim(start));        // parse single def
       if (defonly=*NULL);
          upd='EZmsg text="'+%trim(start)+' not found";';
         return rc;                               // find error; terminate
       endif;
       wid=ezWinOpen(defonly);                    // Display window
       if (wid<0);
         *inlr = *on;                             // Open error; terminate
       endif;
       clear upd;                                 // clear upd buffer
       select;                                    // any updates?
       when (%trim(start)='launch');
         rc=setLaunch();
       when (%trim(start)='text');
         rc=setText();
       when (%trim(start)='menu');
         rc=setMenu();
       when (%trim(start)='entry');
         rc=setEntry();
       when (%trim(start)='list');
         rc=setList();
       when (%trim(start)='option');
         rc=setOption();
       when (%trim(start)='scroll');
         rc=setScroll();
       when (%trim(start)='radio');
         rc=setRadio();
       other;
       endsl;
       rc=1;
       dou rc<>0;                                 // not ok;
         rc=ezWinUpdGetDim(wid:upd:
              %addr(fields):fieldsDim);           // Upd/Get user input
         select;                                  // handle results
         when (%trim(start)='launch');
           rc=getLaunch(rc:fields);
         when (%trim(start)='text');
           rc=getText(rc:fields);
         when (%trim(start)='menu');
           rc=getMenu(rc:fields);
         when (%trim(start)='entry');
           rc=getEntry(rc:fields);
         when (%trim(start)='list');
           rc=getList(rc:fields);
         when (%trim(start)='option');
           rc=getOption(rc:fields);
         when (%trim(start)='scroll');
           rc=getScroll(rc:fields);
         when (%trim(start)='radio');
           rc=getRadio(rc:fields);
         other;
         endsl;
       enddo;
       dealloc defonly;                           // free file read
       ezWinClose(wid);                           // close window
       return rc;
      /end-free
     P                 E

      *****************************************************
      * handle launch definition
      *****************************************************
     P setLaunch       B
     D setLaunch       PI            10i 0
      /free
       upd='EZmsg text="Select a new window with buttons";';
       return 0;
      /end-free
     P                 E

     P getLaunch       B
     D getLaunch       PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
      /free
       // buttons return code
       return rc;
      /end-free
     P                 E

      *****************************************************
      * handle text definition
      *****************************************************
     P setText         B
     D setText         PI            10i 0
      /free
       upd='EZmsg text="Initial value is roger";';
       return 0;
      /end-free
     P                 E

     P getText         B
     D getText         PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
      /free
       // EZmsg is the only widget on the screen
       if (rc<>0);
         return 999;
       endif;
       upd='EZmsg text="Ok pressed";';
       return 0;
      /end-free
     P                 E

      *****************************************************
      * handle menu definition
      *****************************************************
     P setMenu         B
     D setMenu         PI            10i 0
      /free
       // nothing to do
       return 0;
      /end-free
     P                 E

     P getMenu         B
     D getMenu         PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D menu            s             60a   inz(*blanks)
      /free
       // menu bar will return one string for menu selected
       menu=%trim(%str(fields(1)));             // copy results string #1
       dealloc fields(1);                       // free result storage #1
       if (%trim(menu)='File,Exit');
         return 999;
       endif;
       upd='EZmsg text="'+%trim(menu)+' selected";';
       return 0;
      /end-free
     P                 E

      *****************************************************
      * handle entry definition
      *****************************************************
     P setEntry        B
     D setEntry        PI            10i 0

     D Symbol          s             10a   inz('IBM')
     D Quantity        s             10a   inz('100')
     D Price           s             10a   inz('233.33')
     D LotNbr          s             10a   inz('22')
     D LotDate         s             10a   inz('2008-07-05')
      /free
       // This entry screen has 5 elements
       upd='sc3SYMB init="'+%trim(Symbol)+'";'+
           'sc3QUAN init="'+%trim(Quantity)+'";'+
           'sc3PRICE init="'+%trim(Price)+'";'+
           'sc3LOT init="'+%trim(LotNbr)+'";'+
           'sc3DATE init="'+%trim(LotDate)+'"';
       return 0;
      /end-free
     P                 E

     P getEntry        B
     D getEntry        PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D Symbol          s             10a   inz(*blanks)
     D Quantity        s             10a   inz(*blanks)
     D Price           s             10a   inz(*blanks)
     D LotNbr          s             10a   inz(*blanks)
     D LotDate         s             10a   inz(*blanks)
      /free
       // cancel button pushed (no data)
       if (rc=4);
         return 999;
       endif;
       // This entry screen will always return 5 elements
       Symbol=%trim(%str(fields(1)));           // copy results string #1
       Quantity=%trim(%str(fields(2)));         // copy results string #2
       Price=%trim(%str(fields(3)));            // copy results string #3
       LotNbr=%trim(%str(fields(4)));           // copy results string #4
       LotDate=%trim(%str(fields(5)));          // copy results string #5
       dealloc fields(1);                       // free result storage #1
       dealloc fields(2);                       // free result storage #2
       dealloc fields(3);                       // free result storage #3
       dealloc fields(4);                       // free result storage #4
       dealloc fields(5);                       // free result storage #5
       upd='EZmsg text="'+
           %trim(Symbol)+' '+
           %trim(Quantity)+' '+
           %trim(Price)+' '+
           %trim(LotNbr)+' '+
           %trim(LotDate)+' '+
           '";';
       return 0;
      /end-free
     P                 E

      *****************************************************
      * handle list definition
      *****************************************************
     P setList         B
     D setList         PI            10i 0

     D STOCK_CHAR_t...
     D                 ds                  qualified
     D                                     based(Template)
     D   SYMBOL                      10a
     D   sep1                         1A
     D   NBR                         10a
     D   sep2                         1A
     D   QUOTE                       15a
     D   comma                        1A
     D StockList       ds                  dim(3) likeds(STOCK_CHAR_t)
     d ptr             s               *   inz(%addr(StockList))
      /free
       // This screen has a list
       StockList(1).SYMBOL='ibm'; 
       StockList(1).NBR='3';
       StockList(1).QUOTE ='        $323.99';
       StockList(1).comma=','; 
       StockList(2).SYMBOL='mdt';
       StockList(2).NBR='2';
       StockList(2).QUOTE ='         $68.11';
       StockList(2).comma=','; 
       StockList(3).SYMBOL='mmm';
       StockList(3).NBR='4';
       StockList(3).QUOTE ='        $401.12';
       StockList(3).comma=','; 
       upd='stockrecs items="'+%str(ptr)+'"';
       return 0;
      /end-free
     P                 E

     P getList         B
     D getList         PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D multiline       s            200a   inz(*blanks)
      /free
       // cancel button pushed (no data)
       if (rc=4);
         return 999;
       endif;
       // list will return one string for list items selected
       multiline=%trim(%str(fields(1)));        // copy results string #1
       dealloc fields(1);                       // free result storage #1
       upd='EZmsg text="'+%trim(multiline)+' selected";';
       return 0;
      /end-free
     P                 E

      *****************************************************
      * handle options definition
      *****************************************************
     P setOption       B
     D setOption       PI            10i 0
      /free
       // nothing to do
       return 0;
      /end-free
     P                 E

     P getOption       B
     D getOption       PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D option          s             60a   inz(*blanks)
      /free
       // cancel button pushed (no data)
       if (rc=4);
         return 999;
       endif;
       // options will return one string for option selected
       option=%trim(%str(fields(1)));           // copy results string #1
       dealloc fields(1);                       // free result storage #1
       upd='EZmsg text="'+%trim(option)+' selected";';
       return 0;
      /end-free
     P                 E

      *****************************************************
      * handle scrolled_text definition
      *****************************************************
     P setScroll       B
     D setScroll       PI            10i 0
      /free
       // set scrolled text
       upd='words text="Initial value is roger";';
       return 0;
      /end-free
     P                 E

     P getScroll       B
     D getScroll       PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D words           s            200a   inz(*blanks)
      /free
       // cancel button pushed (no data)
       if (rc=4);
         return 999;
       endif;
       // scrolled_text will return one string
       words=%trim(%str(fields(1)));            // copy results string #1
       dealloc fields(1);                       // free result storage #1
       upd='EZmsg text="'+%trim(words)+'";';
       return 0;
      /end-free
     P                 E

      *****************************************************
      * handle radio button definition
      *****************************************************
     P setRadio        B
     D setRadio        PI            10i 0
      /free
       // nothing to do
       return 0;
      /end-free
     P                 E

     P getRadio        B
     D getRadio        PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D option          s             60a   inz(*blanks)
      /free
       // cancel button pushed (no data)
       if (rc=4);
         return 999;
       endif;
       // radio buttons will return one string for selected
       option=%trim(%str(fields(1)));           // copy results string #1
       dealloc fields(1);                       // free result storage #1
       upd='EZmsg text="'+%trim(option)+' selected";';
       return 0;
      /end-free
     P                 E

Customer Edit (hide window child)

This window was generated by RPG on V5R3 System i using ezwindow binary and rendered on my Linux PC using ssh -X my400. I also rendered the window on my Windows PC using cygwin with ssh -Y my400 (without using VNC). See ILE RPG, ILE c, perl, ksh and php sample code for this window on this page.

ezcust.dspf: ezWindow Definition

  • File (PASE) or lib/file(mbr) (ILE)
    • EBCDIC for ILE RPG and ILE c in FREEWARE/QDDSSRC(EZCUST)
    • ASCII for PASE perl, ksh, php, etc. in /home/freeware/ezcust.dspf
###################################################
:start cust title="Customer" exit_buttons=no \
typechk_rc=0 fg=Black bg=LightSteelBlue hide=yes
:menu_bar rc=25  fg=ivory bg=DarkSlateBlue
:pulldown Customer\\mnem=C
New\\mnem=N
Exit\\mnem=E
:epulldown
:pulldown Help\\mnem=H
About\\mnem=A
:epulldown
:text text="CustomerId      Customer             \
Credit Card     Expires  " \
fg=SlateBlue bg=Grey
:list id=custrecs lines=10 width=65 policy=s1 results=position \
fg=Black bg=ivory click=single rc=27
:text id=EZmsg lines=3 fg=IndianRed bell=no
:stop
###################################################
:start edit title="Edit" exit_buttons=no \
typechk_rc=0 fg=Black bg=LightSteelBlue hide=yes
:title text="Add..." id=scTitle fg=SlateBlue bg=Grey
:ltr frame=yes
:text_entry_group enter=exit(0) \
input_fg=SlateBlue input_bg=ivory
Customer Name \max=20 id=scName type=NONBLANK
Credit Card Number \max=15 id=scCard type=NONBLANK
Credit Card Experation \max=15 id=scExpire type=NONBLANK \
  comment=(yyyy-mm-dd)
:eltr
:space
:ltr
:text text="                   "
:hot_button_row
name="  Ok    " rc=0 fg=ivory bg=DarkSlateBlue
name=" Cancel " rc=3 fg=ivory bg=DarkSlateBlue
:eltr
:text id=EZmsg lines=3 fg=IndianRed bell=no
:stop
###################################################
:start about title="About"  exit_buttons=no \
fg=Black bg=LightSteelBlue hide=yes
:ltr frame=yes
:text reflow=off
This is an RPG ezwindows demo.
:eltr
:space
:ltr
:text text="      "
:hot_button_row
name="  Ok    " rc=0 fg=ivory bg=DarkSlateBlue
:eltr
:stop
###################################################

ezcustr.rpg: ILE RPG

  • Configuration (from 5250 screen)
    • ADDENVVAR ENVVAR(DISPLAY) VALUE(‘localhost:10.0′) (ssh -X my400)
    • ADDENVVAR ENVVAR(DISPLAY) VALUE(‘mypc:10.0′) (no encrypt to PC)
    • Call freeware/ezcustr
     H AlwNull(*UsrCtl)
      /copy xgui10_h
      *****************************************************
      * global variables
      *****************************************************
     D rc              s             10i 0 inz(0)
     D def             s               *
     D upd             s           2000a   inz(*blanks)
     d widCust         s             10i 0 inz(0)
     d widEdit         s             10i 0 inz(0)
     d widAbout        s             10i 0 inz(0)

      *****************************************************
      * customer records
      *****************************************************
     D CUST_CHAR_t...
     D                 ds                  qualified
     D                                     based(Template)
     D   CUSTID                      15a
     D   sep1                         1A
     D   NAME                        20a
     D   sep2                         1A
     D   CARD                        15a
     D   sep3                         1A
     D   EXPIRE                      10a
     D   comma                        1A
     D CustList        ds                  dim(20) likeds(CUST_CHAR_t)
     d HighMAX1        s             10i 0 inz(20)
     d HighRRN1        s             10i 0 inz(0)
     d RRN1            s             10i 0 inz(0)

      *****************************************************
      * subroutines
      *****************************************************
     D doOpen          PR            10i 0
     D   start                       20A   VALUE
     D doPopUp         PR            10i 0
     D   start                       20A   VALUE
     d   wid                         10i 0 VALUE
     D setCust         PR            10i 0
     D getCust         PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D setEdit         PR            10i 0
     D getEdit         PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D setAbout        PR            10i 0
     D getAbout        PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

      *****************************************************
      * main(): RPG cycle.
      *****************************************************
      /free
       if (def=*NULL);
         def=ezWinLFM('freeware/qddssrc(ezcust)'); // read window defs
         if (def=*NULL);
           *inlr = *on;                           // read error; terminate
         endif;
         widCust=doOpen('cust');                  // open cust window
         widEdit=doOpen('edit');                  // open edit window
         widAbout=doOpen('about');                // open about window
         dealloc def;                             // free definition
       endif;
       select;
       when rc=4;                                 // Cancel button clicked
         ezWinClose(widAbout);                    // close about window
         ezWinClose(widEdit);                     // close edit window
         ezWinClose(widCust);                     // close cust window
         *inlr = *on;                             // terminate
       when rc=5;                                 // edit window
         rc=doPopUp('edit':widEdit);
       when rc=6;                                 // about window
         rc=doPopUp('about':widAbout);
       other;                                     // default cust window
         rc=doPopUp('cust':widCust);                      
       endsl;
      /end-free

      *****************************************************
      * open all windows
      *****************************************************
     P doOpen          B
     D doOpen          PI            10i 0
     D   start                       20A   VALUE

     d wid             s             10i 0 inz(0)
     D defonly         s               *
      /free
       defonly=ezWinDef(def:%trim(start));        // parse single def
       if (defonly=*NULL);
         *inlr = *on;                             // Open error; terminate
       endif;
       wid=ezWinOpen(defonly);                    // Display window
       dealloc defonly;                           // free def
       if (wid<0);
         *inlr = *on;                             // Open error; terminate
       endif;
       return wid;                                // return window id
      /end-free
     P                 E

      *****************************************************
      * popup window
      *****************************************************
     P doPopUp         B
     D doPopUp         PI            10i 0
     D   start                       20A   VALUE
     d   wid                         10i 0 VALUE

     D rc              s             10i 0 inz(0)
     D rc1             s             10i 0 inz(0)
     D fields          s               *   dim(100)
     D fieldsDim       c                   100
      /free
       clear upd;                                 // clear update buffer
       select;                                    // any updates?
       when (%trim(start)='cust');
         rc=setCust();
       when (%trim(start)='edit');
         rc=setEdit();
       when (%trim(start)='about');
         rc=setAbout();
       other;
       endsl;
       rc=1;
       dou rc<>0;                                 // not ok;
         rc=ezWinUpdGetDim(wid:upd:
              %addr(fields):fieldsDim);           // Upd/Get user input
         select;                                  // handle results
         when (%trim(start)='cust');
           rc=getCust(rc:fields);
         when (%trim(start)='edit');
           rc=getEdit(rc:fields);
         when (%trim(start)='about');
           rc=getAbout(rc:fields);
         other;
         endsl;
       enddo;
       if (wid<>widCust);                         // main/cust never hide
         rc1=ezWinUpd(wid:'Window hide=yes');     // hide window, no close
       endif;
       return rc;
      /end-free
     P                 E

      *****************************************************
      * handle menu definition
      *****************************************************
     P setCust         B
     D setCust         PI            10i 0

     d ptr             s               *   inz(%addr(CustList))
     d i               s             10i 0 inz(0)
      /free
       // This screen has a list
       if (HighRRN1=0);                           // first time loop
         CustList(1).CUSTID='1'; 
         CustList(1).NAME='Ranger Cairns';
         CustList(1).CARD ='435 342 252 243';
         CustList(1).EXPIRE ='2012-01-01';
         CustList(1).comma=' ';
         HighRRN1+=1;
       else;                                      // verify list update
         for i = 1 to HighRRN1;
           CustList(1).comma=',';
         endfor;
         CustList(HighRRN1).comma=' ';            // last no comma
       endif;
       upd='custrecs items="'+%trim(%str(ptr))+'"'; // list update request
       return 0;
      /end-free
     P                 E

     P getCust         B
     D getCust         PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D menu            s             60a   inz(*blanks)
     D row             s             60a   inz(*blanks)
      /free
       // menu bar will return one string for menu selected
       menu=%trim(%str(fields(1)));               // copy results string #1
       dealloc fields(1);                         // free result storage #1
       // list will return one string for selection
       row=%trim(%str(fields(2)));                // copy results string #1
       dealloc fields(2);                         // free result storage #1
       select;
       when (%trim(menu)='Help,About');           // menu help,About
         return 6;
       when (%trim(menu)='Customer,New');         // menu Customer,New
         RRN1=0;                                  // RRN1=0 means new
         return 5;                                // goto edit window
       when (%trim(menu)='Customer,Exit');        // menu Customer,Exit
         return 4;                                // cancel/exit program
       when (rc=27);                              // list row edit click
         RRN1=%dec(row:12:0);                     // edit row in cust list
         return 5;                                // goto edit window
       other;
       endsl;
       return 0;                                  // ok, stay here
      /end-free
     P                 E

      *****************************************************
      * handle edit definition
      *****************************************************
     P setEdit         B
     D setEdit         PI            10i 0
      /free
       if (RRN1>0);                               // update selected
         upd='scName init="'+%trim(CustList(RRN1).NAME)+'";'+
           'scCard init="'+%trim(CustList(RRN1).CARD)+'";'+
           'scExpire init="'+%trim(CustList(RRN1).EXPIRE)+'"';
       else;                                      // new selected
         upd='scName init=" ";'+
           'scCard init=" ";'+
           'scExpire init=" "';
       endif;
       return 0;
      /end-free
     P                 E

     P getEdit         B
     D getEdit         PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D rc1             s             10i 0 inz(0)
      /free
       // cancel button pushed (no data)
       if (rc=4);
         return 999;                              // goto main/cust window
       endif;
       // This entry screen will always return 3 elements
       if (RRN1=0);                               // new customer?
         RRN1=HighRRN1+1;
       endif;
       if (RRN1<=HighMAX1);                       // cust id in range?
         CustList(RRN1).CUSTID=%char(RRN1);       // cust id is RRN1
         CustList(RRN1).NAME=
           %trim(%str(fields(1)));                // copy results string #1
         CustList(RRN1).CARD=
           %trim(%str(fields(2)));                // copy results string #2
         CustList(RRN1).EXPIRE=
           %trim(%str(fields(3)));                // copy results string #3
         if (RRN1=HighRRN1+1);                    // new record?
           HighRRN1=RRN1;                         // HighRRN1+1
         endif;
         rc1=999;                                 // goto main/cust window
       else;                                      // too many customers
         upd='EZmsg text="Max new customers reached.";';
         rc1=0;                                   // stay to display error
       endif;
       dealloc fields(1);                         // free result storage #1
       dealloc fields(2);                         // free result storage #2
       dealloc fields(3);                         // free result storage #3
       RRN1=0;
       return rc1;                                // if 0, stay here
      /end-free
     P                 E


      *****************************************************
      * handle about definition
      *****************************************************
     P setAbout        B
     D setAbout        PI            10i 0
      /free
       // nothing to do
       return 0;
      /end-free
     P                 E

     P getAbout        B
     D getAbout        PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D option          s             60a   inz(*blanks)
      /free
       return 999;                                // goto main/cust window
      /end-free
     P                 E

Dynamic window (arrays)

This window was generated by RPG on V5R3 System i using ezwindow binary and rendered on my my Windows PC using cygwin with ssh -Y my400 (without using VNC). See ILE RPG, ILE c, perl, ksh and php sample code for this window on this page.

ezbudr.rpg: ILE RPG

  • Configuration (from 5250 screen)
    • ADDENVVAR ENVVAR(DISPLAY) VALUE(‘localhost:10.0′) (ssh -X my400)
    • ADDENVVAR ENVVAR(DISPLAY) VALUE(‘mypc:10.0′) (no encrypt to PC)
    • Call freeware/ezbudr
     H AlwNull(*UsrCtl)
      /copy xgui10_h
      *****************************************************
      * global variables
      *****************************************************
     D i               s             10i 0 inz(0)
     D j               s             10i 0 inz(0)
     D rc              s             10i 0 inz(0)
     D def             s               *
     D bigstring       s           4000a   inz(*blanks)
     D upd             s           2000a   inz(*blanks)
     d widMain         s             10i 0 inz(0)
     d widAbout        s             10i 0 inz(0)
     D EZmsg           s            100a   inz(*blanks)
     D junk            s             20a

      *****************************************************
      * Months
      *****************************************************
     D dsMM            ds
     D mm01                           3    inz('Jan')
     D                                3    inz('Feb')
     D                                3    inz('Mar')
     D                                3    inz('Apr')
     D                                3    inz('May')
     D                                3    inz('Jun')
     D                                3    inz('Jul')
     D                                3    inz('Aug')
     D                                3    inz('Sep')
     D                                3    inz('Oct')
     D                                3    inz('Nov')
     D                                3    inz('Dec')
     D pdsMM           s               *   inz(%addr(dsMM))
     D MM_NBR          c                   %div(%size(dsMM):%size(mm01)) 
     D MM_ARRAY        s              3    dim(MM_NBR) based(pdsMM)
     D last            s              3    inz('Man')
     D curr            s              3    inz('Jan')

      *****************************************************
      * 8(row) x 4(col) array data         (dataCol)
      *****************************************************
     D DATA_VALUE_t...
     D                 ds                  qualified
     D                                     based(Template)
     D   row                         20a   dim(8)
     D dataCol         ds                  dim(4) likeds(DATA_VALUE_t)
     d col             s             10i 0 inz(1)
     d row             s             10i 0 inz(1)
     d pos             s             10i 0 inz(1)

      *****************************************************
      * subroutines
      *****************************************************
     D doOpen          PR            10i 0
     D   start                       20A   VALUE
     D doPopUp         PR            10i 0
     D   start                       20A   VALUE
     d   wid                         10i 0 VALUE
     D setMain         PR            10i 0
     D getMain         PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D setAbout        PR            10i 0
     D getAbout        PR            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)
     D initialize      PR             
     D calculate       PR           
     D edit20d2        PR            20a
     D   PRICE                       20a   value

      *****************************************************
      * main(): RPG cycle.
      *****************************************************
      /free
       if (def=*NULL);
         bigstring=
           '########################################;'+
           ':start main title="Budget" exit_buttons=no'+
           ' typechk_rc=0 fg=Black bg=LightSteelBlue hide=yes;'+
           ':menu_bar rc=25  fg=ivory bg=DarkSlateBlue;'+
           ':pulldown Month\\mnem=M;';
         for i=1 to 12;
           bigstring=%trim(bigstring)+
             MM_ARRAY(i)+';';
         endfor;
         bigstring=%trim(bigstring)+
           'Exit\\mnem=E;'+
           ':epulldown;'+
           ':pulldown Help\\mnem=H;'+
           'About\\mnem=A;'+
           ':epulldown;'+
           ':text text="          Description            '+
           'Budget                 '+
           'Actual               Difference"'+
           ' fg=SlateBlue bg=Grey;'+
           ':ltr frame=yes;'+
           ':text_entry_group enter=exit(0)'+
           ' input_fg=SlateBlue input_bg=Grey;';
           for i=1 to 8;
             bigstring=%trim(bigstring)+
               '\max=2 id=s'+%char(i)+
               '0 editable=no init='+%char(i)+';';
           endfor;
         for i=1 to 4;
           bigstring=%trim(bigstring)+
             ':text_entry_group enter=exit(0)'+
             ' input_fg=SlateBlue input_bg=ivory;';
           for j=1 to 8;
             if (i<4 and j<8);
               bigstring=%trim(bigstring)+
                 '\max=20 id=s'+%char(j)+%char(i)+';';
             else;
               bigstring=%trim(bigstring)+
                 '\max=20 id=s'+%char(j)+%char(i)+' editable=no;';
             endif;
           endfor;
         endfor;
         bigstring=%trim(bigstring)+
           ':eltr;'+
           ':text id=EZmsg lines=3 fg=IndianRed bell=no;'+
           ':stop;'+
           '########################################;'+
           ':start about title="Demo0202"  exit_buttons=no'+
           ' fg=Black bg=LightSteelBlue hide=yes;'+
           ':ltr frame=yes;'+
           ':text reflow=off;'+
           'This is an RPG ezwindows demo.;'+
           ':eltr;'+
           ':space;'+
           ':ltr;'+
           ':text text="      ";'+
           ':hot_button_row;'+
           'name="  Ok    " rc=0 fg=ivory bg=DarkSlateBlue;'+
           ':eltr;'+
           ':stop;'+
           '########################################;';
         def=ezWinTok(bigstring:';');             // format window def(s)
         if (def=*NULL);
           *inlr = *on;                           // read error; terminate
         endif;
         widMain=doOpen('main');                  // open main window
         widAbout=doOpen('about');                // open about window
         dealloc def;                             // free definition
       endif;
       select;
       when rc=4;                                 // Cancel button clicked
         ezWinClose(widAbout);                    // close about window
         ezWinClose(widMain);                     // close Main window
         *inlr = *on;                             // terminate
       when rc=6;                                 // about window
         rc=doPopUp('about':widAbout);
       other;                                     // default main window
         rc=doPopUp('main':widMain);                      
       endsl;
      /end-free

      *****************************************************
      * open all windows
      *****************************************************
     P doOpen          B
     D doOpen          PI            10i 0
     D   start                       20A   VALUE

     d wid             s             10i 0 inz(0)
     D defonly         s               *
      /free
       defonly=ezWinDef(def:%trim(start));        // parse single def
       if (defonly=*NULL);
         *inlr = *on;                             // Open error; terminate
       endif;
       wid=ezWinOpen(defonly);                    // Display window
       dealloc defonly;                           // free def
       if (wid<0);
         *inlr = *on;                             // Open error; terminate
       endif;
       return wid;                                // return window id
      /end-free
     P                 E

      *****************************************************
      * popup window
      *****************************************************
     P doPopUp         B
     D doPopUp         PI            10i 0
     D   start                       20A   VALUE
     d   wid                         10i 0 VALUE

     D rc              s             10i 0 inz(0)
     D rc1             s             10i 0 inz(0)
     D fields          s               *   dim(100)
     D fieldsDim       c                   100
      /free
       clear upd;                                 // clear update buffer
       select;                                    // any updates?
       when (%trim(start)='main');
         rc=setMain();
       when (%trim(start)='about');
         rc=setAbout();
       other;
       endsl;
       rc=1;
       dou rc<>0;                                 // not ok;
         rc=ezWinUpdGetDim(wid:upd:
              %addr(fields):fieldsDim);           // Upd/Get user input
         select;                                  // handle results
         when (%trim(start)='main');
           rc=getMain(rc:fields);
         when (%trim(start)='about');
           rc=getAbout(rc:fields);
         other;
         endsl;
       enddo;
       if (wid<>widMain);                         // main never hide
         rc1=ezWinUpd(wid:'Window hide=yes');     // hide window, no close
       endif;
       return rc;
      /end-free
     P                 E

      *****************************************************
      * handle menu definition
      *****************************************************
     P setMain         B
     D setMain         PI            10i 0
      /free
       if (last<>curr);                           // new month selected?
         initialize();                            // init new month
         last=curr;
       endif;
       clear EZmsg;
       calculate();                               // calculate budget
       for col = 1 to 4;                          // copy to screen
         for row = 1 to 8;                        // entry fields
           if (dataCol(col).row(row)<>*BLANKS);
             upd=%trim(upd)+
               %trim('s'+%char(row)+%char(col))+
               ' init="'+%trim(dataCol(col).row(row))+'";';
           endif;
         endfor;
       endfor;
       if (EZmsg<>*BLANKS);
         upd=%trim(upd)+'EZmsg text="'+%trim(EZmsg)+'";';
       else;
         upd=%trim(upd)+'EZmsg text=" ";';
       endif;
       return 0;
      /end-free
     P                 E

     P getMain         B
     D getMain         PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D menu            s             60a   inz(*blanks)
      /free
       // cancel no data
       if (rc=4);
         return 4;
       endif;
       // menu bar will return one string for menu selected
       menu=%trim(%str(fields(1)));               // copy results string #1
       dealloc fields(1);                         // free result storage #1
       // entry fields will return one string for each row,col
       pos=2;
       for col = 0 to 4;
         for row = 1 to 8;
           if (col=0);
             junk=%trim(%str(fields(pos)));
           else;
             dataCol(col).row(row)=
               %trim(%str(fields(pos)));          // copy results string
           endif;
            dealloc fields(pos);                  // free result storage
           pos+=1;
         endfor;
       endfor;
       select;
       when (%trim(menu)='Help,About');           // menu help,About
         return 6;
       when (%trim(menu)='Month,Jan');            // menu Month,Jan
         curr=MM_ARRAY(1);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Feb');            // menu Month,Feb
         curr=MM_ARRAY(2);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Mar');            // menu Month,Mar
         curr=MM_ARRAY(3);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Apr');            // menu Month,Apr
         curr=MM_ARRAY(4);
         return 999;                              // goto main window
       when (%trim(menu)='Month,May');            // menu Month,May
         curr=MM_ARRAY(5);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Jun');            // menu Month,Jun
         curr=MM_ARRAY(6);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Jul');            // menu Month,Jul
         curr=MM_ARRAY(7);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Aug');            // menu Month,Aug
         curr=MM_ARRAY(8);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Sep');            // menu Month,Sep
         curr=MM_ARRAY(9);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Oct');            // menu Month,Oct
         curr=MM_ARRAY(10);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Nov');            // menu Month,Nov
         curr=MM_ARRAY(11);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Dec');            // menu Month,Dec
         curr=MM_ARRAY(12);
         return 999;                              // goto main window
       when (%trim(menu)='Month,Exit');           // menu Month,Exit
         return 4;                                // cancel/exit program
       other;
       endsl;
       return 999;
      /end-free
     P                 E

      *****************************************************
      * handle about definition
      *****************************************************
     P setAbout        B
     D setAbout        PI            10i 0
      /free
       // nothing to do
       return 0;
      /end-free
     P                 E

     P getAbout        B
     D getAbout        PI            10i 0
     D   rc                          10i 0 VALUE
     D   fields                        *   VALUE dim(100)

     D option          s             60a   inz(*blanks)
      /free
       return 999;                                // goto main window
      /end-free
     P                 E

      *****************************************************
      * calculate(): Routine to calculate data.
      *****************************************************
     P calculate       B
     D calculate       PI          

     d col             s             10i 0 inz(1)
     d row             s             10i 0 inz(1)
     D pos             S             10i 0
     D budget          S             12p 2
     D actual          S             12p 2
     D tbudget         S             12p 2 inz(0.00)
     D tactual         S             12p 2 inz(0.00)
     D diff            S             12p 2
     D var             S              3a
     D error           S              1n
     D cprice          S             15a
     D dl              C                   '$'
     D nb              C                   ' '
      /free
       for row = 1 to 7;
         error=*OFF;
         monitor;
           cprice=%trim(%XLATE(dl:nb:dataCol(2).row(row)));
           budget=%dec(cprice:12:2);
         on-error;
           budget=0.00;
           error=*ON;
         endmon;
         monitor;
           cprice=%trim(%XLATE(dl:nb:dataCol(3).row(row)));
           actual=%dec(cprice:12:2);
         on-error;
           actual=0.00;
           error=*ON;
         endmon;
         diff=budget-actual;
         if (error=*ON);
           dataCol(4).row(row)='$0.00 (entry error)';
           EZmsg = 'Family budget data entry error';
         else;
           if (diff=0.00);
             dataCol(4).row(row)='$0.00 (spot on)';
           elseif (diff<0.00);
             dataCol(4).row(row)=%trim(edit20d2(%char(diff)))+' (ouch)';
           else;
             dataCol(4).row(row)=%trim(edit20d2(%char(diff)))+' (cool)';
           endif;
         endif;
         tbudget+=budget;
         tactual+=actual;
       endfor;
       diff=tbudget-tactual;
       dataCol(2).row(8)=edit20d2(%char(tbudget));
       dataCol(3).row(8)=edit20d2(%char(tactual));
       dataCol(4).row(8)=edit20d2(%char(diff));
      /end-free
     P                 E

      *****************************************************
      * initialize(): Routine to calculate data.
      *****************************************************
     P initialize      B
     D initialize      PI           
      /free
       dataCol(1).row(1)='Mortgage';
       dataCol(2).row(1)=edit20d2('888.88');
       dataCol(3).row(1)=edit20d2('888.88');
       dataCol(1).row(2)='Electric';
       dataCol(2).row(2)=edit20d2('78.88');
       dataCol(3).row(2)=edit20d2('128.88');
       dataCol(1).row(3)='Heat';
       dataCol(2).row(3)=edit20d2('88.88');
       dataCol(3).row(3)=edit20d2('388.88');
       dataCol(1).row(4)='Water';
       dataCol(2).row(4)=edit20d2('8.88');
       dataCol(3).row(4)=edit20d2('18.88');
       dataCol(1).row(5)='Insurance';
       dataCol(2).row(5)=edit20d2('88.88');
       dataCol(3).row(5)=edit20d2('98.88');
       dataCol(1).row(6)='Phone';
       dataCol(2).row(6)=edit20d2('38.88');
       dataCol(3).row(6)=edit20d2('68.88');
       dataCol(1).row(7)='Cable';
       dataCol(2).row(7)=edit20d2('188.88');
       dataCol(3).row(7)=edit20d2('188.88');
       dataCol(1).row(8)=*BLANKS;
       dataCol(2).row(8)=*BLANKS;
       dataCol(3).row(8)=*BLANKS;
      /end-free
     P                 E

      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      * edit20d2(): 20 wide conversion to dollars with 2 decimal points
      *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
     P edit20d2        B                   export
     D edit20d2        PI            20a
     D   PRICE                       20a   value
     D*
     D fmt             ds
     D  val1                          2A
     D  val2                         20A
     D fmtp            s               *   inz(%addr(fmt))
     D ebuf            ds                  based(fmtp)
     D  buf                          22A
     D DPRICE          S             12p 2
      /free
       DPRICE=%dec(PRICE:12:2);
       buf=%editc(DPRICE:'K': *CURSYM);
       return val2;
      /end-free
     P                 E