SYS-CON MEDIA Authors: Elizabeth White, Yeshim Deniz, Pat Romanski, Gary Arora, Zakia Bouachraoui

Blog Feed Post

Refactoring PowerBuilder code with the PowerDesigner plug-in

Here’s a trivia question for you… How long ago did Sybase release the PowerDesigner Plug-in for PowerBuilder?

Your answer would probably be, “What the heck is the PowerDesigner Plug-in for PowerBuilder???”  It is, arguably, the least-discussed feature of both PB and PD, and yet, with the release of PB12.NET, it could become the most important tool in your PB toolkit.  As developers look to migrate their existing (and often, aging) PB applications to PB12.Net and Windows Presentation Foundation (WPF), they may encounter the need for some level of refactoring.  It may be necessary to “flatten” the object hierarchy by consolidating classes, or to better isolate the presentation layer (View) from the business logic (Controller) and the data access layer (Model).  My colleague Yakov Werde has published a number of great articles and videos on the ups and downs of PowerBuilder migrations.  You can find them all here.

As long time PB developers know, this type of work is never fun, due to some basic restrictions built into the PB IDE itself.   For example, since PB always opens objects in “edit” mode, it cannot allow an ancestor class and one of its descendent classes to be open in the painter simultaneously.  The refactoring process becomes a tedious and error-prone cycle of opening the descendent, copying code to the clipboard, closing the descendent, opening the ancestor, pasting in the code, closing…  Oh, and don’t forget that the Classic PB requires an object to compile cleanly before it allows a save.  And some tasks, like altering an object’s ancestry, can’t be done in the painter at all!  These require the developer to resort to the “Edit Source” option, working directly with the PB source code!  Not a task for the faint of heart (or the newbie)…


Most PowerBuilder developers are probably familiar with PowerDesigner and it’s industry-leading Data Modeling capabilities, and perhaps they even use it to generate a Data Dictionary for their relational database.  But PowerDesigner has a depth and breadth far beyond basic data modeling that many are just not aware of…  One of the primary features of the Developer edition of PD is the Object Oriented Modeling (OOM) tool.  The OOM has the ability to reverse-engineer code modules into a UML compliant Class Diagram.  It actually reads and parses the code, and generates all the UML artifacts into a PD model!  Once the code is reversed into a Class Diagram, the developer can work with the model in a graphical drag-and-drop UI, and then forward-engineer the changes back into the code.  PD can read and write a number of languages, including Java, Visual Basic, C, C++, C#, and (wait for it…), PowerBuilder!    PowerDesigner can directly update the PowerScript inside PB Classic PBLs!


Let’s get started with a simple demo using the Examples app that ships with PB 12 Classic, and PD 15.2. One note: the PD plug-in is a free component, but you do have to have PowerDesigner (Developer or Studio editions) installed to get it.

The first step (after both PB and PD are installed) is to enable the plug-in inside the PowerBuilder IDE.  Open PB, and select Tools > Plug-in Manager… This opens the dialog shown in Figure 1.  Simply check PowerDesigner on and click OK.

Plug-in Manager dialog

Three new panels will appear in the IDE – the Class Browser and two “output” panels.  Since these take up valuable screen real estate, I typically close the output panels and just leave the Object Browser visible.  The output panels will automatically reappear when needed, so just close those for now.

 PB IDE with PD Plug-in activated

The next step is to reverse-engineer the PowerBuilder code into an Object Oriented Model.  The plug-in will add three new menu options to the Target context menu.  Right-click on the Target and select Reverse Engineer.

Plug-in menu items

This brings up a dialog that shows a treeview containing all the PBLs in the current target, and all the objects in each PBL.  This lets you select the PBLs or individual objects that need to be reverse-engineered.  Typically, one would reverse the entire target, but hundreds of classes can result in quite a messy diagram.  If you know you’ll be working with a distinct subset of the target, deselect anything that isn’t required.  Click OK to initiate the reverse-engineering process, and then go get a cup of coffee (or maybe even grab lunch?).  The process can take several minutes, depending upon the number of objects being reversed, and the number of object references that are detected.

Reverse Engineer dialog


When the process finishes, there are two important steps that must be completed to “finalize” the linkage between the model and the PB target.

  1. Save the OO Model to a .OOM file.  Right-click the second node in the PD Object Browser (the one just below the topmost “Workspace” node) and select Save As…  to save the .OOM file into a folder somewhere.  
  2.  Now go back to the PB System Tree and right-click on the Target node (again, not the Workspace node).  Select Plug-in Attributes… to open the dialog window shown below.  Set the oompath attribute to the full path/filename of the .OOM file that was just created.  Click OK to close this dialog.

 Plug-in Properties dialog

You should immediately notice a couple of changes to the IDE:

  • The PD Object Browser pane will be populated with a set of folders, one for each PBL in the target.
  • Expanding a PBL node will display a set of subfolders:
    • Classes:  This folder contains the shortcut to the object in the PBL, including PB system classes like checkbox, radiobutton, datawindow, etc.  This is just like the PB System Tree.
    • Associations:  This list shows the relationships between any object in the PBL and any other object it references, like controls or user objects on a window.
    • Generalizations:  This folder contains an entry for every inheritance relationship, from a child to its parent.  For example, since w_about_system is a direct descendent of w_center, then in OO terms, w_about_system is a generalization of w_center.
    • Dependencies: For PB applications, Dependencies are very much like Associations, but you’ll also see “influent objects” listed here.  For example, w_add_sales_order has 6 commandbuttons and 2 datawindows, so those 8 entries are Associations.  The PB system classes “commandbutton” and “datawindow” are both “influent object dependencies”.
    • You’ll also see an entry called “ClassDiagram_1″.  This is the graphical representation of all the entries in the four folders listed above, for that specific PBL. 

You’ll also see a new menu item in the PB system tree context menu – Find in Class Diagram.  Choosing this item will open the OOM class diagram and select the class.  Double-clicking a class in the PD diagram opens the object in the corresponding PowerBuilder painter.  You now have the full depth and breadth of PowerDesigner’s Object Oriented Modeling tool at your disposal.  Attempting to define all that functionality is clearly beyond the scope of this blog post (and probably would fill a book). 

You have a full cross-reference of object classes and system classes, ancestry and descendent lineages, as well as the ability to view methods and event scripts!   However, it’s important to remember that PowerDesigner is a software MODELING tool, NOT a software DEVELOPMENT tool like PowerBuilder.  PD doesn’t allow you to compile code, check syntax, or deploy targets.  And even though the integration between the model and the code is bi-directional, it’s not automatic.  Changes made in one side are not automatically visible in the other. 

  • To move a change from the model into the code, select Language > Generate PowerBuilder… from the PD menu. 
  • To move a change from the code into the model, select Reverse Engineer… from the PB target context menu.

Let’s walk through a simple example.  We’re going to change the ancestor of a window class and generate that change into PB.  To do this in PB would require use of the Edit Source option, and a knowledge of the internal syntax of the PowerScript code that is usually hidden from the developer’s view.  In PD, it’s a simple drag and drop!

  1. In the PD browser, find the w_main class.  It lives in the pbexamfe PBL. Right-click it and select Find in Diagram…
  2. Press F7 to zoom out a bit, because you’ll need to see both w_main and w_center on the screen at the same time.  w_center is in the same PBL, so it exists in the same diagram.
  3. Select the Generalization tool from the PD toolbar (it’s the one that looks sort of like an organization chart).  Then click on w_main and drag the arrow over to drop it on w_center.  That class is now the ancestor of w_main!
  4. * An alternative method is to use the Properties dialog, as shown below.  When you first open the properties for w_main, you’ll see that the “Extends” property reads <None>.  Click the button immediately to the right of that field (Select Classifier), then select w_center in the list of window classes.  This has the same effect as dragging and dropping a Generalization link.

Class Properties dialog


To generate the code back into the PBLs, select Language > Generate PowerBuilder…  The dialog shown below is presented, which allows you to select or de-select objects.  You can also have PD save a backup copy of any changed PBLs at this time.  Since I knew that I’d only changed one object, I deselected everything except w_main.  Click OK to start the generation process.  Note: even if you only change a single object, PB will still initiate an incremental build on the target.


Generate PowerBuilder dialog


If you now open w_main in the PB editor, you’ll see that it shows as being descended from w_center.  A simple example, I know, but think of how easy this would make the process of adding a “corporate” layer between the existing framework layers in a PFC-based application!   You’d create new empty classes with the PFD_ prefix, create a generalization from those to their corresponding PFC_ layer components, then change the PFE_ components’ ancestry by dropping their existing generalizations from the PFC_ to the PFD_ layer.   

To refactor a method or event script from one class to another, it’s as simple as dragging and dropping the operation definition from one classes’ Operations folder to another.  That single step brings over the method signature, the parameters, as well as all the PowerScript!  Once all the refactoring work is done and tested on the “Classic” side, the migration to PB12.Net and the Visual Studio Isolated Shell will proceed much more smoothly.


In summary, PowerDesigner and the PD Plug-in for PowerBuilder can be a fantastic addition to your PB tools arsenal, especially if you’re considering a migration to PB12.Net.



Read the original blog entry...

More Stories By Paul Horan

Paul Horan is a Senior Solution Advisor and Mobility Architect at SAP, and works with the SAP Mobile Platform and SAP Mobile Secure product lines. Paul joined SAP as part of their acquisition of Sybase in June, 2010. Prior to that, Paul worked for Sybase as a technical pre-sales architect supporting PowerBuilder, PowerDesigner, and SQL Anywhere. Paul works out of SAP's Reston VA office. A 1984 graduate of Indiana University, Paul currently resides in Arlington VA.

Latest Stories
SUSE is a German-based, multinational, open-source software company that develops and sells Linux products to business customers. Founded in 1992, it was the first company to market Linux for the enterprise. Founded in 1992, SUSE is the world's first provider of an Enterprise Linux distribution.
Intel is an American multinational corporation and technology company headquartered in Santa Clara, California, in the Silicon Valley. It is the world's second largest and second highest valued semiconductor chip maker based on revenue after being overtaken by Samsung, and is the inventor of the x86 series of microprocessors, the processors found in most personal computers (PCs). Intel supplies processors for computer system manufacturers such as Apple, Lenovo, HP, and Dell. Intel also manufactu...
Artifex Software began 25-years ago with Ghostscript, a page description language (PDL) interpreter software prevalent in printing and related applications requiring rendering and/or conversion from one software language to another. Founded by renowned computer scientist Dr. L. Peter Deutsch, our company has thrived on the basis of our sharp focus on this area of expertise, a zealous commitment to quality and a strong customer service orientation. Over 100 OEM partners representing some of th...
Moving to Azure is the path to digital transformation, but not every journey is effective. Organizations that start with a cohesive, well-planned migration strategy can avoid common mistakes and stay a step ahead of the competition. Learn from Atmosera CEO, Jon Thomsen about the opportunities and challenges found in three pivotal phases of the journey to the cloud: Evaluation and Architecting, Migration and Management, and Optimization & Innovation. In each phase, there are distinct insights tha...
FinTech is a disruptive innovation that denotes the adoption of technologies that have changed how traditional financial services work. While FinTech is now embedded deeply into the financial services ecosystem, the rise of digital age has paved way to FinTech 2.0 - which is rolling out innovative solutions through emerging technologies at a disruptive pace while maintaining the tenets of security and compliances. Blockchain as a technology has started seeing pilot adoption in FinTech around ...
Now is the time for a truly global DX event, to bring together the leading minds from the technology world in a conversation about Digital Transformation. DX encompasses the continuing technology revolution, and is addressing society's most important issues throughout the entire $78 trillion 21st-century global economy. DXWorldEXPO® has organized these issues along 10 tracks, 22 keynotes and general sessions, and a faculty of 222 of the world's top speakers.
In an age of borderless networks, security for the cloud and security for the corporate network can no longer be separated. Security teams are now presented with the challenge of monitoring and controlling access to these cloud environments, as they represent yet another frontier for cyber-attacks. Complete visibility has never been more important-or more difficult. Powered by AI, Darktrace's Enterprise Immune System technology is the only solution to offer real-time visibility and insight into ...
Alan Hase is Vice President of Engineering and Chief Development Officer at Big Switch. Alan has more than 20 years of experience in the networking industry and leading global engineering teams which have delivered industry leading innovation in high end routing, security, fabric and wireless technologies. Alan joined Big Switch from Extreme Networks where he was responsible for product strategy for its secure campus switching, intelligent mobility and campus orchestration products. Prior to Ext...
At CloudEXPO Silicon Valley, June 24-26, 2019, Digital Transformation (DX) is a major focus with expanded DevOpsSUMMIT and FinTechEXPO programs within the DXWorldEXPO agenda. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive over the long term. A total of 88% of Fortune 500 companies from a generation ago are now out of business. Only 12% still survive. Similar percentages are found throug...
Blockchain has shifted from hype to reality across many industries including Financial Services, Supply Chain, Retail, Healthcare and Government. While traditional tech and crypto organizations are generally male dominated, women have embraced blockchain technology from its inception. This is no more evident than at companies where women occupy many of the blockchain roles and leadership positions. Join this panel to hear three women in blockchain share their experience and their POV on the futu...
92% of enterprises are using the public cloud today. As a result, simply being in the cloud is no longer enough to remain competitive. The benefit of reduced costs has normalized while the market forces are demanding more innovation at faster release cycles. Enter Cloud Native! Cloud Native enables a microservices driven architecture. The shift from monolithic to microservices yields a lot of benefits - but if not done right - can quickly outweigh the benefits. The effort required in monitoring,...
Financial enterprises in New York City, London, Singapore, and other world financial capitals are embracing a new generation of smart, automated FinTech that eliminates many cumbersome, slow, and expensive intermediate processes from their businesses. Accordingly, attendees at the upcoming 23rd CloudEXPO, June 24-26, 2019 at Santa Clara Convention Center in Santa Clara, CA will find fresh new content in full new FinTech & Enterprise Blockchain track.
The dream is universal: heuristic driven, global business operations without interruption so that nobody has to wake up at 4am to solve a problem. Building upon Nutanix Acropolis software defined storage, virtualization, and networking platform, Mark will demonstrate business lifecycle automation with freedom of choice and consumption models. Hybrid cloud applications and operations are controllable by the Nutanix Prism control plane with Calm automation, which can weave together the following: ...
Isomorphic Software is the global leader in high-end, web-based business applications. We develop, market, and support the SmartClient & Smart GWT HTML5/Ajax platform, combining the productivity and performance of traditional desktop software with the simplicity and reach of the open web. With staff in 10 timezones, Isomorphic provides a global network of services related to our technology, with offerings ranging from turnkey application development to SLA-backed enterprise support. Leadin...
As the digitization of business accelerates the move of critical applications and content to the cloud, the network has never been as critical to business success. Consuming everything ‘as-a-service' requires new levels of network automation, agility and security. Discover how Enterprises can take advantage of Digital Platforms, directly connecting to an extensive ecosystem of digital partners and flex their service at the click of a button.