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

ABAP query

Former Member
0 Likes
623

Hi,

I need to extract data from two tables REGUH and PAYR common key is vblnr.

fields are zbukr hbkid hktid vblnr from REGUH and CHECT from PAYR,

could anyone help me to write the sql statement

Jeff

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
596

tables : REGUH,

PAYR .

data : begin of itab occurs 0,

zbukr like reguh-zbukr,

hbkid like reguh-hbkid,

hktid like reguh-hktid,

vblnr like reguh-vblnr,

CHECT like payr-CHECT,

end of itab.

start-of-selection.

select azbukr ahbkid ahktid avblnr

b~chect into table itab

from reguh as a inner join payr as b on bvblnr = avblnr.

4 REPLIES 4
Read only

Former Member
0 Likes
597

tables : REGUH,

PAYR .

data : begin of itab occurs 0,

zbukr like reguh-zbukr,

hbkid like reguh-hbkid,

hktid like reguh-hktid,

vblnr like reguh-vblnr,

CHECT like payr-CHECT,

end of itab.

start-of-selection.

select azbukr ahbkid ahktid avblnr

b~chect into table itab

from reguh as a inner join payr as b on bvblnr = avblnr.

Read only

0 Likes
596

I am getting duplicate entries.

how to avoid it?

Read only

0 Likes
596

Jeff, you are getting duplicates because the field chect is not key in table reguh.

You can: DELETE ADJACENT DUPLICATES FROM i_reguh comparing chect.

But verify if functionally is ok that yoy delete whose records and you are not losing information. Otherwise you should use and inner join comparing both tables by vblnr or ZBUKR or put more conditions in the where clause like ZBUKR = i_reguh-zbukr.

Regards,

Roxana

Read only

Former Member
0 Likes
596

Hi Jeff,

Maybe you can do:

select zbukr

hbkid

vblnr

from reguh

into i_reguh.

select chect

from payr

for all entries in i_reguh

where chect = i_reguh-chect.

It will be more performant if you put some condition in the where clause of reguh selection.

Regards,

Roxana