FOR EACH statement & table name

mapr

New Member
Hi everybody,
I am new to Progress and currently getting known to 4GL. I wanted to write a small application, which reads the name of a table, counts the amount of records in the table an writes out this number. It could look like this:

DEFINE VARIABLE myCounter AS INTEGER.
DEFINE VARIABLE tableName AS CHARACTER.

/* The code in the trigger: */

myCounter = 0.
ASSIGN tableName = FILL-IN-2:SCREEN-VALUE.

FOR EACH tableName:
myCounter = myCounter + 1.
END.

ASSIGN FILL-IN-4:SCREEN-VALUE = STRING(billigCounter).

It won't compile, because 'tableName' isn't a valid table name. What kind of variable do I have to define so that 'tableName' is not recognized as a table, but as a variable which holds the table name ???

Thanks in advance

Mario
 
Try this (V9+)
Code:
DEF VAR hBuffer AS HANDLE NO-UNDO.
DEF VAR hQuery  AS HANDLE NO-UNDO.
DEF VAR billigCounter AS INT NO-UNDO.
DEF VAR cTable AS CHAR NO-UNDO.
ASSIGN cTable = FILL-IN-2:SCREEN-VALUE.
CREATE BUFFER hBuffer FOR TABLE cTable.
CREATE QUERY hQuery.
hQuery:ADD-BUFFER(hBuffer).
hQuery:QUERY-PREPARE("FOR EACH " + hBuffer:TABLE).
hQuery:QUERY-OPEN.
hQuery:GET-FIRST(NO-LOCK).
REPEAT :
  IF hQuery:QUERY-OFF-END THEN
	LEAVE.
  billigCounter = billigCounter + 1.
  hQuery:GET-NEXT(NO-LOCK).
END.
ASSIGN FILL-IN-4:SCREEN-VALUE = STRING(billigCounter).
DELETE OBJECT hQuery NO-ERROR.
DELETE OBJECT hBuffer NO-ERROR.
 
Thanks very much !
Do I guess right, that you can refer to progress objects only through the handle variables?! In the manual are mentioned a few handles I can define, but the corresponding methods I can only find in the language reference ... is there somewhere an object model of the progress objects and its properties ??

Thanks
Mario
 
Back
Top