Monday, 3 January 2011

Mainframe Transaction Simulation with JAVA

This is a simple example for converting programs from mainframe to JAVA - UNIX machines.

The simple example below is a full prototype of realizing mainframe transaction logic
with JAVA and uNIX systems. The transaction table processing is omitted to make things simple but it is self explanatory to add it to the right place.

A mainframe program works in a CICS like environment. In order to simulate this I will use Tomcat application server and start a JAVA program from a JSP. JSP will simulate CICS screen where you enter the transaction id.

The JSP will call the simple utility lib ARSlib which has the function to invoke the
program that corresponds to this transaction. The program itself is pur into the same place in the same jar as the utility lib. In reality it can be in another jar,
presumably a transaction-program library or even lib structure.

The simple example below is done with NetBeans 6.9.1 and JDK1.6.
It works fine as you will notice from the outputs.

<?xml version="1.0" encoding="UTF-8"?>
<web-app id="WebApp_9" version="2.4" xmlns="" xmlns:xsi="" xsi:schemaLocation="">

<display-name>Transaction Call Simulation</display-name>



<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
<%@ page import="testPackage.*" %>

ARSlibrary lib = new ARSlibrary();

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<h1>Hello World!</h1>

package testPackage;

public class ARSlibrary {
public ARSlibrary() {
System.out.println("ARSlibrary's constructor");

public void invokeProgram(String name) throws Exception {
Class<? extends ARSprogram> np = (Class<? extends ARSprogram>) Class.forName(name);
if (np == null) {
throw new Exception("Program " + name + " not in this library");
ARSprogram a = (ARSprogram) np.newInstance();

package testPackage;

public class ARSprogram {
public void main() {
System.out.println("ARSprogram's constructor");

package testPackage;

public class testClass extends ARSprogram {
public testClass(){
System.out.println("testClassS constructor");
public void main(){
System.out.println("Transaction testClass has worked!");