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

Move COMP-3 field to Numeric?


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

New User


Joined: 26 Sep 2006
Posts: 38
Location: India

PostPosted: Mon May 10, 2010 2:36 pm
Reply with quote

Hello All,

Is it possible to move a value from COMP-3 field to NUMERIC?


10 TST-VAL PIC S9(3) COMP-3.

10 WS-VAL PIC S9(3).


MOVE TST-VAL TO WS-VAL.


When I tried to move 055 the value in WS-VAL was 0 and for 111 the value was 1.

I tried to increase the length of WS-Val to 9(10) but still not getting the correct value.
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Mon May 10, 2010 4:58 pm
Reply with quote

You are not telling us everything. I duplicated what you SAID you did:
Code:
           10  TST-VAL-1               PIC S9(03) COMP-3 VALUE 055.
           10  TST-VAL-2               PIC S9(03) COMP-3 VALUE 110.
           10  WS-VAL                  PIC S9(03).

       LINKAGE SECTION.
      /
       PROCEDURE DIVISION.
       S1000-MAIN       SECTION.
           DISPLAY 'TST-VAL-1   ' TST-VAL-1.
           DISPLAY 'TST-VAL-2   ' TST-VAL-2.
           MOVE TST-VAL-1              TO  WS-VAL.
           DISPLAY 'WS-VAL      ' WS-VAL.
           MOVE TST-VAL-2              TO  WS-VAL.
           DISPLAY 'WS-VAL      ' WS-VAL.
           GOBACK.
and got results exactly as expected of:
Code:
 TST-VAL-1   055
 TST-VAL-2   110
 WS-VAL      05E
 WS-VAL      11{
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Mon May 10, 2010 7:48 pm
Reply with quote

TS70363 - why would you suggest that the receiving field needs two more digits?

Also, while "sign separate" is a very useful way to see "display" data, it is not necessary to get the correct result.
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 May 10, 2010 7:49 pm
Reply with quote

Hello,

Quote:
When I tried to move 055 the value in WS-VAL was 0 and for 111 the value was 1.
Just for verification, run an experiment changing the MOVE to a COMPUTE.

As Robert mentioned, you haven't told us everything. . .
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Mon May 10, 2010 7:50 pm
Reply with quote

Hey - who deleted TS70363's comment? It may have been misleading, but now I have a dangling reply (and we don't want those, do we?).
Back to top
View user's profile Send private message
Escapa

Senior Member


Joined: 16 Feb 2007
Posts: 1399
Location: IL, USA

PostPosted: Tue May 11, 2010 10:25 am
Reply with quote

Phrzby Phil wrote:
Hey - who deleted TS70363's comment? It may have been misleading, but now I have a dangling reply (and we don't want those, do we?).

lol.... Yeah.. I could connect as I had gone through post yesterday..
Back to top
View user's profile Send private message
jsnair

New User


Joined: 26 Sep 2006
Posts: 38
Location: India

PostPosted: Tue May 11, 2010 2:55 pm
Reply with quote

Hello All,

First of all I am confused how Robert can display a COMP-3 field directly. He is displaying TST-VAL-1 directly?? When I tried to display a COMP-3 field I was getting some garbage values.

My scenario is I have one COMP-3 field and I am moving TST-VAL to WS-VAL. The output I am getting as below. TST-VAL's value was 059. See the definition below for the fields.

Even I tried COMPUTE instead of MOVE still getting the same result.

Code:
WORKING-STORAGE.

10 TST-VAL                  PIC S9(3) COMP-3.


10 WS-VAL                   PIC 9(5)  VALUE ZERO.



Code:
output:

WS-VAL : 00 0



Thanks in advance...
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Tue May 11, 2010 3:01 pm
Reply with quote

Hi Jiji,
Quote:
My scenario is I have one COMP-3 field and I am moving TST-VAL to WS-VAL. The output I am getting as below. TST-VAL's value was 059. See the definition below for the fields.
1. How are u saying the value of TST-VAL is 059.
2. Can we see your "move" statement.

Quote:
When I tried to display a COMP-3 field I was getting some garbage values.
icon_rolleyes.gif ... Please have a look into the manuals to understand how the COMP-3 fields will be displayed...
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Tue May 11, 2010 4:01 pm
Reply with quote

First, t here is a link to manuals at the top of the page. Click on it, find the COBOL Language Reference and Programming Guide manuals. Learn to use them, for you will need them often.

Second, if you do this, you will find that a COMP-3 field is a numeric field to COBOL and can be directly displayed without any issues at all -- as my code shows.

Third, you still are not telling us everything -- if you cannot tell us everything, you're not going to get your problem resolved.

Fourth, how do I know you're not telling us everything? Your display of WS-VAL is either space-zero-zero-space-zero or zero-zero-space-zero-space (although the space in the middle could be something else) -- depending upon the exact DISPLAY statement you used, which again you did not give us. The only way to get this result in a numeric field is by moving an alphanumeric (PIC X) field to it at some point. You're not showing us this move.

As my code shows, what you claim as results is not possible in COBOL -- so the presumption is that you are doing something wrong. We cannot tell what since you are not giving us everything, but you are definitely doing something wrong.
Back to top
View user's profile Send private message
jsnair

New User


Joined: 26 Sep 2006
Posts: 38
Location: India

PostPosted: Tue May 11, 2010 4:08 pm
Reply with quote

Hi Binop,

Quote:
Please have a look into the manuals to understand how the COMP-3 fields will be displayed...


As per my understanding COMP-3 values can't be displayed directly. We have to move to a intermediary field or redefine it with dispaly field. If you look above can see Robert's code where he is directly dispalying COMP-3 values.

Quote:
1. How are u saying the value of TST-VAL is 059.
2. Can we see your "move" statement.


Regarding the TST-VAL I am reading it from a file and I just did a redefine that field with DISPLAY field. When I looked the spool i can see the correct value for TST-VAL-X. See the code below. Please look into the vale populated in WS-FONDS. Hope it's clear for you??


Code:
10 TST-VAL                  PIC S9(3) COMP-3.
10 TST-VAL-X redefines TST-VAL PIC X(03).

10 WS-FONDS                 PIC 9(5)  VALUE ZERO.


compute WS-FONDS = TST-VAL


SPOOL OUPUT:

TST-VAL-X : 059


WS-FONDS : 00 0
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


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

PostPosted: Tue May 11, 2010 4:18 pm
Reply with quote

Quote:
As per my understanding COMP-3 values can't be displayed directly. We have to move to a intermediary field or redefine it with dispaly field.
Your understanding is wrong. You desperately need to spend a few days (or weeks) reading the COBOL manuals cover to cover. The internal format for a PIC S9(03) COMP-3 variable with a value of +059 is X'059C' -- note that this is only two bytes, but that's the way COMP-3 variables are stored. There is absolutely no way you can use a REDEFINE into a USAGE DISPLAY variable that will allow this value to be processed as a numeric value. A PIC S9(03) variable with a value of +059 is stored as X'F0F5C9' and you cannot redefine the two-byte field into this three-byte field. It simply does not work.

Go back to your code, clear out all of the garbage you've added to "convert" values from one format to the other and just use the numeric variables as numeric variables.
Back to top
View user's profile Send private message
Binop B

Active User


Joined: 18 Jun 2009
Posts: 407
Location: Nashville, TN

PostPosted: Tue May 11, 2010 9:48 pm
Reply with quote

Hi Jiji,

First and foremost, your REDEFINE code...
Code:
10 TST-VAL                  PIC S9(3) COMP-3.
10 TST-VAL-X redefines TST-VAL PIC X(03).
If you look into the compile listing, you would certainly find a warning as mentioned below.
Code:
IGYDS1154-W   "WS-WORK10-R" redefined a smaller item.  The program was accepted as written.
Hope this makes sense to you when you read this warning along with Robert's description ...



Based on the inputs you have mentioned, Robert has already showed you how the output will look like.
I have slightly modified that concept based on the code and output that you have mentioned ...
Code:
 01  WS-WORKING-VARIABLES.
     05  WS-WORK10               PIC S9(03) USAGE COMP-3
                                            VALUE 59.   
     05  WS-WORK10-R             REDEFINES  WS-WORK10   
                                 PIC  X(03).             
     05  WS-WORK11               PIC  9(5)  VALUE ZERO. 
*                                                       
 PROCEDURE DIVISION.                                     
*                                                       
 MAIN-LINE-PARA.                                         
*                                                       
     MOVE '059'                  TO WS-WORK10-R.         
     COMPUTE WS-WORK11 = WS-WORK10.                     
     DISPLAY WS-WORK11.                                 
*                                                       
and the Output ...
Code:
00.0.
Going by this... my guess is you are populating the REDEFINE field (TST-VAL-X) with a value of '059' ( while all this time you have been mentioning that your packed field (TST-VAL) is having a value of 059) ... As Robert have already mentioned you need to have a look into the manuals ... and understand the REDEFINE functionality also ... icon_smile.gif
Back to top
View user's profile Send private message
Marso

REXX Moderator


Joined: 13 Mar 2006
Posts: 1353
Location: Israel

PostPosted: Wed May 12, 2010 2:33 am
Reply with quote

jsnair wrote:
When I tried to display a COMP-3 field I was getting some garbage values.
In fact, you never tried to display the COMP-3 field itself.

If you hide what you are really doing and tell stories, how can we help? icon_evil.gif

Don't forget, next time, to give a complete and correct description of what you do in your program.
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 Replace Multiple Field values to Othe... DFSORT/ICETOOL 12
No new posts COBOL - Move S9(11)v9(7) COMP-3 to -(... COBOL Programming 5
No new posts Join 2 files according to one key field. JCL & VSAM 3
No new posts How to move the first field of each r... DFSORT/ICETOOL 5
No new posts S0C7 - Field getting overlayed COBOL Programming 2
Search our Forums:

Back to Top