View previous topic :: View next topic
|
Author |
Message |
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
Hi,
I have the following requirement.
A variable is declared as below: ws-hold sign will contain + or - and ws-hold-amt will contain values like 222.99
Code: |
01 WS-HOLD-FULL-AMT.
05 WS-HOLD-SIGN PIC X(01) VALUE SPACES.
05 WS-HOLD-AMT PIC 9(07)V(99). |
Another variable is declared is declared as below
Code: |
01 WS-FINAL-OUT PIC S9(07)V(99). |
I need to store the value that is there in WS-HOLD-FULL-AMT group variable to WS-FINAL-OUT. Can we just use move statement to move WS-HOLD-FULL-AMT to WS-FINAL-OUT ?
Please help me out. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
No. But you can look at the SIGN clause in the COBOL manual, and make a definition which you can just MOVE to your destination field. |
|
Back to top |
|
|
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
well.. I cannot change the source layout as it is existing. Is there any way to do this using redefines ? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Code: |
If ws-hold-sign = '-'
Compute ws-final-out = ws-hold-amt × -1
Else
Compute ws-final-out = ws-hold-amt × (+1)
End-if |
Or use a redefine. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Yes, it works with REDEFINES. Why wouldn't it? |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Rohit,
Code: |
If ws-hold-sign = '-'
Compute ws-final-out = 0 - ws-hold-amt
Else
Move ws-hold-amt To ws-final-out
End-if |
The '-' is better as an 88, but then TS/OP is unable to change the definition...
seahawk789,
It is a little unclear, re-reading. That "." isn't in your data, is it? |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Bill,
Code: |
The '-' is better as an 88, but then TS/OP is unable to change the definition... |
You are right and as that would be as per the coding standards.
My understanding is TS could not be able to change below piece
Code: |
01 WS-HOLD-FULL-AMT.
05 WS-HOLD-SIGN PIC X(01) VALUE SPACES.
05 WS-HOLD-AMT PIC 9(07)V(99). |
But I thought he could add up a another 88 level and place the above logic. |
|
Back to top |
|
|
seahawk789
New User
Joined: 22 Feb 2010 Posts: 56 Location: Cochin
|
|
|
|
So will the below redefine work for the scenario ?
Code: |
01 WS-FINAL-OUT PIC S9(07)V(99).
01 WS-HOLD-FULL-AMT REDEFINES WS-FINAL-OUT.
05 WS-HOLD-SIGN PIC X(01) VALUE SPACES.
05 WS-HOLD-AMT PIC 9(07)V(99).
|
|
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Quote: |
So will the below redefine work for the scenario ? |
I would prefer to say nothing but request you to try and let us know the results. YOu have two options already in your hand as a solution. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
You've not clarified what you input data actually is and what output you want. I doubt that REDEFINES will give you what you want, but as Rohit said... |
|
Back to top |
|
|
Rohit Umarjikar
Global Moderator
Joined: 21 Sep 2010 Posts: 3048 Location: NYC,USA
|
|
|
|
Code: |
PIC S9(7)V9(2) SIGN LEADING SEPARATE |
what happens when you move to this directly btw? |
|
Back to top |
|
|
|