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

Character valus on numeric field


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

New User


Joined: 05 Dec 2007
Posts: 57
Location: chennai

PostPosted: Wed Mar 31, 2010 5:28 pm
Reply with quote

SOURCE :

Code:
IDENTIFICATION DIVISION.                   
PROGRAM-ID. PGM1.                         
ENVIRONMENT DIVISION.                     
DATA DIVISION.                             
WORKING-STORAGE SECTION.                   
01   A  PIC S9(8).                         
PROCEDURE DIVISION.                       
         ACCEPT A.                             
         DISPLAY 'A IS:' A.                     
         STOP RUN.   


RUN JCL :

Code:

//job11###  JOB ,'SAMPLE',                                                     
//CLASS=S,MSGCLASS=1,REGION=0M,MSGLEVEL=1,NOTIFY=XXXX 
//STEP10   EXEC COBXG,                       
//              PROG=PGM1                                                           
//STEPLIB  DD  DSN=LOADLIB,                               
//             DISP=(SHR,KEEP,KEEP)                                 
//SYSPRINT DD  SYSOUT=*                                             
//SYSUDUMP DD  SYSOUT=*                                             
//SYSIN    DD   *                                                   
ASDFGH                                                             
/*                                                                 
//SYSOUT   DD  SYSOUT=*                                             
//                                         



OUTPUT :

Code:
ASDFGH


I am trying to understand how it is accepting non numeric value into numeric field... can some one help me to understand...

If try to initialize a value in source itself then getting error message

Code:
 "'ASDFGH'" AND "A (NUMERIC INTEGER)" DID NOT FOLLOW THE "MOV DISCARDED. 
Back to top
View user's profile Send private message
arivazhagan_k

New User


Joined: 05 Dec 2007
Posts: 57
Location: chennai

PostPosted: Wed Mar 31, 2010 5:30 pm
Reply with quote

Try to initialize like below

Code:
01   A  PIC 9(8) VALUE('ASDFGH').
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Wed Mar 31, 2010 5:41 pm
Reply with quote

Your variable is USAGE DISPLAY. Such variables allow anything to be stored in them. Where you would get a problem would be attempting to use the non-numeric value for arithmetic (S0C7 abend, anyone?) -- but merely displaying the value or moving it to another USAGE DISPLAY field is not prohibited by COBOL.

A lot of people new to COBOL seem to think that a numeric variable cannot hold anything but digits. This is a false belief. Variables of USAGE COMP (and all the other COMP types) can hold only numeric digits. But USAGE DISPLAY variables can hold anything a PIC X field can. COBOL prevents obvious discrepancies such as MOVE 'ASDFG' TO A, but ACCEPT and MOVE variable to A will both be allowed.
Back to top
View user's profile Send private message
arivazhagan_k

New User


Joined: 05 Dec 2007
Posts: 57
Location: chennai

PostPosted: Wed Mar 31, 2010 7:54 pm
Reply with quote

Thanks for this valuable information.

Quote:
but ACCEPT and MOVE variable to A will both be allowed.


As per your statement the following code should not through any error but it is throwing a compilation error.

source:
Code:
IDENTIFICATION DIVISION.                   
PROGRAM-ID. MANU.                           
ENVIRONMENT DIVISION.                       
DATA DIVISION.                             
WORKING-STORAGE SECTION.                   
01   A  PIC 9(8).                           
01   B  PIC A(8) VALUE 'ASDF'.             
PROCEDURE DIVISION.                         
    MOVE B TO A.         
    DISPLAY 'A IS:' A.                     
    DISPLAY 'B IS:' B.     


compilation error:
Code:
"B (ALPHABETIC)" AND "A (NUMERIC INTEGER)" DID NOT FOLLOW
STATEMENT WAS DISCARDED.   


This code is working fine.
Code:
IDENTIFICATION DIVISION.                   
PROGRAM-ID. MANU.                           
ENVIRONMENT DIVISION.                       
DATA DIVISION.                             
WORKING-STORAGE SECTION.                   
01   A  PIC 9(8).                           
01   B  PIC X(8) VALUE 'ASDF'.             
PROCEDURE DIVISION.                         
    MOVE B TO A.         
    DISPLAY 'A IS:' A.                     
    DISPLAY 'B IS:' B.   


output:
Code:
----+----1----+----2----+----3-
 A IS:ASDF   0                 
 B IS:ASDF                     
*******************************     


But how 0 is displaying at end...
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8697
Location: Dubuque, Iowa, USA

PostPosted: Wed Mar 31, 2010 8:12 pm
Reply with quote

Note in my post I said PIC X. You are using PIC A. See the difference? A means ALPHABETIC, which by its very definition cannot be moved to a numeric variable.

The zero comes about because COBOL ensures that your numeric variable is unsigned. How does it do this? By doing an OR of the last byte of the variable with X'F0', which ensures there is no sign associated with the number. Since you moved 4 bytes to an 8-byte variable, and the move was left justified, the value was actually ASDF followed by 4 spaces (or X'40'). X'40', when ORed to X'F0', becomes X'F0' -- which is a zero. Hence your display shows ASDF, three spaces, then a zero.
Back to top
View user's profile Send private message
arivazhagan_k

New User


Joined: 05 Dec 2007
Posts: 57
Location: chennai

PostPosted: Wed Mar 31, 2010 8:32 pm
Reply with quote

Good explanation. thanks.
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 Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts S0C7 - Field getting overlayed COBOL Programming 2
Search our Forums:

Back to Top