Collection and sorting of common ABAP string operations

Source: Internet
Author: User

The first character index of the string is 0; character fields: C, N, D, T, string (cndt => CN data time)

1. String connection
Concatenate dobj1 dobj2... into result
[In {byte | character} mode]
[Separated by SEP].

2. String separation. Split the part of a string to an inner table or a series of variables.
Split dobj at Sep
{Result1 result2...} | {table result_tab }}
[In {byte | character} mode].

3. string SEARCH: Find or search)
Find sub_string
In section [offset off] [length Len] of dobj --> the gray part is used to narrow the search range of the target string.
[In {byte | character} mode]
[{Respecting | ignoring} case]
[Match offset Moff] [Match length mlen].

Find 'dones'
In section offset 5 of 'Everybody knows this is nowhere'
Match offset Moff "=> Moff = 10
Match length mlen. "=> mlen = 5

Search for pattern in the string dobj
Search dobj for pattern [in {byte | character} mode]
[Starting at P1] [ending at P2]
[Abbreviated]
[And Mark].
If sy-subrc = 0. Then SY-FDPOS = returns the position of pattern in dobj
About pattern:
'Pat '-ignore trailing Spaces
'. Pat.'-do not ignore trailing Spaces
'* Pat'-end with Pat
'Pat * '-start with Pat
A word refers to a space ,;:? ! ()/+ = Separator string

4. String replacement
Replace section [offset off] [length Len]
Of dobj with new
[In {byte | character} mode].

Replace [{First Occurrence} | {all occurrences} of]
[Substring] sub_string
In [Section [offset off] [length Len] of] dobj with new
[In {byte | character} mode]
[{Respecting | ignoring} case]
[Replacement count rcnt]
[Replacement offset roff]
[Replacement length rlen].
Eg:
Data: text1 type string value 'xababx '.
Replace 'AB' in text1 with 'xx'. --> xxxabx

5. Remove leading zero)
Shift dobj Left deleting leading '0 '.
FM: conversion_exit_alpha_output

Add leading zero)
Data v_s (5 ).
Unpack '000000' to v_s. ==> v_s = '000000'
FM: conversion_exit_alpha_input

Shift dobj
[{By num places} | {up to sub_string}]
[Left | right] [Circular]
Shift dobj
{Left deleting leading} | {right deleting trailing} pattern.
[In {byte | character} mode].

6. String Length, number of rows in the table
Strlen (dobj) String Length
Number of rows in the Table in lines (itab)

7. Delete spaces in the string: condense text [no-gaps].

8. Case and character conversion
Translate text {to {upper | Lower} case} | {Using Pattern }.
Eg: text = 'barbcbdbarb '.
Translate text using 'abababba'. => 'abracadaba'

9. Convert
Convert date dat [Time Tim [Daylight Saving Time DST]
Into time stamp time_stamp Time Zone tz.

Convert time stamp time_stamp Time Zone TZ
Into [date dat] [Time Tim]
[Daylight Saving Time DST].

Convert text into sortable code hex.

10. Overlay text1 with text2 [only pattern].
If only pattern is not specified, spaces in text1 will be replaced by corresponding characters in text2.
If only matching characters are specified, they will be replaced. Note that the case sensitivity is true.

11. Pattern Matching
CO/CN contains only or not
Ca/Na contains any or not any
CS/ns contain string or not
CP/NP contains pattern or not

Note:
A). CO, NO, Ca, and Na are case sensitive and the trailing space is within the range of comparison.
Data: S1 (10) value 'aab '.
If S1 Co 'AB' => false
If S1 Co 'AB' => true
CS, NS, CP, and NP are case insensitive and trailing Spaces

B). For CP, NP
* =/S?
+ =/S
# Code-changing characters used to match characters such as * and +
##
#*
# +
# ___ Comparison end space
# [A-Z] It must be case sensitive in CP and NP

C) after the comparison, if the result is true, Sy-fdpos returns the offset of S2 in S1.

12. special characters
Add a newline or Tab character to the string, and use the ASCII code $13 $10 in other languages for insertion. however, the SAP class cl_abap_char_utilities should be used in the ABAP. there are character constants: cr_lf, horizontal_tab, newline, and so on.

13. String bit operation
Data: v_s (10) value 'abc '.
V_s + 0 (1) = 'B '.
V_s + 2 (*) = '12 '.
=> V_s = 'bb12 '.

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.