View previous topic :: View next topic |
Author |
Message |
rajkumar_1981 Beginner
Joined: 05 Jan 2007 Posts: 5 Topics: 4
|
Posted: Wed Jun 06, 2007 5:01 am Post subject: Cobol program to populate s9(4) field value |
|
|
hi,
input
------
01 a pic x value '+'
01 b pic 9(4)
output
-------
01 c pic s9(4).
to populate the input value into output.
for example,
a=+(x) , b=1000(9(4))
c=+1000(in s9(4))
Please help me... |
|
Back to top |
|
|
CICS Guy Intermediate
Joined: 30 Apr 2007 Posts: 292 Topics: 3
|
Posted: Wed Jun 06, 2007 5:45 am Post subject: |
|
|
If a will always be "+", just move b to c.
If a might be "+" or "-", use a conditional to set the sign such as:
move zero to c
if a = '+' add b to c
if a = '-' subtract b from c
The "S" in the pic of c is not a plus or minus sign, is is actually a difference in the high half of the low-order byte. |
|
Back to top |
|
|
rajkumar_1981 Beginner
Joined: 05 Jan 2007 Posts: 5 Topics: 4
|
Posted: Wed Jun 06, 2007 11:02 pm Post subject: Re: Cobol program to populate s9(4) field value |
|
|
rajkumar_1981 wrote: | hi,
input
------
01 a pic x value '+'
01 b pic 9(4)
output
-------
01 c pic s9(4).
to populate the input value into output.
for example,
a=+(x) , b=1000(9(4))
c=+1000(in s9(4))
it is not add or sub. it populate the inputs values (a, b ) to output variable
(c).i.e., it combine the input values(a, b) to populate into output variable.
Please help me... |
|
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Thu Jun 07, 2007 12:46 am Post subject: |
|
|
rajkumar_1981,
signed display numeric values can have their sign either leading or trailing - indicated by the 'leading or trailing clause' in the element definition.
If you wish to actually move the sign character, then c needs to be redefined. You should refer to the manual for information how to accomplish this for your student project.
A professional would write code that would work for either trailing/leading as well as display and Packed-decimal - or any other numeric designation. That way, if the data definition changes, the code must not.
Code: |
MOVE b TO c
IF a = '-'
THEN
COMPUTE c = c * -1
END-COMPUTE
END-IF
|
also, in the future please use BBcode to enable better readability _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
|
|