• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Question Get Query From Browse

#1
Hi.

I´m developing a new classes to show information using telerik controls. I have the .p files that have the query and show the information now, so I want to sustituded the display in the .p for my new class using telerik, but I have a problem because I can´t get the query that is executed in the .p file. It is a way to get the query or the data of the browse in the .p file to pass it to the new class?
I see this link but I couldn´t get the query from the browse

Question - Scoped-define Query

Thx!! All your help will be appreciated.
 

Osborne

Active Member
#2
If you use QUERY-PREPARE instead of OPEN QUERY in the .p file you can pass the query details to the class:
Code:
bCusts:QUERY:QUERY-PREPARE("FOR EACH Customer NO-LOCK").
myClass:PassQuery(bCusts:QUERY:PREPARE-STRING).
Failing that, to access the data pass the browse handle to the class and in the class get the handle of the browse query:
Code:
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.

hQuery = pBrowse:QUERY.
hQuery:GET-FIRST().
DO WHILE NOT hQuery:QUERY-OFF-END
...
 
#3
Hi, Osborne.

Thanks for your help. I don´t have a QUERY-PREPARE in the .p file. So I pass the handler to the class but I can´t use the query or get the data, this is my code in the .p:

DEFINE VARIABLE a AS CLASS testeaj.
a = NEW testeaj(brw-tab:HANDLE).


If I do this in the class It has a error because it doesn´t run a Get method on query:

HQueryBD = brw-query:QUERY.
HQueryBD:GET-FIRST ().
DO WHILE NOT HQueryBD:QUERY-OFF-END:

MESSAGE "In"
VIEW-AS ALERT-BOX.
END.


This is the error:

upload_2017-4-7_11-51-29.png

If I put and QUERY-OPEN It ask me for a QUERY-PREPARE

upload_2017-4-7_11-54-16.png

The definition of the browse and the qury in the .p is:

DEFINE QUERY qr-tab FOR tg_pais .
DEFINE BROWSE brw-tab QUERY qr-tab
DISPLAY tg_pais.pais_cod
tg_pais.pais_descr
WITH 18 down separators FONT 4 SIZE 40 BY 14 .



Thx for your help.
 

Osborne

Active Member
#4
Ah, if the query is not being opened in the .p file then the class needs to open it. Try something like the following:
Code:
/* Prog */
DEFINE VARIABLE a AS CLASS testeaj.

brw-tab:QUERY:QUERY-PREPARE("FOR EACH tg_pais NO-LOCK").
a = NEW testeaj(brw-tab:HANDLE).

/* Class */
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
DEFINE VARIABLE HQueryBD AS HANDLE NO-UNDO.

HQueryBD = brw-query:QUERY.
hBuffer = HQueryBD:GET-BUFFER-HANDLE(1).
hField = hBuffer:BUFFER-FIELD(1).
HQueryBD:QUERY-OPEN().
HQueryBD:GET-FIRST().
DO WHILE NOT HQueryBD:QUERY-OFF-END:
   MESSAGE "In" VIEW-AS ALERT-BOX.
   MESSAGE "First field value =" hField:BUFFER-VALUE VIEW-AS ALERT-BOX.
   /* HQueryBD:GET-NEXT(). */ LEAVE.
END.
 
Last edited:
#5
Hi, Osborne.

Thx for your help.

I put the code in the .p and the other in the class, but it has the next errors:

upload_2017-4-7_14-28-23.png

upload_2017-4-7_14-29-42.png

Any idea? because in the class I don´t have the query string. I try to pass it but I couldn´t get it in the class

thx a lot.
 

Osborne

Active Member
#6
Sorry, typo error on my part as missed out the EACH. In the .p the extra line required should be:
Code:
brw-tab:QUERY:QUERY-PREPARE("FOR EACH tg_pais NO-LOCK").
 
#7
Hi, Osborne.

Excellent thx for your help, but I still can´t get the query the message error is that the query is already link to a brwose ABL. It is a way of get number of fileds that the query return for show it all in the new class?

Thx.
 

Osborne

Active Member
#8
If I understand it correctly, you do not want to use the actual browse query from the .p file, but build dynamically in the class from all the parts that make up the browse, is that correct?

If so, then yes this can be done. As mentioned, in the .p file you need to add the QUERY-PREPARE line and pass the browse handle to the class, then build from the passed browse handle using some of the parts outlined here: Progress KB - Sample Code to Create Dynamic Browser.

Getting the tables the browse contains:
Code:
DO i = 1 TO brw-query:QUERY:NUM-BUFFERS:
   hQuery:ADD-BUFFER(brw-query:QUERY:GET-BUFFER-HANDLE(i)).
END.
Getting the fields the browse contains:
Code:
DO i = 1 TO brw-query:NUM-COLUMNS:
   hColumn = brw-query:GET-BROWSE-COLUMN(i).
   IF hColumn:NAME = ? THEN.  /* Calculated column */
   ELSE. /* Database field */
END.
Use the query criteria as per the browse and open:
Code:
hQuery:QUERY-PREPARE(brw-query:QUERY:PREPARE-STRING).
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().
DO WHILE NOT hQuery:QUERY-OFF-END:
   MESSAGE "In" VIEW-AS ALERT-BOX.
   /* hQuery:GET-NEXT(). */ LEAVE.
END.
 
Last edited: