hi_char value

John

Member
There is a screen where fields are placed like "From Code" and "To Code". Now if user runs the report keeping both inputs as BLANK "".
Now query should fetch all the records. Could some one suggest if this query should work fine?

lchar= "".
hchar = chr(1024).
for each table where code >= lchar and code <= hchar no-lock:
disp table.
end.
 

John

Member
There is a screen where fields are placed like "From Code" and "To Code". Now if user runs the report keeping both inputs as BLANK "".
Now query should fetch all the records. Could some one suggest if this query should work fine?

lchar= "".
hchar = chr(1024).
for each table where code >= lchar and code <= hchar no-lock:
disp table.
end.
 

TomBascom

Curmudgeon
Trying to write a single WHERE clause that does two completely different things is a bad idea. You will end up with code that does neither thing well.

Code:
define variable lr as int64 no-undo.
define variable rr as int64 no-undo.
define variable rx as int64 no-undo.
define variable sr as int64 no-undo.
define variable ir as int64 no-undo.

define variable p1       as character no-undo label "From".
define variable p2       as character no-undo label "To".
define variable showData as logical   no-undo label "Show Data".

define query q for customer fields( name ) cache 5000.

find _myconnection no-lock no-error.

do while true:

  find _userio no-lock where _userio-id = _myconn-userid + 1 no-error.
  find _actSummary no-lock no-error.
  find _actIndex no-lock no-error.

  assign
    lr = _userio-dbaccess
    rr = 0
    rx = 0
    sr = _summary-recReads
    ir = _index-Find
  .

  update
    p1 p2 skip
    showData skip
    skip(1)
   with
    side-labels
    no-box
  .

  if p1 = "" and p2 = "" then
    open query q for each customer no-lock.
   else if p1 <> "" and p2 <> "" then
    open query q for each customer no-lock where name >= p1 and name <= p2.
   else if p1 <> "" then
    open query q for each customer no-lock where name >= p1.
   else if p2 <> "" then
    open query q for each customer no-lock where name <= p2.

  get first q.
  do while available customer:

    rr = rr + 1.
    if showData = yes then
      do:
        display name with frame a down no-box row 12.
        down 1 with frame a.
      end.

    rx = rx + 1.
    get next q.

  end.

  close query q.

  find _userio no-lock where _userio-id = _myconn-userid + 1 no-error.
  find _actSummary no-lock no-error.
  find _actIndex no-lock no-error.

  display
    ( _userio-dbaccess - lr )  label "logical reads"
    ( _summary-recReads - sr ) label "record rds"
    ( _index-Find - ir )      label "index rds"
    rr  label "records read"
    rx  label "recs displayed"
   with
    1 column
    side-labels
  .

  pause.

  hide frame a no-pause.
    
end.

The bits in purple handle prompting for the search criteria and fetching the records. The black parts are for collecting data about the efficiency of the query so that you can see how efficient (or inefficient) it is.
 

TomBascom

Curmudgeon
Oops. [ C O D E ] tags don't respect colors. Oh well, it shouldn't be all that hard to figure out which bits are just test scaffolding.
 
There is a screen where fields are placed like "From Code" and "To Code". Now if user runs the report keeping both inputs as BLANK "".
Now query should fetch all the records. Could some one suggest if this query should work fine?

lchar= "".
hchar = chr(1024).
for each table where code >= lchar and code <= hchar no-lock:
disp table.
end.
Yes, should work.
On mfgpro "hi_char" (and hi_date low_date) are calculated this way (Just for make sure hi_char is the highest value.):
Code:
     hi_char = chr(1).

     do i = 2 to 131071:
        if chr(i) > hi_char then hi_char = chr(i).
     end. 

     assign
        hi_date = 12/31/3999
        low_date = 01/01/1900.

And is used like this way:
Code:
...
REPEAT:
IF tocode = hi_char THEN tocode = "".
UPDATE fromcode tocode.
IF tocode = "" THEN tocode = hi_char.

  FOR EACH yourtable WHERE code >= fromcode AND code <= tocode:
  ....
  END.
...
END.
 

antonylejos

New Member
Use the below code to find hi char.

def var i as int.
def var k as int.
def var hi_char as char.
do i = 2 to 2550:
if chr(i) > hi_char
then do:
assign hi_char = chr(i).
k = i.
end. /*if chr(i) > hi_char*/
end. /*do i = 2 to 2550*/
display hi_char k.
 
Top