Comments
rock333 wrote: At the IaaS Cloud layer virtualisation is going to be essential to allow the self service attributes, all painful and slow to do with physical hardware. Moving up the stack to PaaS and SaaS the use of virtualisation may, as you say, be less required if you put lots of smarts into your software. A lot of software does not have those smarts and by utalising virtualisation of the layers below can manipulate existing software architectures to have more cloudy attributes through automation (eg run load balancers and deploy more servers automagically). Over time, as new investment in software at...
Cloud Expo on Google News


2008 West
DIAMOND SPONSOR:
Data Direct
SOA, WOA and Cloud Computing: The New Frontier for Data Services
PLATINUM SPONSORS:
Red Hat
The Opening of Virtualization
GOLD SPONSORS:
Appsense
User Environment Management – The Third Layer of the Desktop
Cordys
Cloud Computing for Business Agility
EMC
CMIS: A Multi-Vendor Proposal for a Service-Based Content Management Interoperability Standard
Freedom OSS
Practical SOA” Max Yankelevich
Intel
Architecting an Enterprise Service Router (ESR) – A Cost-Effective Way to Scale SOA Across the Enterprise
Sensedia
Return on Assests: Bringing Visibility to your SOA Strategy
Symantec
Managing Hybrid Endpoint Environments
VMWare
Game-Changing Technology for Enterprise Clouds and Applications
Click For 2008 West
Event Webcasts

2008 West
PLATINUM SPONSORS:
Appcelerator
Get ‘Rich’ Quick: Rapid Prototyping for RIA with ZERO Server Code
Keynote Systems
Designing for and Managing Performance in the New Frontier of Rich Internet Applications
GOLD SPONSORS:
ICEsoft
How Can AJAX Improve Homeland Security?
Isomorphic
Beyond Widgets: What a RIA Platform Should Offer
Oracle
REAs: Rich Enterprise Applications
Click For 2008 Event Webcasts
SYS-CON.TV
Top Links You Must Click On


Exploring DataWindow Display Formats
Getting more than simple data formatting from display formats

DataWindow display formats aren't a big secret. Most PowerBuilder developers use them to format numeric, date, time, and string values properly. Such display formats are usually straightforward and contain characters that have special meaning for a specific datatype like '#' for numeric values or '@' for string values. However, the DataWindow display format is a very powerful tool and you can get more than simple data formatting. This article explores what you can do with DataWindow display formats demonstrating a few tricks.

Using Regular Characters
A DataWindow display format can contain the usual characters along with characters that have special meaning. For example, brackets and hyphens can be used in a display format for a string value containing a phone number to separate the city code and group the rest digits: if the number is 4951234567 then the format '(@@@) @@@-@@-@@' gives more readable results as shown in the Figure 1.

An interesting thing is that the whole display format string (the display format is a string, isn't it?) can contain only regular characters. In this case, the display format string is displayed itself instead of data. For example, if you specify qwerty as the display format for a string column, you get the result shown in Figure 2.

It may seem useless unless you build the display format string dynamically using a DataWindow expression for the Format DataWindow object property.

Embellishing Special Values
Let's demonstrate building a display format string. Let's assume that we use two date values with special meaning: NULL in the value means that the user didn't enter any value, and 11/11/1111 means that the date is unknown. We don't want the field to be empty in the case of NULL values and we don't want to show our special date value for unknown dates; we want our field display 'Empty' instead of NULL and 'Unknown' instead of 11/11/1111. For all other values we want to use the [shortdate] keyword that formats the value according to the regional settings for date defined in Windows. To do so, we use the following expression for the Format DataWindow column property:

if(string( date_val, 'dd.mm.yyyy') = '11.11.1111', '\U\n\k\n\o\w\n', '[shortdate];\E\m\p\t\y' )

The result is shown in Figure 3.

Two things are worth mentioning in this example. First, note the use of backslashes before each character in the format strings. It guarantees a more robust result because the backslash tells PowerBuilder not to try to interpret the display format but simply display the characters as they are. Second, note that the expression for the display format for a column refers to the value of the column. This is a very powerful technique, and it will be explored further in this article.

Decoding Values
A very similar approach can be used for decoding values such as codes from a lookup table using the display format. If we have a short lookup table, like the one shown in Figure 4, we can decode the codes using the following expression for the Format DataWindow column property:

case( color when 1 then 'Red' when 2 then 'Green' when 3 then 'Blue' else 'Unknown' )

The result is shown in Figure 5.

As you noticed, the result is pretty much the same as using the Code Table for the Edit DataWindow column type. However, sometimes this property can't be used unlike display formats that can. We'll come back to decoding values a bit later.

Sorting Values
You may wonder how display formats can be connected with sorting. No, you can't sort data using display formats. However, you can use them for your benefit when you don't want to show the real data used for sorting. A classic example is a list of names of the months sorted in alphabetical order. The result is shown in Figure 6.

The problem can be easily solved if the number of the month is used in the data. In this case the columns are sorted properly as shown in Figure 7.

But we don't want the month numbers to be displayed. To hide them, the following expression can be used for the Format DataWindow column property: mid( month, 3). The result is shown in Figure 8.

Note how part of the data value is used as the display format string. Using string values in display formats displayed as they are doesn't look useless as it did in the example with the "qwerty" string, does it?

Decoding Lists of Values
In the end I'd like to demonstrate what DataWindow display formats are capable of in the CrossTab DataWindow. Let's imagine that we have a CrossTab with names of months as row headers and laboratory names as column headers. For each pair we may have several records in a database with a unique color for the pair as shown in Figure 9, and the list of possible colors is rather short.

We'd like to display a list of colors on the intersection of a month and a laboratory, e.g., it would be 'Red Green Blue' for January, Lab 1, just 'Blue' for February, Lab 1, then 'Red Green' for January, Lab 2, and so on. One of the possible ways to do this is by using the DataWindow column display format.

We have to code the colors in such a way that each code could be detected in the sum (on the condition that the sum can contain only unique codes, that is the same code can't be added more than one time). For purposes of illustration it's enough to make each color occupy a certain decimal position in the code. The same lookup table with the changed codes is shown in Figure 10.

As you can see, if we sum up the codes, the rightmost one will tell us if the red color is here, the next one will tells us about green, and the leftmost tells about blue. Now we can build our CrossTab DataWindow. The result is shown in Figure 11.

Note the months. They are formatted as I described earlier. Now, we need to decode the lists of colors in each cell. We can do so with the following expression for the Format DataWindow column property:

if( mid( string( color_code, '000'), 3, 1) = '1', 'Red ', '' ) +
if( mid( string( color_code, '000'), 2, 1) = '1', 'Green ', '' ) +
if( mid( string( color_code, '000'), 1, 1) = '1', 'Blue', '' )

The final result is shown in Figure 12.

Conclusion
This article demonstrated several unusual applications of the DataWindow display format. It showed that by using dynamically built strings as the DataWindow column display format, you can get more than simple data formatting from display formats. It happens that everyday routine can make a PowerBuilder programmer forget that PowerBuilder is a powerful tool, and I hope this article will encourage such programmers to cast a fresh glance even on very basic possibilities of PowerBuilder such as the DataWindow display format.

About Konstantin Goldobin
Konstantin Goldobin is a senior developer living in Voronezh, Russia. He has been working with PowerBuilder since 1995 version 4.0. Visit his web site at www.vsi.ru/~kgold.

In order to post a comment you need to be registered and logged in.

Register | Sign-in

Reader Feedback: Page 1 of 1

Enterprise Open Source Magazine Latest Stories . . .
Integrated Windows Authentication (IWA) provides a user-friendly interface for single sign-on. IWA uses ‘Simple and Protected GSSAPI Negotiation Mechanism’ (SPNEGO) to allow the initiators and acceptors to negotiate the underlying protocol to be used for authentication. In this article...
Preternaturally quiet since a hedge fund offered to buy it two weeks ago and take it private, Novell stated on Wednesday that the open source Ingres database is available in the free SUSE Studio as part of the SUSE Appliance Program. Novell and Ingres are supposed to jointly support an...
Cloud Computing Journal caught up with the CEO of a major new player in the fast-emerging Cloud ecosystem - a CEO who has taken an interesting and unusual decision. While signing up as the Platinum Plus Sponsor of the 5th International Cloud Expo, he and his company have decided to rem...
Open-Xchange, a provider of business-class open source collaboration software, today announced enhancements that give users telephone and fax integrated with e-mail, contacts, calendar and task information. By combining Open-Xchange (hosted and on-premise editions) with Unified Commun...
Home Energy monitoring products maker People Power has come out with an open source hardware and software application developer kit called SuRF that lets embedded systems developers build energy saving apps for household electronics and devices on top of its Open Source Home Area Netwo...
Novell and Ingres Corporation on Wednesday announced the Ingres database is available within SUSE Studio as part of the SUSE Appliance Program. Both companies have entered into a cooperative agreement to make it easier and more cost-effective for independent software vendors (ISVs) and...
Subscribe to the World's Most Powerful Newsletters
Subscribe to Our Rss Feeds & Get Your SYS-CON News Live!
Click to Add our RSS Feeds to the Service of Your Choice:
Google Reader or Homepage Add to My Yahoo! Subscribe with Bloglines Subscribe in NewsGator Online
myFeedster Add to My AOL Subscribe in Rojo Add 'Hugg' to Newsburst from CNET News.com Kinja Digest View Additional SYS-CON Feeds
Publish Your Article! Please send it to editorial(at)sys-con.com!

Advertise on this site! Contact advertising(at)sys-con.com! 201 802-3021


SYS-CON Featured Whitepapers
ADS BY GOOGLE