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
 
Convert alpha numeric to signed digits

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

New User


Joined: 01 Aug 2016
Posts: 14
Location: India

PostPosted: Mon Feb 25, 2019 10:39 pm    Post subject: Convert alpha numeric to signed digits
Reply with quote

INPUT WILL BE '-1234567891' WITH PIC X(11).

EXPECTED OUTPUT IS WITH PIC S9(8)V9(2) AS '-12345678.91'


SIMILARLY WHEN INPUT IS '01234567891' WITH PIC X(11). EXPECTED OUTPUT IS WITH PIC S9(8)V9(2) AS '12345678.91'


I tried below code,

Code:
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
DATA DIVISION.
WORKING-STORAGE SECTION.
        01   AMOUNT-R-X.
            05   AMOUNT-R  PIC 9(11).                   
     01   AMOUNT-R-AM    PIC S9(8)V9(2).
     
PROCEDURE DIVISION.
MOVE '-1234567890' to AMOUNT-R
DISPLAY 'AMOUNT-R :' AMOUNT-R

MOVE AMOUNT-R-X TO AMOUNT-R-AM
DISPLAY 'AMOUNT-R-AM :' AMOUNT-R-AM

STOP RUN.


and got the output

AMOUNT-R :-1234567890
AMOUNT-R-AM :+-1234567.89

still i think i am missing somewhere..
Back to top
View user's profile Send private message

Robert Sample

Global Moderator


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

PostPosted: Tue Feb 26, 2019 1:33 am    Post subject: Reply to: Convert alpha numeric to signed digits
Reply with quote

You CANNOT achieve what you want the way you stated it. The V in a COBOL PICTURE clause is an implied decimal point -- it does not exist at all, ever. Depending upon exactly what you want, you could use a numeric edited PICTURE clause such as PIC 9(08).9(02) or you could separate the integer and decimal parts of the source value and move them separately.

And you made no provision for the sign in your PICTURE -- so I think you will probably be surprised at the results you get, whichever route you go.
Back to top
View user's profile Send private message
Balu5491

New User


Joined: 01 Aug 2016
Posts: 14
Location: India

PostPosted: Tue Feb 26, 2019 1:56 pm    Post subject:
Reply with quote

Hi Robert,

Thanks,

I tried the first option PIC 9(08).9(02) but still i could not achieve what i wanted.


INPUT '-1234567891' WITH PIC X(11).

EXPECTED OUTPUT IS WITH PIC S9(8)V9(2) AS '-12345678.91'
Back to top
View user's profile Send private message
Nic Clouston

Global Moderator


Joined: 10 May 2007
Posts: 2176
Location: Hampshire, UK

PostPosted: Tue Feb 26, 2019 2:34 pm    Post subject: Reply to: Convert alpha numeric to signed digits
Reply with quote

Why do you expect to see a decimal point when there isn't one? The 'V' is an implied i.e. imaginary decimal point position - not a real one. Your input is integer, until you divide it (by 100) you will not get a decimal.
Back to top
View user's profile Send private message
Balu5491

New User


Joined: 01 Aug 2016
Posts: 14
Location: India

PostPosted: Tue Feb 26, 2019 8:46 pm    Post subject:
Reply with quote

Hi Nic, Robert,

Thanks...

I need to display it in sysout for observation purpose, so visually we need decimal point.

I have done the code as below and that satisfies my request:

Quote:
IDENTIFICATION DIVISION.
PROGRAM-ID. HELLO-WORLD.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 AMOUNT-R PIC X(11).
01 AMOUNT-R9 PIC 9(10).
01 FINALVAL PIC S9(11)V9(2).
01 SIGNCHECK PIC X(1).

PROCEDURE DIVISION.

MOVE '-1234567891' to AMOUNT-R
DISPLAY 'INPUT VALUE :' AMOUNT-R

MOVE AMOUNT-R(1:1) TO SIGNCHECK

MOVE AMOUNT-R TO AMOUNT-R9

IF SIGNCHECK = '-'
COMPUTE FINALVAL= -1 * (AMOUNT-R9 / 100);
DISPLAY 'TOTAL AMOUNT :' FINALVAL
ELSE
COMPUTE FINALVAL= AMOUNT-R9/100;
DISPLAY 'TOTAL AMOUNT :' FINALVAL
END-IF

STOP RUN.
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 Line numbers contains last 6 digits o... selvagukan TSO/ISPF 4 Mon Apr 22, 2019 8:32 pm
No new posts Comparison of numeric edited variables Nileshkul COBOL Programming 4 Sat Mar 16, 2019 1:18 am
No new posts Display Signed ZD field socker_dad DFSORT/ICETOOL 11 Thu Feb 28, 2019 1:17 am
No new posts How to convert hex to Displayable for... Log Thangavel DFSORT/ICETOOL 11 Fri Feb 22, 2019 9:33 am
No new posts Convert CICS Modules to AMODE ANY CICSWOLF PL/I & Assembler 6 Fri Feb 08, 2019 7:10 pm

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