Datamatics Ltd. UNDCP NDS32-Coding Standard forPowerBuilders-Annex-4 NDS-32

National System (NDS-32)

Coding Standards for PowerBuilder

Annex – 4

02/28/2000 /10:24 AM ver.1.0.0 Doc. Id: RNPBS softcopy : pb page : 1/9 Datamatics Ltd. UNDCP NDS32-Coding Standard forPowerBuilders-Annex-4 NDS-32

Introduction

A well-defined system needs to follow standards. The philosophy behind it is consistency, ease of remembrance and maintenance. The following sections state the programming standards for the GUI tool PowerBuilder 6.0 and RDBMS ORACLE.

Standards for programming in PowerBuilder

Naming Conventions

An application consists of various components such as windows, menus, listboxes, commandbuttons, and their associated scripts.

The following naming convention will be followed for the above to facilitate quick understanding of the source code. All names will have a two prefix and an underscore (_), followed by a string of characters that uniquely describes the particular component. The names will be in lower case, with suitable underscore separators between words and without any spaces. (The identifier names in PowerScript are case insensitive). Names will not contain any hyphens (-). To the extent possible, a name must convey the contents of the object.

The component name will not be more than 30 characters long, will not have any punctuation marks and will not start with numbers.

Application variable names

The first character of the prefix will signify the of the variable followed by the (maximum 3 characters)

Scope of variables

Scope of variable within an application First character of prefix(in small case) Local L Instance I Shared S Global G Argument A

Data types will have the following prefix

Data Type Second, third and fourth character of prefix Any A_

02/28/2000 /10:24 AM ver.1.0.0 Doc. Id: RNPBS softcopy : pb page : 2/9 Datamatics Ltd. UNDCP NDS32-Coding Standard forPowerBuilders-Annex-4 NDS-32

Blob Bbl_ Boolean B_ Character Ch_ Date D_ DateTime Dtm_ Decimal Dc_ Double Dbl_ Integer i_ Long l_ Real r_ String s_ Time Tm_ UnsignedInteger Ui_ UnsignedLong Ul_ Enumerated e_

For constants , the same convention followed by ‘_const’ for constant will be used e.g. a local constant of type integer will be declared as ‘li_const_variablename’.

PowerBuilder Object names

PowerBuilder Objects will have the following prefix:

PowerBuilder Object type Prefix Application app_ Application Function af_ Application Structure astr_ Window w_ Window Function wf_ Window Structure wstr_ Menu Function mf_ Menu Structure mstr_ User Object Function uf_ User Object Structure Ustr_ Function f_ Function Structure Fstr_ Structure str_ Query q_ DataWindow d_ DataPipeline Pipe Project Prj_ Connection cn_ ConnectionInfo Cninfo_ ConnectObject Cno_ DataStore ds_ DynamicDescriptionArea Dda_ DynamicStagingArea Dsa_ Environment Env_

02/28/2000 /10:24 AM ver.1.0.0 Doc. Id: RNPBS softcopy : pb page : 3/9 Datamatics Ltd. UNDCP NDS32-Coding Standard forPowerBuilders-Annex-4 NDS-32

PowerBuilder Object type Prefix Error Err_ NonVisualObject nv_ WindowObject Wo_ Transaction Tr Proxy prox_

PowerBuilder Control names

PowerBuilder Controls will have the following prefix:

PowerBuilder Control type Prefix Checkbox cbx_ Commandbutton cb_ Computed Field Cf_ Computed column Co_ DataWindow dw_ DropDownListBox ddlb_ DropDownPictureListBbox ddplb_ DropDownDataWindow dddw_ Graph gr_ Horizontal Scrollbar hsb_ Line ln_ Listbox lb_ ListView lv_ Multi Line Edit mle_ OLE 2.0 ole_ Picture p_ Picturebutton pb_ Picture Listbox plb_ Radiobutton rb_ Rectangle rec_ Rich Text Edit rte_ RoundRectangle rrec_ Single Line Edit sle_ Static Text st_ Tab tab_ Tree View tv_ User Object uo_ Vertical Scrollbar vsb_ DataWindowChild dwc_ DragObject drg_ DrawObject drw_ DatawindowObject dwo_ EditMask em_ ExternalObject ext_

02/28/2000 /10:24 AM ver.1.0.0 Doc. Id: RNPBS softcopy : pb page : 4/9 Datamatics Ltd. UNDCP NDS32-Coding Standard forPowerBuilders-Annex-4 NDS-32

PowerBuilder Control type Prefix GraphicObject go_ GraphAxis grax_ GraphDisplayAttribute grda_ GroupBox gb_ ListViewItem lvi_ MultipleDocumentInterfaceClient mdi_ Menu m_ MenuCascade mc_ Message msg_ MultiLineEdit mle_ ObjectLinkingEmbeddingControl oc_ ObjectLinkingEmbeddingObject oo_ ObjectLinkingEmbeddingStorage ostg_ Oval oval_ Pipeline Pl PowerObject po_ Rectangle rec_ RichTextEditObject rteo_ TabPage tabpg_ TreeViewItem tvi_ UserEvent ue_

Application level constant names

Constants defined at the application level will follow the same conventions, which are defined for the variables. Application level constants will be defined in upper case.

02/28/2000 /10:24 AM ver.1.0.0 Doc. Id: RNPBS softcopy : pb page : 5/9 Datamatics Ltd. UNDCP NDS32-Coding Standard forPowerBuilders-Annex-4 NDS-32

Programming Conventions

It is essential to establish a set of programming conventions to ensure the use of good and consistent coding techniques across projects. Conventions can greatly enhance the quality of scripts, make them more readable and above all ensure that they are easy to maintain and reuse.

Following are the guidelines for programming conventions to be followed in Power Builder code:

The source code will be in mixed case and the conventions stated below will be followed for case of code. Names of user-defined functions, events, and variables will be in lower case. • Power Script statement keywords like IF, THEN, FOR, DO, CHOOSE will be in uppercase . • All the PowerBuilder function calls will be in Hungarian Notation. example: integer li_fetched_count = 0

SELECT Count("order_header"."order_id" ) INTO :li_fetched_count FROM "order_header" WHERE "order_cust_id" = :ai_custid USING sqlca;

IF gtr_undcp.SQLCode = -1 THEN li_fetched_count = -1

RETURN li_fetched_count

I. Local variables will be declared at the beginning of the script.

example:

decimal ldc_balance, ldc_grandtotal_price string ls_highlight_format, ls_regular_format

A. A variable name will indicate the scope, type and purpose of the variable. B. Use of global variables will be limited to the minimum. As far as possible local and instance variables will be used. C. When referring to objects or controls, PowerScript pronouns (such as This, Parent, and ParentWindow) will be used whenever possible instead of using the actual object or control names explicitly. D. For example, for coding the Clicked event script for the cb_close CommandButton in the w_maintaincurrentaccount window

02/28/2000 /10:24 AM ver.1.0.0 Doc. Id: RNPBS softcopy : pb page : 6/9 Datamatics Ltd. UNDCP NDS32-Coding Standard forPowerBuilders-Annex-4 NDS-32

Close (parent)

Will be used instead of

Close (w_maintaincurrentaccount)

This helps in making the script code more reusable because it will not be attached to particular objects and controls.

II. All operators in expressions will have at least one preceding and succeeding white space e.g. A + B, A / B - C, A > B

III. Use of ‘Any’ data types will be avoided as far as possible, as these variables are slow at runtime and compilation errors are not tracked for them.

IV. As calling functions and events dynamically open up the application to potential errors, they will be avoided as much as possible.

V. Following standard errors will be tracked at all places in all components: E. Network connection errors F. Database access errors G. Data entry errors

VI. Every complex database transaction involving a series of related insert and / or update statements will be processed as a single transaction, i.e. it must be preceded by an explicit begin transaction statement. All transaction operations must be committed on successful completion using the commit transaction statement. All transaction operations will be rolled back, in case of errors, using the rollback statement.

VII. Comments will be used wherever required.

Inline Documentation

Inline documentation increases the ease of maintenance of the application. Suitable comments describing functional aspects of the function will be provided.

Event routine / User defined function source code

Each event routine, user defined function will have a descriptor header consisting of the following:

• Name of the event routine / user defined function • Description of the event routine / user defined function • Arguments list • Return values list • Creation date • Author

02/28/2000 /10:24 AM ver.1.0.0 Doc. Id: RNPBS softcopy : pb page : 7/9 Datamatics Ltd. UNDCP NDS32-Coding Standard forPowerBuilders-Annex-4 NDS-32

• Modification history consisting of modifier, modification date and modification details

A sample description header for an event is as follows:

////////////////////////////////////////////////////////////////////////////// // //Event Name : ue_copydata // // Arguments : None // // Returns : None // //Description : Calls the user object function uf_copydata // // Author : userid // // Version : 1.0 Initial version dated : 13 - Dec - 1998 // ////////////////////////////////////////////////////////////////////////////// // //Revision History // // dd-mon-yyyy Author : userid Description : // //////////////////////////////////////////////////////////////////////////////

A sample description header for a function is as follows:

////////////////////////////////////////////////////////////////////////////// // //Function Name : uf_xxxx // // Arguments : None // // Returns : None // //Description : Copies selected rows from the source datawindow to the // destination datawindow // // Author : userid // // Version : 1.0 Initial version dated : 13 - Dec - 1998 // ////////////////////////////////////////////////////////////////////////////// // //Revision History // // dd-mon-yyyy Author : userid Description : //

02/28/2000 /10:24 AM ver.1.0.0 Doc. Id: RNPBS softcopy : pb page : 8/9 Datamatics Ltd. UNDCP NDS32-Coding Standard forPowerBuilders-Annex-4 NDS-32

//////////////////////////////////////////////////////////////////////////////

Comments

Complex logic in the code will be preceded by an explanatory comment. The convention of using double slash i.e. // will be followed.

Indentation

Appropriate indentation (through the use of tabs) improves the readability of complex statements. This is especially helpful with complex statements listed below. Only tabs will be used for indenting the script. Tab stop will be set to 4 by default for indentation.

PowerScript statements that will have proper indentation:

• CHOOSE CASE • DO...LOOP • FOR...NEXT • IF...THEN

The template for indentation is as follows:

IF THEN statement 1 statement 2 ELSE statement 3 statement 4 END IF example:

IF ldwis_itemprod = DataModified! OR & ldwis_itemprod = NewModified! OR & ldwis_itemqty = DataModified! OR & ldwis_itemqty = NewModified! THEN lb_itemchange = true

/* Exit from the loop as soon as a changed row is found. */

EXIT

ELSE lb_itemchange = false END IF --- XXX ---

02/28/2000 /10:24 AM ver.1.0.0 Doc. Id: RNPBS softcopy : pb page : 9/9