Blog > This is not the next article about new ALPHA conversion – ABAP Tricks #1

This is not the next article about new ALPHA conversion – ABAP Tricks #1

ALPHA_conversion_Halicki
Andrzej Halicki SAP Integration Consultant
icon__calendar 2019-09-19

In this short blog post Andrzej Halicki reveals:

  • How to use ABAP 7.4 syntax to reduce the amount of redundant code
  • How does ALPHA conversion work
  • How to Constructor expression CONV

New ALPHA conversion

Well, actually it is but in slightly different approach. We all know what ALPHA conversion is and how it looked like before ABAP 7.4. Unfamous CONVERSION_EXIT_ALPHA_INPUT and CONVERSION_EXIT_ALPHA_OUTPUT. There may be some newbies among us so let’s remind what it does. If you want to perform SQL query in ABAP very often you need to convert your data to internal format (or in the opposite direction when you take care for user experience and want to get rid of leading zeros). In the ancient times you would do something like this:

Code Snippet

Kinda lenghty isn’t it? But with arrival of ABAP 7.4 it changed a little bit (a lot). You can achieve the same result in one line instead of 5:

Code Snippet Int4

So far I haven’t discovered anything you were not aware of before – it’s been around for some time.

Let’s imagine a scenario, where you have a mapping table with generic fields or range of type char20 – you don’t have data element you can refer to. In this case you would need to do something like this:

Code Snippet Int4 3

A little bit annoying – you need to create helping variable, perform alpha conversion and then assign. And this is where we get to the point of this article – you can do it even easier.

Constructor expression CONV

You could combine the above solution with constructor expression CONV!

Code Snippet Int4 4

Imagine how easier life gets with this technique and how many helping variables can be saved. You can use it directly in VALUE constructors and FOR loops:

Code Snippet Int4 5

Code Snippet Int4 6

And what do you think about this approach?

Andrzej Halicki SAP Integration Consultant
Andrzej Halicki is an SAP integration consultant and developer. He has strong experience in ABAP development across local and international projects. Andrzej works with the latest solutions like ABAP for HANA and Cloud Platform Integration. Author of many technical articles that are available online in the SAP Community and Int4 website.