Try OpenEdge Now
skip to main content
Programming Interfaces
Data Management : Database Access : Creating schema cache files : Example schema cache file creation
 
Example schema cache file creation
The following event-driven application allows you to create partial schema cache files for any combination of tables in the sports2000 database.
The main procedure, i-schcs1.p, presents all the available sports2000 database tables in a multiple selection list and a field to enter a name for the schema cache file.
i-schcs1.p
DEFINE VARIABLE filen AS CHARACTER NO-UNDO FORMAT "x(8)"
  LABEL "Schema Cache Name".
DEFINE VARIABLE icnt  AS INTEGER   NO-UNDO.

DEFINE VARIABLE db-table AS CHARACTER LABEL "Select Tables"
  VIEW-AS SELECTION-LIST
  MULTIPLE NO-DRAG SIZE 32 BY 7
  LIST-ITEMS "customer", "invoice", "item", "localdefault",
             "order", "orderline", "refcall", "salesrep",
             "state".

DEFINE BUTTON bsave   LABEL "Save to File".
DEFINE BUTTON bcancel LABEL "Cancel".

DEFINE FRAME SchemaFrame
  SPACE(1)
  db-table
  VALIDATE(db-table <> "" AND db-table <> ?, "You must select a table.")
  filen
  VALIDATE(filen <> "" AND filen <> ?, "You must enter filename.")
  SKIP(1)
  SPACE(20) bsave bcancel
  WITH TITLE "Save Schema Cache File" SIDE-LABELS SIZE 80 by 11.

ON CHOOSE OF bcancel IN FRAME SchemaFrame QUIT.

ON CHOOSE OF bsave IN FRAME SchemaFrame DO:
  ASSIGN filen db-table.
  IF NOT filen:VALIDATE() THEN RETURN NO-APPLY.
  IF NOT db-table:VALIDATE() THEN RETURN NO-APPLY.
  DO WHILE NOT CONNECTED("sports2000"):
    BELL.
    PAUSE MESSAGE
      "When ready to connect the sports2000 database, press <RETURN>".
    CONNECT sports2000 -1 NO-ERROR.
    IF NOT CONNECTED("sports2000") THEN
      DO icnt = 1 to ERROR-STATUS:NUM-MESSAGES:
        MESSAGE ERROR-STATUS:GET-MESSAGE(icnt).
      END.
    ELSE
      MESSAGE "Sports2000 database connected.".
  END.
  RUN i-schcs2.p (INPUT db-table, INPUT filen).
  DISCONNECT sports2000 NO-ERROR.
END. /* ON CHOOSE OF bsave */

ENABLE ALL WITH FRAME SchemaFrame.
WAIT-FOR CHOOSE OF bcancel IN FRAME SchemaFrame.
When you click Save to File, it connects to the sports2000 database, and calls i-schcs2.p, which reads the selected tables and saves the resulting schema cache file in the current working directory.
i-schcs2.p
DEFINE INPUT PARAMETER db-table AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER filen    AS CHARACTER NO-UNDO.

DEFINE VARIABLE iTab AS INTEGER NO-UNDO.

Table-Add:
DO iTab = 1 to NUM-ENTRIES(db-table):
  CASE ENTRY(iTab, db-table):
    WHEN "customer"     THEN FIND FIRST Customer NO-ERROR.
    WHEN "invoice"      THEN FIND FIRST Invoice NO-ERROR.
    WHEN "item"         THEN FIND FIRST Item dO-ERROR.
    WHEN "localdefault" THEN FIND FIRST LocalDefault NO-ERROR.
    WHEN "order"        THEN FIND FIRST Order NO-ERROR.
    WHEN "orderline"    THEN FIND FIRST OrderLine NO-ERROR.
    WHEN "refcall"      THEN FIND FIRST RefCall NO-ERROR.
    WHEN "salesrep"     THEN FIND FIRST SalesRep NO-ERROR.
    WHEN "state"        THEN FIND FIRST State NO-ERROR.
    OTHERWISE           LEAVE Table-Add.
  END CASE.
END.

SAVE CACHE CURRENT sports2000 TO VALUE(filen + ".csh") NO-ERROR.
IF NOT ERROR-STATUS:ERROR THEN
  MESSAGE "Saved partial schema cache for the sports2000 database in "
    + filen + ".csh.".
ELSE DO:
  BELL.
  DO iTab = 1 TO ERROR-STATUS:NUM-MESSAGES:
    MESSAGE ERROR-STATUS:GET-MESSAGE(iTab) VIEW-AS ALERT-BOX.
  END.
END.
The main procedure then disconnects the sports2000 database to allow new table selections for a different schema cache file.