Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sign trailing separate 3

Status
Not open for further replies.

LenaS

Technical User
Nov 28, 2000
98
US
As input to my program I have an ascii table file with an amount S9(9)v99 defined as sign trailing separate. If a record meets certain criteria, a sign reversal is necessary. I am doing this by multiplying the amount by -1. This causes an amount value of 1000000- to become
-00010000013. Amounts not requiring this action move thru the program fine, no problem. Debug shows me that as soon as the compute or multiply(I tried both) happens, it messes up my amount. I am obviously not a COBOL programmer. I inherited this code and it is just one application(I plan to rewrite it in the future). Maybe I should just write a simple program to read the file in via sign trailing separate and output it to something COBOL likes better. I am using CA-Realia COBOL on a PC. Please help. Thanks.
 
Can you let us know a specific example?

Say you multiply X by -1 and you get A when you really should be getting B. Give us specific values of X, A, and B so we can look into what might be happening. Under what conditions are the amounts being "messed up" and exactly how are they being "messed up?"

Nina Too
 
As I said, I multiply 1000000- by -1 and get -00010000013 instead of 1000000. This IS a specific example. I don't know what else to tell you.
 
I have what seems to be a truly dumb question. Sorry if it's so basic. But what is the actual value of '1000000-' in ASCII? Is it supposed to be the same as '-1000000'?

Because I looked up the trailing hyphen in my COBOL manual. And when used in a PIC clause, it functions as some sort of editor involving fixed or floating decimal points or as an exponent.

I'm not sure how a PIC S9(9)V99 field in a program would handle '1000000-' coming into it. I've never used values with trailing signs, and what my COBOL manual wrote was a bit confusing to me. But I suspect that COBOL sees '1000000-' as being some sort of exponential value, different from '-1000000'.

If so, what I would do is use a working storage field to change '1000000-' to '-1000000' before doing your computation.

I don't know if this helps, but I hope it does.

Nina Too
 
Nope. What I started with was sign leading separate like you said '-1000000'. Same thing happens but at the high order. I get '-131000000'. It seems to read a minus sign (wherever it sees it) as a value of 13 when it does the math.
 
This sound really far off, and probably means nothing. It qualifies as a wild guess.

But in ASCII, the hex value of a hyphen is 2D. I'm just wondering if the hyphen/minus sign byte is coming in as 2D but is truncating the '2' so that you only get 'D'. Which is 13 in hex. So it's placing a '13' in front of your '1000000'.

Or else it does see the '-' and places it in front, but then places the 'D' (as a hex value of 13) in front of your value of 1000000. I wonder if somehow some data element sees the incoming value as a string rather than a number. Even though your PIC clause is defining the element as a signed number.

I do know that when a data element is defined as a signed number in COBOL, that there is a "sign byte" included. I wonder if some mix-up with this sign byte and your incoming ASCII value is somehow occuring.

I think that you'll have to do a hex display of your incoming value. And then trace the computation to see what happens to it. See how your function sees this incoming value -- is it seeing it a -1000000 or is it seeing it as 131000000?

Again, I am grasping at straws. I welcome anyone else's imput. Let me know what happens.

Nina Too
 
Interactive Debug shows the value of 'AMOUNT' as 1000000- before the calculation. When it does 'COMPUTE AMOUNT = AMOUNT * -1' the value becomes -00010000013.
 
First, I assume that the variable AMOUNT is defined as a PIC S9(7) in Working-Storage.

If not, define a field, WS-AMOUNT PIC S9(7) in Working-Storage.

You have AMOUNT with 1000000- in it when you get the data. Trying moving -1000000 (with the sign leading) into AMOUNT, or else move -1000000 into WS-AMOUNT and then do the calculation and move the result back into AMOUNT.

Don't move the field directly from AMOUNT. Instead, take the value 1000000- and re-format it as -1000000 and then move -1000000 into WS-AMOUNT.

I'm almost positive that COBOL sees 1000000- and -1000000 as different amounts.

Nina Too
 
What you are doing should work. I tried it on the mainframe and it generates the expected result of simply changing the sign.

Would you try the following and let me know what happens...

SUBTRACT AMOUNT FROM ZERO GIVING AMOUNT

The subtracting from ZERO is a technique I have used when porting COBOL applications from the mainframe to the PC. It has worked well for me over the years.

I do not have Realia but I could try the same thing on Micro Focus COBOL and see what happens...

Good Luck...
Saginaw
helpdesk@simotime.com
 
Saginaw...I get exactly the same result using subtract as I did with multiply.

Nina... I have tried both formats, sign leading and trailing. When I move the value to WS-AMOUNT it's still correct. The value changes after the subtract,compute,etc. Moving it back to AMOUNT does not correct it.

Maybe I need to contact Realia.
 
Okay, just got through looking up in my COBOL guide again.

There is a function where you can put parentheses around a number, put a '-' in front of it, and the result will be the same as if mulitplying by -1.

So try this:

IF AMOUNT < 0
COMPUTE AMOUNT = -(AMOUNT)
END-IF.

Hope this works, Nina Too

 
I appreciate all your help, but that one didn't make any difference either. I guess I'll try asking Realia. Thanks. I am going to forget about this until Tuesday and have a good 4-day weekend. You all do the same.
 
LenaS,

I would agree with your decision to call Realia... However, one last attempt and I do not recommend the following as a final answer... this suggestion is only an attempt to further define the problem...

EVALUATE AMOUNT(12:1)
WHEN '-' MOVE '+' TO AMOUNT(12:1)
WHEN '+' MOVE '-' TO AMOUNT(12:1)
WHEN OTHER DISPLAY 'ERROR MESSAGE'
END-EVALUATE

If AMOUNT is defined in WORKING STORAGE as:

01 AMOUNT PIC S9(9)V99 SIGN TRAILING SEPARATE
VALUE -1000000.

then the actual memory should contain the following ASCII string...

X'30303130303030303030302D'

and after executing the EVALUATE the string should be...

X'30303130303030303030302B'

I tried this with Micro Focus Net Express and it works... But then so do the other suggestions...

Let me know the results...
but first... enjoy your four-day weekend...

Saginaw
helpdesk@simotime.com
 
Saginaw, I was thinking of a similar solution if none of the COBOL functions worked.

But first, you have to change AMOUNT into a PIC X field and then make sure the sign gets in. Because you can't use anything like &quot;(12:1)&quot; on a PIC S9 field.

After you do your string manipulation to strip off the minus sign (and its negative value) then move it back into a PIC 9 or PIC S9 field.

But actually, I think that Lena should call Realia. Because something is terribly wrong here.

Sorry we couldn't be of further help. But I think one or more of our functions should work once you get the Realia software straightened out.

Nina Too
 
Ooops, Saginaw, it looks as though there are things you can do in Microfocus COBOL which I can't do in mainframe MVS COBOL. Because I notice that your PIC descriptions have parameters which I don't recognize ('PIC S9(9)V99 SIGN TRAILING SEPARATE').

Or else I can use it in MVS COBOL but just don't know it. :-D

Have a good week-end everyone. I plan to be in the computer-less wilds of northern Michigan next week. s-)

Nina Too

 
NinaToo,

The reference modification definitely Works with Micro Focus Net Express, version 3.1... and if my memory serves me correctly it was/is supported on the mainframe starting with VS COBOL/II, release 4.0. I know it does not work with earlier releases...

Anyway... just for grins I will try it on the mainframe a little later and let you know... will also include the actual source code for the test...

Interesting problem... Saginaw
helpdesk@simotime.com
 
I have tried this in Realia COBOL and it works like it is supposed to, i.e. no 13's in sight. How do you know about the 13? Are you doing a DISPLAY in your program or reading the file into some other utility to look at it? Betty Scherber
Brainbench MVP for COBOL II
 
A few things. What is the USAGE of the original field? You have defined it as PIC S9(9)v(99) SIGN SEPARATE TRAILING. Does it contain 00010000000- or bbb10000000-? What is the picture and usage of the receiving field?
(Since you say you are not a COBOL programmer, if USAGE is not specified, it is DISPLAY. If it is something else, it will be part of the description. Please give us the COMPLETE description of the sending and receiving fields, including VALUE phrases, if any.)
Hmmm, if the sending and receiving field are the SAME field, and it is defined as SIGN SEPARATE TRAILING, something is VERY wrong if the result has the sign LEADING. You COULD have a compiler bug ... it has been known to happen :) especially with a feature as little used as SIGN SEPARATE TRAILING.

Stephen J Spiro
Member, J4 COBOL Standards Committee
check it out at

stephenjspiro at hotmail.com
 
NinaToo...

I did get a chance to run the test on the mainframe using VS COBOL/II, release 4.0 and you do not need to move to a PIC X field. The EVALUATE using reference modification works. I also ran the test on Micro Mainframe Express and Micro Focus Net Express and it works as I would expect...

The following is a snipet of the code used in the test...

01 FIELD-SIGN-TRAIL-A.
05 FIELD-SIGN-TRAIL PIC S9(9)V99
SIGN TRAILING SEPARATE.
...

TEST-VARIOUS-SIGNED-FIELDS.
DISPLAY '* CBLNUMC1 SIGN TRAILING SEPARATE...'
DISPLAY '* CBLNUMC1 ' FIELD-SIGN-TRAIL
EVALUATE FIELD-SIGN-TRAIL(12:1)
WHEN '-' MOVE '+' to FIELD-SIGN-TRAIL(12:1)
WHEN '+' MOVE '-' to FIELD-SIGN-TRAIL(12:1)
WHEN OTHER DISPLAY 'FORMAT ERROR'
END-EVALUATE
DISPLAY '* CBLNUMC1 ' FIELD-SIGN-TRAIL

Te entire program and the mainframe JCL may be downloaded from the following URL...


We are either missing something in the problem definition or there is a compiler bug...




Saginaw
helpdesk@simotime.com
 
NinaToo...

I did get a chance to run the test on the mainframe using VS COBOL/II, release 4.0 and you do not need to move to a PIC X field. The EVALUATE using reference modification works. I also ran the test on Micro Mainframe Express and Micro Focus Net Express and it works as I would expect...

The following is a snipet of the code used in the test...

01 FIELD-SIGN-TRAIL-A.
05 FIELD-SIGN-TRAIL PIC S9(9)V99
SIGN TRAILING SEPARATE.
...

TEST-VARIOUS-SIGNED-FIELDS.
DISPLAY '* CBLNUMC1 SIGN TRAILING SEPARATE...'
DISPLAY '* CBLNUMC1 ' FIELD-SIGN-TRAIL
EVALUATE FIELD-SIGN-TRAIL(12:1)
WHEN '-' MOVE '+' to FIELD-SIGN-TRAIL(12:1)
WHEN '+' MOVE '-' to FIELD-SIGN-TRAIL(12:1)
WHEN OTHER DISPLAY 'FORMAT ERROR'
END-EVALUATE
DISPLAY '* CBLNUMC1 ' FIELD-SIGN-TRAIL

Te entire program and the mainframe JCL may be downloaded from the following URL...


We are either missing something in the problem definition or there is a compiler bug...

LenaS...

If you want to send me the source code in care of helpdesk@simotime.com I will take a closer look at the problem...




Saginaw
helpdesk@simotime.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top