Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

String Processsing

chandan_kumar02
Product and Topic Expert
Product and Topic Expert
0 Likes
1,261

What is the ABAP code to find the first n characters of a string?

Moderator Message: Very basic question. Please search before posting your question

Message was edited by: Suhas Saha

8 REPLIES 8
Read only

tolga_polat
Active Participant
0 Likes
1,233

search more pls. this is very basic you can find it with F1 ( help )

Read only

RaymondGiuseppi
Active Contributor
0 Likes
1,233

Did you try to look at F1 help index on Abap source Editor or at a site like http://help.sap.com/abapdocu_731/en/abenabap.htm ?

Regards,

Raymond

Read only

Read only

former_member217916
Participant
0 Likes
1,233

Hi Chandan,

Just an Example:

str is a string variable.

<pattern> - search pattern

Statement to search for a pattern for the first n characters:

SEARCH str FOR <patter> ENDING AT n.

Please refer to http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb33cc358411d1829f0000e829fbfe/content.htm

-

Karan

Read only

Former Member
0 Likes
1,233

DATA : lv_string TYPE STRING VALUE 'ABCDEFGH IJKL',

       lv_find   TYPE STRING VALUE 'CD'.



  FIND LV_FIND IN LV_STRING.

  IF sy-subrc IS INITIAL.

    write : 'success'.

  else.

   write : 'failure'.

  ENDIF.

Read only

chandan_kumar02
Product and Topic Expert
Product and Topic Expert
0 Likes
1,233

Let me put my question more clearly,

Scenario:

There are two field-symbols containig strings :

<ls_record>-string  type C(1000)    and  <ls_descr>-description   type C(40)

and I am doing:

CONCATENATE <ls_record>-string   <ls_descr>-description INTO <ls_record>-string.

Here, I want to add the value of  <ls_descr>-description     to   <ls_record>-string    only after first 37th position of  <ls_record>-string. 

It doesn't matter for me, whether <ls_record>-string containing values till 37th or not. Values can be less than 37th position also. but I have to concatenate second string only after 37th position of first one.

Read only

0 Likes
1,233

did you try this?

CONCATENATE <ls_record>-string+0(36) 

                            <ls_descr>-description

                            <ls_record>-string+37  INTO <ls_record>-string.

Read only

0 Likes
1,233

Hi,

Get the character length of first variable <ls_record>-string if its more than 37. Then offset and concatenate a blank character variable with just spaces say e.g.

DATA: var1(37) type c value space.

Then say strlen() gives value 20 in variable len where len is type i then

offset = 37 - len

CONCATENATE

<ls_record>-string

var1(offset)

<ls_descr>-description

INTO

<ls_record>-string RESPECTING BLANKS.

Cheers,

Arindam