Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 1.88 KB | None | 0 0
  1. report zdev_test.
  2.  
  3.  
  4. class zrun_decoding definition.
  5.   public section.
  6.     types: begin of zty_cod,
  7.              caracter type c length 1,
  8.              cod      type c length 4,
  9.            end of zty_cod,
  10.            begin of zty_txt,
  11.              cod type c length 4,
  12.            end of zty_txt.
  13.     class-data: ztty_cod type table of zty_cod.
  14.     class-data: zsty_cod type zty_cod.
  15.     class-methods append_tdecoding
  16.       importing
  17.         im_caracter type char1
  18.         im_cod      type char4.
  19.  
  20.     class-methods mdecoding
  21.       changing
  22.         cg_string type string .
  23.  
  24.   private section.
  25.  
  26. endclass.
  27.  
  28.  
  29. class zrun_decoding implementation.
  30.  
  31.   method append_tdecoding.
  32.     clear:zsty_cod.
  33.     zsty_cod-caracter = im_caracter.
  34.     zsty_cod-cod = im_cod.
  35.     append zsty_cod to ztty_cod.
  36.   endmethod.
  37.  
  38.   method mdecoding.
  39.  
  40.     data: lt_txt    type table of zty_txt,
  41.           lv_return type string.
  42.  
  43.     split cg_string at space into table lt_txt.
  44.  
  45.     loop at lt_txt assigning field-symbol(<fs_txt>).
  46.  
  47.       read table ztty_cod with key cod = <fs_txt>-cod into zsty_cod.
  48.       if sy-subrc = 0.
  49.         lv_return = lv_return && zsty_cod-caracter.
  50.       endif.
  51.     endloop.
  52.  
  53.     cg_string = lv_return.
  54.  
  55.   endmethod.
  56. endclass.
  57.  
  58. data: zcl_run type ref to zrun_decoding.
  59.  
  60. start-of-selection.
  61.  
  62.   data: lv_text type string.
  63.  
  64.   "Test case1
  65.   lv_text = '.- -... -.-. -.. .'.
  66.   zcl_run = new zrun_decoding(  ).
  67.  
  68.   zcl_run->append_tdecoding( exporting im_caracter = 'A' im_cod = '.-' ).
  69.   zcl_run->append_tdecoding( exporting im_caracter = 'B' im_cod = '-...' ).
  70.   zcl_run->append_tdecoding( exporting im_caracter = 'C' im_cod = '-.-.' ).
  71.   zcl_run->append_tdecoding( exporting im_caracter = 'D' im_cod = '-..' ).
  72.   zcl_run->append_tdecoding( exporting im_caracter = 'E' im_cod = '.' ).
  73.  
  74.   zcl_run->mdecoding( changing cg_string = lv_text ).
  75.  
  76.   write lv_text.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement