Skip to Content

Abap alpha comparison

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

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

4 Answers

  • Best Answer
    Posted on May 30, 2013 at 01:47 PM

    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


    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 30, 2013 at 01:59 PM

    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.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on May 30, 2013 at 01:44 PM



























    Operator Meaning CO Contains 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. CN Contains 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. CA Contains 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. NA Contains 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. CS Contains 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. NS Contains 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. CP Covers 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. NP No 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,
    Add a comment
    10|10000 characters needed characters exceeded

  • Posted on May 30, 2013 at 02:21 PM

    Thanks a lot.

    Amine

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.