Advertisement
rplantiko

Determine Text Diff in ABAP

Dec 19th, 2012
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 3.27 KB | None | 0 0
  1. report  zz_test_get_delta line-size 320.
  2.  
  3. * Diff tool for texts,
  4. * using the function module of the ABAP version management
  5. * SVRS_COMPUTE_DELTA_REPS
  6. * Mode 2 ignores indentations
  7.  
  8. types:
  9.   ty_text type c length 300,
  10.   begin of ty_delta,
  11.     vrsflag type c length 4,
  12.     vrsnr type i,
  13.     line  type ty_text,
  14.   end of ty_delta,
  15.   ty_delta_tab type standard table of ty_delta,
  16.   begin of ty_wrapped_text,
  17.     line type ty_text,
  18.   end of ty_wrapped_text,
  19.   ty_wrapped_text_tab type standard table of ty_wrapped_text.
  20.  
  21. start-of-selection.
  22.   perform start.
  23.  
  24. * ---
  25. form start.
  26.  
  27.   data: lt_new type stringtab,
  28.         lt_old type stringtab,
  29.         lt_delta type ty_delta_tab.
  30.  
  31.   append :
  32.     'Abc' to lt_new,
  33.     'Def' to lt_new,
  34.     '    abc' to lt_old,
  35.     'Ghi' to lt_old,
  36.     'Jkl' to lt_old.
  37.  
  38.   perform edit_text using :
  39.     'New Version' changing lt_new,
  40.     'Old Version' changing lt_old.
  41.  
  42.   perform compare using lt_new lt_old
  43.                   changing lt_delta.
  44.  
  45.   perform output using lt_new lt_delta.
  46.  
  47. endform.                    "start
  48.  
  49.  
  50. *
  51. form output using it_new   type stringtab
  52.                   it_delta type ty_delta_tab.
  53.   data: ls_delta type ty_delta,
  54.         lv_new type ty_text.
  55.   loop at it_delta into ls_delta.
  56.     write: / ls_delta-vrsflag, 6 ls_delta-vrsnr, 20 ls_delta-line.
  57.     read table it_new into lv_new index ls_delta-vrsnr.
  58.     if sy-subrc eq 0.
  59.       write: /20 lv_new.
  60.     endif.
  61.   endloop.
  62. endform.                    "output
  63.  
  64.  
  65. * ---
  66. form compare using it_new type stringtab
  67.                    it_old type stringtab
  68.              changing et_delta type ty_delta_tab.
  69.  
  70.   data: lt_dummy1 type table of trdir,
  71.         lt_dummy2 type table of trdir,
  72.         lt_dummy3 type table of xtrdir,
  73.         lt_new type ty_wrapped_text_tab,
  74.         lt_old type ty_wrapped_text_tab.
  75.  
  76.   perform wrap_text :
  77.     using it_new changing lt_new,
  78.     using it_old changing lt_old.
  79.  
  80.   clear et_delta.
  81.   call function 'SVRS_COMPUTE_DELTA_REPS'
  82.     exporting
  83.       compare_mode            = 2
  84.       ignore_case_differences = 'X'
  85.     tables
  86.       texttab_old             = lt_old
  87.       texttab_new             = lt_new
  88.       trdirtab_old            = lt_dummy1  " Oblig. in interface
  89.       trdirtab_new            = lt_dummy2  " Oblig. in interface
  90.       trdir_delta             = lt_dummy3  " Oblig. in interface
  91.       text_delta              = et_delta.
  92.  
  93. endform.                    "compare
  94.  
  95. * ---
  96. form wrap_text using it_text type stringtab
  97.                changing et_text type ty_wrapped_text_tab.
  98.   data: lv_line type string,
  99.         ls_line type ty_wrapped_text.
  100.   clear et_text.
  101.   loop at it_text into lv_line.
  102.     ls_line-line = lv_line.
  103.     append ls_line to et_text.
  104.   endloop.
  105.  
  106. endform.                    "wrap_text
  107.  
  108. * ---
  109. form edit_text using iv_title
  110.                changing ct_text type stringtab.
  111.   call function 'TERM_CONTROL_EDIT'
  112.     exporting
  113.       titel          = iv_title
  114.     tables
  115.       textlines      = ct_text
  116.     exceptions
  117.       user_cancelled = 1
  118.       others         = 2.
  119.   if sy-subrc eq 1.
  120.     leave to screen 0.
  121.   elseif sy-subrc ne 0.
  122.     message id sy-msgid type 'A' number sy-msgno
  123.       with sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
  124.   endif.
  125. endform.                    "edit_text
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement