Beruflich Dokumente
Kultur Dokumente
2
Agenda
What is a
Why Redundancy
Domain Specific and
Language (DSL)? Readability Matter?
I really wanted to
ABL write 4GL here!
4
In other words…
Code is:
• Easy to read (self-documenting)
• Hard to make errors (related to the domain of transactional database applications)
• Small group of programmers can create complex systems
• New programmers can look at 20+ year old code and understand original ‘intent’
5
Why We Love ABL
Readable Compact Monoglot
6
https://github.com/progress/WhyABL/blob/master/BasicQuery/example.p
ABL
import java.sql.*;
All ‘boilerplate’
public class example {
// JDBC driver name and database URL
static final String JDBC_DRIVER = "com.mysql.jdbc.Driver";
static final String DB_URL = "jdbc:mysql://localhost/sports2000";
// Database credentials
static final String USER = "root"; Connection
static final String PASS = ""; explicit: Language
public static void main(String[] args) { does not ‘know’
Connection conn = null;
PreparedStatement preparedStmt = null; about DB.
try {
// Register JDBC driver
Class.forName(JDBC_DRIVER);
// Open a connection
conn = DriverManager.getConnection(DB_URL,USER,PASS);
conn.setAutoCommit(false);
(continued)
11
All ‘work’ of the
Java JDBC Example (p.2)
(continued from above)
program is in SQL, not
in Java (or C#, or
// Execute a query
String sql =
Python)
"UPDATE customers " +
"SET BALANCE = BALANCE * ?" +
"WHERE SALESREPEMPLOYEENUMBER = ? AND BALANCE > CREDITLIMIT";
preparedStmt = conn.prepareStatement(sql);
// Handle exceptions
catch(Exception e){
System.out.println(e.getMessage());
try {
Transactions not
conn.rollback();
} catch (SQLException excep) {
special so error
System.out.println("Rollback failed."); handling ‘general
excep.printStackTrace();
} purpose’.
}
// Close resources
finally {
try {
preparedStmt.close();
} catch (SQLException e) {
e.printStackTrace();
}
try { Resource cleanup
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
System.out.println("Goodbye!");
}
}
13
Monoglot vs Polyglot: Out-of-Band Knowledge
String sql =
"UPDATE customers " +
"SET BALANCE = BALANCE * ?" +
"WHERE SALESREPEMPLOYEENUMBER = ? AND BALANCE > CREDITLIMIT";
14
https://github.com/progress/WhyABL/blob/master/OperateOnResults/example.p
ABL
15
Need to know the type that you
Java JDBC Example
define, cast to, and store….
…and they need to match
16
Java JDBC Example
17
Java JDBC Example
In previous example, it was simple enough to keep things on one page, and
we used one naming convention.
19
The Longer the SQL, The Harder to Debug
Multi-table relations
20
Works with Debugger: can set Breakpoints
SQL for ERP Applications: A “Simple” Case
21
Other Real Examples
select
UPDATE PUB.“RECORD" SET recordIndexed = 2 PERSTAMM.PSEINDAT, PERSTAMM.PSAUSDAT, PERSTAMM.FIRMA, PERSTAMM.PSNR
from PUB.BENSTM, PUB.PERSTAMM
WHERE “scancode" in ( where
AND
BENSTM.FIRMA = PERSTAMM.FIRMA
((BENSTM.BSTPESTM = 'N')
'000000034439805', OR
( ( ( (BENSTM.KSTACCEPT ='N')
'000000034412710', OR
(PERSTAMM.KSTNR IN
'000000034412337', OR
(PERSTAMM.PGNR IN
(SELECT PGNR FROM PUB.BSPERGRP
'000000034400916', WHERE BSPERGRP.FIRMA=BENSTM.FIRMA
AND BSPERGRP.BENNR=BENSTM.BENNR
'000000034413595',
OR
(BENSTM.PGRPACCEPT ='J')
OR …………………………………
This example
(BENSTM.SHIFTACCEPT ='J')
'000000034398492' OR
(BENSTM.SHIFTDENY ='J') ) ) intentionally
); OR
((PERSTAMM.PSNR IN
(SELECT PSNR FROM PUB.BSPERSTM
WHERE BSPERSTM.FIRMA=BENSTM.FIRMA
unreadable as
AND BSPERSTM.BENNR=BENSTM.BENNR
)
)
AND BSPERSTM.ZULASSEN='J')))
an illustration
22
https://github.com/progress/WhyABL/blob/master/ComplexQuery/example.p
ABL
23
Demo:
What would this look like in
Python
https://github.com/progress/WhyABL/blob/master/ComplxQuery/example.py
Python Example
import MySQLdb as mdb
shipDate = '1999-09-19'
try:
[…snip…]
cur.execute(sql)
26
Transaction Scope and Data Handling and Movement
27
Automatic Transaction Scoping in ABL
28
Key Points
30
In ABL: Temp-Tables and Datasets
31
An Example Problem
I have a list of my “Prime” Customers (their IDs) and their new sales rep
• Provided by an external system (API, REST, flat file, or whatever)
Case 2: I want to find all the Salesreps who now have responsibilities in Massachusetts
• I want to talk to this team specifically
32
https://github.com/progress/WhyABL/blob/master/DbAndStructures/example.p
Case 2: Python (Find New Salesreps that now have “MA” customers)
Goal: Query the Database for a long list of customer numbers, and
pass a list of new values.
38
For More Information
Presentation:
• http://pugchallenge.org/downloads.html
Code Samples:
• https://github.com/progress/WhyABL
39
Would Like to Thank the
following WebSites that made
all this possible…