1

To begin with, I am not looking for just a solution to fix this error message. I would be far more appreciative of being directed to documentation explaining this error than a solution to the code problem. I need to understand WHY this is happening because I cannot find any documentation which explains what is causing this error. I'm relatively new to RPG (less than 2 years) so I'm at a reasonable level of ignorance on this.

I am working on some legacy RPG code which was recompiled in October, 2017. This code has been in place since 2013.

My issue is that my users have recently (within the past 3-4 months) begun to get decimal data errors reported on this line of code:

C                   EvalR     NewValueA = %char(NewValue)

The dumps from the error message shows that NewValue is empty. Not 0, just empty. In my experience with other languages, that's a NULL. None of my resources (including Google) give any indication how NULL is handled by %char() in RPGLE. It would be easy to assume that %char() doesn't handle NULL gracefully and move on, but that's hard to justify in a code review.

NewValue is defined as 7 0 decimal. NewValueA is an 8 character char.

Thanks in advance to all who have productive comments to offer.

CoMo G-Dawg
  • 401
  • 1
  • 3
  • 18
  • 1
    Recommend editing the title of your question to be more descriptive of the problem you're encountering. You're likely to get more engagement that way. – Sean Mar 02 '20 at 20:38

3 Answers3

4

The current version of RPG doesn't fully support NULL.

Specifically, a stand-a-lone variable can't be NULL. Only variables which originate directly or indirectly (via LIKE, LIKEDS, or LIKEREC) in an externally described file (table), and which are defined in that file to allow NULL, can be NULL in an RPG program; and even that requires that the program be compiled with the ALWNULL(*USRCTL) option. See Database Null Value Support

While this support has been available for a long time (the beginning of ILE?), most legacy files and related RPG code don't use NULL.

So NewValue isn't likely to be empty (NULL).
What is the hex value you see in debug?

As jtaylor's answer mentions, most decimal data errors come from bad data being written to legacy DDS defined files. However, in that case, the error would have been thrown when the file was read, not on the line you've shown. (Unless the file is being read directly into a data structure.)

Where is NewValue defined? How does it get a value?

For a program variable, the most likely reason for a decimal data error is that the numeric variable is in a data structure that doesn't specify the INZ keyword. In that case, the data structure gets initialized to all blanks.

Charles
  • 21,637
  • 1
  • 20
  • 44
  • NewValue is defined as part of a data structure `D DS D NewValue 1 7 0 D PrtValue 1 7 2` Here is the value at the time of the error `NEWVALUE ZONED(7,0) . '40404040404040'X ` And the code formatting does not honor whitespace, so I apologize. – CoMo G-Dawg Mar 02 '20 at 21:30
  • 1
    Ok, that's the scenario I described, add the `INZ` keyword to the data structure. Also, you could have just included the code in your question to get better formatting. – Charles Mar 02 '20 at 21:52
  • 1
    Data structures having numerics default to blanks is hole every new RPG programmer must put their foot into at least once. It is ostensibly for efficiency and backwards compatibility since you might not want a large array of data structures to go through and initialize everything to 0. I mean I would want it to, so I use INZ, but in the 70s those clock cycles were more valuable. – Mike Mar 03 '20 at 15:33
  • @MikeSupportsMonica - I wish I could blame this on my ignorance and lack of knowledge, but I inherited it. The person who wrote this has been doing it for a long time, so it's possible that they were ingrained with the habit. @Charles - I'll see if adding that `INZ` keyword takes care of it. – CoMo G-Dawg Mar 03 '20 at 16:18
  • 1
    @CoMoG-Dawg `INZ` should solve the issue, but something has changed for this issue to have just started. If the program hasn't changed, then the way it is being used has. Before, `NewValue` must have been getting data loaded before the `%char()` now it's not. – Charles Mar 03 '20 at 16:21
0

My guess would be that NewValue is being read in from a legacy PF (i.e. DDS) that allows bogus values in that column. Those PFs allow bogus data to be written, but fail when you read it in and try to use it. On the flip side, DDL defined tables will error on the write.

John Y
  • 14,123
  • 2
  • 48
  • 72
jtaylor___
  • 609
  • 1
  • 6
  • 14
0

In such situations, I act as follows:

dcl-s strValue  char(7)  based(pValue);

pValue = %addr(NewValue);

This works for type zoned since in fact, it is identical to type char (regarding storage in memory).

After such a simple manipulation, you can check the value strValue - whether it is empty (contains only spaces), whether it contains non-digits, etc.