Replace Conversion Exit FM with ALPHA in ABAP new syntax


Overview

This article covers the new syntax introduced in SAP ABAP, focusing on the ALPHA keyword and its application in handling leading zeros.

Key Concepts

1. ALPHA Keyword

  • Purpose: The Alpha keyword simplifies the process of adding and removing leading zeros in SAP ABAP.
  • Usage :
    • ALPHA = IN: This syntax is used to add leading zeros to a number or string.
    • ALPHA = OUT: This syntax is used to remove leading zeros from a number or string.

2. Previous Function Modules

  • Previously, two function modules were commonly used:
    • CONVERSION_EXIT_ALPHA_OUTPUT: To add leading zeros.
    • CONVERSION_EXIT_ALPHA_INPUT: To remove leading zeros.

3. New Syntax Benefits

The introduction of the ALPHA keyword allows for a more streamlined approach, eliminating the need for multiple function modules. This enhances code readability and efficiency.

Practical Application

The below examples demonstrates practical usage of ALPHA keyword, showcasing how it can be implemented in real time programming.

For Removing Leading Zeros

Instead of:

DATA lv_int TYPE char10 VALUE '0000098765'.

DATA lv_ext TYPE char10.


CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT' 

  EXPORTING

    input  = lv_int

  IMPORTING

    output = lv_ext.  


Use:

DATA lv_int TYPE char10 VALUE '0000098765'.

DATA(lv_ext) = |{ lv_int ALPHA = OUT }|.


For Adding Leading Zeros:

Instead of:

DATA lv_ext TYPE char10 VALUE '12345'.

DATA lv_int TYPE char10.


CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT' 

  EXPORTING

    input  = lv_ext

  IMPORTING

    output = lv_int.


Use:

DATA lv_ext TYPE char10 VALUE '12345'.

DATA(lv_int) = |{ lv_ext ALPHA = IN }|.


Summary

The ALPHA keyword is a significant addition to the SAP ABAP syntax, making it easier to manage leading zeros without relying on separate function modules.

Important Points

ALPHA = IN = Add leading zeros

ALPHA = OUT = Remove leading zeros

Post a Comment

Previous Post Next Post