Beruflich Dokumente
Kultur Dokumente
adapya 0.7
September 1, 2008
Table of Contents
1 What is adapya ? ...........................................................................................3
2 adapya License .............................................................................................3
3 Change History .............................................................................................4
4 Setting up an Execution Environment for MS-Windows ...........................................4
4.1 Prerequisites ............................................................................................4
4.2 Installation of adapya ................................................................................5
4.2.1 Windows PYTHONPATH installation .......................................................5
4.2.2 Windows Standard Installation.............................................................5
4.2.3 Unix/Linux PYTHONPATH Installation ....................................................6
4.2.4 Installation of adapya-v.r.l.zip with easy_install.....................................6
5 Using the Adabas API ......................................................................................7
5.1 Simple ACBX Example..................................................................................7
5.1.1 Adabasx Objects ................................................................................8
5.1.2 String Buffers ....................................................................................9
5.1.3 Storing a Record ................................................................................10
5.1.4 Reading a Record...............................................................................10
5.1.5 Backing-out the Transaction ................................................................10
5.1.6 Closing the User session .....................................................................10
5.1.7 Response Code Checking vs. Exception Handling ...................................10
5.2 Further Details of adapya............................................................................11
5.2.1 Read/Write Buffers with Abuf ..............................................................11
5.2.2 Working with Structures with Datamap .................................................12
5.3 LOB Demo Center Sample Web Application......................................................13
5.3.1 Configuration of the Apache http.conf file (example): .............................15
5.3.2 Configuration of Adabas and Net-Work .................................................15
5.4 UDHR Browser ...........................................................................................17
5.4.1 Configuration of the Apache http.conf file (example): .............................18
5.4.2 UDHR text stored as LOB or MU field ....................................................18
5.4.3 Storing from the NLTK Corpora ............................................................18
5.4.4 Configuring the scripts readudhr/readudhr2.py ......................................19
6 Event Replication for Adabas............................................................................20
6.1 Additional Prerequisites ..............................................................................20
6.2 outq.py Reptor Output Queue Client .............................................................20
6.3 inq.py Reptor Input Queue Client .................................................................21
Software AG 2008
Company Confidential
Page 1/26
adapya 0.7
September 1, 2008
Software AG 2004-2008
Page 2/26
adapya 0.7
September 1, 2008
1 What is adapya ?
With adapya you can access Adabas databases from Python programs using the Adabas API.
It comes with sample programs to show its use and demonstrates new Adabas features like reading
and storing of large binary objects using the extended Adabas API (ACBX).
Adabas is a commercial database system that runs on Windows, Unix and mainframe systems.
For more information see
http://en.wikipedia.org/wiki/Adabas and
http://www.softwareag.com/corporate/products/adabas/default.asp
in the download area you may also find an Adabas community version for Windows.
Here is the Adabas product documentation http://documentation.softwareag.com/adabas/
Python is a scripting language that allows rapid prototyping, object-oriented or functional style
programming. It is open source and is used in a large number of projects.
Note:
adapya is a pure Python package: it does not require compilation of extensions. It should work on
all platforms where CPython and Adabas are available. It has been tested on Windows, Solaris and
z/Linux. It can access local Adabas databases and with the product NET-WORK remote Adabas
databases on all platforms including mainframe (z/OS, VSE, BS2000).
Prerequisite for adapya is Python version 2.5, or Python version 2.3 and 2.4 where it requires the
extra ctypes package.
adapya can be downloaded from
http://tech.forums.softwareag.com/viewforum.php?f=171&C=11
2 adapya License
Copyright 2004-2008 Software AG
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Software AG 2004-2008
Page 3/26
adapya 0.7
September 1, 2008
3 Change History
adapya 0.7 is the first public release.
3. -you may skip this step when using easy_install since it takes care of prerequisites -ctypes (required) for Python versions below 2.5 - it is already included in Python 2.5).
Download Win32 installer or tar file from
http://sourceforge.net/projects/ctypes/
4. (Optional for LOB and other web demo programs) Install additional software.
For Windows you may select the installers depending on the Python version.
a. apache (optional). Used for the demo web applications.
http://httpd.apache.org/download.cgi
b. mod_python (optional). Used for the demo web applications.
http://www.internet.bs/apache.org/httpd/modpython/
c. PIL - Python Image Library (optional). Used with LOB Demo Center application
http://www.effbot.org/zone/pil-index.htm
Note:
PIL and mod_python packages have Python extensions (i.e. separately compiled
dynamic loadable modules). They only work with the Python version that they're
compiled with. Make sure that you select the binary for your Python version.
As of August 2008 current versions of the components are: python-2.5.2, ctypes1.0.2, apache-2.2.9 or apache-2.0.63, mod_python-3.3.1, PIL-1.1.6.
Software AG 2004-2008
Page 4/26
adapya 0.7
September 1, 2008
For the very prudent there are some introductory Video Tutorials at
http://showmedo.com/videos/series?name=pythonOzsvaldPyNewbieSeries
Create a file py25.bat with the following content, adapt it to your environment and save it
to a directory that is in the system PATH:
REM Python installation directory
set PY=C:\Python25
REM Adabas Python directory: Python will pick up Adabas python
modules
set PYTHONPATH=C:\ada\python\adapya-v.r.l
REM add paths for Python runtime if not done at Python installation
PATH=%PY%;%PY%\DLLs;%PATH%
REM cd to Adabas demo files directory
cd %PYTHONPATH%\adabas\demo
When the Python interpreter is started it evaluates the environment variable PYTHONPATH and
adds any directories listed to its search path for modules.
Check successful installation with dblist.py to show the status of active Adabas database <dbid>
python dblist.py d <dbid>
Check successful installation with doing an open to an active Adabas database <dbid>
python %PY%\scripts\dblist.py d <dbid>
Software AG 2004-2008
Page 5/26
adapya 0.7
September 1, 2008
# root directory
cd $APYDIR/adabas/demo
# go to demo directory
python dblist.py d 12
If your local internet is protected by a http proxy you may need to set the
HTTP_PROXY environment variable before running easy_install (CYGWIN):
SET HTTP_PROXY=http://<httpprox.your-local.net>:<httpprox-port>
Not setting it may result in timing out operations.
Software AG 2004-2008
Page 6/26
adapya 0.7
September 1, 2008
# Employees
c1=Adabasx(fbl=64,rbl=64)
# issue OP
c1.cb.cid='abcd'
c1.cb.isn=0
c1.fb.value=FB
c1.rb.value='ABCDEFGE'
c1.rabd.send=8
c1.store()
# issue N1
# c1.rb.value='4'*8
c1.rabd.send=0
# don't initialize rb
# reset send size !
c1.get()
# issue L1
# issue backout
# issue close
Some explanations in the following sections. You may also look into source adabas/api.py
Software AG 2004-2008
Page 7/26
adapya 0.7
September 1, 2008
Software AG 2004-2008
Page 8/26
adapya 0.7
September 1, 2008
When creating the Adabasx object Python calls the __init__() method defined in the Adabas class.
The method does the following
a) create a buffer of length ACBXLEN and assign it to the attribute acbx of the Adabasx instance:
self.acbx=Abuf(ACBXLEN)
b) define a mapping of Acbx fields to the buffer
self.cb=Acbx(buffer=self.acbx)
Statement 18 assigns the file number 11 to c1.cb.fnr This is the file number field in the Adabas
control block cb used in the Adabasx instance c1.
18
c1.cb.fnr=11
Python's built-in string type can also be used as a buffer with the Adabas call. However,
since strings are immutable they could only be used for read-only buffers like format or
search buffers.
Adabas Python defines a buffer class Abuf(size) which is backed by the CTYPES character buffer.
Abuf() defines slice and fileIO operations and is used as read/write buffer throughout the code (see
below).
Internally, Python has no concept to store data of different variables physically together as in a
assembler DSECT or C struct. But with pack() and unpack() functions from the built-in Python struct
module variables can be mapped to a buffer (or string).
With the adabas/datamap module such a mapping may be defined equivalent to C structs (see
below).
In the c1 initialization Adabasx.__init__() the following 2 statements create a ACBX
buffer c1.acbx and overlay this buffer with the Acbx datamap:
self.acbx=Abuf(ACBXLEN)
self.cb=Acbx(buffer=self.acbx)
c1.cb.fnr is then file number at ACBXFNR in the ACBX buffer
Software AG 2004-2008
Page 9/26
adapya 0.7
September 1, 2008
c1.cb.cid='abcd'
c1.cb.isn=0
c1.fb.value=FB
c1.rb.value='ABCDEFGE'
c1.rabd.send=8
c1.store()
# issue N1
23
c1.cb.cid='abcd'
Command id is set with a 4 byte string
26
c1.rb.value='ABCDEFGE'
c1.rb is the record buffer. Make sure that you assign a value with c1.rb.value or with the slice
operator
c1.rb[0:8]='ABCDEFGE'
27
c1.rabd.send=8
# set send size for record buffer
With ACBX the size of the buffers to send must be set. c1.rabd is the record buffer ABD.
# c1.rb.value='4'*8
c1.rabd.send=0
# don't initialize rb
# reset send size !
c1.get()
# issue L1
c1.bt()
# issue backout
c1.close()
# issue close
Software AG 2004-2008
Page 10/26
42
43
44
adapya 0.7
September 1, 2008
print line
dump.dump(apa.acbx, header='Control Block')
raise
>>> a=Abuf(8)
>>> a.value='Bell'
>>> a.raw
'bell\x00\x00\x00\x00'
# show contents of a
>>> a[0:8]
'bell\x00\x00\x00\x00'
>>> a[0:4]
'bell'
>>> a[0]='W'
'Well\x00\x00\x00\x00'
>>> a.read(5)
'Well\x00'
>>> a.read(5)
'\x00\x00\x00'
>>> a.tell()
8
# inquire position
>>> a.seek(0)
>>> a.write('Sun')
'Sunl\x00\x00\x00\x00'
Software AG 2004-2008
Page 11/26
adapya 0.7
September 1, 2008
>>> dm.dprint()
# print out values of datamap dm
mymap at offset X'0000'
name = "Bell"
age = 64
>>> dm.age
64
>>> dm.name
'Bell'
Software AG 2004-2008
Page 12/26
adapya 0.7
>>> dm.name='12345678'
>>> dm.name
'123456'
# silent truncation
>>> dm.name='1234
>>> dm.name
'1234'
'
September 1, 2008
)
With Uint4 and Uint8 the additional option T_STCK indicates that the value is a timestamp value in
mainframe STCK format. This is evaluated with the dprint() function to print the timestamp in
readable ISO format.
Select a predefined set of images for display and storage into the LDC file
Enter the URL of an image to display or store it into the LDC file
Software AG 2004-2008
Page 13/26
adapya 0.7
September 1, 2008
The Lob Demo Center application requires Apache, mod_python and PIL.
Software AG 2004-2008
Page 14/26
adapya 0.7
September 1, 2008
"C:/ADA/WEB/LobDemoCenter"
"C:/ADA/WEB/LobDemoCenter/images"
<-
<Directory "C:/ADA/WEB/LobDemoCenter">
- directory of the LobDemoCenter files
Options Indexes MultiViews
AllowOverride All
Order allow,deny
Allow from all
AddHandler mod_python .py
PythonHandler mod_python.publisher
PythonDebug On
PythonPath "sys.path+['c:/ADA/python/dev','C:/ADA/WEB/LobDemoCenter']" optional
</Directory>
Adding extra paths to PythonPath for directories of python programs that have not been installed
with the Python installer setup.py
Software AG 2004-2008
Page 15/26
adapya 0.7
September 1, 2008
COMPRESS NUMREC=0
FNDEF='01,A1,025,A,DE,NU'
FNDEF='01,A2,004,A,DE,NU'
FNDEF='01,A3,008,A'
FNDEF='01,L1,0,A,LB,NV,NB,NU'
FNDEF='01,L2,0,A,LA,NV'
FNDEF='01,X1,180,A,NU'
Software AG 2004-2008
Page 16/26
adapya 0.7
September 1, 2008
The browser is implemented as a mod_python script. It can be called with e.g. the following URL
http://localhost/apps/readudhr2.py/browse
or with extra parameters
http://localhost/apps/readudhr2.py/browse?maxlines=10;dbid=12
Software AG 2004-2008
Page 17/26
adapya 0.7
September 1, 2008
Software AG 2004-2008
Page 18/26
adapya 0.7
September 1, 2008
http://localhost/apps/readudhr.py?browse
Note that the following URL parameters could be specified when calling it from the browser:
dbid
fnr
maxlines
name
database id
file number of UDHR file
maximum number of lines to display
Name of language to start browsing from
Example:
http://localhost/apps/readudhr.py?browse?maxlines=100;dbid=12
Displaying individual texts is implemented with the select function:
http://localhost/apps/readudhr.py/select?isn=1
or
http://localhost/apps/readudhr.py/select?name=English
Software AG 2004-2008
Page 19/26
adapya 0.7
September 1, 2008
Options:
-h,
-b,
-c,
-n,
-s,
-u,
-t,
--help
--broker ..
--class ..
--name ..
--service ..
--userid ..
--trace ..
Example:
python outq.py -b ETB50019 -u MM -s MMSERV
Software AG 2004-2008
Page 20/26
adapya 0.7
September 1, 2008
Status
Initial-state-request
Prior-transaction request
>inq.py
---- inq.py -- Reptor input queue writer ---Write messages to the Reptor input queue
via EntireX Broker ACI call interface
Usage: python inq.py [options]
Options:
-h, --help
-b, --brokerid ..
-c, --class ..
-n, --name ..
-s, --service ..
-u, --userid ..
-k, --token
-r, --rnam ..
-e, --arc ..
-t, --trace ..
for
-a
-f
-i
-l
-v
-g
-w
fnr_list
isn_list
Software AG 2004-2008
Page 21/26
value_string
adapya 0.7
September 1, 2008
Examples:
python inq.py -b ETB50019 -u MM -c REPTOR -n MMSERV -s IN1 -d OUT1
python inq.py -b ETB50019 --userid MM --class REPTOR --name MMSERV
--service IN1 -dnam OUT1
python inq.py -b ETB50019 --userid MM --class REPTOR --name MMSERV
--service IN1 --rnam OUT1 --token TOKTOK
--inam ICOLOR --dbid 12345 --fnr (1,2)
----- = file_list
python inq.py ... --isnl (1,2,3,11-20,25)
requests initial state for ISNs 1,2,3 11 thru 20 and 25
python inq.py ... --value (GR001,x'89AB',e'"ABC "') or alternatively
"(GR001,x'89AB',e'ABC ')"
with value being composed of 'GR001',x'89AB',x'C1C2C340'
python inq.py ... --value "A B " --arc 9 --acode cp1252 --wcode utf8
SUBSCRIPTION NAME=EMPLOYEE
SACODE=819,SWCODE=4091,SARC=9
SDESTINATION='OUT1'
SFILE=11,SFDBID=10006
SGFORMATAI=EMPLTEL
GFORMAT NAME=EMPLTEL
GFB='AA,AC,AD,AE,'
GFB='AH,8,U,AL,'
GFB='AN,AM,AO,AP.'
Software AG 2004-2008
Page 22/26
adapya 0.7
September 1, 2008
6.4.2 Configuration
The following lines configure the client program - see out1Config.py.
# define the mapping of data in record buffer to attributes
# of EmpTel class
empTelFormat='AA,AC,AD,AE,AH,8,U,AL,AN,AM,AO,AP.'
# create datamap object for Employees-Telephone-List
emp=Datamap('EmplTel',
String('personnel_id', 8),
String('firstname',
20),
String('m_initial',
20),
String('lastname',
20),
String('birth',
8),
String('country',
3),
String('areacode',
6),
String('phone',
15),
String('department',
6),
String('jobtitle',
25)
)
# define formats and mapping for each file specified in subscription
psf=ParmsSfile(sdbid=10006,sfnr=9,tdbid=12,tfnr=7,\
fb=empTelFormat,dmap=emp)
# define subscription with all its sfiles defined
psu=ParmsSubscription(subscription='EMPLOYEE',sversion='01',sfiles=[psf])
# define Reptor Broker parameters
pbs=ParmsBrokerService(\
broker_id='ETB50019',\
server_class='REPTOR',
server_name='MMSERV',
service='OUT1',
user_id='UEmplTel')
20002900TOM
DILWORTH
00400224USA
101 (219)464-2
21 MGMT10SECRE
ARY
Software AG 2004-2008
Page 23/26
adapya 0.7
September 1, 2008
(312)824-9206
(213)183-1707
(213)793-6785
(415)822-9155
(608)793-6137
(316)409-2438
(301)738-5508
(415)538-7860
(219)464-2421
SALE40
TECH10
TECH10
SALE20
SALE20
SALE20
MGMT30
TECH10
MGMT10
0028-09-23
0026-03-05
0027-09-02
0034-12-31
0046-01-02
0056-07-16
0045-04-06
0048-12-25
0040-02-24
Secretary (*)
Dba
Programmer
Sales Person
Sales Person
Sales Person
Manager
Analyst
Secretary
(*) The full name and position are stored upper-case in the database and capitalized for display
Software AG 2004-2008
Page 24/26
adapya 0.7
September 1, 2008
Software AG 2004-2008
Page 25/26
adapya 0.7
September 1, 2008
Software AG 2004-2008
Page 26/26