Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Data Decimal Error using a Data Structure

Status
Not open for further replies.

jsplice

Programmer
Jun 3, 2003
88
US
Hello all. I'm having a problem using a data structure; when trying to sum a certain subfield of the data structure, I receive a data decimal error that I cannot resolve. Here is the code:
Code:
     D ReportTable     DS                  DIM(10000) QUALIFIED
     D  VendorNum                     7P 0 INZ(*HIVAL)
     D  Payee                        20A   INZ(*HIVAL)
     D  InvNum                        7A   INZ(*HIVAL)
     D  DueDate                       8P 0 INZ(*HIVAL)
     D  InvTotal                      8P 2 INZ(*HIVAL)
     D  Discount                      9P 2 INZ(*HIVAL)
     D  NetCheck                     11S 2 INZ(*HIVAL)

     D NumRec          S              8  0
     D VendorTotal     S              8P 2
     D NetCheckTotal   S             11S 2
     D VendorNumTemp   S              7P 0
     D SortArray       S             50A   DIM(10000)
     D i               S              5  0            

     //the following code is within a loop that is reading all records in a file and placing the info into the data structure which is later sorted
       NumRec += 1;
       ReportTable(NumRec).VendorNum = A7SUP#;
       ReportTable(NumRec).Payee = A7SRC;
       ReportTable(NumRec).InvNum = A7INVN;
       ReportTable(NumRec).DueDate = A7DUDT;
       ReportTable(NumRec).InvTotal = A7INV$;
       ReportTable(NumRec).Discount = A7DS$;
       ReportTable(NumRec).NetCheck = A7INV$ - A7DS$;


       //Sort the table array ---------------------------------------------------------------
       For i = 1 to %Elem(ReportTable);
         SortArray(i) = ReportTable(i);
       EndFor;
       SortA SortArray;
       For i = 1 to %Elem(ReportTable);
         ReportTable(i) = SortArray(i);
       EndFor;

       //Processing for summary report ------------------------------------------------------
       VendorNumTemp = ReportTable(1).VendorNum;
       For i = 1 to NumRec;
         If VendorNumTemp = ReportTable(i).VendorNum;
           VendorTotal += ReportTable(i).InvTotal;
//****ERROR OCCURS ON THE LINE BELOW*************
           NetCheckTotal += ReportTable(i).NetCheck;
           VendorNumTemp = ReportTable(i).VendorNum;
           VENNUM2 = ReportTable(i).VendorNum;
           PAYEE2 = ReportTable(i).Payee;
           INVNUM2 = ReportTable(i).InvNum;
           DUEDATE2 = ReportTable(i).DueDate;
           INVTOTAL2 = ReportTable(i).InvTotal;
           DISCOUNT2 = ReportTable(i).Discount;
           NETCHECK2 = ReportTable(i).NetCheck;
           If *IN96 = *ON;
             write HEADER2;
             *IN96 = *OFF;
           EndIf;
           write DETAIL2;
           Iter;
         Else;
           If *IN96 = *ON;
             write HEADER2;
             *IN96 = *OFF;
           EndIf;
           VENTOTAL2 = VendorTotal;
           NETCHKTOT2 = NetCheckTotal;
           write DETAIL2;
           VendorTotal = *zeros;
           NetCheckTotal = *zeros;
           VendorNumTemp = ReportTable(i).VendorNum;
         EndIf;
       EndFor;

It gives me a decimal data error saying "Cause . . . . . : The sign or the digit codes of the packed or the zoned
decimal operand is in error. Valid signs are hex A-F, valid digit range is hex 0-9."

The other weird thing, is that before it enters the For loop, the value for ReportTable(i).NetCheck is ok. But as soon as it enters the loop, the two decimal values are always .04.

I've tried playing around with different data types in the data structure and for the NetCheckTotal variable, but I always get the same results. I just don't understand why entering a For loop would cause something like this.


Thanks

 
Well I just found that the sort array has all kinds of junk data in it after moving the values from ReportTable into SortArray. This is the only thing I could think of as far as being able to sort those values without using a work file. Any suggestions?
 
Why do you have INZ(*HIVAL) on all of the subfields of the DS? Is there a reason for that?

I would put an INZ on the whole data structure and drop the INZ(*HIVAL) on the individual subfields. And, before you move anything into the DS, do this:

Code:
Clear *ALL ReportTable;

That will clear the entire data structure and set the values to blanks or zeros, as appropriate for the type of field.

Tibi gratias agimus quod nihil fumas.

 
each ReportTable entry is actually 57 bytes long while SortArray is only 50.
 
Ah - good catch, Mercury2. I missed that.


Tibi gratias agimus quod nihil fumas.

 
jsplice,
BTW you'd be better off using the fast QSORT() API instead of the antique SortA (-:

 
Thanks for the replies, guys. Actually I had begun coding this before I realized that the file from which I am reading has actual fields in it; all programs like this one that I was doing before, I read in data from a flat file so I had to parse the data and sort via my own method. But with this program I was able to just use a logical file which got things in the order I needed. But I will definitely remember the QSORT for next time. Thanks again.
 
> BTW you'd be better off using the fast QSORT() API instead of the antique SortA

Just curious. Why? Does it perform better ?
 
Scott Klement said:
The qsort() and bsearch() APIs use %paddr() to call the "compare" routine. This provides a level of flexibility that's unmatched by any of the other sort routines, without adding much complexity.

Additionally, you might read the Rory Hewitt's Article published in March 2006 by System iNetwork titled A (Better?) Sorting Technique.
(I believe that a System iNetwork membership isn't required to read the article)


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top