SHARE
TWEET

Untitled

a guest Oct 25th, 2019 132 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. CLASS zgs_fi201711_scrabblecalc DEFINITION
  2.   PUBLIC
  3.   FINAL
  4.   CREATE PUBLIC .
  5.  
  6.   PUBLIC SECTION.
  7.  
  8.     METHODS setlanguage
  9.       IMPORTING
  10.         !im_language TYPE string .
  11.     METHODS calculate
  12.       IMPORTING
  13.         !im_word        TYPE string
  14.       RETURNING
  15.         VALUE(rv_score) TYPE i .
  16.   PROTECTED SECTION.
  17.   PRIVATE SECTION.
  18.  
  19.     DATA wa_lettervalues TYPE zgs_11_letter_de .
  20.     DATA language TYPE string .
  21.  
  22.     METHODS lettervalue
  23.       IMPORTING
  24.         !im_letter      TYPE c
  25.       RETURNING
  26.         VALUE(rv_score) TYPE i .
  27. ENDCLASS.
  28.  
  29.  
  30.  
  31. CLASS ZGS_FI201711_SCRABBLECALC IMPLEMENTATION.
  32.  
  33.  
  34. * <SIGNATURE>---------------------------------------------------------------------------------------+
  35. * | Instance Public Method ZGS_FI201711_SCRABBLECALC->CALCULATE
  36. * +-------------------------------------------------------------------------------------------------+
  37. * | [--->] IM_WORD                        TYPE        STRING
  38. * | [<-()] RV_SCORE                       TYPE        I
  39. * +--------------------------------------------------------------------------------------</SIGNATURE>
  40.   METHOD calculate.
  41.  
  42.     DATA: index  TYPE i,
  43.           length TYPE i,
  44.           char   TYPE c.
  45.  
  46.  
  47.     length = strlen( im_word ).
  48.     rv_score = 0.
  49.  
  50.     WHILE index < length.
  51.       char = im_word+index(1). "no idea what's happening here, but char iterates through the letters of im_word
  52.  
  53.       rv_score = rv_score + lettervalue( im_letter = char ).
  54.  
  55.       ADD 1 TO index.
  56.     ENDWHILE.
  57.  
  58.  
  59.   ENDMETHOD.
  60.  
  61.  
  62. * <SIGNATURE>---------------------------------------------------------------------------------------+
  63. * | Instance Private Method ZGS_FI201711_SCRABBLECALC->LETTERVALUE
  64. * +-------------------------------------------------------------------------------------------------+
  65. * | [--->] IM_LETTER                      TYPE        C
  66. * | [<-()] RV_SCORE                       TYPE        I
  67. * +--------------------------------------------------------------------------------------</SIGNATURE>
  68.   METHOD lettervalue.
  69.  
  70.     DATA: letter    TYPE c,
  71.           tablename TYPE string.
  72.  
  73.     letter = im_letter.
  74.     TRANSLATE letter TO UPPER CASE.
  75.     tablename = 'zgs_11_letter_' && language.
  76.  
  77.     SELECT *
  78.     FROM (tablename) AS l
  79.     WHERE l~letter = @letter
  80.     INTO CORRESPONDING FIELDS of @wa_lettervalues.
  81.     ENDSELECT.
  82.  
  83.     rv_score = wa_lettervalues-value.
  84.  
  85.   ENDMETHOD.
  86.  
  87.  
  88. * <SIGNATURE>---------------------------------------------------------------------------------------+
  89. * | Instance Public Method ZGS_FI201711_SCRABBLECALC->SETLANGUAGE
  90. * +-------------------------------------------------------------------------------------------------+
  91. * | [--->] IM_LANGUAGE                    TYPE        STRING
  92. * +--------------------------------------------------------------------------------------</SIGNATURE>
  93.   METHOD setlanguage.
  94.     IF ( im_language = 'en' OR im_language = 'de' ).
  95.       language = im_language.
  96.     ELSE.
  97.       WRITE `Language ` && im_language && ' is not supported. Defaulting to en.'.
  98.       language = 'en'.
  99.     ENDIF.
  100.   ENDMETHOD.
  101. ENDCLASS.
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top