ABAP String Manipulation : String manipulation is the process of manipulating the values to the required format, using various manipulating commands like:
* Concatenate : Combines two or more separate strings into one.
Ex: DATA: file_path(5) VALUE '/tmp/',
name(8) VALUE 'MATERIAL',
ext(4) VALUE '.txt',
file_name(50).
CONCATENATE file_path name '_' sy-datum '_' sy-uzeit ext INTO file_name.
Write : 'File Name is :', File_name.
Concatenate
|
Split
|
Shift
|
Condense
|
Translate
|
Convert Text
|
Overlay
|
Replace
|
Search
|
* Concatenate : Combines two or more separate strings into one.
syntax : CONCATENATE <c1> ... <cn> INTO <c> [SEPARATED BY <s>].
name(8) VALUE 'MATERIAL',
ext(4) VALUE '.txt',
file_name(50).
CONCATENATE file_path name '_' sy-datum '_' sy-uzeit ext INTO file_name.
Write : 'File Name is :', File_name.
Out Put: file_name has value “/tmp/MATERIAL_20060222_064430.txt”.
* Split : Split a character string into two or more smaller strings.
syntax : SPLIT <c> AT <del> INTO <c1> ... <cn>.
name(12) TYPE C,
delimiter(1) VALUE '/'.
SPLIT file_name AT delimiter INTO directory name.
Write : 'directory : ' , directory .
* Split : Split a character string into two or more smaller strings.
syntax : SPLIT <c> AT <del> INTO <c1> ... <cn>.
Ex: DATA: file_name(30) TYPE C VALUE 'tmp/MATERIAL.txt',
directory(10) TYPE C,name(12) TYPE C,
delimiter(1) VALUE '/'.
SPLIT file_name AT delimiter INTO directory name.
Write : 'directory : ' , directory .
Out Put: Now directory contains “tmp” and name contains “MATERIAL.txt”.
* Shift : Shift the contents of a field, character by character.
syntax : SHIFT <c> [BY <n> PLACES] [<LEFT/RIGHT/CIRCULAR>].
Ex: DATA v_cost(10) TYPE c VALUE ‘345.98-’.
SHIFT v_cost BY 1 PLACES RIGHT CIRCULAR.
CONVERT TEXT var INTO SORTABLE CODE Con_txt.
WRITE : Con_text.
* Shift : Shift the contents of a field, character by character.
syntax : SHIFT <c> [BY <n> PLACES] [<LEFT/RIGHT/CIRCULAR>].
Out Put: Now v_cost = “- 345.98”.
* Condense : Deletes redundant spaces from a string.
syntax : CONDENSE <c> [NO-GAPS].
Ex: DATA var(10) TYPE c VALUE ' HELLO '.
CONDENSE var.
WRITE : var.
CONDENSE var.
WRITE : var.
Out Put: Now Var will holds the value "HELLO" by deleting initial and ending Blank Spaces.
* Translate : Converts characters into upper or lower case, or uses substitution rules to convert all occurrences of one character to another character.
syntax : TRANSLATE <c> TO UPPER CASE/LOWER CASE.
TRANSLATE <c> USING <r>.
Ex: DATA: letters(20) TYPE C VALUE 'abcabcabcXabc',
change(15) TYPE C VALUE 'aXbaYBabZacZB'.
TRANSLATE letters USING change.
WRITE : letters.
change(15) TYPE C VALUE 'aXbaYBabZacZB'.
TRANSLATE letters USING change.
WRITE : letters.
Out Put: letters now contains 'XaZXaZXaZXXaZ'.
* Convert Text : Converts strings into a format that can be sorted alphabetically.
syntax : CONVERT TEXT <c> INTO SORTABLE CODE <sc>.
field <c> must be of type C and the field <sc> must be of type X with a minimum size of 16 times the size of <c>.
Ex: DATA: Var(5) TYPE C VALUE 'Hello',
Con_text TYPE xstring.CONVERT TEXT var INTO SORTABLE CODE Con_txt.
WRITE : Con_text.
Out Put: Now Con_text will holds the value "342E3C3C420109018F08".
* Overlay : Overlays one string with another.
Ex: DATA: c1(4) VALUE 'ABC',
c2(4) VALUE 'XVYZ'.
OVERLAY c1 WITH c2 ONLY 'B'.
WRITE c1.
Out Put: Now C1 holds the value "AVC".
syntax : OVERLAY <c1> WITH <c2>.
Ex: DATA: c1(4) VALUE 'ABC',
c2(4) VALUE 'XVYZ'.
OVERLAY c1 WITH c2 ONLY 'B'.
WRITE c1.
Out Put: Now C1 holds the value "AVC".
No comments:
Post a Comment