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
 
how to get only the decimal part from a variable

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

New User


Joined: 08 Sep 2006
Posts: 7
Location: Bangalore

PostPosted: Thu Sep 14, 2006 11:44 am    Post subject: how to get only the decimal part from a variable
Reply with quote

hi friends,

how to get only the decimal part from a variable

if i have
77 var1 pic 9(4)v99 value 123422.

from this variable i need to extract only decimal part i.e. 22.
can anybody suggest me.
eagerly waiting,
vivek
Back to top
View user's profile Send private message

guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Thu Sep 14, 2006 12:07 pm    Post subject:
Reply with quote

Hi vivek,

Do u want it thru COBOL program or by using Sort utility
Back to top
View user's profile Send private message
bijjaragi
Warnings : 2

New User


Joined: 08 Sep 2006
Posts: 7
Location: Bangalore

PostPosted: Thu Sep 14, 2006 12:43 pm    Post subject: Re: how to get only the decimal part from a variable
Reply with quote

hi guptae,
I am asking in cobol only.
thanks in advance.
Back to top
View user's profile Send private message
guptae

Moderator


Joined: 14 Oct 2005
Posts: 1187
Location: Bangalore,India

PostPosted: Thu Sep 14, 2006 12:53 pm    Post subject:
Reply with quote

Hi Bijjarangi,

Code:
 10 VAR2.
     15 VAR2-A                PIC 9(4).
     15 VAR2-B                PIC 9(2).


MOVR VAR1 TO VAR2.
DISPLAY 'DECIMAL:' VAR2-B

Hope it will helpful
Back to top
View user's profile Send private message
kgumraj

Active User


Joined: 01 May 2006
Posts: 151
Location: Hyderabad

PostPosted: Thu Sep 14, 2006 8:44 pm    Post subject: Re: how to get only the decimal part from a variable
Reply with quote

To get only decimal's you can you

MOVE VAR1(5:2) TO VAR2.
Back to top
View user's profile Send private message
DavidatK

Active Member


Joined: 22 Nov 2005
Posts: 700
Location: Troy, Michigan USA

PostPosted: Fri Sep 15, 2006 4:40 am    Post subject: Re: how to get only the decimal part from a variable
Reply with quote

Vivek,

Here?s a few more ways that you will find a little more flexible.

Code:

WORKING-STORAGE SECTION.                         
                                                 
77 VAR1       PIC 9(4)V99 VALUE 1234.22.         
77 VAR2       PIC 9(4)    VALUE 0.               
77 VAR3       PIC V9(2)   VALUE 0.               
                                                 
LINKAGE SECTION.                                 
                                                 
PROCEDURE DIVISION.                               
                                                 
PROGRAM-START. 

            DISPLAY ' '.                                       
            DISPLAY 'MOVE'.                                   
            DISPLAY 'BEFORE ' VAR1 ' ' VAR2 ' ' VAR3.   
       
    MOVE VAR1          TO VAR2.                       
    COMPUTE VAR3 = VAR1 - VAR2.                       

            DISPLAY 'AFTER  ' VAR1 ' ' VAR2 ' ' VAR3.         
                                                       
            MOVE 0    TO VAR2 VAR3.                           
                                                       
            DISPLAY ' '.                                       
            DISPLAY 'FUNCTION INTEGER-PART'.                   
            DISPLAY 'BEFORE ' VAR1 ' ' VAR2 ' ' VAR3.         

    COMPUTE VAR3 = VAR1 - FUNCTION INTEGER-PART(VAR1).

            DISPLAY 'AFTER  ' VAR1 ' ' VAR2 ' ' VAR3.         
                                                       
                                                 
            MOVE 0    TO VAR2 VAR3.                       
                                                 
            DISPLAY ' '.                                 
            DISPLAY 'DIVIDE'.                             
            DISPLAY 'BEFORE ' VAR1 ' ' VAR2 ' ' VAR3.     

    DIVIDE VAR1 BY 1 GIVING VAR2 REMAINDER VAR3. 

            DISPLAY 'AFTER  ' VAR1 ' ' VAR2 ' ' VAR3.     
                                                 
    GOBACK.                                       


Display results:

Code:

.SARPAGE 4                   
.                             
.                             
.MOVE                         
.BEFORE 123422 0000 00       
.AFTER  123422 1234 22       
.                             
.FUNCTION INTEGER-PART       
.BEFORE 123422 0000 00       
.AFTER  123422 0000 22       
.                             
.DIVIDE                       
.BEFORE 123422 0000 00       
.AFTER  123422 1234 22       
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 Moving values to a variable of copybo... Vignesh Sid COBOL Programming 6 Wed Sep 06, 2017 1:04 pm
No new posts Updating the Trailer count in variabl... satheshbabur DFSORT/ICETOOL 6 Wed Aug 30, 2017 9:49 pm
No new posts Repeat part of record multiple times Learncoholic DFSORT/ICETOOL 4 Tue Aug 29, 2017 11:33 am
No new posts Move from Comp3 variable to Edited Va... sreekusr COBOL Programming 8 Thu Aug 10, 2017 4:20 pm
No new posts Can I traverse a STEM variable? chong.zhou CLIST & REXX 5 Wed May 31, 2017 3:54 pm

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