Nested If Then Else statement strange behaviour in routines.
Moderators: chulett, rschirm, roy
-
- Participant
- Posts: 78
- Joined: Fri Mar 02, 2007 4:54 am
- Location: CHENNAI
Nested If Then Else statement strange behaviour in routines.
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..
***************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..
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.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
Re: Nested If Then Else statement strange behaviour in routi
That looks to be controlled by RIDER_FORM_CD, who's value you haven't mentioned.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..
-craig
"You can never have too many knives" -- Logan Nine Fingers
"You can never have too many knives" -- Logan Nine Fingers
-
- Participant
- Posts: 54607
- Joined: Wed Oct 23, 2002 10:52 pm
- Location: Sydney, Australia
- Contact:
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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
-
- Participant
- Posts: 78
- Joined: Fri Mar 02, 2007 4:54 am
- Location: CHENNAI
Re: Nested If Then Else statement strange behaviour in routi
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.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
When i'm giving value of BUSINESS_FG = "G" and PLAN_CD1 = "CAT"(i,e not equal to CES) then OUTPUT:AT instead of DMCode: 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
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..
-
- Participant
- Posts: 78
- Joined: Fri Mar 02, 2007 4:54 am
- Location: CHENNAI
-
- Premium Member
- Posts: 1735
- Joined: Thu Mar 01, 2007 5:44 am
- Location: Troy, MI
Just dry run the routineMOHAMMAD.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..
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******************
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.
Priyadarshi Kunal
Genius may have its limitations, but stupidity is not thus handicapped.
Genius may have its limitations, but stupidity is not thus handicapped.
-
- Participant
- Posts: 78
- Joined: Fri Mar 02, 2007 4:54 am
- Location: CHENNAI
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.
<a href=http://www.worldcommunitygrid.org/team/ ... TZ9H4CGVP1 target="WCGWin">
</a>
</a>
-
- Premium Member
- Posts: 1735
- Joined: Thu Mar 01, 2007 5:44 am
- Location: Troy, MI
Once again its the same problem.MOHAMMAD.ISSAQ wrote:It's not working for BUSINESS_FG = 'U' also
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
Change the condition with proper condition.
Putting this condition at proper place may also resolve you problem.
Regards,
Priyadarshi Kunal
Genius may have its limitations, but stupidity is not thus handicapped.
Genius may have its limitations, but stupidity is not thus handicapped.
-
- Participant
- Posts: 78
- Joined: Fri Mar 02, 2007 4:54 am
- Location: CHENNAI