Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Conversion of NUMERIC field to PACKED DECIMAL

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
Nithya.U.M
Warnings : 1

New User


Joined: 11 Nov 2008
Posts: 21
Location: India

PostPosted: Wed Dec 10, 2008 6:24 pm    Post subject: Conversion of NUMERIC field to PACKED DECIMAL
Reply with quote

I HAVE A PACKED DECIMAL FIELD WHICH IS REDEFINED TO A NUMERIC FIELD TO ADD "1" TO ITS TENTH DIGIT. AFTER THIS IT NEED BE AGAIN CONVERTED BACK INTO PACKED DECIMAL INORDER TO INSERT THIS FIELD INTO A TABLE.

PLEASE SUGGEST A METHOD TO CONVERT A NUMERIC FIELD TO PACKED DECIMAL IN COBOL PROGRAM.

Warning: Turn Off your CAPS Lock.
Back to top
View user's profile Send private message

Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Dec 10, 2008 6:32 pm    Post subject:
Reply with quote

move
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Wed Dec 10, 2008 6:32 pm    Post subject:
Reply with quote

Code:
01  WS-SOURCE               PIC 9(05).
01  WS-TARGET               PIC S9(05) COMP-3.

...

MOVE WS-SOURCE TO WS-TARGET.


Your post is not at all clear about what you want -- packed decimal fields don't have to be redefined to be numeric, they are numeric by definition. Post the variables you're using so we can figure out what you're trying to do.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Dec 10, 2008 6:44 pm    Post subject: Re: CONVERSION OF NUMERIC FIELD TO PACKED DECIMAL
Reply with quote

Nithya.U.M wrote:
I HAVE A PACKED DECIMAL FIELD WHICH IS REDEFINED TO A NUMERIC FIELD TO ADD "1" TO ITS TENTH DIGIT.


That won't work, packed decimal is numeric. Why don't you just add 1 to the packed decimal field. Better idea please explain what you are trying to do.
Back to top
View user's profile Send private message
Nithya.U.M
Warnings : 1

New User


Joined: 11 Nov 2008
Posts: 21
Location: India

PostPosted: Wed Dec 10, 2008 6:46 pm    Post subject:
Reply with quote

ROBERT ,
IF I MOVE WS-SOURCE IN UR EXAMPLE TO TARGET YOU WILL GET A TRUNCATED VALUE IN THE COMP-3 FIELD

i HAVE A COMP-3 FIELD AS BELOW

GRID1 PIC S9(11)V COMP-3. THE VALUE IN THIS FIELD IS "92345678601" ( 10TH DIGIT IS 0)
THIS VALUE IS MOVED TO A NUMERIC FIELD SAY NUMERIC1 PIC 9(11).
THIS NUMERIC FIELD IS THEN REDEFINED TO 11 FIELDS EACH HAVING 1 DIGIT.

LIKE : WS-DIG1 PIC 9(1). I NEED TO ADD ONE TO ITS TENTH DIGIT. THATS WHY IT IS REDEFINED LIKE THIS.

SO I ADD ONE TI WS-DIG10.

NOW AS THE PACKED DECIMAL FIELD IS UNPACKED BY THE REDEFINES CLAUSE, THE SIZE IT OCCUPIES ALMOST DOUBLES.

NOW I NEED TO CONVERT THIS NUMERIC FIELD TO PACKED DECIMAL TO INSERT THIS FIELD IN THE TABLE AS THE TABLE FIELD IS DECIMAL AND WONT ALLOW ME TO INSERT NUMERIC DATA.

I FEEL I HAVE EXPLAINED MY SITUATION CLEARLY.YOU CAN EVEN SUGGEST ME IF THERE IS ANY OTHER METHOD TO ADD ONE TO THE 1OTH DIGIT OF VALUE IN A PACKED DECIMAL FIELD WITHOUT CONVERTING IT INTO NUMERIC .
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Wed Dec 10, 2008 6:58 pm    Post subject:
Reply with quote

Why would you get a truncated value? If the definition size matches there shouldn't be any truncation. This code:
Code:
 WORKING-STORAGE SECTION.
 01  WS-VARIABLES.
     05  WS-SOURCE               PIC S9(11)V COMP-3
                                 VALUE 92345678601.
     05  WS-TARGET               PIC S9(11).

 LINKAGE SECTION.
/
 PROCEDURE DIVISION.
 S1000-MAIN       SECTION.
     DISPLAY 'INITIAL: ' WS-SOURCE.
     MOVE WS-SOURCE              TO  WS-TARGET.
     DISPLAY 'TARGET:  ' WS-TARGET.
     MOVE '1'                    TO  WS-TARGET (10 : 1).
     DISPLAY 'TARGET:  ' WS-TARGET.
     MOVE WS-TARGET              TO  WS-SOURCE.
     DISPLAY 'ENDING:  ' WS-SOURCE.
produces this output:
Code:
INITIAL: 92345678601
TARGET:  9234567860A
TARGET:  9234567861A
ENDING:  92345678611
which to me appears to be exactly what you say you need.
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2171
Location: @my desk

PostPosted: Wed Dec 10, 2008 7:06 pm    Post subject:
Reply with quote

Quote:
IF THERE IS ANY OTHER METHOD TO ADD ONE TO THE 1OTH DIGIT OF VALUE IN A PACKED DECIMAL FIELD WITHOUT CONVERTING IT INTO NUMERIC
Nithya.U.M,

Dont you like using lower-case at all? It's really difficult to read what you've posted here. Given that your input field length is 11, what output would you expect for an input like this?
Code:
----+----+---
99999999999
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Wed Dec 10, 2008 7:38 pm    Post subject:
Reply with quote

Hi nithya,

Craig was on the right track. do the following:

ADD +10 TO GRID1

Try it, you'll like it. BUT, will that digit ever be something like a "9"? Will the ADD serve your purposes in that case or do you need an "insert"?
Back to top
View user's profile Send private message
Nithya.U.M
Warnings : 1

New User


Joined: 11 Nov 2008
Posts: 21
Location: India

PostPosted: Wed Dec 10, 2008 8:30 pm    Post subject:
Reply with quote

hi all thanks for your answers . but this doesnt solve my issue.:-(

Robert,
what you have explained is correct . But i need to perform an arithmetic operation vizz adding one ( not moving one) to the 10th digit of the packed decimal value. with reference modification this addition operation would not be possible . while performing the below operation i got a truncated value .

so as i had explained earlier , i moved the packed decimal field to a numeric field and redefined the numeric field each having one digit. and added one to the 1oth digit and now i have a numeric field as below

original field : ws-grid -> s9(11)v comp-3.
ws-grid-numeric ->9(11)
ws-key-grid -> s9(11) comp-3
move ws-grid to ws-grid-numeric .


01 ws-numeric redefines ws-grid-numeric .

05 num1 pic 9(1)
05 num2 ''
--------
--------
05 num10
05 num 11 ''

add 1 to num10.
move ws-numeric to ws-key-grid

when displayed ws-numeric had all perfect output but ws-key-grid had a truncated value.

i beleive i have explined it correctly.
Please suggest if you have any method to get this arithmetic operation done as well as to get correct output into the packed decimal field.

Thanks and regards,
Nithya
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2171
Location: @my desk

PostPosted: Wed Dec 10, 2008 8:35 pm    Post subject:
Reply with quote

Nithya.U.M wrote:
i beleive i have explined it correctly.
You have not answered all.

arcvns wrote:
Given that your input field length is 11, what output would you expect for an input like this?
Code:
----+----+---
99999999999

mmwife wrote:

will that digit ever be something like a "9"? Will the ADD serve your purposes in that case or do you need an "insert"?
Back to top
View user's profile Send private message
Nithya.U.M
Warnings : 1

New User


Joined: 11 Nov 2008
Posts: 21
Location: India

PostPosted: Wed Dec 10, 2008 8:37 pm    Post subject:
Reply with quote

Arcvns,
This condition will not be present in the database . No rid number will have this value.

Thanks,
Nithya
Back to top
View user's profile Send private message
Arun Raj

Moderator


Joined: 17 Oct 2006
Posts: 2171
Location: @my desk

PostPosted: Wed Dec 10, 2008 8:40 pm    Post subject:
Reply with quote

Nithya.U.M,

Still you have not mentioned what all are the possible values expected in the 10th position. Will it ever be a "9"?
Back to top
View user's profile Send private message
Nithya.U.M
Warnings : 1

New User


Joined: 11 Nov 2008
Posts: 21
Location: India

PostPosted: Wed Dec 10, 2008 8:45 pm    Post subject:
Reply with quote

Arcvns,

I have never seen a grid number in the database which has 9 in the tenth position... mostly its one or zero. or any number between 1 to 5. Above that its not present as communicated to me. but it wud be better if i handle that condition in my code .

regards,
Nithya
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Wed Dec 10, 2008 9:11 pm    Post subject:
Reply with quote

Code:
 WORKING-STORAGE SECTION.
 01  WS-VARIABLES.
     05  WS-SOURCE               PIC S9(11)V COMP-3
                                 VALUE 92345678601.
     05  WS-TARGET               PIC S9(11).
     05  WS-TARGET-R             REDEFINES WS-TARGET
                                           OCCURS 11
                                           PIC 9(01).

 LINKAGE SECTION.
/
 PROCEDURE DIVISION.
 S1000-MAIN       SECTION.
     DISPLAY 'INITIAL: ' WS-SOURCE.
     MOVE WS-SOURCE              TO  WS-TARGET.
     DISPLAY 'TARGET:  ' WS-TARGET.
     ADD 1                                 TO  WS-TARGET-R (10).
     DISPLAY 'TARGET:  ' WS-TARGET.
     MOVE WS-TARGET              TO  WS-SOURCE.
     DISPLAY 'ENDING:  ' WS-SOURCE.
which is a slight modification to my previously posted code, has been tested and correctly adds 1 to the 10th digit -- same output as previously posted.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 7914
Location: Bellevue, IA

PostPosted: Wed Dec 10, 2008 9:13 pm    Post subject:
Reply with quote

Handling the case of the 10th digit being 9 is a trivial IF statement. As provided this code handles the case by wrapping to zero.
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Dec 10, 2008 10:15 pm    Post subject:
Reply with quote

Why don't you just add 10 to the comp-3 field, why make it more difficult.
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1219
Location: Israel

PostPosted: Wed Dec 10, 2008 10:25 pm    Post subject:
Reply with quote

Nithya.U.M wrote:
so as i had explained earlier , i moved the packed decimal field to a numeric field and redefined the numeric field each having one digit. and added one to the 1oth digit and now i have a numeric field as below

original field : ws-grid -> s9(11)v comp-3.
ws-grid-numeric ->9(11)
ws-key-grid -> s9(11) comp-3
move ws-grid to ws-grid-numeric .


01 ws-numeric redefines ws-grid-numeric .

05 num1 pic 9(1)
05 num2 ''
--------
--------
05 num10
05 num 11 ''

add 1 to num10.
move ws-numeric to ws-key-grid

when displayed ws-numeric had all perfect output but ws-key-grid had a truncated value.

i beleive i have explined it correctly.

Yes, your explanation is very clear. But there is one error in your code, I'm surprised nobody corrected it yet:
the phrase move ws-numeric to ws-key-grid
should have been: move ws-grid-numeric to ws-key-grid
Back to top
View user's profile Send private message
mmwife

Super Moderator


Joined: 30 May 2003
Posts: 1592

PostPosted: Thu Dec 11, 2008 2:16 am    Post subject:
Reply with quote

Well, Crag beat me to it. But anyway.

In my prev post I said:
Quote:
ADD +1 TO GRID1


I meant:
Quote:
ADD +10 TO GRID1

This will work except for the condition that arcvns mentioned: 99999999999

PS. I corrected the previous post.
Back to top
View user's profile Send private message
Nithya.U.M
Warnings : 1

New User


Joined: 11 Nov 2008
Posts: 21
Location: India

PostPosted: Thu Dec 11, 2008 11:44 am    Post subject:
Reply with quote

Thanks everyone for the replies.....now i know more than one method that wud work.

special thanks to Marso coz he just found out the problem with my existing code due to which i was getting truncated value while inserting it into the table causing db2 error.

Regards,
Nithya
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 Performing arithmetic on input field zh_lad DFSORT/ICETOOL 24 Tue Dec 06, 2016 8:04 pm
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts Conversion of a VB file to FB. isssal DFSORT/ICETOOL 1 Mon Oct 31, 2016 10:23 pm
No new posts How to split the records using the am... vnktrrd DFSORT/ICETOOL 24 Fri Oct 28, 2016 7:33 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us