NAVAPAT_T

ABAP : find first tree rank

Aug 9th, 2017
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ABAP 3.87 KB | None | 0 0
  1. REPORT ZPAT_RANK.
  2. DATA : BEGIN OF pat,      "1
  3.       name(10) VALUE 'pat',
  4.       score TYPE i,
  5.   END OF pat.
  6.  
  7. DATA : BEGIN OF fern,     "2
  8.       name(10) VALUE 'fern',
  9.       score    type i,
  10.       END OF fern.
  11.  
  12. DATA : BEGIN OF fah,      "3
  13.       name(10) VALUE 'fah',
  14.       score    TYPE i,
  15.       END OF fah.
  16.  
  17. DATA : BEGIN OF peet,     "4
  18.       name(10) VALUE 'peet',
  19.       score    TYPE i,
  20.       END OF peet.
  21.  
  22. DATA : begin of sai,      "5
  23.       name(10)  VALUE 'sai',
  24.       score TYPE i,
  25.       END OF sai.
  26.  
  27. DATA : BEGIN OF eve,      "6
  28.       name(10)  VALUE 'eve',
  29.       score TYPE i,
  30.       END OF eve.
  31.  
  32. DATA : BEGIN OF nut,      "7
  33.       name(10)  VALUE 'nut',
  34.       score     TYPE i,
  35.       END OF nut.
  36.  
  37. DATA : BEGIN OF peter,    "8
  38.       name(10)  VALUE 'peter',
  39.       score     TYPE i,
  40.       end of peter.
  41.  
  42. DATA result like QF00-RAN_INT.
  43.  
  44. *-------------------------------------------------------
  45. do.
  46.   IF  ( pat-score >= 100 )    or
  47.       ( fern-score >= 100 )   or
  48.       ( fah-score >= 100 )    or
  49.       ( peet-score >= 100 )   or
  50.       ( sai-score >= 100 )    or
  51.       ( eve-score >= 100 )    or
  52.       ( nut-score >= 100 )    or
  53.       ( peter-score >= 100 )  .
  54.       exit.
  55.   ENDIF.
  56. CALL FUNCTION 'QF05_RANDOM_INTEGER'
  57.  EXPORTING
  58.    RAN_INT_MAX         = 8
  59.    RAN_INT_MIN         = 1
  60.  IMPORTING
  61.    RAN_INT             = result
  62.  EXCEPTIONS
  63.    INVALID_INPUT       = 1
  64.    OTHERS              = 2
  65.           .
  66. IF SY-SUBRC <> 0.
  67. * Implement suitable error handling here
  68. ENDIF.
  69.  
  70. IF     result = 1.
  71.    add 1 to pat-score.
  72. ELSEIF result = 2.
  73.    add 1 to fern-score.
  74. ELSEIF result = 3.
  75.    add 1 to fah-score.
  76. ELSEIF result = 4.
  77.    add 1 to peet-score.
  78. ELSEIF result = 5.
  79.    add 1 to sai-score.
  80. ELSEIF result = 6.
  81.    add 1 to eve-score.
  82. ELSEIF result = 7.
  83.    add 1 to nut-score.
  84. else.
  85.    add 1 to peter-score.
  86. ENDIF.
  87.  
  88. ENDDO.
  89. *----------------------------------------
  90. DATA:first    TYPE i VALUE -9999,
  91.      winner(10),
  92.      second   type i VALUE -9999,
  93.      first_runner_up(10),
  94.      third    TYPE i VALUE -9999,
  95.      second_runner_up(10).
  96.  
  97. DATA : BEGIN OF it_winner OCCURS 0,
  98.      name(10),
  99.      score TYPE i,
  100.   END OF it_winner.
  101.  
  102. IT_WINNER-name  = pat-name.
  103. it_winner-score = pat-score.
  104. APPEND it_winner.
  105. IT_WINNER-name  = fern-name.
  106. it_winner-score = fern-score.
  107. APPEND it_winner.
  108. IT_WINNER-name  = fah-name.
  109. it_winner-score = fah-score.
  110. APPEND it_winner.
  111. IT_WINNER-name  = peet-name.
  112. it_winner-score = peet-score.
  113. APPEND it_winner.
  114. IT_WINNER-name  = sai-name.
  115. it_winner-score = sai-score.
  116. APPEND it_winner.
  117. IT_WINNER-name  = eve-name.
  118. it_winner-score = eve-score.
  119. APPEND it_winner.
  120. IT_WINNER-name  = nut-name.
  121. it_winner-score = nut-score.
  122. APPEND it_winner.
  123. IT_WINNER-name  = peter-name.
  124. it_winner-score = peter-score.
  125. APPEND it_winner.
  126.  
  127. LOOP AT it_winner.
  128.   IF it_winner-score > first.
  129.       second = first.
  130.       first_runner_up = winner.
  131.       first = it_winner-SCORE.
  132.       winner = it_winner-name.
  133.   ELSEIF it_winner-score > second.
  134.       third = second.
  135.       second_runner_up = first_runner_up.
  136.       second = it_winner-score.
  137.       first_runner_up = it_winner-NAME.
  138.   ELSEIF it_winner-score > third.
  139.       second = it_winner-score.
  140.       second_runner_up = it_winner-name.
  141.   ENDIF.
  142. ENDLOOP.
  143.  
  144. *---------------- Display ---------------
  145. DATA: concat_1(20), concat_2(20), concat_3(20),
  146.       first_char(3),
  147.       second_char(3),
  148.       third_char(3).
  149. WRITE: first to first_char,
  150.        second to second_char,
  151.        third  to third_char.
  152. CONCATENATE '1' winner 'score : ' first_char into concat_1 SEPARATED BY SPACE.
  153. CONCATENATE '2' first_runner_up 'score : ' second_char into concat_2 SEPARATED BY SPACE.
  154. CONCATENATE '3' second_runner_up 'score : ' third_char into concat_3 SEPARATED BY SPACE.
  155.  
  156. *WRITE : concat_1 COLOR 5.
  157. WRITE : concat_1 COLOR 5,
  158.        / concat_2 COLOR 3,
  159.        / concat_3 COLOR 7.
Advertisement
Add Comment
Please, Sign In to add comment