SlideShare una empresa de Scribd logo
1 de 5
Descargar para leer sin conexión
PBDJ APRIL 2012 | POWERBUILDER.SYS-CON.COM
PAGE 24
Tips & tricks
I
n data entry type applications there can be a need
for users to customize the data entry windows
in some way. This is especially true for packaged
software that goes to a variety of companies and in-
dustries where rules and requirements for the same
type of data can be very different. Properties such
as what is a required field, initial values, edit masks
can vary for each installation. This article describes
some of the methods that can be used to create uni-
fied customizable data entry DataWindows, specifi-
cally for the input of new records.
	 Usually entering new data for an account, contact
or part requires a certain minimum set of informa-
tion consisting of either application required fields
and user required and recommended fields. This
could be a small set out of a large number of fields.
Creating a runtime generated custom data input Da-
taWindow makes entering new data much easier for
the user as they are presented with only the data that
needs to be input for a new entity of some sort rather
than sifting through a large number of optional fields
that could exist on multiple windows. The DataWin-
dow control allows for this type of flexibility.
Issues
	 There are some considerations when merging
input fields from different DataWindows: (for this ar-
ticle it is assumed the data is sourced from database
tables):
1.	Datatype.
2.	Input type: simple free input, dropdown list,
calendar or child DataWindow, checkbox.
3.	Initial values associated with the field.
4.	Editmask associated with the field.
Example
	 In the example used for this article is a contact
application with five different edit windows avail-
able for different aspects of contact information as
seen in Figure 1.
Generating Dynamic Input DataWindows
By buck wooLley
DataWindow Consolidation
Tips & tricks
PBDJ april 2012 | POWERBUILDER.SYS-CON.COM
PAGE 26
	 Each DataWindow contains input fields that are re-
quired by the application or can be set to either required
or recommended by the user (see Figure 2).
	 Each of these windows contais one or two DataWindows
for data entry and editing.The new record input screen
is created be deconstructing each of these individual Da-
taWindows, removing each field that has been marked as
required or recommended and at runtime creating a new
DataWindow containing only these fields with their associ-
ated properties (see Figure 3).
Creating the Input DataWindow
	 Some of the properties such as column name, label text
and edit style are part of the DataWindow, others such as
initial values, edit mask and required flags are user definable
and are stored in tables for each DataWindow and are based
on the DataWindow and column name.
	 The new input DataWindow to be created as an external
DataWindow.The base DataWindow syntax is stored as an
instance variable with position holders for the tables and
column section of the DataWindow.These are marked by
the strings‘*tables*’ and‘*columns*’.These strings can be
replaced later by syntax that will be generated in two vari-
ables called ls_dw_tables and ls_dw_columns.
string idw_syntax = ‘release 10.5; datawindow(units=0 timer_inter-
val=0’....
....’detail(height=1000 color=”536870912” height.autosize=yes) ‘+&
‘table(*tables*) *columns* ‘+&
‘htmltable(border=”1” ) ‘....
	 A datastore called lds_column_list is used to select all
columns defined by the user as required or recommend. An
array containing the names of all relevant DataWindows is
the input parameter to this select.The req_flag determines
if the column is required to recommended.The SQL for this
would look something like:
select column_name, column_label, dw_object, req_flag
from recommended_fields
where dw_object in (‘d_input1’ ,‘d_input2’, ‘d_input3’ ....)
	 Figure 4 shows some of the data in lds_column_list,
specifically the column label, column name and source
DataWindow name.
	 The resulting list is sorted alphabetically by the column
label text so that the generated DataWindow displays labels
in alphabetic order.The list is looped through to gener-
ate strings that will contain the definition syntax for each
column and the create syntax for each column and label.
	 For each row in lds_column_list the DataWindow name
is loaded into a datastore object to extract its table and
display properties.
ls_dataobject = lds_column_list.object.dw_object[ll_row]
	 The DataWindow name is assigned to a datastore
dataobject called lds_work.
lds_work.dataobject = ls_dataobject
	 Now the code has reference to the syntax of the input
DataWindow. The column_name is moved from lds_col-
umn_list to the variable ls_column_name.
ls_column_name = lds_column_list.object.column_name[ll_row]
	 From this variable the information regarding proper-
ties the column is extracted from the datastore lds_work
using the describe function.
Figure 1: Five input windows for different aspects of a contact
Figure 2: Window allows user to mark an input field as mandatory or recommended
POWERBUILDER.SYS-CON.COM | PBDJ november 2011POWERBUILDER.SYS-CON.COM | PBDJ april 2012
contact
CORINNA MELCON
tel 201-802-3026
corinna@sys-con.com
REPRINTS!
ls_syntax = lds_work.describe(‘datawindow.syntax’)
	 The ls_syntax variable contains the entire syntax of lds_work
and will be used to extract the definition of the column ls_column_
name. Other properties are extracted.
ls_column = lds_work.describe(ls_column_name+’.dbname’)
ls_label = lds_work.describe(ls_column_name+’_t.text’)
ls_coltype = lds_work.describe(ls_column_name+’.coltype’)
ls_values = lds_work.describe(ls_column_name+’.values’)
ls_dddw_name = lds_work.describe(ls_column_name+’.dddw.name’)
	 Once these variables are loaded, the syntax for table section can
be generated for the column:
ls_dw_tables = ls_dw_tables+’ column=(type=’+ls_coltype+’ updatewhereclause=yes
name=’+ls_column_name+’ dbname=”’+ls_column+’” values=”’+ls_values+’”) ‘
	 The next step is to extract the Create() syntax for the column
defined in ls_column_name. There are several ways to do this. This
method first locates the name of the column in the ls_syntax string.
ll_pos = LASTPOS(ls_syntax,’name=’+ls_column_name+’ ‘)
	 If the column is found, find the start and end of the create syntax
for that column. First find the start position and store it in ll_pos1.
ll_pos1 = LASTPOS(LEFT(ls_syntax,ll_pos),’column(‘)
	 Next, find the end of the objects definition by finding the start of the
next object.To be most generic this involves finding the start of all pos-
sible objects and find the one closest to and greater than the amount in
variable ll_pos.
Figure 3: The dynamically created input DataWindow with fields from each of the five
data edit windows
PBDJ APRIL 2012 | POWERBUILDER.SYS-CON.COM
PAGE 28
Tips & tricks
ll_pos_a[1] = POS(ls_syntax,’htmltable(‘, ll_pos)
ll_pos_a[2] = POS(ls_syntax,’column(‘, ll_pos)
ll_pos_a[3] = POS(ls_syntax,’text(‘, ll_pos)
ll_pos_a[4] = POS(ls_syntax,’compute(‘, ll_pos)
ll_pos_a[5] = POS(ls_syntax,’rectangle(‘, ll_pos)
ll_pos_a[6] = POS(ls_syntax,’line(‘, ll_pos)
ll_pos_a[7] = POS(ls_syntax,’button(‘, ll_pos)
	 Loop through array ll_pos_a to find the end of the columns
syntax and store that value in ll_pos2. Using the values in ll_
pos1 and ll_pos2 extract the column definition using the MID()
function, then set the id and tabsequence for the column
which will be a sequence number variable ll_detail_id.
ll_detail_id++
	 Extract the column definition for ls_column_name.
ls_column = MID(ls_syntax,ll_pos1,ll_pos2 - ll_pos1)
	 Find the id for the column and replace it with ll_detail_id.
ll_pos = POS(ls_column,’id=’)
IF ll_pos > 0 THEN
	 ll_pos = ll_pos+3
	 ll_pos1 = POS(ls_column,’ ‘,ll_pos)
	 ls_column = REPLACE(ls_column, ll_pos, ll_pos1 - ll_pos, STRING	
(ll_detail_id)+’ ‘)
END IF
	 Find the tabsequence for the column and replace it with
ll_detail_id.
ll_pos = POS(ls_column,’tabsequence=’)
IF ll_pos > 0 THEN
	 ll_pos = ll_pos+12
	ll_pos1 = POS(ls_column,’ ‘,ll_pos)
	ls_column = REPLACE(ls_column, ll_pos, ll_pos1 - ll_pos, STRING	
(ll_detail_id)+’ ‘)
END IF
	 A definition of the column label must be created after
creating the definition for the column. The label definition
is static except for the label text and name. The label text
was extracted earlier from lds_work and the label name is
ls_column_name +’_t’.
ls_label_name = ls_column_name+’_t’
ls_dw_columns = ls_dw_columns+’ text(band=detail alignment=”0”
text=”’+ls_label+’” name=’+ls_label_name....			
	 After looping through the list of required columns the con-
tents of the variables the complete DataWindow syntax can
be made by taking the template DataWindow syntax defined
earlier in idw_syntax and doing the appropriate substitutions.
Once the syntax is made then the new data input DataWin-
dow can be created.
ll_pos = POS(ls_dwsyntax,’*tables*’)
ls_dwsyntax = REPLACE(ls_dwsyntax,ll_pos,8,ls_dw_tables)
ll_pos = POS(ls_dwsyntax,’*columns*’)
ls_dwsyntax = REPLACE(ls_dwsyntax,ll_pos,9,ls_dw_columns)
dw_step.create(ls_dwsyntax,ls_err)
	
	 The DataWindow has now been created but it still needs to
be formatted. This involves looping through the column list
again and adjusting the y values for each input field based
on the sort order. It is also at this point child DataWindows
are retrieved and initial values and edit masks are set.
ls_dwsyntax=ls_dwsyntax+’ ‘+ls_column_name+”.Initial=’”+ls_default_
Figure 4: Table containing information regarding recommended column
Figure 5: Shows the various sources of properties for the generated DataWindow
PBDJ APRIL 2012 | POWERBUILDER.SYS-CON.COM
PAGE 30
TIPS & TECHNIQUES
Advertiser Index
advertiser 	 url	 phone pG
General Conditions: The Publisher reserves the right to refuse any advertising not meeting the standards that are set to protect the high
editorial quality of PowerBuilder Developer’s Journal. All advertising is subject to approval by the Publisher.The Publisher assumes no liability
for any costs or damages incurred if for any reason the Publisher fails to publish an advertisement. In no event shall the Publisher be liable
for any costs or damages in excess of the cost of the advertisement as a result of a mistake in the advertisement or for any other reason.
The Advertiser is fully responsible for all financial liability and terms of the contract executed by the agents or agencies who are acting on
behalf of theAdvertiser.Conditions set in this document (except the rates) are subject to change by the Publisher without notice.No conditions
other than those set forth in this “General Conditions Document” shall be binding upon the Publisher.Advertisers (and their agencies) are fully
responsible for the content of their advertisements printed in PowerBuilder Developer’s Journal Advertisements are to be printed at the
discretion of the Publisher.This discretion includes the positioning of the advertisement, except for “preferred positions” described in the rate
table. Cancellations and changes to advertisements must be made in writing before the closing date. “Publisher” in this “General Conditions
Document” refers to SYS-CON Publications, Inc.This index is provided as an additional service to our readers.The publisher does not assume
any liability for errors or omissions.
Big Data Expo	 http://events.sys-con.com	 201-802-3020	 31
eLearnIT	http://www.isug.com/pbtraining		 11
PBDJournal	http://pbdj.sys-con.com/		 29
Sybase	 http://www.sybase.com/powerbuilder		 C2 & C4
Sybase	http://www.sybase.com/powerbuilder		 18-19
SYS-CON Events East	 http://events.sys-con.com	 201-802-3020	 C3
SYS-CON Events West	 http://events.sys-con.com	 201-802-3020	 17
string+”’”
ls_dwsyntax=ls_dwsyntax+’ ‘+ls_column_name+”.editmask.mask=’”+ls_mask+”’”
	 To determine if the field contains a child DataWindow, then the
following test is made:
IF ls_dddw_name <> ‘?’ THEN
	 If a child DataWindow exists, then determine if arguments ex-
ists and retrieve the DataWindow. Most of the child DataWindows
either have no argument or require a language id.
lds_work.getchild(ls_column_name,ldwc)
ldwc.settransobject(gtr_main)
ls_arguments = ldwc.describe(‘DataWindow.Table.Arguments’)
IF ls_arguments = ‘?’ THEN
	ldwc.retrieve()
ELSE
	ldwc.retrieve(ll_language_id)
END IF
	 Columns with child DataWindows with more complex arguments
are removed prior to presentation.The user must go to the appropriate
edit window to edit these columns.
	 The DataWindow dw_input is now presented to the user correctly
formatted with all recommended and required fields. Once the user has
filled in the fields then the data can be saved.
Save Process
	 The saving of a new contact is a two-step process.The first step is
inserting new records in the various tables.These new records contain
the data that is considered as required by the application. For instance
a name, country and language for a contact are considered applica-
tion requirements.This data is saved directly from a static contact
DataWindow.
	 This process establishes the new contact record and creates a key val-
ue for the new contact. Once this is done, then the data in dw_input is
applied to tables using dynamic SQL updates.This is achieved by loop-
ing through lds_column_list to get column information and extracting
the entered value for each column from the dw_input DataWindow.
	 In the save loop the first tasks is to get the DataWindow column
name for the field.
ls_column_name = lds_column_list.object.column_name[ll_row]
	 Next get the database name for the column from the original
DataWindow object which has temporarily been created in datastore
lds_work. Extract the table name from the column name.
ls_column = lds_work.describe(ls_column_name+’.dbname’)
ll_pos = POS(ls_column,’.’)
ls_table = LEFT(ls_column,ll_pos - 1)
	 Next, get the user entered data for the column from dw_input.
ls_data = STRING(dw_input.getitemstring(1, ls_column_name))
	 Use these variables to build the SQL update statement for the
column and execute it.
ls_sql = ‘Update ‘+ls_table+’ set ‘+ls_column+’=’+ls_data+’ where id=’+ls_id
EXECUTE IMMEDIATE :ls_sql USING sqlca;
	 Repeat this process for all columns in dw_input. Figure 5 shows
the relationship between the original data edit DataWindow, the user
selected recommended and required fields in lds_column_list, and the
generated new record input DataWindow dw_input. It summarizes the
process for a single column AssociateType which is defined as a recom-
mended field. It has a format of dropdown DataWindow and an initial
value of Client/Applicant.
Conclusion
	 In complex applications where there are several data edit windows,
it’s possible to dynamically create new data input windows that con-
tain only the columns that are marked as recommended or required
by the user.This process aggregates multiple input windows into one
dynamically created DataWindow eliminating the need for the user to
open and edit multiple windows while insuring that all necessary data
has been entered.
About the Author
Buck Woolley has been involved in programming and software develop- ment since
1987 and has been a Powerbuilder consultant since 1994, starting with version 3.0.
Currently he is the main client server developer at Patrix AB in Gothenberg, Sweden.
He has made numerous Techwave presentations covering advanced datawindow tech-
niques. Buck and his wife reside in San Diego, California.
bwoolley@dw-extreme.com

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

CIS 336 Final Exam 2 (Devry)
CIS 336 Final Exam 2 (Devry) CIS 336 Final Exam 2 (Devry)
CIS 336 Final Exam 2 (Devry)
 
12 SQL
12 SQL12 SQL
12 SQL
 
Sql
SqlSql
Sql
 
Learning sql from w3schools
Learning sql from w3schoolsLearning sql from w3schools
Learning sql from w3schools
 
Lab
LabLab
Lab
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
Sql basics
Sql basicsSql basics
Sql basics
 
Sql fundamentals
Sql fundamentalsSql fundamentals
Sql fundamentals
 
Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)Introduction to SQL (for Chicago Booth MBA technology club)
Introduction to SQL (for Chicago Booth MBA technology club)
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Introduction to structured query language (sql)
Introduction to structured query language (sql)Introduction to structured query language (sql)
Introduction to structured query language (sql)
 
Sql intro & ddl 1
Sql intro & ddl 1Sql intro & ddl 1
Sql intro & ddl 1
 
Dbms record
Dbms recordDbms record
Dbms record
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
dbms lab manual
dbms lab manualdbms lab manual
dbms lab manual
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Sq lite module5
Sq lite module5Sq lite module5
Sq lite module5
 
DBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) pptDBMS information in detail || Dbms (lab) ppt
DBMS information in detail || Dbms (lab) ppt
 
Les09
Les09Les09
Les09
 

Similar a Create Customizable Data Entry Windows

Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studioAravindharamanan S
 
ScenarioXYZ Corp. is a parent corporation with 2 handbag stores l.pdf
ScenarioXYZ Corp. is a parent corporation with 2 handbag stores l.pdfScenarioXYZ Corp. is a parent corporation with 2 handbag stores l.pdf
ScenarioXYZ Corp. is a parent corporation with 2 handbag stores l.pdfalokindustries1
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016Mir Mahmood
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5Mahmoud Ouf
 
Data Warehouse and Business Intelligence - Recipe 2
Data Warehouse and Business Intelligence - Recipe 2Data Warehouse and Business Intelligence - Recipe 2
Data Warehouse and Business Intelligence - Recipe 2Massimo Cenci
 
Python Programming.pptx
Python Programming.pptxPython Programming.pptx
Python Programming.pptxSudhakarVenkey
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastoreHaris Khan
 
Data Warehouse and Business Intelligence - Recipe 1
Data Warehouse and Business Intelligence - Recipe 1Data Warehouse and Business Intelligence - Recipe 1
Data Warehouse and Business Intelligence - Recipe 1Massimo Cenci
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Achmad Solichin
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operationsanujaggarwal49
 
Unit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxUnit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxPetroJoe
 

Similar a Create Customizable Data Entry Windows (20)

Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
Simple ado program by visual studio
Simple ado program by visual studioSimple ado program by visual studio
Simple ado program by visual studio
 
ScenarioXYZ Corp. is a parent corporation with 2 handbag stores l.pdf
ScenarioXYZ Corp. is a parent corporation with 2 handbag stores l.pdfScenarioXYZ Corp. is a parent corporation with 2 handbag stores l.pdf
ScenarioXYZ Corp. is a parent corporation with 2 handbag stores l.pdf
 
Fahri tugas cloud1
Fahri tugas cloud1Fahri tugas cloud1
Fahri tugas cloud1
 
New Features of SQL Server 2016
New Features of SQL Server 2016New Features of SQL Server 2016
New Features of SQL Server 2016
 
Ado.Net
Ado.NetAdo.Net
Ado.Net
 
Intake 38 data access 5
Intake 38 data access 5Intake 38 data access 5
Intake 38 data access 5
 
Intake 37 linq3
Intake 37 linq3Intake 37 linq3
Intake 37 linq3
 
Data Warehouse and Business Intelligence - Recipe 2
Data Warehouse and Business Intelligence - Recipe 2Data Warehouse and Business Intelligence - Recipe 2
Data Warehouse and Business Intelligence - Recipe 2
 
Python Programming.pptx
Python Programming.pptxPython Programming.pptx
Python Programming.pptx
 
Intake 37 ef2
Intake 37 ef2Intake 37 ef2
Intake 37 ef2
 
Mongo db basics
Mongo db basicsMongo db basics
Mongo db basics
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastore
 
Databases with SQLite3.pdf
Databases with SQLite3.pdfDatabases with SQLite3.pdf
Databases with SQLite3.pdf
 
Data Warehouse and Business Intelligence - Recipe 1
Data Warehouse and Business Intelligence - Recipe 1Data Warehouse and Business Intelligence - Recipe 1
Data Warehouse and Business Intelligence - Recipe 1
 
ABAP Cheat sheet
ABAP Cheat sheetABAP Cheat sheet
ABAP Cheat sheet
 
Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)Les09 (using ddl statements to create and manage tables)
Les09 (using ddl statements to create and manage tables)
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD OperationsMongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
 
Unit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptxUnit 2 Chap 4 SQL DDL.pptx
Unit 2 Chap 4 SQL DDL.pptx
 

Create Customizable Data Entry Windows

  • 1. PBDJ APRIL 2012 | POWERBUILDER.SYS-CON.COM PAGE 24 Tips & tricks I n data entry type applications there can be a need for users to customize the data entry windows in some way. This is especially true for packaged software that goes to a variety of companies and in- dustries where rules and requirements for the same type of data can be very different. Properties such as what is a required field, initial values, edit masks can vary for each installation. This article describes some of the methods that can be used to create uni- fied customizable data entry DataWindows, specifi- cally for the input of new records. Usually entering new data for an account, contact or part requires a certain minimum set of informa- tion consisting of either application required fields and user required and recommended fields. This could be a small set out of a large number of fields. Creating a runtime generated custom data input Da- taWindow makes entering new data much easier for the user as they are presented with only the data that needs to be input for a new entity of some sort rather than sifting through a large number of optional fields that could exist on multiple windows. The DataWin- dow control allows for this type of flexibility. Issues There are some considerations when merging input fields from different DataWindows: (for this ar- ticle it is assumed the data is sourced from database tables): 1. Datatype. 2. Input type: simple free input, dropdown list, calendar or child DataWindow, checkbox. 3. Initial values associated with the field. 4. Editmask associated with the field. Example In the example used for this article is a contact application with five different edit windows avail- able for different aspects of contact information as seen in Figure 1. Generating Dynamic Input DataWindows By buck wooLley DataWindow Consolidation
  • 2. Tips & tricks PBDJ april 2012 | POWERBUILDER.SYS-CON.COM PAGE 26 Each DataWindow contains input fields that are re- quired by the application or can be set to either required or recommended by the user (see Figure 2). Each of these windows contais one or two DataWindows for data entry and editing.The new record input screen is created be deconstructing each of these individual Da- taWindows, removing each field that has been marked as required or recommended and at runtime creating a new DataWindow containing only these fields with their associ- ated properties (see Figure 3). Creating the Input DataWindow Some of the properties such as column name, label text and edit style are part of the DataWindow, others such as initial values, edit mask and required flags are user definable and are stored in tables for each DataWindow and are based on the DataWindow and column name. The new input DataWindow to be created as an external DataWindow.The base DataWindow syntax is stored as an instance variable with position holders for the tables and column section of the DataWindow.These are marked by the strings‘*tables*’ and‘*columns*’.These strings can be replaced later by syntax that will be generated in two vari- ables called ls_dw_tables and ls_dw_columns. string idw_syntax = ‘release 10.5; datawindow(units=0 timer_inter- val=0’.... ....’detail(height=1000 color=”536870912” height.autosize=yes) ‘+& ‘table(*tables*) *columns* ‘+& ‘htmltable(border=”1” ) ‘.... A datastore called lds_column_list is used to select all columns defined by the user as required or recommend. An array containing the names of all relevant DataWindows is the input parameter to this select.The req_flag determines if the column is required to recommended.The SQL for this would look something like: select column_name, column_label, dw_object, req_flag from recommended_fields where dw_object in (‘d_input1’ ,‘d_input2’, ‘d_input3’ ....) Figure 4 shows some of the data in lds_column_list, specifically the column label, column name and source DataWindow name. The resulting list is sorted alphabetically by the column label text so that the generated DataWindow displays labels in alphabetic order.The list is looped through to gener- ate strings that will contain the definition syntax for each column and the create syntax for each column and label. For each row in lds_column_list the DataWindow name is loaded into a datastore object to extract its table and display properties. ls_dataobject = lds_column_list.object.dw_object[ll_row] The DataWindow name is assigned to a datastore dataobject called lds_work. lds_work.dataobject = ls_dataobject Now the code has reference to the syntax of the input DataWindow. The column_name is moved from lds_col- umn_list to the variable ls_column_name. ls_column_name = lds_column_list.object.column_name[ll_row] From this variable the information regarding proper- ties the column is extracted from the datastore lds_work using the describe function. Figure 1: Five input windows for different aspects of a contact Figure 2: Window allows user to mark an input field as mandatory or recommended
  • 3. POWERBUILDER.SYS-CON.COM | PBDJ november 2011POWERBUILDER.SYS-CON.COM | PBDJ april 2012 contact CORINNA MELCON tel 201-802-3026 corinna@sys-con.com REPRINTS! ls_syntax = lds_work.describe(‘datawindow.syntax’) The ls_syntax variable contains the entire syntax of lds_work and will be used to extract the definition of the column ls_column_ name. Other properties are extracted. ls_column = lds_work.describe(ls_column_name+’.dbname’) ls_label = lds_work.describe(ls_column_name+’_t.text’) ls_coltype = lds_work.describe(ls_column_name+’.coltype’) ls_values = lds_work.describe(ls_column_name+’.values’) ls_dddw_name = lds_work.describe(ls_column_name+’.dddw.name’) Once these variables are loaded, the syntax for table section can be generated for the column: ls_dw_tables = ls_dw_tables+’ column=(type=’+ls_coltype+’ updatewhereclause=yes name=’+ls_column_name+’ dbname=”’+ls_column+’” values=”’+ls_values+’”) ‘ The next step is to extract the Create() syntax for the column defined in ls_column_name. There are several ways to do this. This method first locates the name of the column in the ls_syntax string. ll_pos = LASTPOS(ls_syntax,’name=’+ls_column_name+’ ‘) If the column is found, find the start and end of the create syntax for that column. First find the start position and store it in ll_pos1. ll_pos1 = LASTPOS(LEFT(ls_syntax,ll_pos),’column(‘) Next, find the end of the objects definition by finding the start of the next object.To be most generic this involves finding the start of all pos- sible objects and find the one closest to and greater than the amount in variable ll_pos. Figure 3: The dynamically created input DataWindow with fields from each of the five data edit windows
  • 4. PBDJ APRIL 2012 | POWERBUILDER.SYS-CON.COM PAGE 28 Tips & tricks ll_pos_a[1] = POS(ls_syntax,’htmltable(‘, ll_pos) ll_pos_a[2] = POS(ls_syntax,’column(‘, ll_pos) ll_pos_a[3] = POS(ls_syntax,’text(‘, ll_pos) ll_pos_a[4] = POS(ls_syntax,’compute(‘, ll_pos) ll_pos_a[5] = POS(ls_syntax,’rectangle(‘, ll_pos) ll_pos_a[6] = POS(ls_syntax,’line(‘, ll_pos) ll_pos_a[7] = POS(ls_syntax,’button(‘, ll_pos) Loop through array ll_pos_a to find the end of the columns syntax and store that value in ll_pos2. Using the values in ll_ pos1 and ll_pos2 extract the column definition using the MID() function, then set the id and tabsequence for the column which will be a sequence number variable ll_detail_id. ll_detail_id++ Extract the column definition for ls_column_name. ls_column = MID(ls_syntax,ll_pos1,ll_pos2 - ll_pos1) Find the id for the column and replace it with ll_detail_id. ll_pos = POS(ls_column,’id=’) IF ll_pos > 0 THEN ll_pos = ll_pos+3 ll_pos1 = POS(ls_column,’ ‘,ll_pos) ls_column = REPLACE(ls_column, ll_pos, ll_pos1 - ll_pos, STRING (ll_detail_id)+’ ‘) END IF Find the tabsequence for the column and replace it with ll_detail_id. ll_pos = POS(ls_column,’tabsequence=’) IF ll_pos > 0 THEN ll_pos = ll_pos+12 ll_pos1 = POS(ls_column,’ ‘,ll_pos) ls_column = REPLACE(ls_column, ll_pos, ll_pos1 - ll_pos, STRING (ll_detail_id)+’ ‘) END IF A definition of the column label must be created after creating the definition for the column. The label definition is static except for the label text and name. The label text was extracted earlier from lds_work and the label name is ls_column_name +’_t’. ls_label_name = ls_column_name+’_t’ ls_dw_columns = ls_dw_columns+’ text(band=detail alignment=”0” text=”’+ls_label+’” name=’+ls_label_name.... After looping through the list of required columns the con- tents of the variables the complete DataWindow syntax can be made by taking the template DataWindow syntax defined earlier in idw_syntax and doing the appropriate substitutions. Once the syntax is made then the new data input DataWin- dow can be created. ll_pos = POS(ls_dwsyntax,’*tables*’) ls_dwsyntax = REPLACE(ls_dwsyntax,ll_pos,8,ls_dw_tables) ll_pos = POS(ls_dwsyntax,’*columns*’) ls_dwsyntax = REPLACE(ls_dwsyntax,ll_pos,9,ls_dw_columns) dw_step.create(ls_dwsyntax,ls_err) The DataWindow has now been created but it still needs to be formatted. This involves looping through the column list again and adjusting the y values for each input field based on the sort order. It is also at this point child DataWindows are retrieved and initial values and edit masks are set. ls_dwsyntax=ls_dwsyntax+’ ‘+ls_column_name+”.Initial=’”+ls_default_ Figure 4: Table containing information regarding recommended column Figure 5: Shows the various sources of properties for the generated DataWindow
  • 5. PBDJ APRIL 2012 | POWERBUILDER.SYS-CON.COM PAGE 30 TIPS & TECHNIQUES Advertiser Index advertiser url phone pG General Conditions: The Publisher reserves the right to refuse any advertising not meeting the standards that are set to protect the high editorial quality of PowerBuilder Developer’s Journal. All advertising is subject to approval by the Publisher.The Publisher assumes no liability for any costs or damages incurred if for any reason the Publisher fails to publish an advertisement. In no event shall the Publisher be liable for any costs or damages in excess of the cost of the advertisement as a result of a mistake in the advertisement or for any other reason. The Advertiser is fully responsible for all financial liability and terms of the contract executed by the agents or agencies who are acting on behalf of theAdvertiser.Conditions set in this document (except the rates) are subject to change by the Publisher without notice.No conditions other than those set forth in this “General Conditions Document” shall be binding upon the Publisher.Advertisers (and their agencies) are fully responsible for the content of their advertisements printed in PowerBuilder Developer’s Journal Advertisements are to be printed at the discretion of the Publisher.This discretion includes the positioning of the advertisement, except for “preferred positions” described in the rate table. Cancellations and changes to advertisements must be made in writing before the closing date. “Publisher” in this “General Conditions Document” refers to SYS-CON Publications, Inc.This index is provided as an additional service to our readers.The publisher does not assume any liability for errors or omissions. Big Data Expo http://events.sys-con.com 201-802-3020 31 eLearnIT http://www.isug.com/pbtraining 11 PBDJournal http://pbdj.sys-con.com/ 29 Sybase http://www.sybase.com/powerbuilder C2 & C4 Sybase http://www.sybase.com/powerbuilder 18-19 SYS-CON Events East http://events.sys-con.com 201-802-3020 C3 SYS-CON Events West http://events.sys-con.com 201-802-3020 17 string+”’” ls_dwsyntax=ls_dwsyntax+’ ‘+ls_column_name+”.editmask.mask=’”+ls_mask+”’” To determine if the field contains a child DataWindow, then the following test is made: IF ls_dddw_name <> ‘?’ THEN If a child DataWindow exists, then determine if arguments ex- ists and retrieve the DataWindow. Most of the child DataWindows either have no argument or require a language id. lds_work.getchild(ls_column_name,ldwc) ldwc.settransobject(gtr_main) ls_arguments = ldwc.describe(‘DataWindow.Table.Arguments’) IF ls_arguments = ‘?’ THEN ldwc.retrieve() ELSE ldwc.retrieve(ll_language_id) END IF Columns with child DataWindows with more complex arguments are removed prior to presentation.The user must go to the appropriate edit window to edit these columns. The DataWindow dw_input is now presented to the user correctly formatted with all recommended and required fields. Once the user has filled in the fields then the data can be saved. Save Process The saving of a new contact is a two-step process.The first step is inserting new records in the various tables.These new records contain the data that is considered as required by the application. For instance a name, country and language for a contact are considered applica- tion requirements.This data is saved directly from a static contact DataWindow. This process establishes the new contact record and creates a key val- ue for the new contact. Once this is done, then the data in dw_input is applied to tables using dynamic SQL updates.This is achieved by loop- ing through lds_column_list to get column information and extracting the entered value for each column from the dw_input DataWindow. In the save loop the first tasks is to get the DataWindow column name for the field. ls_column_name = lds_column_list.object.column_name[ll_row] Next get the database name for the column from the original DataWindow object which has temporarily been created in datastore lds_work. Extract the table name from the column name. ls_column = lds_work.describe(ls_column_name+’.dbname’) ll_pos = POS(ls_column,’.’) ls_table = LEFT(ls_column,ll_pos - 1) Next, get the user entered data for the column from dw_input. ls_data = STRING(dw_input.getitemstring(1, ls_column_name)) Use these variables to build the SQL update statement for the column and execute it. ls_sql = ‘Update ‘+ls_table+’ set ‘+ls_column+’=’+ls_data+’ where id=’+ls_id EXECUTE IMMEDIATE :ls_sql USING sqlca; Repeat this process for all columns in dw_input. Figure 5 shows the relationship between the original data edit DataWindow, the user selected recommended and required fields in lds_column_list, and the generated new record input DataWindow dw_input. It summarizes the process for a single column AssociateType which is defined as a recom- mended field. It has a format of dropdown DataWindow and an initial value of Client/Applicant. Conclusion In complex applications where there are several data edit windows, it’s possible to dynamically create new data input windows that con- tain only the columns that are marked as recommended or required by the user.This process aggregates multiple input windows into one dynamically created DataWindow eliminating the need for the user to open and edit multiple windows while insuring that all necessary data has been entered. About the Author Buck Woolley has been involved in programming and software develop- ment since 1987 and has been a Powerbuilder consultant since 1994, starting with version 3.0. Currently he is the main client server developer at Patrix AB in Gothenberg, Sweden. He has made numerous Techwave presentations covering advanced datawindow tech- niques. Buck and his wife reside in San Diego, California. bwoolley@dw-extreme.com