Pre-requisites: The readers must have the knowledge on basic ABAP programming. Purpose of this tutorial: This tutorial demonstrates how to create a wizard to do a step by step job in SAP. Introduction: Wizard is a tool that guides a user to do a certain task in SAP step by step. The real time example of a wizard is the one, which guides us while installing any software in our systems. The following function modules play vital role in wizard customization. SWF_WIZARD_CALL SWF_WIZARD_DIALOG_DATA_GET SWF_WIZARD_DIALOG_DATA_SET SWF_WIZARD_DIALOG_MODIFY SWF_WIZARD_DIALOG_OKCODE_GET SWF_WIZARD_DIALOG_OKCODE_SET SWF_WIZARD_DIALOG_REFRESH SWF_WIZARD_PROCESS SWF_WIZARD_PROCESS_INTERNAL SWF_WIZARD_PROCESS_MODIFY SWF_WIZARD_PROCESS_READ Have a look the following flow chart, for which we are going to build in wizard.
Step 1 : Create a program with three screens:
First screen to get two numbers as input with two radio buttons of arithmetic operations(Add/Subtract).
Second screen to show the addition result.
Third screen to show the subtraction result.
All these screens should be subscreens. So that they can be placed in wizard. Step 2 : Wizard title and description creation: To have wizard title and description in every screen of wizard, we need to create document text object. Go to transaction SE61 and create a dialog text object.
Create the title with a brief description, save and activate.
Function module SWF_WIZARD_PROCESS: This is the first and important function module to be called to define the wizard. The important input parameter to this function module is Definition, to which one internal table of program name, wizard link texts and subroutines of the wizard screen definitions is populated. Example program will have further details on this. Function module SWF_WIZARD_CALL: This function module is mainly used to call the wizard screen in a defined workflow. The important input parameter, what we have to supply to this function module, is Wizard_Data. Pass the document text object and screen type in the structure. The screen types in wizard are Starting screen Ending screen Input screen Normal screen Report screen Text screen These types of screens have been defined in <wizard> include. This must be included in your program to create wizard. Function module SWF_WIZARD_PROCESS_MODIFY: This is the one, which diverts the wizard flow according to the user input dynamically. The important input parameter that the user has to supply are Step_program, Step_form and Command. First two parameters say in which program, which wizard definition subroutine should be executed. Commands are three values. A, D and J. A - Activate a screen in wizard definition D - Deactivate a screen in wizard definition. J - Jump to a screen in the wizard flow. The example program of above flow chart will give you clear picture how to create the wizard. *&---------------------------------------------------------------------* *& Report ZRUN_WIZARD * *& Wizard creation demo. *&---------------------------------------------------------------------*
REPORT zrun_wizard.
* This include is mandatory to make use of wizard macro definition. INCLUDE: <wizard>.
DATA : it_wizdef TYPE TABLE OF swf_wizdef, wa_wizdef TYPE swf_wizdef, wa_wizard TYPE swf_wizard. * Creation of wizard definition. PERFORM wizard_append_def USING : 'ZRUN_WIZARD' 'Start' 'START_WIZARD', 'ZRUN_WIZARD' 'User Input' 'SHOW_SCREEN_0500', 'ZRUN_WIZARD' 'Addition result' 'SHOW_SCREEN_0501', 'ZRUN_WIZARD' 'Subtraction result' 'SHOW_SCREEN_0502', 'ZRUN_WIZARD' 'Complete' 'END_WIZARD'. * Starting the wizard. CALL FUNCTION 'SWF_WIZARD_PROCESS' EXPORTING container_compensation = 'X' TABLES definition = it_wizdef EXCEPTIONS operation_cancelled_by_user = 1 process_in_error = 2 OTHERS = 3.
*&---------------------------------------------------------------------* *& Form wizard_append_def *&---------------------------------------------------------------------* * This subroutine is used to create wizard definition. * It defines the subrountines that are to be executed in a program * and the wizard link texts. *----------------------------------------------------------------------* FORM wizard_append_def USING lv_program TYPE c lv_text TYPE c lv_subroutine TYPE c. CLEAR wa_wizdef. wa_wizdef-program = lv_program. wa_wizdef-text = lv_text. wa_wizdef-form = lv_subroutine. APPEND wa_wizdef TO it_wizdef. ENDFORM. "append_definition
*&---------------------------------------------------------------------* *& Form start_wizard *&---------------------------------------------------------------------* * This subroutines starts the wizard. *----------------------------------------------------------------------* FORM start_wizard TABLES container USING command. CLEAR wa_wizard. wa_wizard-descobject = 'WIZARD_DEMO_TEXT'. wa_wizard-screen_typ = wizard_screen_start. CALL FUNCTION 'SWF_WIZARD_CALL' EXPORTING wizard_data = wa_wizard start_column = 2 start_row = 2 EXCEPTIONS operation_cancelled_by_user = 1 back = 2 OTHERS = 3. swf_evaluate command.
ENDFORM. "start_wizard *&---------------------------------------------------------------------* *& Form show_screen_0500 *&---------------------------------------------------------------------* * This subroutine shows the initial input screen of two number * in the wizard. *----------------------------------------------------------------------* FORM show_screen_0500 TABLES container USING command. wa_wizard-docuobject = 'WIZARD_DEMO_TEXT'. wa_wizard-screen_typ = wizard_screen_normal. wa_wizard-subscpool1 = 'ZWIZARD_DEMO'. wa_wizard-subscreen1 = '0500'.
CALL FUNCTION 'SWF_WIZARD_CALL' EXPORTING wizard_data = wa_wizard start_column = 2 start_row = 2 EXCEPTIONS operation_cancelled_by_user = 1 back = 2 OTHERS = 3. swf_evaluate command. ENDFORM. "show_screen_0500 *&---------------------------------------------------------------------* *& Form show_screen_0501 *&---------------------------------------------------------------------* * This subroutine is used to show the addition result screen * in the wizard. *----------------------------------------------------------------------* FORM show_screen_0501 TABLES container USING command. wa_wizard-docuobject = 'WIZARD_DEMO_TEXT'. wa_wizard-screen_typ = wizard_screen_normal. wa_wizard-subscpool1 = 'ZWIZARD_DEMO'. wa_wizard-subscreen1 = '0501'.
*&---------------------------------------------------------------------* *& Form show_screen_0502 *&---------------------------------------------------------------------* * This subroutine is used to show the subtraction result screen * in the wizard. *----------------------------------------------------------------------* FORM show_screen_0502 TABLES container USING command. wa_wizard-docuobject = 'WIZARD_DEMO_TEXT'. wa_wizard-screen_typ = wizard_screen_normal. wa_wizard-subscpool1 = 'ZWIZARD_DEMO'. wa_wizard-subscreen1 = '0502'.
*&---------------------------------------------------------------------* *& Form end_wizard *&---------------------------------------------------------------------* * This subroutine is used to end the wizard. *----------------------------------------------------------------------* FORM end_wizard TABLES container USING command. wa_wizard-descobject = 'WIZARD_DEMO_TEXT'. wa_wizard-screen_typ = wizard_screen_end.
CALL FUNCTION 'SWF_WIZARD_CALL' EXPORTING wizard_data = wa_wizard start_column = 2 start_row = 2 EXCEPTIONS operation_cancelled_by_user = 1 back = 2 OTHERS = 3. swf_evaluate command. ENDFORM. "end_wizard Sample output: Execute the example program. The wizard is started.
Input two numbers and select one of arithmetic operations.
Result screen appears according to the arithmetic input.
The wizard is ended.
Summary: As a result of this tutorial, the reader will be able to create SAP wizard with dynamic screens.