Question How to use Delete-Current-Row() method?

reynold12

New Member
Hello All -

I am using OpenEdge 10.2B with windows XP.
I just want to understand about browser methods provided by OE.

I want to delete some records from my browser(or in other words dont want to display it on screen) on the basis of some condition .. like when value of a variable = xyz.

I understand from the help given by OE that Delete-Current-Row() and Delete-Selected-Row() methods will be suitable for my situation, but I really dont know where to write those methods in my abc.w file (like under which procedure or trigger).

what exactly I want is:

def var cKt as char no-undo.
...... on some DB query I can assign cKt with some values.......
if cKt = "xyz" then
browse {browser-name}:Delete-Current-Row().

I tried to place that code under Row-Display trigger but it was giving run-time error that I cant run the method under Row-Display trigger. So I want How/Where should I Use/Place Delete-Current-Row() or Delete-Selected-Row() methods?

Thanks.
 
Hi Reynold,
If you would want to delete a row on the "Row Display" event would it not be better to tune the where phrase of your browser query?
Thanks
Joel
 

reynold12

New Member
hello Joel -Thanks for your reply. But the suggestion you gave is the easiest way to modify the query itself. but I can't do that that's the reason I want too understand from some expert how to use those browser methods and which is the best place/procedure to place that. Hope you understand my concern. Thanks.



Hi Reynold,
If you would want to delete a row on the "Row Display" event would it not be better to tune the where phrase of your browser query?
Thanks
Joel
 

reynold12

New Member
Could anyone can help me on this ... like how do I use Delete-Current-Row() and Delete-Selected-Row() methods given by progress with some small code snippet (like in which trigger or procedure I should write those methods)..??
 

rzr

Member
Deleting browse rows


Deleting a record by way of a browse is a two-step process. First, you need to delete the record from the underlying temp-table or database table, and then you need to remove the record from the browse itself, along with the query’s result list. If you are browsing a database table directly and the user indicates a deletion, you should again get the records by
EXCLUSIVE-LOCK NO-WAIT and then use the DELETE statement to remove the records from the database. In the case of a temp-table, you can simply use the DELETE statement to remove the records.


Next, you use the DELETE-SELECTED-ROWS( ) method to delete one or more selected records from both the browse widget and the associated query result list

 

rzr

Member
Add button for delete operation and write this CHOOSE trigger for the new button:

Code:
DO:
    DEFINE VARIABLE iRow AS INTEGER NO-UNDO.
    DO iRow = 1 TO hBrowse:NUM-SELECTED-ROWS:
        hBrowse:FETCH-SELECTED-ROW(iRow).
        DELETE ttOline.
    END.
    hBrowseELETE-SELECTED-ROWS().
END.
 

reynold12

New Member
Add button for delete operation and write this CHOOSE trigger for the new button:

Code:
DO:
    DEFINE VARIABLE iRow AS INTEGER NO-UNDO.
    DO iRow = 1 TO hBrowse:NUM-SELECTED-ROWS:
        hBrowse:FETCH-SELECTED-ROW(iRow).
        DELETE ttOline.
    END.
    hBrowseELETE-SELECTED-ROWS().
END.

The options you suggested won't fit for me but Thanks for your reply.
First thing - I don't want to delete the record from the Database.
My Exact Requiremet is: When I press the Search/Refresh button which actually runs the query of DB table and display the data in the browser. I can't change the pre written Query filter criteria. But, still I need to implement is to check the Data on the basis of some security setting and if it fails, don't display in the Browser. For this change I don't need any button action as well.
I hope you understand my case.
Could you/anyone suggest some solution for such a case.
Thanks in advance.
 

rzr

Member
I can't change the pre written Query filter criteria.

Why can't you do this? Is there any restriction?

to "refresh" your browse display you will need to either open/close the query that populates the browse or open the query with the "modified" filter condition.
Do you have an option to modify the "source" for your browse. If yes then you can build your browse on this new source that can contain all the data from previous source + the filter check.
 

reynold12

New Member
Why can't you do this? Is there any restriction?
Yes, we have a restriction to change the existing Query. In other words you are saying there is no other way to get the expected result what I am expecting in my above post without modifying the query criteria?

Can't we achieve the expected result without touching the existing query criteria by using some other Progress Methods/Statements?

In simple words - I don't want to display some particular grid rows/records on the basis of some condition and that too after the query ran and without modifying the query itself.
 

Osborne

Active Member
As rzr posted, changing the query is the option to use.

I suppose you could do something like this which first loads all the records then removes from the browse all odd numbers, but not sure how practical this really is:
Code:
DEFINE VARIABLE vi AS INTEGER NO-UNDO.
DEFINE VARIABLE vRowid AS ROWID NO-UNDO.
 
DEFINE TEMP-TABLE ttNumbers NO-UNDO
       FIELD nField AS INTEGER LABEL "Number"
       INDEX nfield IS UNIQUE PRIMARY nField.
 
DEFINE QUERY q1 FOR ttNumbers SCROLLING.
DEFINE BROWSE b1 QUERY q1 DISPLAY ttNumbers.nField WITH MULTIPLE 10 DOWN.
 
DEFINE BUTTON button1 LABEL "Remove Odd Numbers".
 
DEFINE FRAME f1 b1 SKIP(1) button1 WITH SIDE-LABELS AT ROW 2 COLUMN 2.
 
ON CHOOSE OF button1
DO:
   GET FIRST q1.
   DO WHILE AVAILABLE(ttNumbers):
      IF ttNumbers.nField = 1 OR ttNumbers.nField = 3 OR
         ttNumbers.nField = 5 OR ttNumbers.nField = 7 OR
         ttNumbers.nField = 9 THEN DO:
         vRowid = ROWID(ttNumbers).
         REPOSITION q1 TO ROWID vRowid.
         b1:SELECT-FOCUSED-ROW().
      END.
      GET NEXT q1.
   END.
   IF b1:NUM-SELECTED-ROWS > 0 THEN
      b1:DELETE-SELECTED-ROWS().
END.
 
DO vi = 1 TO 10:
   CREATE ttNumbers.
   ASSIGN ttNumbers.nField = vi.
END.
 
OPEN QUERY q1 FOR EACH ttNumbers.
ENABLE b1 button1 WITH FRAME f1.
WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.
 

reynold12

New Member
As rzr posted, changing the query is the option to use.

I suppose you could do something like this which first loads all the records then removes from the browse all odd numbers, but not sure how practical this really is:
Code:
DEFINE VARIABLE vi AS INTEGER NO-UNDO.
DEFINE VARIABLE vRowid AS ROWID NO-UNDO.

DEFINE TEMP-TABLE ttNumbers NO-UNDO
       FIELD nField AS INTEGER LABEL "Number"
       INDEX nfield IS UNIQUE PRIMARY nField.

DEFINE QUERY q1 FOR ttNumbers SCROLLING.
DEFINE BROWSE b1 QUERY q1 DISPLAY ttNumbers.nField WITH MULTIPLE 10 DOWN.

DEFINE BUTTON button1 LABEL "Remove Odd Numbers".

DEFINE FRAME f1 b1 SKIP(1) button1 WITH SIDE-LABELS AT ROW 2 COLUMN 2.

ON CHOOSE OF button1
DO:
   GET FIRST q1.
   DO WHILE AVAILABLE(ttNumbers):
      IF ttNumbers.nField = 1 OR ttNumbers.nField = 3 OR
         ttNumbers.nField = 5 OR ttNumbers.nField = 7 OR
         ttNumbers.nField = 9 THEN DO:
         vRowid = ROWID(ttNumbers).
         REPOSITION q1 TO ROWID vRowid.
         b1:SELECT-FOCUSED-ROW().
      END.
      GET NEXT q1.
   END.
   IF b1:NUM-SELECTED-ROWS > 0 THEN
      b1:DELETE-SELECTED-ROWS().
END.

DO vi = 1 TO 10:
   CREATE ttNumbers.
   ASSIGN ttNumbers.nField = vi.
END.

OPEN QUERY q1 FOR EACH ttNumbers.
ENABLE b1 button1 WITH FRAME f1.
WAIT-FOR WINDOW-CLOSE OF CURRENT-WINDOW.

I can't use any button to delete the selected-rows. When I am trying to put code containing method to selcet-Focused-row under Row-Display Trigger, it giving me runtime error that I can't use those methods Select-Focused-row() and Delete-Selected_row() in Row-Display.

So could you suggest where I can put/use those methods under some triggers where before displaying to grid I can take that action and decide to display it in grid or not?
 

Osborne

Active Member
The best place would be to put into an internal procedure and run every time the browse query is updated:
Code:
ENABLE b1 button1 WITH FRAME f1.
 
OPEN QUERY q1 FOR EACH ttNumbers.
RUN remove_browse_records.
 
PROCEDURE remove_browse_records:
   DEFINE VARIABLE vRowid AS ROWID NO-UNDO.
 
   GET FIRST q1.
   DO WHILE AVAILABLE(ttNumbers):
      IF ttNumbers.nField = 1 OR ttNumbers.nField = 3 OR
         ttNumbers.nField = 5 OR ttNumbers.nField = 7 OR
         ttNumbers.nField = 9 THEN DO:
         vRowid = ROWID(ttNumbers).
         REPOSITION q1 TO ROWID vRowid.
         b1:SELECT-FOCUSED-ROW().
         b1:DELETE-SELECTED-ROWS().
      END.
      GET NEXT q1.
   END.
END PROCEDURE.
 

LarryD

Active Member
you might want to try a variation on this (assuming you are opening the query with the table)

Code:
on find of mydbtable do:
    if mydbtable.cKt = "xyz" 
    then return error.
end.
 
Top