Application Development 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: 

Abap alpha comparison

amine_lamkaissi
Active Contributor
0 Kudos

Hi experts,

In BW i have to compare 2 fields with a statement Read Table with key.

The issue is that the 2 fields that I have to compare even if they contain the same kind of information, they have different lenghts, both of them are char, but the difference will be like this example because of lenghts:

Field1 : 0001

Field2: 00000001

As you see, both of them contain information 1 but with different lenghts, how can i bypass this in a Read table with key statment?

Thanks for your support.

Amine

1 ACCEPTED SOLUTION

custodio_deoliveira
Active Contributor
0 Kudos

Hi Amine,

Not sure this is what you need, but try using conversion exit:

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

   EXPORTING

     input         = FIELD1

  IMPORTING

    OUTPUT        = FIELD1_AUX.

Declare  FIELD1_AUX same type as FIELD2.

Then use field1_aux to read table.

Hope this helps.

Cheers,

Custodio


6 REPLIES 6

Former Member
0 Kudos



























OperatorMeaning
COContains Only: True, if operand1 only contains characters from operand2. Upper/lower case and trailing
blanks are taken into account for both operands. If operand2 is of type string and is initial, then the logical expression
is false, unless operand1 is also
of type string and is initial, in
which case the logical expression is always true. If the result of the
comparison is negative, sy-fdpos
contains the offset of the first character in operand1, that is not contained in operand2. If the result of the comparison is
positive, sy-fdpos contains the
length of operand1.
CNContains Not Only; True if a logical expression with CO is false, that is, if operand1 contains not only characters from
operand2. sy-fdpos is set in the same way as for CO. If the comparison is true, sy-fdpos contains the offset of the first
character in operand1 that is not
contained in operand2. If the
comparison is false, sy-fdpos
contains the length of operand1.
CAContains Any: True, if operand1 contains at least one character from
operand2. Upper/lower case and
trailing blanks are taken into account for both operands. If operand1 or operand2 is of type string and initial, the logical expression is
always false. If result of the comparison is positive, sy-fdpos contains the offset of the first
character in operand1 that is also
contained in operand2. If the
result of the comparison is negative, sy-fdpos contains the length of operand1.
NAContains Not Any: True if a logical expression with CA is false, that is if operand1 does not contain any characters from
operand2. If the result of the
comparison is negative, sy-fdpos
contains the offset of the first character in operand1 that is also contained in operand2. If the result of the comparison is true,
sy-fdpos contains the le of
operand1.
CSContains String: True if the content of operand2 is contained in operand1. Upper/lower case is not taken into
account, trailing blanks of the left operand are taken into account. If operand1 is of type string and initial, or of type c and contains only blank characters, the logical
expression is false, unless operand2 is also of type string and initial, or of type c and only contains blank characters. In this case
the logical expression is always true. If the result of the comparison is true,
sy-fdpos contains the offset of
operand2 in operand1. If the result of the comparison is
negative, sy-fdpos contains the
length of operand1.
NSContains No String: True, if a logical expression with CS is false, that is if operand1 does not contain the content of operand2. If the result of the comparison
is negative, sy-fdpos contains the
offset of operand2. If the
comparison is true, sy-fdpos
contains the length of operand1.
CPCovers Pattern: True, if the content of operand1 fits the pattern in operand2. Wildcard characters can be used for
forming the operand2 pattern,
where "*" represents any character string, and "+" represents any character.
Upper/lower case is not taken into account. If the comparison is true, sy-fdpos contains the offset of operand2 in operand1, whereby leading wildcard characters "*"
in operand2 are ignored if
operand2 also contains other
characters. If the comparison is false, sy-fdpos contains the length of operand1. You can select characters in operand2 for a direct comparison by adding
the escape symbol "#" before the
required characters. For these characters, upper/lower case is taken into
account, wildcard characters and the escape symbol itself do not receive special
treatment, and trailing blanks in operands of type c are not cut off.
NPNo Pattern: True, if a logical expression with CP is false, that is, if operand1 does not fit the pattern operand2. If the comparison is false, sy-fdpos contains the offset of operand2 in operand1, whereby leading wildcard characters "*"
in operand2 are ignored if
operand2 also contains other
characters. If the comparison is true, sy-fdpos contains the length of operand1.


Note


As of release 6.10, operands of byte-like data types can only be compared
with the comparison operators in this table outside of Unicode programs. To execute
the corresponding comparisons for byte-like objects in Unicode programs, you can
use the Comparison operators for byte-like
data types
.

Try with one of these operater.,
Thanks,
sam,

custodio_deoliveira
Active Contributor
0 Kudos

Hi Amine,

Not sure this is what you need, but try using conversion exit:

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

   EXPORTING

     input         = FIELD1

  IMPORTING

    OUTPUT        = FIELD1_AUX.

Declare  FIELD1_AUX same type as FIELD2.

Then use field1_aux to read table.

Hope this helps.

Cheers,

Custodio


Former Member
0 Kudos

Type conversion can be done before read table like this.

TYPES:

BEGIN OF ty,

  field TYPE n LENGTH 4,

END OF ty,

tty TYPE TABLE OF ty.

DATA wa TYPE ty.

DATA it TYPE tty.

DATA value1 TYPE n LENGTH 8 VALUE 1.

DATA key1 TYPE n LENGTH 4.

APPEND '0002' TO it.

APPEND '0001' TO it.

APPEND '0005' TO it.

key1 = value1"type conversion

WRITE:/ key1, value1.

READ TABLE it INTO wa WITH KEY field = key1.

IF sy-subrc EQ 0.

  WRITE:/ wa-field, key1, value1.

ENDIF.

amine_lamkaissi
Active Contributor
0 Kudos

Thanks a lot.

Amine

0 Kudos

By the way, in ABAP 7.40 you will be able to read it directly. Keep one eye on 's blog for more information.

Horst Keller wrote:

I love these questions hitting the mark.

No, you didn't miss it, conversion routines are simply not supported in string tenplates. If there is a large demand for an important general routine, it might be covered by a special format option. E.g. with Release 7.40 is a new option ALPHA was introduced, that does the same as CONVERSION_EXIT_ALPHA_INPUT or CONVERSION_EXIT_ALPHA_OUTPUT.                  

horst.keller: ABAP News for Release 7.40 - Expr... | SCN

Cheers,

Custodio

0 Kudos

Thanks Custodio.

Amine