Registration

Dear SAP Community Member,
In order to fully benefit from what the SAP Community has to offer, please register at:
http://scn.sap.com
Thank you,
The SAP Community team.
Skip to end of metadata
Go to start of metadata

This program asks you to choose a file (on your frontend computer only) and displays the file in hexadecimal, by lines of 8 bytes, for example:

5B00530079007300
740065006D005D00
0D000A004E006100
6D0065003D004500
440036000D000A00
4400650073006300
7200690070007400
69006F006E003D00
0D000A0043006C00
...

Note: there is a variant of this program which allows editing the file in hexadecimal.

Here is the file hex viewer, you just have to copy it, activate and run:

REPORT z_file_hex_viewer.

DATA go_textedit TYPE REF TO cl_gui_textedit.

PARAMETER: dummy(1).

AT SELECTION-SCREEN OUTPUT.
  PERFORM s1000_pbo.

AT SELECTION-SCREEN.
  PERFORM s1000_pai.

*&---------------------------------------------------------------------*
*&      Form  S1000_PBO
*&---------------------------------------------------------------------*
FORM s1000_pbo.
  IF go_textedit IS INITIAL.
    DATA lt_filetable    TYPE filetable.
    DATA ls_filetable    TYPE LINE OF filetable.
    DATA l_rc           TYPE i.
    DATA l_action       TYPE i.
    CALL METHOD cl_gui_frontend_services=>file_open_dialog
      CHANGING
        file_table              = lt_filetable
        rc                      = l_rc
        user_action             = l_action
      EXCEPTIONS
        file_open_dialog_failed = 1
        cntl_error              = 2
        error_no_gui            = 3
        not_supported_by_gui    = 4
        OTHERS                  = 5.
    IF sy-subrc NE 0.
* error
      LEAVE PROGRAM.
    ELSEIF l_action NE cl_gui_frontend_services=>action_ok.
* Cancelled
      LEAVE PROGRAM.
    ELSE.
      READ TABLE lt_filetable INDEX 1 INTO ls_filetable.
      ASSERT sy-subrc = 0.
      DATA l_xstring TYPE xstring.
      DATA l_string TYPE string.
      DATA lt_textedit TYPE abaptxt255_tab.
      PERFORM read_bin_file USING ls_filetable-filename CHANGING l_xstring.
* Convert binary into hexa string (becomes string like "00FF...")
      l_string = l_xstring.
      CALL FUNCTION 'SWA_STRING_TO_TABLE'
        EXPORTING
          character_string = l_string
        IMPORTING
          character_table  = lt_textedit[].
      CREATE OBJECT go_textedit
        EXPORTING
          parent = cl_gui_container=>screen0.
      CALL METHOD go_textedit->set_wordwrap_behavior
        EXPORTING
          wordwrap_mode     = cl_gui_textedit=>wordwrap_at_fixed_position
          wordwrap_position = 16.
      CALL METHOD go_textedit->set_text_as_stream
        EXPORTING
          text = lt_textedit.
      CALL METHOD go_textedit->set_readonly_mode
        EXPORTING
          readonly_mode	= 1.
    ENDIF.
  ENDIF.
  SET TITLEBAR 'TIT' OF PROGRAM 'SAPLDSYP' WITH 'File Hex Viewer'(001).
ENDFORM.                                                    "s1000_pbo

*&---------------------------------------------------------------------*
*&      Form  S1000_PAI
*&---------------------------------------------------------------------*
FORM s1000_pai.
* keep from going to START-OF-SELECTION event (it would restart the
* program and global variables would be reset = DATA LOSS)
  MESSAGE e001(00) WITH 'Execute button deactivated'(001).
ENDFORM.                                                    "s1000_pai

*&---------------------------------------------------------------------*
*&      Form  read_bin_file
*&---------------------------------------------------------------------*
FORM read_bin_file
      USING i_filename TYPE clike
      CHANGING e_file_xstring TYPE xstring.
  DATA l_filename TYPE string.
  DATA l_length TYPE i.
  DATA lt_x255 TYPE TABLE OF x255.
  l_filename = i_filename.
  CALL METHOD cl_gui_frontend_services=>gui_upload
    EXPORTING
      filename   = l_filename
      filetype   = 'BIN'
    IMPORTING
      filelength = l_length
    CHANGING
      data_tab   = lt_x255
    EXCEPTIONS
      OTHERS     = 1.
  IF sy-subrc = 0.
    CALL METHOD cl_swf_utl_convert_xstring=>table_to_xstring
      EXPORTING
        i_table  = lt_x255
        i_size   = l_length
      RECEIVING
        r_stream = e_file_xstring
      EXCEPTIONS
        OTHERS   = 3.
  ENDIF.
ENDFORM.                    "read_bin_file
  • No labels