Numeric edited field issue



Support for OS/VS COBOL, VS COBOL II, COBOL for OS/390 & VM and Enterprise COBOL for z/OS

Numeric edited field issue

Postby shrishant » Sat Dec 10, 2011 7:32 pm

Hi All,
I have a report file as a input where the amount field has been defined as numeric edited field in the format given below.
I want to read that amount for every record from the input file and do summation.

The picture clause defined for amount field is --------------9.99

I have redefined this field using the below format.

01 Ws-original-amt pic --------------9.99.
01 Ws-field REDEFINES Ws-original-amt.
05 ws-first-value pic S9(15).
05 filler pic x.
05 ws-last-value pic 99.

I am able to read the positive amount using redefine clause but having issues with reading the negative amount. The negative sign is considered as space and I am not able to identify the negative amount.

For example if I have the amount as -15.00 in the input report file then I can see the same amount in display before doing summation using the redefined field (ws-first-value) but the instead of reducing the total it gets increased by 15.

Please let me know if anybody have solution for this.

Regards,
Shrishant
shrishant
 
Posts: 4
Joined: Sat Dec 10, 2011 4:45 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Numeric edited field issue

Postby Robert Sample » Sat Dec 10, 2011 7:49 pm

What I don't understand is why you don't just use
MOVE WS-ORIGINAL-AMT TO <numeric-variable>
since 6.2.24.1.1 of the COBOL Language Reference manual on the MOVE statement explicitly states
When the sending item is numeric-edited, the compiler de-edits the sending data to establish the unedited value of the numeric-edited item (this value can be signed). The unedited numeric value is used in the move to the receiving numeric or numeric-edited data item.
Due to the size of WS-ORIGINAL-AMT you might have to use ARITH(EXTEND) compiler option, but that's no big deal.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Numeric edited field issue

Postby shrishant » Tue Dec 13, 2011 6:10 pm

Thanks for your reply.

I have tried using the numeric variable but when the value of sending data is negative then the negative sign is not considered and the final total after calculation gets added by 15 instead of reducing by 15.
See the display below.

WS-TEST-AGAIN : -1E
SH-B4-CAL-TOT-LN-BAL :0000000012562253E
SH-AT-CAL-TOT-LN-BAL :0000000012562403E

The picture clause of WS-TEST-AGAIN is PIC S9(15) and i have ket the display before compute statement and after compute statement.
The final total is increased by 15.

I have tried to move the numeric edited value into 9(15) as well and that didnt give me the correct total as well. The issue is same as above.

Please let me know if you have any option to resolve this.
Thanks in advance.

Regards,
Shri
shrishant
 
Posts: 4
Joined: Sat Dec 10, 2011 4:45 pm
Has thanked: 0 time
Been thanked: 0 time

Re: Numeric edited field issue

Postby BillyBoyo » Tue Dec 13, 2011 6:36 pm

"-1E" is not a valid numeric-edited value.

"-15" would be valid.

"1E" in a PIC S99 is +15, but is not a valid numeric-edited value.

Maybe you can show your definitions and code if you want assistance in making sense of it.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: Numeric edited field issue

Postby Robert Sample » Tue Dec 13, 2011 6:48 pm

     05  WS-ORIGINAL-AMT               PIC --------------9.99.
     05  WS-NUMERIC-AMT                PIC S9(15)V99.
     05  WS-NUMVAL-AMT                 PIC S9(15)V99.
 PROCEDURE DIVISION                  .
 0000-START.
     MOVE -12345.67                    TO  WS-ORIGINAL-AMT.
     MOVE WS-ORIGINAL-AMT              TO  WS-NUMERIC-AMT.
     COMPUTE WS-NUMVAL-AMT = FUNCTION NUMVAL (WS-ORIGINAL-AMT).
     DISPLAY 'WS-ORIGINAL-AMT <' WS-ORIGINAL-AMT '>'.
     DISPLAY 'WS-NUMERIC-AMT  <' WS-NUMERIC-AMT  '>'.
     DISPLAY 'WS-NUMVAL-AMT   <' WS-NUMVAL-AMT   '>'.
produces results of
 WS-ORIGINAL-AMT <         -12345.67>
 WS-NUMERIC-AMT  <0000000000123456P>
 WS-NUMVAL-AMT   <0000000000123456P>
exactly as expected. So either you are not dealing with pure numeric edited data as you claim, or you are not getting the results you claim.
Robert Sample
Global moderator
 
Posts: 3720
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Numeric edited field issue

Postby shrishant » Wed Dec 14, 2011 3:09 pm

Hey Robert, Thanks a lot buddy.
I did the modification in my code as per your explanation and its working great.

I tried using the PIC S9(15)v99 earlier but I got abend with S0C7.
That must been my misunderstanding and that abend must have been caused due to some other issue in code.

Thanks again for your help. This issue is successfully resovled.

Regards,
Shri
shrishant
 
Posts: 4
Joined: Sat Dec 10, 2011 4:45 pm
Has thanked: 0 time
Been thanked: 0 time


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post