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

Conversion of comp-3 to character


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
rarvins

New User


Joined: 24 Jan 2007
Posts: 59
Location: Texas

PostPosted: Thu Feb 08, 2007 11:51 pm
Reply with quote

I have to move a decimal ( comp -3 ) to a character(A) field and write it into a output file...But the value is not retained properly...For example if i move 22.90 to the character or alphanumeric variable , the direct move doesnt work properly...can somebody suggest a soln such that im able to get 22.90 in the character output file properly
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Thu Feb 08, 2007 11:58 pm
Reply with quote

What is the pic of the input and output fields?

05 a-field pic s9(5)v99 value 22.90.
05 out-field pic x(10) value space.
move a-field to out-field.
doesn't work?
try:
05 temp-field pic -9(5).99.
move a-field to temp-field.
move temp-field to out-field.
is better?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Feb 09, 2007 1:07 am
Reply with quote

Hello,

It would be helpful if you post what you ARE getting rather than just saying that the move doesn't work properly. It would also help if you post what kind of output you'd like beyond just saying 22.90.

Do you want leading zeros? If the value was 2222.90 would you want a comma (2,222.90) inserted?. How do you want negatives to appear?

The more info you provide, the more we can help.
Back to top
View user's profile Send private message
rarvins

New User


Joined: 24 Jan 2007
Posts: 59
Location: Texas

PostPosted: Fri Feb 09, 2007 10:12 pm
Reply with quote

hi, sorry for not providing enuf input.

What I am facing rite now.
If I have 22.90 ( S9(3)V9(2) ) in the input file, I am moving it to a character fields ( A size 8) the value 22.90 comes as some 480 and sumthing.

What I need:
I wud need to supress the leading zeros.No trailing supression is required.
I need the same input value in the output character field.

so I just want 22.90
Even if it is 2222.90 I want it as 2222.90
No more formatting is required.
In case theres is -22.90 I would need the negative sign also
So I need -22.90 in the output

Hope I havent missed out anything this time.
icon_smile.gif
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Feb 09, 2007 11:00 pm
Reply with quote

rarvins wrote:
What I am facing rite now.
If I have 22.90 ( S9(3)V9(2) ) in the input file, I am moving it to a character fields ( A size 8) the value 22.90 comes as some 480 and sumthing.
First, what exactally if the description of the field in the input file, what is its PICture and usage (comp/comp-3)?
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Feb 09, 2007 11:05 pm
Reply with quote

Hi Rarvins,

To get what you want, please try:

Code:

    05 a-field            pic s9(5)v99 value 22.90.
    05 b-field            pic x(8).
    05 b-field-edited redefines b-field pic '-----.99'.

Code:
move a-field to b-field-edited

I ran a small test with 22.90 and -22.90 which gave:
Code:

   22.90     
  -22.90     


Please let us know if you need any additional info.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Feb 09, 2007 11:07 pm
Reply with quote

Dick, I'm more interested in that "22.90 comes as some 480 and sumthing".....Now that's got my curiosity up.... icon_biggrin.gif
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Feb 09, 2007 11:14 pm
Reply with quote

Hi Bill,

Me too, but unless/until we can see the actual result, we'll just have to wonder. . . . icon_confused.gif

I should have also mentioned that the move statement should be
Code:
move a-field to b-field-edited

Ooops icon_redface.gif
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Fri Feb 09, 2007 11:19 pm
Reply with quote

dick scherrer wrote:
I should have also mentioned that the move statement should be
Code:
move a-field to b-field-edited

Ooops icon_redface.gif
Hi Dick,
I don't know, it looks good to me......
Bill
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Sat Feb 10, 2007 12:42 am
Reply with quote

Mercy,

'Tis a bad day when your mistake is that you think you made one icon_biggrin.gif

Don't know if i should feel better or worse. . . .
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Mon Feb 12, 2007 4:53 pm
Reply with quote

rarvins wrote:
hi, sorry for not providing enuf input.

What I am facing rite now.
If I have 22.90 ( S9(3)V9(2) ) in the input file, I am moving it to a character fields ( A size 8) the value 22.90 comes as some 480 and sumthing.

What I need:
I wud need to supress the leading zeros.No trailing supression is required.
I need the same input value in the output character field.

so I just want 22.90
Even if it is 2222.90 I want it as 2222.90
No more formatting is required.
In case theres is -22.90 I would need the negative sign also
So I need -22.90 in the output

Hope I havent missed out anything this time.
icon_smile.gif




Hi Ravin
Please let us know whethet the following code solve your query.

01 IN-PUT PIC 9(5)v9(2) COMP-3.
01 OUT-PUT PIC X(8).


01 IP-TEMP PIC 9(5)V9(2).
01 IP-FMAT PIC ZZZZZ.99.



MOVE IN-PUT TO IP-TEMP.
MOVE IP-TEMP TO IP-FMAT.
MOVE IP-FMAT TO X(8).

DISPLAY IN-PUT
DISPLAY IP-FMAT
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Mon Feb 12, 2007 8:19 pm
Reply with quote

Hi Rajesh,

Please modify your solution to include a floating minus sign. What you posted will "work" but the -22.90 will be missing the '-'. Also, if you use redefinition, you will not need to move the data more than once.

If you look at a prior post in this thread, you will see code that does what Rarvins requested. Once you compare the 2 suggestions, try yours and see if you get the correct result for both positive and negative numbers.
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Tue Feb 13, 2007 2:30 pm
Reply with quote

Hi Scherrer
Thanks for your suggestion. Is the following sound ok?


01 IN-PUT PIC 9(5)v9(2) COMP-3.
01 OUT-PUT PIC X(8).

01 IN-PUT-RES.
05 IP-TEMP PIC 9(5)V9(2).
05 IP-FMAT REDEFINE IP-TEMP PIC -ZZZZZ.99.


MOVE IN-PUT TO IP-PUT-RES.
MOVE IP-FMAT TO OUT-PUT.

DISPLAY IN-PUT.
DISPLAY OUT-PUT.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Feb 13, 2007 2:45 pm
Reply with quote

Rajesh,

Why don't you just move in-put to ip-fmat with out the redefined?

Bill
Back to top
View user's profile Send private message
rajesh_mbt

New User


Joined: 27 Mar 2006
Posts: 97
Location: India

PostPosted: Tue Feb 13, 2007 3:18 pm
Reply with quote

Hi Bill

I am not damn sure whether we can directly move comp-3 variable to editing fields like Zero suppressed(IP-FMAT) since, the sending field(IN-PUT) value is stored as packed decimal format. Also I got some errors in my previous exp when I did the same. Hence, I firstly moved it to decimal variable(IP-TEMP) which is moved later to output field.

MOVE IN-PUT TO IP-TEMP.
MOVE IP-FMAT TO OUT-PUT.
Back to top
View user's profile Send private message
William Thompson

Global Moderator


Joined: 18 Nov 2006
Posts: 3156
Location: Tucson AZ

PostPosted: Tue Feb 13, 2007 3:44 pm
Reply with quote

Trust me on this, move the comp-3 field directly to the edit field, no redef, just directly, it is now edited, move the edit field anywhere you want (except to a numeric field). I am 'dang sure' that is all you need.
Back to top
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Tue Feb 13, 2007 8:28 pm
Reply with quote

Hello,

Please review my earlier post and do the redefine that way. You will get the editing needed and will have an x(8) field that is easier to move around or string.
Code:

    05 a-field            pic s9(5)v99 value 22.90.
    05 b-field            pic x(8).
    05 b-field-edited redefines b-field pic '-----.99'.


The preferred way to get a comp-3 field into edited format is moving it directly. Moving it to some other pic just adds overhead and room for error. The underlying assembler issues an "edit" instruction that must have a comp-3 (packed decimal) field as input. If you don't have the data in a comp-3 field, it will happen internally. If you'd like to see this, put several different formats in some test code and then look at the generated assembler.
Back to top
View user's profile Send private message
umasankar.eee06

New User


Joined: 04 Sep 2008
Posts: 11
Location: chennai

PostPosted: Fri Sep 05, 2008 12:59 pm
Reply with quote

Hi,
I have a filed in my inputfile declared as s9(5)v99 comp-3. I read that file and moved to copy book declared as same at the same time I moved that filed to as variable declared with same notation and displayed that filed but i didt got the exact value.

value is 1143.85 but it displayed as 000 011.
Can any one help me. Thios is urgent I need to solve it by 5pm today.



Thanks
Back to top
View user's profile Send private message
umasankar.eee06

New User


Joined: 04 Sep 2008
Posts: 11
Location: chennai

PostPosted: Fri Sep 05, 2008 1:20 pm
Reply with quote

Sorry to every one rather than answer his question I asked my doubt.





Thanks
Back to top
View user's profile Send private message
Anuj Dhawan

Superior Member


Joined: 22 Apr 2006
Posts: 6250
Location: Mumbai, India

PostPosted: Fri Sep 05, 2008 7:44 pm
Reply with quote

Hi,
umasankar.eee06 wrote:
Sorry to every one rather than answer his question I asked my doubt.
Not to worry, this is not a bother but you have a seprate thread on the same topic..why?

After going through that thread, would suggest you to post a bit of your code, with WS varaibles and yes please post the scrap from the data which you are referring to as comp-3. Use BBcode when you post your code/data.
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 10 byte RBA conversion DB2 2
No new posts 10 byte RBA conversion -non applicati... JCL & VSAM 1
No new posts file manager is doing string conversion IBM Tools 3
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Converting ASCII values to COMP-3 (ZD... JCL & VSAM 2
Search our Forums:

Back to Top