0
  1. How to access column name and underlying table name of that column in a datawindow in powerbuilder. I could get the column name by having an instance variable and assigning dwo.name to this instance variable in itemfocuschanged event. But how to get the table name of this column.

  2. If I have multiple datawindow controls in a window how to get the name of the selected datawindow control.

2 Answers2

1

First get the SQL Statement for the DW by using the code below...

ls_sql = this.dw_report.Object.DataWindow.Table.SQLSelect

OR

ls_sql = dw_report.Describe("DataWindow.Table.Select")

Then I use this custom function to return the Table name...

ls_table = f_get_table_name(ls_sql)

Code of the "f_get_table_name()" function...

//Obtains the main Table name from the passed SQL string

long ll_pos1
long ll_pos2
string ls_table = ""

ll_pos1 = PosA(Upper(as_sql), "FROM")
ll_pos1 = PosA(as_sql, '"', ll_pos1 + 1)
ll_pos2 = PosA(as_sql, '~~', ll_pos1 + 1)
ls_table = MidA(as_sql, ll_pos1 + 1, ll_pos2 - ll_pos1 - 1)

if (ls_table = "" OR isNull(ls_table)) then
    ll_pos1 = PosA(Upper(as_sql), "SELECT")
    ll_pos1 = PosA(as_sql, ' ', ll_pos1 + 1)
    ll_pos2 = PosA(as_sql, '.', ll_pos1 + 1)
    ls_table = MidA(as_sql, ll_pos1 + 1, ll_pos2 - ll_pos1 - 1)
end if

if (ls_table = "" OR isNull(ls_table)) then
    ll_pos1 = PosA(Upper(as_sql), "WHERE")
    ll_pos1 = PosA(as_sql, ' ', ll_pos1 + 1)
    ll_pos2 = PosA(as_sql, '.', ll_pos1 + 1)
    ls_table = MidA(as_sql, ll_pos1 + 1, ll_pos2 - ll_pos1 - 1)
end if

if (ls_table = "" OR isNull(ls_table)) then
    ll_pos1 = PosA(Upper(as_sql), "FROM")
    ll_pos1 = PosA(as_sql, ' ', ll_pos1 + 1)
    ll_pos2 = PosA(as_sql, ' ', ll_pos1 + 1)
    ls_table = MidA(as_sql, ll_pos1 + 1, ll_pos2 - ll_pos1 - 1)
end if

return Trim(ls_table)
  • I didn't study the code, but at a glance I think something like this would work as global functions do execute in expressions (if you need it there). There are many ways to skin a cat- you could creatively use tag values or other unused property to store things, or name the columns creatively in datawindow with table name some character pattern then column name, some shops leave table name off the main update table and leave it on secondary update table as prefix to the column name. Quick ideas not solution. – Rich Bianco May 25 '18 at 01:33
0

Question 1: Use dw_a.Describe("<yourcolumn>.dbName") This will give you the database name of the colum, in the form tablename.columnname. You can then parse it.

Question 1: Not sure what you mean. If you want to know which one of the datawindows has received focus lastly, you could define a window instance variable (type datawindow) and use the GetFocus event of the various datawindows by putting :

idw_datawindowfocue = this

I wonder though why you need this. Could you explain the rationale?