Depending on the data type of the field, there is a conversion when the contents of a screen field are converted from display format to SAP-internal format and vice versa. If this standard conversion is not suitable, you can override it by defining a conversion routine in the underlying domain.
Conversion routines are identified by a five-place name and are stored as a group of two function modules. The function modules have a fixed naming convention. The following function modules are assigned to conversion routine xxxxx:
The INPUT module converts from display format to internal format, and the OUTPUT module converts from internal format to display format.
Execution of the Conversion Routine
If a screen field refers to a domain with a conversion routine, this conversion routine is executed automatically when entries are saved in this screen field or when values are displayed in this screen field.
The conversion routine of the domain is also triggered when the field contents are output with the WRITE statement.
The following example explains a conversion routine for a table.
Table SPFLI in the flight model contains information about the flights offered by the carriers. The time for each flight is recorded in field FLTIME. The time of the flight must be entered and displayed in input templates in the format HHH:MM (Hours:Minutes). The system stores the entered flight time in the database as an integer number (number of minutes of the flight). The system stores an entry 3:27 in the database as 207 (3 hours, 27 minutes = 207 minutes).
Field FLTIME refers to domain S_DURA, to which conversion routine SDURA is assigned. The value is converted by the two function modules CONVERSION_EXIT_SDURA_INPUT and CONVERSION_EXIT_SDURA_OUTPUT.
You can see the explained example in the figure below.
You can also trigger a conversion routine by specifying its five-place name in the attributes of a field in the Screen Painter, or with the addition USING EDIT MASK <Name of conversion routine> in the WRITE command in the program. With the USING NO EDIT MASK addition in the WRITE statement, you can skip a conversion routine defined for a domain when outputting.
The two function modules of a conversion routine must have precisely two parameters with the names INPUT and OUTPUT for the value to be converted and the converted value.
The INPUT parameter in the INPUT conversion and the OUTPUT parameter in the OUTPUT conversion must not have any reference fields because the value passed in the call could have a different length than that expected.
Programming Conversion Routines
ABAP statements that result in an interruption of processing (such as CALL SCREEN, CALL DIALOG, CALL TRANSACTION, SUBMIT, COMMIT WORK, ROLLBACK WORK, MESSAGE I, MESSAGE W) are not allowed in conversion routines.
Only A messages are meaningful in output conversion, but A, E and S messages can be triggered in input conversion (although S messages are not meaningful here). E messages result in an error dialog. The system does not intercept exceptions in the call.
The output conversion is also triggered with WRITE and WRITE TO. The conversion routine can occur frequently with lists. The output conversion must be programmed as efficiently as possible.
No external performs must be used in conversion routines. Programs that are called externally use the table work areas of the first calling main program. In conversion routines this can result in errors that cannot be easily analyzed since they are sometimes called at unpredictable times in the program flow.