Focal Point
[CLOSED] Can I condition which field to print

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

October 24, 2011, 06:44 PM
Brenda Wilkerson
[CLOSED] Can I condition which field to print
I have a merged file with 3 different date fields. I need to condition which one actually prints on a report based on the value of another field. Is this possible?

example: If tran_type = 'R' Print dateAA
else If tran_type = 'E' Print dateBB
else If tran_type = 'A' Print dateCC


Report looks something like this:
Name tran_type Date count
John R 07/11 40
John E 08/01/2011 29 John A 31 Amy R 09/10 17 Amy R 12/11 7 Amy E 07/14/2011 21
Bill R 02/11 44 Bill R 12/11 19 Bill E 08/01/2011 21

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



WebFOCUS 7.7.03
Windows 7
October 24, 2011, 06:52 PM
Brenda Wilkerson
Well that report sample didn't come out right, try it again..


Name tran_type Date count
John R 07/11 40
John E 08/01/2011 29
John A 31
Amy R 09/10 17
Amy R 12/11 7
Amy E 07/14/2011 21
Bill R 02/11 44
Bill R 12/11 19
Bill E 08/01/2011 21



WebFOCUS 7.7.03
Windows 7
October 24, 2011, 06:53 PM
Waz
I think you have answered your own question

DEFINE or COMPUTE
PRINT_DATE/{format} = IF TRAN_TYPE EQ 'R' THEN dateAA ELSE
IF TRAN_TYPE EQ 'E' THEN dateBB ELSE
IF TRAN_TYPE EQ 'A' THEN dateCC ELSE {other date} ;



Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

October 24, 2011, 08:48 PM
Brenda Wilkerson
getting If then else syntax error. I'm new at this for WF so I must be missing something. Here is actual:
COMPUTE PRINT_DATE/A20V = IF MERGE.MERGE.TYPE EQ 'R' THEN MERGE.MERGE.MMYY ELSE
IF MERGE.MERGE.TYPE EQ 'E' THEN MERGE.MERGE.OLDEST ELSE
IF MERGE.MERGE.TYPE EQ 'A' THEN MERGE.MERGE.ALL ;



WebFOCUS 7.7.03
Windows 7
October 24, 2011, 09:47 PM
Doug
Please post a copy of your error message. It may have something to do with the fieldname: "TYPE" (MERGE.MERGE.TYPE). But, a closer look at the error message and number may prove otherwise...




   In FOCUS Since 1983 ~ from FOCUS to WebFOCUS.
   Current: WebFOCUS Administrator at FIS Worldpay | 8204, 8206
October 24, 2011, 09:59 PM
Brenda Wilkerson
Here is the error:

(FOC266) IF .. THEN .. ELSE .. SYNTAX ERROR
(FOC009) INCOMPLETE REQUEST STATEMENT
BYPASSING TO END OF COMMAND



WebFOCUS 7.7.03
Windows 7
October 24, 2011, 10:09 PM
Waz
I would suggest adding an ELSE something at the end of the IF THEn ELSE for the compute.


Waz...

Prod:WebFOCUS 7.6.10/8.1.04Upgrade:WebFOCUS 8.2.07OS:LinuxOutputs:HTML, PDF, Excel, PPT
In Focus since 1984
Pity the lost knowledge of an old programmer!

October 25, 2011, 03:44 AM
Dave
Brenda,

is het possible that one ( or more ) of the dates is 'empty' or 'missing'?

That might cause the IF...THEN...ELSE error.

Have you tried using a define instead?

G'luck


_____________________
WF: 8.0.0.9 > going 8.2.0.5
October 25, 2011, 09:23 AM
Brenda Wilkerson
The dates are different formats, 1 is yymd and the other 2 are A20V so I will have to convert the date formatted one in the if statement? When I commented that date out, it ran.



WebFOCUS 7.7.03
Windows 7
October 25, 2011, 09:48 AM
njsden
Yes Brenda. Your PRINT_DATE compute field is defined as A20V and therefore it expects that every result sent to it is an alphanumeric value. If your expression contains numbers or dates then they have to be converted to alphas.

You can use DATECVT to convert dates to alpha, and EDIT/FTOA/PTOA to convert numbers to alpha.



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 25, 2011, 11:30 AM
Dgraff
Brenda convert the dates to the same format first in a Define and then do the IF then Else using the converted dates.


Duane

WebFOCUS 8.0.7
DS 8.0.7 AS 8.0.7
Windows
Output: Excel, HTML, PDF, AHTML,Mobile
In Focus 1982
October 25, 2011, 03:51 PM
Brenda Wilkerson
thx, got it to work with the define.....

Code below, if there is a shorter way around this, please let me know. Otherwise thanks so much for all your help Big Grin

DEFINE FILE MERGE
cvtdate/YYMD=DATECVT(OLDEST, 'YYMD', 'YYMD');
cvtdate1/A8YYMD=cvtdate;
cvtdate2/A20V=cvtdate1;
cvtdatedsp/A20V=EDIT(cvtdate2,'9999/99/99');
END



WebFOCUS 7.7.03
Windows 7
October 25, 2011, 04:02 PM
njsden
quote:
DATECVT(OLDEST, 'YYMD', 'YYMD');


Is OLDEST already a date? No conversion is taking place in the code you posted.

Try this:

DEFINE FILE MERGE
cvtdatedsp/A20V=EDIT(DATECVT(OLDEST,'YYYY','A8YYMD'),'9999/99/99')
END




Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 25, 2011, 04:25 PM
Brenda Wilkerson
oldest is a YYMD date,



WebFOCUS 7.7.03
Windows 7
October 25, 2011, 04:35 PM
njsden
I figured so. Using the DEFINE line I posted above takes care of converting your date into an alpha field [ DATECVT(date, 'YYMD',' A8YYMD) ] and then formatting it by adding "/" in between the components.

Not functionally different from your original logic but you'll be saving yourself 3 temporary fields from the internal matrix for each processed row. Yeah, even on this day and time I still worry about saving one byte here and there Wink



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
October 25, 2011, 05:10 PM
Brenda Wilkerson
Yes, thank you that worked as well and cleaner. I knew there had to be an easier way but being fairly new at this, couln't put it together from looking at the help.

I took classed over 3 years ago and by the time we installed WF I had been pulled off on other projects. I am just now getting my feet wet again and it has been a struggle. The old saying "what you don't use you loose" is so true. But, I am getting there.

Thanks again



WebFOCUS 7.7.03
Windows 7
October 25, 2011, 06:37 PM
njsden
Well, better late than never to get back to dive into WebFOCUS waters! Just don't give up Brenda and keep both the WF documentation and the URL to this forum nearby as it has been (and continues to be) of great help to many of us.

As other folks in this forum have said before, happy WebFOCUS sailing!



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.