Input and Output Conversions 

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 and when outputting with the ABAP statement WRITE.

Conversion Routine

Non-standard conversions from display format to SAP-internal format and vice versa are implemented with so-called conversion routines. 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 ABAP function modules are assigned to the conversion routine xxxxx:

The INPUT module carries out the conversion from display format to internal format, while the OUTPUT module converts from internal format to display format. If required, new conversion routines can be added. However, the corresponding function modules must adhere to the above naming conventions and to the conventions defined below.

When is a Conversion Routine Executed?

If a screen field refers to a domain with a conversion routine, this conversion routine is executed automatically each time an entry is made in this screen field or when values are displayed in this screen field.

Table SPFLI in the flight model contains information about the flights offered by the carriers. The time for each flight is recorded in the field FLTIME. Enter and display the time of the flight in input templates in the form HHH:MM (hours:minutes). The time of the flight entered should be stored in the database as an integer number (number of minutes of the flight). An entry 3:27 is therefore stored in the database as 207 (3 hours, 27 minutes = 207 minutes).

Field FLTIME refers to domain S_DURA, to which the conversion routine SDURA is assigned. The value is thus converted by the two function modules CONVERSION_EXIT_SDURA_INPUT and CONVERSION_EXIT_SDURA_OUTPUT.

A conversion routine can also be triggered directly in the program by specifying its five-place name in the attributes of a field in the Screen Painter or by adding "USING EDIT MASK'==<Name of conversion exit>' " in the WRITE command.

Parameters

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 should not have any reference field because the screen or ABAP field assigned in the call could have a different length than that expected because a matchcode input is expected, for example.

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 the conversion routines.

During output conversion, only A messages are meaningful, but during input conversion, A, E and S messages can be triggered (although S messages are not very meaningful here). E messages result in an error dialog. Exceptions are not intercepted in the call.

The output conversion is also triggered with WRITE and WRITE TO. The conversion routine may therefore occur very frequently with lists. The output conversion should therefore be programmed to be as efficient as possible.

No external performs should be used in conversion routines because the table work areas of the first calling main program are also used in externally called programs. With conversion routines, this could result in errors that cannot be analyzed because they are sometimes included in the program flow at unexpected times.