- SAP ABAP - Web Dynpro
- SAP ABAP - Business Add-Ins
- SAP ABAP - User Exits
- SAP ABAP - Customer Exits
- SAP ABAP - SAPscripts
- SAP ABAP - Smart Forms
- SAP ABAP - Dialog Programming
- SAP ABAP - Report Programming
- SAP ABAP - Object Events
- SAP ABAP - Interfaces
- SAP ABAP - Encapsulation
- SAP ABAP - Polymorphism
- SAP ABAP - Inheritance
- SAP ABAP - Classes
- SAP ABAP - Objects
- SAP ABAP - Object Orientation
- SAP ABAP - Deleting Internal Tables
- SAP ABAP - Reading Internal Tables
- SAP ABAP - Copying Internal Tables
- ABAP - Populating Internal Tables
- SAP ABAP - Creating Internal Tables
- SAP ABAP - Internal Tables
- SAP ABAP - Native SQL Overview
- SAP ABAP - Open SQL Overview
- SAP ABAP - Include Programs
- SAP ABAP - Function Modules
- SAP ABAP - Macros
- SAP ABAP - Subroutines
- SAP ABAP - Modularization
- SAP ABAP - Lock Objects
- SAP ABAP - Search Help
- SAP ABAP - Views
- SAP ABAP - Structures
- SAP ABAP - Tables
- SAP ABAP - Data Elements
- SAP ABAP - Domains
- SAP ABAP - Dictionary
- SAP ABAP - Exception Handling
- SAP ABAP - Formatting Data
- SAP ABAP - Date & Time
- SAP ABAP - Strings
- SAP ABAP - Decisions
- SAP ABAP - Loop Control
- SAP ABAP - Operators
- SAP ABAP - Constants & Literals
- SAP ABAP - Variables
- SAP ABAP - Data Types
- SAP ABAP - Basic Syntax
- SAP ABAP - Screen Navigation
- SAP ABAP - Environment
- SAP ABAP - Overview
- SAP ABAP - Home
SAP ABAP Useful Resources
- SAP ABAP - Discussion
- SAP ABAP - Useful Resources
- SAP ABAP - Quick Guide
- SAP ABAP - Questions Answers
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
SAP ABAP - Strings
Strings, which are widely used in ABAP programming, are a sequence of characters.
We use data type C variables for holding alphanumeric characters, with a minimum of 1 character and a maximum of 65,535 characters. By default, these are apgned to the left.
Creating Strings
The following declaration and initiapzation creates a string consisting of the word Hello . The size of the string is exactly the number of characters in the word Hello .
Data my_Char(5) VALUE Hello .
Following program is an example of creating strings.
REPORT YT_SEP_15. DATA my_Char(5) VALUE Hello . Write my_Char.
The above code produces the following output −
Hello
String Length
In order to find the length of character strings, we can use STRLEN statement. The STRLEN () function returns the number of characters contained in the string.
Example
REPORT YT_SEP_15. DATA: title_1(10) VALUE Tutorials , length_1 TYPE I. length_1 = STRLEN( title_1 ). Write: / The Length of the Title is: , length_1.
The above code produces the following output −
The Length of the Title is: 9
ABAP supports a wide range of statements that manipulate strings.
S.No. | Statement & Purpose |
---|---|
1 | CONCATENATE Two strings are joined to form a third string. |
2 | CONDENSE This statement deletes the space characters. |
3 | STRLEN Used to find the length of a field. |
4 | REPLACE Used to make replacements in characters. |
5 | SEARCH To run searches in character strings. |
6 | SHIFT Used to move the contents of a string left or right. |
7 | SPLIT Used to sppt the contents of a field into two or more fields. |
The following example makes use of some of the above mentioned statements −
Example
REPORT YT_SEP_15. DATA: title_1(10) VALUE Tutorials , title_2(10) VALUE Point , spaced_title(30) VALUE Tutorials Point Limited , sep, dest1(30), dest2(30). CONCATENATE title_1 title_2 INTO dest1. Write: / Concatenation: , dest1. CONCATENATE title_1 title_2 INTO dest2 SEPARATED BY sep. Write: / Concatenation with Space: , dest2. CONDENSE spaced_title. Write: / Condense with Gaps: , spaced_title. CONDENSE spaced_title NO-GAPS. Write: / Condense with No Gaps: , spaced_title.
The above code produces the following output −
Concatenation: TutorialsPoint Concatenation with Space: Tutorials Point Condense with Gaps: Tutorials Point Limited Condense with No Gaps: TutorialsPointLimited
Note −
In case of Concatenation, the ‘sep’ inserts a space in between the fields.
The CONDENSE statement removes blank spaces between the fields, but leaving only 1 character’s space.
‘NO-GAPS’ is an optional addition to the CONDENSE statement that removes all spaces.