Skip to Content
author's profile photo Former Member
Former Member

regd : drill down report

hi,

I need to get drill down on each row

if i click on revenue.i should get on drill down.

and if i click on expense i need to get another drill down.

Please help me out defenetly points will be rewarded

&----


*& Report ZIN1

*&

&----


*&

*&

&----


REPORT ZIN1.

*&----


*& Table declaration

&----


TABLES : coep,

coas,

tkv11,

cepc,

cskb,

tka01,

cska,

aufk,

setleaf.

*

*&----


*& type-pool declaration

&----


TYPE-POOLS : slis.

*&----


*& Internal tables declaration

&----


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 Currency

mbgbtr LIKE coep-mbgbtr, " Total quantity entered

meinh LIKE coep-meinh, " unit

objnr like coep-objnr,

line_color(4) TYPE c,

END OF itab_coep.

DATA :BEGIN OF itab_cepc OCCURS 0,

kokrs LIKE cepc-kokrs,

prctr LIKE cepc-prctr,

khinr LIKE cepc-khinr, " Profit Center Group

bukrs like cepc-bukrs,

END OF itab_cepc.

DATA : BEGIN OF itab_aufk OCCURS 0,

kokrs LIKE aufk-kokrs,

aufnr LIKE aufk-aufnr, " Order Number

bukrs LIKE aufk-bukrs,

prctr LIKE aufk-prctr, " ProfitCenter

auart LIKE aufk-auart, " OrderType

autyp LIKE aufk-autyp, " Order Category

objnr like aufk-objnr,

END OF itab_aufk.

DATA : BEGIN OF itab_cskb OCCURS 0,

kokrs LIKE cskb-kokrs,

kstar LIKE cskb-kstar,

katyp LIKE cskb-katyp, " Cost Element Type

aufnr LIKE cskb-aufnr,

END OF itab_cskb.

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_setleaf1 occurs 0,

setclass like setleaf-setclass,

subclass like setleaf-subclass,

setname like setleaf-setname, "InternalOrderGroupName

valfrom like setleaf-valfrom,

valto like setleaf-valto,

end of itab_setleaf1.

DATA : BEGIN OF itab_final OCCURS 0,

kokrs LIKE coep-kokrs,

gjahr like coep-gjahr,

perio LIKE coep-perio,

kstar LIKE coep-kstar,

bukrs LIKE coep-bukrs,

wkgbtr LIKE coep-wkgbtr,

mbgbtr LIKE coep-mbgbtr,

meinh LIKE coep-meinh,

aufnr LIKE aufk-aufnr,

auart LIKE aufk-auart,

katyp LIKE cskb-katyp,

prctr LIKE aufk-prctr,

khinr LIKE cepc-khinr,

kagru LIKE tkv11-kagru,

periol like coep-perio,

perioh like coep-perio,

gjahrl like coep-gjahr,

gjahrh like coep-gjahr,

objnr like coep-objnr,

setclass like setleaf-setclass,

subclass like setleaf-subclass,

setname like setleaf-setname, " CostelementGroup

setname1 like setleaf-setname, " InternalOrderGroup

valfrom like setleaf-valfrom,

valto like setleaf-valto,

ca like coep-kokrs,

ccl like coep-bukrs,

cch like coep-bukrs,

pgl like cepc-khinr,

pgh like cepc-khinr,

pcl like cepc-prctr,

pch like cepc-prctr,

kul like coep-kstar,

kuh like coep-kstar,

kgl like setheader-setname,

kgh like setheader-setname,

orl like cskb-aufnr,

orh like cskb-aufnr,

orgl like setleaf-setname,

orgh like setleaf-setname,

line_color(4) TYPE c,

END OF itab_final.

DATA : ifinal like itab_final occurs 0 with header line.

DATA : BEGIN OF itab1 OCCURS 0,

katyp1(100) type c ,

katyp like cskb-katyp,

gjahr like coep-gjahr,

bukrs like coep-bukrs,

wkgbtr LIKE coep-wkgbtr,

perio1(100) type C,

gjahr1(100) type c,

perio LIKE coep-perio,

periol like coep-perio,

perioh like coep-perio,

gjahrl like coep-gjahr,

gjahrh like coep-gjahr,

prctr like cepc-prctr,

setname like setleaf-setname, " CostelementGroup

setname1 like setleaf-setname, " InternalOrderGroup

ca like coep-kokrs,

ccl like coep-bukrs,

cch like coep-bukrs,

pgl like cepc-khinr,

pgh like cepc-khinr,

pcl like cepc-prctr,

pch like cepc-prctr,

kul like coep-kstar,

kuh like coep-kstar,

kgl like setheader-setname,

kgh like setheader-setname,

orl like cskb-aufnr,

orh like cskb-aufnr,

orgl like setleaf-setname,

orgh like setleaf-setname,

line_color(4) TYPE c,

END OF itab1.

DATA : lin type i.

*&----


*& fieldcatalog declaration

&----


DATA : t_fcat TYPE slis_t_fieldcat_alv,

t_fcat1 TYPE slis_t_fieldcat_alv,

t_fcat2 TYPE slis_t_fieldcat_alv,

t_fcat3 TYPE slis_t_fieldcat_alv,

t_fcat4 TYPE slis_t_fieldcat_alv,

t_eve TYPE slis_t_event,

t_subtot TYPE slis_t_sortinfo_alv,

t_subtot1 TYPE slis_t_sortinfo_alv,

t_subtot2 type slis_t_sortinfo_alv,

t_subtot3 type slis_t_sortinfo_alv,

t_subtot4 type slis_t_sortinfo_alv,

subtot LIKE LINE OF t_subtot,

d_fieldcat_wa LIKE LINE OF t_fcat,

gd_layout TYPE slis_layout_alv.

DATA : t_header type slis_t_listheader,

wa_header type slis_listheader.

*&----


*& variables declaration

&----


DATA : gt_gross LIKE coep-wkgbtr,

st_rev LIKE coep-wkgbtr,

st_rev1 LIKE coep-wkgbtr,

st_pc1 LIKE coep-wkgbtr,

st_pc LIKE coep-wkgbtr,

st_all1 LIKE coep-wkgbtr,

st_all LIKE coep-wkgbtr,

st_gross LIKE coep-wkgbtr,

st_gross1 LIKE coep-wkgbtr,

st_net1 LIKE coep-wkgbtr,

st_net LIKE coep-wkgbtr,

st_pt1 LIKE coep-wkgbtr,

st_pt LIKE coep-wkgbtr,

st_nt1 LIKE coep-wkgbtr,

st_nt LIKE coep-wkgbtr.

DATA : gd_repid LIKE sy-repid.

gd_repid = sy-repid.

data : ok_code like sy-ucomm.

data : DC like ok_code.

DC = ok_code.

*&----


*& Selection-Screen declaration

&----


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 matchcode object zyear."default 2007 to 9999.

SELECT-OPTIONS : s_pd FOR coep-perio obligatory .

SELECT-OPTIONS : s_code FOR coep-bukrs.

SELECT-OPTIONS : s_pg FOR cepc-khinr MATCHCODE OBJECT zprofitcentergroup.

SELECT-OPTIONS : s_pc FOR aufk-prctr.

SELECT-OPTIONS : s_ku FOR coep-kstar matchcode object zcost. "no-display

select-options : s_kg for setleaf-setname matchcode object zsetname.

SELECT-OPTIONS : s_or FOR aufk-aufnr.

select-options : s_org for setleaf-setname matchcode object ZSETNAME1.

SELECTION-SCREEN : END OF BLOCK blk1.

*&----


*& Selection-Screen Validation

&----


at selection-screen on p_ca.

select kokrs gjahr perio bukrs from coep

into corresponding fields of table itab_coep

where kokrs = p_ca.

if sy-subrc <> 0.

message e001(zerror) .

endif.

at selection-screen on s_year.

select kokrs gjahr perio bukrs from coep

into corresponding fields of table itab_coep

where gjahr in s_year.

if sy-subrc <> 0.

message e005(zerror).

endif.

at selection-screen on s_code.

select kokrs gjahr perio bukrs from coep

into corresponding fields of table itab_coep

where bukrs in s_code.

if sy-subrc <> 0.

message e006(zerror).

endif.

at selection-screen on s_pd.

select kokrs gjahr perio bukrs from coep

into corresponding fields of table itab_coep

where perio in s_pd.

if sy-subrc <> 0.

message e007(zerror).

endif.

at selection-screen on s_pg.

select kokrs khinr prctr from cepc

into corresponding fields of table itab_cepc

where khinr in s_pg.

if sy-subrc <> 0.

message e002(zerror).

endif.

at selection-screen on s_pc.

select prctr from aufk

into corresponding fields of table itab_cepc

where prctr in s_pc.

if sy-subrc <> 0.

message e008(zerror).

endif.

at selection-screen on s_or.

select single * from aufk where aufnr in s_or.

if sy-subrc <> 0.

message e003(Zerror).

endif.

at selection-screen on s_kg.

select single * from setleaf where setname in s_kg.

if sy-subrc <> 0.

message e017(zerror).

endif.

*&----


*& Start-Of-Selection

&----


START-OF-SELECTION.

clear st_pc.

clear st_rev.

clear st_all.

clear st_net.

clear st_gross.

clear itab1[].

PERFORM get_data.

  • perform sel.

PERFORM build_cat USING t_fcat.

PERFORM build_layout.

PERFORM display.

&----


*& Form build_cat

&----


  • text

----


  • -->TEMP_FCAT text

----


FORM build_cat USING temp_fcat TYPE slis_t_fieldcat_alv.

d_fieldcat_wa-fieldname = 'KATYP1'.

d_fieldcat_wa-seltext_m = 'CostelementType'.

d_fieldcat_wa-hotspot = 'X'.

d_fieldcat_wa-col_pos = 1.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'PERIO1'.

d_fieldcat_wa-seltext_m = 'For The Period'.

d_fieldcat_wa-key = 'X'.

d_fieldcat_wa-col_pos = 3.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'GJAHR1'.

d_fieldcat_wa-seltext_m = 'Year to Date'.

d_fieldcat_wa-key = 'X'.

d_fieldcat_wa-col_pos = 4.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

ENDFORM. "build_cat

&----


*& Form build_eve

&----


  • text

----


FORM build_eve.

CALL FUNCTION 'REUSE_ALV_EVENTS_GET'

EXPORTING

i_list_type = 0

IMPORTING

et_events = t_eve

EXCEPTIONS

list_type_wrong = 1

OTHERS = 2.

IF sy-subrc EQ 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

endform.

&----


*& Form get_data

&----


  • text

----


FORM get_data.

--


To fetch Amount, Period ,Year, CompanyCode--

SELECT kokrs gjahr perio kstar bukrs wkgbtr objnr

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 kstar in s_ku.

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.

APPEND itab_final.

CLEAR itab_final.

ENDLOOP.

IF NOT itab_coep[] IS INITIAL.

--


To fetch Amount,ProfitCenter,InternalOrder--

SELECT kokrs aufnr prctr bukrs auart objnr

FROM aufk INTO CORRESPONDING FIELDS OF TABLE itab_aufk

WHERE aufnr IN s_or

and prctr in s_pc.

loop at itab_final.

READ TABLE itab_aufk WITH KEY kokrs = itab_final-kokrs

objnr = itab_final-objnr.

IF sy-subrc = 0.

itab_final-aufnr = itab_aufk-aufnr.

itab_final-prctr = itab_aufk-prctr.

MODIFY itab_final TRANSPORTING aufnr prctr.

else.

delete itab_final.

ENDIF.

endloop.

IF NOT itab_aufk[] IS INITIAL.

--


To fetch ProfitCenter ,ProfitCenterGroup--

SELECT kokrs khinr prctr

FROM cepc INTO CORRESPONDING FIELDS OF TABLE itab_cepc

WHERE kokrs = itab_aufk-kokrs

and khinr in s_pg.

LOOP AT itab_final.

READ TABLE itab_cepc WITH KEY kokrs = itab_final-kokrs

prctr = itab_final-prctr.

IF sy-subrc = 0.

itab_final-khinr = itab_cepc-khinr.

MODIFY itab_final TRANSPORTING khinr.

else.

delete itab_final.

ENDIF.

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

and valfrom in s_ku

and valto in s_ku.

loop at itab_final.

read table itab_setleaf with key valfrom = itab_final-kstar.

if sy-subrc = 0.

itab_final-setname = itab_setleaf-setname.

modify itab_final transporting setname.

else.

delete itab_final.

endif.

endloop.

if not itab_aufk[] is initial.

--


To fetch CostElementGroup--

clear itab_final-setname.

select setclass subclass setname valfrom valto from setleaf into corresponding fields of table itab_setleaf1

where setclass = '0103'

and setname in s_org

and valfrom in s_or

and valto in s_or.

loop at itab_final .

read table itab_setleaf1 with key valfrom = itab_final-aufnr.

if sy-subrc = 0.

itab_final-setname1 = itab_setleaf1-setname.

modify itab_final transporting setname1.

else.

delete itab_final.

endif.

ENDLOOP.

IF NOT itab_coep[] IS INITIAL.

SELECT kokrs katyp aufnr kstar

FROM cskb INTO CORRESPONDING FIELDS OF TABLE itab_cskb

FOR ALL ENTRIES IN itab_coep

WHERE kokrs = itab_coep-kokrs.

loop at itab_final.

READ TABLE itab_cskb WITH KEY kstar = itab_final-kstar

kokrs = itab_final-kokrs.

IF sy-subrc = 0.

itab_final-katyp = itab_cskb-katyp.

MODIFY itab_final TRANSPORTING katyp.

ENDIF.

ENDLOOP.

endif.

endif.

ENDIF.

ENDIF.

ENDIF.

loop at itab_final where katyp = '11' or katyp = '12'.

move-corresponding itab_final to ifinal.

append ifinal.

clear ifinal.

endloop.

--


calculation for revenue--

SORT ifinal BY katyp.

loop at ifinal where perio = s_pd-high.

st_rev1 = st_rev1 + ifinal-wkgbtr.

endloop.

st_rev1 = ( st_rev1 * ( -1 ) ).

LOOP AT ifinal .

st_rev = st_rev + ifinal-wkgbtr.

ENDLOOP.

st_rev = ( st_rev * ( -1 ) ).

itab1-katyp1 = ' '.

itab1-wkgbtr = st_rev .

concatenate s_pd-high ' ' into itab1-perio1 separated by space.

Concatenate s_pd-low '-' s_pd-high into itab1-gjahr1 separated by space.

itab1-line_color = 'C710'.

APPEND itab1.

itab1-line_color = ' '.

CLEAR : itab1,ifinal.

itab1-katyp1 = 'Revenue '.

itab1-perio1 = st_rev1 .

itab1-gjahr1 = st_rev .

APPEND itab1.

CLEAR : itab1,ifinal.

-- -calculation for DirectExpense --


clear : ifinal[].

loop at itab_final where katyp = '01'.

move-corresponding itab_final to ifinal.

append ifinal.

endloop.

SORT ifinal BY katyp .

LOOP AT ifinal.

st_pc = st_pc + ifinal-wkgbtr.

ENDLOOP.

loop at ifinal where perio = s_pd-high.

st_pc1 = st_pc1 + ifinal-wkgbtr.

endloop.

itab1-katyp1 = 'DirectExpense'.

itab1-wkgbtr = st_pc.

itab1-perio1 = st_pc1.

itab1-gjahr1 = st_pc.

APPEND itab1.

CLEAR : itab1,ifinal.

-- -calculation for Gross Margin --


st_gross1 = st_rev1 - st_pc1.

if st_pc1 > st_rev1.

st_gross1 = ( st_gross1 * ( -1 ) ).

endif.

itab1-katyp1 = 'GrossMargin '.

st_gross = ( st_rev - st_pc ).

if st_pc > st_rev.

st_gross = ( st_gross * ( -1 ) ).

endif.

itab1-wkgbtr = st_gross.

itab1-perio1 = st_gross1.

itab1-gjahr1 = st_gross.

itab1-line_color = 'C500'.

APPEND itab1.

CLEAR: itab1,ifinal.

itab1-katyp1 = ' Percentage (%)'.

if st_rev1 = 0. " Handle Divide by Zero exception

st_pt1 = 0.

endif.

if st_rev = 0.

st_pt = 0.

else.

st_pt1 = ( st_gross1 / st_rev1 ) * 100.

st_pt = ( st_gross / st_rev ) * 100.

endif.

itab1-perio1 = st_pt1.

itab1-gjahr1 = st_pt.

itab1-line_color = 'C710'.

APPEND itab1.

CLEAR: itab1,ifinal.

-- -Calculation for Allocated cost --


clear : ifinal[].

loop at itab_final where katyp <> '01'

and katyp <> '11'

and katyp <> '12'.

move-corresponding itab_final to ifinal.

append ifinal.

endloop.

SORT ifinal BY katyp .

LOOP AT ifinal.

st_all = st_all + ifinal-wkgbtr.

ENDLOOP.

loop at ifinal where perio = s_pd-high.

st_all1 = st_all1 + ifinal-wkgbtr.

endloop.

itab1-katyp1 = 'AllocatedExpenses'.

itab1-wkgbtr = st_all.

itab1-perio1 = st_all1.

itab1-gjahr1 = st_all.

APPEND itab1.

CLEAR: itab1, ifinal.

--


calculation for Net Margin--

st_net1 = st_gross1 - st_all1.

itab1-katyp1 = 'NetMargin'.

st_net = ( st_gross - st_all ).

itab1-wkgbtr = st_net.

itab1-perio1 = st_net1.

itab1-gjahr1 = st_net.

itab1-line_color = 'C500'.

APPEND itab1.

CLEAR: itab1, ifinal .

itab1-katyp1 = ' Percentage (%)'.

if st_rev1 = 0. " Handle Divide by Zero exception

st_nt1 = 0.

endif.

if st_rev = 0.

st_nt = 0.

else.

st_nt1 = ( st_net1 / st_rev1 ) * 100.

st_nt = ( st_net / st_rev ) * 100.

endif.

itab1-perio1 = st_pt1.

itab1-gjahr1 = st_pt.

itab1-line_color = 'C710'.

APPEND itab1.

CLEAR: itab1,ifinal.

ENDFORM. "get_data

&----


*& Form display

&----


  • text

----


FORM display.

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

  • I_INTERFACE_CHECK = ' '

  • I_BYPASSING_BUFFER = ' '

  • I_BUFFER_ACTIVE = ' '

I_CALLBACK_PROGRAM = gd_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = 'USER_COMMAND'

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

  • I_STRUCTURE_NAME =

  • I_BACKGROUND_ID = ' '

I_GRID_TITLE = 'Internal Order Analysis Report'

  • I_GRID_SETTINGS =

IS_LAYOUT = gd_layout

IT_FIELDCAT = t_fcat

  • IT_EXCLUDING =

  • IT_SPECIAL_GROUPS =

IT_SORT = t_subtot

  • IT_FILTER =

  • IS_SEL_HIDE =

  • I_DEFAULT = 'X'

  • I_SAVE = ' '

  • IS_VARIANT =

  • IT_EVENTS = t_eve[]

  • IT_EVENT_EXIT =

  • IS_PRINT =

  • IS_REPREP_ID =

  • I_SCREEN_START_COLUMN = 0

  • I_SCREEN_START_LINE = 0

  • I_SCREEN_END_COLUMN = 0

  • I_SCREEN_END_LINE = 0

  • I_HTML_HEIGHT_TOP = 0

  • I_HTML_HEIGHT_END = 0

  • IT_ALV_GRAPHICS =

  • IT_HYPERLINK =

  • IT_ADD_FIELDCAT =

  • IT_EXCEPT_QINFO =

  • IR_SALV_FULLSCREEN_ADAPTER =

  • IMPORTING

  • E_EXIT_CAUSED_BY_CALLER =

  • ES_EXIT_CAUSED_BY_USER =

TABLES

T_OUTTAB = itab1

EXCEPTIONS

PROGRAM_ERROR = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ENDFORM. "display

&----


*& Form build_layout

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_layout .

gd_layout-zebra = 'X'.

gd_layout-colwidth_optimize = 'X'.

gd_layout-info_fieldname = 'LINE_COLOR'.

ENDFORM. " build_layout

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

1 Answer

  • Best Answer
    Posted on Jan 25, 2008 at 01:22 PM

    When you define your USER_COMMAND you receive parameters :

    > FORM user_command USING r_ucomm LIKE sy-ucomm

    > rs_selfield TYPE slis_selfield.

    rs_selfield-fieldname is the name of the clicked field. Use this field in a CASE to dispatch drill down.

    Regards

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.