Splitting Strings Directly into Internal Tables in SAP ABAP

Overview of String Manipulation in ABAP
String manipulation is a fundamental skill in SAP ABAP programming. Whether you’re parsing user inputs, formatting data for output, or breaking down complex strings into manageable pieces, being adept at string manipulation can save a lot of time and effort. One common requirement is to split a single string into multiple substrings and store them in an internal table.

SPLIT <source_string> AT <delimiter> INTO TABLE <target_internal_table>.

– <source_string>: The string you want to split.
– <delimiter>: The character or substring at which the split should occur.
– <target_internal_table>: The internal table to store the resulting substrings.

Example 1:

 

 

 

DATA:
lv_string TYPE string,
lt_parts TYPE TABLE OF string.

lv_string = ‘This is a sample string’.

SPLIT lv_string AT ‘ ‘ INTO TABLE lt_parts.

 

 

 

In this example, the string lv_string is split at each space character, and the resulting substrings are stored in the internal table lt_parts.

Example 2:

 

 

 

DATA:
lv_string TYPE string,
lt_parts TYPE TABLE OF string,
lv_part TYPE string.

lv_string = ‘apple,banana,cherry,dates’.

SPLIT lv_string AT ‘,’ INTO TABLE lt_parts.

LOOP AT lt_parts INTO lv_part.
WRITE: / lv_part.
ENDLOOP.

 

 

 

In this example:
– The string lv_string contains a list of fruits separated by commas.
– The SPLIT statement divides the string at each comma and stores the substrings in the internal table lt_parts.
– The LOOP statement iterates over the internal table and outputs each fruit name.

 

​ Overview of String Manipulation in ABAPString manipulation is a fundamental skill in SAP ABAP programming. Whether you’re parsing user inputs, formatting data for output, or breaking down complex strings into manageable pieces, being adept at string manipulation can save a lot of time and effort. One common requirement is to split a single string into multiple substrings and store them in an internal table.SPLIT <source_string> AT <delimiter> INTO TABLE <target_internal_table>.- <source_string>: The string you want to split.- <delimiter>: The character or substring at which the split should occur.- <target_internal_table>: The internal table to store the resulting substrings.Example 1:   DATA:
lv_string TYPE string,
lt_parts TYPE TABLE OF string.

lv_string = ‘This is a sample string’.

SPLIT lv_string AT ‘ ‘ INTO TABLE lt_parts.   In this example, the string lv_string is split at each space character, and the resulting substrings are stored in the internal table lt_parts.Example 2:   DATA:
lv_string TYPE string,
lt_parts TYPE TABLE OF string,
lv_part TYPE string.

lv_string = ‘apple,banana,cherry,dates’.

SPLIT lv_string AT ‘,’ INTO TABLE lt_parts.

LOOP AT lt_parts INTO lv_part.
WRITE: / lv_part.
ENDLOOP.   In this example:- The string lv_string contains a list of fruits separated by commas.- The SPLIT statement divides the string at each comma and stores the substrings in the internal table lt_parts.- The LOOP statement iterates over the internal table and outputs each fruit name.   Read More Technology Blogs by Members articles 

#SAP

#SAPTechnologyblog

You May Also Like

More From Author