Nested If Then Else statement strange behaviour in routines.

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
MOHAMMAD.ISSAQ
Participant
Posts: 78
Joined: Fri Mar 02, 2007 4:54 am
Location: CHENNAI

Nested If Then Else statement strange behaviour in routines.

Post 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..
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Re: Nested If Then Else statement strange behaviour in routi

Post 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.
-craig

"You can never have too many knives" -- Logan Nine Fingers
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

Are you sure your input = 'G' and not 'G ' or some other hidden character?
MOHAMMAD.ISSAQ
Participant
Posts: 78
Joined: Fri Mar 02, 2007 4:54 am
Location: CHENNAI

Post 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..
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Re: Nested If Then Else statement strange behaviour in routi

Post 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.
MOHAMMAD.ISSAQ
Participant
Posts: 78
Joined: Fri Mar 02, 2007 4:54 am
Location: CHENNAI

Post 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..
ShaneMuir
Premium Member
Premium Member
Posts: 508
Joined: Tue Jun 15, 2004 5:00 am
Location: London

Post by ShaneMuir »

Does it work correctly when BUSINESS_FG = 'U'?
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post 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.
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
MOHAMMAD.ISSAQ
Participant
Posts: 78
Joined: Fri Mar 02, 2007 4:54 am
Location: CHENNAI

Post by MOHAMMAD.ISSAQ »

It's not working for BUSINESS_FG = 'U' also
ArndW
Participant
Posts: 16318
Joined: Tue Nov 16, 2004 9:08 am
Location: Germany
Contact:

Post 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.
priyadarshikunal
Premium Member
Premium Member
Posts: 1735
Joined: Thu Mar 01, 2007 5:44 am
Location: Troy, MI

Post 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,
Priyadarshi Kunal

Genius may have its limitations, but stupidity is not thus handicapped. :wink:
MOHAMMAD.ISSAQ
Participant
Posts: 78
Joined: Fri Mar 02, 2007 4:54 am
Location: CHENNAI

Post by MOHAMMAD.ISSAQ »

Thanks priyadarshikunal for the help.
I change the order of the IF statements.

Now it's coming properly..
Post Reply