2013 May 27 8:55 AM
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
2013 May 27 9:01 AM
search more pls. this is very basic you can find it with F1 ( help )
2013 May 27 9:06 AM
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
2013 May 27 10:29 AM
2013 May 27 9:08 AM
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
2013 May 27 9:16 AM
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.
2013 May 27 10:02 AM
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.
2013 May 27 10:07 AM
did you try this?
CONCATENATE <ls_record>-string+0(36)
<ls_descr>-description
<ls_record>-string+37 INTO <ls_record>-string.
2013 May 27 10:15 AM
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