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: 

regd : Internal tables

Former Member
0 Kudos

hi,

I am using Two tables.

in coep table cost element (Kstar) is available where as in setleaf table only costelement range (Valfrom and valto is available).

i have to read setleaf table and get setname based on costelment.Since it is having from and to value.If inbetween value exist it is not reading setleaf table.pLease help me out in this.

tables : coep,

setheader.

DATA : BEGIN OF itab_coep OCCURS 0,

kokrs LIKE coep-kokrs, " Controlling Area

gjahr LIKE coep-gjahr, " FiscalYear

perio LIKE coep-perio, " Period

kstar LIKE coep-kstar, " CostElement

bukrs LIKE coep-bukrs, " CompanyCode

wkgbtr LIKE coep-wkgbtr, " Amount in Object mbgbtr LIKE coep-mbgbtr, " Total quantity entered

meinh LIKE coep-meinh, " unit

objnr like coep-objnr,

OWAER like coep-owaer,

belnr like coep-belnr,

line_color(4) TYPE c,

END OF itab_coep.

data : begin of itab_setleaf occurs 0,

setclass like setleaf-setclass,

subclass like setleaf-subclass,

setname like setleaf-setname, " CostElementGroup

valfrom like setleaf-valfrom,

valto like setleaf-valto,

end of itab_setleaf.

data : begin of itab_final occurs 0,

kokrs LIKE coep-kokrs, " Controlling Area

gjahr LIKE coep-gjahr, " FiscalYear

perio LIKE coep-perio, " Period

kstar LIKE coep-kstar, " CostElement

bukrs LIKE coep-bukrs, " CompanyCode

wkgbtr LIKE coep-wkgbtr, " Amount in Object mbgbtr LIKE coep-mbgbtr, " Total quantity entered

meinh LIKE coep-meinh, " unit

objnr like coep-objnr,

OWAER like coep-owaer,

belnr like coep-belnr,

line_color(4) TYPE c,

setclass like setleaf-setclass,

subclass like setleaf-subclass,

setname like setleaf-setname, " CostElementGroup

valfrom like setleaf-valfrom,

valto like setleaf-valto,

endof itab_final.

SELECTION-SCREEN : BEGIN OF BLOCK blk1 WITH FRAME TITLE text-001.

PARAMETERS : p_ca LIKE coep-kokrs obligatory .

SELECT-OPTIONS : s_year FOR coep-gjahr obligatory.

SELECT-OPTIONS : s_pd FOR coep-perio obligatory .

SELECT-OPTIONS : s_code FOR coep-bukrs.

SELECT-OPTIONS : s_pg FOR cepc-khinr

SELECT-OPTIONS : s_pc FOR aufk-prctr.

SELECT-OPTIONS : s_ku FOR coep-kstar no-display

select-options : s_kg for setleaf-setname

SELECT-OPTIONS : s_or FOR aufk-aufnr.

select-options : s_org for setleaf-setname

Select-options : s_dc for coep-belnr.

SELECTION-SCREEN : END OF BLOCK blk1.

SELECT kokrs gjahr perio kstar bukrs wkgbtr objnr owaer belnr

FROM coep INTO CORRESPONDING FIELDS OF TABLE itab_coep

WHERE kokrs = p_ca

AND perio IN s_pd

AND bukrs IN s_code

AND gjahr IN s_year

and belnr in s_dc.

LOOP AT itab_coep.

itab_final-kokrs = itab_coep-kokrs.

itab_final-gjahr = itab_coep-gjahr.

itab_final-perio = itab_coep-perio.

itab_final-kstar = itab_coep-kstar.

itab_final-bukrs = itab_coep-bukrs.

itab_final-wkgbtr = itab_coep-wkgbtr.

itab_final-objnr = itab_coep-objnr.

itab_final-owaer = itab_coep-owaer.

APPEND itab_final.

CLEAR itab_final.

ENDLOOP.

if not itab_coep[] is initial.

--


To fetch InternalOrderGroup--

*clear itab_final-setname.

select setclass subclass setname valfrom valto

from setleaf into corresponding fields of table itab_setleaf

where setclass = '0102'

and subclass = 'VMIN'

and setname in s_kg.

loop at itab_final.

read table itab_setleaf with key valfrom = itab_final-kstar

valto = itab_final-kstar.

if sy-subrc = 0.

itab_final-setname = itab_setleaf-setname.

modify itab_final transporting setname.

else.

delete itab_final.

endif.

endloop.

loop at itab_final.

write 😕 itab_final-setname,

itab_final-wkgbtr,

itab_final-kstar.

endloop.

2 REPLIES 2

raymond_giuseppi
Active Contributor
0 Kudos

Don't read SETLEAF yourself, let SAP do the work, use function module K_COSTELEM_SELECT :

    DATA: t_cskb_ex TYPE cskb_ex OCCURS 0.

    CALL FUNCTION 'K_COSTELEM_SELECT'
         EXPORTING
              kokrs           = p-kokrs
              ce_group        = p-kagru
         TABLES
              it_result       = t_cskb_ex
         EXCEPTIONS
              no_record_found = 1
              group_not_found = 2
              OTHERS          = 3.

If you really need SET, build a RANGE :

    SELECT * FROM setleaf
      WHERE setclass = '0102'
        and subclass = 'VMIN'
        and setname in s_kg.setname = p-set.
      CLEAR s-kstar.
      s-kstar-sign = setleaf-valsign.
      s-kstar-option = setleaf-valoption.
      s-kstar-low = setleaf-valfrom.
      s-kstar-high = setleaf-valto.
      APPEND s-kstar.
    ENDSELECT.

Regards

Former Member
0 Kudos

i didnt went through ur code

but i guess you should RANGES

ranges-high

ranges-low

ranges-i

thnkx

bhanu