Population of spaces in numeric field



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

Population of spaces in numeric field

Postby arya_starc » Thu May 12, 2016 2:17 pm

I need to populate spaces in the numeric field in the cobol program?
What are the possible way to done that?
arya_starc
 
Posts: 136
Joined: Mon Sep 21, 2015 1:39 pm
Has thanked: 5 times
Been thanked: 0 time

Re: Population of spaces in numeric field

Postby Aki88 » Thu May 12, 2016 3:44 pm

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.
Aki88
 
Posts: 381
Joined: Tue Jan 28, 2014 1:52 pm
Has thanked: 33 times
Been thanked: 36 times

Re: Population of spaces in numeric field

Postby Robert Sample » Thu May 12, 2016 4:18 pm

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.
Robert Sample
Global moderator
 
Posts: 3719
Joined: Sat Dec 19, 2009 8:32 pm
Location: Dubuque, Iowa, USA
Has thanked: 1 time
Been thanked: 279 times

Re: Population of spaces in numeric field

Postby Terry Heinze » Thu May 12, 2016 7:37 pm

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.
.... Terry
Terry Heinze
 
Posts: 239
Joined: Wed Dec 04, 2013 11:08 pm
Location: Richfield, MN, USA
Has thanked: 12 times
Been thanked: 11 times

Re: Population of spaces in numeric field

Postby pranav283 » Fri May 13, 2016 11:33 am

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.
pranav283
 
Posts: 47
Joined: Sat Aug 30, 2014 3:52 pm
Has thanked: 2 times
Been thanked: 0 time

Re: Population of spaces in numeric field

Postby Aki88 » Fri May 13, 2016 1:54 pm

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.
Aki88
 
Posts: 381
Joined: Tue Jan 28, 2014 1:52 pm
Has thanked: 33 times
Been thanked: 36 times

Re: Population of spaces in numeric field

Postby NicC » Fri May 13, 2016 3:32 pm

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.
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: Population of spaces in numeric field

Postby BillyBoyo » Sun May 15, 2016 3:58 am

pranav283,

Not necessarily. Depends on your compile options.
BillyBoyo
Global moderator
 
Posts: 3804
Joined: Tue Jan 25, 2011 12:02 am
Has thanked: 22 times
Been thanked: 265 times


Return to IBM Cobol

 


  • Related topics
    Replies
    Views
    Last post