Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
Moving charecter to Numeric field showing unrelated data?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Ragav86

New User


Joined: 27 Jan 2010
Posts: 37
Location: chennai

PostPosted: Thu Apr 26, 2012 2:10 pm    Post subject: Moving charecter to Numeric field showing unrelated data?
Reply with quote

Code:

  IDENTIFICATION DIVISION.             
  PROGRAM-ID. SAMPLE.                 
  DATA DIVISION.                       
  WORKING-STORAGE SECTION.             
   01 X PIC X(3) VALUE 'A05'.         
   01 X1 PIC 9(4) BLANK WHEN ZERO.     
  PROCEDURE DIVISION.                 
       DISPLAY X                       
       DISPLAY X1                     
       MOVE X TO X1                   
       DISPLAY X1                     
       STOP RUN.                       


Output when BLANK WHEN ZERO on field X1:
Code:

A05               <== value of x
                    <== value of x1
0105             <== value of x1 after move

when we remove BLANK WHEN ZERO on field x1. we are getting the following output.

Output with out BLANK WHEN ZERO on field X1.
Code:

A05              <== value of x
                    <== value of x1       
0A05              <== value of x1 after move

can any one let us know how the numeric field accepting character value?
why output is different when we use BLANK WHEN ZERO option.?
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Thu Apr 26, 2012 2:27 pm    Post subject: Reply to: Moving charecter to Numeric field showing unrelate
Reply with quote

A "numeric" can "accept" any of the 256 bit-pattens in any of its bytes. Unless you want problems, it is up to you to ensure that a "numeric" only contains "numbers".

If you generate the pseudo-assembler (complier option LIST) then you'll see why Blank When Zero behaves differently.
Back to top
View user's profile Send private message
Ragav86

New User


Joined: 27 Jan 2010
Posts: 37
Location: chennai

PostPosted: Thu Apr 26, 2012 2:55 pm    Post subject: Reply to: Moving charecter to Numeric field showing unrelate
Reply with quote

i have attached the compiler listing. I am not familiar with assembler..
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Thu Apr 26, 2012 3:07 pm    Post subject: Reply to: Moving charecter to Numeric field showing unrelate
Reply with quote

You have the OPTimizer compile option.

Turn the OPT off and try again.
Back to top
View user's profile Send private message
Ragav86

New User


Joined: 27 Jan 2010
Posts: 37
Location: chennai

PostPosted: Thu Apr 26, 2012 3:31 pm    Post subject: Reply to: Moving charecter to Numeric field showing unrelate
Reply with quote

move statement when blank when zero.
Code:


 000010  MOVE
    000366  D205 D100 A085          MVC   256(6,13),133(10)       TS2=0                             PGMLIT AT +125
    00036C  F222 D108 8000          PACK  264(3,13),0(3,8)        TS2=8                             X
    000372  960F D10A               OI    266(13),X'0F'           TS2=10
    000376  DE05 D100 D108          ED    256(6,13),264(13)       TS2=0                             TS2=8
    00037C  4770 B16E               BC    7,366(0,11)             GN=15(00038A)
    000380  D205 D100 C004          MVC   256(6,13),4(12)         TS2=0                             SYSLIT AT +4
    000386  47F0 B16E               BC    15,366(0,11)            GN=16(00038A)
    00038A                 GN=15    EQU   *
    00038A                 GN=16    EQU   *
    00038A  D203 8008 D102          MVC   8(4,8),258(13)          X1                                TS2=2


move statement when blank when zero option not specified.
Code:


 000010  MOVE
    00035E  92F0 8008               MVI   8(8),X'F0'              X1
    000362  D202 8009 8000          MVC   9(3,8),0(8)             X1+1                              X
    000368  96F0 800B               OI    11(8),X'F0'             X1+3
Back to top
View user's profile Send private message
Ragav86

New User


Joined: 27 Jan 2010
Posts: 37
Location: chennai

PostPosted: Thu Apr 26, 2012 4:05 pm    Post subject: Reply to: Moving charecter to Numeric field showing unrelate
Reply with quote

thanks for your reply Bill, And one more example..
Code:

//STEP1    EXEC IGYWCLG,PARM.COBOL='NOOPT'                         
//COBOL.SYSIN DD *                                                 
        IDENTIFICATION DIVISION.                                   
        PROGRAM-ID. SAMPLE.                                         
        DATA DIVISION.                                             
        WORKING-STORAGE SECTION.                                   
         01 X PIC X(3) VALUE 'A05'.                                 
         01 X1  REDEFINES X.                                       
         05 X2 PIC 9(3).                                           
        PROCEDURE DIVISION.                                         
             DISPLAY X                                             
             DISPLAY X1                                             
             ADD 1 TO X2                                           
             DISPLAY X2                                             
             STOP RUN.                                             
/*                                                                 
//GO.SYSOUT   DD SYSOUT=*                                           


Output is:
Code:
A05
A05
106


ADD statement:
Code:

011  ADD                                                                       
00036A  F212 D100 8000          PACK  256(2,13),0(3,8)        TS2=0             
000370  960F D101               OI    257(13),X'0F'           TS2=1             
000374  FA10 D100 A031          AP    256(2,13),49(1,10)      TS2=0             
00037A  F321 8000 D100          UNPK  0(3,8),256(2,13)        X2               
000380  96F0 8002               OI    2(8),X'F0'              X2+2             

here how the charecter 'A' is converted to 1. I though it would be data exception.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Thu Apr 26, 2012 4:13 pm    Post subject: Reply to: Moving charecter to Numeric field showing unrelate
Reply with quote

So, the PACK is getting rid of all the "zones" from your four-byte numeric in the code generated for your BLANK WHEN ZERO field. The value of the C from "C1" (character A) has been abandoned.

Without the BLANK WHEN ZERO you have an MVC, so your "zones" are preserved. The value of the C from "C1" has been preserved.

Another example of what a bad idea it is to move a PIC X(n) field to a PIC 9(m) without first testing the PIC X(n) for NUMERIC. Mandatory, unless you are absolutely certain that it cannot contain a non-numeric (0-9).

The OPTimizer, in this short example, knows the result from the MOVE of a static value to the Blank When Zero field, so short-cuts it with a move from the literal pool with the correct output value. Much faster, but more opaque :-)

EDIT: No, it won't be a data exception. You didn't get one, did you? This has been discussed many times. Try to search this forum (S0C7 for instance) or browse it. There must have been at least a couple of examples this year.
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 Copy 4 byte of data from the last rec... arunsoods DFSORT/ICETOOL 9 Fri Oct 06, 2017 12:15 pm
No new posts sort records based on length exceeds ... maxsubrat DFSORT/ICETOOL 7 Wed Oct 04, 2017 4:48 pm
No new posts opening a dataset after reading it fr... arunsoods DFSORT/ICETOOL 5 Wed Oct 04, 2017 3:54 pm
This topic is locked: you cannot edit posts or make replies. PS file data should be passed as symb... d_sarlie JCL & VSAM 15 Tue Oct 03, 2017 5:18 am
No new posts Partial color change of a field in CI... waseem0424 CICS 5 Fri Sep 29, 2017 7:56 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us