Archive for the ‘SAP ABAP’Category

Smartforms tips

Smart Forms provides a migration tool for  migrating layout and texts of a SAPscript form to a Smart Form.

It does not migrate SAPscript form logic of the print program.

Using Smart Forms, this logic is described by the tree structure of the Form Builder. The effort involved in migrating it depends on the complexity of the print program.

You can  migrates SAPscript forms  one-by-one in transaction SMARTFORMS.

You can migrate a SAPscript form into a Smart Form and convert a SAPscript style into a Smart Style.

When converting a SAPscript style into a Smart Style, the system converts all paragraph and character formats with all their properties and attributes without any changes. Thus you can use the converted Smart Style without making any adaptations.

Migrating a SAPscript form

1. Go to the SAP Smart Forms initial screen (transaction SMARTFORMS ).

2. In the Form field enter the name of the Smart Form you want to create.

3. Choose Utilities ® Migrate SAPscript form.

The dialog window Migrate SAPscript Form appears.

4. Enter the name and the language of the source form (SAPscript).

5. Choose Enter.

This takes you to the change mode of the SAP Form Builder.

If the selected SAPscript form does not exist in the selected language, a dialog window appears on which you can select one of the existing languages.

6. Now change the design of the form and of the form logic. To activate the Smart Form choose Activate.

Converting a SAPscript style

  1. Go to the Smart Styles inital screen (transaction SMARTSTYLES ).
  2. In the Style name field enter the name of the Smart Style you want to create.
  3. Choose Smart Styles ® Convert SAPscript style.
  4. Enter the name of the SAPscript style you want to convert.
  5. Choose Enter.
    A list of the converted styles appears.
  6. Choose Back. You can now change the Smart Style (Change).To activate the Smart Style choose Activate.

Mass Migration of SAPscript Forms

  1. In Reporting select the program SF_MIGRATE and execute it.
  2. Select the names and the language of the SAPscript forms and choose Execute. The system creates the Smart Forms under the names of the SAPscript forms plus the extension _SF.
    It displays a list of the migrated forms.
  3. To change and adapt a form, go to transaction SMARTFORMS . Then activate the changed Smart Form.

Migrating Smart Forms to Adobe Forms

1. Go to the Smart Forms initial screen (transaction SMARTFORMS).

2. Choose Utilities ® Migration ® PDF-Based Form ® Export.

3. In the dialog box, enter the name of the Smart Form that you want to migrate, the name of the PDF-based target form, and the target interface. The system suggests the name of the Smart Form as the name for the target form and target interface. You can change these names. The target form and the target interface can have different names.

4. Choose Continue.

5. The system displays the Settings dialog box where you can flag various options for migration. To activate the selected options and close the dialog box, choose Continue.

To view additional information about a particular option, select the option, and press F1.

6. In the dialog box Create Object Directory Entry, enter a package for the interface, or save it as a local object.

7. Assign the form to a package, or save the form as a local object.

8. The system migrates the form.

Transport SmartForm

A smartform is transported no differently than any other object. if it is assigned to a development class that is attached to a transport layer, it will be transported.
The definition is transported, and when called, the function module is regenerated.
This leads to an interesting situation. On the new machine, it is very likely the function module name will be different than the name on the source system. Make sure, before you call the function module, you resolve the external name to the internal name using the ‘SSF_FUNCTION_MODULE_NAME’ function module.
Typically, generate the SF, then use the pattern to being in the interface. Then change the call function to use the name you get back from the above function module.

System fields of Smart Forms

&SFSY-DATE&  Displays the date. You determine the display format in the user master record.

&SFSY-TIME&  Displays the time of day in the form HH:MM:SS.

&SFSY-PAGE&  Inserts the number of the current print page into the text. You determine the  format of the page number (for example, Arabic, numeric) in the page node.

&SFSY-FORMPAGES& Displays the total number of pages for the currently processed form. This  allows you to include texts such as’Page x of y’ into your output.

&SFSY-JOBPAGES&  Contains the total page number of all forms in the currently processed print  request.

&SFSY-WINDOWNAME& Contains the name of the current window (string in the Window field)

&SFSY-PAGENAME&  Contains the name of the current page (string in the Page field)

&SFSY-PAGEBREAK&  Is set to ‘X’ after a page break (either automatic [Page 7] or  command-controlled [Page 46])

&SFSY-MAINEND&  Is set as soon as processing of the main window on the current page ends

&SFSY-EXCEPTION& Contains the name of the raised exception. You must trigger your own  exceptions, which you defined in the form interface, using the user_exception macro (syntax:  user_exception <exception name >).

28

10 2017

SAPScript programs (RSTX*)

RSTXSCRP is the name of the upload program in the R/3 System. Although the RSTXSCRP report is an easy and quick way to get a form into
the R/3 System, there are some restrictions.

RSTXTRAN is a standard ABAP report available within your SAP system to transfer SAPscript texts (or the text key) to be transferred to a
correction or repair of the transport system.

RSTXPDFT4 is for transferring your spool or SAP script to pdf files.

The program RSTXFCON converts the current form page format to the specified page format checking the position and size of each window on each page. In general, the program tries to hold the position and size of a window

Tags:

07

04 2014

Howto Search for BAdi’s in programs

Searching for a Classic BAdi within a program

Search for the keyword GET_INSTANCE in the program.
Double click on the reference variable to navigate to the variable
Double click on the BAdi interface to navigate to the interface
Use the where-used list in classes

Searching for a new BAdi within a program

Search for the keyword GET_BADI in the program
Double click on the reference variable to navigate to the variable
Double click on the BAdi name to navigate to the corresponding enhancement spot

21

03 2014

&SAP_EDIT not working?

Depending on your SAP version you might have possibility to use &SAP_EDIT command in SE16 or not.
For those who have not heard about this command earlier we can say that is like a secret option which lets you to directly edit/delete/insert the data of a table.
Of course under normal circumstances this is something which you should never do on a production system.
Because this may lead to data inconsistencies and cause serious damage to your system.
Having informed you about the danger if you still would like to see here is how you can do it by debugging.

in order to use &SAP_EDIT in breakpoint on LSE16NI01 perform fill_sap_edit
or better in LSE16NF10 / if ld_on <> true. and set ld_on = true
later continue with debug and set sy-subrc to 0 whenever necessary

Of course the prerequisite is that you should have the authorization to debug.

Probably the better way to do this rather than debugging everytime is to reactivate the &SAP_EDIT option.
For more detailed information on how and why SAP deactivated this you can consult the below SAP Notes.

1420281 – CO-OM tools: SE16N: Deactivating &SAP_EDIT
1446530 – CO-OM tools: SE16N: Technical enhancement

21

03 2014

How to unlock a SAP Query

If you receive the message that an SAP Query is locked for changes here is how you can open it.

1. Go to SQ02 transaction
2. Select the Infoset of the query which is locked.
3. From the menu Go to –> Query Directory
4. Select the Query you would want to unlock.
5. Click on Cancel Edit lock button

Now you can go back to SQ01 transaction again and edit the query.

21

03 2014

StartRFC

STARTRFC – Start SAP RFC Function Modules From any Server Within Your Landscape

startrfc is a very easy SAP command line interface to start all of the implemented function modules of SAP systems.

SAP Kernel Programs

startrfc in a SAP System

How to download the latest version ?

startrfc online help with all supported command line options

startrfc in a SAP System
You can start any SAP function module, that is RFC-enabled. You can check this in transaction SE37 or SE80. There you either use existing function modules or create the ones of your desire.
You can start these function modules from any platform with the program startrfc. This program is part of SAP application server and of any SAP RFC SDK on the Presentation CD (SAPGUI CD). So, you can usually use and try this just from your PC connected to the network via TCP/IP to your SAP system. You just need an user for the SAP system and can start with the test. Later on, for the case, that you want to use this as permanent interface, you should change this user so that it can no longer log on in dialog to the SAP system.

startrfc works as follows:
startrfc -3 -h -s -c -l -u -p -F -E

An example for startrfc could look like as follows:
startrfc -3 -h hyperion -s 01 -c 000 -l D -u volker -p password -F SUBST_START_BATCHJOB -E JOBNAME=VOLKERJOB -E REPNAME=RSPFPAR

An example for startrfc with a saprouter string looks as follows:
startrfc -3 -h /H/saprouter/S/3299/H/hyperion -s 01 -c 000 -l D -u volker -p password -F SUBST_START_BATCHJOB -E JOBNAME=VOLKERJOB -E REPNAME=RSPFPAR
(There the saprouter is called “saprouter” and is running on the default port 3299)

On iSeries this would look as follows:
call pgm(startrfc) parm(‘-3’ ‘-h’ ‘hyperion’ ‘-s’ ’01’ ‘-c’ ‘000’ ‘-l’ ‘D’ ‘-u’ ‘volker’ ‘-p’ ‘password’ ‘-F’ ‘SUBST_START_BATCHJOB’ ‘-E’ ‘JOBNAME=VOLKERJOB’ ‘-E’ ‘REPNAME=RSPFPAR’)

This startrfc starts the function module SUBST_START_BATCHJOB, that is able to start a background job of any available report. As this creates a background job, you have to specify the jobname and the report name, that is called. The result is a background job, that creates a spool file of all SAP profile parameters any time you call this startrfc.
You can implement all RFC-enabled function modules with this technique.

How to download the latest version ?
You can download the latest version of all the SAP Executables in the SAP Service Marketplace. As the binaries are different for each platform, you should have a look at the following link:
Download Executable Patches on the SAP Service Marketplace

If you have some more ideas to this topic, please let us know via the Feedback Area.

saposcol online help with all supported command line options
RFC command line interface

Syntax :
startrfc [connect options]

with
function options =

-F =

-T

,,[r=][,w=]
where is a path name to read from (r)
or write to (w) the internal table.
If is -, stdin or stdout is used.

RFC connection options:

-d name of the RFC destination.
Necessary, if you are using a ‘sideinfo’ file.

-2 SNA mode on.
You must set this if you want to connect to R/2.
All other conection data must be suppplied by a
sideinfo file.

-3 R/3 mode on.
You must set this if you want to connect to R/3.
Specify the following options:

-h hostname of the R/3 target system.

-s system number of the target system.
this determines the TCP/IP service to be used to connect
to the R/3 system. The default value is 0 and the default
service being used then is sapgw00.

-gui start sapgui
to allow dynpro and graphics processing
(3.0C or later required on the target system).

Using an intermediate SAP gateway, specify:

-g

-x
(must not be used with -gui or -debug option).

-balanced load balancing mode.
Another way to connect to R/3, if the R/3 system is 3.0C
or later and workload balancing is active on that system.
Requests are automatically routed to the application server
having the best response times in the moment.
Specify the following options:

-h hostname of R/3’s message server.

-s name of the target system.
This determines the TCP/IP service to be used to connect
to the R/3 system.
The system name is a 3 letter word. If the system name
is XXX, the service being used is sapXXX.

-g name of application server group.
The default is PUBLIC.

-gui start sapgui
to allow dynpro and graphics processing.

additional options:

-t turn trace on.
all operations are written to the trace file ‘dev_rfc’

-debug turn ABAP/4 debugging mode on.
this can only be done, if sapgui is installed on the client
system and the target system has version 3.0C or later.

Using the ‘saprfc.ini’-file:

-D name of the RFC destination in saprfc.ini
Instead of using the connection and additional options
defined above, you can also work with the ‘saprfc.ini’-file
and all needed options must be defined in this file.
Using this feature, this program can run in an SNC
environment.

RFC logon data:

-u SAP userid.

-p password.

-c client.

-l logon language.

further options:

-i

-o

-? “this text”

Tags:

18

02 2014

ALE / EDI / IDoc T-Codes

Important IDoc Transaction Codes

SALE – IMG ALE Configuration root
WE20 – Manually maintain partner profiles
BD64 – Maintain customer distribution model
BD71 – Distribute customer distribution model
SM59 – Create RFC Destinations
BDM5 – Consistency check (Transaction scenarios)
BD82 – Generate Partner Profiles
BD61 – Activate Change Pointers – Globally
BD50 – Activate Change Pointer for Msg Type
BD52 – Activate change pointer per change.doc object
BD59 – Allocation object type -> IDOC type
BD56 – Maintain IDOC Segment Filters
BD53 – Reduction of Message Types
BD21 – Select Change Pointer
BD87 – Status Monitor for ALE Messages
BDM5 – Consistency check (Transaction scenarios)
BD62 – Define rules
BD79 – Maintain rules
BD55 – Defining settings for IDoc conversion
WEDI – ALE IDoc Administration
WE21 – Ports in Idoc processing
WE60 – IDoc documentation
SARA – IDoc archiving (Object type IDOC)
WE47 – IDoc status maintenance
WE07 – IDoc statistics

BALE – ALE Distribution Administration
WE05 – IDoc overview
BD87 – Inbound IDoc reprocessing
BD88 – Outbound IDoc reprocessing
BDM2 – IDoc Trace
BDM7 – IDoc Audit Analysis
BD21 – Create IDocs from change pointers
SM58 – Schedule RFC Failures

Basic config for Distributed data:
BD64: Maintain a Distributed Model
BD82: Generate Partner Profile
BD64: Distribute the distribution Model

Programs:
RBDMIDOC – Creating IDoc Type from Change Pointers
RSEOUT00 – Process all selected IDocs (EDI) -> WE14
RBDAPP01 – Inbound Processing of IDocs Ready for Transfer
RSARFCEX – Execute Calls Not Yet Executed
RBDMOIND – Status Conversion with Successful tRFC Execution
RBDMANIN – Start error handling for non-posted IDocs
RBDSTATE – Send Audit Confirmations
For testing you can use WE19

Tags: , ,

18

02 2014

Basic ALE Customizing

To find out which version of the basic type is best suited to your SAP system’s
release level, ALE → ALE Development → IDoc → IDoc Type Development→ IDoc Type for Message (transaction WE82).

For an overview of all the message types, go to Tools → ALE → ALE Development → Logical Messages (transaction WE81).

You can create new model views in Customizing. To do this, in the IMG, go to SAP NetWeaver → SAP Web Application Server → IDoc Interface / Application Link Enabling (ALE) → Modelling and Implementing Business Processes → Maintain Distribution Model and Distribute Views or call the distribution model directly via transaction BD64.

For your ALE scenarios, you create RFC destinations for all the partner systems in each system involved. To do this, select in the ALE Customizing IDoc Interface / Application Link Enabling (ALE) → Communication → Create RFC Connections or use transaction SM59.

Hint: If you give the RFC destination the same name as the logical target system, you can have the system carry out certain settings automatically later on.

In order to use ALE scenarios later on, the RFC must be assigned to a port. The sender uses the port to determine the communication channel to the recipient. You can create ports manually or – if the logical target system and the RFC destination have the same name – have the sender system create them.

Note: There are different types of port in SAP systems. ALE always uses RFC ports. In EDI scenarios, you can also use file ports in addition to RFC ports.

In the SAP system, you can set tRFC parameters for the relevant connection in table RFCDES (for connection types T, 3, I) (SM59):
• Suppress batch job in the event of communication errors (manual start with transaction SM58 required)
• Number of connection attempts
• Interval in minutes between repeated attempts to transfer data

For a model view to be distributed to all the partner systems, the sender system must contain outbound partner profiles for message type SYNCH for all the affected recipient systems. This message type is used only for determining the RFC destination for the target system. If the name of the logical target system and its RFC destination are the same, the sender system can automatically create a port with the appropriate RFC destination and generate the partner profiles for the message types of a model view. The authorization object for distributing model views is B_ALE_MODL.

IDOCS

For an overview of the segment structure of a basic type, see transaction WE30 (IDoc Type Development).

The structure of the basic types provided by SAP is documented in detail in SAP R/3 and mySAP ERM. To call this documentation, go to Tools → ALE → ALE Administration → Services → Documentation → IDoc Types and Segments or call transaction WE60.

The line type of the internal table is determined by the ABAP Dictionary structure type EDIDD.

•Regardless of how the IDoc was created, it is first saved to the sender system’s database (status value 01).
• If all the information required for sending has been obtained from the recipient, then the IDoc receives the status “ready for dispatch” (status value 30).
• If the outbound partner profiles specify that the IDoc is to be transferred immediately to the port stored in the relevant message type, then the IDoc is sent and receives a corresponding status (status value 03). However, it is also possible to send multiple IDocs bundled together at a later time.
• The IDoc is saved to the target system’s database (status value 50).
• If all information about further processing is known, the IDoc can be transferred to the application (status value 64).
• If the inbound partner profiles specify that the IDoc is to be transferred to the application immediately, the target system attempts to post the IDoc data (status value 62). If the inbound processing is successful, the IDoc receives status value 53.

All the Customizing settings you need for cross-system Customizing comparison and subsequent synchronization can be found with transaction SALE. In the menu, select IDoc Interface/Application Link Enabling (ALE) → Modelling and Implementing Business Processes → Synchronization of Customizing Data.
You can call the relevant application transactions in SAP Easy Access via Tools → ALE → ALE Administration → Services → Customizing Data. Here you will find a program for matching Customizing tables in the sending and target systems, known as the “Customizing Cross-System Viewer” (transaction SCU0), and transaction for generating and further processing ALE transport requests for Customizing synchronization. The sending system creates IDocs of message type CONDA2 for the transport requests: these IDocs contain the core information about each request. Inbound processing of these IDocs controls the importing of request data in the target system: either a workflow is sent to the responsible
administrator requesting him or her to carry out the import, or the import is carried out automatically by a program executed in the background.

Synchronizing Customizing Settings with the SAP Solution Manager

There are standard ALE scenarios for distributing master data; these are documented in the SAP Library and in the IMG. You can use transaction SALE to find descriptions of how to set up certain master data distribution scenarios.

First, use this information to create a new view in the distribution model of one of the system’s involved. BD64

If RFC destinations already exist with the same names as the logical target systems, you can now have the system create the outbound partner profiles for the new model view. When it generates partner profiles, the system automatically creates an entry for the message type MATMAS and also an entry for message type SYNCH for each profile (ALE:Dummy Message Type for Determination of RFC Destinations). This message type is not used for generating IDocs: it is only used for determining the RFC destination of the relevant target system. The entry for message type SYNCH is a prerequisite for distributing model views.

Note: If your RFC destinations have different names to the target systems to which they lead, you need to first create the entry for message type SYNCH manually and then assign the RFC destination you require using the relevant port. After you have done this, you can have the system generate the remaining partner profiles.

Partners of the type “logical system” (LS) are always created for ALE scenarios.
The name of the partner is always the same as the logical system name.

In the outbound partner profile for a message type, store the following information:
• Receiver port: in ALE scenarios, the sending and target systems exchange data via RFC. You therefore need to use a port of the type “transactional RFC” in the outbound partner profiles for ALE scenarios; the RFC destination of this RFC leads to the target system, the partner in the profiles.
• Output mode: You can choose between Transfer IDoc Immed. and Collect IDocs.
• Package size: If you choose Transfer IDoc Immed., the IDocs are sent individually. If you choose Collect IDocs, multiple IDocs are collected in packages and sent together. Collecting IDocs to send together can improve performance. As a guideline, we recommended collecting between 20 and 100, depending on the size of the IDocs.
• Basic type: in this field, you need to enter the IDoc type that is compatible with the target system’s release level.
Note: If you select the Collect IDocs output mode, you need to execute the RSEOUT00 program to transfer the IDocs to the communication
layer. This program is usually scheduled as a periodic background job.
After you have created the outbound partner profiles for the target systems, you can distribute the new model view to these systems.

In the inbound partner profile for a message type, store the following information:
• Process code: the process code is a key that refers either to a function module or a workflow for processing the IDocs. The process code for message type MATMAS is MATM. If you double-click on the process code key, a screen appears containing the information as to which function module or which workflow is used for inbound IDoc processing. As a rule, function modules are used in ALE scenarios.
Note: There can be more than one process code for a message type (and, accordingly, more than one inbound function module
or workflow). For information about which process codes are assigned to which message types, see the Inbound process code
table (transaction WE42).
• Processing mode: you can choose between Trigger by background program and Trigger immediately. If you choose Trigger by background program, the IDocs are transferred to the ALE layer using the RBDAPP01 program. This program is usually scheduled as a periodic background job.
Figure 41: Processing Times You can define variants for the RSEOUT00 and RBDAP001 programs for collective background IDoc processing. You can find both programs in the IMG via transaction SALE, by going to IDoc Interface / Application Link Enabling (ALE) → System Monitoring → IDoc Processing → Dispatch Collected IDocs or Update IDocs in Receiver System.

You can check the current status of IDocs in SAP R/3 or mySAP ERM by using a status monitor. You can call this monitor with transaction BD87 or the menu path Tools → ALE → ALE Administration → Monitoring → IDoc Display → Status Monitor.

Sending and Requesting Master Data
The “Share Master Data” tool offers you a variety of application transactions for generating IDocs for distributing master data. You can find these transactions via menu path Tools → ALE → Master Data Distribution. You can also call all of the SMD transactions directly using transaction BALM.

You can send material masters directly using transaction BD10
In ALE scenarios, master data is normally sent from the maintenance system to the downstream systems. However, with cross-application master data (material, customer, vendor), it is also possible to retrieve data. Message type MATFET, for example, is used for fetching material masters. This message type is linked to the corresponding views in the distribution model (see figure). In the application menu, you can find transaction BD11 via Tools → ALE → Master Data Distribution → Cross-Application → Material → Get; the target system can use this transaction to request material masters from the sending system. Message type MATMAS is used for sending the material master IDocs.

CHANGE POINTERS
Note: To view the change documents, use the report RSSCD100. You can also call the change documents from the application transaction
in question. To view the change pointers, see the database table view BDCPV

You can evaluate change pointers by using the program RBDMIDOC. This program is usually scheduled as a periodic background job. You can start the program for testing purposes with transaction BD21

You can display the
assignment of message type and function module for evaluating the the change pointer with transaction BD60

Data Filtering and Reducing the Scope of Data

If you would like to use segment filtering in an ALE scenario, you should first check the structure of the basic type you are going to use to determine the keys for the segments you would like to delete. If, for example, you want the sales area data for the customer masters (basic type DEBMAS0x) to be created in the sales branch system, you can use segment filtering to delete segment group E1KNVVM (Master stomer master sales data) from all communications IDocs for message type DEBMAS and recipient “Sales”. The customer masters are then distributed
to sales without the sales area data.

You can set up segment filtering in the IMG with transaction SALE, via IDoc Interface / Application Link Enabling (ALE) → Modelling and Implementing Business Processes→Master Data Distribution→Scope of Data for Distribution → Filter IDoc Segments.

Filter Objects
If you work with filter objects in ALE scenarios, you have to define conditions that need to be fulfilled for specific application data to be included in a communications IDoc. If the filter object corresponds to a required segment of the basic type in question, then a communications IDoc is only created if the condition is fulfilled.
In the example illustrated below, material masters (message type MATMAS) are distributed at regular intervals from the head office to sales and distribution and production. However, sales and distribution is only supposed to receive material masters for finished products whereas production requires the master records for the finished parts and the raw materials.

Note: Customers can enhance the list of filter objects provided by SAP with their own filter objects. The tables required for this can be found in the application menu along the path Tools → ALE → ALE Development → IDoc → Data Filtering.

Classification
If you would like to use classification as a filter method in an ALE scenario, you first need to carry out some basic settings in the class system itself. You need to mark one class type as the “distribution class type” and create at least one class for grouping your data in this class type. Then you can add the ALE-specific settings. You can activate the use of classification in an ALE scenario in the filter
object area of a model view (see above

Reduced Message Types
Some applications have such flexible programs for inbound and outbound processing that you can choose whether or not each optional segment field is to be transferred. To do this, you create what is known as a reduced message type in the customer namespace as a copy of a message type supplied by SAP; then you select the fields whose content you want to be transferred to a particular target system.

Tags: , ,

18

02 2014

Patience

PROGRAM ZPATIENCE NO STANDARD PAGE HEADING.

DATA: NUMBER LIKE DATATYPE-INTEGER2.
DATA: NUMBER_I TYPE I.
DATA: DUMMY  LIKE DATATYPE-INTEGER2.
DATA: BEGIN OF CARDS OCCURS 52 ,
      ENTRY TYPE I,
      ROW TYPE I,
      COL TYPE I,
      VIS(1),
      END OF CARDS.

DATA: CARD_NUM TYPE I, SUIT_NUM TYPE I, SUIT(1), CARD(2), ROWS TYPE I.
DATA: BLANK(3) VALUE ‘***’.
DATA: NEXT-CARD(4) VALUE ‘Next’.
DATA: RESTART(8) VALUE ‘New game’.
DATA: REVEAL(6) VALUE ‘Reveal’.
DATA: TEST_NUM TYPE I, TO_NUM TYPE I, MOVING_NUM TYPE I,
        PILE_NUM TYPE I.
DATA: CURR_C TYPE I, CURR_H TYPE I, CURR_S TYPE I, CURR_D TYPE I.
DATA: MOVING_SUIT(1), TO_SUIT(1), MOVING_CARD(2), TO_CARD(2),
  PILE_SUIT(1), PILE_CARD(2),MOVING_TYPE(1)    .
DATA: MOVING_ROW TYPE I, MOVING_COL TYPE I,
      TO_ROW TYPE I, TO_COL TYPE I, TEST_ROW TYPE I.
DATA: CURRENT_CARD TYPE I,
       MIN_CARD TYPE I , MAX_CARD TYPE I.
DATA: CURRENTFIELD(50).
DATA: DISC_C(3),DISC_H(3),DISC_S(3),DISC_D(3).
DATA: ROWS_OUT TYPE I, COLS_OUT TYPE I.

PERFORM SHUFFLE.

PERFORM SHOW_SCREEN.

AT LINE-SELECTION.

  GET CURSOR FIELD CURRENTFIELD.
  PERFORM PROCESS-INPUT.

*———————————————————————*
*       FORM SHUFFLE                                                  *
*———————————————————————*
FORM SHUFFLE.

  MIN_CARD = 3.MAX_CARD = 24.
  CURR_C = -1.CURR_D = -1.CURR_H = -1.CURR_S = -1.
  DISC_C = ‘CCC’.DISC_H = ‘HHH’.DISC_S = ‘SSS’.DISC_D = ‘DDD’.
  NUMBER = SY-UZEIT MOD 1000.
  DO NUMBER TIMES.

    CALL FUNCTION ‘RANDOM_I2’
         IMPORTING
              RND_VALUE = DUMMY.

  ENDDO.

  REFRESH CARDS. CLEAR CARDS. SY-TABIX = 0.

  WHILE SY-TABIX < 52.

    CALL FUNCTION ‘RANDOM_I2’
         EXPORTING
              RND_MIN   = 0
              RND_MAX   = 51
         IMPORTING
              RND_VALUE = NUMBER.

    NUMBER_I = NUMBER.
    READ TABLE CARDS WITH KEY NUMBER_I TRANSPORTING NO FIELDS.

    IF SY-SUBRC <> 0.

      CARDS-VIS = ‘n’.

      DESCRIBE TABLE CARDS LINES ROWS.

      CASE ROWS.

        WHEN 0.CARDS-VIS = ‘y’.CARDS-ROW = 0.CARDS-COL = 0.
        WHEN 7.CARDS-VIS = ‘y’.CARDS-ROW = 1.CARDS-COL = 1.
        WHEN 13.CARDS-VIS = ‘y’.CARDS-ROW = 2.CARDS-COL = 2.
        WHEN 18.CARDS-VIS = ‘y’.CARDS-ROW = 3.CARDS-COL = 3.
        WHEN 22.CARDS-VIS = ‘y’.CARDS-ROW = 4.CARDS-COL = 4.
        WHEN 25.CARDS-VIS = ‘y’.CARDS-ROW = 5.CARDS-COL = 5.
        WHEN 27.CARDS-VIS = ‘y’.CARDS-ROW = 6.CARDS-COL = 6.
        WHEN 28.CARDS-ROW = 20.CARDS-COL = 0.
      ENDCASE.

      CARDS-COL = CARDS-COL + 1.
      CARDS-ENTRY = NUMBER.
      APPEND CARDS.

    ENDIF.

  ENDWHILE.
  CURRENT_CARD = MIN_CARD.

ENDFORM.
*———————————————————————*
*       FORM SHOW_SCREEN                                              *
*———————————————————————*
FORM SHOW_SCREEN.

  ROWS_OUT = 1.
  COLS_OUT = 4.
  DO 7 TIMES.

    SKIP TO LINE ROWS_OUT.
    POSITION COLS_OUT.
    WRITE BLANK HOTSPOT.
    COLS_OUT = COLS_OUT + 4.

  ENDDO.

  LOOP
   AT CARDS.
    PERFORM MAKE_CARD.
    IF CARDS-ROW < 20.
      ROWS_OUT = CARDS-ROW + 1.
      SKIP TO LINE ROWS_OUT.
      COLS_OUT = CARDS-COL * 4.
      POSITION COLS_OUT.
      IF CARDS-VIS = ‘n’.
        WRITE ‘XXX’ COLOR OFF INTENSIFIED OFF INVERSE OFF.
      ELSE.
        IF SUIT = ‘D’ OR SUIT = ‘H’.
          WRITE: SUIT NO-GAP COLOR 6 INTENSIFIED INVERSE HOTSPOT,
                 CARD COLOR 6 INTENSIFIED INVERSE HOTSPOT.
        ELSE.
       WRITE: SUIT NO-GAP COLOR OFF INTENSIFIED OFF INVERSE OFF HOTSPOT,
                     CARD COLOR OFF INTENSIFIED OFF INVERSE OFF HOTSPOT.
        ENDIF.
      ENDIF.
    ELSE.

      SKIP TO LINE 20.      COLS_OUT =  CARDS-COL  * 4.
      IF COLS_OUT > 48.

        SKIP TO LINE 21.
        COLS_OUT = COLS_OUT – 48.

      ENDIF.

      POSITION COLS_OUT.
      IF CARDS-COL = CURRENT_CARD.
        PILE_SUIT = SUIT.
        PILE_CARD = CARD.
        PILE_NUM = CARD_NUM.
        IF SUIT = ‘D’ OR SUIT = ‘H’.
          WRITE: PILE_SUIT NO-GAP COLOR 6 INTENSIFIED INVERSE HOTSPOT,
                 PILE_CARD COLOR 6 INTENSIFIED INVERSE HOTSPOT.
        ELSE.
          WRITE: PILE_SUIT NO-GAP COLOR OFF INTENSIFIED OFF HOTSPOT,
                 PILE_CARD COLOR OFF INTENSIFIED OFF HOTSPOT.
        ENDIF.
      ELSE.
        IF CARDS-COL < CURRENT_CARD.
          WRITE ‘XXX’ COLOR OFF INTENSIFIED OFF INVERSE OFF.
        ENDIF.

      ENDIF.

    ENDIF.

  ENDLOOP.

  SKIP TO LINE 4. POSITION 40.WRITE: DISC_C
       COLOR OFF INTENSIFIED OFF INVERSE OFF HOTSPOT.
  SKIP TO LINE 4. POSITION 44. WRITE: DISC_D
       COLOR 6 INTENSIFIED INVERSE HOTSPOT.
  SKIP TO LINE 4. POSITION 48. WRITE: DISC_S
       COLOR OFF INTENSIFIED OFF INVERSE OFF HOTSPOT.
  SKIP TO LINE 4. POSITION 52. WRITE: DISC_H
       COLOR 6 INTENSIFIED INVERSE HOTSPOT.

  IF MIN_CARD > 0.
    SKIP TO LINE 23. POSITION 1. WRITE NEXT-CARD HOTSPOT.
  ENDIF.

  SKIP TO LINE 23. POSITION 20. WRITE RESTART HOTSPOT.
  SKIP TO LINE 25. POSITION 1. WRITE CURRENTFIELD.

  SY-LSIND = 0.

ENDFORM.
*———————————————————————*
*       FORM PROCESS-INPUT                                            *
*———————————————————————*
FORM PROCESS-INPUT.

  IF CURRENTFIELD = ‘NEXT-CARD’.
    IF CURRENT_CARD = MAX_CARD.
      CURRENT_CARD = MIN_CARD.
    ELSE.
      CURRENT_CARD = CURRENT_CARD + 3.
      IF CURRENT_CARD > MAX_CARD.
        CURRENT_CARD = MAX_CARD.
      ENDIF.
    ENDIF.

    MOVING_CARD = SPACE.
    CURRENTFIELD = SPACE.
    PERFORM SHOW_SCREEN.
    EXIT.

  ENDIF.

  IF CURRENTFIELD = ‘REVEAL’.

    LOOP
     AT CARDS.
      CARDS-VIS =  ‘y’.
      MODIFY CARDS.
    ENDLOOP.

    PERFORM SHOW_SCREEN.
    EXIT.
  ENDIF.

  IF CURRENTFIELD = ‘RESTART’.

    PERFORM SHUFFLE.
    CURRENTFIELD = ‘Restarting’.
    PERFORM SHOW_SCREEN.
    EXIT.

  ENDIF.

  IF MOVING_CARD = SPACE.

    IF CURRENTFIELD = ‘CARD’ OR CURRENTFIELD = ‘SUIT’.
      CURRENTFIELD = SPACE.
      ROWS_OUT = SY-CUROW – 1.
      COLS_OUT = SY-CUCOL DIV 4.

      LOOP
       AT CARDS.
        IF CARDS-ROW = ROWS_OUT AND CARDS-COL = COLS_OUT.
          CURRENTFIELD = ‘Moving ‘.
          PERFORM MAKE_CARD.
          MOVING_ROW = CARDS-ROW.
          MOVING_COL = CARDS-COL.
          MOVING_CARD = CARD.
          MOVING_SUIT = SUIT.
          MOVING_TYPE = ‘m’.
          MOVING_NUM = CARD_NUM.
          CURRENTFIELD+8(1) = SUIT.
          CURRENTFIELD+9(2) = CARD.
        ENDIF.

      ENDLOOP.

    ELSE.

      IF CURRENTFIELD = ‘PILE_CARD’ OR CURRENTFIELD = ‘PILE_SUIT’.
        MOVING_CARD = PILE_CARD.
        MOVING_SUIT = PILE_SUIT.
        MOVING_TYPE = ‘p’.
        MOVING_NUM = PILE_NUM.
        CURRENTFIELD = ‘Moving pile card’.
        CURRENTFIELD+17(1) = PILE_SUIT.
        CURRENTFIELD+18(2) = PILE_CARD.

      ELSE.

        CURRENTFIELD = SPACE.

      ENDIF.

    ENDIF.

  ELSE.

    IF CURRENTFIELD = ‘CARD’ OR CURRENTFIELD = ‘SUIT’ OR
           CURRENTFIELD = ‘BLANK’.
      ROWS_OUT = SY-CUROW – 1.
      COLS_OUT = SY-CUCOL DIV 4.
      TEST_ROW = -1.
      IF CURRENTFIELD = ‘BLANK’.
        TO_COL = COLS_OUT.
        TO_ROW = ROWS_OUT – 1.
        IF MOVING_CARD = ‘K’.
          PERFORM MOVE_CARD.
        ELSE.
          CURRENTFIELD = ‘Can only move K to blank’.
          MOVING_CARD = SPACE.
        ENDIF.
      ELSE.
        LOOP
         AT CARDS.
          IF ( CARDS-ROW >= TEST_ROW AND CARDS-ROW < 20 )
                 AND CARDS-COL = COLS_OUT.
            TEST_ROW = CARDS-ROW.
            PERFORM MAKE_CARD.
            TO_COL = CARDS-COL.
            TO_ROW = CARDS-ROW.
            TO_CARD = CARD.
            TO_SUIT = SUIT.
            TO_NUM = CARD_NUM.
          ENDIF.

        ENDLOOP.

        IF TO_COL <> MOVING_COL OR MOVING_TYPE = ‘p’.
          IF
             ( ( MOVING_SUIT = ‘D’ OR MOVING_SUIT = ‘H’ ) AND
               ( TO_SUIT = ‘D’ OR TO_SUIT = ‘H’ ) )
           OR
             ( ( MOVING_SUIT = ‘C’ OR MOVING_SUIT = ‘S’ ) AND
               ( TO_SUIT = ‘S’ OR TO_SUIT = ‘S’ ) ).
            CURRENTFIELD = ‘Can only put black on red or red on black’.
            MOVING_CARD = SPACE.
          ELSE.
            TEST_NUM = TO_NUM – 1.
            IF TEST_NUM = MOVING_NUM.
              PERFORM MOVE_CARD.
            ELSE.
              CURRENTFIELD = ‘Can only put on next higher card’.
              MOVING_CARD = SPACE.
            ENDIF.
          ENDIF.
        ELSE.
          CURRENTFIELD = ‘Can only move to another column’.
          MOVING_CARD = SPACE.
        ENDIF.
      ENDIF.
    ELSE.
      IF CURRENTFIELD(4) = ‘DISC’.
        TO_SUIT = CURRENTFIELD+5(1).
        IF MOVING_TYPE = ‘p’.
        ELSE.
          TEST_ROW = -1.
          LOOP
           AT CARDS.
            IF CARDS-COL = MOVING_COL AND
                    CARDS-ROW > TEST_ROW AND CARDS-ROW < 20.
              TEST_ROW = CARDS-ROW.
              PERFORM MAKE_CARD.
              MOVING_SUIT = SUIT.
              MOVING_CARD = CARD.
              MOVING_ROW = CARDS-ROW.
              MOVING_COL = CARDS-COL.
              MOVING_NUM = CARD_NUM.
            ENDIF.
          ENDLOOP.

        ENDIF.

       IF MOVING_SUIT = TO_SUIT.
          CASE MOVING_SUIT.
            WHEN ‘C’. TEST_NUM = CURR_C + 1.
            WHEN ‘H’. TEST_NUM = CURR_H + 1.
            WHEN ‘D’. TEST_NUM = CURR_D + 1.
            WHEN ‘S’. TEST_NUM = CURR_S + 1.
          ENDCASE.

          IF TEST_NUM = MOVING_NUM.
            PERFORM DISCARD_CARD.
            CASE MOVING_SUIT.
              WHEN ‘C’. CURR_C = CURR_C + 1.
              WHEN ‘D’. CURR_D = CURR_D + 1.
              WHEN ‘S’. CURR_S = CURR_S + 1.
              WHEN ‘H’. CURR_H = CURR_H + 1.
            ENDCASE.
          ELSE.
            CURRENTFIELD = ‘Can only discard on next lower card’.
            MOVING_CARD = SPACE.
          ENDIF.
        ELSE.
          MOVING_CARD = SPACE.
          CURRENTFIELD = ‘Can only discard on same suit’.
        ENDIF.
      ELSE.
        MOVING_CARD = SPACE.
        CURRENTFIELD = SPACE.
      ENDIF.
    ENDIF.
  ENDIF.
  PERFORM SHOW_SCREEN.

ENDFORM.

*———————————————————————*
*       FORM MAKE_CARD                                                *
*———————————————————————*
FORM MAKE_CARD.

  SUIT_NUM = CARDS-ENTRY DIV 13.

  CASE SUIT_NUM.
    WHEN 0.SUIT = ‘D’.
    WHEN 1.SUIT = ‘H’.
    WHEN 2.SUIT = ‘C’.
    WHEN 3.SUIT = ‘S’.
  ENDCASE.

  CARD_NUM = CARDS-ENTRY MOD 13.
  CASE CARD_NUM.
    WHEN 0.CARD = ‘A’.
    WHEN 1.CARD = ‘2’.
    WHEN 2.CARD = ‘3’.
    WHEN 3.CARD = ‘4’.
    WHEN 4.CARD = ‘5’.
    WHEN 5.CARD = ‘6’.
    WHEN 6.CARD = ‘7’.
    WHEN 7.CARD = ‘8’.
    WHEN 8.CARD = ‘9’.
    WHEN 9.CARD = ’10’.
    WHEN 10.CARD = ‘J’.
    WHEN 11.CARD = ‘Q’.
    WHEN 12.CARD = ‘K’.
  ENDCASE.

ENDFORM.

*———————————————————————*
*       FORM MOVE_CARD                                                *
*———————————————————————*
FORM MOVE_CARD.

  IF CURRENTFIELD <> ‘BLANK’.
    CURRENTFIELD = ‘Moving xxx to’.
    MOVE MOVING_SUIT TO CURRENTFIELD+7(1).
    MOVE MOVING_CARD TO CURRENTFIELD+8(2).
    MOVE TO_SUIT TO CURRENTFIELD+14(1).
    MOVE TO_CARD TO CURRENTFIELD+15(2).
  ELSE.
    CURRENTFIELD = ‘Starting emtpy column’.
  ENDIF.

  IF MOVING_TYPE = ‘p’.
    MOVE ‘from pile’ TO CURRENTFIELD+18.

    LOOP
     AT CARDS.
      IF CARDS-ROW = 20 AND CARDS-COL = CURRENT_CARD.
        CARDS-COL = TO_COL.
        CARDS-ROW = TO_ROW + 1.
        CARDS-VIS = ‘y’.
      ENDIF.

      IF CARDS-ROW = 20 AND CARDS-COL > CURRENT_CARD.
        CARDS-COL = CARDS-COL – 1.
      ENDIF.

      MODIFY CARDS.

    ENDLOOP.

    CURRENT_CARD = CURRENT_CARD – 1.
    MAX_CARD = MAX_CARD – 1.
    IF MAX_CARD < MIN_CARD.
      MIN_CARD = MIN_CARD – 1.
      MAX_CARD = MIN_CARD.
    ENDIF.

    IF CURRENT_CARD < 1.
      CURRENT_CARD = MIN_CARD.
    ENDIF.
  ELSE.
    LOOP
     AT CARDS.
      IF CARDS-COL = MOVING_COL AND
       ( CARDS-ROW >= MOVING_ROW AND CARDS-ROW < 20 ).
        CARDS-COL = TO_COL.
        CARDS-ROW = TO_ROW + 1 + CARDS-ROW – MOVING_ROW.
        MODIFY CARDS.
      ENDIF.

    ENDLOOP.

    TEST_ROW = MOVING_ROW – 1.

    LOOP
     AT CARDS.
      IF CARDS-COL = MOVING_COL AND CARDS-ROW = TEST_ROW.
        CARDS-VIS = ‘y’.
        MODIFY CARDS.
      ENDIF.
    ENDLOOP.
  ENDIF.

  MOVING_CARD = SPACE.

ENDFORM.

*———————————————————————*
*       FORM DISCARD_CARD                                             *
*———————————————————————*
FORM DISCARD_CARD.

  MOVE ‘Discarding’ TO CURRENTFIELD.
  MOVE MOVING_SUIT TO CURRENTFIELD+13(1).
  MOVE MOVING_CARD TO CURRENTFIELD+14(2).
  CASE TO_SUIT.
    WHEN ‘C’.
      DISC_C+1(2) = MOVING_CARD.
    WHEN ‘D’.
      DISC_D+1(2) = MOVING_CARD.
    WHEN ‘H’.
      DISC_H+1(2) = MOVING_CARD.
    WHEN ‘S’.
      DISC_S+1(2) = MOVING_CARD.
  ENDCASE.

  IF MOVING_TYPE = ‘p’.
    MOVE ‘from pile’ TO CURRENTFIELD+18.
    LOOP
     AT CARDS.
      IF CARDS-ROW = 20 AND CARDS-COL = CURRENT_CARD.
        CARDS-COL = 0.
      ENDIF.

      IF CARDS-ROW = 20 AND CARDS-COL > CURRENT_CARD.
        CARDS-COL = CARDS-COL – 1.
      ENDIF.

      MODIFY CARDS.

    ENDLOOP.

    CURRENT_CARD = CURRENT_CARD – 1.
    MAX_CARD = MAX_CARD – 1.
    IF MAX_CARD < MIN_CARD.
      MIN_CARD = MIN_CARD – 1.
      MAX_CARD = MIN_CARD.
    ENDIF.

    IF CURRENT_CARD < 1.
      CURRENT_CARD = MIN_CARD.
    ENDIF.

  ELSE.
    LOOP
     AT CARDS.
      IF CARDS-ROW = MOVING_ROW AND CARDS-COL = MOVING_COL.
        CARDS-COL = 0.
        MODIFY CARDS.
      ENDIF.
    ENDLOOP.
    TEST_ROW = MOVING_ROW – 1.

    LOOP
     AT CARDS.
      IF CARDS-COL = MOVING_COL AND CARDS-ROW = TEST_ROW.
        CARDS-VIS = ‘y’.
        MODIFY CARDS.
      ENDIF.
    ENDLOOP.
  ENDIF.
  MOVING_CARD = SPACE.

ENDFORM.

02

02 2010

Hangman

*Create an online program and change UNIX_DICT_FILE
REPORT ZHANGMAN NO STANDARD PAGE HEADING.
* Put correct UNIX Words file on the next line.
DATA: UNIX_DICT_FILE(80) VALUE ‘/usr/share/lib/dict/words’.

INCLUDE <ICON>.
DATA: DICT_TAB(20) OCCURS 10000 WITH HEADER LINE,
      GIVEUP(20),
      LINE(80), GUESSES OCCURS 10 WITH HEADER LINE,
                CORRECT_GUESSES OCCURS 10 WITH HEADER LINE,
                MESG(60),
      LEN TYPE I,
      NUM_WORDS TYPE I,
      NUM_TRYS TYPE I,
      NUM_FAILS TYPE I,
      NUM_BADS TYPE I,
      NUM_GOODS TYPE I.
DATA  LETTER.
DATA: RUNT TYPE I, SEC TYPE I.
DATA: BEGIN OF PIC,
        ROW LIKE SY-CUROW,
        COL LIKE SY-CUCOL,
        LET,
      END OF PIC.
DATA: BEGIN OF FIG OCCURS 10,
        X(2),
        Y(2),
        L,
      END OF FIG.

INITIALIZATION.
  APPEND ‘6006|’ TO FIG.
  APPEND ‘60070’ TO FIG.
  APPEND ‘6008|’ TO FIG.
  APPEND ‘5908/’ TO FIG.
  APPEND ‘5909/’ TO FIG.
  APPEND ‘6109\’ TO FIG.
  APPEND ‘6108\’ TO FIG.
  MOVE ‘acrimonious’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘allegiance’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘ameliorate’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘annihilate’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘antiseptic’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘articulate’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘authoritative’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘benefactor’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘boisterous’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘breakthrough’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘carcinogenic’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘censorious’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘chivalrous’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘collarbone’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘commendable’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘compendium’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘comprehensive’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘conclusive’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘conscientious’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘considerate’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘deferential’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘denouement’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘determinate’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘diffidence’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘disruption’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘earthenware’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘elliptical’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘entanglement’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘escutcheon’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘extinguish’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘extradition’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘fastidious’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘flamboyant’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘forethought’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘forthright’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘gregarious’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘handmaiden’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘honeysuckle’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘hypocritical’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘illustrious’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘infallible’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘lumberjack’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘mischievous’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘mollycoddle’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘nimbleness’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘nonplussed’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘obliterate’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘obsequious’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘obstreperous’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘opalescent’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘ostensible’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘pandemonium’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘paraphernalia’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘pawnbroker’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘pedestrian’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘peremptory’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘perfunctory’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘pernicious’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘perpetrate’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘personable’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘pickpocket’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘poltergeist’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘precipitous’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘predicament’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘preposterous’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘presumptuous’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘prevaricate’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘propensity’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘provisional’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘pugnacious’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘ramshackle’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘rattlesnake’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘reciprocate’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘recrimination’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘redoubtable’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘relinquish’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘remonstrate’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘repository’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘reprehensible’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘resolution’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘resplendent’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘restitution’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘retaliation’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘retribution’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘saccharine’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘salubrious’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘skulduggery’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘skyscraper’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘soothsayer’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘tearjerker’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘transcribe’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘turpentine’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘unassuming’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘underscore’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘undertaker’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘underwrite’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘unobtrusive’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘vernacular’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘waterfront’ TO LINE.  APPEND LINE TO DICT_TAB.
  MOVE ‘watertight);’ TO LINE.  APPEND LINE TO DICT_TAB.

* If you do have the unix-dictionaryfile available, change this line.
  IF 1 = 2.
    OPEN DATASET UNIX_DICT_FILE FOR INPUT IN TEXT MODE.
    DO.
      READ DATASET UNIX_DICT_FILE INTO LINE LENGTH LEN.
      IF SY-SUBRC = 0.
        IF LEN < 20.
          APPEND LINE TO DICT_TAB.
        ENDIF.
      ELSE.
        EXIT.
      ENDIF.
    ENDDO.
    CLOSE DATASET UNIX_DICT_FILE.
  ENDIF.

  DESCRIBE TABLE DICT_TAB LINES NUM_WORDS.

*  write: ‘Number of words in dict:’,num_words.
  PERFORM PRINT_OUT.

*———————————————————————*
*       FORM PRINT_OUT                                                *
*———————————————————————*
  DATA: ABCDE LIKE SY-ABCDE.
*———————————————————————*
*       FORM PRINT_OUT                                                *
*———————————————————————*
FORM PRINT_OUT.
  DATA: WORD_MASK LIKE DICT_TAB, INDEX TYPE I.
  ABCDE = SY-ABCDE.
  SY-LSIND = 0.
  ULINE: AT /(16), AT 18(16), AT 35(15), AT 51(13).
  FORMAT COLOR COL_KEY.
  WRITE:/ ‘|’,ICON_ACTIVATE AS ICON NO-GAP, ‘ New Word ‘ HOTSPOT,
     ‘|’ NO-GAP ,SPACE NO-GAP COLOR COL_BACKGROUND,
          ‘|’, ICON_FAILURE AS ICON NO-GAP, ‘ Give Up! ‘ HOTSPOT,
     ‘|’ NO-GAP ,SPACE NO-GAP COLOR COL_BACKGROUND,
          ‘|’,ICON_SYSTEM_HELP AS ICON NO-GAP,’ Help Me ‘ HOTSPOT,
     ‘|’ NO-GAP ,SPACE NO-GAP COLOR COL_BACKGROUND,
          ‘|’,ICON_BREAKPOINT AS ICON NO-GAP,’ Exit! ‘ HOTSPOT,’|’.
  FORMAT RESET.
  ULINE: AT /(16), AT 18(16), AT 35(15), AT 51(13).
  WRITE:/.

  IF NOT DICT_TAB IS INITIAL.
*   print the word mask
    LEN = STRLEN( DICT_TAB ).
    DO.
      INDEX =  SY-INDEX – 1.
      LETTER = DICT_TAB+INDEX(1).
      SEARCH  CORRECT_GUESSES FOR LETTER.
      IF SY-SUBRC = 0.
        WORD_MASK+INDEX = LETTER.
      ELSE.
        WORD_MASK+INDEX = ‘_’.
      ENDIF.
      IF LEN = SY-INDEX .
        EXIT.
      ENDIF.
    ENDDO.

*   found the word
    IF WORD_MASK = DICT_TAB.
      ADD 1 TO NUM_GOODS.
      WRITE:/ ‘Got it!.  Correct word is’,DICT_TAB,
            /  ‘It took ‘ ,NUM_TRYS,’tries.’.
      CLEAR: NUM_TRYS, NUM_FAILS, DICT_TAB.

    ELSE.
      WRITE:/  ‘Guess the Word:’ .
      DO LEN TIMES.
        INDEX = SY-INDEX – 1.
        LETTER = WORD_MASK+INDEX.
        WRITE: LETTER.
      ENDDO.

*     print guesses
      WRITE: /  ‘Guesses’.
      SORT GUESSES.

      LOOP
       AT GUESSES.
        WRITE:  GUESSES NO-GAP.
      ENDLOOP.
      NEW-LINE.

*     check max failures
      IF NUM_FAILS < 7.
*     print keyboard
        ULINE AT /(55).
        DO 26 TIMES.
          LETTER = ABCDE.
          IF SY-INDEX = 14 OR SY-INDEX = 1. WRITE:/  SPACE. ENDIF.
          WRITE: (3)LETTER CENTERED HOTSPOT COLOR COL_KEY .
          SHIFT ABCDE.
        ENDDO.
        WRITE:/ MESG.
      ELSE.
        WRITE:/ ‘Correct Word was’,DICT_TAB.
        WRITE:/ ‘Pick a new word’.
        ADD 1 TO NUM_BADS.
        CLEAR DICT_TAB.
      ENDIF.

      PERFORM DRAW_FIG.
    ENDIF.
  ELSEIF NOT GIVEUP IS INITIAL.
    WRITE:/ ‘Correct Word was’,GIVEUP.
    CLEAR GIVEUP.
  ENDIF.
  SKIP TO LINE 11.
  ULINE AT /(64).
  WRITE:/’|’,
          (20) ‘Words fully guessed’, (7)NUM_GOODS,’| ‘,
          (20) ‘Words not guessed’,(7)NUM_BADS,’|’.
*    write:/’Letter Guesses’, num_trys, ‘Failed Guesses’,num_fails.
  ULINE AT /(64).

ENDFORM.
*———————————————————————*
*       FORM RANDOM                                                   *
*———————————————————————*
FORM RANDOM.
  GET RUN TIME FIELD RUNT.
  GET TIME.
  SEC = SY-UZEIT MOD 60.
  RUNT = RUNT MOD 100000.
  MULTIPLY RUNT BY SEC.
  GET TIME.
  RUNT = RUNT MOD 100000.
  ADD SEC TO RUNT .
ENDFORM.

AT LINE-SELECTION.
  DATA: FIELD(30),VALUE(50).
  GET CURSOR FIELD FIELD VALUE VALUE.
  IF FIELD = ‘ICON_ACTIVATE’ OR VALUE = ‘ New Word’.
    PERFORM NEW_WORD.
  ELSEIF FIELD = ‘ICON_FAILURE’ OR VALUE = ‘ Give Up!’.
    PERFORM GIVE_UP.
  ELSEIF FIELD = ‘ICON_SYSTEM_HELP’ OR VALUE = ‘ Help Me’.
    PERFORM PRINT_HELP.
  ELSEIF FIELD = ‘ICON_BREAKPOINT’ OR VALUE = ‘ Exit!’.
    LEAVE PROGRAM.
  ELSEIF FIELD = ‘LETTER’ AND NOT VALUE IS INITIAL.
    PERFORM TRY_WORD USING VALUE+1(1).
  ENDIF.

*&———————————————————————*
*&      Form  NEW_WORD
*&———————————————————————*
FORM NEW_WORD.
  IF NOT DICT_TAB IS INITIAL.
    ADD 1 TO NUM_BADS.
  ENDIF.
  DO.
    PERFORM RANDOM.
    RUNT = RUNT MOD NUM_WORDS.
    READ TABLE DICT_TAB INDEX RUNT.
    IF NOT DICT_TAB(1) CO SY-ABCDE AND DICT_TAB NA ‘0123456789’.
      EXIT.
    ENDIF.
  ENDDO.
  TRANSLATE DICT_TAB TO UPPER CASE.
  CLEAR: NUM_TRYS, NUM_FAILS.
  REFRESH: GUESSES, CORRECT_GUESSES.
  PERFORM PRINT_OUT.
ENDFORM.                               ” NEW_WORD

*&———————————————————————*
*&      Form  TRY_WORD
*———————————————————————-*
FORM TRY_WORD USING   P_VALUE TYPE C.
  SY-LSIND = 0.
  SEARCH GUESSES FOR P_VALUE.
  IF SY-SUBRC = 0.
    CONCATENATE ‘Letter’ P_VALUE ‘already guessed’
                                           INTO MESG SEPARATED BY SPACE.
  ELSE.
    APPEND P_VALUE TO GUESSES .
    IF DICT_TAB CS P_VALUE.
      CONCATENATE ‘Letter’ P_VALUE ‘matches’
                                           INTO MESG SEPARATED BY SPACE.
      APPEND P_VALUE TO CORRECT_GUESSES .
    ELSE.
      CONCATENATE ‘Letter’ P_VALUE ‘does not match’
                                          INTO MESG SEPARATED BY SPACE.
      ADD 1 TO NUM_FAILS.
    ENDIF.
    ADD 1 TO NUM_TRYS.
  ENDIF.
  PERFORM PRINT_OUT.
ENDFORM.                               ” TRY_WORD
AT PF8.
  PERFORM NEW_WORD.
*&———————————————————————*
*&      Form  GIVE_UP
*&———————————————————————*
FORM GIVE_UP.
  ADD 1 TO NUM_BADS.
  GIVEUP = DICT_TAB.
  CLEAR DICT_TAB.
  PERFORM PRINT_OUT.
ENDFORM.                               ” GIVE_UP

*———————————————————————*
*       FORM DRAW_FIG                                                 *
*———————————————————————*
FORM DRAW_FIG.
*   |
*   0
*  /|\
*  / \
*
  BACK.
  SKIP 4.
  WRITE: /55 ‘  ——-‘.
  WRITE: /55 ‘  |’.
  WRITE: /55 ‘  |’.
  WRITE: /55 ‘  |’.
  WRITE: /55 ‘  |’.
  WRITE: /55 ‘  |’.
  WRITE: /55 ‘———‘.

  LOOP
   AT FIG TO NUM_FAILS.
    BACK.
    SKIP TO LINE FIG-Y.
    WRITE: AT FIG-X FIG-L.
  ENDLOOP.
  BACK.
ENDFORM.

*&———————————————————————*
*&      Form  PRINT_HELP
*&———————————————————————*
FORM PRINT_HELP.
  ULINE AT /(55).
  WRITE:
  /’What Is “Hangman?”‘,
  /, /'”Hangman” is an old schoolkid game where the’,
  /’computer picks a word or a phrase, and you’,
  /’try to reconstruct it by picking letters.’,
  /’You have a certain number of chances to win.’,
  /’Each time you pick an incorrect letter, you ‘,
  /’lose a chance.’,/,
  /’Loss of a chance is traditionally depicted by adding’,
  /’more body parts to a picture of a hanging man.’,
  /’Once the man is complete, the game is over and you lose.’.
  ULINE AT /(55).
  WRITE:/ ‘Click Green Back Arrow or press F3 to continue…’.
  ULINE AT /(55).
ENDFORM.                               ” PRINT_HELP

02

02 2010


CookieDurationDescription
cookielawinfo-checkbox-analytics11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional11 monthsThe cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance11 monthsThis cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy11 monthsThe cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional
Performance
Analytics
Advertisement
Others