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

Conversion of NUMERIC field to PACKED DECIMAL


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
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
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
Reply with quote

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

Global Moderator


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

PostPosted: Wed Dec 10, 2008 6:32 pm
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
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Wed Dec 10, 2008 6:58 pm
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: 2481
Location: @my desk

PostPosted: Wed Dec 10, 2008 7:06 pm
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
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
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: 2481
Location: @my desk

PostPosted: Wed Dec 10, 2008 8:35 pm
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
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: 2481
Location: @my desk

PostPosted: Wed Dec 10, 2008 8:40 pm
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
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Wed Dec 10, 2008 9:11 pm
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: 8697
Location: Dubuque, Iowa, USA

PostPosted: Wed Dec 10, 2008 9:13 pm
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
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: 1353
Location: Israel

PostPosted: Wed Dec 10, 2008 10:25 pm
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
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
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 View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Issues Converting From ZD to Signed N... DFSORT/ICETOOL 4
No new posts Extracting Variable decimal numbers f... DFSORT/ICETOOL 17
No new posts Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
Search our Forums:

Back to Top