‎2009 Sep 13 8:50 AM
Hi,
I need a help to write ABAP function which get a string as parameter
The fuction returns true only if the string length is 7 & the string contain only one '-'.
Thx
‎2009 Sep 14 8:26 AM
Hi ,
Chk the following code.. it works acc to the requirement..
FUNCTION ZFM.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(W_STRING) TYPE STRING
*" EXPORTING
*" REFERENCE(W_RESULT) TYPE STRING
*"----------------------------------------------------------------------
data: w_len type i.
w_len = strlen( w_string ).
if w_len eq 7.
do.
if w_string ca '-'.
w_result = 'True'.
replace '-' in w_string with space .
if sy-index ge 2.
w_result = 'False'.
exit.
endif.
endif.
check sy-index gt 2 .
exit.
enddo.
else.
w_result = 'False'.
endif.
ENDFUNCTION.
Regards,
Mdi.Deeba
‎2009 Sep 13 8:59 AM
Hello,
I dont think that there is any function available for this.
A few lines of code & thats it.
DATA:
V_TRUE TYPE FLAG,
V_LEN TYPE I,
V_LINES TYPE I.
CLEAR: V_LEN, V_LINES, V_TRUE.
V_LEN = STRLEN( V_INPUT ).
SPLIT V_INPUT AT '-' INTO TABLE ITAB.
V_LINES = LINES( ITAB ).
"If true, then V_LEN = 7 & V_LINES = 2
IF V_LEN = 7 AND V_LINES = 2.
V_TRUE = 'X'.
ENDIF.BR,
Suhas
‎2009 Sep 13 9:05 AM
‎2009 Sep 13 10:26 AM
Hi, Qwart
As i understand your requirement, you need the following, Test the code given bellow and revert me back if any else requirement.
PARAMETERS: string TYPE string.
DATA: ans(1).
PERFORM: check_string USING string ans.
WRITE: ans. " Here it will write T or F ( T for True and F for False )
*&---------------------------------------------------------------------*
*& Form check_string
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->VALUE(STR) text
* -->FLAG text
*----------------------------------------------------------------------*
FORM check_string USING value(str) flag.
DATA: sub_str1 TYPE string,
sub_str2 TYPE string,
slen TYPE i,
sub_slen1(7),
sub_slen2(7).
slen = STRLEN( str ).
IF slen = 7.
FIND FIRST OCCURRENCE OF '-' IN str.
IF sy-subrc = 0.
SPLIT: str AT '-' INTO sub_str1 sub_str2.
FIND FIRST OCCURRENCE OF '-' IN sub_str2.
IF sy-subrc = 0.
flag = 'F'.
ELSE.
flag = 'T'.
ENDIF.
ELSE.
flag = 'F'.
ENDIF.
ELSE.
flag = 'F'.
ENDIF.
ENDFORM. "check_stringRegards,
Faisal
‎2009 Sep 14 7:03 AM
Hi,
From the below program logic you can create the FM
****************************************
data: v_len type i,v_return(1) type c value 'F'.
parameters: P_string type string.
v_len = strlen( p_string ).
if len = 7.
if p_string CO '-'.
v_return = 'T'.
endif.
endif.
write : v_return,len.
********************************************
Hope this will help you.
Regards,
Smart Varghese
‎2009 Sep 14 7:21 AM
HI,
You may use this :-
data len type i.
data str type string .(String to be checked)
len = strlen( str ).
if len = 7.
FIND - IN SECTION OFFSET off OF
str
endif.
regards,
Prakash
‎2009 Sep 14 8:01 AM
data s1 type string value 'asdf-dfgd-234-asd'.
data: d1 type i,l1 type i.
d1 = strlen( s1 ).
DATA : res_tab TYPE MATCH_RESULT_TAB,
res TYPE MATCH_RESULT.
find ALL OCCURRENCES OF '-' in s1 RESULTS res_tab .
DESCRIBE TABLE res_tab LINES l1.
WRITE : 'length:', d1, ' occurance:', l1.
‎2009 Sep 14 8:10 AM
Hi,
try this:
DATA: I_STRING TYPE STRING VALUE '-------'.
DATA: L_STRING TYPE I.
*
L_STRING = STRLEN( I_STRING ).
*
IF L_STRING = 7 AND I_STRING = '-------'.
WRITE: 'OK'.
ELSE.
WRITE: / 'ERROR'.
ENDIF.
regards, Dieter
‎2009 Sep 14 8:26 AM
Hi ,
Chk the following code.. it works acc to the requirement..
FUNCTION ZFM.
*"----------------------------------------------------------------------
*"*"Local Interface:
*" IMPORTING
*" VALUE(W_STRING) TYPE STRING
*" EXPORTING
*" REFERENCE(W_RESULT) TYPE STRING
*"----------------------------------------------------------------------
data: w_len type i.
w_len = strlen( w_string ).
if w_len eq 7.
do.
if w_string ca '-'.
w_result = 'True'.
replace '-' in w_string with space .
if sy-index ge 2.
w_result = 'False'.
exit.
endif.
endif.
check sy-index gt 2 .
exit.
enddo.
else.
w_result = 'False'.
endif.
ENDFUNCTION.
Regards,
Mdi.Deeba