PowerBuilder – Discarding Rows with Find
It’s a fairly common practice to report on a set of data derived from a larger group of rows. There are many techniques to do this in code and with the methods available with datawindows/datastores. One typical approach is to use the Filter method. The problem with this is it requires another trip to the database to get the matching rows. Here is a technique to quickly eliminate rows from a datawindow without filtering.
IF ll_part_id > 0 THEN ll_find_row = dw_part.find('part_id = ' + string(ll_part_id), 1, 999999) //'top to bottom' IF ll_find_row > 1 THEN // if data starts in first row, do nothing dw_part.rowsdiscard( 1, ll_find_row - 1, Primary!) END IF IF dw_part.rowcount() > 0 THEN ll_find_row = dw_part.find('part_id = ' + string(ll_part_id), 999999, 1) //'bottom to top' IF ll_find_row > 0 AND ll_find_row < dw_part.rowcount() THEN dw_part.rowsdiscard( ll_find_row + 1, dw_part.rowcount(), Primary!) END IF END IF END IF
So what I’m doing is finding from the beginning of the row set in the Datawindow until I find the first row of what I want then discard all the unwanted rows. Then I use a Find again but this time starting from the end of the row set and then discard any rows after my desired data.
You might also be interested in