Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 1
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
Applies to: SAP R/3
Summary
Play the exciting games on SAP gui, as well as monitor all existing players.
Author(s): Siddharth Neekhra
Company: L&T InfoTech.
Created on: 14 Aug 2006
Author Bio
Siddharth Neekhra is a Technical Consultant presently working with L&T InfoTech, and has expertise in Implementation Methodologies.
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 2
Table of Contents
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach……….1 Applies to:……………………………………………………………………………………………………1 Summary……………………………………………………………………………………………………. 1 Author Bio……………………………………………………………………………………………………1 Demo…………………………………………………………………………………………………………3 2. Code sample…………………………………………………………………………………………….. 4 Related Content……………………………………………………………………………………………22 Copyright…………………………………………………………………………………………………...23
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 3
Demo
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 4
2. Code sample
Zenjoy.txt
*&---------------------------------------------------------------------*
*& Report ZSN_OOPS4 *
*& *
*&---------------------------------------------------------------------*
*& *
*& *
*&---------------------------------------------------------------------*
REPORT ZENJOY .
DATA: DOC TYPE REF TO CL_DD_DOCUMENT.
DATA: HTML_DOC TYPE REF TO CL_GUI_HTML_VIEWER .
DATA: DOC_URL(80).
DATA SPLITTER TYPE REF TO CL_GUI_EASY_SPLITTER_CONTAINER.
DATA MY_CONTAINER TYPE REF TO CL_GUI_CUSTOM_CONTAINER.
DATA CONTAINER_1 TYPE REF TO CL_GUI_CONTAINER.
DATA CONTAINER_2 TYPE REF TO CL_GUI_CONTAINER.
DATA: HTML_DOC_1 TYPE REF TO CL_GUI_HTML_VIEWER .
DATA: ALV TYPE REF TO CL_GUI_ALV_GRID .
DATA INIT.
DATA: DIS .
CONSTANTS: INDXKEY LIKE INDX-SRTFD VALUE 'ZENJOY'.
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 5
TYPES: BEGIN OF TAB ,
USER LIKE SY-UNAME ,
TERMINAL LIKE USR41-TERMINAL ,
LOGON_DATE TYPE D ,
LOGON_TIME TYPE T ,
END OF TAB .
DATA: ITAB TYPE TABLE OF TAB .
DATA: WA LIKE LINE OF ITAB .
DATA: GS_LAYOUT TYPE LVC_S_LAYO .
DATA IT_FLDCAT TYPE TABLE OF LVC_S_FCAT.
DATA LS_CAT LIKE LINE OF IT_FLDCAT.
CALL SCREEN 101 .
*&---------------------------------------------------------------------*
*& Module EXit INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE EXIT INPUT.
PERFORM LEAVE_PARTICIPENT .
set screen 0 .
ENDMODULE. " EXit INPUT
*&---------------------------------------------------------------------*
*& Module STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE STATUS_0101 OUTPUT.
SET PF-STATUS 'HTM'.
* SET TITLEBAR 'xxx'.
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 6
IF INIT IS INITIAL.
CREATE OBJECT MY_CONTAINER
EXPORTING
CONTAINER_NAME = 'HTML_1'.
DATA: L_DYNNR LIKE SY-DYNNR ,
THIS_REPID LIKE SY-REPID .
L_DYNNR = SY-DYNNR .
THIS_REPID = SY-REPID .
CREATE OBJECT SPLITTER
EXPORTING
LINK_DYNNR = L_DYNNR
LINK_REPID = THIS_REPID
PARENT = MY_CONTAINER
ORIENTATION =
CL_GUI_EASY_SPLITTER_CONTAINER=>ORIENTATION_HORIZONTAL
SASH_POSITION = 27
* metric =
* with_border =
EXCEPTIONS
OTHERS = 1.
IF SY-SUBRC <> 0.
ENDIF.
*CALL METHOD splitter->get_container
* EXPORTING row = 1
* column = 1
* RECEIVING container = container_1.
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 7
**
* CALL METHOD splitter->get_container
* EXPORTING row = 1
* column = 2
* RECEIVING container = container_2.
CONTAINER_1 ?= SPLITTER->TOP_LEFT_CONTAINER.
CONTAINER_2 ?= SPLITTER->BOTTOM_RIGHT_CONTAINER.
CREATE OBJECT HTML_DOC_1
EXPORTING
PARENT = CONTAINER_2 .
CALL METHOD CL_GUI_CFW=>FLUSH
EXCEPTIONS
CNTL_SYSTEM_ERROR = 1
CNTL_ERROR = 2.
INIT = 'X'.
PERFORM LOAD_HOME_PAGE.
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 8
CREATE OBJECT ALV
EXPORTING
I_PARENT = CONTAINER_1 .
PERFORM ALV_FLDCAT .
ENDIF.
ENDMODULE. " STATUS_0101 OUTPUT
*&---------------------------------------------------------------------*
*& Module USER_COMMAND_0101 INPUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0101 INPUT.
CASE SY-UCOMM .
WHEN 'BIL' .
CLEAR DOC_URL .
DOC_URL = 'http://www.geocities.com/siddharth_unv/BILLIARDS.swf' .
CALL METHOD HTML_DOC_1->SHOW_URL
EXPORTING
URL = DOC_URL.
WHEN 'AL1' .
CLEAR DOC_URL .
DOC_URL = 'http://www.geocities.com/siddharth_unv/AlienInvasion.swf' .
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 9
CALL METHOD HTML_DOC_1->SHOW_URL
EXPORTING
URL = DOC_URL.
WHEN 'AL2' .
CLEAR DOC_URL .
DOC_URL = 'http://www.geocities.com/siddharth_unv/Alien_Attack.swf' .
CALL METHOD HTML_DOC_1->SHOW_URL
EXPORTING
URL = DOC_URL.
WHEN 'RAD' .
*--**
WHEN 'MIN' .
CLEAR DOC_URL .
DOC_URL = 'http://www.geocities.com/siddharth_unv/miner.swf' .
CALL METHOD HTML_DOC_1->SHOW_URL
EXPORTING
URL = DOC_URL.
WHEN 'CHE' .
CALL METHOD HTML_DOC_1->DO_REFRESH.
CLEAR DOC_URL .
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 10
DOC_URL = 'http://www.geocities.com/siddharth_unv/Chess.swf' .
CALL METHOD HTML_DOC_1->SHOW_URL
EXPORTING
URL = DOC_URL.
WHEN 'INIT' .
*
CALL METHOD HTML_DOC_1->GO_HOME
EXCEPTIONS
CNTL_ERROR = 1.
WHEN 'BACK' .
PERFORM LEAVE_PARTICIPENT .
set screen 0 .
WHEN 'REFRESH' .
DIS = 'X' .
IMPORT ITAB FROM SHARED BUFFER INDX(ST) ID INDXKEY.
CALL METHOD ALV->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT
CHANGING
IT_FIELDCATALOG = IT_FLDCAT
IT_OUTTAB = ITAB.
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 11
WHEN OTHERS.
CALL METHOD CL_GUI_CFW=>DISPATCH.
ENDCASE .
ENDMODULE. " USER_COMMAND_0101 INPUT
*&--------------------------------------------------------------------*
*& Form LOAD_HOME_PAGE
*&--------------------------------------------------------------------*
* text
*---------------------------------------------------------------------*
FORM LOAD_HOME_PAGE.
*DATA: DOC_URL(80).
*
*DOC_URL = 'http://www.geocities.com/siddharth_unv/BILLIARDS.swf' .
*
* CALL METHOD HTML_DOC_1->SHOW_URL
* EXPORTING
* URL = DOC_URL.
ENDFORM. "LOAD_HOME_PAGE
*&---------------------------------------------------------------------*
*& Form ALV_FLDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM ALV_FLDCAT .
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 12
LS_CAT-FIELDNAME = 'USER'.
LS_CAT-INTTYPE = 'C'.
LS_CAT-OUTPUTLEN = 12.
LS_CAT-COLTEXT = 'Username'.
LS_CAT-TOOLTIP = 'Username'.
APPEND LS_CAT TO IT_FLDCAT .
LS_CAT-FIELDNAME = 'TERMINAL'.
LS_CAT-INTTYPE = 'C'.
LS_CAT-OUTPUTLEN = 36.
LS_CAT-COLTEXT = 'Terminal'.
LS_CAT-TOOLTIP = 'Terminal'.
APPEND LS_CAT TO IT_FLDCAT .
LS_CAT-FIELDNAME = 'LOGON_DATE'.
LS_CAT-INTTYPE = 'D'.
LS_CAT-OUTPUTLEN = 10.
LS_CAT-COLTEXT = 'Login Date'.
LS_CAT-TOOLTIP = 'Login Date'.
APPEND LS_CAT TO IT_FLDCAT .
LS_CAT-FIELDNAME = 'LOGON_TIME'.
LS_CAT-INTTYPE = 'T'.
LS_CAT-OUTPUTLEN = 10.
LS_CAT-COLTEXT = 'Login Time'.
LS_CAT-TOOLTIP = 'Login Time'.
APPEND LS_CAT TO IT_FLDCAT .
GS_LAYOUT-SEL_MODE = 'A'.
GS_LAYOUT-GRID_TITLE = 'Participants'.
GS_LAYOUT-NO_TOOLBAR = 'X'.
.
IF DIS NE 'X' .
IMPORT ITAB FROM SHARED BUFFER INDX(ST) ID INDXKEY.
CALL FUNCTION 'TERMINAL_ID_GET'
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 13
EXPORTING
USERNAME = SY-UNAME
IMPORTING
TERMINAL = WA-TERMINAL
EXCEPTIONS
MULTIPLE_TERMINAL_ID = 1
NO_TERMINAL_FOUND = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
WA-USER = SY-UNAME.
WA-LOGON_DATE = SY-DATUM.
WA-LOGON_TIME = SY-UZEIT.
APPEND WA TO ITAB .
* clear itab .
EXPORT ITAB TO SHARED BUFFER INDX(ST) ID INDXKEY.
ENDIF.
CALL METHOD ALV->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
IS_LAYOUT = GS_LAYOUT
CHANGING
IT_FIELDCATALOG = IT_FLDCAT
IT_OUTTAB = ITAB.
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 14
ENDFORM. " fill_itab
*&---------------------------------------------------------------------*
*& Form leave_participent
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
FORM LEAVE_PARTICIPENT .
* DELETE ITAB WHERE USER = WA-USER
* AND TERMINAL = WA-TERMINAL
* AND LOGON_DATE = WA-LOGON_DATE
* AND LOGON_TIME = WA-LOGON_TIME .
*
* EXPORT ITAB TO SHARED BUFFER INDX(ST) ID INDXKEY.
DATA lf_counter TYPE i.
IMPORT itab FROM SHARED BUFFER indx(st) ID indxkey.
* delete entry in participants
WA-USER = sy-uname.
DELETE ITAB WHERE USER = WA-USER
AND TERMINAL = WA-TERMINAL
AND LOGON_DATE = WA-LOGON_DATE
AND LOGON_TIME = WA-LOGON_TIME .
DESCRIBE TABLE itab LINES lf_counter.
IF lf_counter = 0.
REFRESH: itab .
DELETE FROM SHARED BUFFER indx(st) ID indxkey.
ELSE.
EXPORT itab
TO SHARED BUFFER indx(st) ID indxkey.
ENDIF.
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 15
ENDFORM. " leave_participent
3. Screen Layout
You can download the Screen 101 from here 101 screen and upload it in SE51.
Or else you can create it manually as follows:
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 16
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 17
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 18
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 19
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 20
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 21
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 22
Related Content
www.sdn.sap.com
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/abap-code-samples/SAP%20Radio.doc
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 23
Copyright
© Copyright 2006 SAP AG. All rights reserved.
No part of this publication may be reproduced or transmitted in any form or for any purpose without the express permission of SAP AG. The information contained herein may be changed without prior notice.
Some software products marketed by SAP AG and its distributors contain proprietary software components of other software vendors.
Microsoft, Windows, Outlook, and PowerPoint are registered trademarks of Microsoft Corporation.
IBM, DB2, DB2 Universal Database, OS/2, Parallel Sysplex, MVS/ESA, AIX, S/390, AS/400, OS/390, OS/400, iSeries, pSeries, xSeries, zSeries, z/OS, AFP, Intelligent Miner, WebSphere, Netfinity, Tivoli, Informix, i5/OS, POWER, POWER5, OpenPower and PowerPC are trademarks or registered trademarks of IBM Corporation.
Adobe, the Adobe logo, Acrobat, PostScript, and Reader are either trademarks or registered trademarks of Adobe Systems Incorporated in the United States and/or other countries.
Oracle is a registered trademark of Oracle Corporation.
UNIX, X/Open, OSF/1, and Motif are registered trademarks of the Open Group.
Citrix, ICA, Program Neighborhood, MetaFrame, WinFrame, VideoFrame, and MultiWin are trademarks or registered trademarks of Citrix Systems, Inc.
HTML, XML, XHTML and W3C are trademarks or registered trademarks of W3C®, World Wide Web Consortium, Massachusetts Institute of Technology.
Java is a registered trademark of Sun Microsystems, Inc.
JavaScript is a registered trademark of Sun Microsystems, Inc., used under license for technology invented and implemented by Netscape.
MaxDB is a trademark of MySQL AB, Sweden.
SAP, R/3, mySAP, mySAP.com, xApps, xApp, SAP NetWeaver, and other SAP products and services mentioned herein as well as their respective logos are trademarks or registered trademarks of SAP AG in Germany and in several other countries all over the world. All other product and service names mentioned are the trademarks of their respective companies. Data contained in this document serves informational purposes only. National product specifications may vary.
These materials are subject to change without notice. These materials are provided by SAP AG and its affiliated companies ("SAP Group") for informational purposes only, without representation or warranty of any kind, and SAP Group shall not be liable for errors or omissions with respect to the materials. The only warranties for SAP Group products and services are those that are set forth in the express warranty statements accompanying such products and services, if any. Nothing herein should be construed as constituting an additional warranty.
These materials are provided “as is” without a warranty of any kind, either express or implied, including but not limited to, the implied warranties of merchantability, fitness for a particular purpose, or non-infringement.
SAP shall not be liable for damages of any kind including without limitation direct, special, indirect, or consequential damages that may result from the use of these materials.
Play Games in SAP (Billiards, Chess, Alien, Miner) – An Object Oriented Approach.
SAP DEVELOPER NETWORK | sdn.sap.com BUSINESS PROCESS EXPERT COMMUNITY | bpx.sap.com © 2006 SAP AG 24
SAP does not warrant the accuracy or completeness of the information, text, graphics, links or other items contained within these materials. SAP has no control over the information that you may access through the use of hot links contained in these materials and does not endorse your use of third party web pages nor provide any warranty whatsoever relating to third party web pages.
Any software coding and/or code lines/strings (“Code”) included in this documentation are only examples and are not intended to be used in a productive system environment. The Code is only intended better explain and visualize the syntax and phrasing rules of certain coding. SAP does not warrant the correctness and completeness of the Code given herein, and SAP shall not be liable for errors or damages caused by the usage of the Code, except if such damages were caused by SAP intentionally or grossly negligent.