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

sql , how to get cost elements in cost element group in sql statement ?

Former Member
0 Likes
1,048

sql , how to get cost elements in cost element group in sql statement ?

hello everyone.

i need some help.

i want to get data from bseg which have gl = cost element in cost element group

such as cost element group "promo_allo"

have cost element = 496362,496341,496335

i know that cost element group keep in table "setleaf"

in table "setleaf"

record 1

setname = "promo_allo"

valfrom = 0000496362 = gl

record 2

setname = "promo_allo"

valfrom = 0000496341

record 3

setname = "promo_allo"

valfrom = 0000496335

but i donot know how to get data from table bseg which have gl = cost element in cost element group

SELECT BUKRS BELNR BUZEI GJAHR LIFNR DMBTR MWSKZ SGTXT HKONT

INTO TABLE T_BSEG

FROM BSEG

FOR ALL ENTRIES IN T_DOC_HEADER

WHERE BUKRS = T_DOC_HEADER-BUKRS AND

BELNR = T_DOC_HEADER-BELNR AND

GJAHR = T_DOC_HEADER-GJAHR AND

LIFNR IN S_LIFNR

HKONT = ????????????????????????????????????????

.

please advice

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
921

Hi,

Get all your entries from SETLEAF into an internal table.

ranges : r_HKONT for bseg-HKONT.

select * from SETLEAF into it_setleaf where setname = 'promo_allo' ...

loop at it_setleaf.

r_HKONT-sign = it_setleaf-VALSIGN.

r_HKONT-option = it_setleaf-VALOPTION.

r_HKONT-low = it_setleaf-VALFROM.

r_HKONT-high = it_setleaf-VALTO.

append r_HKONT.

clear r_HKONT.

endloop.

use this r_HKONT in your select ...

SELECT BUKRS BELNR BUZEI GJAHR LIFNR DMBTR MWSKZ SGTXT HKONT

INTO TABLE T_BSEG

FROM BSEG

FOR ALL ENTRIES IN T_DOC_HEADER

WHERE BUKRS = T_DOC_HEADER-BUKRS AND

BELNR = T_DOC_HEADER-BELNR AND

GJAHR = T_DOC_HEADER-GJAHR AND

LIFNR IN S_LIFNR

HKONT in r_HKONT.

Regards,

Srini.

4 REPLIES 4
Read only

Former Member
0 Likes
921

After you have the individual cost elements, put them in a range table and then include that in the SELECT.

Is that the question you are asking?

Rob

Read only

0 Likes
921

thank you Rob.

please tell me how to put data in range table

Read only

Former Member
0 Likes
922

Hi,

Get all your entries from SETLEAF into an internal table.

ranges : r_HKONT for bseg-HKONT.

select * from SETLEAF into it_setleaf where setname = 'promo_allo' ...

loop at it_setleaf.

r_HKONT-sign = it_setleaf-VALSIGN.

r_HKONT-option = it_setleaf-VALOPTION.

r_HKONT-low = it_setleaf-VALFROM.

r_HKONT-high = it_setleaf-VALTO.

append r_HKONT.

clear r_HKONT.

endloop.

use this r_HKONT in your select ...

SELECT BUKRS BELNR BUZEI GJAHR LIFNR DMBTR MWSKZ SGTXT HKONT

INTO TABLE T_BSEG

FROM BSEG

FOR ALL ENTRIES IN T_DOC_HEADER

WHERE BUKRS = T_DOC_HEADER-BUKRS AND

BELNR = T_DOC_HEADER-BELNR AND

GJAHR = T_DOC_HEADER-GJAHR AND

LIFNR IN S_LIFNR

HKONT in r_HKONT.

Regards,

Srini.

Read only

0 Likes
921

thank you for all.

i got solution