SAP ABAP Operations on strings

Source: Internet
Author: User
Tags first string lowercase
Replace field contents
REPLACE [First/all occurrences Of]<str1>into <STR> with <STR2>
DATA STR TYPE C LENGTH VALUE ' how ARE '.
DATA STR1 TYPE C LENGTH 3 VALUE ' how '.
DATA STR2 TYPE C LENGTH 4 VALUE ' sdfh '.
REPLACE occurrence of STR1 in STR with ' sdfh '.
REPLACE occurrence of STR1 in STR with STR2.
REPLACE occurrence of ' how ' in STR with STR2.
Replace string The first occurrence of STR1 in Str.
followed by the replaced content, which can be variables and constants,
With the following to be replaced, can be variables and constants.
DATA STR TYPE C LENGTH VALUE ' how ARE '.
REPLACE all occurrences of STR1 in STR with STR2.
Replaces all occurrences of STR1 in the string str.
REPLACE STR1 in STR with STR2.
The default is only to replace the first occurrence of the place.
REPLACE <STR1> with <STR2> into <STR> [LENGTH <1>]
You can only replace string str where the first occurrence of STR1 occurs.
DATA STR TYPE C LENGTH VALUE ' how ARE '.
DATA STR1 TYPE C LENGTH 3 VALUE ' how '.
DATA STR2 TYPE C LENGTH 4 VALUE ' sdfh '.
REPLACE STR1 with STR2 into STR LENGTH ' 2 '.
Length ' 2 ' indicates the character lengths to be replaced.
REPLACE STR1 with STR2 into STR.
No length default all replace
Attention
First/all occurrences of the difference between two grammars, which cannot be used at the same time as LENGTH.
Convert Large/lowercase
Converts a string to uppercase
DATA STR3 TYPE C LENGTH VALUE ' QAEWRWETW '.
TRANSLATE STR3 to UPPER case.
Converting a string to lowercase
DATA STR TYPE C LENGTH VALUE ' how ARE '.
TRANSLATE STR to LOWER case.
Find string
To see the results, place the results in the Lookup results table.
The ABAP has a special table type Match_result_tab that holds the lookup results.
DATA STR TYPE C LENGTH VALUE ' how ARE '.
DATA STR1 TYPE C LENGTH 3 VALUE ' how '.
DATA reslt TYPE Match_result_tab.
Find the occurrence of STR1 in STR RESULTS reslt.
Finds the first occurrence of a string STR1 in string str.
The lookup result is the number of rows (line No. 0), the starting digits (4th digits), Length (3-bit)
Starting digits 19, length 3
Starting digits 4, length 3
Finds all occurrences of string STR1 in string str.
DATA STR TYPE C LENGTH VALUE ' how ARE '.
DATA STR1 TYPE C LENGTH 3 VALUE ' how '.
Find all occurrences of the STR1 in STR RESULTS reslt.
Gets the length of the string.
STRLEN (<c>):<c> data type can only be c,n,d,t
DATA STR TYPE C LENGTH VALUE ' how ARE '.
DATA INT1 TYPE I.
INT1 = STRLEN (STR).
Gets the length of the string str, and the result is placed in the variable INT1.
INT1 = STRLEN (' STR ').
Note: There should be spaces on either side of the brackets, constants in parentheses, or variables.
The length of the d,t data type is fixed, 8-bit and 6-bit, whereas the C,n type is based on the actual situation.
Compress field Contents
One word at a time
DATA STR4 TYPE C LENGTH ' how '.
Condense STR4.
Remove the blanks on both sides of the word.
When there are more than one word, the words are separated by spaces and the remaining spaces are removed.
DATA STR TYPE C LENGTH VALUE ' how ARE '.
Condense STR.
DATA STR TYPE C LENGTH VALUE ' how ARE '.
Condense STR no-gaps.
No-gaps function, remove all the blanks.
When defined, if the string length is specified, the output length equals the definition length when the write output
DATA STR TYPE C LENGTH VALUE ' how ARE '.
Condense STR.
WRITE:STR, '! '.
50-bit
DATA STR TYPE STRING VALUE ' how ARE '.
Condense STR.
WRITE:STR, '! '.
Note: The variables behind the condense can only be c,n,d,t types.
DATA INT1 TYPE N VALUE ' 21 02 3 '.
Condense INT1
For n-type data, condense removes the space and adds a leading 0 to the front.
DATA INT1 TYPE D VALUE ' 21 2 3 '.
Condense INT1.
DATA INT1 TYPE T VALUE ' 22 3 '.
Condense INT1.
Connection string
Concatenate <c1> ... <cn> into<c> [separated by <s>].
DATA STR1 TYPE STRING VALUE ' AB01 '.
DATA STR2 TYPE STRING VALUE ' CD02 '.
DATA STR TYPE STRING.
Concatenate STR1 STR2 into STR.
It's been removed.
DATA STR1 TYPE STRING VALUE ' AB01 '.
DATA STR2 TYPE STRING VALUE ' CD02 '.
5-bit space
DATA STR1 TYPE STRING VALUE ' AB01 '.
DATA STR2 TYPE STRING VALUE ' CD02 '.
By contrast, stitching will automatically remove the space behind the stitching object, while the preceding space is retained.
Separated by stitching what separates.
Concatenate STR1 STR2 into STR separated by ', '.
TAB key to separate.
Concatenate STR1 STR2 into STR
separated by Cl_abap_char_utilities=>horizontal_tab.
The TAB key cannot be displayed here and the # key indicates
Date stitching
DATA INT1 TYPE D VALUE ' 20110218 '.
DATA INT2 TYPE D VALUE ' 20110219 '.
DATA STR TYPE STRING.
Concatenate INT1 INT2 into STR.
Time Stitching
DATA INT1 TYPE T VALUE ' 123226 '.
DATA INT2 TYPE T VALUE ' 112336 '.
DATA STR TYPE STRING.
Concatenate INT1 INT2 into STR.
Digital text Stitching
DATA INT1 (6) TYPE N VALUE ' 123226 '.
DATA INT2 (6) TYPE N VALUE ' 112336 '.
DATA STR (a) TYPE N.
Concatenate INT1 INT2 into STR.
Note: c,n,d,t types of data can be spliced, i,f,p,x type of data can not be spliced.
D,t type splicing, because all is fixed length, if with the DT type receive, can only take the first data, lose the meaning of stitching, so receive type is set to String or N type.
4-bit space
When stitching, to preserve the space following the string, use the offset method.
1-bit space
5-bit space
DATA STR1 TYPE STRING VALUE ' AB01 '.
DATA STR2 TYPE STRING VALUE ' CD02 '.
DATA STR3 TYPE STRING VALUE ' EF03 '.
DATA STR TYPE C LENGTH 16.
Str+0 (9) = STR1.
Str+9 (5) = STR2.
Note When using offsets: (1) The digit bit at the beginning of the bracket, and the number in the bracket is the length.
(2) The received variable requires a specified length and cannot be of type string.
Split string
SPLIT <c> at <del> into <c1> ... <cn>
DATA STR1 TYPE STRING.
DATA STR2 TYPE STRING.
DATA STR3 TYPE STRING.
DATA STR TYPE STRING VALUE ' Ok,good,nice '.
SPLIT STR at ', ' into STR1 STR2 STR3.
DATA STR4 TYPE C VALUE ', '.
SPLIT STR at STR4 into STR1 STR2 STR3.
Split the string str by ', ' and put it in the variable STR1 STR2 STR3.
Split by letter, need to identify case
Note that the above parts of the changes, the first string to do the tab splicing, because the TAB key can not be shown here, to ' # ', but here the ' # ' number does not represent the # key, so in the use of the ' # ' number of Split can not be successful. The ' # ' here represents the TAB key and can only be split with tab.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.