Portal | Manuals | References | Downloads | Info | Programs | JCLs | Mainframe wiki | Quick Ref
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Profile Log in to check your private messages Log in
 
How to store 2 digit numeric data in a single byte?

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> COBOL Programming
View previous topic :: :: View next topic  
Author Message
cnugemini

New User


Joined: 11 Jun 2014
Posts: 1
Location: india

PostPosted: Thu Jun 26, 2014 8:02 pm    Post subject: How to store 2 digit numeric data in a single byte?
Reply with quote

Hi all,

Could you please help me in knowing how we can store a 2 digit numeric value in a single byte space. I want to know the Picture clause that we use to achieve this. I have only 1 byte of space left in my IMS data base, but I have to store a new 2 digit numeric value in it.

I tried googling and searching many forums, may be I wasn't efficient at it.

Thank you,
Srinivas
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Thu Jun 26, 2014 8:28 pm    Post subject: Reply to: How to store 2 digit numeric data in a single byte
Reply with quote

Code:
01  a-nice-name COMP-3 PIC 99V9.
01  FILLER REDEFINES a-nice-name.
    05  another-nice-name PIC X.
    05  FILLER PIC X.

MOVE your-two-digit-field TO a-nice-name
MOVE another-nice-name TO your-one-byte


To get it back again, just do the reverse.

Say you have 12. It appears in a-nice-name after the first MOVE as X'120F'. The REDEFINES allows another-nice-name to contain X'12', which is the value you want.
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: Thu Jun 26, 2014 11:01 pm    Post subject:
Reply with quote

Very clever, Bill. I hope I never have to resort to the days when 8 switches had to be stored in 1 byte though! Back then, we had to rely on Assembler routines to perform our BIT2BYTE and BYTE2BIT functions.
Back to top
View user's profile Send private message
Akatsukami

Global Moderator


Joined: 03 Oct 2009
Posts: 1775
Location: Bloomington, IL

PostPosted: Thu Jun 26, 2014 11:50 pm    Post subject:
Reply with quote

These days one could do it in PL/I or C, possibly in COBOL itself (I'm not up on the latest bells and whistles).
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7315

PostPosted: Fri Jun 27, 2014 4:10 pm    Post subject: Reply to: How to store 2 digit numeric data in a single byte
Reply with quote

Byte to bit "string".

Code:
WORKING-STORAGE:
01  HERES-OUR-VALUE-FOR-BITS BINARY PIC 9(4) VALUE ZERO.
01  FILLER REDEFINES HERES-OUR-VALUE-FOR-BITS.
    05 FILLER PIC X.
    05 BYTE-TO-CONVERT PIC X.
01 BIT-TABLE.
    05 FILLER PIC X(56) VALUE
    '00000000000000010000001000000011000001000000010100000110'.
    05 FILLER PIC X(56) VALUE
    '00000111000010000000100100001010000010110000110000001101'.
....
05 FILLER PIC X(32) VALUE
'11111100111111011111111011111111'.
01  FILLER REDEFINES BIT-TABLE.
    05 FILLER OCCURS 256 TIMES.
        10 BIT-VALUE PIC X(8).
...
    MOVE source- byte TO BYTE-TO-CONVERT
    DISPLAY "PARM>" CHAR "<BITS>"
            BIT-VALUE ( HERES-OUR-VALUE-FOR-BITS + 1 ) "<"
    GOBACK
    .


Bit string to byte:

Code:
01  HERES-OUR-VALUE-FOR-BITS BINARY PIC 9(4) VALUE ZERO.
01  FILLER REDEFINES HERES-OUR-VALUE-FOR-BITS.
    05  FILLER PIC X.
    05  BACK-AS-A-BYTE PIC X.
01  BIT-STRING.
    05  BITS.
        10  FILLER PIC X.
            88  BIT08-ON VALUE "1".
        10  FILLER PIC X.
            88  BIT07-ON VALUE "1".
        10  FILLER PIC X.
            88  BIT06-ON VALUE "1".
        10  FILLER PIC X.
            88  BIT05-ON VALUE "1".
        10  FILLER PIC X.
            88  BIT04-ON VALUE "1".
        10  FILLER PIC X.
            88  BIT03-ON VALUE "1".
        10  FILLER PIC X.
            88  BIT02-ON VALUE "1".
        10  FILLER PIC X.
            88  BIT01-ON VALUE "1".
PROCEDURE DIVISION USING PARM-IN.
    MOVE ZERO TO HERES-OUR-VALUE-FOR-BITS
    MOVE source-string TO BIT-STRING
    IF BIT08-ON
        ADD 128 TO HERES-OUR-VALUE-FOR-BITS
    END-IF
    IF BIT07-ON
        ADD 64 TO HERES-OUR-VALUE-FOR-BITS
    END-IF
    IF BIT06-ON
        ADD 32 TO HERES-OUR-VALUE-FOR-BITS
    END-IF
    IF BIT05-ON
        ADD 16 TO HERES-OUR-VALUE-FOR-BITS
    END-IF
    IF BIT04-ON
        ADD 8 TO HERES-OUR-VALUE-FOR-BITS
    END-IF
    IF BIT03-ON
        ADD 4 TO HERES-OUR-VALUE-FOR-BITS
    END-IF
    IF BIT02-ON
        ADD 2 TO HERES-OUR-VALUE-FOR-BITS
    END-IF
    IF BIT01-ON
        ADD 1 TO HERES-OUR-VALUE-FOR-BITS
    END-IF
    DISPLAY "BIT STRING>" BITS "<BYTE>" BACK-AS-A-BYTE "<"
    GOBACK
    .


Data-names for explanation only (use better ones in for-real code).

Works from COBOL Day One. First conversion is heavy on storage (people may giggle at that, but when I started we had a maximum of 1MB for the WORKING-STORAGE). Can be replaced by loops of various activities if short of WORKING-STORAGE.
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 More than 1 Include criteria for sing... Roy Ware SYNCSORT 6 Wed Sep 13, 2017 11:45 pm
No new posts Remove leading spaces from numeric field rexx77 SYNCSORT 6 Wed Sep 06, 2017 2:15 am
No new posts Return a Non Numeric value from REXX Learncoholic CLIST & REXX 3 Fri Sep 01, 2017 8:33 pm
No new posts Question related to Data dictionary f... rexx77 SYNCSORT 3 Thu Aug 31, 2017 7:23 am
No new posts Extract Data till prev hour balaji81_k DB2 16 Fri Aug 25, 2017 9:25 pm

Facebook
Back to Top
 
Job Vacancies | Forum Rules | Bookmarks | Subscriptions | FAQ | Polls | Contact Us