cancel
Showing results for 
Search instead for 
Did you mean: 

Why am I able to create special variable which starts with "!" using DATA statement?

Surendra_Karma
Explorer
0 Kudos
400

Hello SAP Community,

I encountered an interesting scenario while working with ABAP where I was able to create a variable that starts with the "!" character using the DATA statement. According to the typical naming conventions for ABAP variables, this should not be possible. Here is a sample example to illustrate this:

surendra_karma_9669_80_1-1722703558816.png

 

surendra_karma_9669_80_2-1722703689247.png

In this example, the variable !_lv_var is created and used without any issues. Also, it can be used without "!" like _lv_var. I am curious to understand why this is allowed and if it is related to any recent changes or enhancements in the ABAP language syntax.

Can someone explain why this behavior is possible and if there are any specific use cases or contexts where this is intended?

Thank you!

junwu
Active Contributor
0 Kudos
Have you read the F1 help?
Surendra_Karma
Explorer
0 Kudos
Yes, Junwu. I have reviewed the F1 help on naming conventions. To summarize, it states that variables can be up to 30 characters long, may include letters (A-Z), numbers (0-9), and underscores (_), and must begin with a letter or an underscore. However, in practice, when using SAP GUI, I found that it also allows declaring variables that start with a digit. The "!" character is particularly interesting because it seems to serve a special referencing purpose. I can use variables as either !lv_var or lv_var, and both work without issue.
Sandra_Rossi
Active Contributor
"The character ! can be written directly before a name operand of a single operand in order to distinguish it from an ABAP word with the same notation in a statement." https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abennames_escaping.ht...
junwu
Active Contributor
0 Kudos
select ! and then F1. that's the correct documentation you have to read if there is any doubt about syntax
View Entire Topic
Surendra_Karma
Explorer

@Sandra_Rossi : Thanks for the explaination.

 

Answer:

  • "The character ! can be written directly before a name operand of a single operand in order to distinguish it from an ABAP word with the same notation in a statement.

https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abennames_escaping.ht...