Monday, November 22, 2010

Script: PB backup – Using PB ORCA to export PBLs

A basic Operating system level unit in Powerbuilder is a library file (.PBL). Each PBL file is a self contained directory in itself, with the objects stored inside in a proprietary binary format. You need Powerbuilder to view and work with this directory structure (System tree, Library painter etc).

Sometimes, it would be nice to be able to work with individual objects as text files at the OS level. This will enable us to use any text utilities to work with the objects as files (like you would a Java or C++ file). For e.g., I have a Perl script to grep through the exported text files. With text files, you can store away these source files in any version control systems (PVCS, SVN etc) easily. And you can easily diff 2 versions of an object by using any text diff tool (Of course, there are tools available to do these from inside PB, but it's just lot easier to work text files). PB allows the source code to be exported to text files with extensions, *.sr? (.srw for windows, .srd for datawindows etc.).

PB ORCA is an API that Powersoft developed early on for 3rd Party CASE tool vendors to work with PB objects. With PB ORCA, you can write programs to work PB libraries and objects from OS command line. Several object level operations available in PB IDE are also available in this API. Incidentally, there is a command line utility available with the same name (pborca.exe) on Google Code. The tool has several commands that correspond to API functions. You can create a ORCA script file (with .orc extension) and run it in batch mode using the tool. See here for a complete list of commands supported by the tool.

Below script uses pborca.exe in a DOS batch file to export all the objects in all the PBLs in a project directory to a corresponding directory structure. The batch file first loops on a list of .pbl files in a directory (passed in), and creates an ORCA script (latax.orc) with export commands. Then it runs the generated ORCA script using pborca.exe to export the object files (.*sr?). When the script finishes, you will have directory with several sub-directories, one for each PBL file exported.

This script uses several advanced features (%~ modifiers, ENABLEDELAYEDEXPANSION) of DOS Batch file. DOS scripts do several things a Unix script does, but it’s almost like an after thought! More on these later.

I use this script for daily backup of my development environment. Often times only a handful of files change on the developer's PC. Once I export the PBLs to a directory, I can diff 2 different versions using a diff tool. (I use Winmerge). The files can be optionally zipped up as well.

Pborca.exe can also handle the reverse (known as bootstrapping). Exported PB object files are only useful for performing file level operations. To be useful in a PB application, they will have to be imported back in to a PBL file again which can then be opened inside Powerbuilder. As of version 9, PB ORCA can be used to bootstrap as well. See here for the idea.

REM 12,2009 Sam V
REM script to export PBLS using pborca.exe (ORCA interface to PB)
REM this copies all the folders from source (typically Z:) to target.
REM then it creates an ORCA script to export each pbl to the subdirectories.
REM Finally it runs the generated orca script in pborca
REM @echo off

echo %0 %1, %2
@REM copy all the directories from the powerbuilder root to the export directory
@REM if a x.PBL is already in x subdirectory, you may not need MKD1 below.

@echo creating the target directory; just copy the entire path with empty sub-directories
xcopy /t /e /I %1 %2

@REM Here we start generating the orca file to be used with <a href="http://pborca.googlecode.com/svn/trunk/install/deploy/pborca.htm">PBORCA</a>.
@echo session begin pborc100.dll > latax.orc

@echo off
@SETLOCAL ENABLEDELAYEDEXPANSION
@FOR /f "usebackq delims=" %%a IN (`dir /s /b %1*.pbl`) DO (
@set a1=%%~dpa
@REM echo a1=%a1%
@call set "a1=!a1:%~1=%~2!"
@REM MKD1
@REM This creates a sub-directory with the same name as PBL file
mkdir "!a1!"
@echo export %%~fa,,,!a1! >> latax.orc)

@echo session end >> latax.orc

@ENDLOCAL

@echo on
@echo run the script in pborca
pborca latax.orc

REM end of script

Thursday, November 11, 2010

More about PB from my Hello World post

In my earlier post, I wrote a very simple program in Powerbuilder (PB) to print/show Hello World. I tried to compare with many other programming languages there. In that post, there were several concepts introduced. But, being a simple post, I ignored most of the details. We will try to analyze the details here and this way explain what it means to program in PB.

Interpreted or Compiled


From that list of examples I had, there is one thing that stands out. PB looks a lot more like C/C++/Java, at least in commenting style. But, then we see it has the simplicity of Basic program that it's usually thought of as originating from. It also has a lot of similarities with Visual Basic (For that matter with other flavors of BASIC such Power basic as well). PB is actually the tool and it uses proprietary language called PowerScript. Like BASIC this is an interpreted language, but not interactive (In a BASIC interpreter, results were displayed as soon as you type a command (or a command block) and press ENTER.). In PB, though the  code is interpreted, it's not the original code that you typed in, but an intermediate code it generated when you compiled (generated) or ran. More on this below.

 

Object Orientedness:


PB is at the very least, an Object based language. Windows environment contains windows with several controls or widgets on each window. The various controls and windows (objects) talk to each other through events and methods (functions). Now, this itself doesn't make it object oriented, but definitely object based. In PB (as in VB) an application is made up of several objects such as Application, Windows, Buttons, Text Boxes (and Data windows - more on this later). You cannot have a program without an application and you cannot communicate with the users without windows or buttons. So essentially when we build a PB application, we are reusing these "objects" as templates to make our own objects. Thus, by the very nature PB is Object based.

Real Object orientation came to it in later versions. A rudimentary "user object " was introduced as early as ver 3.0 and by Ver 5.0 Pb introduced Object-oriented concepts such as function overloading. Many of us still write object based code in PB, but there have been some movements to make it more and more object oriented. There were several frameworks developed for PBincluding PFC, which is still strong in the Client/Server world. A more sophisticated EAF was developed for PB in an enterprise n-tier world.  A lot more companies seem to be dusting off their old PB programs and try to upgrade latest versions of PB. So, as a developer you will see both object-based and object-oriented code out there. This is different from Java perspective which is Object Oriented to the core, but not unlike C++ where people continue(d) to code C style programs.

User Interface (IDE)


When we did the hello world, we mentioned what we coded and what we saw. But, we did not mention how or where we coded it. A Java program can be coded in a simple text editor like Notepad or more sophisticated Eclipse or Netbeans. It can then compiled and executed in a DOS (or unix/linux) command line. Or like in Eclipse, all these functionality can be done in one tool. Such tools are called IDE - Integrated Development Environment. PB has been IDE from the beginning. In fact, you cannot code or compile PB outside Powerbuilder (not exactly true, particularly the compiling part). Unlike other tools, PB is a more complete IDE and allows you, as a developer, to debug and run from within itself. Also, the code that you put into PB is actually stored in files with the extension .pbl in proprietary format. More on these later.

[caption id="attachment_95" align="alignnone" width="300" caption="Powerbuilder Workspace"]PB Workspace[/caption]

Types of Applications built in PB


What is not revealed in the Hello World program is what kind of programs can be written in PB. Apart from the windows programs, PB can also be a great Client/Server tool. In fact, in corporate environments it is mostly used as a Database programming tool. It's strength lies wholly on the simplicity of database connectivity with the use of Datawindows.  With the advent of EA Server, PB can be a great n-tier development tool as well, like Java J2EE. (More on these later).

PB portability


As mentioned above, PB runs in an interpreted mode. When you compile a PB program, it gets compiled into p-code, a proprietary bytecode. In this regard PB is very much like Java. Just like Java, there are options to compile into native machine code, but typically p-code is preferred. Thus, to run a PB application, you need to install a PB runtime. This is very much like a Java VM. (In fact in EA Server terminology, this is called PB VM). So, theoretically, PB application can be ported and run anywhere PB runtime was available. There were Unix versions of PB available. But, you need a specific version of PB runtime to run a program generated with a specific version of PB. Here it is different from Java, where future runtimes are guaranteed to be backward compatible and thus can run older versions of Java classes.This makes PB less portable. Also, by the windowing nature of it, it naturally fits into Microsoft Windows. The direction Sybase is taking, seems to confirms this. PB12 is, apart from being a windows application builder, also an IDE for .Net plaform.

Starting from my next post, I will go into more details about using the product.

History of PB

Powerbuilder grew from the modest beginnings in the early 80's to where it is now. Those of us who have worked with it for a long time know that it's come a long way as a product. But how many of know it's real history (sort of like the history PC programming world itself)? It was originally conceived and produced by a company called Powersoft. Now it is owned by Sybase. We all knew that it was "bought out" by Sybase in the 90's and what it did to the product. But how many of us know the background of it? Both Powersoft, the company, and Powerbuilder, the product had their fair share of competitions from big giants, threat of hostile takeovers. After initial days of glory, it did lie in the dumps for some time and several wrote death sentence for it. Yet, time and again it came back up again and with PB 12 seems to have gained a new life. I can write about all those here. But, I won't try to re-invent the wheel as there have been several nice posts about the subject. I am listing a few, that I liked, here:

An Article by Chris Pollach

 

History of Powerbuilder from the maker of PBLPeeper

A nice blog about Powerbuilder and other tools

The displaced guy or your personal IT guy on the web!

Hello World!

This is my real first post in Powerbuilder. (I wrote a lot about PB and my association with it before). Like it is customary for any tutorial or book on programming to start with a program to print Hello World, I will try to do the same in Powerbuilder.

Before I jump into it, let's some simple ones: (I am only including the actual lines and not full program code here,  please refer to the really interesting site that prints hello world in various languages - here)

In a Pascal program, you can just say,

[sourcecode language="delphi"]
{Hello World in Pascal}
writeln(&quot;Hello world&quot;);
[/sourcecode]

(In Delphi which is based on Pascal, it is written as,

[sourcecode language="delphi"]
{Hello World in Delphi}
WriteLn('Hello World');
[/sourcecode]

In C, you can do

[sourcecode language="cpp"]
/*Hello World in C*/
puts(&quot;Hello World!&quot;);
[/sourcecode]

In Basic Language, (which contributed to  Powerbuilder's Powerscript) you can do

[sourcecode language="vb"]
10 REM Hello World in BASIC
20 PRINT &quot;Hello World!&quot;
[/sourcecode]

Coming to the more Object oriented world,

In C++ you can write,

[sourcecode language="cpp"]
/*Hello World in C++*/
cout &lt;&lt; &quot;Hello World!&quot; &lt;&lt; endl;
[/sourcecode]

And in Java, this would be,

[sourcecode language="java"]
/*Hello World in Java*/
System.out.println(&quot;Hello World!&quot;);
[/sourcecode]

Well, almost of all of them print to a console - a text based screen, like in DOS, Unix, Linux. The same task of showing hello world to the user takes a bit more, when it comes to a windowing world (like MS windows, X-windows, Apple mac interface). The presentation becomes little more important. After all, in such an operating environment, everything is shown inside a window, so our program needs to write into one such too! In a windowing environment, simplest way to present a text is using some type of message box, which is a small window showing the text (and may be some question buttons).  Luckily windows API offers functions to create such a messagebox with ease. Let's see how we could do the same in Java, for a windowing environment:

[sourcecode language="java"]
/*Hello World in Java -windowing version*/
javax.swing.JOptionPane.showMessageDialog(null,&quot;Hello world!&quot;);
[/sourcecode]

Swing is a package available in Java to create an application for a windowing environment.
Coming back to what we started with, to print Hello World in Powerbuilder, we could do something like above using a messagebox. Luckily PB offers a function for that - MessageBox. So, in the simplest form, we will do,

[sourcecode language="cpp"]
/*Hello World in Powerbuilder-Simple*/
MessageBox(&quot;Hi from Powerbuilder&quot;, &quot;Hello World!&quot;)
[/sourcecode]

We are almost done. Like almost all of the examples above (except BASIC which was interpreted, you just type that one line and it did print it), we need to wrap this line in a program. In the java example above,
we would do,

[sourcecode language="java"]
// Hello World in Java using Swing GUI
class HelloWorldSwing {
static public void main(String args[]) {
javax.swing.JOptionPane.showMessageDialog(null,&quot;Hello world!&quot;);
}
}
[/sourcecode]

Notice the main function. That is the entry point in various languages like C, C++, Java. This is the function that is called when the program is executed.

Powerbuilder is built slightly differently. It does have an entry point function - actually an event. This will be the open even of an Application object. Just like the class with main function becomes entry point object in Java, an Application object is the entry point object in Powerbuilder. So in it's simplest form, we simply add the messagebox function in the application open event and just run the application. When run, this is what you will see,





Well, that's for showing the simplest way. But a typical PB application is built not just with application object, but with one or more windows as well. We will see about that in a later post.

Saturday, September 18, 2010

What is Powerbuilder?

Powerbuilder is an IDE, an integrated Development Environment, a tool where a programmer do everything within it, including design and develop screens/reports, write command line programs, compile, deploy applications all from within Powerbuilder.

This is in contrast to programming in languages like C or Pascal, where you use a text editor to edit, a compiler to compile and copy files to deploy.

IDE's and case tools were popular in early 90's. There were several such tools that promised "less or no coding" and yet develop and deploy enterprise applications. Powerbuilder was one of many tools available. I remember reviewing PB, Visual Basic (VB), Gupta SQL windows and Oracle CDE (successor to SQL forms in windows). Of all these, I took to PB easily, I liked SQL windows better (I remember it was more colorful and windowy!). Oracle CDE (forms 4.0) didn't measure up. And Visual Basic needed more programming.  I remember the days when VB and PB were constantly compared and contrasted. Each had it's own strength but PB won in some of the corporate contracts. The datawindow, and the quick reporting capability were probably some of the secret.

Contrary to popular belief, it's not a tool for non-programmers - managers, Business Analysts and the like. Yes, several tried, but any serious screens in PB always needed programming. To this day, I hear people brushing it as a child's play in the world of complex Java and .Net applications. But PB is used, surprisingly, in building big corporate applications, even today. And such serious development activities always involve programming. Programming in a language called Powerscript. It's basic with a twist. Long before Java became so popular, it took some tenets of C++ and became Object oriented. (OO pundits may not agree and call it more Object based than object oriented, but that's a topic for another post!). Oh, about PB for managers, Sybase made another tool called Info-maker, a trimmed down version of PB, which didn't require programming (or lacking programming, depending on who looks at it).

PB is definitely easier to use to build screens and rudimentary database applications. I feel, the user interface is definitely easier to use than that of VB, but then I've been using it for many years. The strength of Powerbuilder, as against other tools was and has been the datawindows, a compiled widget readily available to include in any windows. Strictly speaking, a datawindow is a window that may have many controls on it, but the difference is that a datawindow is managed by PB routines as against windows API. For this reason, Sybase always suggests to combine many different controls in a window into a single datawindow, wherever possible, for performance.

A datawindow widget is not much unlike ADO or DAO objects in VB. The strength of the datawindow is that it's built around SQL (what's called a datasource - there are other data sources, more later) and by keeping the SQL in PB itself and database neutral, we could make the same datawindow work with many different databases, like Oracle, Sybase, Informix etc.

PB has changed a lot over the years. People who have seen it in the 90's will definitely realize the transformation. The IDE itself started packing more in version 7.0. Now, in version 10.x and beyond, it's turned into a true development tool. (Rumor has it that PB 12.0 could actually be used as an IDE for .Net development!). The question still remains, in the world of Eclipse and Netbeans, Java and .net, why PB? That too enterprise edition costs a bundle when Java is all free. This blogger aims to ask some of those questions and try to find answers live on this blog.

Currently I am working at the City of LA where we use Powerbuilder heavily in a clustered EA Server environment. We even have extensions on the web using JSP and Coldfusion. The software is a tax software used by thousands of businesses in and around LA. This is no child's play. EA Server is to Powerbuilder like weblogic to Java. It's an application container that can run PB objects and Java objects alike and it uses CORBA (how much it reminds me of Forte UDS!).

From the simple client/server tool, PB has reinvented itself several times to become a n-tier platform here. Earlier PB turned out a non-visual object (NVO) that proved vital to this n-tier platform. An utterly client widget, datawindow, gave birth to (non-visual) datastores that eventually helped them to be n-tier objects as well.

But then again, I feel, Sybase lost several opportunities to build it up and market it as the greatest tool on earth (I don't mean exactly that, but at least the ads should say it, right?).  They are constantly toying with the ideas and drop them like a fly. Most recently, the EA framework, built by Cynergy Systems for Sybase, that can be used to build Enterprise applications in PB/EA Server environment has been discontinued. EA Server itself is dangling. You hear about PBNI, PB ORCA, I've used them too, but their future is always questionable. In the world, where every version of a software gets better with time, some of these tools inside PB appear and disappear. With PB becoming an IDE to .net, their neutrality to languages may be disappearing. And finally, with SAP buying Sybase recently, the whole existence of PB as a tool may be in jeopardy. (You think this is not possible, think what happened to Forte UDS. Sun bought this company only to kill the software, as it was a competition to Java J2EE at the time. How did they do it? They created a lousy tool called Forte for Java to erase the name Forte and eventually pulled the plug on many websites that talked about the old Forte).

We will go on a journey here in  this blog, where I will not only share my experiences with the tool, but also technical articles, how-tos about PB.

Saturday, January 16, 2010

My Journey with and without Powerbuilder

As I mentioned in my previous post, I worked on Powerbuilder (PB) for a while, went away and finally came back to using it. I came  in contact with Powerbuilder in the early 1990. I was working for a Consulting company and we evaluated several products to port an existing applications written in B-Trieve/C and some others in d-Base.

The version I came to see was ver 3.0 and it really took me by surprise. In those days, writing windows programs was not easy. Anyone written programs in C/C++ programs would understand. I also dabbled in a few tools, including C and Turbo Pascal. Remember all those resource files you had to do, to make a screen? PB (and few other tools of the day) changed all that. It was called the 4GL (4th generation language, as against C which was a 3GL language). These were the times when CASE tools were also becoming popular. See this wiki article for more on those.

So, PB naturally had a lot of competition. Microsoft Visual Basic, Gupta SQL, Oracle forms for windows (CDE) were there to name a few. We did try each of these, but PB fared better than the rest. (Of course Oracle forms was there already, which was popular and did the job, but it wasn't a windows application builder. It's cousin Oracle CDE didn't do a good job at the time). Powerbuilder had something unique that made it win that round of the competition, the datawindows.

I joined one of the medium sized consulting companies in 1994. They got me into a shipping company, APL, in Oakland, CA. The company was porting their mainframe programs to client server world using Powerbuilder/Oracle. It was an ambitious plan, but it definitely looked glamorous (Kind of what mobile apps are to the current generation). With only some exposure to the product, I joined APL as a PB expert. All those mainframe programmers felt threatened and wanted to learn PB from me as quickly as possible to keep their jobs! Legacy has to go and the glitter of client/server was in! I saw several legacy products getting migrated from mainframe and other platforms to PB. There were products to bring mainframe data into PB screens including a "screen scraper" from Mitem View!

At that time Powerbuilder was owned by a company called Powersoft. It was a cute Client/Server product that allowed one to create windows screens that would connect to a database server and these were to replace those complex mainframe applications. It was like gold rush! For over 5 years, PB was ruling the corporate world. And like the gold rush came the bust as well.

The year was 1999. Sybase acquired PB by then. By then PB projects were dwindling down, and PB links on the web started disappearing on the web.  Java was in, at several of those places that went into PB earlier. Client/Server was not going to cut it any more and n-tier was the word. They did come up several contraptions to put themselves in the n-tier world, but none really succeeded back then.

I was in Toronto, trying to win a PB project at the time. I did some prototypes, but the local Sybase developers undercut us. They came with the just released PB 7.0, which we hadn't seen. Their prototype and PB, both included a Treeview structure (sorta what you see in windows explorer). That was end of PB career, or so I thought at the time. I left the PB scene like 1000s of other programmers seeking greener pastures. Java came to the rescue, I also had an opportunity to get to know a great product called Forte. (Forte was a truly OO and n-tier product from the get go. More about it in another post).

Then, came recessions, job losses. In 2004, surprisingly, PB came to my rescue in an unsuspecting place in Fremont, CA. That kept me going a bit more and I branched into Oracle world. And another recession brought me back to the PB world again.

I recently took a job at the city of LA, in supporting and enhancing their Powerbuilder application running against EA Server.

In the world of short lived technologies and dying programming tools, I am amazed to find this product not only surviving, but evolving into what it is today, Powerbuilder + EA Server (Jaguar). In the upcoming posts, I will share some of my experiences and views about the tool!

Born Again Powerbuilder

I am a born again Powerbuilder (developer)! That's right I program in Sybase's Powerbuilder, again!

Like many I also left it sometime in 1999 when it looked like fading. But, Powerbuilder has proved it's worth and reserved it's place and pace in the ever growing world of Java, C++ and .Net. It has not only survived the onslaught of new technologies, but I feel it is coming out of hibernation.

To those who don't have a clue as to what Powerbuilder is, it's a client server development tool that a small company called Powersoft brought out in the late 80's. It had it's hay days in the 90's during the hysteria in corporate world to migrate out of "legacy" mainframe applications to Client/Server. Few of us, that knew Powerbuilder were the "new kids on the block" and the new order priests. But it all dried down soon after Sybase took over. By then internet programming took over and the rest is history.

Now, Powerbuilder is becoming "legacy" application itself and I know what those Mainframe programmers must have felt when we "Client/Server" programmers arrived. One consolation: Powerbuilder did not die while competition like Visual Basic, Gupta SQL and Oracle CDE slowly disappeared in the corporate scene, either naturally or because of company policies. At least, it has been a recession proof job finder for me.

If anyone tries to search "Powerbuilder" on the net, they may be up against broken links and/or old contents. There hasn't been any good books written on the subject and while it seems to be dying, you also hear about Sybase bringing out the Powerbuilder ver 12.x and Pocketbuilder etc. They also silently integrated Java into their product line.

I recently took up yet another Powerbuilder job maintaining a PB 10.x application using EA Server 5.5. I intend to share with you my experiences and my love-hate relationship with the product.

Hope you find this useful.