Focal Point Banner


As of December 1, 2020, Focal Point is retired and repurposed as a reference repository. We value the wealth of knowledge that's been shared here over the years. You'll continue to have access to this treasure trove of knowledge, for search purposes only.

Join the TIBCO Community
TIBCO Community is a collaborative space for users to share knowledge and support one another in making the best use of TIBCO products and services. There are several TIBCO WebFOCUS resources in the community.

  • From the Home page, select Predict: WebFOCUS to view articles, questions, and trending articles.
  • Select Products from the top navigation bar, scroll, and then select the TIBCO WebFOCUS product page to view product overview, articles, and discussions.
  • Request access to the private WebFOCUS User Group (login required) to network with fellow members.

Former myibi community members should have received an email on 8/3/22 to activate their user accounts to join the community. Check your Spam folder for the email. Please get in touch with us at community@tibco.com for further assistance. Reference the community FAQ to learn more about the community.


Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Putting a value from query into variable in Webfocus to use?

Read-Only Read-Only Topic
Go
Search
Notify
Tools
[SOLVED] Putting a value from query into variable in Webfocus to use?
 Login/Join
 
Member
posted
Hey

I been trying to wrap my head around whether this is possible.

I am using an SQL pass through and have a query that pulls the last day of February (trying to account for leap years)

What I wanted to do, is that this query pulls one column "LAST_DAY" with one value (either 28 or 29)

I then want to take this value and put it into a variable and let the rest of the report use this determining date ranges.

How would I go about doing this? Or is this even possible to just pull "one value" from a query?

Thanks in advance

This message has been edited. Last edited by: Kerry,


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 26 | Registered: October 27, 2011Report This Post
Guru
posted Hide Post
Easy does it:

1.) sql here...
2.) TABLE FILE SQLOUT
PRINT ...
ON TABLE HOLD
3.) -READ HOLD &LASTDAY

Now you can use &LASTDAY for the rest of the report.


WF 8.1.05 Windows
 
Posts: 333 | Location: Orlando, FL | Registered: October 17, 2006Report This Post
Virtuoso
posted Hide Post
Just a minor comment to Anatess' code.

If after using -READ, your &LASTDAY variable shows funny characters that would be due to a binary representation of numbers in the HOLD file. If that's the case, make sure the value your SQL passthru returns is "seen" as a character (i.e. select to_char(lastday) as lastday from blah ) -OR- when creating the HOLD file, use ALPHA format. Just something to keep in mind.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
 
Posts: 1533 | Registered: August 12, 2005Report This Post
Expert
posted Hide Post
Also make sure you have a -RUN before the -READ.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

 
Posts: 6347 | Location: 33°49'23.0"S, 151°11'41.0"E | Registered: October 31, 2006Report This Post
Member
posted Hide Post
If the sole purpose of the SQL pass through is to determine if the last day of February in a given year is the 28th or the 29th, then this can be accomplished using a DEFINE FUNCTION. The defined function would include the logic for determining if a year is a leap year. If you are interested I'll look through my notes and post the code.
 
Posts: 13 | Location: New York City | Registered: March 01, 2010Report This Post
Virtuoso
posted Hide Post
Ira, you make a very valid point. I don't think I read Rodney's requirement in detail but focused on his need to "capture SQL output in an &variable" Smiler.

In following your line of thought, it is very easy to determine the last day of any month in any year (leap or otherwise) in "pure" WebFOCUS style using DATEMOV:

-* "Regular" year
SET TESTDATE=20110201
-RUN
-SET &LASTDAY=EDIT(DATECVT(DATEMOV(DATECVT(&YYMD, 'I8YYMD', 'YYMD'), 'EOM'), 'YYMD', 'A8YYMD'), '$$$$$$99');
-TYPE &LASTDAY

-* Leap year
SET TESTDATE=20080201
-RUN
-SET &LASTDAY=EDIT(DATECVT(DATEMOV(DATECVT(&YYMD, 'I8YYMD', 'YYMD'), 'EOM'), 'YYMD', 'A8YYMD'), '$$$$$$99');
-TYPE &LASTDAY



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
 
Posts: 1533 | Registered: August 12, 2005Report This Post
Expert
posted Hide Post
Ira,

I posted a function for exactly that back in February - link

One thing to remember is that century years are not leap years.

T



In FOCUS
since 1986
WebFOCUS Server 8.2.01M, thru 8.2.07 on Windows Svr 2008 R2  
WebFOCUS App Studio 8.2.06 standalone on Windows 10 
 
Posts: 5694 | Location: United Kingdom | Registered: April 08, 2004Report This Post
Member
posted Hide Post
Wow!

To add on to the very helpful suggestions here I just wanted to note some things I noticed for any future readers of this thread.

At first I was using this code

SQL
SELECT LAST_DAY FROM XYZ
;
TABLE ON TABLE HOLD AS TMP_XYZ
END
-RUN
TABLE FILE TMP_XYZ
PRINT LAST_DAY
ON TABLE HOLD
END
-RUN
-READ HOLD &TMP.A6
-TYPE TEST: &TMP;
-EXIT

When testing this, my output for &TMP was actually blank, or it came out to

TEST:

Thanks to the suggestion from njsden I changed it so it would then set the value pulled to a CHAR.

SQL
SELECT TO_CHAR(LAST_DAY) LAST FROM XYZ
;
TABLE ON TABLE HOLD AS TMP_XYZ
END
-RUN
TABLE FILE TMP_XYZ
PRINT LAST
ON TABLE HOLD
END
-RUN
-READ HOLD &TMP.A6
-TYPE TEST: &TMP;
-EXIT

Which gave me what I wanted, though I had to use a TRUNCATE to make sure there were no extra spaces lurking around

That define function is awesome too, I was mainly trying to do the -READ to play with it but I will try that define function too.

Thanks so much for the replies, I am much more encouraged to learn Webfocus now with such a great community!


WebFOCUS 7.6
Windows, All Outputs
 
Posts: 26 | Registered: October 27, 2011Report This Post
Virtuoso
posted Hide Post
quote:
I am much more encouraged to learn Webfocus now


Great! Keep it on, Rodney. You'll encountered a few challenges along the way (just as many of us have) but the experience may be quite rewarding. Smiler



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
 
Posts: 1533 | Registered: August 12, 2005Report This Post
Guru
posted Hide Post
Rodney, glad u manage to solve it. Here's another approach, using the AYMD function.

DEFINE FILE EMPLOYEE
MARCH_FIRST/I8YYMD = IF EMP_ID EQ '071382660' THEN 20080301 ELSE 20110301;
FEBRUARY_LAST/I8YYMD = AYMD(MARCH_FIRST, -1, FEBRUARY_LAST);
END

There are similar functions for the various date-time columns.

Håkan


WebFOCUS DS 8.0.06/08 DS/AS
WebFOCUS RS 8.0.08 (Linux/IBM i)
WebFOCUS Client 8.0.06 (Linux)
 
Posts: 319 | Location: Stockholm, Sweden | Registered: February 04, 2004Report This Post
Virtuoso
posted Hide Post
Rodney, all in light of contributing to your learning I'd like to make a few comments on your sample code.

1) Avoid using LAST as a field name as it is a WebFOCUS reserved word which allows to get the value of a field from the previous record (or previous entry in the internal matrix in case of SUM requests). Though it is working now in your example it *might* not do so in future versions of the product. So:
SELECT TO_CHAR(LAST_DAY) LAST_DAY FROM XYZ
is a better choice. Smiler

2) Whenever possible, give your HOLD files a name. It is not required but it is a practice I've embraced to save me from headaches especially when many HOLD files are involved in a report process.
ON TABLE HOLD AS HLASTDAY


3) The syntax of -READ suggests to use a dot (.) before and after the type/length declaration of the &variable:
-READ HLASTDAY &TMP.A6.


4) Finally, -TYPE does not require a semicolon at the end of the line.


Though those suggestions may look silly or unnecessary, I share them just because after our recent upgrade from WF 5.3 to WF 7.7 we found a few lines of code that stopped running due to code tightening (stricter syntax rules) in the newer version.

Hope that helps somehow Smiler



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
 
Posts: 1533 | Registered: August 12, 2005Report This Post
  Powered by Social Strata  

Read-Only Read-Only Topic

Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     [SOLVED] Putting a value from query into variable in Webfocus to use?

Copyright © 1996-2020 Information Builders