IB - Developer Center    Forums  Hop To Forum Categories  FOCUS/WebFOCUS    reference fields in a hold file in -IF .. THEN GOTO ..
Go
New
Search
Notify
Tools
Reply
  
-star Rating Rate It!  Login/Join 
<bigpgo>
Posted
Hello. I'm trying to compute something with an SQL query, and use that value to determine what GOTO to jump to:

SQL
SELECT MAX(cost) AS MAX_COST FROM ...;
TABLE
ON TABLE HOLD AS myReport
END
-RUN

TABLE FILE myReport
PRINT
COMPUTE myCost/I5 = MAX_COST;
END
ON TABLE HOLD AS myReport2
END

-IF myReport2.myCost EQ 10 THEN GOTO OUT;
....
some other stuff done here
...
-OUT

I know that myCost is 10 (I printed it), but I never jump to OUT. It's as if it ignores this value, or cannot reference it properly in myReport2. Any help appreciated.
 
Reply With QuoteEdit or Delete MessageReport This Post
Silver Member
Posted Hide Post
maybe something like:

SQL
SELECT MAX(cost) AS MAX_COST FROM ...;
TABLE FILE SQLOUT
PRINT *
ON TABLE SAVE
END
-RUN
-READ SAVE &MCOST

-IF &MCOST EQ 10 THEN GOTO OUT;
....
some other stuff done here
...
-OUT


hth,

drew
 
Posts: 46 | Location: Oakland, California | Registered: April 14, 2003Reply With QuoteEdit or Delete MessageReport This Post
Master
Posted Hide Post
Make sure you know how wide the field is when stored in SAVE, and initialize &MCOST to that width (or specify it in the -READ).
 
Posts: 535 | Location: NYC | Registered: January 11, 2005Reply With QuoteEdit or Delete MessageReport This Post
<bigpgo>
Posted
Thanks for the replies. I tried it just like you said (and added the width):
-READ SAVE &MCOST.I22

But it's asking me to enter a value for MCOST. If I specify "no input parameters" in the properties, it says MCOST value is missing. Any thoughts?
 
Reply With QuoteEdit or Delete MessageReport This Post
Master
Posted Hide Post
Some suggestions:

1. Are you sure that the COST variable stored in SAVE is USAGE=I22 (or P22)? Check the MFD of the source table.

2. Add:
-SET &MCOST='0000000000000000000000';
-* (or any string value 22 characters wide)
to initialize &MCOST to the appropriate length before the -READ, instead of specifying format in the -READ

3. Add
-TYPE ## &|MCOST:
-TYPE ## '&MCOST'
-TYPE ## *123456789.123456789.123456789.
before and after the read, to verify what value &MCOST received (length, content).

4. Use EDIT() to force evaluation as an integer:
-IF EDIT(&MCOST) EQ 10 ...
 
Posts: 535 | Location: NYC | Registered: January 11, 2005Reply With QuoteEdit or Delete MessageReport This Post
Guru
Posted Hide Post
-IF myReport2.myCost EQ 10 THEN GOTO OUT;

-READ SAVE &MCOST.I22

Why are are you specifying I22? The width being referred to is the width of the value, not the width of the qualified field name.

Integer formats are generally I9 or less.
 
Posts: 342 | Location: Melbourne Australia | Registered: April 15, 2003Reply With QuoteEdit or Delete MessageReport This Post
<Pietro De Santis>
Posted
The best way for us to help you would be to post an example that we can run on our P.C's.

Here is an example of using Dialog Manager to read a value from a HOLD or SAVE file and then use the value for further processing. This example also illustrates that, in Dialog Manager, you can read a value as an alpha field, but use it in numeric calculations.

The problem you're encountering may be occuring because I22 is not a valid numeric format, there is a maximum length for Integer fields, I10, I think.

SET HOLDLIST=PRINTONLY
TABLE FILE CAR
PRINT RETAIL_COST/P22
WHERE RECORDLIMIT EQ 1
ON TABLE SAVE
END
-RUN
-READ SAVE &RET_COST.A22

-TYPE &RET_COST

-SET &RET_COST2 = &RET_COST * 239;
-TYPE &RET_COST2
-IF &RET_COST GT 5000 GOTO OVER_5;

-TYPE UNDER 5000

-OVER_5

-TYPE OVER 5000

(There's ampersands on all the Dialog Manager variables in case this forum removes them)
 
Reply With QuoteEdit or Delete MessageReport This Post
<bigpgo>
Posted
Pietro, your solution worked. Specifically, this line:

SET HOLDLIST=PRINTONLY

was very important. If I dont have this line, the code doesnt work (it then thinks that MYCOST field that I compute is 0 in my -IF statement, all the time).

One question that I have is: can you provide a code sample that reads from a HOLD file, not a SAVE file? I tried doing:

SET HOLDLIST=PRINTONLY
TABLE FILE report1
PRINT
COMPUTE MYCOST/I5 = MAX_COST;
ON TABLE HOLD AS report2
END
-RUN
-READ report2 &MYCOST.I5

-IF &MYCOST GT 5 GOTO OVER_5;

But it complains that value for MYCOST is missing. What's the proper syntax? Thanks a lot.
 
Reply With QuoteEdit or Delete MessageReport This Post
<Pietro De Santis>
Posted
ON TABLE HOLD FORMAT ALPHA

Format Alpha is very important if you want to read the file with Dialog Manager or copy the HOLD file for use with a non-FOCUS program.

According to the manual, FORMAT HOLD creates a BINARY file, the data is not stored as you may expect.

I always use ON TABLE HOLD FORMAT ALPHA, even if I'm not going to read the file with Dialog Manager.

I hope this helps.

SET HOLDLIST=PRINTONLY
TABLE FILE CAR
PRINT RETAIL_COST/I5
WHERE RECORDLIMIT EQ 1
ON TABLE HOLD FORMAT ALPHA
END
-RUN

-READ HOLD &RET_COST.I5


-TYPE &RET_COST
 
Reply With QuoteEdit or Delete MessageReport This Post
<bigpgo>
Posted
That worked beautifully, thanks a lot.
Complete code:

SET HOLDLIST=PRINTONLY
TABLE FILE report1
PRINT
COMPUTE MYCOST/I5 = MAX_COST;
ON TABLE HOLD AS report2 FORMAT ALPHA
END
-RUN
-READ report2 &MYCOST.I5

-IF &MYCOST GT 5 GOTO OVER_5;
 
Reply With QuoteEdit or Delete MessageReport This Post
Platinum Member
Posted Hide Post
Hi Just as a last note... if you have more than one param, just separate them in the same READ line

like ...

-READ HOLDFILE &X.A1 &Y.A2

etc. Just make sure you refer to every field in the correct order of course.
 
Posts: 163 | Registered: October 01, 2003Reply With QuoteEdit or Delete MessageReport This Post
 Previous Topic | Next Topic powered by eve community  
 

IB - Developer Center    Forums  Hop To Forum Categories  FOCUS/WebFOCUS    reference fields in a hold file in -IF .. THEN GOTO ..

Copyright © 1996-2008 Information Builders, leaders in enterprise business intelligence.