Focal Point
[SOLVED] Conditional execution of fexes using -INCLUDE

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

April 19, 2017, 04:30 PM
Nova27
[SOLVED] Conditional execution of fexes using -INCLUDE
Hello everyone,

I am trying to call 2 fexes from a single fex - the 2 fexes are called based on a Language code Eng or French.

-IF &LANG_CDE EQ 'FR' THEN GOTO FR_RPT ELSE GOTO ENG_RPT;

-FR_RPT
-INCLUDE app/frrpt.fex
-GOTO EXIT

-ENG_RPT
-INCLUDE app/engrpt.fex
-GOTO EXIT

-EXIT


I read the Language code from a ON TABLE HOLD command and I also verified the value in the variable using -TYPE command. Irrespective of the value in the variable, the ENG_RPT fex is the one that executes always. Even if the language code is FR for French, the English version executes. The control does not go to the FR_RPT label at all, no matter what the value of the &LANG_CDE variable is!

I am not sure what I am doing wrong here - am I using labels or -INCLUDE incorrectly?

Thanks in advance for all your help!

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


WF 7.7.03, Win 7
April 19, 2017, 04:33 PM
BabakNYC
Change the code to say -EXIT instead of -GOTO EXIT.


WebFOCUS 8206, Unix, Windows
April 20, 2017, 07:31 AM
MartinY
And why not just perform as this:
-INCLUDE app/&LANG_CDE.EVALrpt.fex

No need to test the language and perform GOTO.

And if you still want to use the GOTO either use Babak suggestion or have a real tag
-IF &LANG_CDE EQ 'FR' THEN GOTO FR_RPT ELSE GOTO ENG_RPT;

-FR_RPT
-INCLUDE app/frrpt.fex
-GOTO XEXIT

-ENG_RPT
-INCLUDE app/engrpt.fex
-GOTO XEXIT

-XEXIT
-EXIT



WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
April 20, 2017, 08:22 AM
BabakNYC
MartinY's suggestion is more elegant.

The point is -EXIT is a reserved syntax that basically means quit processing. You shouldn't use it as a label.


WebFOCUS 8206, Unix, Windows
April 20, 2017, 08:41 AM
Nova27
Tried changing the name of the label for EXIT, but that doesn't help.. I don't think this has anything to do with the label name...

Basically, when the language code is FR it still does not go to the label meant for executing the French version of the report.. It just goes to the Eng report label...

I am not sure why the control won't go to the French report label like it is supposed to!!?

Thanks!


WF 7.7.03, Win 7
April 20, 2017, 08:49 AM
BabakNYC
Please add

-SET &ECHO=ALL;

to the beginning of the code and run it. What does the echo show?


WebFOCUS 8206, Unix, Windows
April 20, 2017, 09:03 AM
Nova27
TABLE FILE T_CAN_CDE_CNDCT_BOX_1
 PRINT
 LANG_CDE
 WHERE MER_NUM EQ 8029283432
 ON TABLE HOLD
 END
 -RUN
 0 NUMBER OF RECORDS IN TABLE=       24  LINES=     24
 -READ HOLD &LANGCDE.A4.
 -TYPE ##AFTER_READ = FR
 ##AFTER_READ = FR
 -IF FR EQ FR THEN GOTO FR_PDF ELSE GOTO ENG_PDF;
 -ENG_PDF
 -TYPE ##INSIDE_ENG_LABEL = FR
 ##INSIDE_ENG_LABEL = FR
 -*-INCLUDE app/disclosurepacket.fex
 -GOTO XEXIT
 -XEXIT
 -EXIT


This is part of the result of SET &ECHO=ALL

Here, in the READ statement - I am reading the language code. It is FR in this case.
Then I just used TYPE to check my value after READ.
The IF statement also replaces &LANGCDE with FR (as expected) and the test is true for FR EQ FR so it should go to the FR_PDF label, but instead it goes to the ENG_PDF label Frowner

And I have a TYPE inside the ENG_PDF label to see what the value is for &LANGCDE, which it says is FR.. I just don't know why it won't go to the FR_PDF label Frowner


WF 7.7.03, Win 7
April 20, 2017, 09:22 AM
BabakNYC
Could it be caused by the A4 size of the &LANG_CDE? I mean maybe your if test is 'FR ' EQ 'FR' which will not be true. Try LTRIM(&LANG_CDE) to get rid of any spaces.


WebFOCUS 8206, Unix, Windows
April 20, 2017, 09:35 AM
Nova27
Isn't LTRIM only used by SQL queries? How do I use it here?

Can't use it in PRINT statement or IF statement either.


WF 7.7.03, Win 7
April 20, 2017, 09:37 AM
BabakNYC
-IF LTRIM(&LANG_CDE) EQ 'FR' THEN GOTO FR_RPT ELSE GOTO ENG_RPT;


WebFOCUS 8206, Unix, Windows
April 20, 2017, 09:48 AM
Nova27
quote:
IF LTRIM(&LANG_CDE) EQ 'FR' THEN GOTO FR_RPT ELSE GOTO ENG_RPT;


This doesn't work with -IF statement, throws an error - I tried earlier.

Anyway, the LTRIM idea is good.. I converted my TABLE FILE statement to a SQL query where I use LTRIM and now the logic works just fine...
It is strange how I couldn't trim the LANG_CDE field when I read it from my master file!!

Thanks a lot for all your help and assistance!


WF 7.7.03, Win 7
April 20, 2017, 09:51 AM
BabakNYC
Your langcde format is set at the -READ.

-READ HOLD &LANGCDE.A4.

But the LTRIM syntax works when I tested it on my side and didn't get any errors. I'm happy you figured it out.


WebFOCUS 8206, Unix, Windows
April 20, 2017, 09:52 AM
susannah
test the size of your &variable
-SET &LANGCDE = TRUNCATE(&LANGCDE);
-TYPE length: &LANGCDE.LENGTH
I use something like Martin's idea:
-SET &cmt_fr = IF &LANGCDE.QUOTEDSTRING EQ 'FR' THEN '' ELSE '-*';
-SET &cmt_en = IF &cmt_fr.QUOTEDSTRING EQ '-*' THEN '' ELSE '-*'
&cmt_fr.EVAL-INCLUDE app/frrpt.fex
&cmt_en.EVAL-INCLUDE app/engrpt.fex




In Focus since 1979///7706m/5 ;wintel 2008/64;OAM security; Oracle db, ///MRE/BID
April 20, 2017, 10:18 AM
MartinY
Nova,

No matter how you perform and call your INCLUDE (using my version, Babak or Susannah) all your problem is related to you &LANGCDE variable.

One thing you can try to prove that is the following:
TABLE FILE T_CAN_CDE_CNDCT_BOX_1
 PRINT LANG_CDE
 WHERE MER_NUM EQ 8029283432
 ON TABLE HOLD
 END
-RUN
-DEFAULTH &LANG_CDE = ''
-READFILE HOLD
-TYPE ##AFTER_READ = -&LANG_CDE-

-IF &LANG_CDE NE 'FR' THEN GOTO ENG_PDF ELSE GOTO FR_PDF;
-FR_PDF
-TYPE ##INSIDE_FR_LABEL = -&LANG_CDE-
-GOTO XEXIT
-ENG_PDF
-TYPE ##INSIDE_ENG_LABEL = -&LANG_CDE-
-GOTO XEXIT
-XEXIT
-EXIT

First I use READFILE instead of READ. That way you don't bother for format.
Second I add dashes enclosing your variable. You will then see its real value (including spaces)
Third I reversed the test just to see what will happen.


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007
April 20, 2017, 10:36 AM
Nova27
Thanks Martin - your way works as expected. I think using READFILE made all the difference, don't need LTRIM anymore. The LANG_CDE variable spits out the value without any spaces.

I think since I was using READ and had to give it a format, that's where I was encountering issues with the extra spaces.

Thanks everyone once again for helping me out! Really appreciate it! Smiler


WF 7.7.03, Win 7
April 20, 2017, 11:26 AM
j.gross
You could make the test insensitive to trailing blanks, by using CONTAINS instead of EQ:

-IF &LANG_CDE CONTAINS 'FR' THEN ...


- Jack Gross
WF through 8.1.05
April 20, 2017, 12:13 PM
MartinY
Also have to pay attention to your NLS setting (Client and Server).
If you are sure that the language read will always come from your TABLE FILE... and only have FR and EN values, you are good to go.

But if you may use the IBIWF_language variable it may contains FC standing for French Canadian where FR is for French France.
So you may need to test both FR and FC or have something such as (in a common profile) :
-DEFAULTH &LANG = '';
-SET &LANG   = IF &LANG EQ 'FOC_NONE' OR '_FOC_NULL' OR '' THEN UPCASE(2, &IBIWF_language, 'A2') ELSE ⟨
-SET &LANG   = IF &LANG CONTAINS 'FC' OR 'FR' THEN 'FR' ELSE ⟨
-SET &LANG   = IF &LANG CONTAINS 'US'         THEN 'EN' ELSE ⟨

and then use &LANG to identify the selected language.


WF versions : Prod 8.2.04M gen 33, Dev 8.2.04M gen 33, OS : Windows, DB : MSSQL, Outputs : HTML, Excel, PDF
In Focus since 2007