The acronym CRUD refers to the basic I/O functions that you typically perform on records within a file. The following table shows the CRUD functions and the EGL keywords that provide those functions:
CRUD function | EGL keyword |
---|---|
Create | add |
Read | get |
Update | replace |
Delete | delete |
Furthermore, EGL tailors the way it executes each of these functions based on the particular type of file with which you are working. For example, if you write a get next statement for a SQL database, EGL generates a series of SQL statements to locate and retrieve the appropriate row from an SQL result set. The same EGL statement generated for a sequential file would simply read the next record in the file.
EGL accomplishes these tasks by means of stereotyping. In everyday use, a stereotype is a common pattern that you can use to characterize an individual. In much the same way, when you apply a stereotype to a record, you tell EGL how it should perform I/O functions that involve that record. For more on stereotypes, see Introduction to Record parts and topics that focus on the specific stereotypes in the EGL Language Reference.
Assuming that you have an existing database (typically created by a database administrator), regular processing generally involves the create, read, update, and delete (CRUD) functions. More specific examples are presented in the topics that deal with specific data access technologies. The following general scenario is possible only because EGL is so efficient at shielding you from implementation details.
package com.companyb.customer Record CustomerRecord type Stereotype customerNumber INT; customerName STRING; customerBalance MONEY; end
The details of the record, and its properties, will vary depending on how you plan to use it.
myCustomer CustomerRecord;
myCustomer.customerNumber = getCustomer();
get myCustomer forUpdate;
EGL generates the appropriate code to read the data from the file or database and then places the information in your record variable. The forUpdate keyword tells EGL to place a hold on the data so you have the option to replace or delete it.
case (showCustomer(myCustomer)) when (-1) delete myCustomer; when (1) replace myCustomer; end
set myCustomer empty; // all fields blank or 0 myCustomer.customerNumber = getCustomer(); // sets cust # try get myCustomer forUpdate; onException (ex AnyException) // couldn't get the record if(myCustomer is noRecordFound) // because customer # not on file if(getReply("Do you want to add this customer? (y/n)") == TRUE) showCustomer(myCustomer); // let user fill in remaining fields add myCustomer; end else myErrorHandler(ex); end
With these few lines of code you have the heart of a customer file service program that you can use with an SQL database or your own VSAM indexed file. The only difference in your program between VSAM and SQL is the stereotype you apply to the CustomerRecord definition.