Skip to Content
author's profile photo Former Member
Former Member

comparing values in different tables

Hi,

I am trying to compare values in two different table fields, can someone advise me of the ABAP to do it.

I need to find IHPA-PARNR(partner number) in table T527X-ORGEH(org unit number)

Thanks,

Alec

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

10 Answers

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 11:12 AM

    Hi,

    Do this way:-

    I need to find IHPA-PARNR(partner number) in table T527X-ORGEH(org unit number)
    select parnr from IHPA into it_IHPA.
    
    sort it_IHPA by PARNR
    if not it_IHPA[] is initial.
       select ORGEH from T527X into table it_T527X
                for all entries in it_IHPA
                where  ORGEH = it_IHPA- PARNR.
    endif.
    
    now it_T527X contains the req result
    

    Thanks & Regards,

    Krishna

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:31 AM

    hi,

    u can select data from IHPA by using slect

    select PARNR from IHPA

    into table it_tab.

    and then select data from T527X

    select ORGEH from t527X into i_tab2

    for all entries in it_tab where parnr = it_tab-parnr.

    then u can compare using loop at it_tab and read from table i_tab2.

    thanks

    Add a comment
    10|10000 characters needed characters exceeded

    • Hi,

      Don't read directly from the Table t527x, first get all the records into an internal table it_t527x and then use it.

      Data : it_ihpa TYPE TABLE OF ihpa,

      wa_ihpa TYEP ihpa,

      it_t527x TYPE TABLE OF t527x,

      wa_t527x TYPE t527x.

      SELECT * FROM ihpa INTO TABLE it_ihpa.

      SELECT * FROM t527x INTO TABLE it_t527x.

      LOOP AT ihpa INTO wa_ihpa.

      READ TABLE it_t527x INTO wa_t527x WITH KEY orgeh = wa_ihpa-parnr

      BINARY SEARCH.

      IF sy-subrc EQ 0.

      WRITE 'HELLO' TO ZORGUNIT.

      ENDIF.

      ENDLOOP.

      Regards

      Bala Krishna

  • Posted on Dec 19, 2008 at 10:29 AM

    Hi,

    Declare 1 internal table with one field PARNR,

    Fill that internal table with all values of table IHPA,

    Select the entries of table T527X into second internal table for all the values in first internal table, so the second internal table has all the vales only of the values in IHPA-PARNR.

    Use SELECT statement with FOR ALL ENTRIES addition.

    Regards

    Bala Krishna

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 11:00 AM

    Hi,

    First check the data type and length of parnr and orgeh fields. And make sure that values of these two fields have same length.

    Check the following code:

    data: it_ihpa like ihpa occurs 0 with header line,

    wa_ihpa like it_ihpa,

    it_t527x like t527x occurs 0 with header line,

    wa_t527x like it_t527x.

    select objnr parnr into corresponding fields of table it_ihpa from ihpa up to 100 rows.

    sort it_ihpa by parnr.

    select orgeh into corresponding fields of table it_t527x from t527x up to 100 rows.

    sort it_t527x by orgeh.

    loop at it_ihpa into wa_ihpa.

    read table it_t527x into wa_t527x with key orgeh = wa_ihpa-parnr binary search.

    if sy-subrc = 0.

    write: 'successfully read'.

    else.

    write: 'read failed'.

    endif.

    endloop.

    Regards,

    Bhaskar

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:22 AM

    Hi,

    use command READ TABLE if you work with internal table.

    If you work with database tables, use command SELECT.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:24 AM

    HI.

    1.fetch PARNR value from table IHPA.

    2.Fetch ORGEH value from table T527X by using All entries

    3.check sy-subrc <> 0.

    Regards.

    Jay

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:24 AM

    Hi Alec,

    In ABAP, you can make use of LOOP and READ statements to compare the values.

    As in this case,

    I need to find IHPA-PARNR(partner number) in table T527X-ORGEH(org unit number)

    Loop at ihpa into wa_ihpa.
    Read table t527x into wa_t527x with key orgeh = wa_ihpa-parnr
                                                                binary search.
    if sy-subrc eq 0.
    " This means the value exists in table t527x. you can do the required modifications here.
    endif.
    Endloop.
    

    Hope this is what you are looking for.

    Best Regards,

    Ram.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:42 AM

    declare 2 internal table read all your data into these table and in loop endloop statement compare all the value you want

    loop

    'your if condition for comparision

    endloop

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:43 AM

    hi,

    data :it_tab like standard table of ihpa with header line.

    now u can loop at it_tab instead of ihpa.

    thanks

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Dec 19, 2008 at 10:45 AM

    Hi,

    Pls check this:

    loop at it_ihpa into wa_ihpa.

    loop at it_t527x into wa_t527x.

    if wa_ihpa-parnr eq wa_t527x-orgeh.

    endif.

    endloop.

    endloop.

    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.