Sometimes, there is a need to know the length of string provided by user. In that case we program to find string length in ABAP. It is not a question that is merely asked in an interview but an important keyword that is used in day to day programming.
To find length of String in ABAP, you need to use a keyword STRLEN which means string length. The following program implements the same:
PARAMETERS: lv_data1 type string. Data : lv_data2(10) type i. lv_data2 = strlen( lv_data1 ) . " The proper Syntax is strlen and then 'bracket open without space' " then space then Your Number/String then space then close bracket else it will give an error Write: lv_data2.
This program is self explanatory, still I am explaining the same step by step below:
- Initially, we have defined a parameter lv_data1 of data type string. This parameter will be used to take input from user.
- Then, we have defined a variable lv_data2 of data type i i.e. integer and length 10.
- In this line, we have used ABAP keyword STRLEN to find the length of the string saved in variable lv_data1. The length that we have calculated is saved in variable lv_data2.
- Now, here we have just printed the output.