View previous topic :: View next topic
|
Author |
Message |
jsnair
New User
Joined: 26 Sep 2006 Posts: 38 Location: India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
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 |
|
|
Phrzby Phil
Senior Member
Joined: 31 Oct 2006 Posts: 1042 Location: Richmond, Virginia
|
|
|
|
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 |
|
|
Escapa
Senior Member
Joined: 16 Feb 2007 Posts: 1399 Location: IL, USA
|
|
|
|
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 |
|
|
jsnair
New User
Joined: 26 Sep 2006 Posts: 38 Location: India
|
|
|
|
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 |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
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. |
... Please have a look into the manuals to understand how the COMP-3 fields will be displayed... |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
jsnair
New User
Joined: 26 Sep 2006 Posts: 38 Location: India
|
|
|
|
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 |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
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 |
|
|
Binop B
Active User
Joined: 18 Jun 2009 Posts: 407 Location: Nashville, TN
|
|
|
|
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 ...
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 ... |
|
Back to top |
|
|
Marso
REXX Moderator
Joined: 13 Mar 2006 Posts: 1353 Location: Israel
|
|
|
|
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?
Don't forget, next time, to give a complete and correct description of what you do in your program. |
|
Back to top |
|
|
|