Variables

cw2kirk

New Member
My code reads;

DEFINE VARIABLE MyTempTable AS CHARACTER "X(25)".
MyTempTable = "Employees".

FOR EACH MyTempTable.
Display MyTempTable.

This gives an error stating MyTempTable is not a table.

Q: Can I get Progress to read the value of MyTempTable variable ("Employees") in my FOR EACH statement?
 
U

Unregistered

Guest
This might be what you're after:

&SCOPED-DEFINE MyTempTable Employees

FOR EACH {&MyTempTable}:
DISPLAY {&MyTempTable}.
END.

HTH,

JimB.
 

cw2kirk

New Member
My real question is how do I get Progress to read the value of the variable and not the name of the variable.
My previous example was not exact because you see me hard code the name "Employees" into the variable, but in my real program the name "Employees" is the value of a field in a table that that contains all my table names.
I want to cycle through that table and perform a "for each" statement on the value of the data in the field.
I can get the value of the field into a variable , but in my "for each" statement I don't know the command/syntax to make Progress understand that I want the value of the variable and not the variable name.

Def Var MyInpTable as Char Format "X(25)".
Def Var MyCount as Int.
FOR EACH TableName.
MyInpTable = Name.
FOR EACH MyInpTable. /*??????????????*/
MyCount = MyCount + 1.
END.
Display MyCount.
END.

Any comments?
 

cw2kirk

New Member
My real question is how do I get Progress to read the value of the variable and not the name of the variable.
My previous example was not exact because you see me hard code the name "Employees" into the variable, but in my real program the name "Employees" is the value of a field in a table that that contains all my table names.
I want to cycle through that table and perform a "for each" statement on the value of the data in the field.
I can get the value of the field into a variable , but in my "for each" statement I don't know the command/syntax to make Progress understand that I want the value of the variable and not the variable name.

Def Var MyInpTable as Char Format "X(25)".
Def Var MyCount as Int.
FOR EACH TableName.
MyInpTable = Name.
FOR EACH MyInpTable. /*??????????????*/
MyCount = MyCount + 1.
END.
Display MyCount.
END.

Any comments?
 

mra

Junior???? Member
Hi!

The folowing code counts the number of rows in every user table in the database. It uses a dynamic query for each table found in _File. A static "for each" can not use dynamic table reference, so this is the only way to do it. Dynamic queries can look complicated at first, but don't panic, it's easier than it looks.


Regards
Mike



def var hBuf as handle no-undo.
def var hQry as handle no-undo.
def var i as int no-undo.

create query hQry.

for each _File where _File._File-number > 0 and _File._File-number < 32000:
create buffer hBuf for table _File._file-name.
hQry:add-buffer( hBuf ).
hQry:query-prepare( substitute( "for each &1 no-lock", _File._file-name ) ).
hQry:query-open.
hQry:get-first.
i = 0.
do while not hQry:query-off-end:
i = i + 1.
hQry:get-next.
end.
disp substitute( "Number of rows in table '&1' is &2", _File._file-name, string( i ) ) format "x(60)".
hQry:query-close.
delete object hBuf.
end.
 
Top