Consultor Eletrônico



Kbase 15831: How to populate a browse from a temp-table in V7 & V8
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   10/15/2008
Status: Verified

GOAL:

How to populate a browse from a temp-table in V7 & V8.

FACT(s) (Environment):

Progress 7.x
Progress 8.x

FIX:

In versions prior to version 9, The Progress UIB does not allow you to directly create a browse that can/will be populated from a temp-table. There is a way to fool Progress into believing that the temp-table is a table in the database though.  The following example will explain how.

Set-up:
=======

Before we can accomplish this task we need to do some set-up of our development environment.  First do the following;
1)  Start the UIB.
2)  Go to -> Options -> Preferences...
3)  Uncheck the toggle-box "Fully Qualify Database fields with
   Database name" so that it is off.
4)  Use the UIB Section Editor (Definition Section) to define your
   temp-table.
5)  Go to -> Tools -> Data Dictionary
6)  Click on "Create Table"
7)  Create a table with the same name as the temp-table.

****Note:  This should only be done in your development environment.  In your live environment you do not need this table in your database.

8)  Now create fields for this table exactly like the defined fields
   for your temp-table.
9)  Now return to the UIB and create a browse based against the new
   table in the database.
10) Populate your temp-table with information or set up the structure
    by which your temp-table will be populated.

Now that "Fully Qualify Database fields with Database name" is turned off you can design your window and browse.  When this is compiled and run it will consider that the database is sports and populate the browse from the temp-table.  The following example will demonstrate this process.

Notes:
======
1)  Remember you only need this table to be added to your
   development database not your live one.
2)  Make sure the Temp-table and table names are the same, but unique
   in all other aspects.
3)  Make sure the Temp-table and table field names are the same, but
   unique in all other aspects.
4)  This will work for viewers also.

Code Sample:
============

To use the following code do the following;
1)  Copy the following code and paste it in your procedure editor.
2)  save the code as examplepopulate.w
3)  open this code in your UIB

&ANALYZE-SUSPEND _VERSION-NUMBER UIB_v8r12 GUI
&ANALYZE-RESUME
&Scoped-define WINDOW-NAME W-Win
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _DEFINITIONS W-Win
/*------------------------------------------------------------------------

 File:

 Description: from cntnrwin.w - ADM SmartWindow Template

 Input Parameters:
     <none>

 Output Parameters:
     <none>

 History:
         
------------------------------------------------------------------------*/
/*          This .W file was created with the Progress UIB.             */
/*----------------------------------------------------------------------*/

/* Create an unnamed pool to store all the widgets created
    by this procedure. This is a good default which assures
    that this procedure's triggers and internal procedures
    will execute in this procedure's storage, and that proper
    cleanup will occur on deletion of the procedure. */

CREATE WIDGET-POOL.

/* ***************************  Definitions  ************************** */

/* Parameters Definitions ---                                           */

/* Local Variable Definitions ---                                       */

define temp-table tt-stuff
   field holder as char
   field holder2 as char.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-PREPROCESSOR-BLOCK

/* ********************  Preprocessor Definitions  ******************** */

&Scoped-define PROCEDURE-TYPE SmartWindow

&Scoped-define ADM-CONTAINER WINDOW

/* Name of first Frame and/or Browse and/or first Query                 */
&Scoped-define FRAME-NAME F-Main
&Scoped-define BROWSE-NAME BROWSE-5

/* Internal Tables (found by Frame, Query & Browse Queries)             .*/
&Scoped-define INTERNAL-TABLES tt-stuff

/* Definitions for BROWSE BROWSE-5                                      */
&Scoped-define FIELDS-IN-QUERY-BROWSE-5 holder holder2   
&Scoped-define ENABLED-FIELDS-IN-QUERY-BROWSE-5   
&Scoped-define FIELD-PAIRS-IN-QUERY-BROWSE-5
&Scoped-define SELF-NAME BROWSE-5
&Scoped-define OPEN-QUERY-BROWSE-5 OPEN QUERY {&SELF-NAME} FOR EACH tt-stuff.
&Scoped-define TABLES-IN-QUERY-BROWSE-5 tt-stuff
&Scoped-define FIRST-TABLE-IN-QUERY-BROWSE-5 tt-stuff


/* Definitions for FRAME F-Main                                         */
&Scoped-define OPEN-BROWSERS-IN-QUERY-F-Main ~
   ~{&OPEN-QUERY-BROWSE-5}

/* Standard List Definitions                                            */
&Scoped-Define ENABLED-OBJECTS RECT-1 FILL-IN-1 FILL-IN-2 BUTTON-2 BUTTON-1 ~
BROWSE-5
&Scoped-Define DISPLAYED-OBJECTS FILL-IN-1 FILL-IN-2

/* Custom List Definitions                                              */
/* List-1,List-2,List-3,List-4,List-5,List-6                            */

/* _UIB-PREPROCESSOR-BLOCK-END */
&ANALYZE-RESUME


/* ***********************  Control Definitions  ********************** */

/* Define the widget handle for the window                              */
DEFINE VAR W-Win AS WIDGET-HANDLE NO-UNDO.

/* Definitions of the field level widgets                               */
DEFINE BUTTON BUTTON-1
    LABEL "refresh browse"
    SIZE 18 BY 1.14.

DEFINE BUTTON BUTTON-2
    LABEL "Add to TT"
    SIZE 15 BY 1.14.

DEFINE VARIABLE FILL-IN-1 AS CHARACTER FORMAT "X(256)":U
    LABEL "Holder"
    VIEW-AS FILL-IN
    SIZE 29 BY 1 NO-UNDO.

DEFINE VARIABLE FILL-IN-2 AS CHARACTER FORMAT "X(256)":U
    LABEL "Holder2"
    VIEW-AS FILL-IN
    SIZE 29 BY 1 NO-UNDO.

DEFINE RECTANGLE RECT-1
    EDGE-PIXELS 2 GRAPHIC-EDGE  NO-FILL
    SIZE 50 BY 5.95.

/* Query definitions                                                    */
&ANALYZE-SUSPEND
DEFINE QUERY BROWSE-5 FOR
     tt-stuff SCROLLING.
&ANALYZE-RESUME

/* Browse definitions                                                   */
DEFINE BROWSE BROWSE-5
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _DISPLAY-FIELDS BROWSE-5 W-Win _FREEFORM
 QUERY BROWSE-5 DISPLAY
     holder holder2
/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
   WITH NO-ROW-MARKERS SIZE 60 BY 8.1.


/* ************************  Frame Definitions  *********************** */

DEFINE FRAME F-Main
    FILL-IN-1 AT ROW 2.91 COL 26 COLON-ALIGNED
    FILL-IN-2 AT ROW 4.33 COL 26 COLON-ALIGNED
    BUTTON-2 AT ROW 6 COL 26
    BUTTON-1 AT ROW 6 COL 40
    BROWSE-5 AT ROW 9.1 COL 11
    RECT-1 AT ROW 1.95 COL 17
   WITH 1 DOWN NO-BOX KEEP-TAB-ORDER OVERLAY
        SIDE-LABELS NO-UNDERLINE THREE-D
        AT COL 1 ROW 1
        SIZE 80 BY 17.


/* *********************** Procedure Settings ************************ */

&ANALYZE-SUSPEND _PROCEDURE-SETTINGS
/* Settings for THIS-PROCEDURE
  Type: SmartWindow
  Allow: Basic,Browse,DB-Fields,Query,Smart,Window
*/
&ANALYZE-RESUME _END-PROCEDURE-SETTINGS

/* *************************  Create Window  ************************** */

&ANALYZE-SUSPEND _CREATE-WINDOW
IF SESSION:DISPLAY-TYPE = "GUI":U THEN
 CREATE WINDOW W-Win ASSIGN
        HIDDEN             = YES
        TITLE              = "<insert SmartWindow title>"
        HEIGHT             = 17.05
        WIDTH              = 78.6
        MAX-HEIGHT         = 19.62
        MAX-WIDTH          = 93.2
        VIRTUAL-HEIGHT     = 19.62
        VIRTUAL-WIDTH      = 93.2
        RESIZE             = no
        SCROLL-BARS        = no
        STATUS-AREA        = no
        BGCOLOR            = ?
        FGCOLOR            = ?
        THREE-D            = yes
        MESSAGE-AREA       = no
        SENSITIVE          = yes.
ELSE {&WINDOW-NAME} = CURRENT-WINDOW.
/* END WINDOW DEFINITION                                                */
&ANALYZE-RESUME


/* ***************  Runtime Attributes and UIB Settings  ************** */

&ANALYZE-SUSPEND _RUN-TIME-ATTR.IBUTES
/* SETTINGS FOR WINDOW W-Win
 VISIBLE,,RUN-PERSISTENT                                               */
/* SETTINGS FOR FRAME F-Main
                                                                       */
/* BROWSE-TAB BROWSE-5 BUTTON-1 F-Main */
IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(W-Win)
THEN W-Win:HIDDEN = yes.

/* _RUN-TIME-ATTRIBUTES-END */
&ANALYZE-RESUME


/* Setting information for Queries and Browse Widgets fields            */

&ANALYZE-SUSPEND _QUERY-BLOCK BROWSE BROWSE-5
/* Query rebuild information for BROWSE BROWSE-5
    _START_FREEFORM
OPEN QUERY {&SELF-NAME} FOR EACH tt-stuff.
    _END_FREEFORM
    _Query            is OPENED
*/  /* BROWSE BROWSE-5 */
&ANALYZE-RESUME




&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _INCLUDED-LIB W-Win
/* ************************* Included-Libraries *********************** */

{src/adm/method/containr.i}

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


/* ************************  Control Triggers  ************************ */

&Scoped-define SELF-NAME W-Win
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL W-Win W-Win
ON END-ERROR OF W-Win /* <insert SmartWindow title> */
OR ENDKEY OF {&WINDOW-NAME} ANYWHERE DO:
 /* This case occurs when the user presses the "Esc" key.
    In a persistently run window, just ignore this.  If we did not, the
    application would exit. */
 IF THIS-PROCEDURE:PERSISTENT THEN RETURN NO-APPLY.
END.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL W-Win W-Win
ON WINDOW-CLOSE OF W-Win /* <insert SmartWindow title> */
DO:
 /* This ADM code must be left here in order for the SmartWindow
    and its descendents to terminate properly on exit. */
 APPLY "CLOSE":U TO THIS-PROCEDURE.
 RETURN NO-APPLY.
END.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define SELF-NAME BUTTON-1
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL BUTTON-1 W-Win
ON CHOOSE OF BUTTON-1 IN FRAME F-Main /* refresh browse */
DO:
 open query browse-5  for each tt-stuff.
END.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define SELF-NAME BUTTON-2
&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CONTROL BUTTON-2 W-Win
ON CHOOSE OF BUTTON-2 IN FRAME F-Main /* Add to TT */
DO:
 create tt-stuff.
   Assign holder = FILL-IN-1:screen-value.
   Assign holder2 = FILL-IN-2:screen-value.
END.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&Scoped-define BROWSE-NAME BROWSE-5
&UNDEFINE SELF-NAME

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _CUSTOM _MAIN-BLOCK W-Win


/* ***************************  Main Block  *************************** */

/* Include custom  Main Block code for SmartWindows. */
{src/adm/template/windowmn.i}

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


/* **********************  Internal Procedures  *********************** */

&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE adm-create-objects W-Win _ADM-CREATE-OBJECTS
PROCEDURE adm-create-objects :
/*------------------------------------------------------------------------------
 Purpose:     Create handles for all SmartObjects used in this procedure.
              After SmartObjects are initialized, then SmartLinks are added.
 Parameters:  <none>
------------------------------------------------------------------------------*/

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE adm-row-available W-Win _ADM-ROW-AVAILABLE
PROCEDURE adm-row-available :
/*------------------------------------------------------------------------------
 Purpose:     Dispatched to this procedure when the Record-
              Source has a new row available.  This procedure
              tries to get the new row (or foriegn keys) from
              the Record-Source and process it.
 Parameters:  <none>
------------------------------------------------------------------------------*/

 /* Define variables needed by this internal procedure.             */
 {src/adm/template/row-head.i}

 /* Process the newly available records (i.e. disp.lay fields,
    open queries, and/or pass records on to any RECORD-TARGETS).    */
 {src/adm/template/row-end.i}

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE disable_UI W-Win _DEFAULT-DISABLE
PROCEDURE disable_UI :
/*------------------------------------------------------------------------------
 Purpose:     DISABLE the User Interface
 Parameters:  <none>
 Notes:       Here we clean-up the user-interface by deleting
              dynamic widgets we have created and/or hide
              frames.  This procedure is usually called when
              we are ready to "clean-up" after running.
------------------------------------------------------------------------------*/
 /* Delete the WINDOW we created */
 IF SESSION:DISPLAY-TYPE = "GUI":U AND VALID-HANDLE(W-Win)
 THEN DELETE WIDGET W-Win.
 IF THIS-PROCEDURE:PERSISTENT THEN DELETE PROCEDURE THIS-PROCEDURE.
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE enable_UI W-Win _DEFAULT-ENABLE
PROCEDURE enable_UI :
/*------------------------------------------------------------------------------
 Purpose:     ENABLE the User Interface
 Parameters:  <none>
 Notes:       Here we display/view/enable the widgets in the
              user-interface.  In addition, OPEN all queries
              associated with each FRAME and BROWSE.
              These statements here are based on the "Other
              Settings" section of the widget Property Sheets.
------------------------------------------------------------------------------*/
 DISPLAY FILL-IN-1 FILL-IN-2
     WITH FRAME F-Main IN WINDOW W-Win.
 ENABLE RECT-1 FILL-IN-1 FILL-IN-2 BUTTON-2 BUTTON-1 BROWSE-5
     WITH FRAME F-Main IN WINDOW W-Win.
 {&OPEN-BROWSERS-IN-QUERY-F-Main}
 VIEW W-Win.
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE local-exit W-Win
PROCEDURE local-exit :
/* -----------------------------------------------------------
 Purpose:  Starts an "exit" by APPLYing CLOSE event, which starts "destroy".
 Parameters:  <none>
 Notes:    If activated, should APPLY CLOSE, *not* dispatch adm-exit.   
-------------------------------------------------------------*/
  APPLY "CLOSE":U TO THIS-PROCEDURE.
  
  RETURN.
      
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE send-records W-Win _ADM-SEND-RECORDS
PROCEDURE send-records :
/*------------------------------------------------------------------------------
 Purpose:     Send record ROWID's for all tables used by
              this file.
 Parameters:  see template/snd-head.i
------------------------------------------------------------------------------*/

 /* Define variables needed by this internal procedure.               */
 {src/adm/template/snd-head.i}

 /* For each requested table, put it's ROWID in the output list.      */
 {src/adm/template/snd-list.i "tt-stuff"}

 /* Deal with any unexpected table requests before closing.           */
 {src/adm/template/snd-end.i}

END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME


&ANALYZE-SUSPEND _UIB-CODE-BLOCK _PROCEDURE state-changed W-Win
PROCEDURE state-changed :
/* -----------------------------------------------------------
 Purpose:     
 Parameters:  <none>
 Notes:       
-------------------------------------------------------------*/
 DEFINE INPUT PARAMETER p-issuer-hdl AS HANDLE NO-UNDO.
 DEFINE INPUT PARAMETER p-state AS CHARACTER NO-UNDO.
END PROCEDURE.

/* _UIB-CODE-BLOCK-END */
&ANALYZE-RESUME
.