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

Shift Half word (Nibble) from Binary data


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

New User


Joined: 02 Mar 2012
Posts: 48
Location: India

PostPosted: Wed Oct 17, 2012 8:31 pm
Reply with quote

Hi, I have a Incoming message with compressed data (binary format), as below,
Hex format: x'005705D121022250'.
If its the Tag 0057 (two bytes) is found, the next byte is the length (here it is 05), then i need to populate next 5 bytes to a common variable (x'D121022250').

The Problem is the half byte 'D' is a junk data that should not be moved to common variable, the data movement should be as x'1210222500' (adding 0 as the last nibble since D was removed).

Could someone can help me out,?
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Wed Oct 17, 2012 8:46 pm
Reply with quote

Multiply by 16 will shift left a half-nybble. Use COMP-5 and no sign. Big COMP-5. Put your value in the low-order five bytes (via REDEFINES) and multiply. Move it back out. Your "D" will evaporate at the left and zero appear as if by magic at the right.
Back to top
View user's profile Send private message
dudenithy

New User


Joined: 02 Mar 2012
Posts: 48
Location: India

PostPosted: Thu Oct 18, 2012 2:26 am
Reply with quote

Hi Bill, Thanks for your thoughts, But could you please explain further (pseudo code), Your suggestion is really appreciated but it ll be great if u explain with example,,
Back to top
View user's profile Send private message
Bill Woodger

Moderator Emeritus


Joined: 09 Mar 2011
Posts: 7309
Location: Inside the Matrix

PostPosted: Thu Oct 18, 2012 3:18 am
Reply with quote

You have five bytes of binary data. In Cobol, you can't define five bytes. as you get given a minimum size (which you could descibe as "twice times the 'boundary' already exceeded, or two bytes, whichever is bigger'.

So, you need eight bytes. So you define a binary item which is eight bytes long - you have to choose the correct number of 9s, or at least enough to make it eight bytes long and best to have at least as many 9s you need to represent the maximum value in your five-byte field.

Don't make the field signed. It won't matter in this case, but if you unthinkingly copy the code for something similar, it might matter.

Make the field COMP-5. Again, it won't matter in this case, but the same advice.

Now redefine that as a FILLER of 3 and a named-field of 5.

Put your five-byte value into the five bytes of the redefinition.

Now multiply the COMP-5 by 16, putting the result in the same COMP-5.

Why 16? If it is base-10, and you have a number 9876, and you multiply by 10, you get 8760, the effect you want. 'Binary' is, for us humans, in base-16. So multiply by 16.

Now you can move the five-byte field to your final destination.

There are other ways, but this is straightforward. Give everything nice clear names, relevant to the task, And document it, both inside and outside the program.

EDIT: In the cold light of day, I noticed I left this out:

Put your five-byte value into the five bytes of the redefinition.

I have added it in the appropriate place.
Back to top
View user's profile Send private message
dudenithy

New User


Joined: 02 Mar 2012
Posts: 48
Location: India

PostPosted: Thu Oct 18, 2012 12:00 pm
Reply with quote

Thanks Bill for your well explained suggestion. Will try this out icon_smile.gif
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 How to save SYSLOG as text data via P... All Other Mainframe Topics 3
No new posts Store the data for fixed length COBOL Programming 1
No new posts PARSE Syntax for not fix length word ... JCL & VSAM 7
No new posts Search two or more word with FILEAID Compuware & Other Tools 15
No new posts Data set Rec-Cnt and Byte-Cnt Testing & Performance 2
Search our Forums:

Back to Top