LogiView

Function 'sel_value'

     

This function is used to read a database value.

If only one of the quantity functions 'min', 'max', 'sum', 'avg' or 'count' is executed, the 'sel_value' function returns an "integer" or "float" type value according to the result of the function.

Otherwise the table column to be read must be either "integer" type or "float" type.

If the function is called using the Where clause "actual', LogiView tries to read the table field value from the current mask.

If the number of values which are returned by the where clause is unknown, it is possible to call sel_value(count) and proceed with the programming depending on the result. If the result > 1 , an array must be read-in.

Example:
RES=sel_value(count({FLD}),{WHERE|actual})
if(RES==0)
   put("No result")
elseif(RES==1)
  {DAT_VAR}= sel_value({FLD},{WHERE|actual})else
else
  {DAT_VAR}= sel_value({FLD},{WHERE|actual})else
endif

OR:

If the number of values which are returned is >1, the returned number of found records is stored in REC_NR.

Example:

ART_ID=sel_value("T_MASTER_DAT.C_ID","T_MASTER_DAT.PART_ID"="screw%",REC_NR)

(Variable declaration: ART_ID = integer variable / REC_NR = integer variable)

 

Syntax:

 

{INT_VAR|FLO_VAR}= sel_value({FLD},{WHERE|actual}),
{INT_VAR|FLO_VAR}=sel_value(FLD},{WHERE},{INT_VAR}) or
{INT_VAR|FLO_VAR}= sel_value({DBF}({FLD}),{WHERE}) or
{INT_VAR|FLO_VAR}= sel_value(act_fld)

 

I/O parameters:

{FLD} Name of a table field in the format "table name.column name".
{WHERE|actual} Where clause followed by the database access (see explanation field menu {WHERE} or {actual}).
{DBF} Database quantity function: 'avg', 'count', 'min', 'max' or 'sum'. These functions can be combined with the 'actual' Where clause!

avg

The 'avg' quantity function determines the average of all entries in the specified table field that correspond to the Where clause of the 'sel_value' function. The function can only applied to "integer" or "float" type table fields; the result corresponds to the type of table field.

count

This quantity function determines the number of different entries in the specified table field that correspond to the Where clause of the 'sel_value' function. The function can applied to table fields of any type; the result of the function is an integer value.

If a counter query is performed using the LGV command "sel_value(count(...))", also the "distinct" command is executed in the Select command on database level.

This may have a great effect because multiple occurances of identical records also return a result of "1". Assuming to have only one corresponding record in the database and accessing this record using another command (e.g. sel_string) this would cause the display of selection menus in several records.

min

This quantity function determines the lowest entry in the specified table field for all records that correspond to the Where clause of the 'sel_value' function. The function can only applied to "integer" or "float" type table fields; the result corresponds to the type of table field.

max

This quantity function determines the greatest entry in the specified table field for all records that correspond to the Where clause of the 'sel_value' function. The function can only applied to "integer" or "float" type table fields; the result corresponds to the type of table field.

sum

This quantity function determines the sum of all entries in the specified table field that correspond to the Where clause of the 'sel_value' function. The function can only applied to "integer" or "float" type table fields; the result corresponds to the type of table field.

act_fld

The keyword "act_fld" defines the access to the current (mask) field without the necessity to know its name. "Act_fld" represents a unique and complete Where clause; therefore, using further Where clauses is excluded.

"Act_fld" can only be used if LogiView is called as "pre-field" or "post-field" userexit.

  In this case no database access is necessary. However, the mask contents may vary from the actual database contents unless an update was performed just before.
{INT_VAR} Number of found records.
-  
 

Return value:

 
{INT_VAR|FLO_VAR} Value read from the database.
 

Example:

  Declaration of Variables
 
30 DOCU_INT_1=sel_value(min("MAT.ISO"),"MAT.NAME"= "maho-%")
  Result:
  The function determines the lowest field entry of all records of the "MAT" table with a field corresponding to "maho-%". Then this contents is assigned to the integer variable DOCU_INT_1.

Functions and commands: DB/Mask Interface