Rexx – Handheld & Embedded Programming ”; Previous Next Handheld devices have come a long way and Rexx has a lot of ways in which it can run on these devices. Rexx has support for Pocket PC’s, Palm devices, PDA’s and other smart phone devices. The advantage of Rexx to work on these platforms is that Rexx is really a small weight programming system which just runs in the span of a few kilobytes. Hence it becomes easier to run Rexx programs on these devices. Rexx on hand-held devices can run in the following modes − The first mode is the native node where it runs directly on the operating system itself. The advantage on running in this mode is that it is faster since it runs directly off the operating system. The next mode is on top of the DOS or emulator program on top of the hand held device. The advantage of this mode is that is can run on any type of operating system as long as the emulator runs on that operating system. The Rexx Interpreters for the various hand held devices categories are shown below. Windows CE − Brexx Palm OS − Rexx for Palm OS Symbian OS − Regina For the DOS emulator, the following steps need to be carried out − Step 1 − First is to download PocketDOS which is a popular DOS emulator. It is designed to run on many operating systems and has support for common VGA screens and serial and parallel ports. Step 2 − The next step is to download the BRexx files for 16-bit DOS to a Windows PC. Step 3 − The final step is to use ActiveSync to sync the Rexx program to the hand held device. There are some other commercial DOS based products available. XTM is a product which falls under this category. The features of this product are as follows − Support for the 80186 CPU and instruction set. It kind of works off the BIOS code for better performance. It can provide emulation for the Math co-processor, version 8087 MPU It provides access to the serial ports. It supports a variety of languages such as English, French and German. Print Page Previous Next Advertisements ”;
Category: Computer Programming
Rexx – Databases
Rexx – Databases ”; Previous Next Rexx has the ability to work with a variety of databases which are listed below. HSQLDB Oracle SQL Server MySQL MongoDB All the information for Rexx databases can be found once you click on the following link − https://rexxsql.sourceforge.net/ In our example, we are going to use MySQL DB as a sample. So the first step is to ensure to download the required drivers from the Rexx SQL site so that Rexx programs can work with SQL accordingly. So follow the subsequent steps to ensure that Rexx programs can work with MySQL databases. Step 1 − Go to the following drivers download page from the Rexx site − https://sourceforge.net/projects/rexxsql/files/rexxsql/2.6/ Step 2 − Download the MYSQL drivers – rxsql26B3_my_w32_ooRexx Step 3 − Unzip the contents to the local machine. Step 4 − Add the path of the unzipped folder to the path variable on your machine. For all the subsequent examples, make sure of the following pointers are in place − You have created a database TESTDB. You have created a table EMPLOYEE in TESTDB. This table has fields FIRST_NAME, LAST_NAME, AGE, SEX and INCOME. User ID “testuser” and password “test123” are set to access TESTDB. Ensure you have downloaded the mysql jar file and added the file to your classpath. You have gone through MySQL tutorial Database Connection To establish a database connection, you first need to the Rexxsql DLL and then use the SQLConnect function to establish a connection to the database. The syntax and example of how this can be achieved is given below. Syntax SQLConnect(cname,username,password,dbname) Parameters cname − This is the name to give to the connection. username − The user name to connect to the database. password − The password to connect to the database. dbname − The database schema to connect to. Return Value A value equal to 0 will mean that the database connection is successful. Example /* Main program */ Call RxFuncAdd ”SQLLoadFuncs”, ”rexxsql”, ”SQLLoadFuncs” Call SQLLoadFuncs say SQLConnect(c1,” testuser ”,” test123”,”testdb”) The output of the above program would be as shown below. 0 Creating a Database Table The next step after connecting to the database is to create the tables in our database. The following example shows how to create a table in the database using Rexx. All of the commands in Rexx SQL are executed by using the SQLCommand function. Syntax SQLConnect(sname,statement) Parameters sname − This is the name to give to the statement to execute. statement − This is the statement which needs to be executed against the database. Return Value A value equal to 0 will mean that the command was successful. Example /* Main program */ Call RxFuncAdd ”SQLLoadFuncs”, ”rexxsql”, ”SQLLoadFuncs” Call SQLLoadFuncs if SQLConnect(c1,”testuser”,”test123”,”testdb”) == 0 then say ”Connect Succedded” if SQLCommand(u1,”use testdb”) == 0 then say ”Changed database to testdb” sqlstr = ”create table employee (first_name char(20) not null, last_name char(20),age int, sex char(1), income float)” if SQLCommand(c2,sqlstr) == 0 then say ”Employee table created” The output of the above program would be as shown below. Connect Succedded Changed database to testdb Employee table created Operations on a Database Table The following types of operations are most commonly performed on a database table. Sr.No. Operation & Description 1 Insert Operation It is required when you want to create your records into a database table. 2 Read Operation A READ Operation on any database means to fetch some useful information from the database. 3 Update Operation The UPDATE Operation on any database means to update one or more records, which are already available in the database. 4 Delete Operation The DELETE operation is required when you want to delete some records from your database. 5 Closing a Connection The following command can be used to close a connection to the database. Performing Transaction Transactions are a mechanism that ensures data consistency. Transactions have the following four properties − Atomicity − Either a transaction completes or nothing happens at all. Consistency − A transaction must start in a consistent state and leave the system in a consistent state. Isolation − Intermediate results of a transaction are not visible outside the current transaction. Durability − Once a transaction was committed, the effects are persistent, even after a system failure. Here is a simple example of how to implement transactions. Example /* Main program */ Call RxFuncAdd ”SQLLoadFuncs”, ”rexxsql”, ”SQLLoadFuncs” Call SQLLoadFuncs if SQLConnect(c1,”testuser”,”test123”,”testdb”) == 0 then say ”Connect Succedded” if SQLCommand(u1,”use testdb”) == 0 then say ”Changed database to testdb” sqlstr = “DELETE FROM EMPLOYEE WHERE AGE > 20″ if SQLCommand(c2,sqlstr) == 0 then if sqlcommit() == 0 then say committed The output of the above program would be as shown below. Connect Succedded Changed database to testdb COMMITTED Commit Operation The commit operation is what tells the database to proceed ahead with the operation and finalize all changes to the database. In our above example, this is achieved by the following command. Sqlcommit() Rollback Operation If you are not satisfied with one or more of the changes and you want to revert back those changes completely, then use rollback method. In our above example, this is achieved by the following command. SqlRollback() Print Page Previous Next Advertisements ”;
Rexx – Netrexx
Rexx – Netrexx ”; Previous Next NetRexx is the java implementation of Rexx. In NetRexx, the implementer is used to convert the Rexx program to a java program which can then be run on any Java virtual machine. Setting up NetRexx The first step in NetRexx is to set it up on the local machine. To do this, one needs to perform the following steps − Step 1 − Go to the NetRexx download site − http://www.netrexx.org/downloads.nsp Download the NetRexx.3.04.GA file. Step 2 − Ensure that java is installed and running on your system. You can verify that java is running by using the java–version command. An example of the output is shown below. H:>java -version java version “1.7.0_79” Java(TM) SE Runtime Environment (build 1.7.0_79-b15) Java HotSpot(TM) Client VM (build 24.79-b02, mixed mode, sharing) Step 3 − Unzip the contents of the Netrexx zipped file. Copy the files from the NetRexx3.04GAlib folder to your java installation/lib/etc folder. Step 4 − Add the NetRexx-3.04GAbin path to the path variable on the system. Running the First NetRexx Program Create a file called main.nrx and place the following code in the file. /* Main program */ say ‘hello’ To compile the code run the following command. NetRexxC main.nrx You will then get the following output. NetRexxC is the compiler which converts the rexx program to its java equivalent. java -cp “;;G:NetRexx-3.04GAlibNetRexxF.jar;.” -Dnrx.compiler = ecj org.netrexx.process.NetRexxC main.nrx NetRexx portable processor 3.04 GA build 4-20150630-1657 Copyright (c) RexxLA, 2011,2015. All rights reserved. Parts Copyright (c) IBM Corporation, 1995,2008. Program main.nrx Compilation of ”main.nrx” successful You can now run your java program using the following java command. java main When you run the above command, you will get the following output. Hello Let us now discuss some of the special aspects of the Netrexx library. Indexed Strings In NetRexx, strings can become the indexes to arrays. An example is shown below. Example /* Main program */ value = ”unknown” value[”a”] = ”b” c = ”a” say value[c] When we run the above program, we will get the following result. Output b Multiple Indexes In NetRexx, you can have multiple indexes for arrays. An example is shown below. Example /* Main program */ value = ”null” value[”a”, ”b”] = 1 say value[”a”, ”b”] When we run the above program we will get the following result. Output 1 Sr.No. Command & Description 1 ask Command This command is used to read a line from the default input stream. 2 digits Command This command is used to display the current value of the digits’ value. 3 form Command This command is used to display the current value of the form value. 4 length Command This command is used to display the length of a string value. 5 version Command This command is used to return the current version of NetRexx being used. 6 trace Command This command is used to return the current trace setting being used by NetRexx. Print Page Previous Next Advertisements ”;
Rexx – Graphical User Interface ”; Previous Next In order to use the graphic user interfaces available in Rexx, one needs to use 2 packages, one is called ActiveTcl and the other is the Rexxtk package. Along with these 2 packages, one can design normal forms which can have buttons and other controls on the forms. Environment Setup The first thing to do is the environment setup. Let’s go through the following steps to have the environment in place. Step 1 − Download the Activetcl package from the following website − https://www.activestate.com/activetcl Step 2 − The next step is to start the installation of ActiveTCl. Click on the Next button on the screen to proceed. Step 3 − Accept the license Agreement and click on the Next button. Step 4 − Choose a location for the installation and click on the next button. Step 5 − Choose a location for the installation of the demo’s and click on the Next button. Step 6 − Click on the Next button to proceed with the installation. Step 7 − Click on the Finish button to complete the installation. Step 8 − The next step is to download the Rexxtk software from the following link − https://sourceforge.net/projects/rexxtk/ Step 9 − Double click the installer file from the link in the previous step to start the installation. Click on the next button to proceed. Step 10 − In the next screen, click on the Yes button to agree to the License Agreement. Step 11 − In the next screen, choose the location for the installation and click on the Next button. Step 12 − Choose the Program folder location and click on the next button. Once the installation is complete, we can now start with programming the GUI’s in Rexx. Basic Program Let’s see how we can design a simple basic program with Rexx in a graphical user interface format. Example /* Main program */ call RxFuncAdd ”TkLoadFuncs”,”rexxtk”,”TkLoadFuncs” call TkLoadFuncs do forever interpret ”Call” TkWait() end call TkDropFuncs exit 0 The following things need to be noted about the above program − The Rexxtk library and all of its functions are loaded using the RxFuncAdd command. The do forever loop will keep the window open and will wait for the user input. Once the user input is detected, the program will exit. When the above program is executed, you will get the following output. Creating Menus Menus are created with the help of the TkMenu and TkAdd functions. The syntax of these functions are given below. Syntax TkMenu(widgetname,options,0) Parameters Widgetname − A name to give to the menu. Options can be anyone of the following − selectcolor − if checkboxes or radio buttons are used as menu options, then this option specifies the color to choose when any menu option is selected. tearoff − This option is used for adding sub menus to the main menu. title − The string that needs to be used to give the window a title. Return Value A handle to the menu created. Example /* Main program */ call RxFuncAdd ”TkLoadFuncs”,”rexxtk”,”TkLoadFuncs” call TkLoadFuncs menubar = TkMenu(”.m1”) filemenu = TkMenu(”.m1.file”,”-tearoff”, 0) call TkAdd menubar, ”cascade”, ”-label”, ”File”, ”-menu”, filemenu call TkAdd filemenu, ”command”, ”-label”, ”Open…”, ”-rexx”, ”getfile” call TkConfig ”.”, ”-menu”, menubar do forever interpret ”Call” TkWait() end call TkDropFuncs exit 0 The following things need to be noted about the above program − The menubar is created using the TkMenu function. The ‘tearoff’ parameter means that we need to create sub menus which is going to be attached to the main menu. We then add 2 menu options called File and Open using the TkAdd function. When the above program is executed, you will get the following output. Print Page Previous Next Advertisements ”;
Rexx – Instructions
Rexx – Instructions ”; Previous Next Rexx provides a number of instructions that gives a wide variety of functionality, most of them which allow you to interact with the Operating System. Let’s look at some of them in detail. Sr.No. Rexx Instructions 1 address This function is used to display the current command environment. 2 drop This function is used to un-assign a variable. 3 interpret Interprets or executes the defined instruction. 4 nop This function means to perform no operation. This command is normally used in if statements. 5 Pull This is used to pull input from the stack or from the default stream. 6 push This is used to push a value onto the Rexx stack. Print Page Previous Next Advertisements ”;
Rexx – Portability
Rexx – Portability ”; Previous Next Portability is an important aspect in any programming language. As one knows, Rexx is available in a variety of operating systems such as Windows and Linux. So it need to be ensured that when one develops a program on the Windows platform, that it has the necessary precautions taken if the same programs runs on a Linux platform. Rexx has the ability to run system level commands. There are commands which can be used to understand what is the operating system on which it is running on. Based on the output it can then take the appropriate actions to see what are the commands that can be run on this operating system. Example The following example shows how the parse functions are used to get the details of the operating system on which the program is running. /* Main program */ parse version language level date month year. parse source system invocation filename. language = translate(language) if pos(”REGINA”,language) = 0 then say ”Error , the default interpreter is not Regina” language say ”The Interpreter version/release date is:” date month year say ”The Language level is: ” level say ”The Operating System is” select when system = ”WIN32” then ”ver” when system = ”UNIX” | system = ”LINUX” then ”uname -a” otherwise say ”Unknown System:” system end if rc <> 0 then say ”Error :” rc The output will vary depending on operating system. A sample output is given below. The Interpreter version/release date: 5 Apr 2015 The Language level is: 5.00 The Operating System is Unknown System: WIN64 Bad return code: RC Print Page Previous Next Advertisements ”;
Rexx – Brexx
Rexx – Brexx ”; Previous Next BRexx is a lighter weight implementation of Rexx. It still has a lot of functionality to offer as part of the Rexx implementation. Setting up BRexx The first step in BRexx is to set it up on the local machine. To do this, one needs to perform the following steps − Step 1 − Go to the BRexx download site − https://ftp.gwdg.de/pub/languages/rexx/brexx/html/rx.html Go to the downloads section and download the product. Step 2 − Unzip the contents of the Brexx zipped file. Step 3 − Add the BRexxbin path to the path variable on the system. Step 4 − Create a new variable called RXLIB and point it to the lib folder in the Brexx folder. Running the First BRexx Program Create a file called main.rexx and place the following code in the file. /* Main program */ say ‘hello’ To run the program, run the following command. rexx32 main.rexx When you run the above command, you will get the following output. hello Let us now discuss some of the most commonly used functions available in the BRexx library. Sr.No. Functions available in the BRexx Library 1 acos Command This command is used to get the arc-cosine conversion of a number. 2 cos Command This command is used to get the cosine conversion of a number. 3 sin Command This command is used to get the sine conversion of a number. 4 asin Command This command is used to get the arc-sine conversion of a number. 5 tan Command This command is used to get the tangent conversion of a number. 6 atan Command This command is used to get the arc-tangent conversion of a number. 7 mkdir Command This command is used to create a directory in the current working directory. 8 rmdir Command This command is used to remove a directory in the current working directory. 9 dir Command This command is used to return the entire directory listing. Print Page Previous Next Advertisements ”;
Rexx – Implementations
Rexx – Implementations ”; Previous Next The Rexx language has a lot of various implementations as we have already seen in the previous chapters. Each implementation has its own functionality. Let’s look at the various implementations available for Rexx. OoRexx This is the object oriented version of Rexx. By default, the Rexx basic implementation is all based on procedures. But with ooRexx you can offer greater flexibility by having an Object oriented approach to Rexx. By using ooRexx you can have better re-use through creating re-usable classes and objects. The following program is an example of a simple Rexx program which can be run with the ooRexx implementer. Example /* Main program */ say ‘hello’ To run this program, run the following command. rexx main.rexx When you run the above command, you will get the following output. hello Netrexx This is for all Java based developers as it provides a Java based alternative for the Rexx language. So all of the objects are based on the Java Object Model. The advantage of this framework is that since Java is a widely popular language it becomes easier for developers to use this framework. So in this implementation, the Rexx code is converted to a Java program which can then be run on any Java virtual machine. The following code is an example of a NetRexx program. Create a file called main.nrx and place the following code in the file. /* Main program */ say ‘hello’ To compile the code run the following command − NetRexxC main.nrx You will then get the following output. NetRexxC is the compiler which converts the Rexx program to its java equivalent. java -cp “;;G:NetRexx-3.04GAlibNetRexxF.jar;.” -Dnrx.compiler = ecj org.netrexx.process.NetRexxC main.nrx NetRexx portable processor 3.04 GA build 4-20150630-1657 Copyright (c) RexxLA, 2011,2015. All rights reserved. Parts Copyright (c) IBM Corporation, 1995,2008. Program main.nrx Compilation of ”main.nrx” successful You can now run your java program using the following java command. java main When you run the above command, you will get the following output. Hello Brexx This is a lightweight implementation of Rexx. This is a lighter package than the standard Rexx implementer. But it still has the full functionality of Rexx. The following code is an example of a BRexx program. /* Main program */ say ‘hello’ To run the program, run the following command. rexx32 main.rexx When you run the above command, you will get the following output. hello Print Page Previous Next Advertisements ”;
Rexx – Error Handling
Rexx – Error Handling ”; Previous Next Rexx has the ability to also work on Error handling as in other programming languages. The following are some of the various error conditions that are seen in Rexx. ERROR − This even is raised whenever a command which is sent to the operating system results in an error. FAILURE − This even is raised whenever a command which is sent to the operating system results in a failure. HALT − This is normally raised whenever an operation is dependent on another operation. An example is if an I/O operation is being halted for any reason. NOVALUE − This event is raised when a value has not been assigned to a variable. NOTREADY − This is raised by any I/O device which is not ready to accept any operation. SYNTAX − This event is raised if there is any syntax error in the code. LOSTDIGITS − This event is raised when an arithmetic operation results in a loss of digits during the operation. Trapping Errors Errors are trapped with the help of the signal command. Let’s take a look at the syntax and an example of this. Syntax signal on [Errorcondition] Where, Errorcondition − This is the error condition which is given above. Example Let’s take a look at an example on this. /* Main program */ signal on error signal on failure signal on syntax signal on novalue beep(1) signal off error signal off failure signal off syntax signal off novalue exit 0 error: failure: syntax: novalue: say ”An error has occured” In the above example, we first turn the error signals on. We then add a statement which will result in an error. We then have the error trap label to display a custom error message. The output of the above program will be as shown below. An error has occurred. An example of error codes is shown in the following program. /* Main program */ signal on error signal on failure signal on syntax signal on novalue beep(1) exit 0 error: failure: syntax: novalue: say ”An error has occured” say rc say signal The output of the above program will be as shown below. An error has occured 40 6 Print Page Previous Next Advertisements ”;
Rexx – Parsing
Rexx – Parsing ”; Previous Next One of the most powerful features of Rexx is its ability to parse text values. You probably will not see this in any other programming languages. The general format of the parse statement is as follows − Syntax PARSE {UPPER|LOWER|CASELESS} source {template} Where, UPPER − The source is converted to upper case before parsing. LOWER − The source is converted to lower case before parsing. CASELESS − When this parameter is passed, the casing is ignored. source − This is the source which needs to be parsed. There are many options available for this and can be any one of the following − ARG − The arguments for the program or procedure can be used as the source. LINEIN − The next line input can be used as the source. SOURCE − The source information of the program can be used as the source. VAR name − The value of a variable name can be used as the source. template − This parameter specifies how to parse the source. There are many options available for this. Some of them are mentioned below. variable name − This is the value assigned to the variable. literal string − A literal string which can be used a pattern to split the strung. # − An absolute character position within the source itself. So if you specify a value of 5, the 5th character will be used. +# − A relative character position within the source itself. So if you specify a value of 5, the 5th character will be used relatively. Let’s look at a simple example of how parsing can be accomplished in Rexx. Example Live Demo /* Main program */ parse value ”This is a Tutorial” with word1 word2 word3 word4 say “””word1″”” say “””word2″”” say “””word3″”” say “””word4″”” The above program parses the words in the phrase. When a value consists of words that are separated by only one space, and there are no leading or trailing spaces, the value is easy to parse into a known number of words as follows. The parse function is used in Rexx to take a string value and then break them down into words. In the above example, the words are then split and then stored in the word variables. The output of the above program would be as follows − ”This” ”is” ”a” ”Tutorial” Another example of parsing is shown in the following program. This time we are using a while clause to do the parsing. Example Live Demo /* Main program */ phrase = ”This is a Tutorial” do while phrase <> ”” parse var phrase word phrase say “””word””” end The above program will give the following output − ”This” ”is” ”a” ”Tutorial” Positional Parsing Rexx also allows one to work with positional parsing. Let’s see an example of how we can achieve positional parsing with the parse statement. Example Live Demo /* Main program */ testString = “Doe John M. 03/03/78 Mumbai India”; parse var testString name1 11 name2 21 birthday 31 town 51 country say name1 say name2 say birthday say town say country From the above example, you can note that along with the variable name, we are also specifying where the string should end. So for name1, we should end by the 11th character and then starting parsing name2. The output of the above program will be as follows − Doe John M. 03/03/78 Mumbai India You can also use relative positional parsing in this case. Example Live Demo /* Main program */ testString = “Doe John M. 03/03/78 Mumbai India”; parse var testString name1 +10 name2 +10 birthday +10 town +20 country say name1 say name2 say birthday say town say country The output of the above program will be as shown below. Doe John M. 03/03/78 Mumbai India Print Page Previous Next Advertisements ”;