Page 1 of 1

Population of spaces in numeric field

PostPosted: Thu May 12, 2016 2:17 pm
by arya_starc
I need to populate spaces in the numeric field in the cobol program?
What are the possible way to done that?

Re: Population of spaces in numeric field

PostPosted: Thu May 12, 2016 3:44 pm
by Aki88
Hello,

You do understand that your query is absurd if taken verbatim; because it goes against the rules of basic COBOL variable assignment.

If you REALLY DO have a requirement of initializing a field, which is inherently NUMERIC, with SPACEs - then the best bet you have is - modify the attribute of the numeric field to alphanumeric; because with NUMERIC, afa I know spaces dont work; or unless you are able to work something out with REDEFinitions. But I'd leave it to you to read the manual and UNDERSTAND the basic variable definition attributes.

Re: Population of spaces in numeric field

PostPosted: Thu May 12, 2016 4:18 pm
by Robert Sample
A "numeric" variable in COBOL may be USAGE DISPLAY or COMP or COMP-1 through COMP-5 and depending upon the USAGE, what you want to do may work in a way you don't expect or it may generate a compiler error.

Re: Population of spaces in numeric field

PostPosted: Thu May 12, 2016 7:37 pm
by Terry Heinze
As previously stated, this is generally not a good idea.
One way to accomplish what you want is:
01  WS-GROUP-NAME.
    05  WS-NUMERIC-DEFINITION  PIC  9.
...
MOVE SPACE TO WS-GROUP-NAME

But again -- not a good idea.

Re: Population of spaces in numeric field

PostPosted: Fri May 13, 2016 11:33 am
by pranav283
Yep, what Terry suggested does that trick.
And if you really want to cross-check your 'MOVE' result, you can validate if WS-NUMERIC-DEFINITION = SPACES or not.

Re: Population of spaces in numeric field

PostPosted: Fri May 13, 2016 1:54 pm
by Aki88
I hope that we do understand that we are not actually moving spaces to a 'numeric field', as requested, but to an 'alphanumeric group variable'; and then referring that field using a 'variable name' which has numeric attributes; which is different from the query: populate spaces in the numeric field in the cobol program

Or maybe I've missed the fine-print somewhere.

Re: Population of spaces in numeric field

PostPosted: Fri May 13, 2016 3:32 pm
by NicC
No Aki88 - you have read the fine print just fine. The others have taken the view that, being a beginner, the TS did not know how to frame the question properly. Hopefully, from now on TS will be able to think a little bit more about the phrasing of their questions.

Re: Population of spaces in numeric field

PostPosted: Sun May 15, 2016 3:58 am
by BillyBoyo
pranav283,

Not necessarily. Depends on your compile options.