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

case sensitive

Former Member
0 Likes
3,178

Hi,

TABLES : ADRC.

DATA : BEGIN OF IT_ADRC OCCURS 0,

ADDRNUMBER LIKE ADRC-ADDRNUMBER,

DATE_FROM LIKE ADRC-DATE_FROM,

NATION LIKE ADRC-NATION,

DATE_TO LIKE ADRC-DATE_TO,

TITLE LIKE ADRC-TITLE,

END OF IT_ADRC.

SELECT-OPTIONS : S_NAME FOR ADRC-NAME1.

SELECT ADDRNUMBER DATE_FROM NATION DATE_TO TITLE FROM ADRC INTO TABLE

IT_ADRC WHERE NAME1 IN S_NAME.

LOOP AT IT_ADRC.

WRITE : / IT_ADRC-ADDRNUMBER.

ENDLOOP.

In the above program S_NAME is char field so while fetching the data from the database table it will consider lower case and upper case i.e. case sensitive.

My requirement is that it should not be case sensitive it should be case insensitive.

Thank you,

Ramu N.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
2,228

I think you have to use native SQL for this if you want to capture it in the select statement.

Rob

12 REPLIES 12
Read only

Former Member
0 Likes
2,228

use TRANSLATE

ex : TRANSLATE S_NAME-LOW UPPER CASE

OR

TRANSLATE S_NAME-LOW LOWER CASE

Use either of the above,as per your requirement.

use the above statement, in the LOOP of S_NAME select-option, to make sure all the input values should be in UPPER/LOWER Case.

LOOP AT S_NAME.

TRANSLATE S_NAME-LOW UPPER CASE.

MODIFY S_NAME.

ENDLOOP.

regards

srikanth

Message was edited by: Srikanth Kidambi

Read only

0 Likes
2,228

hi Ramu,

Use <b>Translate</b> Statement for the smae

<b>Converting to Upper or Lower Case or Replacing Characters</b>

The TRANSLATE statement converts characters into upper or lower case, or uses substitution rules to convert all occurrences of one character to another character.

<b>Converting to Upper or Lower Case</b>

TRANSLATE <c> TO UPPER CASE.

TRANSLATE <c> TO LOWER CASE.

These statements convert all lower case letters in the field <c> to upper case or vice versa.

Substituting Characters

TRANSLATE <c> USING <r>.

This statement replaces all characters in field <c> according to the substitution rule stored in field <r> . <r> contains pairs of letters, where the first letter of each pair is replaced by the second letter. <r> can be a variable.

For more variants of the TRANSLATE statement with more complex substitution rules, see the keyword documentation in the ABAP Editor.

DATA: T(10) VALUE 'AbCdEfGhIj',

STRING LIKE T,

RULE(20) VALUE 'AxbXCydYEzfZ'.

STRING = T.

WRITE STRING.

TRANSLATE STRING TO UPPER CASE.

WRITE / STRING.

STRING = T.

TRANSLATE STRING TO LOWER CASE.

WRITE / STRING.

STRING = T.

TRANSLATE STRING USING RULE.

WRITE / STRING.

Output:

AbCdEfGhIj

ABCDEFGHIJ

abcdefghij

xXyYzZGhIj

Check this Link

http://help.sap.com/saphelp_erp2005/helpdata/en/fc/eb33a5358411d1829f0000e829fbfe/frameset.htm

Regards,

Santosh

Read only

former_member181966
Active Contributor
0 Likes
2,228

Syntax Diagram

TRANSLATE

Variants:

1. TRANSLATE c TO UPPER CASE.

2. TRANSLATE c TO LOWER CASE.

3. TRANSLATE c USING r.

4. TRANSLATE c ...FROM CODE PAGE g1... TO CODE PAGE g2.

5. TRANSLATE f ...FROM NUMBER FORMAT n1... TO NUMBER FORMAT n2.

Depending on whether byte or character string processing is carried out, the operands can only be byte-type or character-type (see Overview).

The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Only character-type fields allowed in string processing.

In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs.

See String processing

Variant 1

TRANSLATE c TO UPPER CASE.

Variant 2

TRANSLATE c TO LOWER CASE.

Effect

The first variant converts all lowercase letters in c to uppercase. The second variant converts all uppercase letters to lowercase.

Example

DATA letters(3) TYPE C.

MOVE 'abc' TO letters.

TRANSLATE letters TO UPPER CASE.

letters now has the contents 'ABC'.

Note

The classification of upper- and lowercase, and the actual characters used are determined by the current text environment (see SET LOCALE LANGUAGE). Problems may occur when the system converts the characters, if the wrong language has been specified in SET LOCALE LANGUAGE, or if data has been processed that does

Variant 3

TRANSLATE c USING r.

Effect

Replaces all the characters in the field c according to the rule in field r. c1 containscharacter pairs. The second character in each pair replaces the first. If r does not contain a character in c, this character remains unchanged. r can also be a variable.

Example

DATA: letters(20) TYPE C VALUE 'abcabcabcXab',

change(15) TYPE C VALUE 'aXbaYBabZacZ'.

TRANSLATE letters USING change.

letters now contains 'XaZXaZXaZXXaZ'.

Variant 4

TRANSLATE c ...FROM CODE PAGE g1 ...TO CODE PAGE g2.

Parts marked with " ..." are interchangeable

TRANSLATE c TO CODE PAGE g2.

TRANSLATE c FROM CODE PAGE g1.

Instead you can use conversion classes.

Effect

Converts the contents of the field c from character set g1 to character set g2. This variant uses the conversion table g1 to determine the SAP character, which is then used to determine the new character from g2.

Transaction SPAD allows you to display and maintain character sets. If one of the conversion tables does not exist, the runtime error CONVERSION_CODEPAGE_UNKNOWN occurs. Conversion combinations that are maintained as part of the runtime system for performance reasons do not trigger runtime errors, and you cannot change them using Transaction SPAD.

Example

DATA c(72) TYPE C.

TRANSLATE c FROM CODE PAGE '1110' TO CODE PAGE '0100'.

This statement converts the contents of field c from the HP-UX character set to IBM EBCDIC.

Note

Fields with types I, P, F, and X remain unchanged by the conversion. The syntax check only allows character fields for specifying the codepage. However, since the codepage is maintained in table TCP00 as a type N field with length 4, you should use this type.

Variant 5

TRANSLATE f ...FROM NUMBER FORMAT n1 ...TO NUMBER FORMAT n2.

Parts marked with " ..." are interchangeable

TRANSLATE f TO NUMBER FORMAT n1.

TRANSLATE f FROM NUMBER FORMAT n1.

Instead you can use conversion classes.

Effect

Converts the number formats in f. Currently, the number formats '0000' (HP, SINIX, IBM) and '0101' (DEC-alpha OSF) are supported. Other formats trigger the runtime error TRANSLATE_WRONG_NUM_FORMAT . If you omit FROM NUMBER FORMAT or TO NUMBER FORMAT, the system uses the system number format.

Example

DATA: f TYPE F,

hex(2) TYPE X,

nform LIKE tcp00-cpcodepage.

...

  • The contents of fields hex and f are stored in /ARCHIV

  • from another platform. hex is stored in a valid number

  • form when it is saved, and can therefore be read on

  • all platforms.

READ DATASET '/ARCHIV' INTO hex.

READ DATASET '/ARCHIV' INTO f.

nform = hex. "Conversion from non-host-specific. HEX into N(4)

TRANSLATE f FROM NUMBER FORMAT nform.

Effect

Converts the contents of f from the nform format of a given platform into the system representation.

Note

This converts fields with types I and F. As in variant 4, you should define the number formats with type N and length 4.

You can display system codepage and number formats using the function module SYSTEM_FORMAT. This allows you to store additional information for archiving purposes.

Note

Performance:

Converting lowercase letters to uppercase (or the other way round) in a 10 byte character field requires around 7 msn (standardized microseconds).

If you use ... c USING c1... to replace two characters of a 10 byte character field,the runtime is around 9 msn.

Exceptions

Non-Catchable Exceptions

Cause: Invalid number format.

TRANSLATE_WRONG_NUM_FORMAT

Related

REPLACE, OVERLAY, Conversion Classes

Additional help

Converting to Upper or Lower Case or Converting Characters

Hope this’ll give you idea!!

<b>P.S award the points.</b>

Good luck

Thanks

Saquib Khan

"Some are wise and some are otherwise"

Read only

Former Member
0 Likes
2,228

Hi,

In may database table i have data for adrc-name1 = 'Super Gas'. If i give <b>'super gas'</b> or <b>'SUPER GAS'</b> in the selection screen i.e S_NAME it is not fetching data it is fetching when i give <b>'Super Gas'</b> only. Is there any way such that if i give 'super gas' or 'SUPER GAS' it should fetch data.

Thank you,

Ramu N.

Read only

0 Likes
2,228

hi,

first get all the entries from ADRC then check those records with your S_NAME.

select * from adrc into table it_adrc.

loop at it_adrc.

translate it_adrc-name1 to upper case.

modify it_adrc.

endloop.

loop at s_name1.

v_tabix = sy-tabix.

translate s_name1-low upper case.

read table it_adrc with key name1 = s_name1-low.

if sy-subrc <> 0.

delete s_name1 index v_tabix.

endif.

endloop.

*--now S_NAME1 will have all valid records.

*--SO Delete unwanted records from IT_ADRC.

delete IT_ADRC where name1 not in S_NAME1.

*--now IT_ADRC will have all name1 matches with S_NAME1.

may be this is big tedious & time consuming process,but check this once, till you get another good logic.

regards

srikanth

Read only

suresh_datti
Active Contributor
0 Likes
2,228

Hi Ramu,

The field adrc-name1 can have both upper & lower case characters. So I don't think you can restrict by case in your where clause. You will have to select it & then translate to upper /lower case & compare with the input string.

Regards,

Suresh Datti

Read only

nablan_umar
Product and Topic Expert
Product and Topic Expert
0 Likes
2,228

Try this one.

loop at s_name.

translate s_name-low to upper case.

translate s_name-high to upper case.

modify s_name.

endloop.

SELECT ADDRNUMBER DATE_FROM NATION DATE_TO TITLE FROM ADRC INTO IT_ADRC.

translate it_adrc-NAME1 to upper case.

check it_adrc-name1 in s_name.

append it_adrc.

endselect.

Read only

Former Member
0 Likes
2,229

I think you have to use native SQL for this if you want to capture it in the select statement.

Rob

Read only

0 Likes
2,228

Something like:

REPORT ztest.

TABLES adrc.

DATA:
wa_src LIKE adrc,
i_src LIKE TABLE OF adrc,
l_str1(20) TYPE c.


PARAMETERS: l_string(20) TYPE c.

START-OF-SELECTION.
  CONCATENATE '%' l_string '%' INTO l_str1.

  EXEC SQL.
    OPEN C FOR
    SELECT *
    FROM  adrc
    WHERE UPPER(NAME1)  LIKE  :L_STR1
  ENDEXEC.

  DO.
    EXEC SQL.
      FETCH NEXT C INTO :wa_SRC
    ENDEXEC.
    IF sy-subrc <> 0.
      EXIT.
    ENDIF.
    APPEND wa_src TO i_src.
  ENDDO.

  EXEC SQL.
    CLOSE C
  ENDEXEC.

This works in DB2 and probably Oracle as well. You'll have to add logic to handle more complex select-options.

Rob

Read only

0 Likes
2,228

Sorry - a <b>much</b> easier example:


REPORT ztest.

TABLES: adrc.

DATA: BEGIN OF it_adrc OCCURS 0,
        addrnumber LIKE adrc-addrnumber,
        date_from  LIKE adrc-date_from,
        nation     LIKE adrc-nation,
        date_to    LIKE adrc-date_to,
        title      LIKE adrc-title,
      END OF it_adrc.

SELECT-OPTIONS: s_name FOR adrc-name1.

LOOP AT s_name.
  TRANSLATE s_name-low  TO UPPER CASE.
  TRANSLATE s_name-high TO UPPER CASE.
  MODIFY s_name.
ENDLOOP.

SELECT  addrnumber date_from nation date_to title
  FROM  adrc
  INTO  TABLE it_adrc
  WHERE <b>mc_name1</b> IN s_name.

LOOP AT it_adrc.
  WRITE: / it_adrc-addrnumber.
ENDLOOP.

MC_NAME1 is an upper case truncated version of NAME1 that is created for use by search helps. But it should be OK here. Users don't often enter more than 25 characters in a select option.

Rob

Message was edited by: Rob Burbank

Read only

Former Member
0 Likes
2,228

Hi,

The best, and SAP recommended, way of doing these kind of searchs is to use the field MC_NAME1 instead of NAME1.

MC_NAME1 will always have upper case format of the field content NAME1. The only except is the lenth of the fields (25 chars to 40 chars).

Regards,

Sumant.

Read only

Former Member
0 Likes
2,228

change ur select statement ...this should work....

SELECT ADDRNUMBER DATE_FROM NATION DATE_TO TITLE FROM ADRC INTO TABLE

IT_ADRC WHERE MC_NAME1 IN S_NAME.