Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
former_member209696
Participant

Refer the below code for creation of number puzzle.

CODE

REPORT  ze00707_sup.

SELECTION-
SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-001.
SELECTION-
SCREEN PUSHBUTTON /14(3)  bt1 USER-COMMAND BT1.
SELECTION-
SCREEN PUSHBUTTON  18(3)  bt2 USER-COMMAND BT2.
SELECTION-
SCREEN PUSHBUTTON  22(3)  bt3 USER-COMMAND BT3.
SELECTION-
SCREEN PUSHBUTTON /14(3)  bt4 USER-COMMAND bt4.
SELECTION-
SCREEN PUSHBUTTON  18(3)  bt5 USER-COMMAND bt5.
SELECTION-
SCREEN PUSHBUTTON  22(3)  bt6 USER-COMMAND bt6.
SELECTION-
SCREEN PUSHBUTTON  28(8)  rst USER-COMMAND rst.
SELECTION-
SCREEN PUSHBUTTON /14(3)  bt7 USER-COMMAND bt7.
SELECTION-
SCREEN PUSHBUTTON  18(3)  bt8 USER-COMMAND bt8.
SELECTION-
SCREEN PUSHBUTTON  22(3)  bt9 USER-COMMAND bt9.
SELECTION-
SCREEN END OF BLOCK b1.

DATA : flag TYPE i VALUE 1.

*----------------------------------------------------------------------*
*       CLASS lcl_super DEFINITION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_super DEFINITION.
PUBLIC SECTION.
METHODS initial.
METHODS invisible IMPORTING btn_name TYPE char10.
METHODS value_exchange IMPORTING bt_text1 TYPE c
EXPORTING bt_text2 TYPE c.
METHODS success.
ENDCLASS.                    "lcl_super DEFINITION


*----------------------------------------------------------------------*
*       CLASS lcl_super IMPLEMENTATION
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
CLASS lcl_super IMPLEMENTATION.

METHOD initial.
MOVE '2' TO bt1.
MOVE '3' TO bt2.
MOVE '5' TO bt3.
MOVE '1' TO bt4.
MOVE '6' TO bt5.
MOVE '8' TO bt6.
MOVE '7' TO bt7.
MOVE '4' TO bt8.
MOVE ' ' TO bt9.
move 'Reset' to rst.
LOOP AT SCREEN.
IF screen-name = 'BT9'.
screen-invisible = 1.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDMETHOD.                    "initial

METHOD invisible.
LOOP AT SCREEN.
IF screen-name = btn_name.
screen-invisible = 1.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
ENDMETHOD.                    "invisible

METHOD value_exchange.
move bt_text1 to bt_text2.
ENDMETHOD.                    "Value_exchange

METHOD success.
IF bt1 = 1 and
bt2 =
2 and
bt3 =
3 and
bt4 =
4 and
bt5 =
5 and
bt6 =
6 and
bt7 =
7 and
bt8 =
8 .
MESSAGE 'You won' TYPE 'S'.
ENDIF.
ENDMETHOD.
ENDCLASS.                    "lcl_super IMPLEMENTATION

START-
OF-SELECTION.


AT SELECTION-SCREEN OUTPUT.
DATA : l_ref TYPE REF TO lcl_super.
CREATE OBJECT l_ref.
if flag ne 1.
l_ref->success( ).
ENDIF.
IF flag = 1.
CALL METHOD l_ref->initial( ).
ELSEif bt1 is INITIAL.
call METHOD l_ref->invisible EXPORTING btn_name = 'BT1'.
ELSEIF bt2 is INITIAL.
call METHOD l_ref->invisible EXPORTING btn_name = 'BT2'.
ELSEIF bt3 is INITIAL.
call METHOD l_ref->invisible EXPORTING btn_name = 'BT3'.
ELSEIF bt4 is INITIAL.
call METHOD l_ref->invisible EXPORTING btn_name = 'BT4'.
ELSEIF bt5 is INITIAL.
call METHOD l_ref->invisible EXPORTING btn_name = 'BT5'.
ELSEIF bt6 is INITIAL.
call METHOD l_ref->invisible EXPORTING btn_name = 'BT6'.
ELSEIF bt7 is INITIAL.
call METHOD l_ref->invisible EXPORTING btn_name = 'BT7'.
ELSEIF bt8 is INITIAL.
call METHOD l_ref->invisible EXPORTING btn_name = 'BT8'.
ELSEIF bt9 is INITIAL.
call METHOD l_ref->invisible EXPORTING btn_name = 'BT9'.
ENDIF.

AT SELECTION-SCREEN.
flag = flag +
1.
DATA : l_ref TYPE REF TO lcl_super.
CREATE OBJECT l_ref.

if bt1 is INITIAL.
if sy-ucomm = 'BT2'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt2
IMPORTING bt_text2 = bt1 ).
CLEAR bt2.
elseif sy-ucomm = 'BT4'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt4
IMPORTING bt_text2 = bt1 ).
CLEAR bt4.
endif.
endif.

if bt2 is INITIAL.
if sy-ucomm = 'BT1'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt1
IMPORTING bt_text2 = bt2 ).
CLEAR bt1.
elseif sy-ucomm = 'BT3'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt3
IMPORTING bt_text2 = bt2 ).
CLEAR bt3.
elseif sy-ucomm = 'BT5'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt5
IMPORTING bt_text2 = bt2 ).
CLEAR bt5.
endif.
endif.


if bt3 is INITIAL.
if sy-ucomm = 'BT2'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt2
IMPORTING bt_text2 = bt3 ).
CLEAR bt2.
elseif sy-ucomm = 'BT6'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt6
IMPORTING bt_text2 = bt3 ).
CLEAR bt6.
endif.
endif.

if bt4 is INITIAL.
if sy-ucomm = 'BT1'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt1
IMPORTING bt_text2 = bt4 ).
clear bt1.
elseif sy-ucomm = 'BT5'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt5
IMPORTING bt_text2 = bt4 ).
clear bt5.
elseif sy-ucomm = 'BT7'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt7
IMPORTING bt_text2 = bt4 ).
clear bt7.
endif.
endif.

if bt5 is INITIAL.
if sy-ucomm = 'BT2'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt2
IMPORTING bt_text2 = bt5 ).
clear bt2.
elseif sy-ucomm = 'BT4'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt4
IMPORTING bt_text2 = bt5 ).
clear bt4.
elseif sy-ucomm = 'BT6'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt6
IMPORTING bt_text2 = bt5 ).
clear bt6.
elseif sy-ucomm = 'BT8'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt8
IMPORTING bt_text2 = bt5 ).
clear bt8.
endif.
endif.

if bt6 is INITIAL.
if sy-ucomm = 'BT3'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt3
IMPORTING bt_text2 = bt6 ).
clear bt3.
elseif sy-ucomm = 'BT5'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt5
IMPORTING bt_text2 = bt6 ).
clear bt5.
elseif sy-ucomm = 'BT9'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt9
IMPORTING bt_text2 = bt6 ).
clear bt9.
endif.
endif.


if bt7 is INITIAL.
if sy-ucomm = 'BT4'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt4
IMPORTING bt_text2 = bt7 ).
clear bt4.
elseif sy-ucomm = 'BT8'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt8
IMPORTING bt_text2 = bt7 ).
clear bt8.
endif.
endif.

if bt8 is INITIAL.
if sy-ucomm = 'BT9'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt9
IMPORTING bt_text2 = bt8 ).
clear bt9.
elseif sy-ucomm = 'BT7'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt7
IMPORTING bt_text2 = bt8 ).
clear bt7.
elseif sy-ucomm = 'BT5'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt5
IMPORTING bt_text2 = bt8 ).
clear bt5.
endif.
endif.


if bt9 is INITIAL.
if sy-ucomm = 'BT6'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt6
IMPORTING bt_text2 = bt9 ).
clear bt6.
elseif sy-ucomm = 'BT8'.
l_ref->value_exchange(
EXPORTING bt_text1 = bt8
IMPORTING bt_text2 = bt9 ).
clear bt8.
endif.

if sy-ucomm = 'RST'.
flag =
1.
endif.
endif.


4 Comments