Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IF THEN STATEMENT

Status
Not open for further replies.

pvuppa1

Programmer
Nov 14, 2003
61
US
Can i print stuff based on some if condition like
TABLE FILE MYFILE
PRINT
MYFIELD1 OVER
MYFIELD2 OVER
..
..

IF FIELD2='something' THEN
PRINT SOMEFIELD AS 'SOMEOTHERFIELD'
END

any help would be great.
THX
-P
 
You'll have to be more specific about what you are trying to do. Does SOMEFIELD appear in one row of a report, but not in another based on the value of FIELD2 for that row? If so, that can be done with a COMPUTE. Or, is FIELD2 evaluated just once for the report? If so, SOMEFIELD can be added or not added by Dialogue Manager.
 
If your are trying to prevent field two from showing on the report completely based on another value from a field, you will need to use a table request to retrieve the value to be checked and read it into a dialog manager variable. You would then use the dialog manager variable with an if statement to print the field.

If you don't mind that a column on the report is reserved for the field, then you could set the value to a blank when the condition is true (or false) using a define or compute.
 
I have so many fields in a row, and i need to show some fields based on a field FIELD3 as below.
so based on the value of field3 I need to disply some fields, but the rest of the fields are displayed with no condition. All my fields are coming from MYFILE
TABLE FILE MYFILE
PRINT
FIELD1 OVER
FIELD2 OVER
IF FIELD3='SOMETHING' THEN PRINT FIELD4 AS 'SOMENAME'
ELSEIF FIELD3='SOMETHINELSE' THEN PRINT FIELD5 AS 'SOMENAME'
ELSEIF FIELD3='SOMEOTHER' THEN PRINT FIELD6 AS 'SOMENAME'
...
...
END
Can we print/display fields on based on some conditions (IF THEN ELSEIf...)??
-P


 
In this case, I would use a compute.

COMPUTE NEWFLD/A20 = IF FIELD3 EQ 'SOMETHING' THEN FIELD4
ELSE IF FIELD3 EQ 'SOMETHINELSE' THEN FIELD5
ELSE IF FIELD3 EQ 'SOMEOTHER' THEN FIELD6;
AS 'SOMENAME'

Another option (if you need to display FIELD4 and FIELD5 if FIELD3 = 'SOMETHING' would be to use subfoots since you are using OVER. Remove the last OVER statement and make FIELD3 the last by field with a NOPRINT and use --

ON FIELD3 SUBFOOT
&quot;<FIELD4&quot;
WHEN FIELD3 EQ 'SOMETHING'

ON FIELD3 SUBFOOT
&quot;<FIELD5&quot;
WHEN FIELD3 EQ 'SOMETHING' OR 'SOMETHINELSE'

ON FIELD3 SUBFOOT
&quot;<FIELD6&quot;
WHEN FIELD3 EQ 'SOMEOTHER'
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top