Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Convert Hexa to Bin

I want to convert an Hexa to Binary

Exemple : the filed KCUMUL has hexa value

KUMUL = 8000008000000u2026.

This 8000008u2026. Has the Binary equivalent 1000000000000000000000001000u2026.

Is there a function or class ?

Thanks in advance for any hep

Soufiene

Former Member
Former Member replied

Hi Soufiene,

Sandra is right, just in case you still haven't got it done or haven't cracked it below is a simple piece of code for the same.

DATA: l_data    TYPE kumul,
      l_dat     TYPE string,
      l_bin     TYPE string,
      l_temp    TYPE char4,
      l_hexchar TYPE c,
      l_offset  TYPE i,
      l_len     TYPE i.

SELECT SINGLE kumul
  FROM t512b
  INTO l_data
 WHERE applikation EQ 'C'
   AND verskey EQ 999
  AND molga EQ '02'
  AND lgart EQ '/388'.

IF sy-subrc EQ 0.
  l_dat = l_data.
  l_len = STRLEN( l_dat ).
  WHILE l_len GT 0.
    l_hexchar = l_dat+l_offset(1).
    l_len = l_len - 1.
    l_offset = l_offset + 1.
    CASE l_hexchar.
      WHEN '0'.
        l_temp = '0000'.
      WHEN '1'.
        l_temp = '0001'.
      WHEN '2'.
        l_temp = '0010'.
      WHEN '3'.
        l_temp = '0011'.
      WHEN '4'.
        l_temp = '0100'.
      WHEN '5'.
        l_temp = '0101'.
      WHEN '6'.
        l_temp = '0110'.
      WHEN '7'.
        l_temp = '0111'.
      WHEN '8'.
        l_temp = '1000'.
      WHEN '9'.
        l_temp = '1001'.
      WHEN 'A'.
        l_temp = '1010'.
      WHEN 'B'.
        l_temp = '1011'.
      WHEN 'C'.
        l_temp = '1100'.
      WHEN 'D'.
        l_temp = '1101'.
      WHEN 'E'.
        l_temp = '1110'.
      WHEN 'F'.
        l_temp = '1111'.
      WHEN OTHERS.
    ENDCASE.
    CONCATENATE l_bin l_temp INTO l_bin.
  ENDWHILE.
ENDIF.

WRITE l_bin.

Regards,

Chen

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question