×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Contact US

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Data Decimal Error using a Data Structure

Data Decimal Error using a Data Structure

Data Decimal Error using a Data Structure

(OP)
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

RE: Data Decimal Error using a Data Structure

(OP)
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?

RE: Data Decimal Error using a Data Structure

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.

RE: Data Decimal Error using a Data Structure

each ReportTable entry is actually 57 bytes long while SortArray is only 50.

RE: Data Decimal Error using a Data Structure

Ah - good catch, Mercury2. I missed that.
 

Tibi gratias agimus quod nihil fumas.

RE: Data Decimal Error using a Data Structure

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

RE: Data Decimal Error using a Data Structure

(OP)
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.

RE: Data Decimal Error using a Data Structure

> BTW you'd be better off using the fast QSORT() API instead of the antique SortA

Just curious.  Why?  Does it perform better ?

RE: Data Decimal Error using a Data Structure

Quote (Scott Klement):

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)


Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close