ppt progress report programming

52
Progress Report Programming Fahman Agus Abadi

Upload: namhaf2012

Post on 27-Oct-2014

103 views

Category:

Documents


4 download

DESCRIPTION

Progress 4GL Programming

TRANSCRIPT

Page 1: PPT Progress Report Programming

Progress Report Programming

Fahman Agus Abadi

Page 2: PPT Progress Report Programming

Overview What is database? Progress 4GL Programming Language Data Manipulation Language Standard function on Progress 4GL Work Tables & Temporary Tables Working with include file and sub-program Record Locking Frame and Form

Page 3: PPT Progress Report Programming

Goal Understand about database Understand about Progress 4GL Programming

Language Understand how to data manipulating using Progress Understand about standard function on Progress Understand how to working with work tables and

temporary tables Understand how to working with include file and sub-

program Understand about record locking on progress Understand how to create report using Progress

programming with Frame and Form

Page 4: PPT Progress Report Programming

What is database? DATABASE DEFINITION

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

TABLE DEFINITIONA collection of logically related records organized into records (or rows) and fields (or columns).

INDEX Like a book index, which helps a reader to retrieve information on a

topic quickly, a database table index speeds up the process of searching and sorting rows. Although it is possible to search and sort data without using indexes, indexes generally speed up data access. Use them to avoid or limit row scanning operations and to avoid sorting operations. If you frequently search and sort row data by particular columns, you might want to create indexes on those columns. Or, if you regularly join tables to retrieve data, consider creating indexes on the common columns.

Page 5: PPT Progress Report Programming

Progress 4GL Programming Language

Page 6: PPT Progress Report Programming

Example : FOR EACH item : Disp item. End.

Page 7: PPT Progress Report Programming

PROGRESS PROGRAM FILES

File Type Description

xxxxx.p 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 Progress application builder files

xxxxx.r This file is the result from compilation of xxxxx.p file.

Page 8: PPT Progress Report Programming

Progress Data Types

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

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

DecimalContains decimal numbers up to 50 digits.

DateContains dates from 1/1/32768 BC to 12/31/32767 AD

Logicalyes/no, true/false

RecidContains the record ID.

Page 9: PPT Progress Report Programming

VARIABLE DECLARATION STATEMENT

SYNTAX DEFINE [ [ NEW [ GLOBAL ] ] SHARED ] VARIABLE

variable { AS datatype | LIKE field } [ EXTENT n ] [ FORMAT string ] [ INITIAL { constant | { [ constant [ , constant ] ... ] } }  ] [ LABEL string [ , string ] ... ]

Page 10: PPT Progress Report Programming

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 eachFindInsertUpdate Delete

Page 11: PPT Progress Report Programming

The FOR EACH StatementWrite 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.

Page 12: PPT Progress Report Programming

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.

Page 13: PPT Progress Report Programming

The BY ClauseNo 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.

Page 14: PPT Progress Report Programming

Data GroupingWhen 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.

With break by statement we can this function :

first-of (field-name)

last-of (field name)

Total by

Page 15: PPT Progress Report Programming

Data Grouping Example

Page 16: PPT Progress Report Programming

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 table.

Many-to-many

Many records in one file are related to many records in another file.

Customer Order ItemONE-TO-MANY

Every Customer may have placed 0 or more orders

MANY-TO-ONE

Multiple orders may have been placed by just one customer

ONE-TO-MANY

Every item may appear on 0 or more orders

many-TO-one

Every order is for one or more items

Page 17: PPT Progress Report Programming

Selecting Data from More Than One TableTo 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.

Page 18: PPT Progress Report Programming

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. It’s 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.

 

FIND Syntax :

Find First table_name where_clause.

Page 19: PPT Progress Report Programming

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.

REPEAT :

CREATE customer.

UPDATE customer WITH 1 COLUMN.

END.

Page 20: PPT Progress Report Programming

MANUALLY CHANGING AN CUSTOMER RECORD

Ask (PROMPT-FOR) which record needs to change.

Find (FIND) the customer record.

Update (UPDATE) the customer record.

PROMPT-FOR customer.cust-num.

FIND customer WHERE

Customer.cust-num = INPUT customer.cust-num.

UPDATE customer WITH 2 COLUMN.

PROMPT-FOR customer.cust-num.

FIND customer USING customer.cust-num.

UPDATE customer WITH 1 COLUMN.

USINGUSING

PROMPT-FORPROMPT-FOR FINDFIND

Page 21: PPT Progress Report Programming

COMBINING, ADDING, AND CHANGING RECORDS

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.

END.

CREATECREATE ASSIGNASSIGN NO-ERRORNO-ERRORSETSET

Page 22: PPT Progress Report Programming

DELETING RECORD

Ask (PROMPT-FOR) which record needs to delete.

Find (FIND) the record.

Update (UPDATE) the record.

REPEAT:

PROMPT-FOR customer.cust-num.

FIND customer USING cust-num.

DELETE customer.

END.

DELETEDELETE

Page 23: PPT Progress Report Programming

Comparing UPDATE and SET

UPDATE S E T

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

Page 24: PPT Progress Report Programming

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. Absolute (n)

DEFINE VAR a AS INTEGER.

a = -100.

DISPLAY a ABSOLUTE(a) LABEL "Absolute a".

Page 25: PPT Progress Report Programming

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.

a = “abcd”.

Display a CAPS(a) label “CAPS a”.

Page 26: PPT Progress Report Programming

CHR CHR (expression) DATE Date (String) DECIMAL DECIMAL (expression) ENTRY ENTRY ( element , list [ , character ] ) EXP EXP ( base , exponent ) INDEX INDEX ( source , target [ , starting ] ) LC LC ( string ) LEFT-TRIM LEFT-TRIM ( string [ , trim-chars ] ) LENGTH LENGTH ( { string [ type ] | raw-expression } ) MATCHES expression MATCHES pattern MAXIMUM MAXIMUM ( expression , expression [ , expression ] ... ) MINIMUM MINIMUM ( expression , expression [ , expression ] ... ) MODULO expression MODULO base ROUND ROUND ( expression , precision ) TODAY MONTH MONTH (date) YEAR YEAR (date) DAY DAY(date)

Page 27: PPT Progress Report Programming

Reporting with agregate function

FOR EACH customer : DISPLAY NAME address credit-

limit(TOTAL).END.

TOTALTOTAL

Page 28: PPT Progress Report Programming

FOR EACH customer BY state:DISPLAY NAME address credit-limit(COUNT MAX MIN AVERAGE TOTAL).

END.

COUNTCOUNT MAXMAX MINMIN AVERAGEAVERAGE

Page 29: PPT Progress Report Programming

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

limit(ACCUM TOTAL credit-limit).END.

Page 30: PPT Progress Report Programming

USING CONTROL BREAKS AND AGGREGATES

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

END.

Page 31: PPT Progress Report Programming

USING THE FIRST-OF FUNCTIONFOR EACH customer BREAK BY state:

IF FIRST-OF (state)THEN DISPLAY state.DISPLAY name address credit-limit(TOTAL COUNT BY state).

END.

Page 32: PPT Progress Report Programming

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 defined to be LIKE a database field). Work tables also have the option to adopt the same dictionary validation specified for the corresponding database table.Does not have indexes, therefore you cannot do a FIND work-table. However, you can do a FIND FIRST work-table.

NOTE: Because Progress stores and processes work tables in memory, the number of work tables and the number of records in a work table that you can use is limited by the memory available on your system.

Page 33: PPT Progress Report Programming
Page 34: PPT Progress Report Programming
Page 35: PPT Progress Report Programming

Temporary Tables

Temporary 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 only one user at a time to access them. Finally, temporary tables are private, visible only to the user (process) that creates them. In short, if you want to sort, search, and process data for a duration not longer than the Progress session, use temporary tables.

Progress stores temporary tables and temporary files in the same directory by default, your current working directory. You can change this directory by using the Temporary Directory (-T) startup parameter.

Temporary tables require less memory than large work tables. The Buffers for Temporary Tables (-Bt) startup parameter allows you to set the size of the buffer that Progress uses to control temporary tables. For more information on the -Bt parameter, see the Progress Startup Command and Parameter Reference.

NOTE: You cannot access temporary tables using SQL statements.

Page 36: PPT Progress Report Programming

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:

Inherits the field definitions of an existing database table, or has the fields you define explicitly

Inherits the index definitions of an existing table, or has the indexes you define explicitly

Lasts only as long as the procedure that creates it, or as long as the Progress session

Is private to a single procedure, or shared among several procedures

Page 37: PPT Progress Report Programming
Page 38: PPT Progress Report Programming
Page 39: PPT Progress Report Programming

Using Database, Temporary, and Work Tables Database 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:

Temporary tables perform like database tables. Because temporary tables have indexes, you can use

statements that require indexes, such as FOR EACH or a simple FIND.

Temporary tables are not limited to the value of the buffer size defined by the -Bt parameter. Progress stores any overflow of temporary table records to disk. Work tables, however, are limited by the amount of memory available on your system.

Page 40: PPT Progress Report Programming

Similarities between Temporary and Work Tables

Temporary tables and work tables have the following similarities: You 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 triggers from the database table.

The NEW SHARED and SHARED options allow two or more procedures to access the same temporary tables and work tables.

Update statements, such as UPDATE, CREATE, and DELETE, that reference a temporary table or a work table do not require a transaction to be active. If you want a temporary table or a work table to participate in a transaction, you must explicitly start a transaction for it.

Whenever a Progress session ends due to a crash or a QUIT statement, Progress deletes all records in temporary tables (and the temporary database itself) and all records in work tables.

Page 41: PPT Progress Report Programming

Differences between Temporary and Work Tables

Temporary tables and work tables have the following differences: When 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.

While temporary table records are stored in a temporary database on disk, work table records are stored in memory. Note that for a relatively small application with a sufficiently large buffer allocation, Progress does not have to perform any disk I/O for temporary tables. To specify buffer size for temporary tables, use the -Bt parameter.

The FIND statement for temporary tables uses the same cursor concept and choose-index logic that are used for regular database tables. When a temporary table record is created, its logical position in the table depends on the values of its key fields. Its logical position in the table can be changed by changing the key values.

Because temporary tables have indexes similar to regular database tables, they can perform fast sequential and random access to temporary table records using one or more indexes. Since work tables have no index support, all record access is performed with a sequential search.

Page 42: PPT Progress Report Programming

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 recordsResolving locking issues

The concepts explained in this chapter apply to applications running in a multi-user environment. If you are developing an application on a single-user system, you can use all the multi-user statements shown in this chapter. Progress simply disregards those statements when you run the application in single-user mode.

Page 43: PPT Progress Report Programming

APPLICATIONS IN A MULTI-USER ENVIRONMENT

Page 44: PPT Progress Report Programming

USING LOCKS TO AVOID RECORD CONFLICTS

FOR EACH customer NO-LOCK :    DISPLAY cust-num name address city state postal-code.END.

Page 45: PPT Progress Report Programming

WORKING WITH INCLUDE FILE AND SUB PROGRAM

INCLUDE FILECauses 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 | { &argument-name = "argument-value" } ] ... }

Page 46: PPT Progress Report Programming
Page 47: PPT Progress Report Programming

SUB PROGRAMWhen 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.

Page 48: PPT Progress Report Programming

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.

Page 49: PPT Progress Report Programming

FRAME ALLOCATION

FOR EACH customer WITH FRAME a:

DISPLAY cust-num name.

END.

Page 50: PPT Progress Report Programming

FORM HEADERSAll frames have a header and body.

A header is the top part of a frame.

When defining a FORM HEADER for a display frame, PROGRESS adds labels to the form header unless you specify NO-LABELS in the body of the frame.PAGE-BOTTOMPAGE-BOTTOM PAGE-SIZEPAGE-SIZE PAGE-NUMBERPAGE-NUMBER

PAGE-TOPPAGE-TOP VIEWVIEW

Page 51: PPT Progress Report Programming
Page 52: PPT Progress Report Programming

Thanks For Your Attention