File: n_svc_dw.sru
Size: 82785
Date: Mon, 07 Apr 2008 21:31:11 +0200
$PBExportHeader$n_svc_dw.sru
$PBExportComments$Datawindow, Datastore and DatawindowChild service
forward
global type n_svc_dw from n_svc_base
end type
end forward

global type n_svc_dw from n_svc_base
end type
global n_svc_dw n_svc_dw

type variables
Protected:

CONSTANT string YES = "yes"
CONSTANT string NO = "no"

CONSTANT string COLUMN_COUNT = "Datawindow.Column.Count"
CONSTANT string OBJECTS = "DataWindow.Objects"
CONSTANT string PROCESSING = "Datawindow.Processing"
CONSTANT string SORT = "Datawindow.Table.Sort"
CONSTANT string UPDATETABLE = "Datawindow.Table.UpdateTable"

CONSTANT string TAG_SEPARATOR = ";"
end variables

forward prototypes
public subroutine of_disable (ref n_svc_mgr anv_svc, readonly datawindow adw)
protected function boolean of_isservicableobject (readonly powerobject apo)
public function string of_buildcolumnvaluestring (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly long al_colid, readonly string as_value, readonly boolean ab_matchcase)
public function string of_buildcolumnvaluestring (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly string as_colname, readonly string as_value, readonly boolean ab_matchcase)
public function long of_findrow (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly string as_colname, readonly string as_value, long al_startrow)
public function long of_findrow (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly string as_colname, readonly string as_value)
public function long of_findrow (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly long al_colid, readonly string as_value)
public function long of_findrow (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly long al_colid, readonly string as_value, long al_startrow)
public function long of_getcolumncount (readonly powerobject apo)
public function integer of_getvisiblecolumns (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_colnames[], readonly boolean ab_includecomputed, readonly boolean ab_sortbyx)
public function integer of_getvisiblecolumns (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_colnames[])
public function string of_getcolumndatatype (readonly powerobject apo, readonly long al_colid)
public function string of_getcolumndatatype (readonly powerobject apo, readonly string as_colname)
public function string of_getcolumndisplayvalue (readonly powerobject apo, readonly long al_row, readonly string as_colname)
public function string of_getcolumndisplayvalue (readonly powerobject apo, readonly long al_row, readonly long al_colid)
public function string of_getcolumneditstyle (readonly powerobject apo, readonly string as_colname)
public function string of_getcolumneditstyle (readonly powerobject apo, readonly long al_colid)
public function integer of_getcomputedfields (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_name[], ref string as_datatype[])
public function any of_getitemany (readonly powerobject apo, long al_row, string as_colname)
public function any of_getitemany (readonly powerobject apo, long al_row, long al_colid)
public function integer of_getobjects (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_name[], ref string as_type[])
public function integer of_getprimarykeys (readonly powerobject apo, ref string as_names[], ref string as_datatypes[])
public function integer of_getprimarykeyvalues (readonly powerobject apo, readonly long al_row, ref string as_values[])
public function string of_gettag (readonly powerobject apo, readonly string as_colname)
public function string of_gettagkeyword (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly string as_col, readonly string as_key)
public function string of_gettagkeyword (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly long al_colid, readonly string as_key)
public function boolean of_isobjectvisible (readonly powerobject apo, readonly string as_objname)
public subroutine of_ordercolumnsbypositionx (readonly powerobject apo, ref string as_colnames[])
public subroutine of_removetabsequence (ref n_svc_mgr anv_svc, readonly powerobject apo)
public function integer of_retrievedddw (readonly powerobject apo, readonly transaction atr, string as_colname)
public function integer of_retrievedddw (readonly powerobject apo, string as_colname)
public subroutine of_getobjectrect (readonly powerobject apo, readonly string as_objname, ref long al_x, ref long al_y, ref long al_width, ref long al_height)
public subroutine of_getobjectrelativerect (readonly powerobject apo, readonly string as_objname, ref long al_x, ref long al_y, ref long al_width, ref long al_height)
public function string of_getcolumnname (readonly powerobject apo, readonly long colid)
public function integer of_getsort (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_colnames[], ref string as_sortdirection[])
public function string of_getupdatetable (readonly powerobject apo)
public function integer of_retrievedddw (readonly powerobject apo, readonly transaction atr)
public function integer of_retrievedddw (readonly powerobject apo)
public function long of_totalselectedrows (readonly powerobject apo)
public function integer of_createstringdatastore (ref n_svc_mgr anv_svc, readonly powerobject apo, ref datastore ads)
public function integer of_saveas (ref n_svc_mgr anv_svc, readonly powerobject apo, readonly string as_fullpath, readonly saveastype asa_type)
public function integer of_saveas (ref n_svc_mgr anv_svc, readonly powerobject apo)
public subroutine of_settabsequence (ref n_svc_mgr anv_svc, readonly powerobject apo, readonly string as_tabsequence)
public function boolean of_iserrorstring (readonly string as_string)
public subroutine of_settagkeyword (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly string as_col, readonly string as_key, readonly string as_value)
public function string of_fixdwstring (ref n_svc_mgr anv_svc, readonly string as_string)
public function string of_getdwstyle (readonly datawindow adw)
public function string of_gettabsequence (ref n_svc_mgr anv_svc, readonly powerobject apo)
public subroutine of_removedropdownarrows (ref n_svc_mgr anv_svc, readonly powerobject apo, readonly boolean ab_set)
public function blob of_getsyntaxcompressed (ref n_svc_mgr anv_svc, readonly powerobject adw)
public function integer of_createfromcompressedsyntax (ref n_svc_mgr anv_svc, readonly powerobject adw, readonly blob ablb_compressed)
public function blob of_getfullstatecompressed (ref n_svc_mgr anv_svc, readonly powerobject adw)
public function integer of_setfullstatecompressed (ref n_svc_mgr anv_svc, readonly powerobject adw, readonly blob ablb_compressed)
public function boolean of_hasretrievalarguments (readonly powerobject apo)
public function integer of_getretrievalarguments (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_argnames[], ref string as_datatypes[])
public function string of_makefriendlyname (readonly string as_name)
public function integer of_getcolumns (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_colnames[], ref string as_datatypes[])
public function integer of_getvisiblecolumns (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_colnames[], readonly string as_bandname, readonly boolean ab_includecomputed, readonly boolean ab_sortbyx)
public function string of_getcolumnid (readonly powerobject apo, readonly string as_colname)
public function integer of_setitem (readonly powerobject apo, long al_row, string as_colname, string as_value)
public function integer of_setitem (readonly powerobject apo, long al_row, long al_colid, string as_value)
end prototypes

public subroutine of_disable (ref n_svc_mgr anv_svc, readonly datawindow adw);//===========================================================================
// Function: of_Disable (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly DataWindow adw
//---------------------------------------------------------------------------
// Returns: (none)
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_cols[], ls_type, ls_mod
long ll_count, n, ll_backcolor, ll_color
n_svc_win32 lnv_win32

IF NOT of_IsServicableObject(adw) THEN RETURN

anv_svc.of_LoadSvc(lnv_win32, CSvc.WIN32)
ll_backcolor = lnv_win32.GetSysColor(CWin32.COLOR_BTNFACE)
ll_color = lnv_win32.GetSysColor(CWin32.COLOR_GRAYTEXT)

ll_count = of_GetVisibleColumns(anv_svc, adw, ls_cols)

FOR n = 1 TO ll_count
   ls_mod += " " + ls_cols[n] + ".TabSequence=0"
   ls_mod += " " + ls_cols[n] + ".Background.Color=" + STRING(ll_backcolor)
   ls_mod += " " + ls_cols[n] + ".Color=" + STRING(ll_color)
NEXT

adw.SetRedraw(FALSE)
adw.Modify(ls_mod)
of_RemoveDropdownArrows(anv_svc, adw, TRUE)
adw.SetRedraw(TRUE)
end subroutine

protected function boolean of_isservicableobject (readonly powerobject apo);//===========================================================================
// Function: of_Isservicableobject (protected )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
boolean lb

IF ISVALID(apo) THEN
   CHOOSE CASE apo.TypeOf()
      CASE Datawindow!, Datastore!, DatawindowChild!
         lb = TRUE
      CASE ELSE
         lb = FALSE
   END CHOOSE
END IF

RETURN lb
end function

public function string of_buildcolumnvaluestring (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly long al_colid, readonly string as_value, readonly boolean ab_matchcase);//===========================================================================
// Function: of_Buildcolumnvaluestring (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr ansvc_mgr
//  readonly PowerObject apo
//  readonly Long al_colid
//  readonly String as_value
//  readonly Boolean ab_matchcase
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string lsc

// Get Column Name
lsc = of_GetColumnName(apo, al_colid)
// Check if Valid Colid
IF ISNULL(lsc) THEN RETURN lsc

RETURN of_BuildColumnValueString(ansvc_mgr, apo, lsc, as_value, ab_matchcase)
end function

public function string of_buildcolumnvaluestring (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly string as_colname, readonly string as_value, readonly boolean ab_matchcase);//===========================================================================
// Function: of_Buildcolumnvaluestring (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr ansvc_mgr
//  readonly PowerObject apo
//  readonly String as_colname
//  readonly String as_value
//  readonly Boolean ab_matchcase
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string         lst, lss
n_svc_string   lsvc_String
n_svc_isempty  lsvc_IsEmpty

IF NOT of_IsServicableObject(apo) THEN RETURN lss

//load service
ansvc_mgr.of_LoadSvc(lsvc_IsEmpty, cSvc.ISEMPTY)

IF lsvc_IsEmpty.of_IsEmpty(as_colname) &
   OR lsvc_IsEmpty.of_IsEmpty(as_value) THEN RETURN lss

//get datatype
lst = of_GetColumnDatatype(apo, as_colname)

IF lsvc_IsEmpty.of_IsEmpty(lst) THEN RETURN lss

CHOOSE CASE lst
   CASE Cdwdatatype.CHAR
      IF ab_matchcase THEN
         lss = "{1} = '{2}'"
      ELSE
         lss = "lower({1}) = '{2}'"
      END IF
   CASE Cdwdatatype.DATE
      lss = "{1} = date('{2}')"
   CASE Cdwdatatype.TIME
      lss = "{1} = time('{2}')"
   CASE Cdwdatatype.DATETIME, Cdwdatatype.TIMESTAMP
      lss = "{1} = datetime('{2}')"
   CASE Cdwdatatype.INT, Cdwdatatype.LONG, Cdwdatatype.NUMBER, Cdwdatatype.REAL, Cdwdatatype.DECIMAL, Cdwdatatype.ULONG
      lss = "{1} = {2}"
END CHOOSE

ansvc_mgr.of_LoadSvc(lsvc_String, Csvc.STRING)

IF ab_matchcase THEN
   lss = lsvc_string.of_Format(lss, {as_colname, as_value})
ELSE
   lss = lsvc_string.of_Format(lss, {as_colname, lower(as_value)})
END IF

RETURN lss
end function

public function long of_findrow (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly string as_colname, readonly string as_value, long al_startrow);//===========================================================================
// Function: of_Findrow (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr ansvc_mgr
//  readonly PowerObject apo
//  readonly String as_colname
//  readonly String as_value
//  value Long al_startrow
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
IF NOT of_IsServicableObject(apo) THEN RETURN Cret.FAILURE

RETURN apo.DYNAMIC Find( &
         of_BuildColumnValueString(ansvc_mgr, apo, as_colname, as_value, TRUE), &
         al_startrow, apo.DYNAMIC RowCount())
end function

public function long of_findrow (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly string as_colname, readonly string as_value);//===========================================================================
// Function: of_Findrow (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr ansvc_mgr
//  readonly PowerObject apo
//  readonly String as_colname
//  readonly String as_value
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN of_FindRow(ansvc_mgr, apo, as_colname, as_value, 1)
end function

public function long of_findrow (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly long al_colid, readonly string as_value);//===========================================================================
// Function: of_Findrow (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr ansvc_mgr
//  readonly PowerObject apo
//  readonly Long al_colid
//  readonly String as_value
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string lsc

lsc = of_GetColumnName(apo, al_colid)

RETURN of_FindRow(ansvc_mgr, apo, lsc, as_value)
end function

public function long of_findrow (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly long al_colid, readonly string as_value, long al_startrow);//===========================================================================
// Function: of_Findrow (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr ansvc_mgr
//  readonly PowerObject apo
//  readonly Long al_colid
//  readonly String as_value
//  value Long al_startrow
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string lsc

lsc = of_GetColumnName(apo, al_colid)

RETURN of_FindRow(ansvc_mgr, apo, lsc, as_value, al_startrow)
end function

public function long of_getcolumncount (readonly powerobject apo);//===========================================================================
// Function: of_Getcolumncount (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls

IF NOT ISVALID(apo) THEN RETURN Cret.FAILURE

ls = apo.DYNAMIC Describe(COLUMN_COUNT)

IF NOT ISNUMBER(ls) OR ISNULL(ls) THEN ls = "-1"

RETURN LONG(ls)
end function

public function integer of_getvisiblecolumns (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_colnames[], readonly boolean ab_includecomputed, readonly boolean ab_sortbyx);//===========================================================================
// Function: of_Getvisiblecolumns (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  reference String as_colnames[]
//  readonly Boolean ab_includecomputed
//  readonly Boolean ab_sortbyx
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN  of_GetVisibleColumns(anv_svc, apo, as_colnames, CString.EMPTY, ab_includecomputed, ab_sortbyx)
end function

public function integer of_getvisiblecolumns (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_colnames[]);//===========================================================================
// Function: of_Getvisiblecolumns (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  reference String as_colnames[]
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN of_GetVisibleColumns(anv_svc, apo, as_colnames, FALSE, FALSE)
end function

public function string of_getcolumndatatype (readonly powerobject apo, readonly long al_colid);//===========================================================================
// Function: of_Getcolumndatatype (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly Long al_colid
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string lsc

// Get Column Name
lsc = of_GetColumnName(apo, al_colid)
// Check if Valid Colid
IF ISNULL(lsc) THEN RETURN lsc

RETURN of_GetColumnDatatype(apo, lsc)
end function

public function string of_getcolumndatatype (readonly powerobject apo, readonly string as_colname);//===========================================================================
// Function: of_Getcolumndatatype (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly String as_colname
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string lsr

IF NOT of_IsServicableObject(apo) THEN RETURN lsr

lsr = LOWER(apo.DYNAMIC Describe(as_colname + ".ColType"))

CHOOSE CASE LEFT(lsr, 4)
   CASE Cdwdatatype.CHAR
      lsr = Cdwdatatype.CHAR
   CASE "deci"
      lsr = Cdwdatatype.DECIMAL
   CASE "?", "!"
      SetNull(lsr)
END CHOOSE
   
RETURN lsr
end function

public function string of_getcolumndisplayvalue (readonly powerobject apo, readonly long al_row, readonly string as_colname);//===========================================================================
// Function: of_Getcolumndisplayvalue (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly Long al_row
//  readonly String as_colname
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_ret

IF NOT of_IsServicableObject(apo) THEN RETURN ls_ret

ls_ret = apo.DYNAMIC Describe( &
           "evaluate('lookupdisplay(" + as_colname + ")'," + STRING(al_row) + ")" &
           )

RETURN ls_ret
end function

public function string of_getcolumndisplayvalue (readonly powerobject apo, readonly long al_row, readonly long al_colid);//===========================================================================
// Function: of_Getcolumndisplayvalue (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly Long al_row
//  readonly Long al_colid
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
String   lsc

// Get Column Name
lsc = of_GetColumnName(apo, al_colid)
// Check if Valid Colid
IF ISNULL(lsc) THEN RETURN lsc

RETURN of_GetColumnDisplayValue(apo, al_row, lsc)
end function

public function string of_getcolumneditstyle (readonly powerobject apo, readonly string as_colname);//===========================================================================
// Function: of_Getcolumneditstyle (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly String as_colname
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string lsr

IF NOT of_IsServicableObject(apo) THEN RETURN lsr

RETURN LOWER(apo.DYNAMIC Describe(as_colname + ".Edit.Style"))
end function

public function string of_getcolumneditstyle (readonly powerobject apo, readonly long al_colid);//===========================================================================
// Function: of_Getcolumneditstyle (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly Long al_colid
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
String   lsc

// Get Column Name
lsc = of_GetColumnName(apo, al_colid)
// Check if Valid Colid
IF ISNULL(lsc) THEN RETURN lsc

RETURN of_GetColumnEditStyle(apo, lsc)
end function

public function integer of_getcomputedfields (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_name[], ref string as_datatype[]);//===========================================================================
// Function: of_Getcomputedfields (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  reference String as_name[]
//  reference String as_datatype[]
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
integer li_c, n, c
string ls_names[], ls_types[]

IF NOT of_IsServicableObject(apo) THEN RETURN Cret.FAILURE

li_c = of_GetObjects(anv_svc, apo, ls_names, ls_types)

FOR n = 1 to li_c
   IF ls_types[n] <> Cdwobj.COMPUTE THEN CONTINUE
   
   c ++
   as_name[c] = ls_names[n]
   as_datatype[c] = of_GetColumnDataType(apo, ls_names[n])
NEXT

RETURN c
end function

public function any of_getitemany (readonly powerobject apo, long al_row, string as_colname);//===========================================================================
// Function: of_Getitemany (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  value Long al_row
//  value String as_colname
//---------------------------------------------------------------------------
// Returns: Any
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
any la_ret
string ls_dtype
decimal ld

IF NOT of_IsServicableObject(apo) THEN RETURN la_ret

ls_dtype = of_GetColumnDataType(apo, as_colname)

CHOOSE CASE ls_dtype
   CASE Cdwdatatype.CHAR
      la_ret = apo.DYNAMIC GetItemString(al_row, as_colname)
   CASE Cdwdatatype.DECIMAL
      ld = apo.DYNAMIC GetItemDecimal(al_row, as_colname)
      RETURN ld
   CASE Cdwdatatype.INT, Cdwdatatype.LONG, Cdwdatatype.NUMBER, Cdwdatatype.REAL, Cdwdatatype.ULONG
      la_ret = apo.DYNAMIC GetItemNumber(al_row, as_colname)
   CASE Cdwdatatype.DATE
      la_ret = apo.DYNAMIC GetItemDate(al_row, as_colname)
   CASE Cdwdatatype.DATETIME
      la_ret = apo.DYNAMIC GetItemDateTime(al_row, as_colname)
   CASE Cdwdatatype.TIME, Cdwdatatype.TIMESTAMP
      la_ret = apo.DYNAMIC GetItemTime(al_row, as_colname)
   CASE ELSE
      SetNull(la_ret)
END CHOOSE

RETURN la_ret
end function

public function any of_getitemany (readonly powerobject apo, long al_row, long al_colid);//===========================================================================
// Function: of_Getitemany (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  value Long al_row
//  value Long al_colid
//---------------------------------------------------------------------------
// Returns: Any
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string lsc

// Get Column Name
lsc = of_GetColumnName(apo, al_colid)
// Check if Valid Colid
IF ISNULL(lsc) THEN RETURN lsc

RETURN of_GetItemAny(apo, al_row, lsc)
end function

public function integer of_getobjects (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_name[], ref string as_type[]);//===========================================================================
// Function: of_Getobjects (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  reference String as_name[]
//  reference String as_type[]
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
integer c
string ls_objs
n_svc_isempty lnv_isempty
n_svc_string lnv_string

IF NOT of_IsServicableObject(apo) THEN RETURN Cret.FAILURE

//load services
anv_svc.of_LoadSvc(lnv_isempty, Csvc.ISEMPTY)
anv_svc.of_LoadSvc(lnv_string, Csvc.STRING)

ls_objs = apo.DYNAMIC Describe(OBJECTS)

DO WHILE NOT lnv_isempty.of_IsEmpty(ls_objs)
   c ++
   as_name[c] = lnv_string.of_GetToken(ls_objs, CString.TAB)
   as_type[c] = apo.DYNAMIC Describe(as_name[c] + ".Type")
LOOP

RETURN c
end function

public function integer of_getprimarykeys (readonly powerobject apo, ref string as_names[], ref string as_datatypes[]);//===========================================================================
// Function: of_Getprimarykeys (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  reference String as_names[]
//  reference String as_datatypes[]
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
integer c
long ll_count, n

IF NOT of_IsServicableObject(apo) THEN RETURN Cret.FAILURE

ll_count = of_GetColumnCount(apo)

FOR n = 1 to ll_count
   IF LOWER(apo.DYNAMIC Describe("#" + STRING(n) + ".Key")) = YES THEN
      c ++
      as_names[c] = apo.DYNAMIC Describe("#" + STRING(n) + ".Name")
      as_datatypes[n] = this.of_GetColumnDataType(apo, as_names[c])
   END IF
NEXT

RETURN c
end function

public function integer of_getprimarykeyvalues (readonly powerobject apo, readonly long al_row, ref string as_values[]);//===========================================================================
// Function: of_Getprimarykeyvalues (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly Long al_row
//  reference String as_values[]
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
long ll_count, n
string ls_names[], ls_types[]

IF NOT ISVALID(apo) THEN RETURN Cret.FAILURE

ll_count = of_GetPrimaryKeys(apo, ls_names, ls_types)

FOR n = ll_count TO 1 STEP -1
   as_values[n] = STRING(of_GetItemAny(apo, al_row, ls_names[n]))
NEXT

RETURN ll_count
end function

public function string of_gettag (readonly powerobject apo, readonly string as_colname);//===========================================================================
// Function: of_Gettag (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly String as_colname
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_ret

IF NOT of_IsServicableObject(apo) THEN RETURN ls_ret

ls_ret = apo.DYNAMIC Describe(as_colname + ".Tag")
//bug fix, remove '"'
IF LEFT(ls_ret, 1) = '"' AND RIGHT(ls_ret, 1) = '"' THEN
   ls_ret = MID(ls_ret, 2, LEN(ls_ret) - 2)
END IF

RETURN ls_ret
end function

public function string of_gettagkeyword (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly string as_col, readonly string as_key);//===========================================================================
// Function: of_Gettagkeyword (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr ansvc_mgr
//  readonly PowerObject apo
//  readonly String as_col
//  readonly String as_key
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string         lst, lsk
n_svc_string   lsvc_String
n_svc_isempty  lsvc_IsEmpty

IF NOT of_IsServicableObject(apo) THEN RETURN lsk

//load service
ansvc_mgr.of_LoadSvc(lsvc_IsEmpty, Csvc.ISEMPTY)

IF lsvc_IsEmpty.of_IsEmpty(as_key) THEN RETURN lsk

lst = apo.DYNAMIC Describe(as_col + ".Tag")
ansvc_mgr.of_LoadSvc(lsvc_String, Csvc.STRING)
lsk = lsvc_String.of_GetKeyValue(lst, as_key, ";")

RETURN lsk
end function

public function string of_gettagkeyword (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly long al_colid, readonly string as_key);//===========================================================================
// Function: of_Gettagkeyword (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr ansvc_mgr
//  readonly PowerObject apo
//  readonly Long al_colid
//  readonly String as_key
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string lsc

// Get Column Name
lsc = of_GetColumnName(apo, al_colid)
// Check if Valid Colid
IF ISNULL(lsc) THEN RETURN lsc

RETURN of_GetTagKeyword(ansvc_mgr, apo, lsc, as_key)
end function

public function boolean of_isobjectvisible (readonly powerobject apo, readonly string as_objname);//===========================================================================
// Function: of_Isobjectvisible (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly String as_objname
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
boolean lb_ret
string ls_ret

IF NOT of_IsServicableObject(apo) THEN RETURN lb_ret

ls_ret = apo.DYNAMIC Describe(as_objname + ".Visible")

CHOOSE CASE ls_ret
   CASE "1", "yes"
      lb_ret = TRUE
END CHOOSE

RETURN lb_ret
end function

public subroutine of_ordercolumnsbypositionx (readonly powerobject apo, ref string as_colnames[]);//===========================================================================
// Function: of_Ordercolumnsbypositionx (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  reference String as_colnames[]
//---------------------------------------------------------------------------
// Returns: (none)
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
long ll_count, ll_innercount, n
boolean lb_swap
string ls_temp
long llx1, llx2, m

IF NOT of_IsServicableObject(apo) THEN RETURN

ll_count = UPPERBOUND(as_colnames)
ll_innercount = ll_count - 1

FOR n = 1 TO ll_count
   lb_swap = FALSE
   
   FOR m = 1 TO ll_innercount
      llx1 = LONG(apo.DYNAMIC Describe(as_colnames[m] + ".X"))
      llx2 = LONG(apo.DYNAMIC Describe(as_colnames[m + 1] + ".X"))
      IF llx1 > llx2 THEN
         lb_swap = TRUE
         ls_temp = as_colnames[m]
         as_colnames[m] = as_colnames[m + 1]
         as_colnames[m + 1] = ls_temp
      END IF      
   NEXT
   
   IF NOT lb_swap THEN EXIT
NEXT

RETURN
end subroutine

public subroutine of_removetabsequence (ref n_svc_mgr anv_svc, readonly powerobject apo);//===========================================================================
// Function: of_Removetabsequence (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//---------------------------------------------------------------------------
// Returns: (none)
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_cols[], ls_mod
long ll_count, n

IF NOT of_IsServicableObject(apo) THEN RETURN

ll_count = of_GetVisibleColumns(anv_svc, apo, ls_cols)

FOR n = 1 TO ll_count
   ls_mod += " " + ls_cols[n] + ".TabSequence=0"
NEXT

apo.DYNAMIC Modify(ls_mod)
end subroutine

public function integer of_retrievedddw (readonly powerobject apo, readonly transaction atr, string as_colname);//===========================================================================
// Function: of_Retrievedddw (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly Transaction atr
//  value String as_colname
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_ret
DatawindowChild ldo

IF NOT of_IsServicableObject(apo) THEN RETURN CRet.FAILURE

ls_ret = apo.DYNAMIC Describe(as_colname + ".dddw.Name")

IF of_IsErrorString(ls_ret) THEN RETURN CRet.FAILURE
IF ISNULL(ls_ret) THEN RETURN CRet.FAILURE

IF apo.DYNAMIC GetChild(as_colname, ldo) = CRet.FAILURE THEN RETURN CRet.FAILURE
ldo.SetTransObject(atr)
ldo.Retrieve()

RETURN CRet.SUCCESS
end function

public function integer of_retrievedddw (readonly powerobject apo, string as_colname);//===========================================================================
// Function: of_Retrievedddw (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  value String as_colname
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN of_RetrieveDDDW(apo, SQLCA, as_colname)
end function

public subroutine of_getobjectrect (readonly powerobject apo, readonly string as_objname, ref long al_x, ref long al_y, ref long al_width, ref long al_height);//===========================================================================
// Function: of_Getobjectrect (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly String as_objname
//  reference Long al_x
//  reference Long al_y
//  reference Long al_width
//  reference Long al_height
//---------------------------------------------------------------------------
// Returns: (none)
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
IF NOT of_IsServicableObject(apo) THEN RETURN

al_x = LONG(apo.DYNAMIC Describe(as_objname + ".X"))
al_y = LONG(apo.DYNAMIC Describe(as_objname + ".Y"))
al_width = LONG(apo.DYNAMIC Describe(as_objname + ".Width"))
al_height = LONG(apo.DYNAMIC Describe(as_objname + ".Height"))
end subroutine

public subroutine of_getobjectrelativerect (readonly powerobject apo, readonly string as_objname, ref long al_x, ref long al_y, ref long al_width, ref long al_height);//===========================================================================
// Function: of_Getobjectrelativerect (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly String as_objname
//  reference Long al_x
//  reference Long al_y
//  reference Long al_width
//  reference Long al_height
//---------------------------------------------------------------------------
// Returns: (none)
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
IF NOT of_IsServicableObject(apo) THEN RETURN

al_x = LONG(apo.DYNAMIC Describe(as_objname + ".X")) - LONG(apo.DYNAMIC Describe("Datawindow.HorizontalScrollPosition"))
al_y = LONG(apo.DYNAMIC Describe(as_objname + ".Y")) - LONG(apo.DYNAMIC Describe("Datawindow.VerticalScrollPosition"))
al_width = LONG(apo.DYNAMIC Describe(as_objname + ".Width"))
al_height = LONG(apo.DYNAMIC Describe(as_objname + ".Height"))
end subroutine

public function string of_getcolumnname (readonly powerobject apo, readonly long colid);//===========================================================================
// Function: of_Getcolumnname (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly Long colid
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_column

IF NOT of_IsServicableObject(apo) THEN 
   SetNull(ls_column)
   RETURN ls_column
END IF

//get column name
ls_column = TRIM(apo.DYNAMIC Describe("#" + STRING(colid) + ".Name"))
//Set null if invalid colid
IF ISNULL(ls_column) OR TRIM(ls_column) = "" OR of_IsErrorString(ls_column) THEN
   SetNull(ls_column)
END IF
   
RETURN ls_column
end function

public function integer of_getsort (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_colnames[], ref string as_sortdirection[]);//===========================================================================
// Function: of_Getsort (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  reference String as_colnames[]
//  reference String as_sortdirection[]
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_ret, ls_p[]
n_svc_string lnv_string
long ll_count, n

IF NOT of_IsServicableObject(apo) THEN RETURN CRet.FAILURE

ls_ret = apo.DYNAMIC Describe(SORT)

IF of_IsErrorString(ls_ret) THEN RETURN CRet.FAILURE

anv_svc.of_LoadSvc(lnv_string, CSvc.STRING)

lnv_string.of_ParseToArray(ls_ret, ",", ls_p)

ll_count = UPPERBOUND(ls_p)

FOR n = 1 TO ll_count
   as_colnames[n] = TRIM(MID(ls_p[n], 1, LEN(ls_p[n]) - 1))
   as_sortdirection[n] = RIGHT(ls_p[n], 1)
NEXT

RETURN ll_count
end function

public function string of_getupdatetable (readonly powerobject apo);//===========================================================================
// Function: of_Getupdatetable (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
IF NOT of_IsServicableObject(apo) THEN RETURN CString.EMPTY

RETURN apo.DYNAMIC Describe(UPDATETABLE)
end function

public function integer of_retrievedddw (readonly powerobject apo, readonly transaction atr);//===========================================================================
// Function: of_Retrievedddw (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//  readonly Transaction atr
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
long ll_count, n
string ls_colnames[]
n_svc_mgr lnv_svc

ll_count = of_GetVisibleColumns(lnv_svc, apo, ls_colnames)

FOR n = 1 TO ll_count
   IF of_RetrieveDDDW(apo, atr, ls_colnames[n]) = CRet.FAILURE THEN RETURN CRet.FAILURE
NEXT

RETURN CRet.SUCCESS
end function

public function integer of_retrievedddw (readonly powerobject apo);//===========================================================================
// Function: of_Retrievedddw (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN of_RetrieveDDDW(apo, SQLCA)
end function

public function long of_totalselectedrows (readonly powerobject apo);//===========================================================================
// Function: of_Totalselectedrows (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//---------------------------------------------------------------------------
// Returns: Long
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
long ll_r, ll_ctr

IF NOT of_IsServicableObject(apo) THEN RETURN CRet.FAILURE

DO
   ll_r = apo.DYNAMIC GetSelectedRow(ll_r)
   IF ll_r > 0 THEN ll_ctr ++
LOOP WHILE ll_r > 0

RETURN ll_ctr
end function

public function integer of_createstringdatastore (ref n_svc_mgr anv_svc, readonly powerobject apo, ref datastore ads);//===========================================================================
// Function: of_Createstringdatastore (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  reference DataStore ads
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_string lnv_string
string ls_colnames[], ls_syntax, ls_coldef, ls_x, ls_w, ls_txt
long ll_count, n, ll_rcount, m

CONSTANT string dwsyntax = 'release 10;datawindow(units=0 timer_interval=0 color=1090519039 processing=1 HTMLDW=no print.documentname="" print.orientation = 0 print.margin.left = 110 print.margin.right = 110 print.margin.top = 96 print.margin.bottom = 96 print.paper.source = 0 print.paper.size = 0 print.prompt=no print.buttons=no print.preview.buttons=no grid.lines=0 ) header(height=80 color="536870912" ) summary(height=0 color="536870912" ) footer(height=0 color="536870912" ) detail(height=92 color="536870912" ) table('
CONSTANT string coldef = ' column=(type=char(255) updatewhereclause=no name={1} dbname="{1}")'
CONSTANT string header = ' text(band=header alignment="2" text="{2}" border="0" color="33554432" x="{3}" y="8" height="64" width="{4}" name={1} font.face="Arial" font.height="-10" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912")'
// 1=name, 2=text, 3=x, 4=width
CONSTANT string column = ' column(band=detail id={2} alignment="0" tabsequence=10 border="0" color="33554432" x="{3}" y="8" height="76" width="{4}" format="[general]" name={1} edit.limit=0 edit.case=any edit.focusrectangle=no edit.autoselect=yes edit.autohscroll=yes font.face="Arial" font.height="-10" font.weight="400" font.family="2" font.pitch="2" font.charset="0" background.mode="1" background.color="536870912")'
// 1=name, 2=id, 3=x, 4=width

IF NOT of_IsServicableObject(apo) THEN RETURN CRet.FAILURE

anv_svc.of_LoadSvc(lnv_string, CSvc.STRING)

ll_count = of_GetVisibleColumns(anv_svc, apo, ls_colnames, TRUE, TRUE)

FOR n = 1 TO ll_count
   //skip icon column
   IF ls_colnames[n] = "icon_col" THEN CONTINUE
   //column table
   ls_coldef += lnv_string.of_Format(coldef, {ls_colnames[n]})
   //columns
   ls_x = apo.DYNAMIC Describe(ls_colnames[n] + ".X")
   ls_w = apo.DYNAMIC Describe(ls_colnames[n] + ".width")
   ls_syntax += lnv_string.of_Format(column, {ls_colnames[n], STRING(n), ls_x, ls_w})
   //headers
   ls_txt = apo.DYNAMIC Describe(ls_colnames[n] + "_t.text")
   IF ls_txt = "!" OR ls_txt = "?" THEN ls_txt = ls_colnames[n]
   ls_syntax += lnv_string.of_Format(header, {ls_colnames[n] + "_t", ls_txt, ls_x, ls_w})
NEXT

ls_syntax = dwsyntax + ls_coldef + ")" + ls_syntax

//create datastore
IF NOT ISVALID(ads) THEN ads = CREATE n_ds
IF ads.Create(ls_syntax, ls_x) = CRet.FAILURE THEN
   DESTROY ads
   RETURN CRet.FAILURE
END IF

//load rows as as string into new datastore
ll_rcount = apo.DYNAMIC RowCount()
FOR n = 1 to ll_rcount
   ads.InsertRow(0)
   FOR m = 1 to ll_count
      IF ls_colnames[m] = "icon_col" THEN CONTINUE
      ls_x = TRIM(apo.DYNAMIC Describe("evaluate('lookupdisplay(" + ls_colnames[m] + ")'," + STRING(n) + ")"))
      IF of_IsErrorString(ls_x) THEN ls_x = ""
      ads.SetItem(n, ls_colnames[m], ls_x)
   NEXT
NEXT

RETURN CRet.SUCCESS
end function

public function integer of_saveas (ref n_svc_mgr anv_svc, readonly powerobject apo, readonly string as_fullpath, readonly saveastype asa_type);//===========================================================================
// Function: of_Saveas (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  readonly String as_fullpath
//  readonly SaveAsType asa_type
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
Datastore lds

IF NOT of_IsServicableObject(apo) THEN RETURN CRet.FAILURE

IF of_CreateStringDatastore(anv_svc, apo, lds) = CRet.FAILURE THEN
   IF ISVALID(lds) THEN DESTROY lds
   RETURN CRet.FAILURE
END IF

lds.SaveAs(as_fullpath, asa_type, TRUE)

RETURN CRet.SUCCESS
end function

public function integer of_saveas (ref n_svc_mgr anv_svc, readonly powerobject apo);//===========================================================================
// Function: of_Saveas (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_types, ls_path, ls_file
saveastype lsa
int li_rc

IF NOT of_IsServicableObject(apo) THEN RETURN CRet.FAILURE

IF apo.DYNAMIC RowCount() <= 0 THEN 
   MessageBox("Save rows", "There are no rows to export.", Exclamation!)
   RETURN CRet.FAILURE
END IF

ls_types = "Text (Tab delimited) (*.TXT),*.TXT,"
ls_types += "CSV (Comma delimited) (*.CSV),*.CSV,"
ls_types += "SYLK (Symbolic Link) (*.SLK),*.SLK,"
ls_types += "WKS (1-2-3) (*.WKS),*.WKS,"
ls_types += "WK1 (1-2-3) (*.WK1),*.WK1,"
ls_types += "DIF (Data Interchange Format) (*.DIF),*.DIF,"
//ls_types += "DBF 2 (dBASE II) (*.DBF),*.DBF,"
ls_types += "DBF 3 (dBASE III) (*.DBF),*.DBF,"
ls_types += "SQL (SQL Insert) (*.SQL),*.SQL,"
ls_types += "PSR (Powersoft Report) (*.PSR),*.PSR,"
ls_types += "WMF (Windows Metafile) (*.WMF),*.WMF,"
ls_types += "Web Page (HTML) (*.HTM),*.HTM,"
//ls_types += "Excel 95 (*.XLS),*.XLS,"
ls_types += "Excel (*.XLS),*.XLS,"
ls_types += "XML (*.XML),*.XML,"
ls_types += "PDF (Portable Document Format) (*.PDF),*.PDF"

IF GetFileSaveName ( "Save Rows As", &
    ls_path, ls_file, "TXT", &
    ls_types) <> 1 THEN RETURN CRet.FAILURE
 
CHOOSE CASE UPPER(RIGHT(ls_file, 3))
   CASE "TXT"
      lsa = Text!
   CASE "CSV"
      lsa = CSV!
   CASE "SLK"
      lsa = SYLK!
   CASE "WKS"
      lsa = WKS!
   CASE "WK1"
      lsa = WK1!
   CASE "DIF"
      lsa = DIF!
   CASE "DBF"
      lsa = dBASE3!
   CASE "SQL"
      lsa = SQLInsert!
   CASE "PSR"
      lsa = PSReport!
   CASE "WMF"
      lsa = WMF!
   CASE "HTM"
      lsa = HTMLTable!
   CASE "XLS"
      lsa = Excel!
   CASE "XML"
      lsa = XML!
   CASE "PDF"
      lsa = PDF!
   CASE ELSE
      lsa = Text!
END CHOOSE

of_SaveAs(anv_svc, apo, ls_path, lsa)

RETURN CRet.SUCCESS
end function

public subroutine of_settabsequence (ref n_svc_mgr anv_svc, readonly powerobject apo, readonly string as_tabsequence);//===========================================================================
// Function: of_Settabsequence (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  readonly String as_tabsequence
//---------------------------------------------------------------------------
// Returns: (none)
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_colnames[], ls, ls_tabs[]
long ll_count, n
n_svc_string lnv_string

IF NOT of_IsServicableObject(apo) THEN RETURN

anv_svc.of_LoadSvc(lnv_string, CSvc.STRING)

lnv_string.of_ParseToArray(as_tabsequence, ",", ls_tabs)

ll_count = of_GetVisibleColumns(anv_svc, apo, ls_colnames)

IF UPPERBOUND(ls_tabs) = ll_count THEN
   FOR n = 1 TO ll_count
      ls += " " + ls_colnames[n] + ".TabSequence=" + ls_tabs[n]
   NEXT
   
   apo.DYNAMIC Modify(ls)
END IF
end subroutine

public function boolean of_iserrorstring (readonly string as_string);//===========================================================================
// Function: of_Iserrorstring (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly String as_string
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN (as_string = "!" OR as_string = "?")
end function

public subroutine of_settagkeyword (ref n_svc_mgr ansvc_mgr, readonly powerobject apo, readonly string as_col, readonly string as_key, readonly string as_value);//===========================================================================
// Function: of_Settagkeyword (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr ansvc_mgr
//  readonly PowerObject apo
//  readonly String as_col
//  readonly String as_key
//  readonly String as_value
//---------------------------------------------------------------------------
// Returns: (none)
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string         lst, lsk, lsn
n_svc_string   lsvc_String
n_svc_isempty  lsvc_IsEmpty

IF NOT of_IsServicableObject(apo) THEN RETURN

lst = apo.DYNAMIC Describe(as_col + ".Tag")
ansvc_mgr.of_LoadSvc(lsvc_String, Csvc.STRING)
//check if key exists
lsk = lsvc_String.of_GetKeyValue(lst, as_key, ";")
//load service
ansvc_mgr.of_LoadSvc(lsvc_IsEmpty, Csvc.ISEMPTY)

lsn = as_key + "=" + as_value + ";"

IF NOT lsvc_IsEmpty.of_IsEmpty(lsk) THEN
   lsk = as_key + "=" + lsk + ";"
   lsvc_String.of_GlobalReplace(lst, lsk, lsn, TRUE)
ELSE
   IF RIGHT(lst, 1) <> ";" THEN lst += ";"
   lst += lsn
END IF

lst = of_FixDWString(ansvc_mgr, lst)

apo.DYNAMIC Modify(as_col + ".Tag='" + lst + "'")
end subroutine

public function string of_fixdwstring (ref n_svc_mgr anv_svc, readonly string as_string);//===========================================================================
// Function: of_Fixdwstring (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly String as_string
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_string lnv_str
string ls_ret, ls[]
long ll_count, n

//special chars that require tilde (~)
ls = {"'", '"', "&"}
ll_count = UPPERBOUND(ls)
ls_ret = as_string
anv_svc.of_LoadSvc(lnv_str, CSvc.STRING)
FOR n = 1 to ll_count
   ls_ret = lnv_str.of_GlobalReplace(ls_ret, ls[n], "~~" + ls[n], TRUE)
NEXT

RETURN ls_ret
end function

public function string of_getdwstyle (readonly datawindow adw);//===========================================================================
// Function: of_Getdwstyle (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly DataWindow adw
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
RETURN adw.Describe(PROCESSING)
end function

public function string of_gettabsequence (ref n_svc_mgr anv_svc, readonly powerobject apo);//===========================================================================
// Function: of_Gettabsequence (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_ret, ls_colnames[]
long ll_count, n

IF NOT of_IsServicableObject(apo) THEN RETURN ls_ret

ll_count = of_GetVisibleColumns(anv_svc, apo, ls_colnames)
FOR n = 1 to ll_count
   ls_ret += apo.DYNAMIC Describe(ls_colnames[n] + ".TabSequence")
   IF n <> ll_count THEN ls_ret += ","
NEXT  

RETURN ls_ret
end function

public subroutine of_removedropdownarrows (ref n_svc_mgr anv_svc, readonly powerobject apo, readonly boolean ab_set);//===========================================================================
// Function: of_Removedropdownarrows (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  readonly Boolean ab_set
//---------------------------------------------------------------------------
// Returns: (none)
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
string ls_cols[], ls_type, ls_mod
long ll_count, n
string ls

IF NOT of_IsServicableObject(apo) THEN RETURN

IF ab_set THEN
   ls = "no"
ELSE
   ls = "yes"
END IF

ll_count = of_GetVisibleColumns(anv_svc, apo, ls_cols)

FOR n = 1 TO ll_count
   ls_type = of_GetColumnEditstyle(apo, ls_cols[n])
   
   IF ls_type = CDwedit.DDLB THEN
      ls_mod += " " + ls_cols[n] + ".ddlb.UseAsBorder='" + ls + "'"
   ELSEIF ls_type = CDwedit.DDDW THEN
      ls_mod += " " + ls_cols[n] + ".dddw.UseAsBorder='" + ls + "'"
   END IF
NEXT

apo.DYNAMIC Modify(ls_mod)
end subroutine

public function blob of_getsyntaxcompressed (ref n_svc_mgr anv_svc, readonly powerobject adw);//===========================================================================
// Function: of_Getsyntaxcompressed (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject adw
//---------------------------------------------------------------------------
// Returns: Blob
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
blob lb_ret
n_svc_zlib lnv_z
string ls_syntax

IF NOT of_IsServicableObject(adw) THEN RETURN lb_ret

anv_svc.of_LoadSvc(lnv_z, CSvc.ZLIB)
ls_syntax = adw.DYNAMIC Describe("Datawindow.Syntax")
lnv_z.of_compress(lb_ret, &
   BLOB(ls_syntax, EncodingANSI!))

RETURN lb_ret
end function

public function integer of_createfromcompressedsyntax (ref n_svc_mgr anv_svc, readonly powerobject adw, readonly blob ablb_compressed);//===========================================================================
// Function: of_Createfromcompressedsyntax (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject adw
//  readonly Blob ablb_compressed
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_zlib lnv_z
blob lb_expand
string ls_syntax, ls_err

IF NOT of_IsServicableObject(adw) THEN RETURN CRet.FAILURE

anv_svc.of_LoadSvc(lnv_z, CSvc.ZLIB)

lnv_z.of_uncompress(lb_expand, ablb_compressed)

ls_syntax = STRING(lb_expand, EncodingANSI!)

adw.DYNAMIC Create(ls_syntax, ls_err)

IF LEN(ls_err) > 0 THEN RETURN Cret.FAILURE

RETURN CRet.SUCCESS
end function

public function blob of_getfullstatecompressed (ref n_svc_mgr anv_svc, readonly powerobject adw);//===========================================================================
// Function: of_Getfullstatecompressed (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject adw
//---------------------------------------------------------------------------
// Returns: Blob
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
blob lb_ret, lb_state
n_svc_zlib lnv_z

IF NOT of_IsServicableObject(adw) THEN RETURN lb_ret

anv_svc.of_LoadSvc(lnv_z, CSvc.ZLIB)
IF adw.DYNAMIC GetFullState(lb_state) <> CRet.FAILURE THEN
   lnv_z.of_compress(lb_ret, lb_state)
END IF

RETURN lb_ret
end function

public function integer of_setfullstatecompressed (ref n_svc_mgr anv_svc, readonly powerobject adw, readonly blob ablb_compressed);//===========================================================================
// Function: of_Setfullstatecompressed (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject adw
//  readonly Blob ablb_compressed
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_zlib lnv_z
blob lb_expand

IF NOT of_IsServicableObject(adw) THEN RETURN CRet.FAILURE

anv_svc.of_LoadSvc(lnv_z, CSvc.ZLIB)

lnv_z.of_uncompress(lb_expand, ablb_compressed)

IF adw.DYNAMIC SetFullState(lb_expand) = Cret.FAILURE THEN RETURN Cret.FAILURE

RETURN CRet.SUCCESS
end function

public function boolean of_hasretrievalarguments (readonly powerobject apo);//===========================================================================
// Function: of_Hasretrievalarguments (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly PowerObject apo
//---------------------------------------------------------------------------
// Returns: Boolean
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
IF NOT of_IsServicableObject(apo) THEN RETURN FALSE

string ls

ls = apo.DYNAMIC Describe("Datawindow.Table.Arguments")

IF of_IsErrorString(ls) THEN ls = CString.EMPTY

RETURN ls <> CString.EMPTY
end function

public function integer of_getretrievalarguments (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_argnames[], ref string as_datatypes[]);//===========================================================================
// Function: of_Getretrievalarguments (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  reference String as_argnames[]
//  reference String as_datatypes[]
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
n_svc_string lnv_str
string ls_argstring, ls_tmp
long c, //, ll_count, n

anv_svc.of_LoadSvc(lnv_str, CSvc.STRING)

ls_argstring = apo.DYNAMIC Describe("Datawindow.Table.Arguments")

IF of_IsErrorString(ls_argstring) THEN RETURN CRet.FAILURE

DO
   ls_tmp = lnv_str.of_gettoken(ls_argstring, Char(10))
   IF ls_tmp <> CString.EMPTY THEN
      c ++
      ll_pos = POS(ls_tmp, CString.TAB)
      as_argnames[c] = MID(ls_tmp, 1, ll_pos - 1)
      as_datatypes[c] = MID(ls_tmp, ll_pos + 1)

      //make the argument name friendly
      //assign the new argument name
//    as_argnames[c] = of_MakeFriendlyName(as_argnames[c])
   END IF
LOOP WHILE ls_argstring <> CString.EMPTY

RETURN c
end function

public function string of_makefriendlyname (readonly string as_name);//===========================================================================
// Function: of_Makefriendlyname (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  readonly String as_name
//---------------------------------------------------------------------------
// Returns: String
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
char lc[]
string ls_tmp
long ll_count, n

lc = as_name
ls_tmp = CString.EMPTY
ll_count = UPPERBOUND(lc)
FOR n = 1 to ll_count
   IF n > 1 THEN
      IF lc[n] = '_' THEN 
         lc[n] = CString.SPACE
      ELSEIF lc[n - 1] = CString.SPACE THEN
         lc[n] = UPPER(lc[n])
      //check wordcap, insert space
      ELSEIF lc[n] = UPPER(lc[n]) AND &
            lc[n - 1] = LOWER(lc[n - 1]) THEN
         ls_tmp += CString.SPACE
         lc[n] = UPPER(lc[n])
      END IF
   ELSEIF n = 1 THEN
      lc[n] = UPPER(lc[n])
   END IF
   
   ls_tmp += STRING(lc[n])
NEXT

RETURN ls_tmp
end function

public function integer of_getcolumns (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_colnames[], ref string as_datatypes[]);//===========================================================================
// Function: of_Getcolumns (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  reference String as_colnames[]
//  reference String as_datatypes[]
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
integer c
long ll_count, n

IF NOT of_IsServicableObject(apo) THEN RETURN CRet.FAILURE

ll_count = of_GetColumnCount(apo)

FOR n = 1 TO ll_count
   c ++
   as_colnames[c] = apo.DYNAMIC Describe("#" + STRING(n) + ".Name")
   as_datatypes[c] = apo.DYNAMIC Describe("#" + STRING(n) + ".ColType")
NEXT

RETURN c
end function

public function integer of_getvisiblecolumns (ref n_svc_mgr anv_svc, readonly powerobject apo, ref string as_colnames[], readonly string as_bandname, readonly boolean ab_includecomputed, readonly boolean ab_sortbyx);//===========================================================================
// Function: of_Getvisiblecolumns (public )
// Object: n_svc_dw
//---------------------------------------------------------------------------
// Description:
// Note:
//---------------------------------------------------------------------------
// Parameters:
//  reference n_svc_mgr anv_svc
//  readonly PowerObject apo
//  reference String as_colnames[]
//  readonly Boolean ab_includecomputed
//  readonly Boolean ab_sortbyx
//---------------------------------------------------------------------------
// Returns: Integer
//---------------------------------------------------------------------------
// Author: (Yeyi) Gabriel B. Abulencia
//===========================================================================
integer c
long ll_count, n
string ls_tmp
n_svc_isempty lnv_check

IF NOT of_IsServicableObject(apo) THEN RETURN CRet.FAILURE

ll_count = of_GetColumnCount(apo)

anv_svc.of_LoadSvc(lnv_check, CSvc.ISEMPTY)

FOR n = 1 TO ll_count
   IF apo.DYNAMIC Describe("#" + STRING(n) + ".Visible") = "1" THEN
      IF lnv_check.of_IsEmpty(as_bandname) THEN
         c ++
         as_colnames[c] = apo.DYNAMIC Describe("#" + STRING(n) + ".Name")
      ELSE
         ls_tmp = apo.DYNAMIC Describe("#" + STRING(n) + ".Band")
         IF lower(ls_tmp) = lower(as_bandname) THEN
            c ++
            as_colnames[c] = apo.DYNAMIC Describe("#" + STRING(n) + ".Name")
         END IF
      END IF
   END IF
NEXT

//computed fields
IF ab_includecomputed THEN
   string ls_computes[], ls_dtypes[]
   
   ll_count = of_GetComputedFields(anv_svc, apo, ls_computes, ls_dtypes)
   
   FOR n = 1 TO ll_count
      IF apo.DYNAMIC Describe(ls_computes[n] + ".Visible") = "1" THEN
         IF lnv_check.of_IsEmpty(as_bandname) THEN
            c ++
            as_colnames[c] = ls_computes[n]
         ELSE
            ls_tmp = apo.DYNAMIC Describe(ls_computes[n] + ".Band")
            IF lower(ls_tmp) = lower(as_bandname) THEN
               c ++
               as_colnames[c] = ls_computes[n]
            END IF
         END IF
      END IF
   NEXT
END IF

//order columns by x position
IF ab_sortbyx THEN
   of_OrderColumnsByPositionX(apo, as_colnames)
END IF

RETURN c
end function

public function string of_getcolumnid (readonly powerobject apo, readonly string as_colname);string ls_column

IF NOT of_IsServicableObject(apo) THEN 
   SetNull(ls_column)
   RETURN ls_column
END IF

//get column name
ls_column = TRIM(apo.DYNAMIC Describe(as_colname + ".ID"))
//Set null if invalid colid
IF ISNULL(ls_column) OR TRIM(ls_column) = "" OR of_IsErrorString(ls_column) THEN
   SetNull(ls_column)
END IF
   
RETURN ls_column
end function

public function integer of_setitem (readonly powerobject apo, long al_row, string as_colname, string as_value);integer li_ret
string ls_dtype
decimal ld

IF NOT of_IsServicableObject(apo) THEN RETURN li_ret

ls_dtype = of_GetColumnDataType(apo, as_colname)

CHOOSE CASE ls_dtype
   CASE Cdwdatatype.CHAR
      li_ret = apo.DYNAMIC SetItem(al_row, as_colname, as_value)
   CASE Cdwdatatype.DECIMAL
      ld = DEC(as_value)
      li_ret = apo.DYNAMIC SetItem(al_row, as_colname, ld)
   CASE Cdwdatatype.INT, Cdwdatatype.LONG, Cdwdatatype.NUMBER, Cdwdatatype.ULONG
      li_ret = apo.DYNAMIC SetItem(al_row, as_colname, LONG(as_value))
   CASE Cdwdatatype.REAL
      li_ret = apo.DYNAMIC SetItem(al_row, as_colname, REAL(as_value))
   CASE Cdwdatatype.DATE
      li_ret = apo.DYNAMIC SetItem(al_row, as_colname, DATE(as_value))
   CASE Cdwdatatype.DATETIME
      li_ret = CRet.FAILURE //apo.DYNAMIC GetItemDateTime(al_row, as_colname)
   CASE Cdwdatatype.TIME, Cdwdatatype.TIMESTAMP
      li_ret = apo.DYNAMIC SetItem(al_row, as_colname, TIME(as_value))
   CASE ELSE
      li_ret = CRet.FAILURE
END CHOOSE

RETURN li_ret
end function

public function integer of_setitem (readonly powerobject apo, long al_row, long al_colid, string as_value);string lsc

// Get Column Name
lsc = of_GetColumnName(apo, al_colid)
// Check if Valid Colid
IF ISNULL(lsc) THEN RETURN CRet.FAILURE

RETURN of_SetItem(apo, al_row, lsc, as_value)
end function

on n_svc_dw.create
call super::create
end on

on n_svc_dw.destroy
call super::destroy
end on