SAP ABAP - Strings | Learn and Master SAP ABAP - Software Development PDF Download

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 aligned to the left.

Creating Strings

The following declaration and initialization 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.
SAP ABAP - Strings | Learn and Master SAP ABAP - Software Development

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.
The document SAP ABAP - Strings | Learn and Master SAP ABAP - Software Development is a part of the Software Development Course Learn and Master SAP ABAP.
All you need of Software Development at this link: Software Development
Are you preparing for Software Development Exam? Then you should check out the best video lectures, notes, free mock test series, crash course and much more provided by EduRev. You also get your detailed analysis and report cards along with 24x7 doubt solving for you to excel in Software Development exam. So join EduRev now and revolutionise the way you learn!
Sign up for Free Download App for Free
73 videos|68 docs

Up next

73 videos|68 docs
Download as PDF

Up next

Explore Courses for Software Development exam
Related Searches

SAP ABAP - Strings | Learn and Master SAP ABAP - Software Development

,

study material

,

Free

,

past year papers

,

Exam

,

Summary

,

pdf

,

ppt

,

mock tests for examination

,

Objective type Questions

,

Extra Questions

,

Viva Questions

,

shortcuts and tricks

,

SAP ABAP - Strings | Learn and Master SAP ABAP - Software Development

,

practice quizzes

,

Semester Notes

,

Previous Year Questions with Solutions

,

Sample Paper

,

MCQs

,

SAP ABAP - Strings | Learn and Master SAP ABAP - Software Development

,

Important questions

,

video lectures

;