WhatsApp Button




top of page

Take 10 Minutes to Get Started With STRINGS IN ABAP

Updated: May 31, 2022



Strings are set of characters arranged in sequence. Strings also called as character strings. Character or string data type is used to declare the character strings in ABAP.

Character data type holds alphanumeric characters with minimum length of 1 character and maximum of 65535 characters. Character data type is left justified and spaces padded to right.

Character data type considered as default data type when no data type specified during the declaration. If character data type used in declaration, length of the string should be specified in the declaration itself.

CREATING STRINGS

In ABAP programming, string variables defined by declaring the data type as Character. The string variables can get initialized in the same declaration or the string can get passed to the variable anywhere in the program execution.

SYNTAX——>

DATA STRING_NAME(SIZE_OF_STRING) TYPE C VALUE ‘STRING_VALUE’ .






NOTE—> In almost every ABAP program the system field SUBRC is used, because it’s meaning is connected with the successful execution of a statement. It contains return value, set by ABAP statements. It is an integer value like 0, 4, 8 or other. This value is used to determine the status of the execution of an ABAP statement. If SY-SUBRC is 0, the ABAP statement has been executed successfully. If the value is different from 0, than the statement has raised an error or warning. Usually 4 means error and 8 means warning, but this is not obligatory. It depends on the statement.




STRING OPERATIONS

  1. CONCATENATE——> Used to join two or more strings to form a third string. Separated by Clause used to separate the strings by a specified delimiter. "sy-subrc" identifies whether the concatenate was successful or not. If "sy-subrc" is zero, then concatenate successful. Otherwise, concatenate not successful.


SYNTAX—>

CONCATENATE STR1 STR2 STR3 INTO FINAL_STRING_NAME.


CODING SCREEN—>



INPUT—>


OUTPUT—>




2. SPLIT——> Used to split the string content into two or more fields.

"sy-subrc" identifies whether the split was successful or not. If "sy-subrc" is zero, then split successful. Otherwise, split not successful.


SYNTAX—>

SPLIT MAIN_STRING AT POS INTO STR1 STR2 STR3… .


CODING SCREEN—>



OUTPUT—>




3. CONDENSE——> Used to delete the space characters. Leave only one-character space in between the characters. NO-GAPS is optional and used to remove all spaces in between the characters. "sy-subrc" identifies whether the condense was successful or not. If "sy-subrc" is zero, then condense successful. Otherwise, condense not successful.


SYNTAX—->

CONDENSE STR_NAME.


CODING SCREEN—>


OUTPUT—>



If you want to delete all spaces between characters the use NO-GAPS.


SYNTAX—>

CONDENSE STR_NAME NO-GAPS.


CODING SCREEN—>



OUTPUT—>



4. REPLACE——> Used to replace the characters. REPLACE replaces the matching first instances of string. "sy-subrc" identifies whether the replace was successful or not. If "sy-subrc" is zero, then replace successful. Otherwise, replace not successful.


SYNTAX—->

REPLACE FIRST OCCURRENCE OF ‘OLD_CHAR’ IN STRING_NAME WITH ‘NEW_CHAR’ .

REPLACE ALL OCCURRENCE OF ‘OLD_CHAR’ IN STRING_NAME WITH ‘NEW_CHAR’ .


CODING SCREEN—>



OUTPUT—>



5. LENGTH——-> Holds the length of the string returned by STRLEN.


SYNTAX —>

INTEGER_VALUE = STRLEN(STR_NAME) .


6. TRANSLATE—-> Used to convert uppercase to lowercase or vice versa.


SYNTAX——>

TRANSLATE STR_NAME TO UPPER CASE.

TRANSLATE STR_NAME TO LOWER CASE.


CODING SCREEN—>



OUTPUT—>






ISHNOOR SINGH SETHI

3,659 views0 comments

Recent Posts

See All
bottom of page