Wednesday, November 5, 2008

FM to Get Manager

FUNCTION z_hr_wf_rule_get_manager.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" TABLES
*" ACTOR_TAB STRUCTURE SWHACTOR
*" AC_CONTAINER STRUCTURE SWCONT
*" EXCEPTIONS
*" NOBODY_FOUND
*"----------------------------------------------------------------------
*
* Author: Jon Amos
* Date: 2007-02-12
*
* Description:
* This FM was built based on SWX_GET_MANAGER.
* That FM gets the manager for an HR Object (i.e. UserID, etc).
* However, it only looks up one level in the reporting structure.
* This FM keeps searching up the reporting structure until it finds
* a filled position (or reachs the top of the reportning structure).
*
*---------------------------------------------------------------------

* Container macros
INCLUDE .

* Constants (for checking relationship config)
CONSTANTS: co_pprel TYPE t77s0-grpid VALUE 'PPREL',
co_orgha TYPE t77s0-semid VALUE 'ORGHA'.

* Relationship subtype for 'Reports to' (to account for customer specific config)
DATA: lv_orgha LIKE plog-subty.

* Evaluation Path for 'Holder'
DATA: lv_eval_path TYPE t77aw-wegid, "THY160604#746188
lv_ev_is_internal TYPE xflag. "THY160604#746188

* Variables stored in container
DATA: lv_plvar TYPE hrsobid-plvar.
DATA: lv_otype TYPE hrsobid-otype.
DATA: lv_sobid TYPE hrsobid-sobid.
DATA: ls_org_object TYPE swhactor.

* Data objects for leading positions
DATA: lw_leadpos TYPE hrobject,
lt_leadpos TYPE TABLE OF hrobject,
lt_currpos TYPE TABLE OF hrobject.

FIELD-SYMBOLS: TYPE hrobject.

* Data objects for HR relationships
DATA: lt_relations TYPE TABLE OF p1001.

FIELD-SYMBOLS: TYPE p1001.

* Holders table
DATA: result_tab TYPE TABLE OF swhactor.


* Initialize
CLEAR actor_tab.
REFRESH actor_tab.


* Get the HR object to start from
swc_get_element ac_container 'ORG_OBJECT' ls_org_object.
IF sy-subrc > 0 OR
ls_org_object IS INITIAL.
swc_get_element ac_container 'OTYPE' lv_otype.
swc_get_element ac_container 'OBJID' lv_sobid.
ELSE.
lv_otype = ls_org_object-otype.
lv_sobid = ls_org_object-objid.
ENDIF.

IF lv_otype IS INITIAL OR lv_sobid IS INITIAL.
* Msg: There is no chief position for & &.
MESSAGE e802(5w) WITH lv_otype lv_sobid RAISING nobody_found.
ENDIF.


* Get the Active WF Org Plan
swc_get_element ac_container 'PLVAR' lv_plvar.

IF lv_plvar IS INITIAL.
CALL FUNCTION 'RH_GET_ACTIVE_WF_PLVAR'
IMPORTING
act_plvar = lv_plvar
EXCEPTIONS
no_active_plvar = 1.

IF sy-subrc > 0.
* Msg: No active plan version exists
MESSAGE e300(5w) RAISING nobody_found.
ENDIF.
ENDIF.


* Check for customer specific 'Reports to' relationship (A002)
CALL FUNCTION 'HR_READ_T77S0'
EXPORTING
grpid = co_pprel
semid = co_orgha
IMPORTING
gsval = lv_orgha
EXCEPTIONS
entry_not_found = 1
OTHERS = 2.

* Default 'Reports to' relationship if not determined
IF sy-subrc <> 0 OR lv_orgha IS INITIAL.
lv_orgha = 'A002'.
ENDIF.


* Define 'Holder' relationship
* THY 180604 Note 746188 {
lv_eval_path = 'SAP_TAGT'.

CALL FUNCTION 'RH_PBUILD_WORKFLOW'
EXPORTING
iv_evaluation_path = lv_eval_path
IMPORTING
ev_mod_ev = lv_eval_path
ev_is_internal = lv_ev_is_internal.
* }


*-----
* (Jon Amos) NOTE:
* We never want to consider vacant positions since we will check this ourselves
*-----
* consider vacant positions flag in table T77S0
* wflow-vapos
* PERFORM re77s0(mstt77s0) USING 'WFLOW' 'VAPOS' lv_sw_vapos lv_subrc.

* Get leading position(s) for passed HR object -- one level up in Reporting Structure
CALL FUNCTION 'RH_GET_LEADING_POSITION'
EXPORTING
plvar = lv_plvar
otype = lv_otype
sobid = lv_sobid
date = sy-datum
auth = ' '
consider_vac_pos = space
TABLES
leading_pos = lt_leadpos
EXCEPTIONS
no_lead_pos_found = 1
OTHERS = 2.

* Search up the Reporting Structure for the first filled position
DO.

* Have we run out of positions to check (without finding a holder)?
IF lt_leadpos[] IS INITIAL.
* Msg: There is no chief position for & &.
MESSAGE e802(5w) WITH lv_otype lv_sobid RAISING nobody_found.
ENDIF.

* Process the leading position(s)
LOOP AT lt_leadpos ASSIGNING .

* Get the holder(s) of the position
CALL FUNCTION 'RH_STRUC_GET'
EXPORTING
act_otype = -otype
act_objid = -objid
act_wegid = lv_eval_path "THY180604#746188
act_int_flag = lv_ev_is_internal "THY180604#746188
TABLES
result_tab = result_tab
EXCEPTIONS
no_plvar_found = 1
no_entry_found = 2
OTHERS = 3.

* Add the holder(s) to the Actor_tab
APPEND LINES OF result_tab TO actor_tab.

ENDLOOP. "loop at lt_leadpos...

IF actor_tab[] IS NOT INITIAL.
* Stop looking
EXIT.

ELSE.
* The leading positions become the current positions
lt_currpos = lt_leadpos.

* Initialize
CLEAR lt_leadpos.

* Get the leading positions for current leading positions
CALL FUNCTION 'RH_READ_INFTY_1001'
EXPORTING
istat = '1'
subty = lv_orgha
begda = sy-datum
endda = sy-datum
TABLES
i1001 = lt_relations
OBJECTS = lt_currpos
EXCEPTIONS
nothing_found = 1
wrong_condition = 2
OTHERS = 3.

* Build table for next loop pass
IF sy-subrc = 0.
LOOP AT lt_relations ASSIGNING .
CLEAR lw_leadpos.
lw_leadpos-plvar = -plvar.
lw_leadpos-otype = -sclas.
lw_leadpos-objid = -sobid.
APPEND lw_leadpos TO lt_leadpos.
ENDLOOP.
ENDIF. "IF sy-subrc....
ENDIF. "IF actor_tab[]....
ENDDO.

* Only keep the Actors that are Persons or Users
* THY 180604 Note 746188
DELETE actor_tab WHERE otype <> 'P' AND
otype <> 'US'.
* }

ENDFUNCTION.

Game Memory

REPORT zmemory.
INCLUDE .
TABLES : sscrfields.
*** internal table for storing the list of icons temporarily
DATA : BEGIN OF i_icons OCCURS 1000,
id LIKE icon-id,
END OF i_icons.
*** internal table for storing the 32 icons/pictures
DATA : BEGIN OF i_iconlist OCCURS 32,
id LIKE icon-id,
END OF i_iconlist.

*** internal table for storing the icons in the 64 positions
DATA : BEGIN OF i_layout OCCURS 0,
row(1) TYPE n,
col(1) TYPE n,
id LIKE icon-id,
END OF i_layout.
*** data declaration
DATA : w_layout LIKE i_layout.
DATA : ran_no TYPE i.
DATA : len TYPE i.
DATA : subrc LIKE sy-subrc.
DATA : count TYPE i.
DATA : name(10).
DATA : flg_one.
DATA : flg_two.
DATA : icon_one LIKE icon-id.
DATA : icon_two LIKE icon-id.

DATA : b_one(5).
DATA : b_two(5).
DATA : current_ucomm LIKE sscrfields-ucomm.
DATA : ls_memory TYPE zmemory.
DATA: lv_start TYPE i,
lv_total TYPE i,
lv_tick TYPE i,
lv_timlo TYPE i.


FIELD-SYMBOLS : TYPE ANY.
**** selection-screen declaration.
*** keeping the button names and its user-command same will
*** make things easier later....
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE title NO INTERVALS.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(25) no_tries.
PARAMETERS : p_tries TYPE i MODIF ID hid VISIBLE LENGTH 14.
PARAMETERS : p_secon TYPE i MODIF ID hid VISIBLE LENGTH 14.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(25) yu_score.
PARAMETERS : p_score TYPE char25 MODIF ID hid VISIBLE LENGTH 14.
PARAMETERS : l_score TYPE char25 MODIF ID hid VISIBLE LENGTH 14.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(25) lu_secon.
PARAMETERS : l_second TYPE char25 MODIF ID hid VISIBLE LENGTH 14.
PARAMETERS : h_second TYPE char25 MODIF ID hid VISIBLE LENGTH 14.
SELECTION-SCREEN END O
F LINE.

SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN PUSHBUTTON /2(4) pb11 USER-COMMAND pb11.
SELECTION-SCREEN PUSHBUTTON 9(4) pb12 USER-COMMAND pb12.
SELECTION-SCREEN PUSHBUTTON 16(4) pb13 USER-COMMAND pb13.
SELECTION-SCREEN PUSHBUTTON 23(4) pb14 USER-COMMAND pb14.
SELECTION-SCREEN PUSHBUTTON 30(4) pb15 USER-COMMAND pb15.
SELECTION-SCREEN PUSHBUTTON 37(4) pb16 USER-COMMAND pb16.
SELECTION-SCREEN PUSHBUTTON 44(4) pb17 USER-COMMAND pb17.
SELECTION-SCREEN PUSHBUTTON 51(4) pb18 USER-COMMAND pb18.
SELECTION-SCREEN SKIP 1.

SELECTION-SCREEN PUSHBUTTON /2(4) pb21 USER-COMMAND pb21.
SELECTION-SCREEN PUSHBUTTON 9(4) pb22 USER-COMMAND pb22.
SELECTION-SCREEN PUSHBUTTON 16(4) pb23 USER-COMMAND pb23.
SELECTION-SCREEN PUSHBUTTON 23(4) pb24 USER-COMMAND pb24.
SELECTION-SCREEN PUSHBUTTON 30(4) pb25 USER-COMMAND pb25.
SELECTION-SCREEN PUSHBUTTON 37(4) pb26 USER-COMMAND pb26.
SELECTION-SCREEN PUSHBUTTON 44(4) pb27 USER-COMMAND pb27.
SELECTION-SCREEN PUSHBUTTO
N 51(4) pb28 USER-COMMAND pb28.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN PUSHBUTTON /2(4) pb31 USER-COMMAND pb31.
SELECTION-SCREEN PUSHBUTTON 9(4) pb32 USER-COMMAND pb32.
SELECTION-SCREEN PUSHBUTTON 16(4) pb33 USER-COMMAND pb33.
SELECTION-SCREEN PUSHBUTTON 23(4) pb34 USER-COMMAND pb34.
SELECTION-SCREEN PUSHBUTTON 30(4) pb35 USER-COMMAND pb35.
SELECTION-SCREEN PUSHBUTTON 37(4) pb36 USER-COMMAND pb36.
SELECTION-SCREEN PUSHBUTTON 44(4) pb37 USER-COMMAND pb37.
SELECTION-SCREEN PUSHBUTTON 51(4) pb38 USER-COMMAND pb38.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN PUSHBUTTON /2(4) pb41 USER-COMMAND pb41.
SELECTION-SCREEN PUSHBUTTON 9(4) pb42 USER-COMMAND pb42.
SELECTION-SCREEN PUSHBUTTON 16(4) pb43 USER-COMMAND pb43.
SELECTION-SCREEN PUSHBUTTON 23(4) pb44 USER-COMMAND pb44.
SELECTION-SCREEN PUSHBUTTON 30(4) pb45 USER-COMMAND pb45.
SELECTION-SCREEN PUSHBUTTO
N 37(4) pb46 USER-COMMAND pb46.
SELECTION-SCREEN PUSHBUTTON 44(4) pb47 USER-COMMAND pb47.
SELECTION-SCREEN PUSHBUTTON 51(4) pb48 USER-COMMAND pb48.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN PUSHBUTTON /2(4) pb51 USER-COMMAND pb51.
SELECTION-SCREEN PUSHBUTTON 9(4) pb52 USER-COMMAND pb52.
SELECTION-SCREEN PUSHBUTTON 16(4) pb53 USER-COMMAND pb53.
SELECTION-SCREEN PUSHBUTTON 23(4) pb54 USER-COMMAND pb54.
SELECTION-SCREEN PUSHBUTTON 30(4) pb55 USER-COMMAND pb55.
SELECTION-SCREEN PUSHBUTTON 37(4) pb56 USER-COMMAND pb56.
SELECTION-SCREEN PUSHBUTTON 44(4) pb57 USER-COMMAND pb57.
SELECTION-SCREEN PUSHBUTTON 51(4) pb58 USER-COMMAND pb58.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN PUSHBUTTON /2(4) pb61 USER-COMMAND pb61.
SELECTION-SCREEN PUSHBUTTON 9(4) pb62 USER-COMMAND pb62.
SELECTION-SCREEN PUSHBUTTON 16(4) pb63 USER-COMMAND pb63.
SELECTION-SCREEN PUSHBUTTON 23(4) pb64 USER-COMMAND pb64.
SELECTION-SCREEN PUSHBUTTON 30(4) pb65 USER-COMMAND pb65.
SELECTION-SCREEN PUSHBUTTON 37(4) pb66 USER-COMMAND pb66.
SELECTION-SCREEN PUSHBUTTON 44(4) pb67 USER-COMMAND pb67.
SELECTION-SCREEN PUSHBUTTON 51(4) pb68 USER-COMMAND pb68.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN PUSHBUTTON /2(4) pb71 USER-COMMAND pb71.
SELECTION-SCREEN PUSHBUTTON 9(4) pb72 USER-COMMAND pb72.
SELECTION-SCREEN PUSHBUTTON 16(4) pb73 USER-COMMAND pb73.
SELECTION-SCREEN PUSHBUTTON 23(4) pb74 USER-COMMAND pb74.
SELECTION-SCREEN PUSHBUTTON 30(4) pb75 USER-COMMAND pb75.
SELECTION-SCREEN PUSHBUTTON 37(4) pb76 USER-COMMAND pb76.
SELECTION-SCREEN PUSHBUTTON 44(4) pb77 USER-COMMAND pb77.
SELECTION-SCREEN PUSHBUTTON 51(4) pb78 USER-COMMAND pb78.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN PUSHBUTTON /2(4) pb81 USER-COMMAND pb81.
SELECTION-SCREEN PUSHBUTTON 9(4) pb82 USER-COMMAND pb82.
SELECTION-SCREEN PUSHBUTTON 16(4) pb83 USER-COMMAND pb83.
SELECTION-SCREEN PUSHBUTTON 23(4) pb84 USER-COMMAND pb84.
SELECTION-SCREEN PUSHBUTTON 30(4) pb85 USER-COMMAND pb85.
SELECTION-SCREEN PUSHBUTTON 37(4) pb86 USER-COMMAND pb86.
SELECTION-SCREEN PUSHBUTTON 44(4) pb87 USER-COMMAND pb87.
SELECTION-SCREEN PUSHBUTTON 51(4) pb88 USER-COMMAND pb88.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.

SELECTION-SCREEN COMMENT 2(22) hu_score.
PARAMETERS : h_score TYPE char50 MODIF ID hid VISIBLE LENGTH 50.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(22) low_sc.
PARAMETERS : plow_sc TYPE char50 MODIF ID hid VISIBLE LENGTH 50.
SELECTION-SCREEN END OF LINE.

SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 2(22) yu_secon.
PARAMETERS : y_second TYPE char25 MODIF ID hid VISIBLE LENGTH 15.
PARAMETERS : z_second TYPE char25 MODIF ID hid VISIBLE LENGTH 15.
SELECTION-SCREEN END OF LINE.


SELECTION-SCREEN END OF BLOCK b1.

INITIALIZATION.
PERFORM do_initialization.

AT SELECTION-SCREEN OUTPUT.
IF i_layout[] IS INITIAL.
lv_total = lv_timlo - lv_start.
MESSAGE i001(00) WITH 'Congratulations You did it !!!'.
ls_memory-uname = sy-uname.
ls_memory-sc_date = sy-datlo.
ls_memory-sc_time = sy-timlo.
ls_memory-sc_tries = p_tries.
ls_memory-sc_seconds = lv_total.
INSERT INTO zmemory VALUES ls_memory.
ENDIF.
*** make the count field display only
LOOP AT SCREEN.
IF screen-group1 = 'HID'.
screen-input = 0.
MODIFY SCREEN.
ENDIF.
ENDLOOP.

AT SELECTION-SCREEN.

* clear time and tries on restart
IF sscrfields-ucomm = 'ONLI'.
CLEAR: p_tries, p_secon.
ENDIF.

lv_timlo = sy-timlo.
CHECK sscrfields-ucomm CS 'PB'.
IF lv_start IS INITIAL.
lv_start = lv_timlo.
ENDIF.

lv_tick = lv_timlo - lv_start.
p_secon = lv_tick.

*** make sure it is one of the buttons that is clicked and
*** not clicking the same button again
*** exception is if 2 are open and you want to keep the 2nd one open
*** you can do so....

CHECK sscrfields-ucomm CS 'PB' AND
( sscrfields-ucomm <> current_ucomm OR
NOT flg_two IS INITIAL ).
current_ucomm = sscrfields-ucomm.
*** making sure again that a button is clicked and get the icon
*** hidden in the clicked button.
READ TABLE i_layout WITH KEY row = sscrfields-ucomm+2(1)
col = sscrfields-ucomm+3(1).
CHECK sy-subrc = 0.
PERFORM validate.
*&---------------------------------------------------------------------*
*& Form validate
*&---------------------------------------------------------------------*
* checking whether its the 1st or the 2nd button click, assign the ucomm
* to the field-symbol. The trick is the buttons have been named same as
* its ucomm, so assigning it gives the value of the button.
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM validate.
IF NOT flg_two IS INITIAL.
ASSIGN (b_one) TO .
= '@5F@'.
ASSIGN (b_two) TO .
= '@5F@'.
CLEAR : flg_one,flg_two,
icon_one,icon_two,
b_one,b_two.
ENDIF.
IF flg_one IS INITIAL OR
flg_two IS INITIAL.
ASSIGN (sscrfields-ucomm) TO .
IF sy-subrc = 0.
= i_layout-id.
ENDIF.
IF flg_one IS INITIAL.
flg_one = 'X'.
icon_one = i_layout-id.
b_one = sscrfields-ucomm.
ELSEIF flg_two IS INITIAL.
flg_two = 'X'.
icon_two = i_layout-id.
b_two = sscrfields-ucomm.
ENDIF.
ENDIF.
IF icon_one = icon_two.
p_tries = p_tries + 1.
DELETE i_layout WHERE id = icon_one.
CLEAR : flg_one,flg_two,icon_one,icon_two.
ENDIF.
IF NOT flg_two IS INITIAL.
p_tries = p_tries + 1.
ENDIF.

ENDFORM. " validate
*&---------------------------------------------------------------------*
*& Form do_initialization
*&---------------------------------------------------------------------*
* Make all the buttons show blank space. Also select, the list of
* all icons from the standard table and select 32 from it randomly. Once
* the 32 icons are selected, lay it out in pairs on the 8 X 8 board of
* buttons.
*----------------------------------------------------------------------*
*----------------------------------------------------------------------*
FORM do_initialization.


MESSAGE i001(00) WITH 'Welcome to the Memory Game!!!'.

DATA: lv_score TYPE numc4,
lv_name TYPE uname.

*l_second.
*h_second.
SELECT MAX( sc_seconds ) FROM zmemory INTO lv_score WHERE uname = sy-uname.
IF sy-subrc NE 0.
l_score = 'Not Completed Game Yet'.
ELSE.
CONCATENATE lv_score space INTO h_second SEPARATED BY space.
ENDIF.
CLEAR: lv_score.

SELECT MIN( sc_seconds ) FROM zmemory INTO lv_score WHERE uname = sy-uname.
IF sy-subrc NE 0.
l_score = 'Not Completed Game Yet'.
ELSE.
CONCATENATE lv_score space INTO l_second SEPARATED BY space.
ENDIF.
CLEAR: lv_score.



SELECT MAX( sc_tries ) FROM zmemory INTO lv_score WHERE uname = sy-uname.
IF sy-subrc NE 0.
p_score = 'Your Previous Score is ZERO'.
ELSE.
CONCATENATE lv_score space INTO l_score SEPARATED BY space.
ENDIF.
CLEAR: lv_score.

SELECT MIN( sc_tries ) FROM zmemory INTO lv_score WHERE uname = sy-uname.
IF sy-subrc NE 0.
p_score = 'Your Previous Score is ZERO'.
ELSE.
CONCATENATE lv_score space INTO p_score SEPARATED BY space.
ENDIF.

CLEAR lv_score.

SELECT MIN( sc_tries ) FROM zmemory INTO lv_score.
IF sy-subrc NE 0.
h_score = 'Higest Score is ZERO'.
ELSE.
SELECT SINGLE * FROM zmemory INTO ls_memory WHERE sc_tries = lv_score.
CONCATENATE lv_score 'by' ls_memory-uname 'on' ls_memory-sc_date INTO h_score SEPARATED BY space.
ENDIF.

CLEAR lv_score.
SELECT MAX( sc_tries ) FROM zmemory INTO lv_score.
IF sy-subrc NE 0.
plow_sc = 'Lowest Score is ZERO'.
ELSE.
SELECT SINGLE * FROM zmemory INTO ls_memory WHERE sc_tries = lv_score.
CONCATENATE lv_score 'by' ls_memory-uname 'on' ls_memory-sc_date INTO plow_sc SEPARATED BY space.
ENDIF.

* Time
SELECT MIN( sc_seconds ) FROM zmemory INTO lv_score.
IF sy-subrc NE 0.
h_score = 'No One Played Yet'.
ELSE.
SELECT SINGLE * FROM zmemory INTO ls_memory WHERE sc_seconds = lv_score.
CONCATENATE lv_score 'secs -' ls_memory-uname INTO y_second SEPARATED BY space.
ENDIF.

CLEAR lv_score.
SELECT MAX( sc_seconds ) FROM zmemory INTO lv_score.
IF sy-subrc NE 0.
h_score = 'No One Played Yet'.
ELSE.
SELECT SINGLE * FROM zmemory INTO ls_memory WHERE sc_seconds = lv_score.
CONCATENATE lv_score 'secs -' ls_memory-uname INTO z_second SEPARATED BY space.
ENDIF.



title = 'Watch the Clock. The time is runnig so Hurry !'.
yu_score = 'Your Best/Worst Score'.
lu_secon = 'Your Best/Worst Time'.
no_tries = 'No. of Tries/Time(Sec)'.
hu_score = 'Best Score'.
low_sc = 'Worst Score'.
yu_secon = 'Overall Min/Max Time'.

pb11 = pb12 = pb13 = pb14 = pb15 = pb16 = pb17 = pb18 = icon_space.
pb21 = pb22 = pb23 = pb24 = pb25 = pb26 = pb27 = pb28 = icon_space.
pb31 = pb32 = pb33 = pb34 = pb35 = pb36 = pb37 = pb38 = icon_space.
pb41 = pb42 = pb43 = pb44 = pb45 = pb46 = pb47 = pb48 = icon_space.
pb51 = pb52 = pb53 = pb54 = pb55 = pb56 = pb57 = pb58 = icon_space.
pb61 = pb62 = pb63 = pb64 = pb65 = pb66 = pb67 = pb68 = icon_space.
pb71 = pb72 = pb73 = pb74 = pb75 = pb76 = pb77 = pb78 = icon_space.
pb81 = pb82 = pb83 = pb84 = pb85 = pb86 = pb87 = pb88 = icon_space.
SELECT id FROM icon INTO TABLE i_icons
WHERE NOT id IN ('@5F@','@E5@','@00@','@E6@','@E7@',
'@EI@','@GE@','@GG@','@JX@','@JY@',
'@JZ@','@K0@').
DESCRIBE TABLE i_icons LINES len.
CLEAR : subrc.
WHILE subrc < 32.
CALL FUNCTION 'QF05_RANDOM_INTEGER'
EXPORTING
ran_int_max = len
ran_int_min = 1
IMPORTING
ran_int = ran_no
EXCEPTIONS
invalid_input = 1
OTHERS = 2.
READ TABLE i_icons INDEX ran_no.
READ TABLE i_iconlist WITH KEY id = i_icons-id.
IF sy-subrc <> 0.
i_iconlist-id = i_icons-id.
APPEND i_iconlist.
ENDIF.
DESCRIBE TABLE i_iconlist LINES subrc.
ENDWHILE.
REFRESH : i_icons.
CLEAR : subrc.
WHILE subrc < 64.
IF subrc <> 0.
READ TABLE i_layout INDEX subrc.
IF i_layout-col = 8.
i_layout-col = 1.
i_layout-row = i_layout-row + 1.
ELSE.
i_layout-col = i_layout-col + 1.
ENDIF.
ELSE.
i_layout-row = 1.
i_layout-col = 1.
ENDIF.
CLEAR : count,i_iconlist.
CALL FUNCTION 'QF05_RANDOM_INTEGER'
EXPORTING
ran_int_max = 32
ran_int_min = 1
IMPORTING
ran_int = ran_no
EXCEPTIONS
invalid_input = 1
OTHERS = 2.
READ TABLE i_iconlist INDEX ran_no.
LOOP AT i_layout INTO w_layout WHERE id = i_iconlist-id.
count = count + 1.
ENDLOOP.
IF count < 2.
i_layout-id = i_iconlist-id.
APPEND i_layout.
ENDIF.
CLEAR : i_layout.
DESCRIBE TABLE i_layout LINES subrc.
ENDWHILE.
CLEAR : flg_one,flg_two,icon_one,icon_two, current_ucomm.

ENDFORM. " do_initialization



Game Marbles

REPORT zmarbles NO STANDARD PAGE HEADING.
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* I N C L U D E
*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
INCLUDE .

*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*
* 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: 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 .
IF l_no_s = l_half
AND l_no_m = l_half.
= '0'.
w_total = w_total - 1.
ELSE.
= '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: 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 .
CLEAR l_name.
CONCATENATE 'WA_PRINT-C' l_no_c INTO l_name.
ASSIGN (l_name) TO .
CASE .
WHEN '1'.
= icon_1.
WHEN '0'.
= icon_0.
WHEN '2'.
= 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: 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 .
IF NOT IS INITIAL.
WRITE: (2) 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: TYPE ANY,
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 .
* value = 0 >> No marble
IF = '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 .
IF = '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 .
IF = '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 = '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 = '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'.
= '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: 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 .
IF = '2'.
= '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: 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 .
* Destination should be empty
IF <> '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: 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 .
IF = 1.
= '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 .
IF = 1.
= '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 .
= '1'.
MODIFY itab FROM l_itab INDEX w_dest_line.
CLEAR l_itab.
* Make Selected = 0.
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 .
= '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 .
= '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: TYPE ANY,
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 .
IF IS INITIAL
OR = '0'.
CONTINUE.
ENDIF.
* IF = '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 .
IF = '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 .
IF = '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 .
IF = '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 .
IF = '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 .
* 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 = '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 = '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 = '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 = '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