Page 1 of 1
Nested If Then Else statement strange behaviour in routines.
Posted: Tue Mar 18, 2008 6:06 am
by MOHAMMAD.ISSAQ
The following code is of a routine :
***************Routine Start***************
Ans = ""
VAL = ""
IF PREMIUM_CATEGORY = "4" THEN
VAL = "SY"
END
IF PREMIUM_CATEGORY = "3" THEN
VAL = "MA"
END
IF PREMIUM_CATEGORY = "2" THEN
VAL = "MM"
END
IF BUSINESS_FG = "G" THEN
IF (PLAN_CD1 = "CES" OR PLAN_CD2 = "CES") THEN
VAL = "ES"
END
ELSE
VAL = "DM"
END
END
IF BUSINESS_FG = "U" THEN
IF (PLAN_CD1 = "CEM" OR PLAN_CD2 = "CEM") THEN
VAL = "EM"
END
ELSE
VAL = "PH"
END
END
IF PLAN_CD1 = "CCB" OR PLAN_CD2 = "CCB" THEN
VAL = "CB"
END
IF PLAN_CD1 = "CAL" OR PLAN_CD2 = "CAL" THEN
VAL = "AN"
END
IF (PLAN_CD1 = "CAT" OR PLAN_CD2 = "CAT") THEN
IF ( RIDER_FORM_CD = "ES" OR RIDER_FORM_CD = "09" ) THEN
VAL = "AH"
END
ELSE
VAL = "AT"
END
END
IF (PLAN_CD1 = " " OR PLAN_CD2 = " ") AND ( RIDER_FORM_CD = "ES" OR RIDER_FORM_CD = "09" ) THEN
VAL = "NH"
END
IF PLAN_CD1 = "CAM" OR PLAN_CD2 = "CAM" THEN
VAL = "AM"
END
IF PLAN_CD1 = "CER" OR PLAN_CD2 = "CER" THEN
VAL = "ER"
END
IF ADJUST_FORM_CD = "H5" THEN
VAL = "KW"
END
IF BUSINESS_FG="N" THEN
IF PROXY_FG = "1" THEN
VAL = "DN"
END
ELSE
VAL = "NZ"
END
END
IF BUSINESS_FG="H" THEN
IF PROXY_FG = "1" THEN
VAL = "DH"
END
ELSE
VAL = "HJ"
END
END
Ans = VAL
***********ROUTINE END******************
When i'm giving value of BUSINESS_FG = "G" and PLAN_CD1 = "CAT"(i,e not equal to CES) then OUTPUT:AT instead of DM
It's not going to the ELSE part.
When i gave BUSINESS_FG = "G" and PLAN_CD1 = "Cd" (i,e. some value other than "CAT") then OUTPUT:DM (correct)
I don't know why this strange thing is happening..
Please help me out..
Posted: Tue Mar 18, 2008 6:17 am
by ArndW
Please try using the "code" tags to make the program legible. I would suggest that you put "PRINT" statements in to ensure that the values are as you expect before the IF-THEN-ELSE parts.
Re: Nested If Then Else statement strange behaviour in routi
Posted: Tue Mar 18, 2008 7:44 am
by chulett
MOHAMMAD.ISSAQ wrote:The following code is of a routine :
Code: Select all
***************Routine Start***************
Ans = ""
VAL = ""
IF PREMIUM_CATEGORY = "4" THEN
VAL = "SY"
END
IF PREMIUM_CATEGORY = "3" THEN
VAL = "MA"
END
IF PREMIUM_CATEGORY = "2" THEN
VAL = "MM"
END
IF BUSINESS_FG = "G" THEN
IF (PLAN_CD1 = "CES" OR PLAN_CD2 = "CES") THEN
VAL = "ES"
END
ELSE
VAL = "DM"
END
END
IF BUSINESS_FG = "U" THEN
IF (PLAN_CD1 = "CEM" OR PLAN_CD2 = "CEM") THEN
VAL = "EM"
END
ELSE
VAL = "PH"
END
END
IF PLAN_CD1 = "CCB" OR PLAN_CD2 = "CCB" THEN
VAL = "CB"
END
IF PLAN_CD1 = "CAL" OR PLAN_CD2 = "CAL" THEN
VAL = "AN"
END
IF (PLAN_CD1 = "CAT" OR PLAN_CD2 = "CAT") THEN
IF ( RIDER_FORM_CD = "ES" OR RIDER_FORM_CD = "09" ) THEN
VAL = "AH"
END
ELSE
VAL = "AT"
END
END
IF (PLAN_CD1 = " " OR PLAN_CD2 = " ") AND ( RIDER_FORM_CD = "ES" OR RIDER_FORM_CD = "09" ) THEN
VAL = "NH"
END
IF PLAN_CD1 = "CAM" OR PLAN_CD2 = "CAM" THEN
VAL = "AM"
END
IF PLAN_CD1 = "CER" OR PLAN_CD2 = "CER" THEN
VAL = "ER"
END
IF ADJUST_FORM_CD = "H5" THEN
VAL = "KW"
END
IF BUSINESS_FG="N" THEN
IF PROXY_FG = "1" THEN
VAL = "DN"
END
ELSE
VAL = "NZ"
END
END
IF BUSINESS_FG="H" THEN
IF PROXY_FG = "1" THEN
VAL = "DH"
END
ELSE
VAL = "HJ"
END
END
Ans = VAL
***********ROUTINE END******************
When i'm giving value of BUSINESS_FG = "G" and PLAN_CD1 = "CAT"(i,e not equal to CES) then OUTPUT:AT instead of DM
It's not going to the ELSE part.
When i gave BUSINESS_FG = "G" and PLAN_CD1 = "Cd" (i,e. some value other than "CAT") then OUTPUT:DM (correct)
I don't know why this strange thing is happening..
Please help me out..
That looks to be controlled by RIDER_FORM_CD, who's value you haven't mentioned.
Posted: Tue Mar 18, 2008 3:25 pm
by ray.wurlod
Print out your code and "bench test" it. Using a pencil trace your way through the various pieces of logic in the code for particular values of the variables. Make sure also that every path through the logic assignes a value to the variable called VAL.
Posted: Tue Mar 18, 2008 4:30 pm
by ShaneMuir
Are you sure your input = 'G' and not 'G ' or some other hidden character?
Posted: Tue Mar 18, 2008 11:34 pm
by MOHAMMAD.ISSAQ
Chulett
RIDER_FORM_CD is BLANK..
I've checked the code and it's flow it's correct.
I don't know what the problem..
Can anybody provide an alternate solution to this..
Re: Nested If Then Else statement strange behaviour in routi
Posted: Wed Mar 19, 2008 12:28 am
by ShaneMuir
MOHAMMAD.ISSAQ wrote:
Code: Select all
IF BUSINESS_FG = "G" THEN
IF (PLAN_CD1 = "CES" OR PLAN_CD2 = "CES") THEN
VAL = "ES"
END
ELSE
VAL = "DM"
END
END
Code: Select all
IF (PLAN_CD1 = "CAT" OR PLAN_CD2 = "CAT") THEN
IF ( RIDER_FORM_CD = "ES" OR RIDER_FORM_CD = "09" ) THEN
VAL = "AH"
END
ELSE
VAL = "AT"
END
END
When i'm giving value of BUSINESS_FG = "G" and PLAN_CD1 = "CAT"(i,e not equal to CES) then OUTPUT:AT instead of DM
It's not going to the ELSE part.
When i gave BUSINESS_FG = "G" and PLAN_CD1 = "Cd" (i,e. some value other than "CAT") then OUTPUT:DM (correct)
I don't know why this strange thing is happening..
Please help me out..
Ok then - your input is hitting the 2nd part of the code. This means that your input for BUSINESS_FG cannot be 'G' else it would have picked up the first bit of code. Check the input for spaces, non printing characters etc.
Posted: Wed Mar 19, 2008 12:59 am
by MOHAMMAD.ISSAQ
I checked Shane, when i kept the same value as BUSINESS_FG = "G" and change only the PLAN_CD1 value for e.g. PLAN_CD1 ="CA" (Other than "CAT" and "CES") then i'm getting the correct output as "DM".
If the problem is with the BUSINESS_FG = "G" then i won't get as "DM"
Please help me out..
Posted: Wed Mar 19, 2008 1:25 am
by ShaneMuir
Does it work correctly when BUSINESS_FG = 'U'?
Posted: Wed Mar 19, 2008 1:40 am
by priyadarshikunal
MOHAMMAD.ISSAQ wrote:I checked Shane, when i kept the same value as BUSINESS_FG = "G" and change only the PLAN_CD1 value for e.g. PLAN_CD1 ="CA" (Other than "CAT" and "CES") then i'm getting the correct output as "DM".
If the problem is with the BUSINESS_FG = "G" then i won't get as "DM"
Please help me out..
Just dry run the routine
as you said
When i'm giving value of BUSINESS_FG = "G" and PLAN_CD1 = "CAT"(i,e not equal to CES) then OUTPUT:AT instead of DM
It's not going to the ELSE part.
When i gave BUSINESS_FG = "G" and PLAN_CD1 = "Cd" (i,e. some value other than "CAT") then OUTPUT:DM (correct)
Code: Select all
***************Routine Start***************
** Taking BUSINESS_FG = "G" and PLAN_CD1 = "CAT"
Ans = ""
VAL = ""
IF PREMIUM_CATEGORY = "4" THEN
VAL = "SY"
END
IF PREMIUM_CATEGORY = "3" THEN
VAL = "MA"
END
IF PREMIUM_CATEGORY = "2" THEN
VAL = "MM"
END
IF BUSINESS_FG = "G" THEN <<<----True
IF (PLAN_CD1 = "CES" OR PLAN_CD2 = "CES") THEN <<<---False
VAL = "ES"
END
ELSE
VAL = "DM" <<<--- Current Value
END
END
IF BUSINESS_FG = "U" THEN
IF (PLAN_CD1 = "CEM" OR PLAN_CD2 = "CEM") THEN
VAL = "EM"
END
ELSE
VAL = "PH"
END
END
IF PLAN_CD1 = "CCB" OR PLAN_CD2 = "CCB" THEN
VAL = "CB"
END
IF PLAN_CD1 = "CAL" OR PLAN_CD2 = "CAL" THEN
VAL = "AN"
END
IF (PLAN_CD1 = "CAT" OR PLAN_CD2 = "CAT") THEN <<<--- True
IF ( RIDER_FORM_CD = "ES" OR RIDER_FORM_CD = "09" ) THEN <<<---False
VAL = "AH"
END
ELSE
VAL = "AT" <<<--- Current Value
END
END
IF (PLAN_CD1 = " " OR PLAN_CD2 = " ") AND ( RIDER_FORM_CD = "ES" OR RIDER_FORM_CD = "09" ) THEN
VAL = "NH"
END
IF PLAN_CD1 = "CAM" OR PLAN_CD2 = "CAM" THEN
VAL = "AM"
END
IF PLAN_CD1 = "CER" OR PLAN_CD2 = "CER" THEN
VAL = "ER"
END
IF ADJUST_FORM_CD = "H5" THEN
VAL = "KW"
END
IF BUSINESS_FG="N" THEN
IF PROXY_FG = "1" THEN
VAL = "DN"
END
ELSE
VAL = "NZ"
END
END
IF BUSINESS_FG="H" THEN
IF PROXY_FG = "1" THEN
VAL = "DH"
END
ELSE
VAL = "HJ"
END
END
Ans = VAL <<<---VAL=AT Not DM
***********ROUTINE END******************
As Chulett said its driven by the another part
In second part you can define like
If VAL <> 'DM' then VAL='AT'
I am going through it once again to find out if I have done any mistake
You can also try a dry run as Ray said.
Posted: Wed Mar 19, 2008 2:07 am
by MOHAMMAD.ISSAQ
It's not working for BUSINESS_FG = 'U' also
Posted: Wed Mar 19, 2008 2:09 am
by ArndW
Mohammed - please, try putting "PRINT" statements in your job to debug it, right before the offending "IF" statements so that you can see what values are being used.
Posted: Wed Mar 19, 2008 2:23 am
by priyadarshikunal
MOHAMMAD.ISSAQ wrote:It's not working for BUSINESS_FG = 'U' also
Once again its the same problem.
Go through the code
Code: Select all
IF (PLAN_CD1 = "CAT" OR PLAN_CD2 = "CAT") THEN
IF ( RIDER_FORM_CD = "ES" OR RIDER_FORM_CD = "09" ) THEN
VAL = "AH"
END
ELSE
VAL = "AT"
END
END
This code overwrites the value you want
Change the condition with proper condition.
Putting this condition at proper place may also resolve you problem.
Regards,
Posted: Wed Mar 19, 2008 3:36 am
by MOHAMMAD.ISSAQ
Thanks priyadarshikunal for the help.
I change the order of the IF statements.
Now it's coming properly..