0

How do you get the list of columns that can be seen in a dw? When I loop through the columns using dwobject.object.datawindow.column.count, I get all the columns in sql. Is there at least a way to figure out which of them isn't displayed?

Mouna Cheikhna
  • 38,870
  • 10
  • 48
  • 69
Guy
  • 325
  • 1
  • 3
  • 18

4 Answers4

1
  Long li_Loop
  String ls_ColName, lsa_ColNames[]

  FOR li_Loop = 1 TO dwobject.object.datawindow.column.count
    ls_ColName = dwobject.Describe("#" + String( ll_Loop ) + ".Name")
    IF Long( dwobject.Describe( ls_ColName + ".Visible") ) > 0 THEN
      lsa_ColNames[ UpperBound(lsa_ColNames[]) + 1] = ls_ColName
    END IF

 next

// The array lsa_ColNames[] contains all the visible columns names.

Ali Waqas
  • 11
  • 2
  • This will **crash** if there is an expression in the Visible expression (the Long() function won't have a valid parm). Also *suspect* that it will crash if there is no UI component for a given column ("DataWindow.Column" goes against the data set, and if the UI element for a given column was deleted or never created, I believe Visible will return either ? or !, again a bad parm for Long()). Other comments to Guy's solution apply. – Terry Dec 21 '11 at 14:40
0

I've managed to find it out by myself:

Integer li_col_idx, &
        li_pos

String  ls_objects, &
        ls_contorl, &
        ls_columns[], &
        ls_type, &
        ls_visible


li_col_idx = 1
ls_objects = dw_tab.object.datawindow.objects  // Forgot to add this row

DO while ls_objects <> ""
    li_pos = Pos(ls_objects, "~t")

    IF li_pos > 0 THEN
        ls_control = left(ls_objects, li_pos - 1)
        ls_objects = mid(ls_objects, li_pos + 1)
    ELSE
        ls_control = ls_objects
        ls_objects = ""
    END IF

    ls_type = dw_tab.describe(ls_control + ".type")
    ls_visible = dw_tab.describe(ls_control + ".visible")
    IF ls_type = "column" AND ls_visible = "1" THEN 
        ls_columns[li_col_idx] = ls_control
        li_col_idx++
    END IF
LOOP 
Guy
  • 325
  • 1
  • 3
  • 18
  • 3
    Good code, but a couple of potential brief gotchas. You don't account for the possibility of an expression in the Visible attribute. Some developers fear deleting UI columns (no need, you can still get/set on the data set column), so they drag the column to the right or below the lower band border, out of sight; if this has been done in your app, your criteria for "visibility" may need to be more complex. You may or may not want to consider Computes, depending on your requirement. You don't include the Describe() you used for the list, although I suspect you're pn the right track. Out of space – Terry Jan 05 '11 at 13:42
  • I've also seen DataWindows that have controls hidden behind other objects. You may need to take that into account as well. The easiest way to deal with the cases Terry & I mentioned might be to add an attribute to the tag, e.g. hidden=yes; – Hugh Brackett Jan 05 '11 at 15:00
  • I've just noticed that I forgot to add the row that gets the list of controls from the dw. Fixed it. – Guy Jan 06 '11 at 10:38
0

In recent code I improved (hopefully) the above by looking at Edit Style. I needed to find not only the active/displayed columns but a sort might be set with a hidden column (no visual control(VC)) and it can't be indicated (see threads on "column sort indicators").

ls_control = idw.describe(ls_next_column + ".type")
if f_IsEmpty(ls_control) then continue

choose case ls_control
case 'column'
    // EDIT STYLE; dddw, ddlb, edit, mask...
    ls_control = idw.Describe(ls_next_column + ".Edit.Style")

    if f_IsEmpty(ls_control) then continue

    choose case ls_control
    case '?', '!'
        continue

    case else
        . . . 

THUS Edit style is Empty, ? or ! when the column does not have a VC. Once you know it's a VC, THEN check if it's Visible or whatever is needed. For my code, I keep a list of VC's only, then check if it's OK/not to indicate...

Steve
  • 1
  • 1
0

The I wrote the following function to properly evaluate the attribute of an object (column,compute,text, etc) in a dataobject.

Example: The following code will return '1' if the location_id column is currently visible or a '0' if it is not currently visible. It doesn't matter if the visible expression contains a complex expression or not.

gfs_evaluate_dw_attribute ( dw_mydatawindow, 1, 'location_id', 'visible' )



global function string gfs_evaluate_dw_attribute (datawindow adw_data, long al_row, string as_columname, string as_attribute);
/*              
    FUNCTION:       gfs_evaluate_dw_attribute
    ARGUMENT:       datawindow adw_data
                        long al_row - row number, 0 or greater
                        string as_columname - dw column or object with attribute to evaluate. This can also be an object on the DW, ie. "DataWindow", "DataWindow.Print", "DataWindow.Trailer.<group #>"
                        string as_attribute - column or object attrbiute to evaluate    
    RETURN:         string
    DESCRIPTION:    returns the attribute setting whether or not there is an expression 
    HISTORY:        Chis Daugherty 01/14/2014   INITIAL VERSION 

*/  
//////////////////////////////////////////////////////////////////////////////

string ls_expression, ls_result, ls_evaluate , ls_type
long ll_tab_pos, ll_Pos_quote 

ls_expression = adw_data.Describe ( as_columname + "." + as_attribute  )

if ls_expression = '!' or isnull(ls_expression) then return ''

IF Left( ls_expression, 1 ) = "~"" AND Right(ls_expression, 1 ) = "~"" THEN 
    // PB quirk will SOMETIMES return an expression in quotes!
    ls_expression= Mid ( ls_expression, 2 , Len ( ls_expression ) - 2 ) 
END IF 

ll_tab_pos = Pos( ls_expression, "~t" ) 

ls_type =  adw_data.Describe( as_columname + ".Type"    )

IF  ls_type =  'compute' THEN

    IF ll_tab_pos > 0 AND lower(as_attribute) <> 'expression' THEN
        choose case lower(trim(Mid( ls_expression, 1, ll_tab_pos  ),true))  
        case '1','0'
            ls_expression = Mid( ls_expression, ll_tab_pos + 1 ) 
        case else
        end choose
    END IF  

    ll_Pos_quote = Pos ( upper(ls_expression) , "'" ) 
    do while ll_Pos_quote > 0 
        ls_expression = Replace( ls_expression, ll_Pos_quote , 0, "~~" )  //insert tilda!
        ll_Pos_quote += 2 //move past quote and tilda
        ll_Pos_quote = Pos ( upper(ls_expression) , "'", ll_Pos_quote  ) 
    loop    
ELSEIF ll_tab_pos > 0 THEN // conditional value 
    ls_expression = Mid( ls_expression, ll_tab_pos + 1 ) 
    //check for single quote that gets in way of quote below
    ll_Pos_quote = Pos ( upper(ls_expression) , "'" ) 
    do while ll_Pos_quote > 0 
        ls_expression = Replace( ls_expression, ll_Pos_quote , 0, "~~" )  //insert tilda!
        ll_Pos_quote += 2 //move past quote and tilda
        ll_Pos_quote = Pos ( upper(ls_expression) , "'", ll_Pos_quote  ) 
    loop
else
    //NO expression just the value was set
    ls_result = ls_expression  
    return ls_result
END IF 

if isnull(al_row) or al_row < 0 then al_row = 0
ls_evaluate = "Evaluate('" + ls_expression + "', " + string(al_row) +") "

ls_result = adw_data.describe(ls_evaluate)



return ls_result


//end of function

I've been using it for years in one form or another. Enjoy! Chris Daugherty