IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

How to edit a nibble in COBOL?


IBM Mainframe Forums -> COBOL Programming
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
Agni

New User


Joined: 22 Nov 2007
Posts: 83
Location: Chennai

PostPosted: Thu Dec 27, 2007 11:04 am
Reply with quote

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
View user's profile Send private message
murmohk1

Senior Member


Joined: 29 Jun 2006
Posts: 1436
Location: Bangalore,India

PostPosted: Thu Dec 27, 2007 6:24 pm
Reply with quote

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
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Dec 27, 2007 7:35 pm
Reply with quote

Quote:

MOVE WW-PACKED-4-HEX-2 TO WW-UNPACKED-4


that's dumb.
Back to top
View user's profile Send private message
ParagChouguley

Active User


Joined: 03 Feb 2007
Posts: 175
Location: PUNE(INDIA)

PostPosted: Wed Jan 07, 2009 6:27 pm
Reply with quote

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
View user's profile Send private message
Terry Heinze

JCL Moderator


Joined: 14 Jul 2008
Posts: 1249
Location: Richfield, MN, USA

PostPosted: Wed Jan 07, 2009 9:37 pm
Reply with quote

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
View user's profile Send private message
ParagChouguley

Active User


Joined: 03 Feb 2007
Posts: 175
Location: PUNE(INDIA)

PostPosted: Fri Jan 09, 2009 4:37 pm
Reply with quote

Well....anyone?
Back to top
View user's profile Send private message
enrico-sorichetti

Superior Member


Joined: 14 Mar 2007
Posts: 10872
Location: italy

PostPosted: Fri Jan 09, 2009 4:50 pm
Reply with quote

Quote:
Well....anyone?


no pestering, please, people reply on their own time
Back to top
View user's profile Send private message
Robert Sample

Global Moderator


Joined: 06 Jun 2008
Posts: 8696
Location: Dubuque, Iowa, USA

PostPosted: Fri Jan 09, 2009 5:55 pm
Reply with quote

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
View user's profile Send private message
dick scherrer

Moderator Emeritus


Joined: 23 Nov 2006
Posts: 19244
Location: Inside the Matrix

PostPosted: Fri Jan 09, 2009 8:56 pm
Reply with quote

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
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> COBOL Programming

 


Similar Topics
Topic Forum Replies
No new posts Replace each space in cobol string wi... COBOL Programming 3
No new posts COBOL -Linkage Section-Case Sensitive COBOL Programming 1
No new posts COBOL ZOS Web Enablement Toolkit HTTP... COBOL Programming 0
No new posts Calling DFSORT from Cobol, using OUTF... DFSORT/ICETOOL 5
No new posts Generate random number from range of ... COBOL Programming 3
Search our Forums:

Back to Top