Progress
Language Tutorial
for Windows


Creating Records

When you create a record, you are directly manipulating the database. Progress creates a new empty record and copies that record to the record buffer in EXCLUSIVE-LOCK state. The new record may not be entirely empty, however. Depending on your database schema, some of the fields may have default initial values or values generated by sequences and database triggers. Figure 8–14 shows the data movement of CREATE.

Figure 8–14: Data Movement with the CREATE Statement

This is the syntax for the CREATE statement.

SYNTAX
CREATE table-name 

As soon as you create a record, you’ll want to fill it with data. One way to acquire new data for the record is to use a dialog box with an UPDATE statement.

Follow these steps for a demonstration of creating records:

  1. Open the file named lt-08-05.p and run it. The following display appears:
  2. Choose Add, enter data in the update dialog box, shown below, and choose OK:
  3. The main form displays data from the new record.

  4. Choose Exit, then press SPACEBAR to return to the Procedure Editor.

Here is the code that created the display:

lt-08-05.p
      /**********  DEFINE QUERY  **********/
      DEFINE QUERY Item-Query FOR Item. 
      /**********  DEFINE VARIABLES  **********/
      DEFINE VARIABLE Current-Record AS ROWID.

      /**********  DEFINE FORM  **********/
      {lt-08-f1.i}

      /**********  DEFINE TRIGGERS  **********/
      {lt-08-t1.i} {lt-08-t2.i} 

      ON CHOOSE OF btn-Add
      DO:
/*1*/      CREATE Item.
/*2*/     UPDATE Item.Item-Name Price On-Hand Allocated Re-Order 
            On-Order Cat-Page Cat-Description btn-OK btn-Cancel 
                WITH FRAME Dialog1.
/*3*/     DISPLAY Item-Num Item-Name Price On-Hand Allocated Re-Order 
            On-Order Cat-Page Cat-Description WITH FRAME Frame1.
      END.

     /**********  MAIN LOGIC  **********/
     OPEN QUERY Item-Query FOR EACH Item NO-LOCK.
     GET FIRST Item-Query.
    DISPLAY Item.Item-Num Item-Name Price On-Hand Allocated Re-Order 
        On-Order Cat-Page Cat-Description WITH FRAME Frame1 USE-TEXT.
     ENABLE btn-Prev btn-Next btn-Update btn-Add btn-Exit 
      WITH FRAME Frame1.
     WAIT-FOR CHOOSE OF btn-Exit.
     CLOSE QUERY Item-Query. 

These notes help to explain the code:

  1. The CREATE statement establishes the record and interacts with the schema to get default values.
  2. Since the record has EXCLUSIVE-LOCK, you can move right to an UPDATE statement.
  3. The DISPLAY statement refreshes the main form with the new data.

Copyright © 2004 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095