Quantcast
Channel: Tweaks
Viewing all articles
Browse latest Browse all 66
โ†ง

Why Underscore โ€œ_โ€ is Converted into Space at Runtime in ABAP?

$
0
0

Few years back, my seniors say they feared ABAP will be Dead. But today with S/4HANA, CDS, AMDP, RESTful Application Programming, ABAP Programming for SAP Fiori, ABAP on Cloud .. fewwwwhh!! ABAP cannot be more ALIVE and KICKing. So, it is good time we come back to basics of SAP ABAP.

In this article we will discuss a very simple topic, Why _ (underscore) is converted into space at runtime and how can we handle it? Lets discuss the scenario once. Here I am considering standard t-codes and screens viz SE11, SE38 etc to show the standard behavior in ABAP or should we say the exemption which is there in ABAP? ๐Ÿ™‚

Which Standard behavior I am talking about? Letโ€™s dig a little more. Here we are talking about โ€˜_โ€™ . This special character is converted into space at runtime. Letโ€™s see it first hand. Got to t-code SE11. If you enter _ (underscore) in any of the selection input, it will get converted into space. Let me try putting _(underscore) in SE11 selection input and see the behavior by clicking enter.

This image has an empty alt attribute; its file name is image-9.pngThis image has an empty alt attribute; its file name is image-8.png
Before and after clicking enter, โ€˜_โ€™ will disappear.

As it is clear from above example, _(underscore) will disappear after clicking enter. Letโ€™s take into account another example. We have some standard table. For example VBAP. Lets see what is the behavior in the selection screen for table input.

If we input _ (underscore) in any of the table fields and hit the return key, it vanishes.

This image has an empty alt attribute; its file name is image-11.pngThis image has an empty alt attribute; its file name is image-12.png
Same Behavior here also after clicking enter

Now the question arises why this behavior in ABAP? What could be the reason that _ (underscore) and ! (exclamation) are getting converted into space at runtime. Let us try to understand the behavior with few datatypes. We have created the following simple report for better explanation.

In this report , I have created parameters to get input from user. I have used char1, char2, string, sstring, text40 to see the behavior. Enter _ (underscore) as input to all the parameters.

Can you guess the Output?

From this it is clear that only string data type supports the โ€œ_โ€(underscore). My hypothesis which might be completely wrong is that because strings are dynamic data objects and string can hold variable length, it shows _. String datatype has no upper limit. sstring datatype also has variable length but there is upper limit.

If anyone of you have a better explanation, please put in the comments sections. We will update our post accordingly.

Now, if the text consists of several words, they are joined together automatically by underscores, which are replaced by spaces at runtime. This could be one of the reasons . But string hold value dynamically and there is no reset on the field at runtime.

How can we store underscore in database table with char1 (if we need only one character)?

We do not have any specific real business case. Lets assume for some reason we want to save _ in one of the fields of the table. Can can we achieve it? Is it really possible to achieve it? Can we store underscore as single character in database?

Answer is yes, we can do that. We can do it with the help of TMG (Table Maintenance Generator).

Follow the below steps

1. Create a database table using SE11. I created the database table with fields as follows:

2. Create Table Maintenance generator from utilities> Table Maintenance Generator (TMG) as follows:

3. After creation of TMG, double click on overview screen number, following screens will open:

This image has an empty alt attribute; its file name is image-18.pngThis image has an empty alt attribute; its file name is image-19.png
After double clicking overview screen number ,other screen will open as shown

4. Now click on layout (highlighted above), following screen will open. Double click on field and select โ€œWithout Resetโ€ and โ€œWithout Templateโ€. With the help of these you can add underscore in DB table. Click save and activate button.

5. Now you will be able to save _ (underscore) in table as follows:

Also Read โ€“ SAP TMG โ€“ No Need to Delete & Regenrate After Change of Table Structure

This was one trick which I recently learned. Not sure, how many of you will need in real projects. But, this was a very unique and different learning experience. Therefore thought of sharing with you. Do let me know how you feel about this simple concept.

Comments Please

Please follow our LinkedIn Page,LinkedIn Group, Facebook Page, Facebook Group, Twitter , Instagramand Telegram SAP Technical Group.

Do not forget to SUBSCRIBE to our YouTube Channel for Free Courses and Unconventional Interesting Videos.

Also consider joining SAPYardโ€™s Telegram Channel for SAP Blogs and Tutorials.

Save our number +1-251-727-9273 and send us a Whatsapp message โ€˜LEARNโ€™ to be part of our Learning Community.

Also Check ABAP on Cloud Tutorials

The post Why Underscore "_" is Converted into Space at Runtime in ABAP? first appeared on https://sapyard.com.

โ†ง

Viewing all articles
Browse latest Browse all 66

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>