ASCII-Tabelle

Von Urs Rohner stammt das Programm zur Generierung einer ASCII-Tabelle.

ascii

REPORT zexp_ascii NO STANDARD PAGE HEADING.
**********************************************************
* Show ASCII Codes
*
*   This is freeware. Please read the terms of use.
*   Written by Urs Rohner, Rohner IT Consulting & Engineering
*
*   Contact Author: Urs Rohner
*
* comments
*  This is a classic report: show a list containing the ordinals
*  of all characters (actually the current SAP codepage will be shown).
*
**********************************************************

PARAMETERS:
_base      TYPE i DEFAULT 2,
_text(128) TYPE c LOWER CASE.

FIELD-SYMBOLS:
<c>, <x>.

DATA:
_b(8) TYPE c, “ bit pattern
_i    TYPE i, “ ordinal value
_c    TYPE c, “ character representation
_x    TYPE x. “ hexadecimal

* Main ( )
START-OF-SELECTION.
ASSIGN _c TO <c> TYPE ‚X‘.
ASSIGN _x TO <x> TYPE ‚X‘.
DO 256 TIMES.
<c> = <x> = _i = sy-index – 1.
PERFORM m_dec2base USING _i _base _b.
IF _text IS INITIAL OR _text CA _c.
WRITE: /  _i, 20 _b, 40 ‚%‘ NO-GAP, _x, 50 _c.
ENDIF.
ENDDO.

* Method: m_dec2base>
* Convert an interger to a string number with base _b
FORM m_dec2base USING
value(_n) TYPE i
value(_b) TYPE i
_s.

  FIELD-SYMBOLS:
<d>.       “ digit in _s
DATA:
d_ TYPE i,
p_ TYPE i,
q_ TYPE i,
r_ TYPE i, “ required length of _s
s_ TYPE c, “ sign of _n
t_ TYPE c, “ type of _s
l_ TYPE i. “ length of _s

  “ prepare sign
IF _n GE 0.
CLEAR s_.
ELSE.
_n = ABS( _n ).
s_ = ‚-‚.
ENDIF.

  “ check for requested base
IF _b GT 1.
“ check whether target string is okay
DESCRIBE FIELD _s TYPE t_ LENGTH l_ IN BYTE MODE.
IF t_ EQ ‚C‘.
“ calculate number of required digits r_
IF _n NE 0.
r_ = CEIL( LOG( _n + 1 ) / LOG( _b ) ).
ELSE.
r_ = 1.
ENDIF.
IF l_ GE r_.
DO r_ TIMES.
p_ = sy-index – 1.
q_ = _b ** ( r_ – sy-index ).
ASSIGN _s+p_(1) TO <d>.
d_ = _n DIV q_.
_n = _n – ( d_ * q_ ).
PERFORM m_dec2dig USING d_ <d>.
ENDDO.
ELSE.
CLEAR _s. “ length of _s is too short
ENDIF.
ELSE.
CLEAR _s. “ _s must be of character type
ENDIF.
ELSE.
CLEAR _s. “ _b must be at least 2
ENDIF.
ENDFORM.                                                    „m_dec2base

*&———————————————————————*
*&      Form  m_dec2dig
*&———————————————————————*
FORM m_dec2dig USING
value(_d) TYPE i
_i        TYPE c.

  CASE _d.
WHEN 0.  _i = ‚0‘.
WHEN 1.  _i = ‚1‘.
WHEN 2.  _i = ‚2‘.
WHEN 3.  _i = ‚3‘.
WHEN 4.  _i = ‚4‘.
WHEN 5.  _i = ‚5‘.
WHEN 6.  _i = ‚6‘.
WHEN 7.  _i = ‚7‘.
WHEN 8.  _i = ‚8‘.
WHEN 9.  _i = ‚9‘.
WHEN 10. _i = ‚A‘.
WHEN 11. _i = ‚B‘.
WHEN 12. _i = ‚C‘.
WHEN 13. _i = ‚D‘.
WHEN 14. _i = ‚E‘.
WHEN 15. _i = ‚F‘.
ENDCASE.
ENDFORM.                                                    „m_dec2dig

 

image_pdfimage_print
Enno Wulff
follow me
Letzte Artikel von Enno Wulff (Alle anzeigen)

Leave a Comment

Diese Website verwendet Akismet, um Spam zu reduzieren. Erfahre mehr darüber, wie deine Kommentardaten verarbeitet werden.