1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Answered Need Reasoning For Below Output (code Attached)

Discussion in 'Development' started by Ashwani Mishra, Aug 22, 2017.

  1. Ashwani Mishra

    Ashwani Mishra New Member

    Hello There,

    Below code show 2 different output for input date. If I pass blank date to function and concatenate the output of funstion to another string, it returns ?. Where as if I simply concatenate 1 string with character "?" it shows the output. Can someone please explain the reason? thanks!

    OS - Window 7, Above code checked in OE10.2B, 11.4

    Code (progress):
    1. DEF VAR cal AS CHAR FORMAT "x(3)" EXTENT 12
    2. INITIAL ["JAN", "FEB", "MAR", "APR", "MAY",
    3. "JUN", "JUL", "AUG", "SEP", "OCT",
    4. "NOV", "DEC"].
    5. DEF VAR d-monddyyyy AS CHAR FORMAT "x(15)" NO-UNDO.
    6. DEF VAR dtblank AS DATE INIT ?.
    7. DEF VAR dt-date AS DATE INIT 08/21/2017.
    8.  
    9. FUNCTION NiceDate RETURNS CHARACTER
    10. (ipDate AS DATE ) FORWARD.
    11.  
    12. d-monddyyyy = NiceDate(dtblank) .
    13. MESSAGE "Date blnk: " + d-monddyyyy
    14.     VIEW-AS ALERT-BOX.
    15. MESSAGE "Date : " + "?"
    16.     VIEW-AS ALERT-BOX.
    17. d-monddyyyy = NiceDate(dt-date) .
    18. MESSAGE "Date : " + d-monddyyyy
    19. VIEW-AS ALERT-BOX.
    20.  
    21.  
    22. FUNCTION NiceDate RETURNS CHARACTER
    23. (ipDate AS DATE ):
    24. /*------------------------------------------------------------------------------
    25. Purpose:
    26. Notes:
    27. ------------------------------------------------------------------------------*/
    28.  
    29. DEFINE VARIABLE chBetterDate AS CHARACTER NO-UNDO.
    30.  
    31. chBetterDate = cal[MONTH(ipdate)] + " "
    32.              + string(DAY (ipDate), "99") + ","
    33.              + string(YEAR(ipDate), " 9999").
    34.  
    35. RETURN chBetterDate.
    36.  
    37.  
    38. END FUNCTION.
    39.  
     
  2.  
  3. Osborne

    Osborne Active Member

    When you add the null value - ? not "?" - to a string it clears the whole string and you just get ?:
    Code (progress):
    1. DEFINE VARIABLE vLogical AS LOGICAL INITIAL ? NO-UNDO.
    2. DEFINE VARIABLE vText AS CHARACTER INITIAL "Some Text" NO-UNDO.
    3.  
    4. vText = vText + " " + STRING(vLogical).
    5.  
    6. MESSAGE "Text =" vText VIEW-AS ALERT-BOX.
    I am not sure of the exact reason, but remember reading it is something to do with Progress using null to terminate a character string.
     
  4. Ashwani Mishra

    Ashwani Mishra New Member

    Thanks for your response. After your reply, I did search how progress deals with null value and found few KB articles. My problem was, I was getting few null values in temp table and while sending this values to HTML file after adding null to character strings, It was making whole HTML file blank i.e. ?. So now I have to put a check for all those fields and handle it before sending it HTML. Thanks again.
     
  5. TomBascom

    TomBascom Curmudgeon

    ? <> "?"

    The first is "the unknown value" -- aka null. The second is the question mark character. They are NOT the same.

    Just like 0 <> "0".

    When you say "I pass blank date" you probably mean that the value of the date that you are passing is null. (When you display an unknown date it shows as blank.)

    When you concatenate strings if any part of the string is unknown the entire string becomes unknown. Because if you add something unknown to something that is known the result is unknown. It's infectious - or "viral" ;)

    One simple way to avoid this is to use the SUBSTITUTE() function rather than concatenation. SUBSTITUTE() converts unknown values to the "?" character -- which is much friendlier than making the whole string ?. This you might code:

    Code (progress):
    1.  
    2. define variable monthList as character no-undo initial "Jan,Feb,Mar,Apr,May,Jun,Jul,Aug,Sep,Oct,Nov,Dec".
    3. define variable d as date no-undo.
    4.  
    5. d = today.
    6.  
    7. display substitute( "&1 &2, &3", entry( month( d ), monthList ), string( day( d ), "99" ), string( year( d ), "9999" )) format "x(12)".
    8.  
    This will display the string "?, ? ?" rather than the unknown value if you have a null date. That avoids the problem of a viral unknown string.

    Note: SUBSTITUTE() does do automatic type conversions but it converts its arguments to strings using EXPORT format -- so if you want formatting like "9999" for the year you need to wrap a STRING() call with a format spec around the argument.
     
    Last edited: Aug 22, 2017
    Marco Mendoza likes this.
  6. Ashwani Mishra

    Ashwani Mishra New Member

    Thanks a ton Tom, This is such a great explanation. I was seeking a reason for it and you gave me proper solution :)
     

Share This Page