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

Regarding SQL ...

Former Member
0 Likes
748

Hello ABAP gurus,

Please help me out in solving following doubt.

Fieldname: Tax-code1 (STCD1), Tax-code2( STCD2), Vendor number(LIFNR)

Table name: LFA1.

I am working on uniqueness for tax code verification for vendors.

Lets say that tax code1 (STCD1) value for a particular vendor is in v_tax1 and tax-code2 (STCD2) value for vendor is in v_tax2.

I want to check tax-code1 value for this vendor number (LIFNR) against tax-code1 values for all the other vendors numbers in table LFA1.

Hence in simple terms I want to see if value of v_tax1 exists for any other vendor's Tax-code1 scanning the whole LFA1 for all the other vendors and comparing with their respective taxcode1s (STCD1).

If an entry exists then raise error.

Same thing I want to do for tax-code2, tax-code3..

Please let me know how do I perform this using SQL ?

Relevant points will be awarded..

6 REPLIES 6
Read only

Former Member
0 Likes
707

Any help will be appreciated...

Read only

Former Member
0 Likes
707


DATA: BEGIN OF i_lfa1 OCCURS 0,
      lifnr LIKE lfa1-lifnr,
      stcd1 LIKE lfa1-stcd1,
      END OF i_lfa1,

      i_lfa1_dup LIKE i_lfa1 OCCURS 0.


SELECT lifnr stcd1
FROM lfa1
INTO TABLE i_lfa1.

i_lfa1_dup[] = i_lfa1[].

LOOP AT i_lfa1.

  LOOP AT i_lfa1_dup WHERE lifnr NE i_lfa1-lifnr.

    IF i_lfa1_dup-stcd1 = i_lfa1-stcd1.

      WRITE: / 'Duplicate Tax Code ',
               i_lfa1_dup-stcd1,
               ' for vendors ',
               i_lfa1-lifnr,
               ' and ',
               i_lfa1_dup-lifnr.
    ENDIF.

  ENDLOOP.

ENDLOOP.
Read only

0 Likes
707

But there is a better way than the above mentioned!

Message was edited by: Sam

Read only

0 Likes
707

Can you please let me know.

Read only

0 Likes
707

Ok I am working on that and will get back to you once I am sure it is efficient than the posted answer...

Read only

Former Member
0 Likes
707

Hi

You can perhaps do this using a subquery in the select stmt.

select lifnr stcd1 from lfa1 as a

into table itab

where lifnr in s_lifnr

and exists ( select stcd1 from lfa1 as b

where blifnr <> alifnr

and bstcd1 = astcd1 ).

Regards

Kalpana

Message was edited by: Kalpana Tyagi