I am fairly new to Progress and even newer to handles so apologies if I have missed anything obvious, I've looked online but am yet to find what I'm looking for.
I am running a dynamic query similar to the below, in this example after then query is run, the "age" field of the corrresponding record is displayed on screen, I understand how this is done from the buffer-field attribute-method, but my question is how do I display the entire record, is there an equivalent attribute method, or have I misunderstood something crucial?. Thank you for your time. :
def var tbl as character no-undo.
def var fld as character no-undo.
def var qh as handle no-undo.
def var bh as handle no-undo.
def var fh as handle no-undo.
assign tbl = "customer".
assign fld = "age".
create buffer bh for table tbl.
create query qh.
qh:set-buffers( bh ).
qh:query-prepare( "for each " + tbl + " where name = 'tom'" ).
qh:query-open.
do transaction:
qh:get-first( no-lock ).
fh = bh:buffer-field( fld ).
display fh:buffer-value.
end.
delete object bh.
delete object qh
There's no "easy" way to display the entire record in one statement the way you can with a static "DISPLAY table-name" statement. You can get the count of fields (buffer-handle:NUM-FIELDS) and then step through the individual fields and display their values using
DO i = 1 to bh:NUM-FIELDS:
DISPLAY bh:BUFFER-FIELD(i):BUFFER-VALUE WITH DOWN.
DOWN.
END.
create query qh.
qh:set-buffers( bh ).
qh:query-prepare( "for each " + tbl + " where name = 'tom'" ).
qh:query-open.
qh:GET-FIRST().
DO while qh:QUERY-OFF-END = False:
DO i = 1 TO bh:NUM-FIELDS:
display bh:BUFFER-FIELD (i):NAME STRING(bh:BUFFER-FIELD(i):BUFFER-VALUE) with down.
down.
END.
qh:GET-NEXT ().
END.
Related
Table :wod_det
In wod_det table i want count for wod_qty_req for all orders
means wod_nbr is a work order for each order there will be component items will be there i.e wod_part for these wod_part there will be wod_qty_req so what i want is each work order i nee count of wod_qty_req for all wod_part i tried like this
{us/mf/mfdtitle.i}
def var site like si_site no-undo.
for first si_mstr no-lock where si_mstr.si_domain = global_domain:
site = si_site.
end.
for each wod_det where wod_domain = global_domain and wod_site = site no-lock break by wod_nbr by wod_part:
if first-of(wod_nbr) then
do:
accumulate wod_qty_req (count).
if last-of(wod_part) then
do:
disp wod_nbr wod_part wod_qty_req (accum count wod_qty_req).
end.
end.
end.
i don't know whether this is correct or not but i didnt get any output for this plz help me out this to resolve?
Thanks in advance..
Here is the Image of table wod_det
answer:
define variable iCount as integer no-undo.
{us/mf/mfdtitle.i}
def var site like si_site no-undo.
def var total like wod_qty_req initial 0 no-undo.
for first si_mstr no-lock where si_mstr.si_domain = global_domain:
site = si_site.
end.
for each wod_det no-lock where wod_domain = global_domain
and wod_site = site break by wod_nbr:
disp wod_nbr wod_part wod_qty_req(total by wod_nbr).
end.
Edited: based on more information.
I personally never use the ACCUM, ACCUMULATE etc functions but that might be my personal preferences.
NB: I don't know exactly what fields correspond to the information in the image so I will describe this in "pseudo" code. Exchange [WORK_ORDER_FIELD] field names to match the correct field in your database!
define variable iCount as integer no-undo.
{us/mf/mfdtitle.i}
def var site like si_site no-undo.
for first si_mstr no-lock where si_mstr.si_domain = global_domain:
site = si_site.
end.
for each wod_det no-lock where wod_domain = global_domain
and wod_site = site
break by wod_det.[WORK_ORDER_FIELD]:
iCount = 0.
if first-of(wod_det.[WORK_ORDER_FIELD]) then do:
iCount = iCount + 1.
end.
display od_det.[WORK_ORDER_FIELD] iCount.
end.
Program:It is a just maintenance program, in this one it displays the Item Code in one frame and it prompt for the input. if you enter the item code it has to displays what are the blank fields for that record in pt_mstr and display in one frame(No need to display all blank fields, just first 4 or 5 fields enough). and also in that frame only if user want to update it update directly to main table pt_mstr.
What i tried is, i just write the code for getting blank fields using buffer handle and after that i create one temp table and displaying the fields, i strucked there itself, i am unable to update fields.
My code:
/*Sample Item master Maintenance Program*/
/* DISPLAY TITLE */
{us/mf/mfdtitle.i "3+ "}
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE j AS INTEGER NO-UNDO.
DEFINE VARIABLE hField AS HANDLE NO-UNDO.
define variable fldnm as character extent 10 no-undo.
define temp-table tt_temp no-undo
field tt_part like pt_part
field field1 as char extent 10.
form
pt_part colon 25
with frame a side-labels width 80.
setFrameLabels(frame a:handle).
/* DISPLAY */
view frame a.
repeat with frame a:
prompt-for pt_part
editing:
/* FIND NEXT/PREVIOUS RECORD */
{us/mf/mfnp.i pt_mstr pt_part "pt_mstr.pt_domain = global_domain and pt_part" pt_part pt_part pt_part }
if recno <> ? then
do:
display pt_part.
find pt_mstr where pt_part = input pt_part and pt_domain=global_domain no-lock no-error.
ASSIGN hBuffer = BUFFER pt_mstr:HANDLE.
empty temp-table tt_temp.
j = 1.
DO i = 1 TO 10:
ASSIGN hField = hBuffer:BUFFER-FIELD(i).
IF ((hField:BUFFER-VALUE = "" )) THEN
do:
/* message hField:NAME "test" view-as alert-box.*/
find first tt_temp where tt_part = pt_part no-lock no-error.
if not avail tt_temp then
do:
create tt_temp.
assign
tt_part = pt_part
field1[j] = hField:NAME.
j = j + 1.
end.
else do:
assign
field1[j] = hField:NAME.
j = j + 1.
end.
end.
end.
end.
for each tt_temp:
display field1[1] field1[2] field1[3] field1[4].
end.
end.
end.
Are you sure you need your temp-tables to do this? I've created an example using only the actual table (but created a fake temp-table instead). You would have to look into data error handling, data validation, transaction, locking etc before putting this into production of course.
/*First we need some fake data */
DEFINE TEMP-TABLE ttMockedData NO-UNDO
FIELD id AS INTEGER
FIELD dataName AS CHARACTER FORMAT "x(8)"
FIELD dataType AS CHARACTER FORMAT "x(8)"
FIELD dataDescrioption AS CHARACTER FORMAT "x(32)".
DEFINE VARIABLE iId AS INTEGER NO-UNDO.
DEFINE VARIABLE iSearch AS INTEGER NO-UNDO LABEL "Search".
PROCEDURE createData:
DEFINE INPUT PARAMETER pcName AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcType AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcDesc AS CHARACTER NO-UNDO.
iId = iId + 1.
CREATE ttMockedData.
ASSIGN
ttMockedData.id = iId
ttMockedData.dataName = pcName
ttMockedData.dataType = pcType
ttMockedData.dataDesc = pcDesc.
END PROCEDURE.
RUN createData("Test 1", "TESTTYPE", "A TEST").
RUN createData("Test 2", "", "ANOTHER TEST").
RUN createData("", "TESTTYPE 2", "").
RUN createData("4", "", "").
/* Program starts here */
updating:
REPEAT:
UPDATE iSearch WITH FRAME x0.
IF iSearch > 0 THEN DO:
FIND FIRST ttMockedData NO-LOCK WHERE ttMockedData.id = iSearch NO-ERROR.
IF NOT AVAILABLE ttMockedData THEN DO:
MESSAGE "Not found" VIEW-AS ALERT-BOX ERROR.
RETURN ERROR.
END.
ELSE DO:
DISP ttMockedData WITH FRAME x1 1 COLUMNS SIDE-LABELS.
/* Is there an empty field? - Then we update! */
IF ttMockedData.dataName = ""
OR ttMockedData.dataType = ""
OR ttMockedData.dataDescrioption = "" THEN DO:
DISPLAY
ttMockedData.dataName
ttMockedData.DataType
ttMockedData.dataDesc
WITH FRAME x2 1 COLUMN SIDE-LABELS TITLE "Complete the data...".
/* This isn't working with temp-tables of course! */
/* Just here to make sure you handle locking! */
FIND CURRENT ttMockedData EXCLUSIVE-LOCK.
UPDATE
ttMockedData.dataName WHEN ttMockedData.dataName = ""
ttMockedData.DataType WHEN ttMockedData.DataType = ""
ttMockedData.dataDesc WHEN ttMockedData.dataDesc = ""
WITH FRAME x2.
/* This isn't working with temp-tables of course! */
/* Just here to make sure you handle locking! */
FIND CURRENT ttMockedData NO-LOCK.
END.
END.
END.
ELSE LEAVE updating.
END.
I'm trying to write a modular procedure, where I pass in a string representation of a table name, and query/update that table.
What I tried was something to this affect:
PROCEDURE foo:
DEFINE INPUT PARAMETER chTableName AS CHARACTER NO-UNDO.
FIND FIRST VALUE(chTableName) NO-LOCK
WHERE blahblahblah NO-ERROR.
IF AVAIL VALUE(chTableName) THEN
ASSIGN
VALUE(chTableName).value = foo.
END PROCEDURE.
This obviously does not work, but hopefully this will get the point across of what I'm trying to accomplish.
Any help or info in this matter would be appreciated. Thanks.
Hopefully you are running version 9 or better where dynamic queries are available.
procedure x:
define input parameter tbl as character no-undo.
define input parameter fld as character no-undo.
define input parameter xyz as character no-undo.
define variable qh as handle no-undo.
define variable bh as handle no-undo.
define variable fh as handle no-undo.
create buffer bh for table tbl.
create query qh.
qh:set-buffers( bh ).
qh:query-prepare( "for each " + tbl ).
qh:query-open.
do transaction:
qh:get-first( exclusive-lock ).
fh = bh:buffer-field( fld ).
display fh:buffer-value.
fh:buffer-value = xyz.
end.
delete object bh.
delete object qh.
return.
end.
run x ( "customer", "name", "fred" ).
find first customer no-lock.
display name.
This can get you started:
DEFINE TEMP-TABLE tt NO-UNDO
FIELD a AS INTEGER.
PROCEDURE foo:
DEFINE INPUT PARAMETER pcTable AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcWhere AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER pcField AS CHARACTER NO-UNDO.
DEFINE INPUT PARAMETER piValue AS INTEGER NO-UNDO.
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hQuery AS HANDLE NO-UNDO.
CREATE BUFFER hBuffer FOR TABLE pcTable.
CREATE QUERY hQuery.
hQuery:SET-BUFFERS(hBuffer).
hQuery:QUERY-PREPARE("FOR EACH " + pcTable + " WHERE " + pcWhere).
hQuery:QUERY-OPEN().
hQuery:GET-FIRST().
IF hBuffer:AVAILABLE THEN DO:
ASSIGN
hBuffer:BUFFER-FIELD(pcField):BUFFER-VALUE = piValue NO-ERROR.
IF ERROR-STATUS:ERROR THEN DO:
MESSAGE "Failed" VIEW-AS ALERT-BOX ERROR.
END.
END.
DELETE OBJECT hBuffer.
DELETE OBJECT hQuery.
END PROCEDURE.
CREATE tt.
ASSIGN tt.a = 1.
RUN foo( INPUT "tt"
, INPUT "tt.a = 1"
, INPUT "a"
, INPUT 2).
DISPLAY tt.
What is the command to find the number of entries/rows in a temp table? version 10.2b
/* create a temp-table so that we can test this technique
*/
define temp-table ttTest
field id as int
.
create ttTest.
id = 1.
create ttTest.
id = 2.
/* how many records?
*/
define query q for ttTest cache 0.
open query q preselect each ttTest.
display num-results( "q" ).
or you can use clasic FOR EACH:
DEFINE VARIABLE iCount AS INT NO-UNDO.
FOR EACH ttTest:
iCount = iCount + 1.
END.
DISPLAY iCount.
Here's mine, that works for any temp-table :
FUNCTION TT_NBREC RETURNS INTEGER ( INPUT pr_hd_temptable AS HANDLE ) :
DEFINE VARIABLE in_nbrec AS INTEGER NO-UNDO INITIAL 0.
DEFINE VARIABLE hd_buffer AS HANDLE NO-UNDO.
DEFINE VARIABLE hd_query AS HANDLE NO-UNDO.
DEFINE VARIABLE ch_query AS CHARACTER NO-UNDO.
DEFINE VARIABLE ch_table AS CHARACTER NO-UNDO.
DEFINE VARIABLE lg_error AS LOGICAL NO-UNDO.
ASSIGN
ch_table = pr_hd_temptable:NAME
ch_query = "FOR EACH " + ch_table + " NO-LOCK".
CREATE BUFFER hd_buffer FOR TABLE ch_table.
CREATE QUERY hd_query.
hd_query:ADD-BUFFER( hd_buffer ).
lg_error = hd_query:QUERY-PREPARE( ch_query ) NO-ERROR.
hd_query:QUERY-OPEN().
hd_query:GET-FIRST().
DO WHILE NOT hd_query:QUERY-OFF-END :
ASSIGN in_nbrec = in_nbrec + 1.
hd_query:GET-NEXT().
END.
hd_query:QUERY-CLOSE().
DELETE OBJECT hd_query.
DELETE OBJECT hd_buffer.
ASSIGN
hd_query = ?
hd_buffer = ?.
RETURN in_nbrec.
END FUNCTION.
Just pass it the handle of your temp-table and you get the number of records.
It can certainly be improved, but it works fast enough for me.
I have a dynamic Browser.It will populate values dynamicaly based on some input given through UI.
Now i wan to get the values displayed in that Browse and make a temp-table for that.
please help
To add new values you first insert a new row into the temp-table and then arrange to update that row. The following code is ugly but it may serve to illustrate:
define temp-table tt_simple no-undo
field id as integer
field name as character
index id_idx is unique id
.
define variable r as integer no-undo.
define query q for tt_simple.
define browse b query q display tt_simple.name with 5 down.
form b with frame easy.
form
tt_simple.name
with
frame updEasy
column 30
row 1
.
procedure newRecord:
define input parameter initName as character no-undo.
create tt_simple.
assign
r = r + 1
id = r
name = initName
.
end.
run newRecord( "abc" ).
run newRecord( "xyz" ).
on "enter" of b in frame easy do:
apply "entry" to tt_simple.name in frame updEasy.
return no-apply.
end.
on "insert-mode", "CTRL-I" anywhere do:
run newRecord( "" ).
close query q.
open query q for each tt_simple.
get last q.
apply "entry" to tt_simple.name in frame updEasy.
return no-apply.
end.
on "go" of tt_simple.name in frame updEasy do:
tt_simple.name = self:screen-value.
close query q.
open query q for each tt_simple.
apply "entry" to b in frame easy.
return no-apply.
end.
on "value-changed" of b in frame easy do:
display tt_simple.name with frame updEasy.
end.
open query q for each tt_simple.
enable tt_simple.name with frame updEasy.
enable b with frame easy.
apply "entry" to b in frame easy.
wait-for "close" of this-procedure.