Re: HELP - Using a cursor in 4gl
Posted in 1996
> Alberto Pardo Fernandez wrote: > > > > Hi. > > > > I need to recover data from a table in a 4gl program. I dont know neither the > > table name nor the table structure at compile time. Although I can find it out > > at run time, I cant declare a record with DEFINE my_record RECORD LIKE tabname.* > > (tabname is a variable that holds the name of my table). > You can prepare a statement to place all the fields you want to retrieve in a string format, thus you will be able to extract from the string all the values, using a delimiter. (eg. Suppose you have the following variables: sql_st CHAR(200) -- The Sql statement that will be created dynamically StrReturned CHAR(200) -- You should increase this value, depending on the row size -- in characters MyTable, MyField1,Myfield2 char(20) LET sql_st = 'select ',Myfield1 CLIPPED,'||','";"','||', Myfield2 CLIPPED,' from ',MyTable CLIPPED PREPARE prepSt from sql_st DECLARE myCur CURSOR FOR prepSt FOREACH myCur INTO StrReturned -- All the values in the String variable, separated -- by the delimiter( in this case the semicolon ; ) -- Extract any field , convert it, work on it etc. END FOREACH I tested this sql statement using the semicolon ; as a delimiter between fields, but you can use anything you want to delimit each field. select field1||";"||field2||";"||field3...||field? FROM table the result string will be something like: 0100;02/09/1996;Hi Pal! The next step is to extract it from the string variable. I hope this help, ---------------------------------------- Mario Estrada Rosa | LESCO, S.A. Systems Engineer | Guatemala, | Central America Phone (502) 3318116 | Fax (502) 3348447 | ---------------------------------------