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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Alphanumeric to numeric conversion 1

Status
Not open for further replies.

mbkhamankar

Programmer
Feb 20, 2003
2
US
Hi,

After I move a signed numeric field (A) which has an alphanumeric value to another signed numeric field (B), B contains a numeric value. The alphanumeric value gets converted to a numeric value after the move. I don't even get the S0C7 error. Since I have to pass the value without any editing, I have to redefined the fields as alpha and if a non-numeric value comes along, I move the alpha to alpha.

Could anyone tell me if this is the expected behaviour for cobol ?

Thanks !
 
Hi,

We need more info to help. What platform (PC, mainframe, etc.), what compiler (micro Fofus, IBM OS309/MVS, etc.), what release or level compiler)? Compilers handle these situations differently, so it's important to know which one it is.

Also show us the ACTUAL data defs and move stmts. Use cut & paste. The internal representation of the data would help too, e.g. FLD-A = X'F1F2C1F9F6'.

HTH, Jack.
 
Here's an explanation of what is probably happening. This is the way it works on an IBM mainframe. When you move zoned decimal signed numeric to zoned decimal signed numeric, the compiler usually generates code that packs the fields into temporary work areas, then zeroes out the receiving field and adds the sending field to it. Finally it unpacks the answer and puts it in the receiving field.

You were lucky with the values that you used that you did not receive the S0C7.

Let's look at an example to see what it did. Let's say you are moving S9(03) to S9(03. Sending field contains 'ABC'. You must understand the hex representation to know what is happening. 'ABC' in hex is 'C1 C2 C3'. When the system packs that into a work area you get '12 3C'. Remember, when a value is packed it reverses the zone and digit of the rightmost byte and then keeps just the numeric portions of the other bytes. This looks like a valid +123. It gets moved to the receiving work area. Now that area gets unpacked and put into your receiving field. To unpack, you reverse the zone and digit of the rightmost byte and then add an 'F' zone to the other half-bytes digits. When unpacking '12 3C' you get 'F1 F2 C3. This looks like a valid numeric value for a S9(03) field.

Now what if your sending field contained '$BC'. In hex that is '5B C2 C3'. When that gets packed you get 'B2 3C'. Now you would get a S0C7 when trying to move that value because the packed value contains non-numeric characters.

That got a little lengthy but I hope it clears up what happened.
 
Thank you for your help. I forgot to paste the hex values as Slade had suggested. I will try out whatever Lunker has written tomorrow.

Thank you once again and sorry about not not pasting the hex value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top