rplantiko

Display structure from bytes given in ABAP shortdump

Apr 2nd, 2015
749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 5.75 KB | None | 0 0
  1. *&---------------------------------------------------------------------*
  2. *& Report  ZZ_SHOW_DATA_FROM_DUMP
  3. *&---------------------------------------------------------------------*
  4. *& In ST22 short dumps, the first 510 bytes of a structure are shown in a
  5. *& four-rows format (in a UTF16 system).
  6. *& This reports tries to align to the data structure and to display the
  7. *& data via RS_COMPLEX_OBJECT_EDIT
  8. *& Just specify the type of the structure, and then paste the
  9. *& four data rows into the text editor field.
  10. *& Data references and deep structures as components have to be replaced
  11. *& by appropriate X fields.
  12. *& Worked in my case, but is probably not working in general.
  13. *& Reason: The substitution of references &c. by 10 raw bytes
  14. *& The number '10' may be something else in other circumstances
  15. *&---------------------------------------------------------------------*
  16.  
  17. report  zz_show_data_from_dump.
  18.  
  19. types: ty_dumpbin type x length 510.
  20.  
  21. parameters: p_type type tabname.
  22.  
  23. data: go_type type ref to cl_abap_structdescr.
  24.  
  25. at selection-screen on p_type.
  26.   perform get_datatype using p_type changing go_type.
  27.  
  28. start-of-selection.
  29.   perform start.
  30.  
  31. * ---
  32. form start.
  33.  
  34.   data: lv_raw  type ty_dumpbin,
  35.         ls_data type ref to data.
  36.  
  37.   perform get_raw_from_input changing lv_raw.
  38.  
  39.   perform get_filled_dataobject using go_type lv_raw
  40.                                 changing ls_data.
  41.  
  42.  
  43.   perform display_data using p_type ls_data.
  44.  
  45. endform.
  46.  
  47. *
  48.  
  49. * Enter 4*255 = 1020 hex digits
  50. * and place them into a 510 byte raw field
  51. * White space will be stripped away
  52. form get_raw_from_input changing cv_raw type ty_dumpbin.
  53.  
  54.   data: lt_rows type stringtab.
  55.  
  56.   call function 'TERM_CONTROL_EDIT'
  57.     exporting
  58.       titel          = 'Vier Zeilen a 255 HexDigits'
  59.     tables
  60.       textlines      = lt_rows
  61.     exceptions
  62.       user_cancelled = 1
  63.       others         = 2.
  64.  
  65.   perform build_dumpbin using lt_rows
  66.                         changing cv_raw.
  67.  
  68. endform.
  69.  
  70. * Splice the four rows, each of 255 hex digits, as given
  71. * in the dump, into a hex digit string,
  72. * and build the raw field from that
  73. form build_dumpbin using it_rows type stringtab
  74.                    changing cv_raw type ty_dumpbin.
  75.  
  76.   data: lv_row type string,
  77.         lv_input_total type string,
  78.         lv_digits type c length 1020,
  79.         lv_idx_source type i,
  80.         lv_idx_target type i,
  81.         lv_idx_row type i,
  82.         lv_idx_col type i.
  83.  
  84.   loop at it_rows into lv_row.
  85.     condense lv_row.
  86.     lv_input_total = lv_input_total && condense( lv_row ).
  87.   endloop.
  88.  
  89.   translate lv_input_total to upper case.
  90.  
  91.   if strlen( lv_input_total ) ne 1020.
  92.     message 'Try again: Enter 1020 non-blank characters!' type 'A'.
  93.   endif.
  94.  
  95.   if not matches( val = lv_input_total regex = '^[0-9A-F]{1020}$' ).
  96.     message 'Try again: Only hex digits allowed' type 'A'.
  97.   endif.
  98.  
  99.   do 1020 times.
  100.     lv_idx_source = sy-index - 1.
  101.     lv_idx_row = lv_idx_source div 255.
  102.     lv_idx_col = lv_idx_source mod 255.
  103.     lv_idx_target = 4 * lv_idx_col + lv_idx_row.
  104.     lv_digits+lv_idx_target(1) = lv_input_total+lv_idx_source(1).
  105.   enddo.
  106.  
  107.   cv_raw = lv_digits.
  108.  
  109.  
  110. endform.
  111.  
  112. * Given the type of the structure, create a data instance
  113. * and fill it with the hex data from IV_RAW
  114. form get_filled_dataobject using io_type type ref to cl_abap_structdescr
  115.                                  iv_raw  type ty_dumpbin
  116.                            changing value(es_data) type ref to data.
  117.  
  118.   field-symbols: <ls_data> type any,
  119.                  <lv_x>    type x.
  120.  
  121.   create data es_data type handle io_type.
  122.  
  123.   assign es_data->* to <ls_data>.
  124.  
  125.   assign <ls_data> to <lv_x> casting.
  126.  
  127.   <lv_x> = iv_raw.
  128.  
  129. endform.
  130.  
  131. * Display a structure
  132. * IV_TYPE = Name of the type (used for information only)
  133. form display_data using iv_type type c
  134.                         is_data type ref to data.
  135.  
  136.   field-symbols: <ls_data> type any.
  137.  
  138.   assign is_data->* to <ls_data>.
  139.  
  140.   call function 'RS_COMPLEX_OBJECT_EDIT'
  141.     exporting
  142.       object_name          = iv_type
  143.       mode                 = space
  144. *     INSERT_TAB           = ' '
  145. *     UPPER_CASE           = ' '
  146. *     POPUP                = ' '
  147. *     DISPLAY_ACCESSIBLE   = ' '
  148.     changing
  149.       object               = <ls_data>
  150.     exceptions
  151.       object_not_supported = 1
  152.       others               = 2.
  153.  
  154.   if sy-subrc <> 0.
  155.     message id sy-msgid type 'A' number sy-msgno
  156.       with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  157.   endif.
  158.  
  159.  
  160.  
  161. endform.
  162.  
  163. * Get data type for the target structure to map the bytes to
  164. * Replace components that may cause a problem by X fields of appropriate length
  165. form get_datatype using iv_type type tabname
  166.                   changing value(eo_type) type ref to cl_abap_structdescr.
  167.  
  168.  
  169.   data: lo_type_orig type ref to cl_abap_structdescr,
  170.         lo_type_abstract type ref to cl_abap_typedescr,
  171.         lt_comp    type cl_abap_structdescr=>component_table.
  172.  
  173.   field-symbols: <ls_comp>  like line of lt_comp.
  174.  
  175.   cl_abap_structdescr=>describe_by_name(
  176.     exporting p_name = iv_type
  177.     receiving p_descr_ref = lo_type_abstract
  178.     exceptions type_not_found = 1 ).
  179.   if sy-subrc ne 0.
  180.     sy-msgli = |Type { iv_type } not found|.
  181.     message sy-msgli type 'E'.
  182.   endif.
  183.  
  184.   lo_type_orig ?= lo_type_abstract.
  185.  
  186.   lt_comp = lo_type_orig->get_components( ).
  187.  
  188. * Replace references by 10-byte raw components
  189.   loop at lt_comp assigning <ls_comp> where type->type_kind ca 'gmvhr'.
  190. * Set length to 10 (why? a reference has only 8 bytes)
  191.     <ls_comp>-type   = cl_abap_elemdescr=>get_x( 10 ).
  192.   endloop.
  193.   if sy-subrc eq 0.
  194.     eo_type = cl_abap_structdescr=>get( lt_comp ).
  195.   else.
  196. * If structure doesn't contain deep components or references, the original type is OK
  197.     eo_type = lo_type_orig.
  198.   endif.
  199.  
  200. endform.
Add Comment
Please, Sign In to add comment