View previous topic :: View next topic |
Author |
Message |
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Thu Apr 16, 2009 10:33 am Post subject: how to subtract a number from a hexadecimal field? |
|
|
Dear Folks,
I have a field VAR-FIELD defined as PIC X(05).
The first byte VAR-FIELD(1:1) is a hexadecimal code indicating the length of VAR-FIELD.
Since I removed a part of the name, I now have to decrease the length of the VAR-FIELD.
can u pls lemme know how do i decrease the length of the hexadecimal part ?
The data is like below in the input File with HEX ON : '15' is the hexadecimal code from which i have to subtract a decimal number... and '.' is the data part....
.
1
5
Many Thanks!! |
|
Back to top |
|
|
jsharon1248 Intermediate
Joined: 08 Aug 2007 Posts: 291 Topics: 2 Location: Chicago
|
Posted: Thu Apr 16, 2009 11:07 am Post subject: |
|
|
I'm not sure exactly what you're trying to do, but I'll bet you can do what you need with a REDEFINES. |
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Thu Apr 16, 2009 11:34 am Post subject: |
|
|
Quote: | I have a field VAR-FIELD defined as PIC X(05).
The first byte VAR-FIELD(1:1) is a hexadecimal code indicating the length of VAR-FIELD.
|
15 hex could be pd meaning 15 or binary meaning 21. either way, why the PIC X(05)? _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Fri Apr 17, 2009 4:26 am Post subject: |
|
|
ok i will rephrase my qn now...
01 VAR-FIELD PIC X(96).
VAR-FIELD(1:1) is a one-byte hexadecimal code indicating the length of VAR-FIELD..
VAR-FIELD(2:96) will contain the first name and last name..
I removed the last name from the field and hence now i have to decrease the length of the VAR-FIELD which is a hexadecimal code and is stored in the first byte of VAR-FIELD(1:1)....
say for example the length of the name field is 21 and it's stored as hexadecimal 15 in VAR-FIELD(1:1)...
now the length of the name field is only 10 since i removed the last name....
how do i decrease the length of the hexa decimal code ??
Decimal 11 should be subtracted from hexadecimal 15....
shld i first convert hexadecimal 15 to decimal, then subtract 11, then convert decimal to hexadecimal and store it in VAR-FIELD(1:1)???
Is there any other better way to do it?
am guessing it is clear now.... Many Thanks!! |
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Fri Apr 17, 2009 5:08 am Post subject: |
|
|
I have since the initial post,
edited this post to make it correct.
apologize for not having tested this,
and wasting the OP's time
and forcing Kolusu to make yet another post to correct mine.
dbz-tue 21 Apr 09
since it is a binary value, and binary calculations require a minimum of 2 bytes:
you could:
Code: |
05 BINARY-FIELD PIC S9(4) BINARY VALUE ZERO.
05 BINFLD-REDEF
REDEFINES
BINARY-FIELD.
10 FILLER PIC X(01).
10 PLUG-VAL PIC X(01).
MOVE VAR-FIELD(1:1) TO PLUG-VAL
COMPUTE BINARY-FIELD
= BINARY-FIELD
- LENGTH-OF-REMOVED-DATA
END-COMPUTE
MOVE PLUG-VAL TO VAR-FIELD(1:1)
|
Since the 'VLI' [VAR-FIELD(1:1)] is only one byte, the max value can only be 255. _________________ Dick Brenholtz
American living in Varel, Germany
Last edited by dbzTHEdinosauer on Tue Apr 21, 2009 2:25 pm; edited 1 time in total |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Fri Apr 17, 2009 10:19 am Post subject: |
|
|
SAHANA,
Are you sure that your length is just 1 byte? I don't think so. If you are dealing with either DB2 Varchar data or COBOL Variable Array, the length is ALWAYS 2 bytes. S9(1) thru s9(4) comp all take 2 bytes.
You can directly subtract the value from the 2 byte field.
Kolusu |
|
Back to top |
|
|
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Fri Apr 17, 2009 11:36 am Post subject: |
|
|
Yes the length is just 1 byte(or am I wrong?)
Please see the values as seen in the input file with HEX ON...
The first byte is the length of the field... and in the below example its '14'
.I.. |
|
Back to top |
|
|
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Tue Apr 21, 2009 11:52 am Post subject: |
|
|
@ dbzTHEdinosauer - The logic proposed by you did not work... it was erroring out with the below error -
Receiving operand "BINARY-FIELD (GROUP)" of an arithmetic statement was neither
The statement was discarded.
"BINARY-FIELD (GROUP)" was not numeric, but was a sender in an arithmetic expression.The statement was discarded.
@Kolusu - I could not directly subtract a decimal number say 9 from VAR-FIELD(1:1)..
Should I try converting hex to decimal, subtract a number from decimal, then convert it back to hexadecimal???
if yes, does not anyone have a handy code ?
Many Thanks!! |
|
Back to top |
|
|
dbzTHEdinosauer Supermod
Joined: 20 Oct 2006 Posts: 1411 Topics: 26 Location: germany
|
Posted: Tue Apr 21, 2009 12:03 pm Post subject: |
|
|
no comment- promised not to flame anymore. _________________ Dick Brenholtz
American living in Varel, Germany |
|
Back to top |
|
|
kolusu Site Admin
Joined: 26 Nov 2002 Posts: 12376 Topics: 75 Location: San Jose
|
Posted: Tue Apr 21, 2009 1:55 pm Post subject: |
|
|
SAHANA,
FWIW Try this
[code:1:1f39411e29]
01 VAR-FIELD PIC X(96).
01 WS-BIN PIC S9(04) COMP VALUE ZERO.
01 TEXT-FIELD REDEFINES WS-BIN.
05 FILLER PIC X(01).
05 PLUG-VAL PIC X(01).
01 OUT-FIELD PIC X(96).
MOVE ' I |
|
Back to top |
|
|
SAHANA Beginner
Joined: 18 Jul 2007 Posts: 18 Topics: 5 Location: United Kingdom
|
Posted: Mon May 04, 2009 7:23 am Post subject: |
|
|
Thanks a lott Kolusu and dbzTHEdinosauer....it worked!!! |
|
Back to top |
|
|
|
|