IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

Convert alpha numeric to signed digits


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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: 8569
Location: Dubuque, Iowa, USA

PostPosted: Tue Feb 26, 2019 1:33 am
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
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: 2448
Location: Hampshire, UK

PostPosted: Tue Feb 26, 2019 2:34 pm
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts how to get total count from numeric d... SYNCSORT 9
No new posts COnvert a column with mix of hex ,cha... DB2 5
No new posts XML-GENERATE to render edited numeric COBOL Programming 0
No new posts To convert numeric to Packed Decimal DFSORT/ICETOOL 9
No new posts how to convert Hex String t char hex PL/I & Assembler 6
Search our Forums:

Back to Top