SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Create simple ASCII List



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1636

PostPosted: Mon Feb 25, 2008 1:04 pm    Post subject: Create simple ASCII List Reply with quote

Code:
report zexp_ascii no standard page heading.title
**********************************************************
* 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).
*
*
*
* history
*    Vers  Date                Own   Remark
*    ----  ------------------  ---   ----------------------------------
*    1.00   6th July     2000  rnr   Initial version
*    1.10  18th April    2001  rnr   Added xml tags, add selection text
*    1.20                      rnr   Changed for 4.6C compliance
*    1.21  30th May      2001  rnr   Added comments
*    1.30  11th June     2001  rnr   Binary representation
*
**********************************************************


  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_.
      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.

  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.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Programming Techniques | Приемы программирования All times are GMT + 4 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
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.