store field name into variable

rinoesc

New Member
Hello everybody,

It is possible to store a database field name into a variable for further use in queries like the one below.


Code:
def var x as char.
x = "field_name";

for each table where x = "value" ...

I'm asking you because I have a report which have a "for each" that breaks by many fields an I have to calculate subtotals. I'm doing this with procedures. Now I send only the value of a field to that procedure and I want to send also the field name so that I don't have to create tens of procedures for all the situations.
Code now is something like this:

Code:
for each temp-table ... break by field1 by field2 by field3:
.....
if last-of (field3) then run procedure calc_prod (input field3_value)
....
end.

procedure calc_prod:
def input parameter field3_value like db_field.
for each totals_table where field3 = field3_value break by other fields:
....code
end.

I want to write fewer procedures like the one below
Code:
for each temp-table ... break by field1 by field2 by field3:
.....
if last-of (field3) then run procedure calc_prod (input field3_name field3_value)
....
end.

procedure calc_prod:
def input parameter field3_name as char
def input parameter field3_value as char.
for each totals_table where field3_name = field3_value break by other fields:
....code
end.

So the system will now that field3_name contains the name of the field and has field3_value as the value of it.


Thank you very much and I hope I made myself clear. ;)
 
That is only possible with dynamic buffers and dynamic queries.

All examples you've posted show only static references. Static references are determined at compile at and can't be changed dynamically at runtime - therefore the code you've posted does not allow you to change the field names at runtime, it won't even compile.

You need to dig into dynamic objects and handles to static objects in order to achieve what you want. And yes, with dynamic objects it's possible.


Heavy Regards, RealHeavyDude.
 
Around ten years ago, amongst other things, dynamic object where introduced with Progress V9. Before that there was no way to make dynamic references to database or temp-table objects. For 4GL developers at that time this was somehow revolutionary - now it should be common knowledge.

Since the functionality is in the product that long and the power it embodies, I still wonder why the knowledge about it has not spread in the developer community.

Plus, in the good ole static days the Progress 4GL almost took care of everything complex for you. You didn't really care much about what you really do when you reference database objects just out-of-magic. Now with dynamic objects you really need to take care of them. You create them - you delete them. Otherwise you will produce memory leaks. Even the garbage collection introduced with OpenEdge 10.2A does not cope with such handle based objects ...


Heavy Regards, RealHeavyDude.
 
I’m afraid its the same old story with progress... the help not that helpful or a least thats my Experience so wanted to code well feels like a very hard slog
 
IMHO:

You can use the 4GL for very simple programing using FOR EACH constructs as well as very complex applications and frameworks. Most people, when they hear 4GL, think it must be a very simple language which an be learned in a matter of days and that's probably one reason why managers are reluctant spending money on educating their developers. That's probably one of the reasons that lead Progress to change the name from 4GL to ABL ( advanced business language - whatever that is supposed to mean to us ).

In the end if developers don't get the chance to stay on top of the technology they work with in getting proper training from time to time it seems more than natural to me that they won't know the "new" features and therefore will not be able to use them properly.

In the past I run many Progress related trainings in many parts of the world. In almost all cases they were offered as standard trainings. But after a negotiation between sales resp and managers they turned out to be so-called individual trainings. That almost always meant that the content stayed the same but somehow the powers that be thought that half or less of the time originally planned should be sufficient.

To me that was always very frustrating because I thought it's better for the students to understand the concept and look for a particular syntax in the manual instead of just presenting them new syntax. But understanding a concept - from my experience - takes much more time that just being able to reproduce plain syntax.

Even working as a consultant for huge companies in the financial sector I did not see anything different when it came to training. Most of these companies pretend that people make the difference and that their employees are their most important asset. From my experience I can tell you that most of these companies don't live up to their own standards. Especially when it comes to training.

While it might be possible to learn everything about syntax from the documentation and online help - IMHO - I think proper training is the best foundation to understand.


Heavy Regards, RealHeavyDude.
 
I agree training has its place. Its just the lack of documentation on progress (or at least its style) doesn’t help. I've used many good books and online resources for VB/C# etc in the past to do what I need to do. but thats just my 2 cents
 
thank you for your help. i finally solved the main problem. but now i have another one. i have to calculate some intermediate sums. and i have to break by some fields. but old fashion "if first-of(field)" doesn't work.

Code:
def var qh as widget-handle.
def var qs as char.
create query qh.
qh:set-buffers(buffer ttot:handle).
qh:query-prepare("for each bla break by bla1 by bla2").
qh:query-open.
repeat:
qh:get-next().
if qh:query-off-end then leave.

      and here i want something like this
      if first(bla1) then do:
            value1= 0.
      end. /*first bla1*/
      value1 = value1 + 1.
      if last-of(bla1) then do:
            disp "bla1 = " + value1.
      end.

end.
qh:query-close().
delete object qh.

when i run the program, when it reaches the line "first-of..." the compiler tells me that it is missing the break by clause in the query.
how can i solve the problem.

thank you
 
jmac12 is right.

You can not mix and match dynamic and static references. Your either reference everything dynamic ( with the handle to the objects ) or static ( with the object names as in their define statement ).


Heavy Regards, RealHeavyDude.
 
Back
Top