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
"There's plenty of bandwidth out there but it's never in the right place. So what Cedexis does is uses data to work out the best pathways to get data from the origin to the person who wants to get it," explained Simon Jones, Evangelist and Head of Marketing at Cedexis, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
Digital Transformation and Disruption, Amazon Style - What You Can Learn. Chris Kocher is a co-founder of Grey Heron, a management and strategic marketing consulting firm. He has 25+ years in both strategic and hands-on operating experience helping executives and investors build revenues and shareholder value. He has consulted with over 130 companies on innovating with new business models, product strategies and monetization. Chris has held management positions at HP and Symantec in addition to ...
Enterprises have taken advantage of IoT to achieve important revenue and cost advantages. What is less apparent is how incumbent enterprises operating at scale have, following success with IoT, built analytic, operations management and software development capabilities - ranging from autonomous vehicles to manageable robotics installations. They have embraced these capabilities as if they were Silicon Valley startups.
In their session at @ThingsExpo, Shyam Varan Nath, Principal Architect at GE, and Ibrahim Gokcen, who leads GE's advanced IoT analytics, focused on the Internet of Things / Industrial Internet and how to make it operational for business end-users. Learn about the challenges posed by machine and sensor data and how to marry it with enterprise data. They also discussed the tips and tricks to provide the Industrial Internet as an end-user consumable service using Big Data Analytics and Industrial C...
René Bostic is the Technical VP of the IBM Cloud Unit in North America. Enjoying her career with IBM during the modern millennial technological era, she is an expert in cloud computing, DevOps and emerging cloud technologies such as Blockchain. Her strengths and core competencies include a proven record of accomplishments in consensus building at all levels to assess, plan, and implement enterprise and cloud computing solutions. René is a member of the Society of Women Engineers (SWE) and a m...
When talking IoT we often focus on the devices, the sensors, the hardware itself. The new smart appliances, the new smart or self-driving cars (which are amalgamations of many ‘things'). When we are looking at the world of IoT, we should take a step back, look at the big picture. What value are these devices providing. IoT is not about the devices, its about the data consumed and generated. The devices are tools, mechanisms, conduits. This paper discusses the considerations when dealing with the...
DXWordEXPO New York 2018, colocated with CloudEXPO New York 2018 will be held November 11-13, 2018, in New York City. Digital Transformation (DX) is a major focus with the introduction of DXWorldEXPO within the program. 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.
To Really Work for Enterprises, MultiCloud Adoption Requires Far Better and Inclusive Cloud Monitoring and Cost Management … But How? Overwhelmingly, even as enterprises have adopted cloud computing and are expanding to multi-cloud computing, IT leaders remain concerned about how to monitor, manage and control costs across hybrid and multi-cloud deployments. It’s clear that traditional IT monitoring and management approaches, designed after all for on-premises data centers, are falling short in ...
With privacy often voiced as the primary concern when using cloud based services, SyncriBox was designed to ensure that the software remains completely under the customer's control. Having both the source and destination files remain under the user?s control, there are no privacy or security issues. Since files are synchronized using Syncrify Server, no third party ever sees these files.
Mobile device usage has increased exponentially during the past several years, as consumers rely on handhelds for everything from news and weather to banking and purchases. What can we expect in the next few years? The way in which we interact with our devices will fundamentally change, as businesses leverage Artificial Intelligence. We already see this taking shape as businesses leverage AI for cost savings and customer responsiveness. This trend will continue, as AI is used for more sophistica...
"We are an integrator of carrier ethernet and bandwidth to get people to connect to the cloud, to the SaaS providers, and the IaaS providers all on ethernet," explained Paul Mako, CEO & CTO of Massive Networks, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
I believe that this may finally be the year that the CIO role ‘crosses the Rubicon,' leaving behind its traditional, IT-focused orientation. But I don't believe that either of the previous predictions of this outcome — fading into oblivion or rising to a business executive level — is correct. Instead, I think this is the year that we will see the role of the CIO transformed into something altogether different.
Cloud-enabled transformation has evolved from cost saving measure to business innovation strategy -- one that combines the cloud with cognitive capabilities to drive market disruption. Learn how you can achieve the insight and agility you need to gain a competitive advantage. Industry-acclaimed CTO and cloud expert, Shankar Kalyana presents. Only the most exceptional IBMers are appointed with the rare distinction of IBM Fellow, the highest technical honor in the company. Shankar has also receive...
"Calligo is a cloud service provider with data privacy at the heart of what we do. We are a typical Infrastructure as a Service cloud provider but it's been designed around data privacy," explained Julian Box, CEO and co-founder of Calligo, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.
"NetApp is known as a data management leader but we do a lot more than just data management on-prem with the data centers of our customers. We're also big in the hybrid cloud," explained Wes Talbert, Principal Architect at NetApp, in this SYS-CON.tv interview at 21st Cloud Expo, held Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA.