Page 1 of 1

size error

PostPosted: Fri Feb 07, 2014 1:18 am
by kartheeswaran
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?

Re: size error

PostPosted: Fri Feb 07, 2014 3:58 am
by BillyBoyo
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?

Re: size error

PostPosted: Fri Feb 07, 2014 5:04 am
by Robert Sample
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.

Re: size error

PostPosted: Fri Feb 07, 2014 2:49 pm
by kartheeswaran
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

Re: size error

PostPosted: Fri Feb 07, 2014 2:59 pm
by NicC
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.

Re: size error

PostPosted: Fri Feb 07, 2014 4:11 pm
by BillyBoyo
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.

Re: size error

PostPosted: Fri Feb 07, 2014 6:23 pm
by Robert Sample
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).

Re: size error

PostPosted: Mon Feb 10, 2014 11:00 pm
by dick scherrer
Hello,

Please post the instructions (specs) you were given to do this. How was the task described to you.