cancel
Showing results for 
Search instead for 
Did you mean: 

Substring in ABAP?

Former Member
0 Kudos
5,682

I have earlier worked with Java and wonder now if there is any function in ABAP like "substring"?

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

hi, if you need the similiar functionality like 'substring' in ABAP, you can do like following:

DATA: strsrc type string.

strsrc = 'hello world.'.

DATA: substr type string.

substr = strsrc+0(5).

hope it will be helpful

thanks

Former Member
0 Kudos

may be CA or CP keyword will be useful to you

regards

Former Member
0 Kudos

Sounds interesting. I am quite new in ABAP, what is CA and CP?

Former Member
0 Kudos

hi,

CA (Contains Any):

c1 contains at least one character from the string c2.

CP (Contains Pattern):

The complete string c1 matches the pattern c2 (c1 "matches" c2).

cheers,

sasi

Former Member
0 Kudos

<b>C</b>ontains <b>A</b>ny

<b>C</b>ontains <b>P</b>attern

If you have Netweaver 2004s you can use regular expression, wich is a very mighty tool for handling strings. (in other languages available since 20 years)

Kind regards

Matthias Kabel

Former Member
0 Kudos

Hi Linn,

What do you want to achieve using substring? Then we can help you better and give the appropriate example.

-


Oops... should have read better. You want to take out month of a date. sasikumar palanichamy has provided a correct answer.

Message was edited by: Bas Jansen

Message was edited by: Bas Jansen

Former Member
0 Kudos

hi,

you can use find option

SEARCH f FOR g

DATA F(50).

MOVE 'Alaska Texas California' TO F.

SEARCH F FOR 'Clfrn' ABBREVIATED.

is it helpful?

sasi

Former Member
0 Kudos

I want to take out month (MM) in YYYYMMDD (sy-datum)...

Former Member
0 Kudos

Hi Linn,

Try this:

data: w_date type sy-datum,
      w_year(2) type c.

w_date = sy-datum.
w_year = w_date+4(2).
write: w_year.

Regards,

Ville

Former Member
0 Kudos

hi

->I want to take out month (MM) in YYYYMMDD (sy-datum)...

data l_month(2) type c

l_month = date+4(2)

cheers,

sasi

Former Member
0 Kudos

output = month+4(2).

Hope this helps. Many answered.

In addition to that read this

<u><b>Substring in SAP's ABAP programming</b></u>

Unlike many of the higher level languages there is no stand-alone substring call. We have split, shift, replace, translate and condense but no substring. So if we want to know the first four characters from the start of a field how do we do it?

The WRITE statement is what we use to substring a field. The syntax is as follows:

WRITE fieldname+starting_position(field_length) to variable

The fieldname is the source (or input). The plus sign precedes the starting position of the substring. IMPORTANT The traditional method of counting on computers is followed. The first position in the string is 0. Immediately after (no space) comes the length of the substring you are going to use. You can also substring the variable that you are writing the string to (the target). I have included an example that illustrates substringing on the source and target fields.

A real-life use of the substring functions

I needed to build a character date field for a cross-platform integration project I was working on. First, I defined the date field:

data: datechar(10).

To build the date lets use sy-datum, which has the current system date. 

  write SY-DATUM+4(2) to datechar+0(2).
  write '/' datechar+2(1).
  write SY-DATUM+6(2) to datechar+3(2).
  write '/' TO datechar+5(1).
  write SY-DATUM+0(4) to datechar+6(4).

Value of SY-DATUM 20010616

Here's how the field changes with the execution of each line.

06________

06/_______

06/16_____

06/16/____

06/16/2001

This is just one of the great functionalities of WRITE.

http://goldenink.com/abap/

Kindly reward points and close the thread.