Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Character valus on numeric field

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: Character valus on numeric field
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    Post subject:
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: 7993
Location: Bellevue, IA

PostPosted: Wed Mar 31, 2010 5:41 pm    Post subject:
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    Post subject:
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: 7993
Location: Bellevue, IA

PostPosted: Wed Mar 31, 2010 8:12 pm    Post subject:
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    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts SORT VSAM file with each field one by... maxsubrat DFSORT/ICETOOL 6 Tue Mar 14, 2017 1:07 pm
No new posts IMS DB-How to update a record (a sing... Nic Clouston IMS DB/DC 9 Thu Mar 09, 2017 4:38 pm
No new posts outrec field outside range Danielle.Filteau SYNCSORT 10 Sat Mar 04, 2017 2:37 am
No new posts the use of 'B3'x character in a panel Pedro TSO/ISPF 1 Thu Feb 16, 2017 3:09 am
No new posts 2 byte YEAR from Y'DATE2' field tecnokrat DFSORT/ICETOOL 2 Tue Feb 07, 2017 12:05 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us