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: 

Excluding the vaues of Internal table while retreiving data from data base

Former Member
0 Kudos
1,203

Dear all,

i had a problem while retreiving data from BKPF table. my problem i will get a list of values from the search help and i had written the following code in my search help exit to exclude the values of table tt_vblnr which is retreived from payer.

I want to get the values other than the retreived values from the search help .

when i am writing the following code it is excluding the values of BUKRS and GJAHR but not considering the BELNR value but if i am giving the BELNR value alone in for all entries it is not cosidering that and displaying all values.

select bukrs

belnr

gjahr

budat from bkpf into table tt_bkpf

FOR ALL ENTRIES IN tt_vblnr

where

( bukrs eq tt_vblnr-zbukr

and belnr ne tt_vblnr-vblnr

and gjahr eq tt_vblnr-gjahr )

and blart = 'KZ' .

can any one help me out how to solve the situation

i tried using ranges but it did not help

8 REPLIES 8

Former Member
0 Kudos
366

the select query is like this

select bukrs

belnr

gjahr

budat from bkpf into table tt_bkpf

FOR ALL ENTRIES IN tt_vblnr

where

( bukrs ne tt_vblnr-zbukr

and belnr ne tt_vblnr-vblnr

and gjahr ne tt_vblnr-gjahr )

and blart = 'KZ' .

can any one help me out how to solve the situation

i tried using ranges but it did not help

0 Kudos
366

Hi

It can't use a FOR ALL ENTRIES option to exclude the records contained in a table, because you'll have a conflict in every selection steps.

Suppose tt_vblnr has 3 records: A, B and C

In the first step the selction should select all records not equal A, that means B and C too, in the second step all records not equal to B, that means A and C,.....and so

I think you need to check if a record is in tt_vblnr after selecting it

SELECT * FROM BKPF WHERE.....
   READ TABLE tt_vblnr WITH KEY BUKRS = BKPF-BUKRS
                                                        BELNR = BKPF-BELNR
                                                        GJAHR = BKPF-GJAHR
    CHECK SY-SUBRC <> 0

But you can try to use a subquery

max

0 Kudos
366

hi,

i have done a teste:


data: it_a type STANDARD TABLE OF bkpf,
      wa_a type bkpf,
      it_bkpf type STANDARD TABLE OF bkpf.
wa_a-bukrs = 'COMP'.
wa_a-belnr = '1234567890'.
wa_a-gjahr = '2010'.
APPEND wa_a to it_a.
select * from bkpf
  into table it_bkpf
UP TO 10 ROWS
  FOR ALL ENTRIES IN it_a
WHERE bukrs NE it_a-bukrs
AND belnr NE it_a-belnr
AND gjahr NE it_a-gjahr
AND blart = 'KZ'.

And it works. The only problema is the blart witch i don´t have..but i change it for another.

Don´t know what is the problema.

0 Kudos
366

Have you checked whether your internal table tt_vblnr[] is empty before FORALL entries

0 Kudos
366

What exactly do you expect from this statement

- FOR ALL ENTRIES executes an UNION of SQL statements for each record, so you get the union of records selected via exclusion, most likely you will get each and every records of this document type (vendor payment).

- Even if it excluded the records of you list, you should get every records companies or year not in the internal table for this document type, once again a bunch of records (if the internal table is not itself a bunch with most records of the database)

So what is your exact purpose ?

If your exclusion list comes from another select, try yo use a [SELECT|http://help.sap.com/abapdocu_70/en/ABAPSELECT.htm] [WHERE|http://help.sap.com/abapdocu_70/en/ABAPWHERE.htm] [NOT EXISTS|http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_EXISTS.htm] [subquery|http://help.sap.com/abapdocu_70/en/ABENWHERE_LOGEXP_SUBQUERY.htm]

Regards,

Raymond

Former Member
0 Kudos
366

try for this,

select bukrs belnr gjahr budat from bkpf into table tt_bkpf

FOR ALL ENTRIES IN tt_vblnr

where

( bukrs <> tt_vblnr-zbukr

and belnr <> tt_vblnr-vblnr

and gjahr <> tt_vblnr-gjahr )

and blart = 'KZ' .

Regards,

Shaligram

0 Kudos
366

Hi shaligram

with your code it will give error without any operator.

thanks for reply

Former Member
0 Kudos
366

Hi,

you can initally fetch the data from BKPF on the conditions BUKRD eq tt_vblnr-zbukr and GJAHR eq tt_vblnr-gjahr and BLART

eq 'KZ'.

then loop at the table TT_VBPF and filter out the records as under:

data: lv_tabix type SYTABIX.

select bukrs

belnr

gjahr

budat from bkpf into table tt_bkpf

FOR ALL ENTRIES IN tt_vblnr

where

( bukrs eq tt_vblnr-zbukr

and gjahr eq tt_vblnr-gjahr )

and blart = 'KZ' .

sort tt_vblnr by belnr.

loop at tt_bkpf into wa_bkpf.

lv_tabix = sy-tabix.

read table tt_vblnr into wa_vblnr with key belnr eq wa_bkpf-belnr.

if sy-subrc eq 0.

delete tt_bkpf index lv_tabix.

endif.

clear: wa_bkpf, wa_vblnr.

clear: lv_tabix.

endloop.

please workout and let me know if you still facing issues.

Regards,

Vishnu.