On size error with comp-3 fields



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

On size error with comp-3 fields

Postby dexik » Thu Jul 26, 2012 7:40 am

Can I do this? (it is giving me on size error) :

01 GPA PIC 9(3)V99.
01 TOTAL-GPA PIC 9(3)V99.
01 AVERAGE-GPA PIC9(3)V99.
01 QTY PIC 99.

MOVE 14 TO QTY.
MOVE 34.45 TO TOTAL-GPA.

DIVIDE TOTAL-GPA BY QTY GIVING AVERAGE-GPA ROUNDED.


==============
With either ROUNDED or without it it's giving me an error. Is this a legal operation with different field types and sizes? Or I'm doing something wrong.
dexik
 
Posts: 28
Joined: Tue Jun 12, 2012 4:30 am
Has thanked: 0 time
Been thanked: 0 time

Re: On size error with comp-3 fields

Postby dick scherrer » Thu Jul 26, 2012 9:24 am

Hello,

Why is GPA in the code - it is not referenced. You mention comp-3 but there is none in the code.

I see no difference in the field types - they are all zoned-decimal (without a sign).

What is the chance that the posted code is Not the code that raises the error?
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: On size error with comp-3 fields

Postby dexik » Thu Jul 26, 2012 9:39 am

It is related to my previous question. I think the problem is that I am trying to output comp-3 field as an alphanumeric field (qsysprt) without converting first. So, if I have this:


01 MY-COMP3 PIC 9(3)V99 COMP-3.

01 MY-ALPHA PIC X(3).
01 MY-DOT PIC X VALUE '.'.
01 MY-DECIMAL PIC X(2).



Say, MY-COMP3 contains 123.88. How do I move MY-COMP3 to MY-ALPHA and MY-DECIMAL?
dexik
 
Posts: 28
Joined: Tue Jun 12, 2012 4:30 am
Has thanked: 0 time
Been thanked: 0 time

Re: On size error with comp-3 fields

Postby dexik » Thu Jul 26, 2012 9:48 am

Hey Dick, sorry, all GPA fields supposed to be comp-3 fields except QTY. I should pay extra attention when posting not to waste people's time.

COMPUTE TOTAL-GPA = TOTAL-GPA + GPA.

DIVIDE TOTAL-GPA BY QTY GIVING AVERAGE-GPA
ON SIZE ERROR MOVE 8 TO SIZE-ER.


I keep getting 8 in SIZE-ER and a gibberish output in AVERAGE-GPA. But if you're saying that this Divide calculation shouldn't in principle produce any errors then I'll keep looking.
dexik
 
Posts: 28
Joined: Tue Jun 12, 2012 4:30 am
Has thanked: 0 time
Been thanked: 0 time

Re: On size error with comp-3 fields

Postby Robert Sample » Thu Jul 26, 2012 4:54 pm

Look at the first line of your compiler output and tell us which compiler and version you are using. I ran your code under Enterprise COBOL 3.4:
       WORKING-STORAGE SECTION.
       01 GPA                          PIC 9(3)V99 COMP-3.
       01 TOTAL-GPA                    PIC 9(3)V99 COMP-3.
       01 AVERAGE-GPA                  PIC 9(3)V99 COMP-3.
       01 QTY                          PIC 99.
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           MOVE 14                     TO  QTY.
           MOVE 34.45                  TO  TOTAL-GPA.
           DIVIDE TOTAL-GPA BY QTY
               GIVING AVERAGE-GPA ROUNDED.
           DISPLAY 'QTY         >' QTY '<'.
           DISPLAY 'GPA         >' GPA '<'.
           DISPLAY 'TOTAL-GPA   >' TOTAL-GPA '<'.
           DISPLAY 'AVERAGE-GPA >' AVERAGE-GPA '<'.
with results of
 QTY         >14<
 GPA         >00000<
 TOTAL-GPA   >03445<
 AVERAGE-GPA >00246<
so there's something you are not telling us about what you are doing, or about the compiler you are using.
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: On size error with comp-3 fields

Postby dexik » Thu Jul 26, 2012 7:52 pm

Hey Robert, yea, as I said the problem was that I was printing it to PRINTER-QSYSPRT, I don't know if this exists in your version of Cobol but it is alphanumeric so before I can print it I have to convert comp-3 to alphanumeric. I'm still trying to figure it out. I have two questions now - Why it doesn't show the decimals and the point? And if I have a comp-3 field with decimals say 34.55 how do I convert it to alphanumeric? Thank you
dexik
 
Posts: 28
Joined: Tue Jun 12, 2012 4:30 am
Has thanked: 0 time
Been thanked: 0 time

Re: On size error with comp-3 fields

Postby Robert Sample » Thu Jul 26, 2012 8:06 pm

You need to review your COBOL syntax. The use of a V in a PICTURE clause provides an IMPLIED decimal point. COBOL will align data to the decimal point, and digits after the implied decimal point are decimals not integers -- but you will never see a decimal piont in a PICTURE clause with a V (unless, of course, someone messed up the logic and / or data). The value 03445 in my post indicates, since the PICTURE IS 9(03)V99 that the actual value is 034.45 and COBOL will treat it as such.

One point to be aware of is that COBOL considers alphanumeric values (PICTURE X) to have a decimal point immediately to the RIGHT of the last character; hence, directly moving any data with decimal digits into an alphanumeric variable causes those decimal digits to be lost. If you want your AVERAGE-GPA variable to be displayed with leading blanks and a decimal point (common requirements), add this to your WORKING-STORAGE:
01  OUTPUT-AVG    PIC ZZ9.99.
01  OUTPUT-AVG-X  REDEFINES OUTPUT-AVG
                  PIC X(06).
and add to your PROCEDURE DIVSIION statements after you compute AVERAGE-GPA:
MOVE AVERAGE-GPA TO OUTPUT-AVG.
You can then use OUTPUT-AVG-X in your print line, or wherever you need the value with a decimal point.
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: On size error with comp-3 fields

Postby dick scherrer » Thu Jul 26, 2012 8:37 pm

Hello,

Is this compiler running on an IBM mainframe?

If the value is 123.45 and you want to address the 123 and the 45 separately, move the average-gpa to the output-avg as Robert showed and then redefine this again as you did in your first post (uding 3 fields).
Hope this helps,
d.sch.
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Re: On size error with comp-3 fields

Postby dexik » Fri Jul 27, 2012 9:51 am

I used PIC ZZ9.99 and it worked like a charm, I didn't even have to move it to alphanumeric field. Thank you guys!

NB. Yea, I need to read more on Cobol syntax and practice more, but the thing is that my mother passed away 2 months ago and it's only been like 3 weeks since I'm feeling better and started finally working on my assignments properly; before that I just stopped caring because with her a part of me died too. So I'm grateful to you guys for all your help.
dexik
 
Posts: 28
Joined: Tue Jun 12, 2012 4:30 am
Has thanked: 0 time
Been thanked: 0 time

Re: On size error with comp-3 fields

Postby dick scherrer » Fri Jul 27, 2012 7:41 pm

Hello,

We are surely sorry for your loss.

When you have questions, someone will be here.

Be well,

d
User avatar
dick scherrer
Global moderator
 
Posts: 6268
Joined: Sat Jun 09, 2007 8:58 am
Has thanked: 3 times
Been thanked: 93 times

Next

Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post