Variant Maintenance
Variant Maintenance
Variant Maintenance
Variant maintenance allow you to save sets of input values for programs that you often start with the same selections. You can use them for any programs except subroutine pools (type S).
Variants: Overview
Use Whenever you start a program in which selection screens are defined, the system displays a set of input fields for database-specific and program-specific selections. To select a certain set of data, you enter an appropriate range of values. For further information about selection screens, refer to Selection Screens in the ABAP User's Guide. If you often run the same program with the same set of selections (for example, to create a monthly statistical report), you can save the values in a selection set called a variant. You can create any number of variants for any program in which selection screens are defined. Variants are assigned exclusively to the program for which they were created. You can also use variants to change the appearance of the selection screen by hiding selection criteria. This is particularly useful when you are working with large selection screens on which not all of the fields are relevant. Reports, module pools, and function groups may have several selection screens. It is therefore possible to create a variant for more than one selection screen. Variants are an interface between the user and the selection screen. They can be used both in dialog and in background mode, although their uses are slightly different. Variants in Dialog Mode In dialog mode, variants make things easier for the user, since they save him or her from continually having to enter identical values. They can also make the selection screen easier to read, because you can use them to hide input fields. Running an executable program with a variant containing an optimal set of values also reduces the capacity for user error. The optimized database selections speed up the runtime of the program. Variants in Background Mode Variants are the only method for passing values to a report program in a background job. Therefore, when you run a program in the background, you must use a variant (or SUBMIT... VIA JOB). To avoid you having to create a new variant each time you run the report, ABAP contains a mechanism allowing you to pass variable values to variants. See Variable Values in Variants. To ensure that an executable program is always started using a variant, you can specify in the program attributes that the program may only be started in this way. Features Creation of variants Display, change, copy, print, and delete variants Use and definition of variables in variants 1. Variable date calculation 2. User-specific fixed values
Page: 1 of 13
File: 130471100.doc
Variant Maintenance
Initial Screen
Call You access the initial screen of the variant maintenance tool from the initial screen of the ABAP Editor (SE38). Enter the name of the program, select Variants in the Subobjects group box, and then choose Display or Change.
Functions The following functions are available on the initial screen: Create variants Display variant directory Display and change values and attributes Copy, delete and rename variants
Page: 2 of 13
File: 130471100.doc
Variant Maintenance
Page: 3 of 13
File: 130471100.doc
Variant Maintenance
3. Choose Create. If the program has more than one selection screen, a dialog box for screen assignment appears. The dialog box does not appear if the program only has one selection screen. The selection screen appears in this case. If there is more than one selection screen, select the screens for which you want to create the Example:
4. variant.
If you choose Variant for All Selection Screens, the variant also applies to any selection screens that were included in the program only after you created the variant Otherwise, the variant only supplies values to the selection screens that you select in the list. 5. Choose Continue. The (first) selection screen for the report appears. If your program has more than one selection screen, use the scroll buttons in the left-hand corner of the application toolbar to navigate between them and to fill the fields with values. If you keep scrolling forwards, the Continue button appears on the last selection screen. 6. Enter the desired selection values, including multiple selection and dynamic selection. 7. Choose Continue. Result You then see an overview screen (ABAP: Save Variant), where you can specify attributes for your variant and save it. See also Attributes of Variants. Note that when you create a new variant, you always have to fill in values and attributes. Name of Variant: This name can comprise up to 14 alphanumeric characters. The character % is not allowed. If you want the variant to be transported automatically with its program, you must
Page: 4 of 13
File: 130471100.doc
Variant Maintenance
create a system variant. The name of a system variant must start with "CUS&" for customers, and "SAP&" for SAP system variants You can only use the "&" character within this prefix in the name of a system variant. It must not occur in any other variant names. System variants are connected to the Workbench Organizer and can be created in all clients. However, they are stored solely in client 000. They can be accessed from all clients.
Variant Attributes
To maintain the attributes of a variant, follow the same procedure as described in creating a variant. Example:
You can enter the following attributes on the ABAP: Save Attributes of Variant screen: Description Enter a short, meaningful description of the variant. This can be up to 30 characters long. Only for background processing Select this field if you want the variant to be available for background processing but not in dialog mode. Protect variant Select this field if you want to prevent your variant being changed by other users. Only display in catalog Select this field if you only want the variant name to be displayed in the variant catalog (and not when the user calls the F4 value help). System variant This field cannot accept input. It is set automatically when a system variant (beginning with CUS& or SAP&) is created. You can also assign the following further attributes to the selections in a variant: Type
Page: 5 of 13
File: 130471100.doc
Variant Maintenance
The system indicates here whether a field is a parameter (P) or a selection option (S). Protected Select this column for each selection that you want to write-protect on the selection screen. These fields are visible on the selection screen when the user starts a program with the variant, but do not accept user input. Invisible If you select this column, the system hides the corresponding field on the selection screen. This allows you to change the appearance of the selection screen. Selection variable If you select this column, you can set the value of the corresponding selection dynamically at runtime. The different ways of doing this are explained in the section Variable Values in Variants. Without values If you select this field, the contents of the corresponding field are not saved with the variant. This is useful if you do not want to overwrite the contents of this field on the selection screen. For example, suppose you create a report 'SAPTEST', with the parameter 'TEST', for which you create the variant 'TESTVARIANT'. In the variant, you set the 'Without values' flag for the parameter. Then, you run time program and enter the value 'ABCD' in the TEST field. If you now retrieve the 'TESTVARIANT' variant, the TEST field retains the value ABC instead of being overwritten by SPACE. SPA/GPA This attribute only appears if you created the corresponding selection criterion using 'MEMORY ID xxx. You can switch the SPA/GPA handling on and off in the variant. This means that fields filled using SPA/GPA appear with their initial values after you have loaded a variant in which those fields have an initial value. Other Functions Save When you have entered all of the parameters, save your settings. When you create a new variant, you must enter both values and attributes. You can only save your variant on the attribute screen. However, if you only want to change values or attributes of an existing variant, you can save on the corresponding screen. Changing the Screen Assignment The attribute screen lists all of the selection screens for which the variant is defined. While it is possible for the same selection criterion to appear on more than one screen, the selection criterion itself may be a global field in the program. For this reason, it can only be set once, when the selection criterion occurs for the first time. If you want to change the screen assignment later on, check the relevant screen number and choose Copy Screen Assignment.
Page: 6 of 13
File: 130471100.doc
Variant Maintenance
Changing Variants
Procedure To change a variant: 1. Open the variant as described in Creating a variant. 2. On the initial screen, choose Values or Attributes. 3. Choose Change. Depending on your choice in step 2, the program selection screen or the attributes screen appears. 4. When you have finished changing the values or attributes, save your changes on the same screen.
Deleting Variants
Procedure 1. Open the appropriate variant as described in Creating a Variant. 2. On the initial screen, choose Variants Delete. The ABAP: Delete Variants dialog box appears. 3. Choose whether you want to delete the variant in all clients, or only in the current client. 4. Confirm your choice. Result The system displays an appropriate message in the status bar. You can delete several variants at once from the variant catalog. Choose Delete variants, select the relevant variants in the selection dialog box, and choose Delete.
Printing Variants
Procedure To print a variant, enter its name on the initial screen of the variant maintenance tool, select either Attributes or Values in the sub-objects group box and choose Print. Note that you cannot print the values if you are working in change mode.
Page: 7 of 13
File: 130471100.doc
Variant Maintenance
The Print Screen List screen appears. If the default print parameters are incorrect, enter the correct values (consult your system administrator if you are not sure). Ensure that the Output immediately option is set. Choose Print.
Page: 8 of 13
File: 130471100.doc
Variant Maintenance
5. 6.
Select type D for dynamic date calculation. In the Variable Name column, choose the F4 help. All possible date calculations are displayed.
7.
Page: 9 of 13
File: 130471100.doc
Variant Maintenance
8. 9.
If necessary, enter the required values. To subtract days, you must enter them in the format of a number with a minus sign in the last position (for example 10-). Note that you cannot change the proposals in the list, nor can you add new proposals. Here you can also specify the selection options for the date calculation. Save your entries. You return to the attributes screen. Save the attributes.
Result You have assigned a variable to a variant for date calculation and saved it. Note that after choosing the selection variable, you must save the attributes again on the attributes screen. You can choose Selection Options on the selection variable screen to make further specifications for date calculations
DATA: CCODE(6). ... SELECT-OPTIONS: CC FOR CCODE MEMORY ID BUK. ... Features Creating User Values See Creating user-specific variables. Changing User Values You can change the values of an existing user variable in two ways: Using the function module VARI_USER_VARS_*. See Changing values from the program) From the selection screen (changed by the user him- or herself). See Changing values interactively).
Page: 10 of 13
File: 130471100.doc
Variant Maintenance
1. Choose Goto User variables. A dialog box appears, containing the user-specific selection criteria
and parameters. From here, you can display or change the values. 2. If you choose Change, a further dialog box appears, in which you can decide whether to accept the values proposed in the variables or use the entries on the selection screen. 3. In either case, another dialog box appears, in which you can enter and save the required values.
Note that these changes affect all variants that use the same user-specific variables.
Page: 11 of 13
File: 130471100.doc
Variant Maintenance
Function Deletes variable values Renames variable values Dialog for entering variable values
To include these function modules in your program, choose Edit Insert statement CALL FUNCTION from the ABAP Editor.
However, note that every change of a value in Table TVARVC affects all variants using this particular variable.
Page: 12 of 13
File: 130471100.doc
Variant Maintenance
3. Choose the F4 key. A list of all variants defined for the program is displayed. 4. Select a variant. 5. Confirm your selection by choosing Select or ENTER. The selection screen of the program is displayed. Those fields that were filled via the variant, already contain values. 6. Choose Execute to run the program.
Page: 13 of 13
File: 130471100.doc