Hi Guys,
I'm very confused and not sure why my "IF NOT AVAILABLE" statement isn't working under certain scenarios.
For example when I use the FIND function in the working code with the "IF NOT AVAILABLE" statement, the "UNAVAILABLE COLOUR" message is displayed as I expect. I can then amend the code with the following statement "IF AVAILABLE" and message it's an "AVAILABLE COLOUR" else "UNAVAILABLE COLOUR".
WORKING CODE
However when I use the below blocks of code that aren't working, it always displays the message when the colour exists but doesn't display the required message when it doesn't exist.
NOT WORKING CODE (VERSION 1)
NOT WORKING CODE (VERSION 2)
I'm obviously missing something but can't see what.... the only difference being FIND vs FOR EACH.
Thanks
I'm very confused and not sure why my "IF NOT AVAILABLE" statement isn't working under certain scenarios.
For example when I use the FIND function in the working code with the "IF NOT AVAILABLE" statement, the "UNAVAILABLE COLOUR" message is displayed as I expect. I can then amend the code with the following statement "IF AVAILABLE" and message it's an "AVAILABLE COLOUR" else "UNAVAILABLE COLOUR".
WORKING CODE
Code:
DEFINE TEMP-TABLE tt-ColourTab
FIELD ttColour AS CHAR
FIELD ttColCode AS CHAR.
CREATE tt-ColourTab.
tt-ColourTab.ttColour = "RED".
tt-ColourTab.ttColCode = "002".
CREATE tt-ColourTab.
tt-ColourTab.ttColour = "GREEN".
tt-ColourTab.ttColCode = "003".
FIND tt-ColourTab WHERE
tt-ColourTab.ttColour = "BLUE".
IF NOT AVAILABLE tt-ColourTab THEN DO:
MESSAGE "UNAVAILABLE COLOUR".
END.
ELSE
MESSAGE "AVAILABLE COLOUR".
However when I use the below blocks of code that aren't working, it always displays the message when the colour exists but doesn't display the required message when it doesn't exist.
NOT WORKING CODE (VERSION 1)
Code:
DEFINE TEMP-TABLE tt-ColourTab
FIELD ttColour AS CHAR
FIELD ttColCode AS CHAR.
CREATE tt-ColourTab.
tt-ColourTab.ttColour = "RED".
tt-ColourTab.ttColCode = "002".
CREATE tt-ColourTab.
tt-ColourTab.ttColour = "GREEN".
tt-ColourTab.ttColCode = "003".
FOR EACH tt-ColourTab WHERE
tt-ColourTab.ttColour = "BLUE".
IF NOT AVAILABLE tt-ColourTab THEN DO:
MESSAGE "UNAVAILABLE COLOUR".
END.
ELSE
MESSAGE "AVAILABLE COLOUR".
END.
NOT WORKING CODE (VERSION 2)
Code:
DEFINE TEMP-TABLE tt-ColourTab
FIELD ttColour AS CHAR
FIELD ttColCode AS CHAR.
CREATE tt-ColourTab.
tt-ColourTab.ttColour = "RED".
tt-ColourTab.ttColCode = "002".
CREATE tt-ColourTab.
tt-ColourTab.ttColour = "GREEN".
tt-ColourTab.ttColCode = "003".
FOR EACH tt-ColourTab WHERE
tt-ColourTab.ttColour = "GREY".
IF AVAILABLE tt-ColourTab THEN DO:
MESSAGE "AVAILABLE COLOUR".
END.
ELSE
MESSAGE "UNAVAILABLE COLOUR".
END.
I'm obviously missing something but can't see what.... the only difference being FIND vs FOR EACH.
Thanks