Tips and Tricks for the ABAP® Programming Language
Y9030004: Simple determination of the string length ?
There are several possibilities to determine the string length within a field.
In general a function of “COMPUTE …” group is used to calc the string length: string length = STRLEN(strings). ” The STRLEN function is not necessarily one of the fastest routine ? “. One programmer know it better: Thanks for it. By the way: Activate ” Move ‘hugo’ …” , What is the time difference ?
ABAP™-Source-Code
You can cut and paste the source code directly into the ABAP™-Workbench.
REPORT Y9030004. "Release 3.1G, 4.5A
************************************************************************
* Copyright (c) 1999 by CT-Team, 33415 Verl, http://www.ct-software.com
*
* You can use or modify this report for your own work as long
* as you don't try to sell or republish it.
* In no event will the author be liable for indirect, special,
* Incidental, or consequental damages (if any) arising out of
* the use of this report.
*
************************************************************************
BREAK-POINT.
*//////////////////////////////////////////////////////////////////////*
MOVE: ' Find out the string length in a fast way'
TO SY-TITLE.
* STRLEN is not very quick
*//////////////////////////////////////////////////////////////////////*
************************************************************************
*************** Paramter declaration **********************
*
PARAMETERS: P_STRING(120) DEFAULT ' here is an abitrary string ...... '
LOWER CASE.
************************************************************************
*
*//////////////////////////////////////////////////////////////////////*
************* Main Section *******************
*//////////////////////////////////////////////////////////////////////*
*
PERFORM STRINGLAENGE.
*
*//////////////////////////////////////////////////////////////////////*
************* Subroutines *******************
*//////////////////////////////////////////////////////////////////////*
*
************************************************************************
* How long is the string ?
************************************************************************
FORM STRINGLAENGE.
*
BREAK-POINT 111.
ULINE. SKIP 1.
WRITE: /5 'Step 1: Simple determination of string length.' COLOR 5.
ULINE. SKIP 1.
*.......................................................................
*
IF P_STRING CP '*# '. ENDIF. " SY-FDPOS is set
* |||
* |||----> ' ' = only blanks up to end of line
* ||-----> # = character for blanks
* |------> * = any character
*.......................................................................
WRITE: /1 'String:', P_STRING COLOR 4.
WRITE: /1 'String length:', SY-FDPOS COLOR 6.
*
ENDFORM.
************************************************************************
************************************************************************
******************* END OF PROGRAM *************************************
