View previous topic :: View next topic
|
Author |
Message |
Agni
New User
Joined: 22 Nov 2007 Posts: 83 Location: Chennai
|
|
|
|
Hi All,
I need to edit a nibble in my output file. I am using COBOL code for the same. Please find below the working storage variables.
Code: |
01 WW-WORKING-STORAGE.
05 WW-PACKED-4 PIC S9(03) COMP-3.
05 FILLER REDEFINES WW-PACKED-4.
10 WW-PACKED-4-HEX-2 PIC X(02).
05 WW-UNPACKED-4 PIC 9(04).
|
COBOL code to edit the nibble.
Code: |
X100-EDIT-NIBBLE.
MOVE WI-UT-REEL TO WW-PACKED-4-HEX-2
MOVE WW-PACKED-4-HEX-2 TO WW-UNPACKED-4
MOVE WW-NIBBLE-VALUE TO WW-UNPACKED-4(1:1)
MOVE WW-UNPACKED-4 TO WW-PACKED-4
MOVE WI-INPT-RECORD TO WO-OUPT-RECORD
MOVE WW-PACKED-4 TO WO-UT-REEL.
X100-EXIT.
EXIT.
|
WW-PACKED-4 is having a value of '0943'. I need to have '4943' in my output file. I am unpacking that variable and moving a value '4' and try to pack it again. After doing so,i am getting the output file as below. I should get the value '4' in column 4 instead of the '0'. WW-NIBBLE-VALUE will have a value of 4.
Code: |
----+----1----+----2----+----3----+----4----+----5----+----6
04C040318F00500000000500610700000000013607090002
10993166F307F000000025F0302F00F00000192F450C00045
|
Note: Here input & output files are same.
Please let me know if you need any other details.
Thanks in advance
Agni. |
|
Back to top |
|
|
murmohk1
Senior Member
Joined: 29 Jun 2006 Posts: 1436 Location: Bangalore,India
|
|
|
|
Agni,
Quote: |
Please let me know if you need any other details. |
Yes.
Quote: |
WW-PACKED-4 is having a value of '0943'. I need to have '4943' in my output file. |
What if WW-PACKED-4 has a value > 1000 (say 1943). Then how does your o/p looks?
If you i/p is always < 1000, then you can simply add '4000'. |
|
Back to top |
|
|
dbzTHEdinosauer
Global Moderator
Joined: 20 Oct 2006 Posts: 6966 Location: porcelain throne
|
|
|
|
Quote: |
MOVE WW-PACKED-4-HEX-2 TO WW-UNPACKED-4
|
that's dumb. |
|
Back to top |
|
|
ParagChouguley
Active User
Joined: 03 Feb 2007 Posts: 175 Location: PUNE(INDIA)
|
|
|
|
I doubt if this code will accept any value at the nibble where sign is stored in COMP-3 (Rightmost nibble).
Could I please get a code to change any nibble to any value (ie acceptable in hex, from 0 to F)?
Thanks in advance! |
|
Back to top |
|
|
Terry Heinze
JCL Moderator
Joined: 14 Jul 2008 Posts: 1249 Location: Richfield, MN, USA
|
|
|
|
If you want WW-PACKED-4 to have a value of X'4943', you will be removing the sign of a packed decimal number which will probably yield a S0C7 (ASRA if in CICS) when you try to move it or use it in a calculation. I think you'd be better off telling us what you want to accomplish and I'm sure someone here can come up with a solution. |
|
Back to top |
|
|
ParagChouguley
Active User
Joined: 03 Feb 2007 Posts: 175 Location: PUNE(INDIA)
|
|
|
|
Well....anyone? |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10872 Location: italy
|
|
|
|
no pestering, please, people reply on their own time |
|
Back to top |
|
|
Robert Sample
Global Moderator
Joined: 06 Jun 2008 Posts: 8696 Location: Dubuque, Iowa, USA
|
|
|
|
As far as I know, you're going to have to write your own routine in Assembler (or maybe PL/1?) and call it from COBOL. LE has bit manipulation routines, but they work on a 32-bit integer (i.e., 4 bytes). COBOL itself doesn't really handle bits as bits, so Assembler (or PL/1) will be required. |
|
Back to top |
|
|
dick scherrer
Moderator Emeritus
Joined: 23 Nov 2006 Posts: 19244 Location: Inside the Matrix
|
|
|
|
Hello,
WHile it is a bit more tedious, you can manipulate bits in cobol or easytrieve by messing around with "powers of 2". Here is the code to take one byte and show the on/off condition for the bits making up the byte. Reversing the logic lets one set bits. The same basic code works in cobol, just the syntax is a bit different (i don't have the cobol code handy just now). This sample uses 80-byte input (fileb):
Code: |
FILE FILEB
BYTE1 1 1 A
BYTE2 2 1 A
BYTE3 3 1 A
THEREST 4 77 A
FBYTE W 1 B
FBIT7 W 1 A
FBIT6 W 1 A
FBIT5 W 1 A
FBIT4 W 1 A
FBIT3 W 1 A
FBIT2 W 1 A
FBIT1 W 1 A
FBIT0 W 1 A
JOB INPUT FILEB
DISPLAY BYTE1
MOVE BYTE1 TO FBYTE
DISPLAY FBYTE
IF FBYTE > 127
MOVE '1' TO FBIT7
FBYTE = FBYTE - 128
* SUBTRACT 128 FROM FBYTE
ELSE
MOVE '0' TO FBIT7
END-IF
IF FBYTE > 63
MOVE '1' TO FBIT6
FBYTE = FBYTE - 64
ELSE
MOVE '0' TO FBIT6
END-IF
IF FBYTE > 31
MOVE '1' TO FBIT5
FBYTE = FBYTE - 32
ELSE
MOVE '0' TO FBIT5
END-IF
IF FBYTE > 15
MOVE '1' TO FBIT4
FBYTE = FBYTE - 16
ELSE
MOVE '0' TO FBIT4
END-IF
IF FBYTE > 7
MOVE '1' TO FBIT3
FBYTE = FBYTE - 8
ELSE
MOVE '0' TO FBIT3
END-IF
IF FBYTE > 3
MOVE '1' TO FBIT2
FBYTE = FBYTE - 4
ELSE
MOVE '0' TO FBIT2
END-IF
IF FBYTE > 1
MOVE '1' TO FBIT1
FBYTE = FBYTE - 2
ELSE
MOVE '0' TO FBIT1
END-IF
IF FBYTE = 1
MOVE '1' TO FBIT0
ELSE
MOVE '0' TO FBIT0
END-IF
DISPLAY FBIT7
DISPLAY FBIT6
DISPLAY FBIT5
DISPLAY FBIT4
DISPLAY FBIT3
DISPLAY FBIT2
DISPLAY FBIT1
DISPLAY FBIT0
DISPLAY BYTE2
DISPLAY BYTE3
STOP
|
An input value of "H" gives:
Code: |
H
200
1
1
0
0
1
0
0
0 |
As Robert mentioned, cobol/easytrieve isn't made for bit manipulation, but if you need to, you can. |
|
Back to top |
|
|
|