IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Diff bw SPACE and SPACES (figurative constants)


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Tue Dec 19, 2006 5:11 pm
Reply with quote

Hi,
Could anyone explain the difference between SPACE and SPACES (figurative constants) COBOL reserved words?

Regards,
Mohan
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Tue Dec 19, 2006 5:18 pm
Reply with quote

Hi Mohan

I think SPACE is for one space & SPACES is for more spaces .
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 5:23 pm
Reply with quote

There is no difference, they both produce the same result. Grammatically speaking, the singular sounds better when used as one while the plural sounds better when used as many.
Back to top
View user's profile Send private message
jcbhimani

New User


Joined: 30 Nov 2006
Posts: 12
Location: Ahmedabad

PostPosted: Tue Dec 19, 2006 11:28 pm
Reply with quote

SPACE represents one blank while SPACES represents more then one blank. Same as ZERO represents one zero while ZEROS or ZEROES represents more then one zero.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Dec 19, 2006 11:58 pm
Reply with quote

num pic 9999
move zero to num
what is in num?

char pic xxxx
move zero to char
what is in char?
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Wed Dec 20, 2006 12:01 am
Reply with quote

As William said, There is no difference in function. SPACE, SPACES and ZERO, ZEROS. The only difference is readability.

Code:

WORKING-STORAGE SECTION.                                       
                                                               
01  CHARSTR1 PIC X(20).                                         
01  CHARSTR2 PIC X(20).                                         
01  DECIMAL1 PIC 9(10).                                         
01  DECIMAL2 PIC 9(10).                                         
                                                               
PROCEDURE DIVISION.                                             
PROGRAM-START.                                                 
                                                               
    DISPLAY 'CHARSTR1 >' CHARSTR1 '< CHARSTR2 >' CHARSTR2 '<'   
    DISPLAY 'DECIMAL1 >' DECIMAL1 '< DECIMAL2 >' DECIMAL2 '<'   
                                                               
    MOVE SPACE TO CHARSTR1.                                     
    MOVE SPACES TO CHARSTR2.                                   
    MOVE ZERO TO DECIMAL1.                                     
    MOVE ZEROS TO DECIMAL2.                                     
                                                               
    DISPLAY 'CHARSTR1 >' CHARSTR1 '< CHARSTR2 >' CHARSTR2 '<'   
    DISPLAY 'DECIMAL1 >' DECIMAL1 '< DECIMAL2 >' DECIMAL2 '<'   


result

Code:

.SARPAGE 4                                                                   
.                                                                           
.CHARSTR1 >....................< CHARSTR2 >....................<             
.DECIMAL1 >..........< DECIMAL2 >..........<                                 
.CHARSTR1 >                    < CHARSTR2 >                    <             
.DECIMAL1 >0000000000< DECIMAL2 >0000000000<                                 
******************************** BOTTOM OF DATA *****************************


As you can see, SPACE and SPACES, ZERO and ZEROS produce the same data.

Dave
Back to top
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Wed Dec 20, 2006 8:28 am
Reply with quote

Thanks all for the quick response.

In one of the program Im working upon (for small enhancement), I have group variable as follows -

01 group-var. (pic of all other level is x)
05 sub-var1 pic x(9).
05 sub-var2 pic x(3).
.
.
.
05 sub-var12 pic x(242).


And also I have statement MOVE SPACE TO GROUP-VAR in procedure division. But found spaces was not moved (i.e., found earlier data in the variable).

So, just got a doubt regarding SPACE and SPACES functioning.

Regards,
Mohan
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1208
Location: Bangalore,India

PostPosted: Wed Dec 20, 2006 9:52 am
Reply with quote

Hi Mohan,


May be after moving spaces u r passing some value in the variable Thats why it is showing some value other than spaces
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Wed Dec 20, 2006 10:53 pm
Reply with quote

Hello,

From one of the COBOL manuals. . .

Quote:

SPACE, SPACES
Represents one or more blanks or spaces. SPACE is treated as an alphanumeric literal when used in a context that requires an alphanumeric character, as a DBCS literal when used in a context that requires a DBCS character, and as a national literal when used in a context that requires a national character. The EBCDIC DBCS space character has the value X?4040?, and the national space character has the value NX?0020?.


From that, one might read that SPACE will only do one.

Put the following into a pgm:

and the following was the result:
Code:

*                                             
 01  SPACEMOVETEST.                           
     05 SMT1   PIC XXX VALUE 'ABC'.           
     05 SMT2   PIC XXX VALUE '123'.           

     DISPLAY 'ORIGINAL   ' SPACEMOVETEST.     
     MOVE SPACE TO SPACEMOVETEST.             
     DISPLAY 'AFTER MOVE ' SPACEMOVETEST.     
     DISPLAY ' '.                             



Code:

ORIGINAL      ABC123
AFTER MOVE       


When i did a preview, the PIC X(3) showed as TTT - is this an undocumented feature of the "reply editor"? Seems like tripleX is converted to TTT. XX and XXXX don't get converted. Must be the auto-censor at work. . . .
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts leading spaces can be removed in trai... DFSORT/ICETOOL 1
No new posts Cobol program with sequence number ra... COBOL Programming 5
No new posts Merge 2 lines based on Space from a S... DFSORT/ICETOOL 5
No new posts To Remove spaces (which is in hex for... JCL & VSAM 10
Search our Forums:

Back to Top