0% found this document useful (0 votes)
10 views7 pages

ABAP String Operations Overview

The document provides an overview of string operations in ABAP, including various string manipulation functions such as concatenation, validation, and replacement. It also outlines the syntax for performing these operations and includes examples for validating email input and manipulating strings based on specific patterns. Additionally, it discusses message types for user feedback in SAP programs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views7 pages

ABAP String Operations Overview

The document provides an overview of string operations in ABAP, including various string manipulation functions such as concatenation, validation, and replacement. It also outlines the syntax for performing these operations and includes examples for validating email input and manipulating strings based on specific patterns. Additionally, it discusses message types for user feedback in SAP programs.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

String Operator

---------------
String is combination of characters.

ABAP(string) ==> AB(Patter)

29.06.2025
29/06/2025
29 June 2025

ABAP IS Easy => IS or not

CO : Containes Only
CN : Not containg any
CA : Contain any
NA : Not contain any
CS : Contain String
NS : Not contain string
Cp : Contain pattern
NP : Not contain any patter

Example ::
PARAMETER : P_EMAIL TYPE STRING.

Validation for Input of Email ::: it must must contain @

IF P_EMAIL CA '@'.
IF SY-SUBRC EQ 0. => SAP provided Vailable
WRITE : 'Valid Email'.
ELSE.
WRITE : 'Not Valie Email, because not having @'.
ENDIF.

Note : Demo program for each Operator

OPeration on String
----------------------
First Name : ABAP
Last Name : Learning

CONCATENATE two string into single string

1. STRLEN : String length


IF we want to put validation on table field length
Employee type
Fname : 50 character.

PARAMETER : P_NAME TYPE STRING.

adddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd
ddddddddddddddddddddddddddddddddddddddddddddd

IF STRLEN(P_NAME) GT 50.
>
WRITE : "wrong Input'.

2. Concatenate : Adding two string into single string


3. Condense : Deleting extra space

Name : ABAP .
4. Replace : Replacing any character with other

P12345 : Iny.
X12345 : IBM
M12345 : Accenture

HR : employee id is number
replace first chanrecter before storing.

5. Search : It is used to search any value/Substring in Main String.

6. Shift : Move content left/Right.

Table : EMaployee ID
ID(8 character of integer type) : 00123456
NAme :

0012345 ===> Parameter value

Another Table : 12345

Shift

7. Split ::: for date functionality

Diving large string into small string.

20.06.2025

Split will happen dbased on some pattern

Table fiild
Month : 06
Days : 20
Year : 2025

Demo with Exmaples


------------------
DATA : GV_FNAME TYPE String VALUE 'ABAP', => any length
GV_LNAME TYPE String 'learning',

GV_FNAME(20) TYPE C. => 20 charater

WRITE : GV_Result. =====> expected Out ABAP learning

Syntax : CONCANATE GV_FNAME GV_LNAME INTO GV_RESULT.

concatenate <veriable1> <variable2>.....<variable n> INTO


<final_vailable>

WRITE : STRLEN( GV_RESULT ). => length of string.

Input Text : 29.06.2025. 11.45.23 (Today's date)


Month , year and days

SYNTAX : SPLIT <Main String> AT <Patter> INTO <VARIBALE1> <VARIABLE2>....


<Variable N>

SPLIT GV_DATE AT '.' INTO GV_DAYS GV_MONTH GV_YEAR.

SPLIT GV_DATE AT '.' INTO GV_DAYS.

WRITE : GV_DAYS, GV_MONTH, GV_YEAR.

Replace :

Input : ABAP Learning

JAVA Learning

Syntax : REPLACE <Pattern> WITH <New_patter> INTO <Soruce>.

REPLACE

REPLACE 'ABAP' WITH 'JAVA' INTO P_INPUT.

WRITE : P_INPUT. ==> JAVA

NAME NAME IS AMIT. ========> Hold

<Waseem> ========> Hold

REPLACE 'Amit' with 'Waseem' INTO 'My name is Amit'.

SEARCH : GV_TEXT = 'My Name is Amit'.

Syntax : SEARCH <Source> FOR <Pattern>


SEARCH GV_TEXT FOR 'Amit'.

GV_STEXT = 'Amit'

SEARCH FOR GV_Text for gv_stext.

if sy-SUBrc = 0.

lOGIC
ELSE
ERROR MESSAGE
endif.

gv_TEXT = 'Amit, how are you Amit, Amit is learning ABAP'.

Replace All Occurrence of


Replace FIRST Occurrence of

sHIFT :

P12345.
12345

SHIFT <SOURCE> LEFT DELETING LEADING 'P'.

Normail Shift :: Shift <Source>.


Sfift <Source> left/Right.

Shift <Source> DELETING RIGHT TRAINING '0'.

123450
12345

Assingment ::
Take Two input from user
1. validate for email : @
2. validate name not contains number

Perform String Operation.

Error Message
-------------
Output using : WRITE ====> Its text display on screen.

Message Type
------------
Display information about flow of your program.

1. Successful (S)
2. Error (E)
3. warning (W)
4. Information (I)
5. Abort.(A)

Program : INPUT FROM USER as Number

P_NUMBER TYPE STRING.

MESSAGE "Correct Value' TYPE 'S'.

MESSAGE 'Wrong Input' TYPE 'E'.

MESSAGE 'Wrong Input' TYPE 'W'.

MESSAGE 'Wrong Input' TYPE 'I'.

MESSAGE 'About' TYPE 'A' => short dump

W : Warning

I : Infomration
It display display message as POPUP

A : Abort (Giv the dump)

IN SAP how many ways we can create message


----------------------------------------------
1. Direct message : Text available in your program.(Hard coded text in program).
2. Using text element/text symbol. (Se38 ) ===>
3. Global Class : Se91 (Transaction code , resubale)

Perchance order
'Record is available in table' => Waseem
=> Sayed

MESSAGE <TEXT> TTPE 'I'

MESSAGE TEXT-002 TYPE 'I' => Text symbol (Se38, EDIT)


001 till 999

MEESAGE<Meesage_type><Message number>(<Message_class)

Class Name : Z/Y


ZAMIT_MSG : Class name Se91

NUmber Text

001 Waseem
002 Sayed
003 Amit.

MEESAGE S001(ZAMIT_MSG).

Common questions

Powered by AI

The 'SHIFT' operation modifies string content by repositioning or deleting parts. It's used in data parsing to trim unnecessary characters. For example, 'SHIFT <SOURCE> LEFT DELETING LEADING 'P'' removes leading 'P' characters in an employee ID, creating a pure numeric ID for database storage .

In ABAP, validation checks include ensuring an email contains the '@' symbol by using the 'CA' operator as in 'IF P_EMAIL CA '@'' to confirm it includes '@'. For names, validation ensures they contain no numbers by checking the absence of digits in the input string . Both verify inputs meet specific criteria for data integrity.

In ABAP, 'searching' locates a substring within a larger string using the SEARCH statement; 'replacing' substitutes parts of a string with a different substring using the REPLACE statement; 'shifting' moves the content of a string left or right, or deletes leading characters, as illustrated by SHIFT operation, e.g., 'SHIFT <SOURCE> LEFT DELETING LEADING 'P'' removes the initial 'P' from strings .

STRLEN calculates the length of a string, which is useful for validations, such as checking if an input exceeds field limits. CONCATENATE merges multiple strings into one string, useful for compiling composite values seamlessly. SPLIT divides a large string into smaller segments based on a pattern, aiding in organized data parsing .

Concatenation in ABAP combines two or more strings into a single string. The purpose is to merge multiple pieces of textual data for ease of handling and further operations. For example, the ABAP syntax 'CONCATENATE GV_FNAME GV_LNAME INTO GV_RESULT' merges the strings GV_FNAME and GV_LNAME into the string GV_RESULT .

SAP messages can be created through direct text in the program, using text elements in Se38, or using global classes in Se91. Message types include Success (S), Error (E), Warning (W), Information (I), and Abort (A). These determine the program's flow, such as terminating execution with Abort or simply displaying information with Information-type messages .

To create an email validation demo program in ABAP, first declare a parameter of STRING type for the email input. Use the CA operator to check for the '@' symbol: 'IF P_EMAIL CA '@'', followed by conditional statements to output 'Valid Email' or 'Not Valid Email' based on presence. Consider edge cases like multiple '@' symbols or missing domain parts .

Direct message creation offers quick implementation with hardcoded text, suitable for simple, immediate needs. Global class messages, facilitated through Se91, promote reusability and central management, beneficial for standardizing messages across programs. While more complex to set up, global classes support consistent, maintainable messaging systems .

The REPLACE function changes specified substrings within a larger string. Using 'REPLACE FIRST' alters only the initial instance of a pattern, whereas 'REPLACE ALL OCCURRENCES' affects every occurrence within the string. This provides flexibility in modifying content selectively or extensively depending on needs .

ABAP string operations like concatenation, length determination, and pattern matching enhance data management by facilitating easier data manipulation and validation. However, improper implementation, such as incorrect operators or syntax errors, can lead to data corruption, inaccurate processing, or program crashes, underscoring the importance of precise coding .

You might also like