View previous topic :: View next topic
|
Author |
Message |
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Hi,
Could anyone explain the difference between SPACE and SPACES (figurative constants) COBOL reserved words?
Regards,
Mohan |
|
Back to top |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
Hi Mohan
I think SPACE is for one space & SPACES is for more spaces . |
|
Back to top |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
jcbhimani
New User
Joined: 30 Nov 2006 Posts: 12 Location: Ahmedabad
|
|
|
|
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 |
|
|
William Thompson
Global Moderator
Joined: 18 Nov 2006 Posts: 3156 Location: Tucson AZ
|
|
|
|
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 |
|
|
DavidatK
Active Member
Joined: 22 Nov 2005 Posts: 700 Location: Troy, Michigan USA
|
|
|
|
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 |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
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 |
|
|
guptae
Moderator
Joined: 14 Oct 2005 Posts: 1208 Location: Bangalore,India
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
|