MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Moving the NUMERIC part from a packed decimal field

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming
View previous topic :: View next topic  
Author Message
Dip
Beginner


Joined: 24 Mar 2006
Posts: 27
Topics: 14

PostPosted: Tue Aug 28, 2007 1:01 pm    Post subject: Moving the NUMERIC part from a packed decimal field Reply with quote

I am extracting a DECIMAL (22,7) field in a file using DB2 utility and trying to move the NUMERIC PART in a variable.

Example:
0000024680000
000013579000C

1st byte- NULL IND
12 bytes for S9(15)V9(7)

How can i move only the NUMERIC part in a 9(15) variable without using COBOL EXTEND?

I am trying like this:

COPYBOOK to read the file:

FILLER PIC X(1)
VAR1 PIC 9(15) COMP-3
FILLER PIC X(4)

WORKING STOREAGE:

WS-VAR2 PIC 9(15).

IF VAR1 NUMERIC

MOVE VAR1 to VAR2
ELSE
MOVE ZEROS TO VAR2
END-IF.

Seems like my format of defining the field is wrong and Its not working. Is that because of sign byte in the last nibble? Can someone help me to resolve this?

Thanks!
Dip.
Back to top
View user's profile Send private message Yahoo Messenger
CICS Guy
Intermediate


Joined: 30 Apr 2007
Posts: 292
Topics: 3

PostPosted: Tue Aug 28, 2007 1:58 pm    Post subject: Reply with quote

Code:

03 DB2-FIELD.
 05 FILLER PIC X(1).
 05 VAR1 PIC 9(17) COMP-3.
 05 FILLER REDEFINES VARG.
  10 FILLER PIC X(8).
  10 VARS PIC X(1).
 05 FILLER PIC X(3).

FILL DB2-FIELD.
MOVE X'0F' TO VARS.
COMPUTE WS-VAR2 = VAR1 / 10.
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Tue Aug 28, 2007 2:07 pm    Post subject: Reply with quote

Dip,

hmm is this a trick question? why can't you simply fetch into s9(15) comp-3?

Code:

01 WS-AMT             PIC S9(15) USAGE COMP-3.
01 WS-NULL-IND        PIC S9(4) COMP VALUE +0.


EXEC SQL                           
     SELECT AMT                     
     INTO :WS-AMT:WS-NULL-IND
     FROM table               
END-EXEC                           

EVALUATE SQLCODE                                 
    WHEN +0                                     
         IF WS-NULL-IND >= 0                     
            DISPLAY 'THE AMT IS :  ' WS-AMT
         ELSE                                   
            Move 0 TO WS-AMT
         END-IF                                 
    WHEN OTHER                                   
         PERFORM ABEND
END-EVALUATE     


Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
s_shivaraj
Beginner


Joined: 21 Sep 2004
Posts: 140
Topics: 14
Location: Chennai, India

PostPosted: Tue Aug 28, 2007 5:20 pm    Post subject: Reply with quote

How about this one..

Code:
 
    01    COMP-VAR2             PIC S9(09)V9(7) COMP-3 VALUE 23.34.   
    01    COMP-VAR3             PIC S9(09)V9(7)        VALUE ZERO.   
    01    COMP-VAR4 REDEFINES                                       
            COMP-VAR3           PIC X(16).                           
    01    COMP-VAR5             PIC X(09).                           
                                                                   
 *                                                                 
    PROCEDURE DIVISION.                                           
                                     
          MOVE COMP-VAR2 TO COMP-VAR3.                             
          MOVE COMP-VAR4(1:9) TO COMP-VAR5.       
                                         
          DISPLAY 'COM- VAR2' COMP-VAR2.                           
          DISPLAY 'COM- VAR3' COMP-VAR3.                           
          DISPLAY 'COM- VAR4' COMP-VAR4.                           
          DISPLAY 'COM- VAR5' COMP-VAR5.                           
        GOBACK.

_________________
Cheers
Sivaraj S

'Technical Skill is the Master of complexity, while Creativity is the Master of Simplicity'
Back to top
View user's profile Send private message AIM Address
Dip
Beginner


Joined: 24 Mar 2006
Posts: 27
Topics: 14

PostPosted: Fri Aug 31, 2007 10:38 am    Post subject: Reply with quote

Kolsu,

I am using DB2 utility to extract the data from the table.

CICS Guy,

Can you revisit ur post when get some time. Is this meeting the the requirement posted by me?

This is the way i coded:

Code:


01  IN-FIELD.                                                           
    05  IN-F5    PIC X(03).                                   
    05  IN-F-REM PIC S9(10)V9(07) COMP-3.                     
01  VAR1     PIC S9(11) COMP-3.                           
01  OUT-COMP17             S9(17) COMP-3.                               
01  FILLER REDEFINES OUT-COMP17.                                         
    05  OUT-F5   PIC X(03).                                   
    05  OUT-COMP11         PIC S9(11) COMP-3.                           
01  DECIMAL17              PIC S9(17).                                   

MOVE IN-F-REM TO VAR1                       
MULTIPLY VAR1 BY 10                                   
                    GIVING OUT-COMP17                                           
MOVE IN-F5 TO OUT-F5                             
               DIVIDE OUT-COMP17 BY 10                                             
                  GIVING DECIMAL17                                             



Thanks!
Dip.
Back to top
View user's profile Send private message Yahoo Messenger
jsharon1248
Intermediate


Joined: 08 Aug 2007
Posts: 291
Topics: 2
Location: Chicago

PostPosted: Fri Aug 31, 2007 10:59 am    Post subject: Reply with quote

Quick question. Why are you trying to avoid the ARITH(EXTEND) compile option?
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Fri Aug 31, 2007 11:31 am    Post subject: Reply with quote

Quote:

Kolsu,

I am using DB2 utility to extract the data from the table.


Dip,

If you are using the DB2 unload utility isn't the null character at the end instead of at the beginning? Look at the syspunch to get the exact the pos of the null ind.

A DB2 definition of DECIMAL(22,0) is equivalent to COBOL definition of PIC S9(15)V9(7) USAGE COMP-3. which occupies 12 bytes. Now if you read this into a 9 Byte packed field you will not have the sign and your program will abend if you refer field in any arthimetic operation.

Insert the following value into the table and run it thru the program

Code:

123456789012345.1234567


That value in hex will be

Code:

----+----1--
024680241357
13579135246C


Your Intention is to get the value of
Code:

123456789012345


leaving out the decimals. The easiest way is to unload the value using CHAR db2 function and unload it in character format.
Code:

SELECT CHAR(DB2-DECIMAL-COL) from table


Now you have the output from this as

Code:

-123456789012345.1234567
 123456789012345.1234567


Now it is easy to get the integer portion of the data.

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12376
Topics: 75
Location: San Jose

PostPosted: Fri Aug 31, 2007 11:33 am    Post subject: Reply with quote

jsharon1248 wrote:
Quick question. Why are you trying to avoid the ARITH(EXTEND) compile option?


jsharon1248,

I think OP has an older version of COBOL which does NOT support the ARITH(EXTEND) compiler option.

kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Application Programming All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group