Wednesday, May 21, 2008
Some SAP and ABAP Short Cuts
Some SAP and ABAP Short Cuts
Find below a list of some useful ABAP short cuts.
General command field formats
/n Skip to the next record if you are processing one batch input session
/bend Cancel a batch input foreground process
/nend Close all R/3 sessions and logoff with a dialog prompt
/nxxxx Call the transaction xxxx in the same session
/o Generate a session list
/oxxxx Call the transaction xxxx in an additional session
/i Delete the current session
/h Turn the debug mode on
/Nex Close all R/3 sessions and logoff without a dialog prompt
Special copy and paste
Click on the area and press CTRL+Y. It allows you to copy many lines at once and paste them afterwards.
Find below a list of some useful ABAP short cuts.
General command field formats
/n Skip to the next record if you are processing one batch input session
/bend Cancel a batch input foreground process
/nend Close all R/3 sessions and logoff with a dialog prompt
/nxxxx Call the transaction xxxx in the same session
/o Generate a session list
/oxxxx Call the transaction xxxx in an additional session
/i Delete the current session
/h Turn the debug mode on
/Nex Close all R/3 sessions and logoff without a dialog prompt
Special copy and paste
Click on the area and press CTRL+Y. It allows you to copy many lines at once and paste them afterwards.
Labels:
Copy Paste,
SAPand ABAP Short Cuts
ABAP Game Tic-Tac-Toe
ABAP Game Tic-Tac-Toe
Please find below a game written in ABAP, this is the famous Tic Tac Toe game.
This is GPL Code
Please find below a game written in ABAP, this is the famous Tic Tac Toe game.
This is GPL Code
REPORT ZEX_TICTACTOE1 .
*&---------------------------------------------------------------------*
*& Report ZTic-tac-toe *
*& *
*&---------------------------------------------------------------------*
* Game Tic-tac-toe in ABAP - GPL Licence. *
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------*
INCLUDE CTSICONS."ICONS FOR THE GAME.
*----------------------------------------------------------------------*
* GLOBAL VARIABLES *
*----------------------------------------------------------------------*
DATA: v_turn(1) VALUE 'X',"Select card.
v_win(1) VALUE ' '."Win a player(X) or tie(-)!
*----------------------------------------------------------------------*
* SELECTION-SCREEN *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (4) icon1 USER-COMMAND uc_icon1."1x1
SELECTION-SCREEN PUSHBUTTON (4) icon2 USER-COMMAND uc_icon2."2x1
SELECTION-SCREEN PUSHBUTTON (4) icon3 USER-COMMAND uc_icon3."3x1
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (4) icon4 USER-COMMAND uc_icon4."1x2
SELECTION-SCREEN PUSHBUTTON (4) icon5 USER-COMMAND uc_icon5."2x2
SELECTION-SCREEN PUSHBUTTON (4) icon6 USER-COMMAND uc_icon6."3x2
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (4) icon7 USER-COMMAND uc_icon7."1x3
SELECTION-SCREEN PUSHBUTTON (4) icon8 USER-COMMAND uc_icon8."2x3
SELECTION-SCREEN PUSHBUTTON (4) icon9 USER-COMMAND uc_icon9."3x3
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (12) restart USER-COMMAND uc_restart.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'UC_ICON1'.
PERFORM push_button USING icon1.
WHEN 'UC_ICON2'.
PERFORM push_button USING icon2.
WHEN 'UC_ICON3'.
PERFORM push_button USING icon3.
WHEN 'UC_ICON4'.
PERFORM push_button USING icon4.
WHEN 'UC_ICON5'.
PERFORM push_button USING icon5.
WHEN 'UC_ICON6'.
PERFORM push_button USING icon6.
WHEN 'UC_ICON7'.
PERFORM push_button USING icon7.
WHEN 'UC_ICON8'.
PERFORM push_button USING icon8.
WHEN 'UC_ICON9'.
PERFORM push_button USING icon9.
WHEN 'UC_RESTART'.
PERFORM restart_game.
ENDCASE.
*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
PERFORM clear_buttons.
*&---------------------------------------------------------------------*
*& Form clear_buttons
*&---------------------------------------------------------------------*
* Clear the buttons of Selection-Screen.
*----------------------------------------------------------------------*
FORM clear_buttons .
icon1 = '@5F@' .
icon2 = '@5F@' .
icon3 = '@5F@' .
icon4 = '@5F@' .
icon5 = '@5F@' .
icon6 = '@5F@' .
icon7 = '@5F@' .
icon8 = '@5F@' .
icon9 = '@5F@' .
restart = 'Restart'.
ENDFORM." clear_buttons
*&---------------------------------------------------------------------*
*& Form push_button
*&---------------------------------------------------------------------*
* Checks when a user push a button.
*----------------------------------------------------------------------*
* --> p_icon Button pushed
*----------------------------------------------------------------------*
FORM push_button USING p_icon.
* Exit if button pushed.
IF p_icon <> '@5F@'.
EXIT.
ENDIF.
* Change icon.
IF v_turn IS INITIAL.
p_icon = '@7C@'.
v_turn = 'X'.
ELSE.
p_icon = '@C9@'.
CLEAR v_turn.
ENDIF.
* Check winner
IF ( icon1 = icon5 AND icon5 = icon9 AND icon1 <> '@5F@' )"Diagonal \
OR ( icon3 = icon5 AND icon5 = icon7 AND icon3 <> '@5F@' )"Diagonal /
OR ( icon1 = icon2 AND icon2 = icon3 AND icon1 <> '@5F@' )"Row 1 -
OR ( icon4 = icon5 AND icon5 = icon6 AND icon4 <> '@5F@' )"Row 2 -
OR ( icon7 = icon8 AND icon8 = icon9 AND icon7 <> '@5F@' )"Row 3 -
OR ( icon1 = icon4 AND icon4 = icon7 AND icon1 <> '@5F@' )"Col 1 |
OR ( icon2 = icon5 AND icon5 = icon8 AND icon2 <> '@5F@' )"Col 2 |
OR ( icon3 = icon6 AND icon6 = icon9 AND icon3 <> '@5F@' )."Col 3 |
v_win = 'X'.
ENDIF.
* Check tie
IF v_win IS INITIAL
AND icon1 <> '@5F@'
AND icon2 <> '@5F@'
AND icon3 <> '@5F@'
AND icon4 <> '@5F@'
AND icon5 <> '@5F@'
AND icon6 <> '@5F@'
AND icon7 <> '@5F@'
AND icon8 <> '@5F@'
AND icon9 <> '@5F@'.
v_win = '-'.
ENDIF.
* Winner or tie?
CASE v_win.
* Winner
WHEN 'X'.
IF v_turn IS INITIAL.
MESSAGE i398(00) WITH 'Win player 1!'.
PERFORM restart_game.
ELSE.
MESSAGE i398(00) WITH 'Win player 2!'.
PERFORM restart_game.
ENDIF.
* Tie
WHEN '-'.
MESSAGE i398(00) WITH 'Tie!'.
PERFORM restart_game.
ENDCASE.
ENDFORM." push_button
*&---------------------------------------------------------------------*
*& Form restart_game
*&---------------------------------------------------------------------*
* Restart the game.
*----------------------------------------------------------------------*
FORM restart_game .
v_turn = 'X'.
CLEAR v_win.
PERFORM clear_buttons.
ENDFORM." restart_game
*&---------------------------------------------------------------------*
*& Report ZTic-tac-toe *
*& *
*&---------------------------------------------------------------------*
* Game Tic-tac-toe in ABAP - GPL Licence. *
*&---------------------------------------------------------------------*
*----------------------------------------------------------------------*
* INCLUDES *
*----------------------------------------------------------------------*
INCLUDE CTSICONS."ICONS FOR THE GAME.
*----------------------------------------------------------------------*
* GLOBAL VARIABLES *
*----------------------------------------------------------------------*
DATA: v_turn(1) VALUE 'X',"Select card.
v_win(1) VALUE ' '."Win a player(X) or tie(-)!
*----------------------------------------------------------------------*
* SELECTION-SCREEN *
*----------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (4) icon1 USER-COMMAND uc_icon1."1x1
SELECTION-SCREEN PUSHBUTTON (4) icon2 USER-COMMAND uc_icon2."2x1
SELECTION-SCREEN PUSHBUTTON (4) icon3 USER-COMMAND uc_icon3."3x1
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (4) icon4 USER-COMMAND uc_icon4."1x2
SELECTION-SCREEN PUSHBUTTON (4) icon5 USER-COMMAND uc_icon5."2x2
SELECTION-SCREEN PUSHBUTTON (4) icon6 USER-COMMAND uc_icon6."3x2
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (4) icon7 USER-COMMAND uc_icon7."1x3
SELECTION-SCREEN PUSHBUTTON (4) icon8 USER-COMMAND uc_icon8."2x3
SELECTION-SCREEN PUSHBUTTON (4) icon9 USER-COMMAND uc_icon9."3x3
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN SKIP 1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN PUSHBUTTON (12) restart USER-COMMAND uc_restart.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b1.
*----------------------------------------------------------------------*
* AT SELECTION-SCREEN *
*----------------------------------------------------------------------*
AT SELECTION-SCREEN.
CASE sy-ucomm.
WHEN 'UC_ICON1'.
PERFORM push_button USING icon1.
WHEN 'UC_ICON2'.
PERFORM push_button USING icon2.
WHEN 'UC_ICON3'.
PERFORM push_button USING icon3.
WHEN 'UC_ICON4'.
PERFORM push_button USING icon4.
WHEN 'UC_ICON5'.
PERFORM push_button USING icon5.
WHEN 'UC_ICON6'.
PERFORM push_button USING icon6.
WHEN 'UC_ICON7'.
PERFORM push_button USING icon7.
WHEN 'UC_ICON8'.
PERFORM push_button USING icon8.
WHEN 'UC_ICON9'.
PERFORM push_button USING icon9.
WHEN 'UC_RESTART'.
PERFORM restart_game.
ENDCASE.
*----------------------------------------------------------------------*
* INITIALIZATION *
*----------------------------------------------------------------------*
INITIALIZATION.
PERFORM clear_buttons.
*&---------------------------------------------------------------------*
*& Form clear_buttons
*&---------------------------------------------------------------------*
* Clear the buttons of Selection-Screen.
*----------------------------------------------------------------------*
FORM clear_buttons .
icon1 = '@5F@' .
icon2 = '@5F@' .
icon3 = '@5F@' .
icon4 = '@5F@' .
icon5 = '@5F@' .
icon6 = '@5F@' .
icon7 = '@5F@' .
icon8 = '@5F@' .
icon9 = '@5F@' .
restart = 'Restart'.
ENDFORM." clear_buttons
*&---------------------------------------------------------------------*
*& Form push_button
*&---------------------------------------------------------------------*
* Checks when a user push a button.
*----------------------------------------------------------------------*
* --> p_icon Button pushed
*----------------------------------------------------------------------*
FORM push_button USING p_icon.
* Exit if button pushed.
IF p_icon <> '@5F@'.
EXIT.
ENDIF.
* Change icon.
IF v_turn IS INITIAL.
p_icon = '@7C@'.
v_turn = 'X'.
ELSE.
p_icon = '@C9@'.
CLEAR v_turn.
ENDIF.
* Check winner
IF ( icon1 = icon5 AND icon5 = icon9 AND icon1 <> '@5F@' )"Diagonal \
OR ( icon3 = icon5 AND icon5 = icon7 AND icon3 <> '@5F@' )"Diagonal /
OR ( icon1 = icon2 AND icon2 = icon3 AND icon1 <> '@5F@' )"Row 1 -
OR ( icon4 = icon5 AND icon5 = icon6 AND icon4 <> '@5F@' )"Row 2 -
OR ( icon7 = icon8 AND icon8 = icon9 AND icon7 <> '@5F@' )"Row 3 -
OR ( icon1 = icon4 AND icon4 = icon7 AND icon1 <> '@5F@' )"Col 1 |
OR ( icon2 = icon5 AND icon5 = icon8 AND icon2 <> '@5F@' )"Col 2 |
OR ( icon3 = icon6 AND icon6 = icon9 AND icon3 <> '@5F@' )."Col 3 |
v_win = 'X'.
ENDIF.
* Check tie
IF v_win IS INITIAL
AND icon1 <> '@5F@'
AND icon2 <> '@5F@'
AND icon3 <> '@5F@'
AND icon4 <> '@5F@'
AND icon5 <> '@5F@'
AND icon6 <> '@5F@'
AND icon7 <> '@5F@'
AND icon8 <> '@5F@'
AND icon9 <> '@5F@'.
v_win = '-'.
ENDIF.
* Winner or tie?
CASE v_win.
* Winner
WHEN 'X'.
IF v_turn IS INITIAL.
MESSAGE i398(00) WITH 'Win player 1!'.
PERFORM restart_game.
ELSE.
MESSAGE i398(00) WITH 'Win player 2!'.
PERFORM restart_game.
ENDIF.
* Tie
WHEN '-'.
MESSAGE i398(00) WITH 'Tie!'.
PERFORM restart_game.
ENDCASE.
ENDFORM." push_button
*&---------------------------------------------------------------------*
*& Form restart_game
*&---------------------------------------------------------------------*
* Restart the game.
*----------------------------------------------------------------------*
FORM restart_game .
v_turn = 'X'.
CLEAR v_win.
PERFORM clear_buttons.
ENDFORM." restart_game
Labels:
ABAPGames,
Tic Tac Toe
Subscribe to:
Posts (Atom)
ABAP TIPS
|
Always use Pretty Printer and Extended Program Check before releasing the code. Do not leave unused code in the program. Comment the code thoroughly. Align the comments and the Code. Follow the SAP Standards and SAP Best Practices guidelines. It’s a good practice to take a dump of the code on your local drive. |