Anda di halaman 1dari 52

Progress Report Programming

Click to edit Master subtitle style Fahman Agus Abadi

8/14/12

Overview

What is database? 4GL Programming Language function on Progress 4GL Manipulation Language Tables & Temporary Tables with include file and sub-program Locking

Progress Data

Standard Work

Working Record Frame

and Form
8/14/12

Goal
Understand Understand

about database about Progress 4GL Programming how to data manipulating using about standard function on

Language Progress Progress

Understand Understand Understand Understand

how to working with work tables and temporary tables how to working with include file and sub-program
8/14/12

What is database?
DATABASE

DEFINITION

A collection of logically related tables or fields that can be accessed or retrieved.


TABLE

DEFINITION

A collection of logically related records organized into records (or rows) and fields (or columns).
INDEX
8/14/12 Like a book index, which helps a reader to

Progress 4GL Programming Language

8/14/12

Example

: FOR EACH item : Disp item. End.

8/14/12

PROGRESS

PROGRAM FILES

File Type xxxxx.p

Description Program file containing either: Your main program External procedures to be called from your main program

xxxxx.i

Include file is a file that will included in the procedure during compilation

xxxxx.w xxxxx.r

Progress application builder files This file is the result from compilation of xxxxx.p file.

8/14/12

Progress Data Types


Character

Contains data of any kind. (alphabet, numerical, special)


Integer

Contains only whole numbers. (from -2,147,483,648 through 2,147,483,647, inclusive. With default value 0)
Decimal

Contains decimal numbers up to 50 digits.


Date
8/14/12

VARIABLE

DECLARATION STATEMENT

SYNTAX DEFINE [ [ NEW [ GLOBAL ] ] SHARED ] VARIABLE variable { AS datatype | LIKE field } [ EXTENT n ] [ FORMAT string ] [ INITIAL { constant | { [ constant [ , constant ] ... ] } }
8/14/12

Data Manipulation Language


Data

Manipulation Language is statement/command to manipulate data (retrieve, insert, update and delete) in the database. The following four basic statements fall under the category of DML statement: For each Find Insert Update Delete
8/14/12

The

FOR EACH Statement

Write For each statement to retrieve data from tables. It is the most frequently used statement because data is retrieves more often than inserted, deleted, or updated. With display command you can see the retrieved data in the screen. For each table_name : Display table_name.column1 table_name.column1 . End.
8/14/12

The

WHERE Clause

For each statement can also define restriction of rows through criteria based based on an optional WHERE clause. The following statement, display the data of those customer whose credit-limit is less than 10000: FOR EACH customer WHERE credit-limit < 10000 : DISPLAY cust-num name address credit-limit. END.

8/14/12

The

BY Clause

No matter what the order of columns and rows in physical storage is, users can retrieve the data in any desired order. Sometime we need to display data sort by column ascending or descending. It can be done with BY clause after for each command. The name of the column that you want to use to order rows should follow the BY keyword. FOR EACH customer BY credit-limit DESCENDING: DISPLAY cust-num name address credit-limit. END.
8/14/12

Data

Grouping

When we retrieve data using for each statement we need data grouping. For. example we retrieve sales data in a year. We need to group all sales by customer, so we can rank the customer by total sales amount. There are two ways to group the data : using by or break-by clause. We can combine for each statement with by or break by to grouping the data.

For each table where . break by field-name: .. .. End.


8/14/12

Data

Grouping Example

8/14/12

Table

Relation

There are three kinds of file relationships that are important for you to understand:

One-to-Many

A record in one table is related to many other records in another table or many records in one table are related to a single record in another table.

One-to-One

One records in one table is related to one record in another Item Customer Order table. ONE-TO-MANY ONE-TO-MANY

placed 0 or more Many-to-many orders Every Customer may have Every item may appear on 0 or more orders

file.

Many records in one file are related tomany-TO-one many records in another MANY-TO-ONE
Multiple orders may have been placed by just one customer Every order is for one or more items

8/14/12

Selecting

Data from More Than One Table

To retrieve data from more than one table you can use double for each command (For each in the for each). Here is the sample how to retrieve data from emp_mstr and dept_mstr tables.

For each customer by name: For each order where order.cust-num = customer.cust-num: Display customer.cust-num name order-num. End. End.
8/14/12

FIND

Statement.

For each statement will retrieve one or more than one records in a table. Sometime you need to retrieve a specific data that only one record from a table. Its can be done using Find statement. Find statement will produce error message if meet more than one record. There are four type of find statement: FIND FIRST : find first record from a table FIND NEXT : find the next record from the current record FIND PREV : Find the previous record from the current record FIND LAST : Find the last record from a table.
8/14/12

INSERTING/ADDING

RECORD To a Table

Manually adding an customer record requires:


Creating(CREATE) an empty record Updating(UPDATE) the empty record Storing the changes in the database

CREATE customer. UPDATE customer WITH 1 COLUMN.

INSERT customer WITH 1 COLUMN.


8/14/12

REPEAT :

MANUALLY

RECORD

CHANGING AN CUSTOMER

Ask (PROMPT-FOR) which record needs to change. Find (FIND) the customer record. Update (UPDATE) the customer record.
PROMPT-FOR FIND

PROMPT-FOR customer.cust-num. FIND customer WHERE Customer.cust-num = INPUT customer.cust-num. UPDATE customer WITH 2 COLUMN.
USING

PROMPT-FOR customer.cust-num. FIND customer USING customer.cust-num. UPDATE customer WITH 1 COLUMN.
8/14/12

COMBINING,

RECORDS

ADDING, AND CHANGING


CREATE ASSIGN SET NO-ERROR

REPEAT: PROMPT-FOR customer.cust-num. FIND customer USING cust-num NO-ERROR. IF NOT AVAILABLE customer THEN DO: MESSAGE New Customer record created. CREATE customer. ASSIGN cust-num. END. DISPLAY customer WITH 2 COLUMN 1 DOWN. SET customer EXCEPT cust-num.
8/14/12

DELETING

RECORD

Ask (PROMPT-FOR) which record needs to delete. Find (FIND) the record. Update (UPDATE) the record.
DELETE

REPEAT: PROMPT-FOR customer.cust-num. FIND customer USING cust-num. DELETE customer. END.

8/14/12

Comparing

UPDATE and SET


SET

UPDATE

Display data

Does not display data

Prompts for changes

Prompts for changes

Assigns changes to a record

Assigns changes to a record

Can use field names or a file name as an argument Can use field names or a file name as an argument

8/14/12

Standard function on Progress 4GL

/*COMMENT*/
/* Procedure written 9/5/87 by CHC revised 9/27/87 by DG */ FOR EACH customer: DISPLAY cust-num name contact phone. END.

ABSOLUTE

Returns the absolute value of a numeric value. (n)

Absolute

DEFINE VAR a AS INTEGER. a = -100.


8/14/12

ASC

Converts a character expression representing a single character into the corresponding ASCII (or internal code page) integer value. ASC(expression)

BEGINS

Tests a character expression to see if that expression begins with a second character expression. For each customer where name begins a : Display name. End.

CAPS Define variable a as character.


8/14/12

CHR

CHR (expression) Date (String) DECIMAL (expression) ENTRY ( element , list [ , character ] ) INDEX ( source , target [ , starting ] ) LEFT-TRIM ( string [ , trim-chars ] )

DATE

DECIMAL ENTRY EXP

EXP ( base , exponent )

INDEX LC

LC ( string )

LEFT-TRIM LENGTH

LENGTH ( { string [ type ] | rawexpression } )


8/14/12 expression MATCHES pattern

MATCHES

Reporting

with agregate function


TOTAL

FOR EACH customer : DISPLAY NAME address credit-limit(TOTAL). END.

8/14/12

COUNT

MAX

MIN

AVERAGE

FOR EACH customer BY state:


DISPLAY NAME address credit-limit(COUNT MAX MIN AVERAGE TOTAL).

END.

8/14/12

FOR EACH customer: ACCUMULATE credit-limit (TOTAL). DISPLAY name address credit-limit(ACCUM TOTAL credit-limit). END.

8/14/12

USING

CONTROL BREAKS AND AGGREGATES

FOR EACH customer BREAK BY state: DISPLAY name address credit-limit (TOTAL BY state). END.

8/14/12

USING

THE FIRST-OF FUNCTION

FOR EACH customer BREAK BY state: IF FIRST-OF (state) THEN DISPLAY state. DISPLAY name address credit-limit(TOTAL COUNT BY state). END.

8/14/12

WORK TABLES AND TEMPORARY TABLES


Work

Tables

Work tables are to database tables what variables are to database fields. Like a variable, a work table: Must be defined in any procedure that uses it. Is a temporary structure stored in memory rather than in the database, and can either be local to a single procedure or shared among multiple procedures. Can be defined to be LIKE a database table (much like a variable can be defined8/14/12 LIKE to be

8/14/12

8/14/12

Temporary Tables
tables are database tables that Progress stores in a temporary database. You define temporary tables as you do work tables. Unlike work tables, temporary tables have indexes and perform at the speed of regular database tables. Unlike regular database tables, which are permanent and which multiple users can access simultaneously, temporary tables last only for the duration of the procedure that defines them (or for the duration of the Progress session, if you make them GLOBAL), and allow 8/14/12

Temporary

Defining

a Temporary Table

You define a temporary table by using the DEFINE TEMP-TABLE statement. For example, the following statement defines temporary table Temp-Cust that inherits the field definitions of table Customer, which must belong to a database that is connected. DEFINE TEMP-TABLE Temp-Cust LIKE Customer. Using the DEFINE TEMP-TABLE statement, you can define a temporary table that: 8/14/12

8/14/12

8/14/12

Using

Database, Temporary, and Work Tables tables provide data storage in a permanent database and can be accessed by single or multiple users. However, if you want to process data for the duration of a procedure in complete privacy, use temporary tables or work tables. Temporary tables have several advantages over work tables: tables perform like database tables.

Database

Temporary Because

temporary tables have indexes, you can use statements that require indexes, such as FOR EACH or a simple FIND. 8/14/12

Similarities

between Temporary and Work Tables tables and work tables have the following similarities: create temporary tables and work tables with a DEFINE statement, and they are scoped to the procedures that define them. When you specify the LIKE table option, both inherit the attributes of the specified database table (table). This optionally includes all Data Dictionary validation for the table (using the VALIDATE option). However, temporary tables and work tables do not inherit schema 8/14/12

Temporary You

Differences

Work Tables

between Temporary and

Temporary When

tables and work tables have the following differences: you define temporary tables with the LIKE option and do not explicitly specify indexes for them, they inherit index information from the database table. Work tables do not have index support. temporary table records are stored in a temporary database on disk, work table records are stored in memory. Note that for a 8/14/12 relatively small application with a sufficiently

While

RECORD

LOCKING

If you write multi-user applications, there are additional issues and features you should address during your application development cycle. This chapter explains: Sharing database records Resolving locking issues The concepts explained in this chapter apply to applications running in a multi-user 8/14/12

APPLICATIONS

ENVIRONMENT

IN A MULTI-USER

8/14/12

USING LOCKS TO AVOID RECORD CONFLICTS

8/14/12

WORKING WITH INCLUDE FILE AND SUB PROGRAM INCLUDE FILE


Causes Progress to retrieve the statements in a file and compile them as part of the main procedure if it encounters the file's name inside braces ({}) when compiling the procedure. You can name arguments you want substituted in the file before compilation. { include-file [ argument | { &argumentname = "argument-value" } ] ... }
8/14/12

8/14/12

SUB

PROGRAM

When we create program, we can have multiple sub program base on our requirement. The different between sub program and include file are :

Sub program extension is .p and include file is .i Sub program not automatically compiled when we compile the main program, include file automatically compiled when we compile the main program. We can use run statement to call the procedure from the main program.

8/14/12

FRAME AND FORM


WHY

PROGRESS USES FRAMES

Progress uses frames to ease the task of laying out your data, so you do not have to individually position every field-level widget that you want to display. Progress automatically lays out frames according to predetermined rules, or defaults. One default is to display a label for each field in the frame. Another is to place a solid box around every frame. You must become familiar with these defaults to use frames effectively. Once you know the defaults, you can override them to change the appearance and placement of your data.
8/14/12

FRAME

ALLOCATION

8/14/12

FORM

HEADERS

All frames have a header and body. A header is the top part of a frame. When defining a FORM HEADER for a display frame, PAGE-SIZE PAGE-NUMBER PROGRESS adds labels to the PAGE-BOTTOM form header unless you specify NO-LABELS in the body of the frame.
PAGE-TOP VIEW

8/14/12

8/14/12

Thanks For Your Attention


8/14/12

Anda mungkin juga menyukai