IF-THEN-ELSE logic is supported as part of an expression, including arithmetic, chararcter, and logical expressions.
The following request uses IF-THEN-ELSE logic in an arithmetic expression to determine how much to add to LISTPR to calculate NEWPRICE.
TABLE FILE MOVIES
SUM COPIES
LISTPR
COMPUTE
NEWPRICE = LISTPR + (IF COPIES GT 10 THEN 0.00 ELSE 25.00);
BY CATEGORY
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
The output is shown in the following image. Where there are more than 10 copies, the NEWPRICE equals LISTPR, otherwise NEWPRICE is $25.00 greater than LISTPR.
The following request uses IF-THEN-ELSE logic to determine what characters to concatenate to MOVIECODE in order to compute NEWCODE.
TABLE FILE MOVIES
PRINT COPIES
MOVIECODE
COMPUTE
NEWCODE/A20 = MOVIECODE |(IF MOVIECODE CONTAINS 'DIS' THEN 'NEY;' ELSE ';');
BY CATEGORY
WHERE CATEGORY EQ 'CHILDREN'
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
The output is shown in the following image. If MOVIECODE contains the characters 'DIS', NEWCODE is generated by concatenating the characters 'NEY;', otherwise NEWCODE is generated by concatenating the character ';'.
The following request uses IF-THEN-ELSE logic in a WHERE clause to select records based on values of WHOLESALEPR where the values used for selection vary depending on the value of LISTPR in that record.
TABLE FILE MOVIES
PRINT COPIES
LISTPR
WHOLESALEPR
BY CATEGORY
WHERE WHOLESALEPR GT (IF LISTPR GT 20.00 THEN 15.00 ELSE 11.00)
ON TABLE SET PAGE NOLEAD
ON TABLE SET STYLE *
GRID=OFF,$
ENDSTYLE
END
The output is shown in the following image. In the selected records, WHOLESALEPR is greater than $15.00 if LISTPR is greater than $20.00. WHOLESALEPR is greater than $11.00 if LISTPR is less than or equal to $20.00.
WebFOCUS | |
Feedback |