Focal Point
Using a Field in a calculation.

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

January 26, 2007, 11:31 AM
Wilky
Using a Field in a calculation.
I am wondering if anybody has done this.

Say I have a table SAMPLE with three fields

field1 field2 field3
10 2 /
3 4 *

TABLE FILE SAMPLE
COMPUTE NEWVALUE/D12.2 = ( FIELD1 FIELD3 FIELD2);
END

So the end results would be that field 3 contains what should be done to the numeric fields.

The output would be

10 / 2 = 5
3 * 4 = 12

-Brian


PROD: WF 7.1.3 on Win 2003/IIS 6/Self-Serve & MRE
TEST: We dont need no Stinking Test Server!
January 26, 2007, 12:19 PM
BlueZone
This seems to work Brian.....
>> First concatenate the 3 fields in the correct order. This will create an alpha-field with the computation expression.
>> Then assign this field with a .EVAL, to another variable to get the result.

The following example is with a -SET. You shold be able to carry it over to a DEFINE or COMPUTE.
-*-*
-*-*
-SET &ECHO=ALL;
-*
-SET &F1='6';
-SET &F2='/';
-SET &F3='2';
-*
-SET &F4= &F1 || &F2 || &F3 ;
-TYPE &F4 // shows literal 6/2
-SET &F5 = &F4.EVAL;
-TYPE &F5; // shows 3
-EXIT

Thanks for the Q Brian, it got those creative juices rolling. I am positive that the FOCUS gurus around will find a more elegant solution too.

Hope that helps.
Sandeep Mamidenna.

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


-------------------------------------------------------------------------------------------------
Blue Cross & Blue Shield of MS
WF.76-10 on (WS2003 + WebSphere) / EDA on z/OS + DB2 + MS-SQL
MRE, BID, Dev. Studio, Self-Service apps & a dash of fun !! Music
January 26, 2007, 02:33 PM
JimRice
Another idea:

DEFINE FILE CAR
CNT/I5 WITH CAR = CNT + 1;
FIELD1/D12.2 WITH CAR = DECODE CNT (
1 5
2 5
3 5
4 5
5 5
);
FIELD2/D12.2 WITH CAR = DECODE CNT (
1 10
2 10
3 10
4 10
5 10
);
FIELD3/A1 WITH CAR = DECODE CNT (
1 '*'
2 '/'
3 '+'
4 '-'
5 '?'
);
END
-*
TABLE FILE CAR
PRINT FIELD1 FIELD2 FIELD3
WHERE RECORDLIMIT EQ 5
ON TABLE HOLD AS TESTFILE FORMAT ALPHA
END
-*
DEFINE FILE TESTFILE
NEWVALUE/D12.2 = IF FIELD3 EQ '*' THEN FIELD1 * FIELD2
ELSE IF FIELD3 EQ '/' THEN FIELD1 / FIELD2
ELSE IF FIELD3 EQ '+' THEN FIELD1 + FIELD2
ELSE IF FIELD3 EQ '-' THEN FIELD1 - FIELD2
ELSE 0.00;
END
-*
TABLE FILE TESTFILE
PRINT FIELD1 FIELD3 FIELD2 NEWVALUE
END
-*

Jim


WF DevStu 5.2.6/WF Srv 5.2.4/Win NT 5.2
February 05, 2007, 04:31 PM
Wilky
Thanks for the help. I ended up doing it the way Jim recommend as the values I wanted to do the comparison on are in table I was reading.

Thanks for the Help


PROD: WF 7.1.3 on Win 2003/IIS 6/Self-Serve & MRE
TEST: We dont need no Stinking Test Server!