Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

How to edit a nibble in COBOL?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
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    Post subject: How to edit a nibble in COBOL?
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: 1439
Location: Bangalore,India

PostPosted: Thu Dec 27, 2007 6:24 pm    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
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    Post subject:
Reply with quote

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

Global Moderator


Joined: 14 Mar 2007
Posts: 10234
Location: italy

PostPosted: Fri Jan 09, 2009 4:50 pm    Post subject: Reply to: How to edit a nibble in COBOL?
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: 8004
Location: Bellevue, IA

PostPosted: Fri Jan 09, 2009 5:55 pm    Post subject:
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

Site Director


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

PostPosted: Fri Jan 09, 2009 8:56 pm    Post subject:
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    IBMMAINFRAMES.com Support Forums -> COBOL Programming All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts RULES(NOEVENPACK) in cobol jackzhang75 COBOL Programming 5 Wed Mar 29, 2017 12:47 am
No new posts Mass comment and edit elixir1986 IBM Tools 3 Thu Mar 02, 2017 10:09 pm
No new posts SQL query not working in Cobol program. CuriousMainframer COBOL Programming 14 Wed Feb 22, 2017 5:56 pm
No new posts Execute TSO ACF commands from COBOL-I... supreethi.srid TSO/ISPF 0 Tue Feb 21, 2017 5:19 pm
No new posts Mainframe Interview Questions CICS,CO... akshathan Mainframe Interview Questions 6 Thu Feb 09, 2017 6:38 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us