String Length in ABAP

by | Jun 3, 2018 | ABAP Programs

Home » SAP » ABAP » ABAP Programs » String Length in ABAP

Preface – This post is part of the ABAP Programs series.

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:

String Length in ABAP

String Length Image Illustration

ABAP Program

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:

  1. Initially, we have defined a parameter lv_data1 of data type string. This parameter will be used to take input from user.
  2. Then, we have defined a variable lv_data2 of data type i i.e. integer and length 10.
  3. 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.
  4. Now, here we have just printed the output.


Submit a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.