Archive for the ‘SAP ABAP’Category

Marbles

*&———————————————————————*
*& Report  ZTEST_NP_MARBLE
*&
*&———————————————————————*
*&
*&
*&———————————————————————*
REPORT  ZTEST_NP_MARBLE NO STANDARD PAGE HEADING.
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* I N C L U D E
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
INCLUDE <ICON>.

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* D A T A   D E F I N I T I O N
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
*….Types
TYPES: BEGIN OF TY_SCORE,
       SRL   TYPE I,
       UNAME TYPE SY-UNAME,
       SCORE TYPE I,
       TIME  TYPE I,
       END   OF TY_SCORE.
*….Internal Tables
DATA: BEGIN OF ITAB OCCURS 0,
      C1,  C2,  C3,
      C4,  C5,  C6,
      C7,  C8,  C9,
      END   OF ITAB.
DATA: BEGIN OF IT_PRINT OCCURS 0,
      C1(4), C2(4), C3(4),
      C4(4), C5(4), C6(4),
      C7(4), C8(4), C9(4),
      END   OF IT_PRINT.
DATA: IT_SCORE TYPE STANDARD TABLE OF TY_SCORE.
*….Work Areas
DATA: WA_ITAB  LIKE ITAB,
      WA_PRINT LIKE IT_PRINT,
      W_SCORE  TYPE TY_SCORE.
*….Globle Variables
DATA: L_NO_M      TYPE I,
      L_NO_S      TYPE I,
      L_NO_C      TYPE CHAR10,
      L_HALF      TYPE I,
      L_HALF_HALF TYPE I,
      L_PRINT     TYPE FLAG,
      L_NAME      TYPE CHAR20,
      L_MOD       TYPE I.
DATA: W_ON        TYPE FLAG,
      W_SEL_LINE  TYPE I,
      W_SEL_COL   TYPE CHAR1,
      W_DEST_OK   TYPE FLAG,
      W_DEST_LINE TYPE I,
      W_DEST_COL  TYPE CHAR1,
      W_FIELD     TYPE CHAR20,
      W_LINE      TYPE I,
      W_GAME_OVER TYPE FLAG,
      W_TOTAL     TYPE I,
      W_REM       TYPE I,
      W_GONE      TYPE I,
      W_ST_TIME   TYPE I,
      W_END_TIME  TYPE I,
      W_EXPORTED  TYPE FLAG.
*….Field symbols
FIELD-SYMBOLS: <F> TYPE ANY.
*….Constants
CONSTANTS: ICON_0(40) TYPE C VALUE ICON_WD_RADIO_BUTTON_EMPTY,
           ICON_1(40) TYPE C VALUE ICON_RADIOBUTTON,
           ICON_2(40) TYPE C VALUE ICON_COLOR.
*.. Some systems don’t have above listed ICONs You can use:
**….Constants
*CONSTANTS: ICON_0(40) TYPE C VALUE ICON_AVERAGE,      ” ICON_WD_RADIO_BUTTON_EMPTY,
*           ICON_1(40) TYPE C VALUE ICON_POSITIVE,     ” ICON_RADIOBUTTON,
*           ICON_2(40) TYPE C VALUE ICON_COLOR.

*….Ranges
RANGES: R_NOT_GREY FOR ABDOCMODE-FLAG.
*….Macros
DEFINE CONV_I_C.
  &2 = &1.
  CONDENSE &2.
END-OF-DEFINITION.

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* S E L E C T I O N   S C R E E N
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
PARAMETERS: P_NUM TYPE I DEFAULT 7.
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* A T   S E L E C T I O N – S C R E E N .
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
AT SELECTION-SCREEN.
  IF  P_NUM GT 9
  OR  P_NUM LT 5.
    MESSAGE E398(00) WITH ‘Currently allowed only: 5, 7, 9’.
  ENDIF.
  L_MOD = P_NUM MOD 2.
  IF L_MOD = 0.
    MESSAGE E398(00) WITH ‘Only odd numbers are allowed’.
  ENDIF.
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* S T A R T   O F   S E L E C T I O N
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
START-OF-SELECTION.
  GET TIME FIELD W_ST_TIME.
  PERFORM FILL_MARBLES.
  PERFORM FILL_PRINT_TABLE.
  PERFORM WRITE_MARBLES.
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* A T   L I N E   S E L E C T I O N
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
AT LINE-SELECTION.
  GET CURSOR FIELD W_FIELD.
  PERFORM CALCULATE_MARBLES.
  PERFORM FILL_PRINT_TABLE.
  SY-LSIND = 0.
  PERFORM WRITE_MARBLES.
  PERFORM CHECK_GAME_OVER.
*&———————————————————————*
*&      Form  fill_marbles
*&———————————————————————*
*       Fillup the initial table for the marbles
*———————————————————————-*
FORM FILL_MARBLES .
* Grey cells
  L_HALF = FLOOR( P_NUM / 2 ).
  L_HALF_HALF = L_HALF / 2.
  R_NOT_GREY-SIGN   = ‘I’.
  R_NOT_GREY-OPTION = ‘BT’.
  R_NOT_GREY-LOW  = ( L_HALF – L_HALF_HALF ) + 1.
  R_NOT_GREY-HIGH = ( L_HALF + L_HALF_HALF ) – 1.
  APPEND R_NOT_GREY.
  CLEAR  R_NOT_GREY.
* Filling up the table
  DO P_NUM TIMES.
    L_NO_M = SY-INDEX.
    NEW-LINE.
    DO P_NUM TIMES.
      L_NO_S = SY-INDEX.
      CLEAR: L_PRINT.
      IF L_NO_M IN R_NOT_GREY.
        L_PRINT = ‘X’.
      ENDIF.
      IF L_NO_S IN R_NOT_GREY.
        L_PRINT = ‘X’.
      ENDIF.
      IF L_PRINT = ‘X’.
        CONV_I_C L_NO_S L_NO_C.
        CONCATENATE ‘WA_ITAB-C’ L_NO_C INTO L_NAME.
        ASSIGN (L_NAME) TO <F>.
        IF  L_NO_S = L_HALF
        AND L_NO_M = L_HALF.
          <F> = ‘0’.
          W_TOTAL = W_TOTAL – 1.
        ELSE.
          <F> = ‘1’.
          W_TOTAL = W_TOTAL + 1.
        ENDIF.
      ELSE.
        WRITE: ‘ ‘.
      ENDIF.
    ENDDO.
    APPEND WA_ITAB TO ITAB.
    CLEAR  WA_ITAB.
  ENDDO.
  W_REM = W_TOTAL.
ENDFORM.                    ” fill_marbles
*&———————————————————————*
*&      Form  fill_print_Table
*&———————————————————————*
*       Convert ITAB value to PRINT table value .
*———————————————————————-*
FORM FILL_PRINT_TABLE .
  FIELD-SYMBOLS: <F1> TYPE ANY.
  REFRESH IT_PRINT.
  LOOP AT ITAB INTO WA_ITAB.
    L_NO_M = SY-INDEX.
    DO P_NUM TIMES.
      CONV_I_C SY-INDEX L_NO_C.
      CLEAR L_NAME.
      CONCATENATE ‘WA_ITAB-C’ L_NO_C INTO L_NAME.
      ASSIGN (L_NAME) TO <F>.
      CLEAR L_NAME.
      CONCATENATE ‘WA_PRINT-C’ L_NO_C INTO L_NAME.
      ASSIGN (L_NAME) TO <F1>.
      CASE <F>.
        WHEN ‘1’.
          <F1> = ICON_1.
        WHEN ‘0’.
          <F1> = ICON_0.
        WHEN ‘2’.
          <F1> = ICON_2.
        WHEN OTHERS.
      ENDCASE.
    ENDDO.
    APPEND WA_PRINT TO IT_PRINT.
    CLEAR  WA_PRINT.
  ENDLOOP.
ENDFORM.                    ” fill_print_Table
*&———————————————————————*
*&      Form  write_marbles
*&———————————————————————*
*       Write marbles from the PRINT table
*———————————————————————-*
FORM WRITE_MARBLES .
  FIELD-SYMBOLS: <F1> TYPE ANY.
  IF W_GAME_OVER IS INITIAL.
    LOOP AT IT_PRINT INTO WA_PRINT.
      SKIP 1.
      W_LINE = SY-TABIX.
      WRITE: (2) W_LINE.
      HIDE  W_LINE.
      DO P_NUM TIMES.
        CONV_I_C SY-INDEX L_NO_C.
        CLEAR L_NAME.
        CONCATENATE ‘WA_PRINT-C’ L_NO_C INTO L_NAME.
        ASSIGN (L_NAME) TO <F1>.
        IF NOT <F1> IS INITIAL.
          WRITE: (2) <F1> AS ICON HOTSPOT ON, (2) ‘ ‘.
        ELSE.
          WRITE: (2) ‘ ‘, (2) ‘ ‘.
        ENDIF.
      ENDDO.
    ENDLOOP.
  ENDIF.
  SKIP 4.
  WRITE: /(30) ‘Total Marbles:’,    W_TOTAL.
  WRITE: /(30) ‘Remaining Marbles’, W_REM.
  SKIP 4.
  PERFORM WRITE_5_HIGH_SCORE.
ENDFORM.                    ” write_marbles
*&———————————————————————*
*&      Form  calculate_marbles
*&———————————————————————*
*       Calculate the marbles after the user input in line selection
*———————————————————————-*
FORM CALCULATE_MARBLES .
* No marble has been selected
  IF W_ON IS INITIAL.
    PERFORM VALIDATE_INPUT.
  ELSE.
* remove the seleced marble
    PERFORM DESELECT_MARBLE.
    IF W_ON = ‘X’.
*     Check destination cell, if the same marble has not been selected
      PERFORM CHECK_DESTINATION.
    ENDIF.
  ENDIF.
* Destination is ok ..? rearrange the marbles in ITAB
  IF W_DEST_OK = ‘X’.
    PERFORM REARRANGE_MARBLES.
  ENDIF.
ENDFORM.                    ” calculate_marbles
*&———————————————————————*
*&      Form  validate_input
*&———————————————————————*
*       Validating the selected marble, is it movable or not
*       if marble is movable, highlight it
*———————————————————————-*
FORM VALIDATE_INPUT .
  DATA: L_SEL_FIELD(20),
        L_TMP_FIELD(20),
        L_SEL_COL(1),
        L_TMP_COL(2),
        L_TMP_LINE TYPE I,
        L_OK TYPE FLAG.
  FIELD-SYMBOLS: <F1> TYPE ANY,
                 <F2> TYPE ANY.
  READ TABLE ITAB INTO WA_ITAB INDEX W_LINE.
  L_SEL_FIELD = W_FIELD.
  L_SEL_COL   = W_FIELD+10(1).
  REPLACE ‘PRINT’ INTO L_SEL_FIELD WITH ‘ITAB’.
  CONDENSE L_SEL_FIELD.
  ASSIGN (L_SEL_FIELD) TO <F1>.
* value = 0 >> No marble
  IF <F1> = ‘0’.
    MESSAGE S398(00) WITH ‘No marble to select.!’.
    EXIT.
  ENDIF.
* Check right
  L_TMP_COL = L_SEL_COL + 2.
  IF L_TMP_COL < 9.
    CONCATENATE ‘WA_ITAB-C’ L_TMP_COL INTO L_TMP_FIELD.
    CONDENSE L_TMP_FIELD.
    ASSIGN (L_TMP_FIELD) TO <F2>.
    IF <F2> = ‘0’.
      L_OK = ‘X’.
    ENDIF.
  ENDIF.
* Check left
  IF L_OK IS INITIAL.
    L_TMP_COL = L_SEL_COL – 2.
    IF L_TMP_COL > 0.
      CONCATENATE ‘WA_ITAB-C’ L_TMP_COL INTO L_TMP_FIELD.
      CONDENSE L_TMP_FIELD.
      ASSIGN (L_TMP_FIELD) TO <F2>.
      IF <F2> = ‘0’.
        L_OK = ‘X’.
      ENDIF.
    ENDIF.
  ENDIF.
* check Above
  IF L_OK IS INITIAL.
    L_TMP_LINE = W_LINE – 2.
    IF L_TMP_LINE > 0.
      READ TABLE ITAB INTO WA_ITAB INDEX L_TMP_LINE.
      IF <F1> = ‘0’.
        L_OK = ‘X’.
      ENDIF.
      READ TABLE ITAB INTO WA_ITAB INDEX W_LINE.
    ENDIF.
  ENDIF.
* Check underneath
  IF L_OK IS INITIAL.
    L_TMP_LINE = W_LINE + 2.
    IF L_TMP_LINE < 9.
      READ TABLE ITAB INTO WA_ITAB INDEX L_TMP_LINE.
      IF <F1> = ‘0’.
        L_OK = ‘X’.
      ENDIF.
      READ TABLE ITAB INTO WA_ITAB INDEX W_LINE.
    ENDIF.
  ENDIF.
* Ok .. than ON
  IF L_OK = ‘X’.
    W_ON = ‘X’.
    <F1> = ‘2’.
    MODIFY ITAB FROM WA_ITAB INDEX W_LINE.
    W_SEL_LINE = W_LINE.
    W_SEL_COL  = L_SEL_COL .
  ELSE.
    MESSAGE S398(00) WITH ‘No marble to select.!’ ‘ ‘ ‘ ‘ ‘ ‘.
  ENDIF.
ENDFORM.                    ” validate_input
*&———————————————————————*
*&      Form  deselect_marble
*&———————————————————————*
*       Deselect the marble if the same marble is selected again
*———————————————————————-*
FORM DESELECT_MARBLE .
  DATA: L_SEL_FIELD(20).
  FIELD-SYMBOLS: <F1> TYPE ANY.
  READ TABLE ITAB INTO WA_ITAB INDEX W_LINE.
  L_SEL_FIELD = W_FIELD.
  REPLACE ‘PRINT’ INTO L_SEL_FIELD WITH ‘ITAB’.
  CONDENSE L_SEL_FIELD.
  ASSIGN (L_SEL_FIELD) TO <F1>.
  IF <F1> = ‘2’.
    <F1> = ‘1’.
    MODIFY ITAB FROM WA_ITAB INDEX W_LINE.
    MESSAGE S398(00) WITH ‘Marble was deselected..!!’.
    CLEAR: W_ON, W_SEL_LINE, W_SEL_COL.
  ENDIF.
ENDFORM.                    ” deselect_marble
*&———————————————————————*
*&      Form  check_destination
*&———————————————————————*
*       Check the destination cell, it should not be empty and distnce
*       between selected cell and destination cell must be 2
*———————————————————————-*
FORM CHECK_DESTINATION .
  DATA: L_DEST_FIELD(20),
        L_DEST_COL(1),
        L_DEST_NOT_OK TYPE FLAG,
        L_TMP_LINE TYPE I,
        L_TMP_COL  TYPE C.
  DATA: L_ITAB_DEST LIKE ITAB.
  FIELD-SYMBOLS: <F1> TYPE ANY.
  READ TABLE ITAB INTO L_ITAB_DEST INDEX W_LINE.
  L_DEST_FIELD = W_FIELD.
  L_DEST_COL   = W_FIELD+10(1).
  REPLACE ‘WA_PRINT’ INTO L_DEST_FIELD WITH ‘L_ITAB_DEST’.
  CONDENSE L_DEST_FIELD.
  ASSIGN (L_DEST_FIELD) TO <F1>.
* Destination should be empty
  IF <F1> <> ‘0’.
    L_DEST_NOT_OK = ‘X’.
  ENDIF.
* Calcualate the distance between selected marble and destination
  IF L_DEST_NOT_OK IS INITIAL.
    IF W_SEL_LINE <> W_LINE.
      L_TMP_LINE = ABS( W_SEL_LINE – W_LINE ).
      IF L_TMP_LINE <> ‘2’.
        L_DEST_NOT_OK = ‘X’.
      ENDIF.
    ENDIF.
  ENDIF.
  IF L_DEST_NOT_OK IS INITIAL.
    IF W_SEL_COL <> L_DEST_COL.
      L_TMP_COL = ABS( W_SEL_COL – L_DEST_COL ).
      IF L_TMP_COL <> ‘2’.
        L_DEST_NOT_OK = ‘X’.
      ENDIF.
    ENDIF.
  ENDIF.
* destination not ok
  IF L_DEST_NOT_OK = ‘X’.
    MESSAGE S398(00) WITH ‘Destination is not GOOD’ ‘ ‘ ‘ ‘ ‘ ‘.
  ELSE.
    W_DEST_OK = ‘X’.
    W_DEST_LINE = W_LINE.
    W_DEST_COL  = L_DEST_COL.
  ENDIF.
ENDFORM.                    ” check_destination
*&———————————————————————*
*&      Form  rearrange_marbles
*&———————————————————————*
*       Rearrange marbles
*     1 Remove the marble which is inbetween the selected & destination
*     2 Remove the marble from the selected cell
*     3 Put marble on the destination cell
*———————————————————————-*
FORM REARRANGE_MARBLES .
  DATA: L_FIELD(20),
        L_TMP_LINE TYPE I,
        L_TMP_COL  TYPE CHAR1,
        L_NO_MOVE  TYPE FLAG,
        L_ITAB LIKE ITAB.

  FIELD-SYMBOLS: <F1> TYPE ANY.
* Make the inbetween column as 0 if both lines are same
  IF W_SEL_LINE = W_DEST_LINE.
    IF W_SEL_COL > W_DEST_COL.
      L_TMP_COL = W_DEST_COL + 1.
    ELSE.
      L_TMP_COL = W_SEL_COL + 1.
    ENDIF.
    READ TABLE ITAB INTO L_ITAB INDEX W_SEL_LINE.
    L_FIELD = W_FIELD.
    REPLACE ‘WA_PRINT’ INTO L_FIELD WITH ‘L_ITAB’.
    CONDENSE L_FIELD.
    L_FIELD+8(1) = L_TMP_COL.
    ASSIGN (L_FIELD) TO <F1>.
    IF <F1> = 1.
      <F1> = ‘0’.
      W_GONE = W_GONE + 1.
      MODIFY ITAB FROM L_ITAB INDEX W_SEL_LINE.
    ELSE.
      L_NO_MOVE = ‘X’.
    ENDIF.
    CLEAR  L_ITAB.
  ENDIF.
* Make the inbetween line as 0 if both lines are same
  IF W_SEL_COL = W_DEST_COL.
    IF W_SEL_LINE > W_DEST_LINE.
      L_TMP_LINE = W_DEST_LINE + 1.
    ELSE.
      L_TMP_LINE = W_SEL_LINE + 1.
    ENDIF.
    READ TABLE ITAB INTO L_ITAB INDEX L_TMP_LINE.
    L_FIELD = W_FIELD.
    REPLACE ‘WA_PRINT’ INTO L_FIELD WITH ‘L_ITAB’.
    CONDENSE L_FIELD.
    L_FIELD+8(1) = W_SEL_COL.
    ASSIGN (L_FIELD) TO <F1>.
    IF <F1> = 1.
      <F1> = ‘0’.
      W_GONE = W_GONE + 1.
      MODIFY ITAB FROM L_ITAB INDEX L_TMP_LINE.
    ELSE.
      L_NO_MOVE = ‘X’.
    ENDIF.
    CLEAR  L_ITAB.
  ENDIF.
  IF L_NO_MOVE IS INITIAL.
*   Make Destination = 1
    READ TABLE ITAB INTO L_ITAB INDEX W_DEST_LINE.
    L_FIELD = W_FIELD.
    REPLACE ‘WA_PRINT’ INTO L_FIELD WITH ‘L_ITAB’.
    CONDENSE L_FIELD.
    L_FIELD+8(1) = W_DEST_COL.
    ASSIGN (L_FIELD) TO <F1>.
    <F1> = ‘1’.
    MODIFY ITAB FROM L_ITAB INDEX W_DEST_LINE.
    CLEAR  L_ITAB.
*   Make.
    READ TABLE ITAB INTO L_ITAB INDEX W_SEL_LINE.
    L_FIELD = W_FIELD.
    REPLACE ‘WA_PRINT’ INTO L_FIELD WITH ‘L_ITAB’.
    CONDENSE L_FIELD.
    L_FIELD+8(1) = W_SEL_COL.
    ASSIGN (L_FIELD) TO <F1>.
    <F1> = ‘0’.
    MODIFY ITAB FROM L_ITAB INDEX W_SEL_LINE.
    CLEAR  L_ITAB.
  ELSE.
*   Make Selected = 1 when no movement
    READ TABLE ITAB INTO L_ITAB INDEX W_SEL_LINE.
    L_FIELD = W_FIELD.
    REPLACE ‘WA_PRINT’ INTO L_FIELD WITH ‘L_ITAB’.
    CONDENSE L_FIELD.
    L_FIELD+8(1) = W_SEL_COL.
    ASSIGN (L_FIELD) TO <F1>.
    <F1> = ‘1’.
    MODIFY ITAB FROM L_ITAB INDEX W_SEL_LINE.
    CLEAR  L_ITAB.
  ENDIF.
  W_REM = W_TOTAL – W_GONE.
  CLEAR: W_DEST_OK, W_DEST_LINE, W_DEST_COL,
         W_ON,      W_SEL_LINE,  W_SEL_COL.

ENDFORM.                    ” rearrange_marbles
*&———————————————————————*
*&      Form  check_game_over
*&———————————————————————*
*       Check game over when the remaining marbles are half than
*         the original marbles. Check for all cells with the marbles and
*         check adjacent cells (right, left, above and underneath cells)
*         with the value. If the marble found in any adjacent cell than
*         GAME is NOT OVER
*———————————————————————-*
FORM CHECK_GAME_OVER .
  STATICS: L_TOT_HALF TYPE I.
  DATA: L_ITAB     LIKE ITAB,
        L_ITAB_TMP LIKE ITAB.
  DATA: L_TMP_FIELD(20),
        L_SEL_COL(1),
        L_TMP_COL(2),
        L_OK       TYPE FLAG,
        L_LINE     TYPE I,
        L_TMP_LINE TYPE I.
  CLEAR: L_OK.
  FIELD-SYMBOLS: <F1> TYPE ANY,
                 <F2> TYPE ANY.
  CHECK W_ON IS INITIAL.
  L_TOT_HALF = ABS( W_TOTAL / 2 ).
  CHECK W_REM < L_TOT_HALF.
  LOOP AT ITAB INTO L_ITAB.
    L_LINE = SY-TABIX.
    L_ITAB_TMP = L_ITAB.
    DO P_NUM TIMES.
      L_ITAB = L_ITAB_TMP.
      L_SEL_COL = SY-INDEX.
      CONV_I_C SY-INDEX L_NO_C.
      CLEAR L_NAME.
      CONCATENATE ‘L_ITAB-C’ L_NO_C INTO L_NAME.
      ASSIGN (L_NAME) TO <F1>.
      IF <F1> IS INITIAL
      OR <F1> = ‘0’.
        CONTINUE.
      ENDIF.
*      IF <F1> = ‘1’.
*        l_ok = ‘X’.
*        exit.
*      ENDIF.
*     right neighbour
      L_TMP_COL = L_SEL_COL + 1.
      IF L_TMP_COL < 9.
        CONCATENATE ‘L_ITAB-C’ L_TMP_COL INTO L_TMP_FIELD.
        CONDENSE L_TMP_FIELD.
        ASSIGN (L_TMP_FIELD) TO <F2>.
        IF <F2> = ‘1’.
          L_TMP_COL = L_SEL_COL + 2.
          IF L_TMP_COL < 9.
            CONCATENATE ‘L_ITAB-C’ L_TMP_COL INTO L_TMP_FIELD.
            CONDENSE L_TMP_FIELD.
            ASSIGN (L_TMP_FIELD) TO <F2>.
            IF <F2> = ‘0’.
              L_OK = ‘X’.
              EXIT.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
*     Check left
      L_TMP_COL = L_SEL_COL – 1.
      IF L_TMP_COL > 0.
        CONCATENATE ‘L_ITAB-C’ L_TMP_COL INTO L_TMP_FIELD.
        CONDENSE L_TMP_FIELD.
        ASSIGN (L_TMP_FIELD) TO <F2>.
        IF <F2> = ‘1’.
          L_TMP_COL = L_SEL_COL – 2.
          IF L_TMP_COL > 0.
            CONCATENATE ‘L_ITAB-C’ L_TMP_COL INTO L_TMP_FIELD.
            CONDENSE L_TMP_FIELD.
            ASSIGN (L_TMP_FIELD) TO <F2>.
            IF <F2> = ‘0’.
              L_OK = ‘X’.
              EXIT.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
      CONCATENATE ‘L_ITAB-C’ L_NO_C INTO L_TMP_FIELD.
      CONDENSE L_TMP_FIELD.
      ASSIGN (L_TMP_FIELD) TO <F2>.
*     check Above
      L_TMP_LINE = L_LINE – 1.
      IF L_TMP_LINE > 0.
        CLEAR L_ITAB.
        READ TABLE ITAB INTO L_ITAB INDEX L_TMP_LINE.
        IF <F2> = ‘1’.
          L_TMP_LINE = L_LINE – 2.
          IF L_TMP_LINE > 0.
            CLEAR L_ITAB.
            READ TABLE ITAB INTO L_ITAB INDEX L_TMP_LINE.
            IF <F2> = ‘0’.
              L_OK = ‘X’.
              EXIT.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
*     Check underneath
      L_TMP_LINE = L_LINE + 1.
      IF L_TMP_LINE < 9.
        CLEAR L_ITAB.
        READ TABLE ITAB INTO L_ITAB INDEX L_TMP_LINE.
        IF <F2> = ‘1’.
          L_TMP_LINE = L_LINE + 2.
          IF L_TMP_LINE < 9.
            CLEAR L_ITAB.
            READ TABLE ITAB INTO L_ITAB INDEX L_TMP_LINE.
            IF <F2> = ‘0’.
              L_OK = ‘X’.
              EXIT.
            ENDIF.
          ENDIF.
        ENDIF.
      ENDIF.
    ENDDO.
    IF L_OK = ‘X’.
      EXIT.
    ENDIF.
  ENDLOOP.
  IF L_OK IS INITIAL.
    W_GAME_OVER = ‘X’.
    MESSAGE S398(00) WITH ‘Game Over. Socre:’ W_REM.
    PERFORM EXPORT_HIGH_SCORE.
*    leave program.
  ENDIF.
ENDFORM.                    ” check_game_over
*&———————————————————————*
*&      Form  export_high_score
*&———————————————————————*
*       Export High Score to memory when the game is over
*———————————————————————-*
FORM EXPORT_HIGH_SCORE .
  DATA: L_TIME TYPE I.
  CHECK W_EXPORTED IS INITIAL.
  GET TIME FIELD W_END_TIME.
  L_TIME = W_END_TIME – W_ST_TIME.
  W_SCORE-UNAME = SY-UNAME.
  W_SCORE-SCORE = W_REM.
  W_SCORE-TIME  = L_TIME.
  APPEND W_SCORE TO IT_SCORE.
  SORT IT_SCORE BY SCORE TIME.
  LOOP AT IT_SCORE INTO W_SCORE.
    W_SCORE-SRL = SY-TABIX.
    MODIFY IT_SCORE FROM W_SCORE.
    CLEAR  W_SCORE.
  ENDLOOP.
  DELETE IT_SCORE WHERE SRL > 5.
  EXPORT IT_SCORE = IT_SCORE TO DATABASE INDX(ZZ)
         ID ‘ZGAME_MAR’.
  W_EXPORTED = ‘X’.
ENDFORM.                    ” export_high_score
*&———————————————————————*
*&      Form  write_5_high_score
*&———————————————————————*
*       Write 5 high scores
*———————————————————————-*
FORM WRITE_5_HIGH_SCORE .
  IMPORT IT_SCORE = IT_SCORE FROM DATABASE INDX(ZZ)
         ID ‘ZGAME_MAR’.
  WRITE: /(12) ‘User’,
          (10) ‘Score’ RIGHT-JUSTIFIED ,
          (10) ‘Time’  RIGHT-JUSTIFIED.
  WRITE: /(34) SY-ULINE.
  LOOP AT IT_SCORE INTO W_SCORE.
    WRITE: /(12) W_SCORE-UNAME,
            (10) W_SCORE-SCORE,
            (10) W_SCORE-TIME.
  ENDLOOP.
ENDFORM.                    ” write_5_high_score

02

02 2010

TicTacToe

report ztictactoe no standard page heading.

************************************************************************
* TYPES
************************************************************************
* build up table of possible, valid options
types:
begin of t_options,
key(1),
one(1),
two(1),
three(1),
four(1),
five(1),
six(1),
seven(1),
eight(1),
nine(1),
end of t_options.

* Build list of all possible numbers
types:
begin of t_possible,
number(2),
end of t_possible.

types:
begin of t_my_pick,
number(2),
end of t_my_pick.

types:
begin of t_your_pick,
number(2),
end of t_your_pick.

types:
begin of t_win_combo,
one(2),
two(2),
three(2),
end of t_win_combo.

types:
begin of t_best_for_me,
count type i,
importance type i,
best_number(2),
one(2),
two(2),
three(2),
end of t_best_for_me.

types:
begin of t_weighting,
number(2),
rank type i,
end of t_weighting.
************************************************************************
* DATA DECLARATIONS FOR INTERNAL TABLES
************************************************************************
data:
i_options type standard table of t_options,
wa_options type t_options,
i_possible type standard table of t_possible,
wa_possible type t_possible.

data:
i_my_pick type standard table of t_my_pick,
i_your_pick type standard table of t_your_pick,
i_win_combo type standard table of t_win_combo,
i_best_for_me type standard table of t_best_for_me,
i_best_for_you type standard table of t_best_for_me,
i_weighting type standard table of t_weighting,
wa_my_pick type t_my_pick,
wa_your_pick type t_your_pick,
wa_win_combo type t_win_combo,
wa_best_for_me type t_best_for_me,
wa_best_for_you type t_best_for_me,
wa_weighting type t_weighting.
************************************************************************
* DATA
************************************************************************
data:
best_save type i,
l_random type i,
once_only(1),
importance_save_me type i,
importance_save_you type i,
block(1),
my_lines like sy-dbcnt,
your_lines like sy-dbcnt,
total_lines like sy-dbcnt,
finish(1).

data:
p1(5),
p2(5),
p3(5),
p4(5),
p5(5),
p6(5),
p7(5),
p8(5),
p9(5).

data:
user_first(1) value ‘ ‘,
index(2) value ‘P5’,
cursor(5),
my_count type i,
your_count type i,
best(2),
best_number(2),
win_flag(1).

constants:
noughts(1) value ‘O’,
crosses(1) value ‘X’,
c_rank1 type i value ‘3’,
c_rank2 type i value ‘2’,
c_rank3 type i value ‘1’.
************************************************************************
* SETUP POSSIBLE VALUE MATRIX
************************************************************************
selection-screen begin of block main.

selection-screen pushbutton 15(25) p_head user-command us01.

selection-screen skip 1.

selection-screen pushbutton 15(25) p_tail user-command us02.

selection-screen end of block main.

************************************************************************
* INITIALIZATION
************************************************************************
initialization.

move ‘Heads’ to p_head.
move ‘Tails’ to p_tail.
************************************************************************
* PROCESSING
************************************************************************
************************************************************************
* AT SELECTION-SCREEN IS RUN FIRST
************************************************************************

at selection-screen.

check finish ne ‘X’.

check once_only = ‘ ‘.
once_only = ‘X’.
perform initialization.

* randomly pick heads or tails based on system time

check sy-ucomm eq ‘US01’ or sy-ucomm eq ‘US02’.

l_random = sy-uzeit mod 2.

if sy-ucomm eq ‘US01’.

if l_random eq 0.

p_head = ‘You Win’.
p_tail = ‘ ‘.
user_first = ‘X’.

else.

p_head = ‘You Lose’.
p_tail = ‘ ‘.

endif.

else.

if l_random eq 1.

p_tail = ‘You Win’.
p_head = ‘ ‘.
user_first = ‘X’.

else.

p_tail = ‘You Lose’.
p_head = ‘ ‘.
endif.
endif.

* Here work out, statistically what is the best number to have
perform get_best_number.

************************************************************************
* AT START-OF-SELECTION RUN SECOND
************************************************************************
start-of-selection.

skip 1.

check once_only = ‘X’.

if user_first eq ‘X’.

write:20 p1, sy-vline, p2, sy-vline, p3.
write:/20 sy-uline(21).
write:/20 p4, sy-vline, p5, sy-vline, p6.
write:/20 sy-uline(21).
write:/20 p7, sy-vline, p8, sy-vline, p9.

else.

perform write_screen using index
noughts
‘ ‘.

endif.

************************************************************************
* AT LINE SELECTION RUN FROM NOW ON
************************************************************************
at line-selection.

clear i_best_for_me[].
clear i_best_for_you[].
clear wa_best_for_me.
clear wa_best_for_you.

 

* Find where the user wishes to place their cross, this has to be the
* User
get cursor field cursor.

read table i_my_pick
into wa_my_pick
with key number = cursor.

if sy-subrc eq 0.

exit.

endif.

read table i_your_pick
into wa_your_pick
with key number = cursor.

if sy-subrc eq 0.

exit.

endif.

if cursor is initial.

exit.

endif.

perform write_screen using cursor
crosses
‘X’.

* Here we look at who has what against the winning combos
* What runs could I make, what runs could the user make
* rank the available numbers, then decide which is the best number
* for me or the user

loop at i_win_combo into wa_win_combo.

perform find_best_number using wa_win_combo-one.
perform find_best_number using wa_win_combo-two.
perform find_best_number using wa_win_combo-three.

case my_count.

when 0.

wa_best_for_me-importance = wa_best_for_me-importance * c_rank3.

when 1.

wa_best_for_me-importance = wa_best_for_me-importance * c_rank2.

when 2.

wa_best_for_me-importance = wa_best_for_me-importance * c_rank1.

endcase.
if my_count ge your_count.

move my_count to wa_best_for_me-count.
move wa_win_combo-one to wa_best_for_me-one.
move wa_win_combo-two to wa_best_for_me-two.
move wa_win_combo-three to wa_best_for_me-three.
append wa_best_for_me to i_best_for_me.

else.

move your_count to wa_best_for_you-count.
move wa_win_combo-one to wa_best_for_you-one.
move wa_win_combo-two to wa_best_for_you-two.
move wa_win_combo-three to wa_best_for_you-three.
append wa_best_for_you to i_best_for_you.

endif.

clear my_count.
clear your_count.
clear importance_save_me.
clear importance_save_you.
clear wa_best_for_me.
clear wa_best_for_you.

endloop.

sort i_best_for_me by count descending
importance descending.

sort i_best_for_you by count descending
importance descending.

delete i_best_for_me where importance is initial.
delete i_best_for_you where importance is initial.

read table i_best_for_me into wa_best_for_me index 1.

read table i_best_for_you into wa_best_for_you index 1.

* if both wa are initial then the end has come

* if we have two numbers and the user does not have the last
* put it in
if wa_best_for_me-count eq 2.

block = ‘X’.
win_flag = ‘X’.

endif.

if wa_best_for_you-count eq 2.

block = ‘X’.

endif.

if not block = ‘X’.

if wa_best_for_me-importance ge wa_best_for_you-importance.

* find which number they have put in
wait up to 2 seconds.
perform write_screen using wa_best_for_me-best_number
noughts
‘ ‘.

else.

wait up to 2 seconds.
perform write_screen using wa_best_for_you-best_number
noughts
‘ ‘.
endif.

else.

if win_flag = ‘X’.
* Computer has third of winning row and wins
wait up to 2 seconds.
perform write_screen using wa_best_for_me-best_number
noughts
‘ ‘.

write:/ ‘I win’.
finish = ‘X’.

else.

wait up to 2 seconds.

if not wa_best_for_you-best_number is initial.

perform write_screen using wa_best_for_you-best_number
noughts
‘ ‘.

else.

perform write_screen using wa_best_for_me-best_number
noughts
‘ ‘.

endif.

endif.

clear i_best_for_me[].
clear i_best_for_you[].

endif.

sort i_my_pick.
sort i_your_pick.

delete adjacent duplicates from i_my_pick.
delete adjacent duplicates from i_your_pick.

describe table i_my_pick lines my_lines.
describe table i_your_pick lines your_lines.

total_lines = my_lines + your_lines.

if total_lines ge 10.

write:/ ‘A Draw’.

finish = ‘X’.

endif.

*&———————————————————————*
*& Form write_screen
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM write_screen using cursor
marker
process.

case cursor.

when ‘P1’.

p1 = marker.

when ‘P2’.

p2 = marker.

when ‘P3’.

p3 = marker.

when ‘P4’.

p4 = marker.

when ‘P5’.

p5 = marker.

when ‘P6’.

p6 = marker.

when ‘P7’.

p7 = marker.

when ‘P8’.

p8 = marker.

when ‘P9’.

p9 = marker.
endcase.

if marker eq crosses.

move cursor to wa_your_pick.
append wa_your_pick to i_your_pick.
clear wa_your_pick.
else.

move cursor to wa_my_pick.
append wa_my_pick to i_my_pick.
clear wa_my_pick.

endif.

check process is initial.

skip 1.

write:20 p1, sy-vline, p2, sy-vline, p3.
write:/20 sy-uline(21).
write:/20 p4, sy-vline, p5, sy-vline, p6.
write:/20 sy-uline(21).
write:/20 p7, sy-vline, p8, sy-vline, p9.
ENDFORM. ” write_screen

*eject
*&———————————————————————*
*& Form initialization
*&———————————————————————*
FORM initialization.
* build vertical index agains horizontal columns
* fill win combo.

move ‘P1’ to wa_win_combo-one.
move ‘P2’ to wa_win_combo-two.
move ‘P3’ to wa_win_combo-three.
append wa_win_combo to i_win_combo.
clear wa_win_combo.

move ‘P4’ to wa_win_combo-one.
move ‘P5’ to wa_win_combo-two.
move ‘P6’ to wa_win_combo-three.
append wa_win_combo to i_win_combo.
clear wa_win_combo.

move ‘P7’ to wa_win_combo-one.
move ‘P8’ to wa_win_combo-two.
move ‘P9’ to wa_win_combo-three.
append wa_win_combo to i_win_combo.
clear wa_win_combo.

move ‘P1’ to wa_win_combo-one.
move ‘P4’ to wa_win_combo-two.
move ‘P7’ to wa_win_combo-three.
append wa_win_combo to i_win_combo.
clear wa_win_combo.

move ‘P2’ to wa_win_combo-one.
move ‘P5’ to wa_win_combo-two.
move ‘P8’ to wa_win_combo-three.
append wa_win_combo to i_win_combo.
clear wa_win_combo.

move ‘P3’ to wa_win_combo-one.
move ‘P6’ to wa_win_combo-two.
move ‘P9’ to wa_win_combo-three.
append wa_win_combo to i_win_combo.
clear wa_win_combo.

move ‘P1’ to wa_win_combo-one.
move ‘P5’ to wa_win_combo-two.
move ‘P9’ to wa_win_combo-three.
append wa_win_combo to i_win_combo.
clear wa_win_combo.

move ‘P7’ to wa_win_combo-one.
move ‘P5’ to wa_win_combo-two.
move ‘P3’ to wa_win_combo-three.
append wa_win_combo to i_win_combo.
clear wa_win_combo.

* fill weighting table
move ‘P5’ to wa_weighting-number.
move ‘9’ to wa_weighting-rank.
append wa_weighting to i_weighting.
clear wa_weighting.

move ‘P3’ to wa_weighting-number.
move ‘8’ to wa_weighting-rank.
append wa_weighting to i_weighting.
clear wa_weighting.

move ‘P7’ to wa_weighting-number.
move ‘7’ to wa_weighting-rank.
append wa_weighting to i_weighting.
clear wa_weighting.

move ‘P9’ to wa_weighting-number.
move ‘6’ to wa_weighting-rank.
append wa_weighting to i_weighting.
clear wa_weighting.

move ‘P1’ to wa_weighting-number.
move ‘5’ to wa_weighting-rank.
append wa_weighting to i_weighting.
clear wa_weighting.

move ‘P2’ to wa_weighting-number.
move ‘4’ to wa_weighting-rank.
append wa_weighting to i_weighting.
clear wa_weighting.

move ‘P8’ to wa_weighting-number.
move ‘3’ to wa_weighting-rank.
append wa_weighting to i_weighting.
clear wa_weighting.

move ‘P6’ to wa_weighting-number.
move ‘2’ to wa_weighting-rank.
append wa_weighting to i_weighting.
clear wa_weighting.

move ‘P4’ to wa_weighting-number.
move ‘1’ to wa_weighting-rank.
append wa_weighting to i_weighting.
clear wa_weighting.

 

* 1
write ‘1’ to wa_options-key.
write ‘ ‘ to wa_options-one.
write ‘1’ to wa_options-two.
write ‘1’ to wa_options-three.
write ‘1’ to wa_options-four.
write ‘1’ to wa_options-five.
write ‘ ‘ to wa_options-six.
write ‘1’ to wa_options-seven.
write ‘ ‘ to wa_options-eight.
write ‘1’ to wa_options-nine.

append wa_options to i_options.
clear wa_options.

* 2
write ‘2’ to wa_options-key.
write ‘1’ to wa_options-one.
write ‘ ‘ to wa_options-two.
write ‘1’ to wa_options-three.
write ‘ ‘ to wa_options-four.
write ‘1’ to wa_options-five.
write ‘ ‘ to wa_options-six.
write ‘ ‘ to wa_options-seven.
write ‘1’ to wa_options-eight.
write ‘ ‘ to wa_options-nine.

append wa_options to i_options.
clear wa_options.

* 3
write ‘3’ to wa_options-key.
write ‘1’ to wa_options-one.
write ‘1’ to wa_options-two.
write ‘ ‘ to wa_options-three.
write ‘ ‘ to wa_options-four.
write ‘1’ to wa_options-five.
write ‘1’ to wa_options-six.
write ‘1’ to wa_options-seven.
write ‘ ‘ to wa_options-eight.
write ‘1’ to wa_options-nine.

append wa_options to i_options.
clear wa_options.

* 4
write ‘4’ to wa_options-key.
write ‘1’ to wa_options-one.
write ‘ ‘ to wa_options-two.
write ‘ ‘ to wa_options-three.
write ‘ ‘ to wa_options-four.
write ‘1’ to wa_options-five.
write ‘1’ to wa_options-six.
write ‘1’ to wa_options-seven.
write ‘ ‘ to wa_options-eight.
write ‘ ‘ to wa_options-nine.

append wa_options to i_options.
clear wa_options.
* 5
write ‘5’ to wa_options-key.
write ‘1’ to wa_options-one.
write ‘1’ to wa_options-two.
write ‘1’ to wa_options-three.
write ‘1’ to wa_options-four.
write ‘ ‘ to wa_options-five.
write ‘1’ to wa_options-six.
write ‘1’ to wa_options-seven.
write ‘1’ to wa_options-eight.
write ‘1’ to wa_options-nine.

append wa_options to i_options.
clear wa_options.

* 6
write ‘6’ to wa_options-key.
write ‘ ‘ to wa_options-one.
write ‘ ‘ to wa_options-two.
write ‘1’ to wa_options-three.
write ‘1’ to wa_options-four.
write ‘1’ to wa_options-five.
write ‘ ‘ to wa_options-six.
write ‘ ‘ to wa_options-seven.
write ‘ ‘ to wa_options-eight.
write ‘1’ to wa_options-nine.

append wa_options to i_options.
clear wa_options.

* 7
write ‘7’ to wa_options-key.
write ‘1’ to wa_options-one.
write ‘ ‘ to wa_options-two.
write ‘1’ to wa_options-three.
write ‘1’ to wa_options-four.
write ‘1’ to wa_options-five.
write ‘ ‘ to wa_options-six.
write ‘ ‘ to wa_options-seven.
write ‘1’ to wa_options-eight.
write ‘1’ to wa_options-nine.

append wa_options to i_options.
clear wa_options.

* 8
write ‘8’ to wa_options-key.
write ‘ ‘ to wa_options-one.
write ‘1’ to wa_options-two.
write ‘ ‘ to wa_options-three.
write ‘ ‘ to wa_options-four.
write ‘1’ to wa_options-five.
write ‘ ‘ to wa_options-six.
write ‘1’ to wa_options-seven.
write ‘ ‘ to wa_options-eight.
write ‘1’ to wa_options-nine.

append wa_options to i_options.
clear wa_options.

* 9
write ‘9’ to wa_options-key.
write ‘1’ to wa_options-one.
write ‘ ‘ to wa_options-two.
write ‘1’ to wa_options-three.
write ‘ ‘ to wa_options-four.
write ‘1’ to wa_options-five.
write ‘1’ to wa_options-six.
write ‘1’ to wa_options-seven.
write ‘1’ to wa_options-eight.
write ‘ ‘ to wa_options-nine.

append wa_options to i_options.
clear wa_options.
* Initialization all possible numbers
write ‘P1’ to wa_possible-number.
append wa_possible to i_possible.

write ‘P2’ to wa_possible-number.
append wa_possible to i_possible.

write ‘P3’ to wa_possible-number.
append wa_possible to i_possible.

write ‘P4’ to wa_possible-number.
append wa_possible to i_possible.

write ‘P5’ to wa_possible-number.
append wa_possible to i_possible.

write ‘P6’ to wa_possible-number.
append wa_possible to i_possible.

write ‘P7’ to wa_possible-number.
append wa_possible to i_possible.

write ‘P8’ to wa_possible-number.
append wa_possible to i_possible.

write ‘P9’ to wa_possible-number.
append wa_possible to i_possible.

ENDFORM. ” initialization
*eject
*&———————————————————————*
*& Form get_best_number
*&———————————————————————*
* text
*———————————————————————-*
* –> p1 text
* <– p2 text
*———————————————————————-*
FORM get_best_number.

do 9 times.

loop at i_possible into wa_possible.

read table i_options
into wa_options
with key key = wa_possible-number.

best = wa_options-one +
wa_options-two +
wa_options-three +
wa_options-four +
wa_options-five +
wa_options-six +
wa_options-seven +
wa_options-eight +
wa_options-nine .

if best gt best_save.

best_save = best.
index = wa_possible-number.

endif.

clear wa_possible.
clear best.

endloop.

enddo.

* write index if it is my go first

if user_first = ‘X’.

perform write_screen using ‘ ‘
‘ ‘
‘ ‘.

else.

perform write_screen using index
noughts
‘ ‘.

endif.

ENDFORM. ” get_best_number

*eject
*&———————————————————————*
*& Form find_best_number
*&———————————————————————*
* text
*———————————————————————-*
* –>P_WA_WIN_COMBO_ONE text
*———————————————————————-*
FORM find_best_number USING WA_WIN_COMBO.

* Look at number 1 from win combo possible
read table i_my_pick
into wa_my_pick
with key number = wa_win_combo.

* Do I already have it

if sy-subrc eq 0.

my_count = my_count + 1.

else.

* If not check if the user has it

read table i_your_pick
into wa_your_pick
with key number = wa_win_combo.

if sy-subrc ne 0.

read table i_weighting
into wa_weighting
with key number = wa_win_combo.

wa_best_for_me-importance = wa_weighting-rank +
wa_best_for_me-importance.
if wa_weighting-rank ge importance_save_me.

importance_save_me = wa_weighting-rank.

wa_best_for_me-best_number = wa_win_combo.

endif.

wa_best_for_you-importance = wa_weighting-rank +
wa_best_for_you-importance.
if wa_weighting-rank ge importance_save_you.

importance_save_you = wa_weighting-rank.

wa_best_for_you-best_number = wa_win_combo.

endif.

else.

your_count = your_count + 1.

endif.

endif.
ENDFORM. ” find_best_number

02

02 2010