‎2006 Jul 06 3:43 PM
Hi ABAPers,
I'm trying to create something in ABAP but I'm stuck right now. I need to do the following:
I have a CHAR that has value: "MZ-OB" -> I need to check if last 2 characters are value "OB". I normally do this in formula editor in transfer rules but now I need to do the same in ABAP. LEFT(2,CHAR) does not work in ABAP and I cannot find the correct syntax for this.
Can somebody help me with this?
thanks
‎2006 Jul 06 3:52 PM
Another method:
ABAP has a host of string operators that you can use with your IF statements. There exists ca(contains any), cs(contains string), cp(contains pattern), and so on. Your requirement could be coded this way:
DATA: word(5) type c value 'MZ-OB'.
IF word cs 'OB'. ">> This would return true if the word contains string OB.
<do something>
ENDIF.
F1 on the IF statement should get you the help on all of these operators.
Hope this helps.
Sudha
‎2006 Jul 06 3:47 PM
use the code below
PARAMETER: ckb1(10).
DATA: len1 TYPE i.
len1 = STRLEN( ckb1 ).
len1 = len1 - 2.
IF ckb1+len1(2) = 'OB'.
MESSAGE i000(vz) WITH ckb1+len1(2).
ENDIF.
U need to ensure that len1 is always GE 2 else you will get a short dump.
-Kiran
*Please mark useful answers
Message was edited by: Kiran Raorane
‎2006 Jul 06 3:47 PM
Hi Joris,
Check this example :
DATA TIME TYPE T VALUE '172545'.
WRITE TIME.
WRITE / TIME+2(2).
CLEAR TIME+2(4).
WRITE / TIME.
The output appears as follows:
172545
25
170000
First, the minutes are selected by specifying an offset in the WRITE statement. Then, the minutes and seconds are set to their initial values by specifying an offset in the clear statement.
DATA: STRING(25) VALUE ' one two three four',
LEN TYPE I.
LEN = STRLEN( STRING ).
WRITE: STRING, '!'.
WRITE: / 'Length: ', LEN.
CONDENSE STRING.
LEN = STRLEN( STRING ).
WRITE: STRING, '!'.
WRITE: / 'Length: ', LEN.
CONDENSE STRING NO-GAPS.
LEN = STRLEN( STRING ).
WRITE: STRING, '!'.
WRITE: / 'Length: ', LEN.
Output:
one two three four !
Length: 25
one two three four !
Length: 18
onetwothreefour !
Length: 15
Note that the total length of the field STRING remains unchanged, but that the deleted blanks appear again on the right.
Regards,
Laxmi.
‎2006 Jul 06 3:48 PM
hi Joris,
try this
data: var(5) type c value 'MZ-OB'.
data: var1(2) type c.
data: var2(2) type c.
split var at '-' into var1 var2.
if var2 ca 'OB'.
write: 'Yes'.
else.
Write: 'No'.
endif.
‎2006 Jul 06 3:50 PM
do like this:
if v_char+3(2) = 'OB'. " If you know the length is always 5 char
endif.
otherwise
if v_char cp '*OB'.
endif.
Regards,
ravi
‎2006 Jul 06 3:50 PM
Hi Joris,
One method is that you can search for a pattern of substring...
ie SEARCH str_name for 'OB'. and getting the SY-FDPOS(which gives the location of occurence)..
Regards,
SP.
‎2006 Jul 06 3:52 PM
Another method:
ABAP has a host of string operators that you can use with your IF statements. There exists ca(contains any), cs(contains string), cp(contains pattern), and so on. Your requirement could be coded this way:
DATA: word(5) type c value 'MZ-OB'.
IF word cs 'OB'. ">> This would return true if the word contains string OB.
<do something>
ENDIF.
F1 on the IF statement should get you the help on all of these operators.
Hope this helps.
Sudha
‎2006 Jul 06 4:03 PM
ok guys, that helped me out a lot! points have been awarded! thanks