MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Displaying binary data as "readable" such

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database
View previous topic :: View next topic  
Author Message
misi01
Advanced


Joined: 02 Dec 2002
Posts: 620
Topics: 173
Location: Stockholm, Sweden

PostPosted: Thu May 16, 2024 5:04 am    Post subject: Displaying binary data as "readable" such Reply with quote

I'm selecting data from a DB2 table that contains 2 binary fields. These fields (in reality) contain the equivalent of a DL/1 segment, so they can easily contain a mixture of character and COMP-3 fields.
The following is the actual select statement I'm using
Code:

SELECT T6H0.PNR
     ,hex(SUBSTR(T6H0.DL1_SEGMENT1,01,2)) AS GENNR
     ,T6H0.NAMN 
     ,T6H0.ADR
     ,T6H0.POSTNR
     ,T6H0.ORT
     ,T6H0.NAMNKOD                   
     ,hex(SUBSTR(T6H0.DL1_SEGMENT2,01,1))  AS ROLL                         
     ,hex(SUBSTR(T6H0.DL1_SEGMENT2,02,5)) AS DFLDAT                       
     ,hex(SUBSTR(T6H0.DL1_SEGMENT2,07,1)) AS KUNDKOD1                     
     ,hex(SUBSTR(T6H0.DL1_SEGMENT2,08,1)) AS KUNDKOD2                     
     ,hex(SUBSTR(T6H0.DL1_SEGMENT2,09,1)) AS KUADRKOD                     
     ,hex(SUBSTR(T6H0.DL1_SEGMENT2,10,5)) AS ANSVDC                       
     ,hex(SUBSTR(T6H0.DL1_SEGMENT2,15,1)) AS DCRESERV1                     
     ,hex(SUBSTR(T6H0.DL1_SEGMENT2,16,5)) AS TRANSDAT
     ,objektid                as OBJEKTID
     ,objektbort    as OBJBORT         
     FROM TDRT6H0      T6H0
     inner join  TDRT6g0      T6g0
     on T6H0.CCK_PNR = T6g0.CCK_PNR
     WHERE T6H0.CCK_PNR = 96611168177
     ORDER BY T6H0.EXTRACT_ORDER ASC


and these are the results

Quote:

0
0005
SIMPSON, MICHAEL
Any st 110
38276
MALERAS
10
40
000000000C
40
40
D6
4040404040
40
020200403C
6158902711100


What I would like to do would be to show the EBCDIC characters as ASCII (?), ie, show a 40 as a "space" and the D6 results as the letter O (as in Oscar).
In addition, it would be nice to show the 020200403C character as the decimal it really is.

I'm assuming I need SOMETHING like CAST or similar, but whatever I try doing doesn't result in what I'm after.

Thanks you.
_________________
Michael
Back to top
View user's profile Send private message Send e-mail
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12368
Topics: 75
Location: San Jose

PostPosted: Thu May 16, 2024 2:52 pm    Post subject: Reply with quote

misi01,

misi01 wrote:

What I would like to do would be to show the EBCDIC characters as ASCII (?), ie, show a 40 as a "space" and the D6 results as the letter O (as in Oscar).


It is not ASCII. X'40' is space in EBCDIC and in ASCII it is X'20'.

You can display X'40' as space if you follow the procedure list here (3rd solution)
https://mvsforums.com/helpboards/viewtopic.php?p=11074#11074

Once you convert aka Unhex the value then you can use the scalar function EBCDIC_CHR to display as space.

X'40' = decimal 64 and X'D6' = 214

Now you can use
Code:

SELECT EBCDIC_CHR(64)   
      ,EBCDIC_CHR(214)   
  FROM SYSIBM.SYSDUMMY1 
  ;                     


Which will show you SPACE and O as output


misi01 wrote:

In addition, it would be nice to show the 020200403C character as the decimal it really is.


If the number is always a packed decimal number then you can use this
Code:

SELECT CASE SUBSTR('020200403C',10,1)                   
              WHEN 'C' THEN '+'                         
              WHEN 'D' THEN '-'                         
               END                              ||     
        DIGITS(INT(SUBSTR('020200403C',1,9)))           
  FROM SYSIBM.SYSDUMMY1                                 
  ;

_________________
Kolusu - DFSORT Development Team (IBM)
DFSORT is on the Web at:
www.ibm.com/storage/dfsort

www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Database All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group