Introduction
Water puzzle in sap. This is developed using dialog programming with simple logical expressions
Developed a material master dashboard using dialog program for our company to automate the material master creation from different units. This dashboard will collect the request from users and create the material codes using BAPI. Once the material is created an email will be send to the requester. The status of the request also can be viewed through this dashboard.
While developing this dashboard, I just had an idea to develop this game in SAP. This development has given great interest and good confidence in dialog program. Through this we can be able to learn Screen design, Screen flows, flow logic’s, logical expressions, etc.
Pre requisite
Basic knowledge in dialog programming
Steps to be followed
1. Create a program in SE80 with type Module Pool
2. Create a screen with type Normal
3. Go to screen layout and design the output according to the requirement
4. Go to flow logic and build the query
5. Create GUI Status, Titile and Transaction code
6. Run the transaction
7. How to Play
8. How it works(Code Snippet)
STEP 1
Create a program in SE80 with type Module Pool
STEP 2
Create a Normal Screen
STEP 3
Go to screen layout and design the output according to the requirement
Create function codes for push buttons
MO85 -> Move from 8L to 5L
MO83 -> Move from 8L to 3L
MO58 ->Move from 5L to 8L
MO53 -> Move from 5L to 3L
MO38 -> Move from 3L to 8L
MO35 -> Move from 3L to 5L
In Element list you have to define the attribute ok_code to validate the user commands
STEP 4
Go to flow logic and build the query
STEP 5
Create GUI Status, Title and Transaction code
STEP 6
Run the transaction
STEP 7
How to Play
Assume that there are three glasses on the screen like 8, 5, and 3 oz. Last two are empty, the first one contains 8 oz. of water. By pouring water from one glass to another make at least one of them contain exactly 4 oz. of water.
Pouring water from/to, use push buttons. Clear button will reset the numbers to 0 in 5L and 3L and set to 8 in 8L.
Output
OR
STEP 8
How it works (Code Snippet)
This logic can be written in a different way too and here I have explained it in a simplest way.
*&---------------------------------------------------------------------*
*& Module Pool ZTH_GLASS
*&
*&---------------------------------------------------------------------*
*&
*&
*&---------------------------------------------------------------------*
PROGRAM zth_glass.
DATA : glass8(12) TYPE c,
glass5(12) TYPE c,
glass3(12) TYPE c.
DATA : ok_code TYPE sy-ucomm,
flag TYPE c.
*&---------------------------------------------------------------------*
*& Module STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE status_0100 OUTPUT.
SET PF-STATUS 'STATUS'.
IF flag IS INITIAL.
glass8 = '8'.
ENDIF.
SET TITLEBAR 'WATER'.
ENDMODULE. " STATUS_0100 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
flag = 'X'.
CASE ok_code.
WHEN 'MO85'.
IF glass8 EQ 8.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass8 = glass8 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass8 = glass8 - 2.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 3.
glass8 = glass8 - 3.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 4.
glass8 = glass8 - 4.
ELSEIF glass5 EQ 0.
glass5 = glass5 + 5.
glass8 = glass8 - 5.
ENDIF.
ELSEIF glass8 EQ 7.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass8 = glass8 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass8 = glass8 - 2.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 3.
glass8 = glass8 - 3.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 4.
glass8 = glass8 - 4.
ELSEIF glass5 EQ 0.
glass5 = glass5 + 5.
glass8 = glass8 - 5.
ENDIF.
ELSEIF glass8 EQ 6.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass8 = glass8 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass8 = glass8 - 2.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 3.
glass8 = glass8 - 3.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 4.
glass8 = glass8 - 4.
ELSEIF glass5 EQ 0.
glass5 = glass5 + 5.
glass8 = glass8 - 5.
ENDIF.
ELSEIF glass8 EQ 5.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass8 = glass8 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass8 = glass8 - 2.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 3.
glass8 = glass8 - 3.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 4.
glass8 = glass8 - 4.
ELSEIF glass5 EQ 0.
glass5 = glass5 + 5.
glass8 = glass8 - 5.
ENDIF.
ELSEIF glass8 EQ 4.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass8 = glass8 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass8 = glass8 - 2.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 3.
glass8 = glass8 - 3.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 4.
glass8 = glass8 - 4.
ENDIF.
ELSEIF glass8 EQ 3.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass8 = glass8 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass8 = glass8 - 2.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 3.
glass8 = glass8 - 3.
ENDIF.
ELSEIF glass8 EQ 2.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass8 = glass8 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass8 = glass8 - 2.
ENDIF.
ELSEIF glass8 EQ 1.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass8 = glass8 - 1.
ENDIF.
ENDIF.
WHEN 'MO83'.
IF glass8 EQ 8.
IF glass3 EQ 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass8 = glass8 - 1.
ELSEIF glass3 EQ 1.
glass3 = glass3 + 2.
glass8 = glass8 - 2.
ELSEIF glass3 EQ 0.
glass3 = glass3 + 3.
glass8 = glass8 - 3.
ENDIF.
ELSEIF glass8 EQ 7.
IF glass3 EQ 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass8 = glass8 - 1.
ELSEIF glass3 EQ 1.
glass3 = glass3 + 2.
glass8 = glass8 - 2.
ELSEIF glass3 EQ 0.
glass3 = glass3 + 3.
glass8 = glass8 - 3.
ENDIF.
ELSEIF glass8 EQ 6.
IF glass3 EQ 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass8 = glass8 - 1.
ELSEIF glass3 EQ 1.
glass3 = glass3 + 2.
glass8 = glass8 - 2.
ELSEIF glass3 EQ 0.
glass3 = glass3 + 3.
glass8 = glass8 - 3.
ENDIF.
ELSEIF glass8 EQ 5.
IF glass3 EQ 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass8 = glass8 - 1.
ELSEIF glass3 EQ 1.
glass3 = glass3 + 2.
glass8 = glass8 - 2.
ELSEIF glass3 EQ 0.
glass3 = glass3 + 3.
glass8 = glass8 - 3.
ENDIF.
ELSEIF glass8 EQ 4.
IF glass3 EQ 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass8 = glass8 - 1.
ELSEIF glass3 EQ 1.
glass3 = glass3 + 2.
glass8 = glass8 - 2.
ELSEIF glass3 EQ 0.
glass3 = glass3 + 3.
glass8 = glass8 - 3.
ENDIF.
ELSEIF glass8 EQ 3.
IF glass3 EQ 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass8 = glass8 - 1.
ELSEIF glass3 EQ 1.
glass3 = glass3 + 2.
glass8 = glass8 - 2.
ELSEIF glass3 EQ 0.
glass3 = glass3 + 3.
glass8 = glass8 - 3.
ENDIF.
ELSEIF glass8 EQ 2.
IF glass3 EQ 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass8 = glass8 - 1.
ENDIF.
ELSEIF glass8 EQ 1.
IF glass3 EQ 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass8 = glass8 - 1.
ENDIF.
ENDIF.
WHEN 'MO53'.
IF glass5 EQ 5.
IF glass3 GE 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass5 = glass5 - 1.
ELSEIF glass3 EQ 1.
glass3 = glass3 + 2.
glass5 = glass5 - 2.
ELSEIF glass3 EQ 0.
glass3 = glass3 + 3.
glass5 = glass5 - 3.
ENDIF.
ELSEIF glass5 EQ 4.
IF glass3 GE 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass5 = glass5 - 1.
ELSEIF glass3 EQ 1.
glass3 = glass3 + 2.
glass5 = glass5 - 2.
ENDIF.
ELSEIF glass5 EQ 3.
IF glass3 GE 3.
ELSEIF glass3 EQ 2.
glass3 = glass3 + 1.
glass5 = glass5 - 1.
ELSEIF glass3 EQ 1.
glass3 = glass3 + 2.
glass5 = glass5 - 2.
ENDIF.
ELSEIF glass5 EQ 2.
ELSEIF glass5 EQ 1.
ENDIF.
WHEN 'MO58'.
IF glass5 EQ 5.
IF glass8 EQ 8.
ELSEIF glass8 EQ 7.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 6.
glass8 = glass8 + 2.
glass5 = glass5 - 2.
ELSEIF glass8 EQ 5.
glass8 = glass8 + 3.
glass5 = glass5 - 3.
ELSEIF glass8 EQ 4.
glass8 = glass8 + 4.
glass5 = glass5 - 4.
ELSEIF glass8 EQ 3.
glass8 = glass8 + 5.
glass5 = glass5 - 5.
ELSEIF glass8 EQ 2.
glass8 = glass8 + 5.
glass5 = glass5 - 5.
ELSEIF glass8 EQ 1.
glass8 = glass8 + 5.
glass5 = glass5 - 5.
ELSEIF glass8 EQ 0.
glass8 = glass8 + 5.
glass5 = glass5 - 5.
ENDIF.
ELSEIF glass5 EQ 4.
IF glass8 EQ 8.
ELSEIF glass8 EQ 7.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 6.
glass8 = glass8 + 2.
glass5 = glass5 - 2.
ELSEIF glass8 EQ 5.
glass8 = glass8 + 3.
glass5 = glass5 - 3.
ELSEIF glass8 EQ 4.
glass8 = glass8 + 4.
glass5 = glass5 - 4.
ELSEIF glass8 EQ 3.
glass8 = glass8 + 4.
glass5 = glass5 - 4.
ELSEIF glass8 EQ 2.
glass8 = glass8 + 4.
glass5 = glass5 - 4.
ELSEIF glass8 EQ 1.
glass8 = glass8 + 4.
glass5 = glass5 - 4.
ELSEIF glass8 EQ 0.
glass8 = glass8 + 4.
glass5 = glass5 - 4.
ENDIF.
ELSEIF glass5 EQ 3.
IF glass8 EQ 8.
ELSEIF glass8 EQ 7.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 6.
glass8 = glass8 + 2.
glass5 = glass5 - 2.
ELSEIF glass8 EQ 5.
glass8 = glass8 + 3.
glass5 = glass5 - 3.
ELSEIF glass8 EQ 4.
glass8 = glass8 + 3.
glass5 = glass5 - 3.
ELSEIF glass8 EQ 3.
glass8 = glass8 + 3.
glass5 = glass5 - 3.
ELSEIF glass8 EQ 2.
glass8 = glass8 + 3.
glass5 = glass5 - 3.
ELSEIF glass8 EQ 1.
glass8 = glass8 + 3.
glass5 = glass5 - 3.
ELSEIF glass8 EQ 0.
glass8 = glass8 + 3.
glass5 = glass5 - 3.
ENDIF.
ELSEIF glass5 EQ 2.
IF glass8 EQ 8.
ELSEIF glass8 EQ 7.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 6.
glass8 = glass8 + 2.
glass5 = glass5 - 2.
ELSEIF glass8 EQ 5.
glass8 = glass8 + 2.
glass5 = glass5 - 2.
ELSEIF glass8 EQ 4.
glass8 = glass8 + 2.
glass5 = glass5 - 2.
ELSEIF glass8 EQ 3.
glass8 = glass8 + 2.
glass5 = glass5 - 2.
ELSEIF glass8 EQ 2.
glass8 = glass8 + 2.
glass5 = glass5 - 2.
ELSEIF glass8 EQ 1.
glass8 = glass8 + 2.
glass5 = glass5 - 2.
ELSEIF glass8 EQ 0.
glass8 = glass8 + 2.
glass5 = glass5 - 2.
ENDIF.
ELSEIF glass5 EQ 1.
IF glass8 EQ 8.
ELSEIF glass8 EQ 7.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 6.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 5.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 4.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 3.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 2.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 1.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ELSEIF glass8 EQ 0.
glass8 = glass8 + 1.
glass5 = glass5 - 1.
ENDIF.
ENDIF.
WHEN 'MO35'.
IF glass3 EQ 3.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass3 = glass3 - 2.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 3.
glass3 = glass3 - 3.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 3.
glass3 = glass3 - 3.
ELSEIF glass5 EQ 0.
glass5 = glass5 + 3.
glass3 = glass3 - 3.
ENDIF.
ELSEIF glass3 EQ 2.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass3 = glass3 - 2.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 2.
glass3 = glass3 - 2.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 2.
glass3 = glass3 - 2.
ELSEIF glass5 EQ 0.
glass5 = glass5 + 2.
glass3 = glass3 - 2.
ENDIF.
ELSEIF glass3 EQ 1.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 0.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ENDIF.
ENDIF.
WHEN 'MO38'.
IF glass3 EQ 3.
IF glass8 EQ 8.
ELSEIF glass8 EQ 7.
glass8 = glass8 + 1.
glass3 = glass3 - 1.
ELSEIF glass8 EQ 6.
glass8 = glass8 + 2.
glass3 = glass3 - 2.
ELSEIF glass8 EQ 5.
glass8 = glass8 + 3.
glass3 = glass3 - 3.
ELSEIF glass8 EQ 4.
glass8 = glass8 + 3.
glass3 = glass3 - 3.
ELSEIF glass8 EQ 3.
glass8 = glass8 + 3.
glass3 = glass3 - 3.
ELSEIF glass8 EQ 2.
glass8 = glass8 + 3.
glass3 = glass3 - 3.
ELSEIF glass8 EQ 1.
glass8 = glass8 + 3.
glass3 = glass3 - 3.
ELSEIF glass8 EQ 0.
glass8 = glass8 + 3.
glass3 = glass3 - 3.
ENDIF.
ELSEIF glass3 EQ 2.
IF glass8 EQ 8.
ELSEIF glass8 EQ 7.
glass8 = glass8 + 1.
glass3 = glass3 - 1.
ELSEIF glass8 EQ 6.
glass8 = glass8 + 2.
glass3 = glass3 - 2.
ELSEIF glass8 EQ 5.
glass8 = glass8 + 2.
glass3 = glass3 - 2.
ELSEIF glass8 EQ 4.
glass8 = glass8 + 2.
glass3 = glass3 - 2.
ELSEIF glass8 EQ 3.
glass8 = glass8 + 2.
glass3 = glass3 - 2.
ELSEIF glass8 EQ 2.
glass8 = glass8 + 2.
glass3 = glass3 - 2.
ELSEIF glass8 EQ 1.
glass8 = glass8 + 2.
glass3 = glass3 - 2.
ELSEIF glass8 EQ 0.
glass8 = glass8 + 2.
glass3 = glass3 - 2.
ENDIF.
ELSEIF glass3 EQ 1.
IF glass8 EQ 8.
ELSEIF glass8 EQ 7.
glass8 = glass8 + 1.
glass3 = glass3 - 1.
ELSEIF glass8 EQ 6.
glass8 = glass8 + 1.
glass3 = glass3 - 1.
ELSEIF glass8 EQ 5.
glass8 = glass8 + 1.
glass3 = glass3 - 1.
ELSEIF glass8 EQ 4.
glass8 = glass8 + 1.
glass3 = glass3 - 1.
ELSEIF glass8 EQ 3.
glass8 = glass8 + 1.
glass3 = glass3 - 1.
ELSEIF glass8 EQ 2.
glass8 = glass8 + 1.
glass3 = glass3 - 1.
ELSEIF glass8 EQ 1.
glass8 = glass8 + 1.
glass3 = glass3 - 1.
ELSEIF glass8 EQ 0.
glass8 = glass8 + 1.
glass3 = glass3 - 1.
ENDIF.
ENDIF.
WHEN 'MO35'.
IF glass3 EQ 3.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass3 = glass3 - 2.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 3.
glass3 = glass3 - 3.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 3.
glass3 = glass3 - 3.
ELSEIF glass5 EQ 0.
glass5 = glass5 + 3.
glass3 = glass3 - 3.
ENDIF.
ELSEIF glass3 EQ 2.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 2.
glass3 = glass3 - 2.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 2.
glass3 = glass3 - 2.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 2.
glass3 = glass3 - 2.
ELSEIF glass5 EQ 0.
glass5 = glass5 + 2.
glass3 = glass3 - 2.
ENDIF.
ELSEIF glass3 EQ 1.
IF glass5 EQ 5.
ELSEIF glass5 EQ 4.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 3.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 2.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 1.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ELSEIF glass5 EQ 0.
glass5 = glass5 + 1.
glass3 = glass3 - 1.
ENDIF.
ENDIF.
WHEN 'CLER'.
glass5 = 0.
glass3 = 0.
glass8 = 8.
WHEN 'BACK'.
SET SCREEN 0.
LEAVE TO SCREEN 0.
ENDCASE.
ENDMODULE. " USER_COMMAND_0100 INPUT
http://2048games.info/
ReplyDelete