ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

YAJLINTO null handling

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • YAJLINTO null handling

    Data-into with YAJLINTO. You can use %parser's 2nd parameter to specify various options like override values for true/false.
    One of those is an override value for null, which is giving me trouble, because it's one value regardless of the data type of the RPG field receiving the value.

    So if my DS is this:
    Code:
    dcl-s myjson qualified;
      myStr   varchar(10);
      myNum   int(10);
    end-ds;
    The only null value compatible with both is 0? But I want my null strings to be blank, not '0'

    So what are my options? Is there a way of defining separate string, numeric, and date/time/timestamp null values?
    Or do I have to set all my DS fields to character, and then convert them in RPGLE to numeric/date/time/timestamp?

  • #2
    The only approach I can think of is to use space and define myNum as char not int. Then test the char field and load up the working copy of myNum with zero or the %Dec version of the char version.

    This is actually IBM's suggested approach for DATA-INTO and XML-INTO for any numeric that may from time to time get a non-numeric value. In the future IBM hopefully will change %Dec/%Int to allow a blank to be treated as a valid numeric (i.e. 0) - When that happens XXX-INTO will also accept blanks in "numeric" data.

    Comment


    • #3
      That is what I ended up doing. Though it would be nice if YAJLINTO allowed type-specific null conversions, or an option to treat null the same as missing and leave the DS field to its previous/inz value

      Sir Scott - feature suggestion?

      Comment


      • #4
        Originally posted by Vectorspace View Post
        That is what I ended up doing. Though it would be nice if YAJLINTO allowed type-specific null conversions, or an option to treat null the same as missing and leave the DS field to its previous/inz value

        Sir Scott - feature suggestion?
        Yes - I'm currently writing an article and building a presentation on DATA-INTO and YAJLINTO and it occurred to me that a type specific default would be good. The example that triggered me into thing that was defaulting for dates. Now that would really mess up your numbers!

        Of course we have the source code so ... when you have 5 minutes to spare!

        Comment


        • #5
          As Jon said, define them both as character. When you need the value as numeric, you can do something = %int(myNum) to make it numeric.

          Then have a value like "*NULL" placed for null values. This way, you can tell the difference between a null value and a blank value (which are very different things.)

          Unfortunately, this is pretty much all that can be done, here.. DATA-INTO does not offer the possibility for a parser to set a field value to RPG's concept of null.

          Comment

          Working...
          X