size error



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

size error

Postby kartheeswaran » Fri Feb 07, 2014 1:18 am

working-storage section.
01 ws-num pic 9(5).
procedure division.
accept ws-num


some time we will give 7 char that time it take 5 char only, so that we can use on size error?
how to use?
kartheeswaran
 
Posts: 10
Joined: Fri Dec 27, 2013 12:34 am
Has thanked: 0 time
Been thanked: 0 time

Re: size error

Postby BillyBoyo » Fri Feb 07, 2014 3:58 am

No, you can't use ON SIZE ERROR, which is only for the results of COMPUTE/ADD/SUBTRACT/MULTIPLY/DIVIDE.

You'll have to define a field large enough to hold the largest possible value, and then write some code to deal with it.

What are you using ACCEPT for anyway? Where and how is your program running? TSO?
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: size error

Postby Robert Sample » Fri Feb 07, 2014 5:04 am

Unless you are a beginning COBOL student who has not yet learned about file I/O, there are no circumstances in which ACCEPT would be used for inputting data into a program -- period.
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: size error

Postby kartheeswaran » Fri Feb 07, 2014 2:49 pm

working-storage section.
01 ws-num pic 9(5).
procedure division.
accept ws-num

//sysin dd *
999978

ws-num take 99978 I WANT DISPLAY ACCEPT VALUE EXCEEDS
kartheeswaran
 
Posts: 10
Joined: Fri Dec 27, 2013 12:34 am
Has thanked: 0 time
Been thanked: 0 time

Re: size error

Postby NicC » Fri Feb 07, 2014 2:59 pm

ws-num take 99978 I WANT DISPLAY ACCEPT VALUE EXCEEDS

Apart from the fact that this makes no sense you will have to do what Billy says. SYSIN DD * is usually 80 bytes so accpet into an 80 byte field and use REDEFINES to define a structure 'over' that input field that gives you what you want.
The problem I have is that people can explain things quickly but I can only comprehend slowly.
Regards
Nic
NicC
Global moderator
 
Posts: 3025
Joined: Sun Jul 04, 2010 12:13 am
Location: Pushing up the daisies (almost)
Has thanked: 4 times
Been thanked: 136 times

Re: size error

Postby BillyBoyo » Fri Feb 07, 2014 4:11 pm

Except for some "Mickey Mouse" program, please don't use ACCEPT.

If you are using //SYSIN DD *, why not instead have your own DD Name, and just do the normal OPEN, READ, CLOSE. Means you can do things like check the FILE STATUS, know when your data has ended,

COBOL is not like languages you may be familiar with: you have to write code with COBOL, not just look for something that does it for you.

01  input-area.
    05  input-number pic 9(5).
    05  input-rest pic x(67).
          88 input-rest-is-ok value space.


IF NOT ( ( input-number NUMERIC )
        AND ( input-rest-is-OK ) )
    it's bad
END-IF


In this case you don't have to code much.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times

Re: size error

Postby Robert Sample » Fri Feb 07, 2014 6:23 pm

One possible solution would be to define your variable as 10 bytes (or however long your numbers can get) alphanumeric (PIC X) and then use the intrinsic function NUMVAL to convert the PIC X value into a numeric variable. Or you could use reference modification against the alphanumeric variable to copy the numeric digits to a numeric variable.

However, there is not really any way to check for overflow with the way you are doing input (ACCEPT).
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: size error

Postby dick scherrer » Mon Feb 10, 2014 11:00 pm

Hello,

Please post the instructions (specs) you were given to do this. How was the task described to you.
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


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post