Error Error - 7317 - Dataset issue - Noobie.

Massis

New Member
I have tried to create a dataset fill example however i keep running into the same error:

When i run the code below I get the following error: ADD/SET-BUFFERS may not be used on static query qTradep.

The results i get back are in the attachments, The customer table is filled with 0(s) instead of their respective database values.

Please let me know if you need any other information.

Code:
USING Progress.Lang.*.



CLASS listandlabeltable:


DEFINE TEMP-TABLE ttTradep
   FIELD TRADING_PARTNER_NUMBER AS INTEGER
   FIELD CUSTOMER_FLAG AS LOGICAL
   INDEX trading_partner_number IS UNIQUE PRIMARY Trading_partner_number.

   DEFINE TEMP-TABLE ttCust
   FIELD TRADING_PARTNER_NUMBER AS INTEGER
   FIELD CUSTOMER_REFERENCE AS INTEGER
   FIELD MAXIMUM_CREDIT_LIMIT AS INTEGER
   INDEX trading_partner_number IS UNIQUE PRIMARY trading_partner_number.


        /*ProDataSet definition*/
     DEFINE DATASET dstest FOR ttTradep, ttcust
     DATA-RELATION drTradeToCust FOR ttTradep, ttCust
     RELATION-FIELDS (trading_partner_number,trading_partner_number).
 
      /*data-source definitions*/      
     DEFINE QUERY qTradep FOR TRADING_PARTNER.
     DEFINE DATA-SOURCE srcTradep FOR QUERY qTradep.
     DEFINE DATA-SOURCE srcCust FOR CUSTOMER.
 
   
    CONSTRUCTOR PUBLIC listandlabeltable ():
    DO:
            
   
       /*Attaching data sources*/
       BUFFER ttTradep:ATTACH-DATA-SOURCE(DATA-SOURCE srcTradep:HANDLE,?,?).
       BUFFER ttCust:ATTACH-DATA-SOURCE(DATA-SOURCE srcCust:HANDLE,?,?).
       
      DEFINE VARIABLE lvc AS CHARACTER NO-UNDO.
      lvc =  "FOR EACH TRADING_PARTNER".
/*        lvc =  "FOR EACH TRADING_PARTNER WHERE TRADING_PARTNER.TRADING_PARTNER_NUMBER EQ 6417".*/

      /* Top-level and child query preparation*/
       QUERY qTradep:ADD-BUFFER ("customer").
       QUERY qTradep:QUERY-PREPARE(lvc).

 
        /*populate dataset*/
        DATASET dstest:FILL().
   
        FOR EACH ttTradep:
           DISPLAY ttTradep.TRADING_PARTNER_NUMBER
                   ttTradep.CUSTOMER_FLAG WITH FRAME tttradeframe 1 COL
                   TITLE "Trading partners".
                   FOR EACH ttCust OF ttTradep:
                       DISPLAY ttCust.CUSTOMER_REFERENCE
                       ttCust.MAXIMUM_CREDIT_LIMIT WITH FRAME ttCustomerFrame 1 COL
                       TITLE "Customer".
                   END.
        END.
        END.
   END.
END CLASS.
 

Attachments

Last edited:

Cringer

ProgressTalk.com Moderator
Staff member
You're mixing your dynamic and static queries. Why do you need to ADD-BUFFER for customer? It's not in the query string. If you did want to add it to the query string then you would need to
DEFINE QUERY qTradep FOR TRADING_PARTNER,Customer.
And you can't query-prepare a static query either.
 

mollyfud

Member
Okay, so you shouldn't need to have a query as such for the child record as it should work off the parent record. It fills the parent record, and I hope I explain it somewhat correctly, then fills out the child records that are needed. So for Orders, it would get all the orderlines of the orders. You don't need a seperate query.

You can see a working example of it for Orders, Orderlines and items in this article.

Hope this helps.
 

Cringer

ProgressTalk.com Moderator
Staff member
Apologies, yes I forgot it was a dataset.
The point still remains you can't add buffers for a static query.
Have you tried copying that example verbatim and modifying to suit your needs?
 

Massis

New Member
Thank you for your time, I was actually working from a white star software training book example. I pretty much modified the example replacing it for my required fields which gave me the error. I will try using the verbatim example for this and get back to you.
 

Cringer

ProgressTalk.com Moderator
Staff member
Do you know the difference between a static and a dynamic query? Might be worth having a look at examples of both for your own edification :)
 

Massis

New Member
I have worked with both, but i can tell it would probably help if i revised it more. Where would i be able to find an example of both?
 

Cringer

ProgressTalk.com Moderator
Staff member
Static:
Code:
DEFINE QUERY qCustomer FOR Customer.

open query qcustomer for each customer no-lock. 

do while query qCustomer:GET-NEXT():
  /*something*/
end. 

close query qCustomer.
Dynamic
Code:
DEFINE VARIABLE lv-Query  AS HANDLE NO-UNDO. 
DEFINE VARIABLE lv-Buffer AS HANDLE NO-UNDO. 


CREATE BUFFER lv-Buffer FOR TABLE "Customer".
CREATE QUERY lv-Query.
lv-Query:SET-BUFFERS(lv-Buffer).
lv-Query:QUERY-PREPARE("FOR EACH Customer NO-LOCK").
lv-Query:QUERY-OPEN() NO-ERROR. 

DO WHILE lv-Query:GET-NEXT():
  /*Something*/
end. 

delete object lv-Query.
Obviously you can do much more clever stuff with either. For example we have a library that you can throw a query string at and it will work out what buffers are needed. The advantage therefore of a dynamic query is that you can have different buffers, and therefore different query strings depending on context. The disadvantage is that they can be more complicated to write if all you need is a simple for each.
 

RealHeavyDude

Well-Known Member
The main difference of a static vs. dynmic query is that a static query gets resolved at compile time whereas a dynamic query gets resolved at runtime. Being resolved at compile time has its consequences. For example for a query it means that you cannot change the buffer it uses although you can change other attributes the same way than you can with a dynamic query when you grab the handle to the static query object.

Another difference is the life cycle of the object. Static means that the ABL takes care of the object since it is automatically scoped correctly at compile time - there is nothing you need to take care of in your code. Dynamic means that you need to take care of the objects's life cycle because it is completely handled at runtime. The rule of thumb is: You create it, you delete it in your code explicitely - otherwise you will most likely introduce a memory leak into your application.

Usually static objects involve less code than dynamic objects and the code is more straightforward.

I for myself would only use dynamic objects when I need their flexibility - not just for the sake of coding dynamic. On the other hand dynamic objects open up a new world when it comes to generic, re-usable code.

Heavy Regards, RealHeavyDude.
 
Top