Advertisement
Guest User

Code Morse

a guest
Oct 18th, 2019
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 2.05 KB | None | 0 0
  1. report zdev_test.
  2.  
  3. class zrun_decoding definition.
  4.   public section.
  5.     types: begin of zty_tcod,
  6.              caracter type c length 1,
  7.              cod      type c length 4,
  8.            end of zty_tcod,
  9.            begin of zty_cod,
  10.              cod type c length 4,
  11.            end of zty_cod,
  12.            begin of zty_char,
  13.              cod type c length 1,
  14.            end of zty_char.
  15.     class-data: ztty_cod type table of zty_tcod.
  16.     class-data: zsty_cod type zty_tcod.
  17.     class-methods append_tdecoding
  18.       importing
  19.         im_cod type string.
  20.  
  21.     class-methods mcoding
  22.       changing
  23.         cg_string type string .
  24.  
  25.   private section.
  26.  
  27. endclass.
  28.  
  29.  
  30. class zrun_decoding implementation.
  31.  
  32.   method append_tdecoding.
  33.  
  34.     data: lt_cod    type table of zty_cod,
  35.           lv_return type string,
  36.           lv_count  type i.
  37.  
  38.     split im_cod at space into table lt_cod.
  39.     lv_count = 0.
  40.  
  41.     loop at lt_cod assigning field-symbol(<fs_txt>).
  42.       clear:zsty_cod.
  43.       zsty_cod-caracter = sy-abcde+lv_count(1).
  44.       zsty_cod-cod = <fs_txt>.
  45.       append zsty_cod to ztty_cod.
  46.       lv_count = lv_count + 1.
  47.     endloop.
  48.  
  49.   endmethod.
  50.  
  51.   method mcoding.
  52.  
  53.     data lv_return type string.
  54.     data lv_count type i.
  55.  
  56.  
  57.     data(lv_strlen) = strlen( cg_string ).
  58.  
  59.     lv_count = 0.
  60.  
  61.     do.
  62.  
  63.       if lv_count = lv_strlen.
  64.         exit.
  65.       endif.
  66.  
  67.       read table ztty_cod with key caracter = cg_string+lv_count(1) into zsty_cod.
  68.       if sy-subrc = 0.
  69.         lv_return = lv_return && zsty_cod-cod.
  70.       endif.
  71.  
  72.       lv_count = lv_count + 1.
  73.  
  74.     enddo.
  75.  
  76.     cg_string = lv_return.
  77.  
  78.   endmethod.
  79. endclass.
  80.  
  81. data: zcl_run type ref to zrun_decoding.
  82.  
  83. parameters: p_text type string.
  84.  
  85. start-of-selection.
  86.  
  87.   data: lv_txt type string.
  88.  
  89.   lv_txt = p_text.
  90.   zcl_run = new zrun_decoding(  ).
  91.  
  92.   zcl_run->append_tdecoding( '.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --..' ).
  93.   zcl_run->mcoding( changing cg_string = lv_txt ).
  94.  
  95.   write lv_txt.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement