/* getdyn.p
*
* run ./getdyn.p ( "customer", "where custNum = 1", "name,custNum,state,xyzzy", output resultList ).
*
*/
define input parameter tableName as character no-undo.
define input parameter whereClause as character no-undo.
define input parameter fieldList as character no-undo.
define output parameter resultList as character no-undo.
define variable b as handle no-undo.
define variable q as handle no-undo.
define variable qs as character no-undo.
define variable fv as character no-undo.
define variable i as integer no-undo.
resultList = ?.
qs = substitute( "for each &1 &2", tableName, whereClause ).
/* message qs. */
create query q.
create buffer b for table tableName.
q:set-buffers( b ).
q:query-prepare( qs ).
q:query-open.
if q:get-next( no-lock ) = false then
do:
message "record not found: " qs.
return.
end.
do i = 1 to num-entries( fieldList ):
resultList = resultList + ( if i > 1 then "," else "" ).
assign
fv = ?
fv = b:buffer-field( entry( i, fieldList )):buffer-value()
no-error.
resultList = resultList + quoter( fv ).
end.
return.