SQL Server administration and T-SQL development, Web Programming with ASP.NET, HTML5 and Javascript, Windows Phone 8 app development, SAP Smartforms and ABAP Programming, Windows 7, Visual Studio and MS Office software
Development resources, articles, tutorials, code samples, tools and downloads for SAP HANA and ABAP, HANA Database, SQLScript, SAP UI5, Screen Personas, Web Dynpro, Workflow

Find Length of a String in ABAP using STRLEN function

To find the length of a string variable or character data in ABAP, developers use ABAP STRLEN string function. STRLEN ABAP string length function is also used to validate input string before using it or assigning to an other variable.

Below ABAP string code calculates the length of the input string variable using ABAP string function STRLEN, stores the length in an integer variable. Then using WRITE function, the length of the input string variable is displayed on the screen.

find string length using ABAP STRLEN function

data lv_str type string.
data lv_int type i.
data lv_length type string.

lv_str = 'Kodyaz'.
lv_int = STRLEN( lv_str ).
lv_length = lv_int.

CONCATENATE lv_str 'has a length of' lv_length 'characters' INTO lv_str separated by space.

CONDENSE lv_str.
write lv_str.
Code

ABAP STRLEN function for string length

An other sample ABAP code below is validating the length of a date variable. If the input string variable has a length of 8 characters then it converts the date string into another date format.

data LV_STR_DATE type CHAR10.

if STRLEN( LV_STR_DATE ) = 8.
 concatenate LV_STR_DATE+4(4) LV_STR_DATE+2(2) LV_STR_DATE(2) into LV_STR_DATE.
 write LV_STR_DATE.
endif.
Code


SAP HANA and ABAP

Install SAP Free
CRM Companies List
Web Based CRM Software


Copyright © 2004 - 2021 Eralper YILMAZ. All rights reserved.