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. Moving forward, myibi is our community platform to learn, share, and collaborate. We have the same Focal Point forum categories in myibi, so you can continue to have all new conversations there. If you need access to myibi, contact us at myibi@ibi.com and provide your corporate email address, company, and name.


Connect to myibi
Focal Point    Focal Point Forums  Hop To Forum Categories  WebFOCUS/FOCUS Forum on Focal Point     Using dialog manager in sql passthru

Read-Only Read-Only Topic
Go
Search
Notify
Tools
Using dialog manager in sql passthru
 Login/Join
 
Member
posted
Hi,

Is it possible to use dialog manager in a sql passthru to build a dynamic select statement without breaking the sql. I need to test the value of an amper variable and modify the select statement based on its value. If so, does anyone have an example?

Thanks...
 
Posts: 19 | Registered: January 04, 2005Report This Post
Virtuoso
posted Hide Post
Certainly.

Bear in mind that the fex is executed in two stages:
In stage 1, Dialog Manager (which does not understand Focus syntax) performs all the DM directives (-if, -set, -repeat etc.); and performs substitution of DM &vars imbedded in the Focus lines, and stacks them for execution in stage 2. Stage 1 ends at end of the fex, or when -RUN, or -EXIT is encountered.
In stage 2, Focus executes the stacked lines.

So you can insert DM statements between and around your lines of SQL and TABLE code, and perhaps imbed DM variables (amper vars) in the SQL code itself.

Add -RUN after the END statement if you want to resume DM processing after the data retrieval is complete, e.g., to test &LINES), and there you are.

Just make sure that the SQL (and TABLE) code generated will be valid, for all possible combinations of conditions (amper parameters).

For example, to screen on one or more columns, depending on input parameters, I have used code like this:

-SET &WHERE='WHERE';

-IF &ALPHA EQ ' ' GOTO ALPHA.X;
&WHERE (ALPHA = '&ALPHA')
-SET &WHERE='OR';
-ALPHA.X

-IF &BETA EQ ' ' GOTO BETA.X;
&WHERE (BETA = '&BETA')
-SET &WHERE='OR';
-BETA.X

-IF &GAMMA EQ ' ' GOTO GAMMA.X;
&WHERE (GAMMA= '&GAMMA)
-SET &WHERE='OR';
-GAMMA.X
. . .

This ensures that the first clause of the WHERE condition that the fex generates will start with WHERE, and all subsequent ones with OR.
 
Posts: 1925 | Location: NYC | In FOCUS since 1983 | Registered: January 11, 2005Report This Post
Member
posted Hide Post
Thanks Jack...I'll give that a try. Until your response, I was trying to do something like this. This is just a test query but it works...
-SET &SQLTEST = IF &DATETYPE EQ 'Bar Date' THEN ',a.assignment_id FROM PAL.SD sd, PAL.SD_ASSIGNMENT a WHERE a.sd_number = sd.sd_number;'<br />-ELSE 'FROM PAL.SD sd;';<br /><br /><br />SET SQLENGINE=SQLORA<br />SQL SET SERVER &MYSERV<br />SQL SELECT sd.sd_number,<br />           sd.doe_s_number<br />           &SQLTEST<br />END
However, it breaks if I try to pass an amper variable in the where string. It gives me an error about mssing quotes. Any ideas how I can get this to work?

-SET &SQLTEST = IF &DATETYPE EQ 'Bar Date' THEN ',a.assignment_id FROM PAL.SD sd, PAL.SD_ASSIGNMENT a WHERE a.sd_number = s.sd_number and a.begin_date >= &date1;'<br />-ELSE 'FROM PAL.SD sd;';<br /><br />SET SQLENGINE=SQLORA<br />SQL SET SERVER &MYSERV<br />SQL SELECT sd.sd_number,<br />           sd.doe_s_number<br />           &SQLTEST<br />END
 
Posts: 19 | Registered: January 04, 2005Report This Post
Expert
posted Hide Post
Because you're embedding a DM variable inside another, you should use .EVAL.
You may also require quotes around the date value:

-SET &SQLTEST = IF &DATETYPE EQ 'BAR DATE'
- THEN ',A.ASSIGNMENT_ID FROM PAL.SD SD, PAL.SD_ASSIGNMENT A WHERE A.SD_NUMBER = S.SD_NUMBER AND A.BEGIN_DATE >= ''&DATE1.EVAL;'''
- ELSE 'FROM PAL.SD SD;';

-TYPE &SQLTEST
 
Posts: 10577 | Location: Toronto, Ontario, Canada | Registered: April 27, 2005Report This Post
Member
posted Hide Post
Here's a trimmed down version of one that works fine for us:

-DEFAULT &FRDATE = 'NONE' ;
-IF &FRDATE EQ 'NONE' GOTO ERR_DATE ;

-SET &FRDATEL = EDIT(&FRDATE,'9999/99/99') ;
-TYPE Getting calls since &FRDATEL ..


-RUN

SQL SQLSYB

select
b.meetingDate
,b.meetingBucketId
...
from cmgMeetingBucket b

where b.meetingDate >= "&FRDATEL"
and ...
;

TABLE FILE SQLOUT
PRINT *
ON TABLE HOLD AS H010 FORMAT ALPHA
END
...
-ERR_DATE
 
Posts: 15 | Location: New York | Registered: April 02, 2004Report 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     Using dialog manager in sql passthru

Copyright © 1996-2020 Information Builders