cancel
Showing results for 
Search instead for 
Did you mean: 

How can I search a field character by character.

Former Member
0 Kudos

Hi people,

I have a field with this numbers: 000089562 and I need to send a e-mail of one person if the first character is equal to '8'. But, the problem is that ever the field have '0' as first character in the field and I can't erase the '0' because I need them. How can I search the character in the field to check if have an eight in the front.

Thanks for the help.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

The following code will not remove the leading zero but will check if eight is in the front

Data: lv_original type char10,

lv_without_leading_zero type char10.

lv_original = '000089562'.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_OUTPUT'

EXPORTING

input = lv_original

IMPORTING

output = lv_without_leading_zero.

if lv_without_leading_zero+0(1) eq 8

"your logic. if the orginal value is needed you can use lv_original.

endif.

Regards,

Sameena

Message was edited by: sameena attarwala

Answers (4)

Answers (4)

Former Member
0 Kudos

Hey Carlos,

To search a character field for a particular pattern, use the SEARCH statement as follows:

<b>SEARCH <c> FOR <str> <options>.</b>

The statement searches the field <c> for <str> starting at position <n1>. If successful, the return code value of SY-SUBRC is set to 0 and SY-FDPOS is set to the offset of the string in the field <c>. Otherwise, SY-SUBRC is set to 4.

The search string <str> can have one of the following forms.

1. <b><pattern></b> Searches for <pattern> (any sequence of characters). Trailing blanks are ignored.

2 <b>.<pattern>.</b> Searches for <pattern>. Trailing blanks are not ignored.

3 <b>*<pattern></b>

A word ending with <pattern> is sought.

4 <b><pattern>*</b> Searches for a word starting with <pattern>.

Words are separated by blanks, commas, periods, semicolons, colons, question marks, exclamation marks, parentheses, slashes, plus signs, and equal signs.

<b><option> in the SEARCH FOR statement can be any of the following:</b>

1) STARTING AT <n1>

Searches the field <c> for <str> starting at position <n1>. The result SY-FDPOS refers to the offset relative to <n1> and not to the start of the field.

2) ENDING AT <n2>

Searches the field <c> for <str> up to position <n2>.

Hope this helps you achieve the desired result .

for your case , you can write :

<b>SEARCH '000089562' FOR '8' .

If sy-subrc = 0.

  • then send mail.

else .

  • do not send mail .

endif. </b>

Regards,

Kunal.

Message was edited by: Kunal Kumar

Former Member
0 Kudos

Try:


REPORT ztest MESSAGE-ID 00.

DATA: field(10) VALUE '000089562',
      w_field(10).
w_field = field.
SHIFT w_field LEFT DELETING LEADING '0'.
IF w_field(1) = '8'.
  WRITE : /001 '8 found'.
ENDIF.

Rob

Former Member
0 Kudos

Try this:

Let's say the variable g_data contains the value '000089562'.

Now do the following:

L_data = (a temporary variable, type c) = g_data.

SHIFT l_data LEFT DELETING LEADING '0'.

IF l_data+0(1) = '8'.

<do whatever you want>

ENDIF.

former_member181966
Active Contributor
0 Kudos

You can read in taking offset

e,g

fild+1(8) = ' value '

OR

you can also used the Logical Expressions - Comparison Operators for Character-Type Fields

e,g

If CN,CA etc in IF condition .

P.S award the points

Thanks

Saquib