how do i add/subtract a column from a datawindow during runtime?

Posted on 2002-04-24
Last Modified: 2013-12-26
i need to do this because the number of columns would depend on the user... thanks!!
Question by:choklitte
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
  • 3
  • +1

Expert Comment

ID: 6965259
At runtime add or delete a column is a question. May exist a complex way to do it but if you want to know the No. of column in the active DW which are visible and (Think that visible are the columns you want and nonvisible are abstracted columns).

Best way:

Which columns you want to abstract, set the property visible to false.

// under some comditions

//You can do it also dynamic.

Now you can with Column.Count property know the number of columns in your datawindow

ls_colcount = dw_1.DESCRIBE("DataWindow.Column.Count")

Change the ls_colcount to long as ll_ColCount =LONG(ls_colcount)

//Now you can know which columns have the property visible and how many have the property nonvisible.

With For loop you can collect the number of columns visible and nn visible with the property visible:

STRING ls_status

ls_status = dw_1.DESCRIBE("Column_name.Visible") //will returmn 0 or 1

This will return string check it as string is it '0' , it is not visible in datawindow
It is '1', it is visible.

Now the visible number of column depend on the USER.

If you have question or you need some explaination, please let me know.

Best regards



Expert Comment

ID: 6974640
You can dynamically build dw in runtime by dw.Create command. Check pb online help for detailed explanation of how to use create. With this u can create dw during run time for required columns.


Author Comment

ID: 6976487
umm... where can i find the pb online help..? thanks!!
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Expert Comment

ID: 6976708

Just Press f1 and search for Create in your Poerbuilder development environment.


Expert Comment

ID: 6976782
How work the CREATE statement to create a datawindow.

In you case:

STRING  ls_sql, ls_syntax, ls_error, ls_err
IF This_condition THEN
     ls_sql = 'SELECT tableA.column1, tableA.column3, tableA.column4' + &
     'FROM tableA WHERE column = condition and column < condition'
ELSEIF that_condition THEN
     ls_sql = 'SELECT tableA.column5, tableA.column7, tableA.column8' + &
     'FROM tableA WHERE column = condition and column >= condition'

ls_syntax = SQLCA.SyntaxFromSQL(ls_sql, 'Style(Type=Form)', ls_error)
IF ls_error > "" THEN
    Messagebox("ERROR", "ERROR")
    dw_abc.CREATE(ls_syntax, ls_err)
    IF ls_err > "" THEN // Write ERROR message

You need to modify the datawindow with some Modify functions.

Best regards.


Expert Comment

ID: 6977119
Hi Bhatti
You r script is correct.
It will work properly.
We have a similar situation, that the customer will select what r the  cols. required on a particular report. According to the selection we are doing the following.

1. Dynamically build sql to a string variable.
2. Create a dynamic dw with create
3. SetTransObject and retrieve.

Similar like your script.

Also, we have a situation to place particular dwos with pre-defined format. Based on user selection we are changing the dwo.

In one type of Composite Report. We are creating dynamic composite report based on user selection during runtime. So all script what u mentioned is correct. But lots of scripting required to format and align and coloring of the cols. That is y i did not add my full script in my answer.

Try with this method, it will work, but lots of pain on maitaining the code. But otherthan this only way is hiding (as u said).



Author Comment

ID: 6980078
but is there a way to create a datawindow where i don't need to get columns from the database? i'm planning on using the external datawindow since i don't need tables. the only problem is i have to make the datawindow change the number of columns (and its headers) during runtime... can this be done..?

Accepted Solution

Bhatti earned 60 total points
ID: 6980313
Make an External Datawindow say with 20 columns.
Which you want to show Set the Property Visible to 1.
( dw_1.Modify("column_name.Visible=1")

Rest columns which you don't want to show set Visible = 0

Header you can also change at run time.

Header alsmost are text objects.

Say you have Headers as t_text1, t_text2, and so on.

dw_1.Modify("column_name.Text='" + ls_text + "'")

You know which column when to display and with which text.

If you need any further explainations, please let me know. THANKS

Best regards


Author Comment

ID: 6980342
so i really can't add or delete columns? because the columns might extend up to 50, or even 100, depending on the user... so if that's the case, i'll have to make 50 columns in the datawindow painter then just set them to visible/invisible?

Expert Comment

ID: 6981206
Yes I think that you should work with visible/invisible of column prperty.

Add a column a runtime and delete a column at runtime ihave not meet a such condition.

If you are setup your mind to work with External datawindow and with visible/invisible property then:

Please select a Grid datawindow for your external DW.
As I wrote above how to make them visible and invisible.

Question: What with the datatype? All columns are string or Numbers or date or mix?

I think you can 99 columns defined in external datawindow..

Make the parts of the as say, 5 for string 5 for integer or 10 for string and 4 for integer and 2 for datetime.

You are getting some data from some where and storing them and then transfering to the external datawindow. You know which data go to where. You know which name you want to give to the column.

If you have Grid datawindow form then Datawindow will show only the columns having Visible=1 property.

You can also change the name of the header.

Make first External datawindow with a good alignment and width and height as required.

Try to do this, little hard.

I shall look also further for more better solution if exist.

Best regards


Author Comment

ID: 6983208
ok, i'll just do the visible/invisible one. so, how can i change the header? can i use dw.Modify?

Expert Comment

ID: 6985709
Yes use the Modify function. In Help for Modify function you find detail.

Anyhow you can write:

If you dw named dw_1:

dw_1.Modify("Text_field_name.Text='" your_header_text" + "'")

This will change the header text  of the column you want to change.

Every header must have a name. ( you can also named to remember as text1, text2, text3 and so on or you know better).

If you become any question for visible/Invisible or other questions for text fields(Header) please let me know.

Best regards


Author Comment

ID: 6986122
thanks bhatti!!

Expert Comment

ID: 7250435
Build a DataWindow Object from a SELECT command with computed columns.

string ls_sql, ls_style, ls_error, ls_syntax
SQLCA.DBParm="Connectstring='DSN=easdemodb v3;UID=dba;PWD=sql'"

ls_sql = "SELECT 'a' as a, 'b' as be, 3.14 as pi"
ls_style = "style(type=tabular)"

ls_syntax = SQLCA.SyntaxFromSQL(ls_sql, ls_style, ls_error)
dw_1.create(ls_syntax, ls_error)
dw_1.object.a.tabsequence = 10    // set the taborder for all columns


Expert Comment

ID: 7250986
Hi ddbeira,

What do you want to say?

Please explain.


Expert Comment

ID: 7251076
Hi Bhatti,

Based in your suggestion for external datawindow, to build the datawindow object from SyntaxFromSql with a select statement only based in computed columns. After defined the 'result set' authorized for that user, build the SELECT statement with computed columns in the same sequence/data type of that.  The length of strings or numbers specified in the 'result set' will be used to define the columns width. The 'as' clause will be used as columns headers. The static text syntax, like title, may be obtained with DWSyntax. Because the taborder is zero (it is a report) the tabsequence property must be defined for all the columns. After the CREATE, it is possible load the primary buffer with Import, SetItem or data expression (or Retrieve).

Best regards

PS.: Sorry, this is the best that I can write.

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
How to install Selenium IDE and loops for quick automated testing. Get Selenium IDE from Go to that link and select download selenium in the right hand columnThat will then direct you to their download page.From that page s…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
The viewer will learn how to use NetBeans IDE 8.0 for Windows to connect to a MySQL database. Open Services Panel: Create a new connection using New Connection Wizard: Create a test database called eetutorial: Create a new test tabel called ee…

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question