Focal Point
GETTOK function issue

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/4891057352

October 25, 2007, 08:59 AM
Suji
GETTOK function issue
Hello,

-SET &SelCol.&COUNTER = GETTOK(&SelCol, 500, &COUNTER, ',',500,A&SelCol.&COUNTER.LENGTH);
This is what I use in my Focprocedure.

Let Selcol be the following,for example,

Selcol before TOK is ACCOUNT REGISTRATION CATEGORY,ACCOUNT MNEMONIC,CASH AVAILABLE,FUND FAMILY,ACTY SECR PRICE,ACTY COMM AMT

SelCol.1 after TOK is ACCOUNT REGISTRAT

The remaining characters(ION CATEGORY) are truncated ..
I could not identify what is the actual problem in the function.
Please suggest me a solution.

Thanks
Suji,

Webfocus 7.1
Windows and Unix O/s
Oracle db


WebFOCUS 7.7.02(Production)
WebFOCUS 7.7.02(Test region)
Oracle backend (10g)and Windows Frontend.
HTML,PDF,EXL2K,FLEX,AHTML
October 25, 2007, 09:44 AM
Kamesh
If you see the syntax of GETTOK

GETTOK(infield,inlength,token,delim,outfield,outlength)

In your manipulation you are doing like below

-SET &SelCol.&COUNTER = GETTOK(&SelCol, 500, &COUNTER, ',',500,A&SelCol.&COUNTER.LENGTH);

A&SelCol.&COUNTER.LENGTH --> A&Selcol1.length

&Selcol1 is ACCOUNT MNEMONIC-- The length of this is 16.

When you use this length on your token, it gets only 16 characters and truncates the remaining.

Instead of getting the length &selcol.counter value, you can default that with maximum value and trim the spaces.

Hope this helps,


WFConsultant

WF 8105M on Win7/Tomcat
October 25, 2007, 09:51 AM
Tom Flynn
Suji,

Try this:

-SET &ECHO=ALL;
-SET &SELCOL = 'ACCOUNT REGISTRATION CATEGORY,ACCOUNT MNEMONIC,CASH AVAILABLE,FUND FAMILY,ACTY SECR PRICE,ACTY COMM AMT';
-SET &CNTR = 0;
-SET &LNGTH = &SELCOL.LENGTH;
-BEG_LOOP
-SET &CNTR = &CNTR + 1;
-SET &FLD.&CNTR = GETTOK('&SELCOL.EVAL', &LNGTH, &CNTR, ',', &LNGTH, 'A&LNGTH.EVAL');
-IF &FLD.&CNTR EQ ' ' GOTO END_LOOP;
-SET &OUTFLD.&CNTR = &FLD.&CNTR;
-GOTO BEG_LOOP
-END_LOOP
-SET &CNTR = &CNTR - 1;
-SET &CNTR2 = 1;
-REPEAT DO_TYPE &CNTR TIMES
-TYPE &OUTFLD.&CNTR2
-SET &CNTR2 = &CNTR2 + 1;
-DO_TYPE
-EXIT


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
October 25, 2007, 10:15 AM
Suji
Hello Tom,
There is a parameter conflict in ARG 5..This arg should contain the length of selcol.counter.length...

Hello Kamesh,
Anyhow the first arg is ACCOUNT REGISTRATION CATEGORY and not ACCOUNT MNEMONIC .. Then there will not a problem.. We keep on incrementing the counter value by 1 in the loop..


WebFOCUS 7.7.02(Production)
WebFOCUS 7.7.02(Test region)
Oracle backend (10g)and Windows Frontend.
HTML,PDF,EXL2K,FLEX,AHTML
October 25, 2007, 10:20 AM
Francis Mariani
The A&SelCol.&COUNTER.LENGTH is causing the problem - WebFOCUS doesn't know the length of that yet, so it probably uses a default length of 16. Change it to A500 - the maximum length of the token.


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
October 25, 2007, 10:25 AM
Tom Flynn
Suji,

Francis, Kamesh and my code example, are correct. Dialogue Manager does not know the length of the anwer set until AFTER the variable is set.

If you are missing an argument, it's probably a comma.

If you copy the code EXACTLY as is, it works fine. Make sure you copy correctly...


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
October 25, 2007, 10:50 AM
Kamesh
Suji,
Can you pls try to display the value for &Selcol1 ? And see what value you are getting?

My understanding is the first value stores on &SELCOL0.

Simple solution is,

SET &SelCol.&COUNTER = GETTOK(&SelCol, 500, &COUNTER, ',',500,A100);

Try the above and that should work.


WFConsultant

WF 8105M on Win7/Tomcat
October 25, 2007, 02:58 PM
GinnyJakes
You can use POSIT to find the position of the comma and use that value - 1 to calculate the length. Then you can use it in GETTOK or SUBSTR.

e.g.
-SET &ECHO=ALL;
-SET &SelCol='ACCOUNT REGISTRATION CATEGORY,ACCOUNT MNEMONIC,CASH AVAILABLE,FUND FAMILY,ACTY SECR PRICE,ACTY COMM AMT';
-TYPE &SelCol.LENGTH
-SET &COMMALOC=POSIT(&SelCol,&SelCol.LENGTH,',',1,'I2');
-TYPE &COMMALOC
-SET &STRLEN=&COMMALOC-1;
-SET &OUTPARM=SUBSTR(&SelCol.LENGTH,&SelCol,1,&STRLEN,&STRLEN,'A&STRLEN');
-SET &OUTTOK=GETTOK(&SelCol,&SelCol.LENGTH,1,',',&STRLEN,'A&STRLEN');
-TYPE &OUTPARM
-TYPE &OUTTOK

I didn't do the counter thing but have done loops where I lop off the front of the string that I've already extracted.

Unfortunately, I think the spaces in the value may be messing you up. I can't get this to work in either 533 or 762.

How about PARAG?


Ginny
---------------------------------
Prod: WF 7.7.01 Dev: WF 7.6.9-11
Admin, MRE,self-service; adapters: Teradata, DB2, Oracle, SQL Server, Essbase, ESRI, FlexEnable, Google
October 26, 2007, 04:53 AM
Suji
Hello Francis,
What you said is correct.My code is working.
Yet there is another problem.
This is my procedure.

-SET &SelCol='ACCOUNT REGISTRATION CATEGORY,ACCOUNT MNEMONIC,CASH AVAILABLE,FUND FAMILY,ACTY SECR PRICE,ACTY COMM AMT';
-DEF_SEL
-SET &SelCol=CTRAN(500,&SelCol,32,95,A&SelCol.LENGTH);
-SET &SelCol.&COUNTER = GETTOK(&SelCol, 500, &COUNTER, ',',30,'A30');
-SET &SelCol.&COUNTER = TRUNCATE(&SelCol.&COUNTER) ;
-SET &COUNTER = &COUNTER + 1 ;
-IF &COUNTER LE 4 THEN DEF_SEL;
-ENDS2

THe output is as follows:
There are junk chars in the last value:
SelCol.1 after TOK is ACCOUNT_CLOSE_DATE
SelCol.2 after TOK is ACCOUNT_TYPE
SelCol.3 after TOK is CUSIP
SelCol.4 after TOK is ACTY_AMT 5ýp

Please someone suggest me a solution to remove this junk chars from the final counter value.

Thanks,
Suji.

Webfocus 7.1
Oracle DB
Windows and Unix O/s.


WebFOCUS 7.7.02(Production)
WebFOCUS 7.7.02(Test region)
Oracle backend (10g)and Windows Frontend.
HTML,PDF,EXL2K,FLEX,AHTML
October 26, 2007, 07:37 AM
Suji
Hello Tom,
Your code is working fine.

Thanks Suji.


WebFOCUS 7.7.02(Production)
WebFOCUS 7.7.02(Test region)
Oracle backend (10g)and Windows Frontend.
HTML,PDF,EXL2K,FLEX,AHTML
October 26, 2007, 09:13 AM
Suji
Hello Tom,
I have one doubt..What does EVAL function do in a variable like SELCOL? Please clarify my doubt.
I have implemented your code in my procedure.It is working fine.

Thanks
Suji.


WebFOCUS 7.7.02(Production)
WebFOCUS 7.7.02(Test region)
Oracle backend (10g)and Windows Frontend.
HTML,PDF,EXL2K,FLEX,AHTML
October 26, 2007, 09:30 AM
Tom Flynn
Hi Suji,

Glad it is working for you. Here is some documentation from IBI website. I probably use it when not needed, so, you can take it off and see the difference.

That will give you a better understanding...




The .EVAL operator enables you to evaluate a variable's value immediately, making it possible to change a procedure dynamically.
The .EVAL operator is particularly useful in modifying code at run time.


--------------------------------------------------------------------------------
Top of page
--------------------------------------------------------------------------------


Syntax: How to Evaluate a Variable Immediately
[&]&variable.EVAL
where:

variable
Is a local or global variable.

When the command procedure is executed, the expression is replaced with the value of the specified variable before any other action is performed.
Without the .EVAL operator, a variable cannot be used in place of some commands.


--------------------------------------------------------------------------------
Top of page
--------------------------------------------------------------------------------


Example: Using .EVAL to Allow WebFOCUS to Interpret a Variable
The code

-SET &A='-TYPE';
&A HELLO
produces an error message which shows that WebFOCUS does not recognize the value of &A:



Appending the .EVAL operator to the &A variable makes it possible for WebFOCUS to interpret the variable correctly.
Adding the .EVAL operator as follows

-SET &A='-TYPE';
&A.EVAL HELLO
produces the following output:

HELLO

--------------------------------------------------------------------------------
Top of page
--------------------------------------------------------------------------------


Example: Evaluating a Variable Immediately
The following example illustrates how to use the .EVAL operator in a record selection expression.
The numbers to the left apply to the notes that follow the procedure:

1. -SET &R='IF SALARY GT 60000';
2. -IF &Y EQ 'YES' THEN GOTO START;
3. -SET &R = '-*';
-START
4. TABLE FILE CENTHR
PRINT SALARY
BY PLANT BY LNAME
5. &R.EVAL
END
The procedure executes as follows:

1. The procedure sets the value of &R to 'IF SALARY GT 60000'.
2. If &Y is YES, the procedure branches to the START label, bypassing the second -SET command.
3. If &Y is NO, the procedure continues to the second -SET command, which sets &R to '-*', which is a comment.
The report request is stacked.

4. The procedure evaluates the value of &R. If the end user wanted a record selection test, the value of &R is
'IF SALARY GT 60000' and this line is stacked.

5. If the end user did not want a record selection test, the value of &R is '-*' and this line is ignored.


Edit: Typo

This message has been edited. Last edited by: Tom Flynn,


Tom Flynn
WebFOCUS 8.1.05 - PROD/QA
DB2 - AS400 - Mainframe
October 26, 2007, 09:39 AM
PBrightwell
The .EVAL evaluates a variable when it is encountered. In Tom's example 'A&LNGTH.EVAL' if &LNGTH is 30 then this evaluates &LNGTH as 30 making the value within the quotes 'A30' rather than literally 'A&LNGTH'


Pat
WF 7.6.8, AIX, AS400, NT
AS400 FOCUS, AIX FOCUS,
Oracle, DB2, JDE, Lotus Notes