Skip to Content
0
Former Member
Jan 07, 2008 at 07:37 AM

regd : alv

44 Views

hi,

please help me out in this..the below code is working fine.but if i give range in profit center and internal order it is picking only lower value.and displaying the amount accordingly......please help me in resolving this issue..

Report zintord message-id zerror.

&----


& Program Name : ZINTORD Date : 21/12/2006

*& Program tilte : Internal Order Analysis Report *

*&

*&----


*&

&----


*&----


*& Table declaration

&----


TABLES : coep,

coas,

tkv11,

cepc,

cskb,

tka01,

aufk.

  • sscrfields,

  • setheader.

*

*&----


*& 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

wogbtr LIKE coep-wogbtr, " Amount in Object Currency

mbgbtr LIKE coep-mbgbtr, " Total quantity entered

meinh LIKE coep-meinh, " unit

line_color(4) TYPE c,

END OF itab_coep.

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

END OF itab_aufk.

DATA : BEGIN OF itab_cepc OCCURS 0,

kokrs LIKE cepc-kokrs,

prctr LIKE cepc-prctr,

khinr LIKE cepc-khinr, " Profit Center Group

END OF itab_cepc.

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_tkv11 OCCURS 0,

kokrs LIKE tkv11-kokrs,

kagru LIKE tkv11-kagru, " Internal Order Group

END OF itab_tkv11.

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,

wogbtr LIKE coep-wogbtr,

mbgbtr LIKE coep-mbgbtr,

meinh LIKE coep-meinh,

aufnr LIKE aufk-aufnr,

auart LIKE aufk-auart,

katyp LIKE cskb-katyp,

prctr LIKE cepc-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,

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 tkv11-kagru,

kuh like tkv11-kagru,

orl like cskb-aufnr,

orh like cskb-aufnr,

line_color(4) TYPE c,

END OF itab_final.

DATA : BEGIN OF itab1 OCCURS 0,

  • katyp LIKE cskb-katyp,

katyp(100) type c ,

gjahr like coep-gjahr,

bukrs like coep-bukrs,

wogbtr LIKE coep-wogbtr,

perio LIKE coep-perio,

periol like coep-perio,

perioh like coep-perio,

gjahrl like coep-gjahr,

gjahrh like coep-gjahr,

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 tkv11-kagru,

kuh like tkv11-kagru,

orl like cskb-aufnr,

orh like cskb-aufnr,

END OF itab1.

DATA : Ifinal like itab_final occurs 0 with header line.

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_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,

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-wogbtr,

st_rev LIKE coep-wogbtr,

st_pc LIKE coep-wogbtr,

st_all LIKE coep-wogbtr,

st_gross LIKE coep-wogbtr,

st_net LIKE coep-wogbtr.

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 cepc-prctr.

SELECT-OPTIONS : s_ku FOR tkv11-kagru MATCHCODE OBJECT zcostelementgroup.

SELECT-OPTIONS : s_or FOR aufk-aufnr.

*select-options : s_kp for cskb-katyp no-display matchcode object zkatyp.

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.

  • and gjahr in s_year

  • and bukrs in s_code

  • and perio in s_pd.

*

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 kokrs khinr prctr from cepc

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_ku.

select single * from tkv11 where kagru in s_ku.

if sy-subrc <> 0.

message e004(zerror).

endif.

*&----


*& Start-Of-Selection

&----


START-OF-SELECTION.

PERFORM get_data.

perform sel.

perform sel1.

PERFORM build_cat USING t_fcat.

perform build_sort.

PERFORM build_eve.

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 = 'KATYP'.

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 = 'WOGBTR'.

d_fieldcat_wa-seltext_m = 'AMount'.

d_fieldcat_wa-key = 'X'.

d_fieldcat_wa-do_sum = 'X'.

d_fieldcat_wa-col_pos = 2.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'PERIO'.

d_fieldcat_wa-seltext_m = 'Period'.

d_fieldcat_wa-col_pos = 3.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'GJAHRL'.

d_fieldcat_wa-seltext_m = 'Yearfrom'.

d_fieldcat_wa-col_pos = 4.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'GJAHRH'.

d_fieldcat_wa-seltext_m = 'YearTo'.

d_fieldcat_wa-col_pos = 5.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

  • d_fieldcat_wa-fieldname = 'BUKRS'.

  • d_fieldcat_wa-seltext_m = 'CompanyCode'.

  • d_fieldcat_wa-col_pos = 6.

  • 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 build_layout

&----


  • text

----


FORM build_layout.

gd_layout-zebra = 'X'.

gd_layout-colwidth_optimize = 'X'.

  • gd_layout-info_fieldname = 'LINE_COLOR'.

ENDFORM. " BUILD_LAYOUT

&----


*& Form get_data

&----


  • text

----


FORM get_data.

SELECT kokrs gjahr perio kstar bukrs wogbtr

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.

IF NOT itab_coep[] IS INITIAL.

SELECT kokrs prctr khinr

FROM cepc INTO CORRESPONDING FIELDS OF TABLE itab_cepc

FOR ALL ENTRIES IN itab_coep

WHERE kokrs = itab_coep-kokrs.

IF NOT itab_cepc[] IS INITIAL.

  • SELECT kokrs aufnr prctr bukrs auart autyp

SELECT kokrs aufnr bukrs auart autyp

FROM aufk INTO CORRESPONDING FIELDS OF TABLE itab_aufk

WHERE aufnr IN s_or.

  • AND prctr = itab_cepc-prctr.

IF NOT itab_aufk[] IS INITIAL.

SELECT kokrs katyp aufnr kstar

FROM cskb INTO CORRESPONDING FIELDS OF TABLE itab_cskb

FOR ALL ENTRIES IN itab_aufk

WHERE kokrs = itab_aufk-kokrs.

IF NOT itab_cskb[] IS INITIAL.

SELECT kokrs kagru

FROM tkv11 INTO CORRESPONDING FIELDS OF TABLE itab_tkv11

FOR ALL ENTRIES IN itab_cskb

WHERE kokrs = itab_cskb-kokrs.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

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-wogbtr = itab_coep-wogbtr.

APPEND itab_final.

CLEAR itab_final.

ENDLOOP.

LOOP AT itab_final.

READ TABLE itab_cepc WITH KEY kokrs = itab_final-kokrs.

IF sy-subrc = 0.

itab_final-prctr = itab_cepc-prctr.

itab_final-khinr = itab_cepc-khinr.

MODIFY itab_final TRANSPORTING prctr khinr.

ENDIF.

READ TABLE itab_aufk WITH KEY kokrs = itab_final-kokrs.

IF sy-subrc = 0.

itab_final-aufnr = itab_aufk-aufnr.

MODIFY itab_final TRANSPORTING aufnr.

ENDIF.

READ TABLE itab_cskb WITH KEY kstar = itab_final-kstar.

IF sy-subrc = 0.

itab_final-katyp = itab_cskb-katyp.

  • itab_final-aufnr = itab_final-aufnr.

MODIFY itab_final TRANSPORTING katyp.

ENDIF.

READ TABLE itab_tkv11 WITH KEY kokrs = itab_final-kokrs.

IF sy-subrc = 0.

itab_final-kagru = itab_tkv11-kagru.

MODIFY itab_final TRANSPORTING kagru.

ENDIF.

ENDLOOP.

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

move-corresponding itab_final to ifinal.

append ifinal.

endloop.

--


calculation for revenue--

SORT ifinal BY katyp.

LOOP AT ifinal.

st_rev = st_rev + ifinal-wogbtr.

itab1-katyp = ifinal-katyp.

itab1-wogbtr = ifinal-wogbtr.

itab1-perio = ifinal-perio.

itab1-gjahrl = ifinal-gjahrl.

itab1-gjahrh = ifinal-gjahrh.

APPEND itab1.

ENDLOOP.

itab1-katyp = 'Revenue (Includes Costelement Type 11 and 12)'.

itab1-wogbtr = st_rev.

itab1-perio = ' '.

itab1-gjahrl = ' '.

itab1-gjahrh = ' '.

APPEND itab1.

CLEAR : ifinal.

-- -calculation for primarycost --


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-wogbtr.

itab1-katyp = ifinal-katyp.

itab1-wogbtr = ifinal-wogbtr.

itab1-perio = ifinal-perio.

itab1-gjahrl = ifinal-gjahrl.

itab1-gjahrh = ifinal-gjahrh.

APPEND itab1.

ENDLOOP.

itab1-katyp = 'DirectExpense(includes costelement type 01)'.

itab1-wogbtr = st_pc.

itab1-perio = ' '.

itab1-gjahrl = ' '.

itab1-gjahrh = ' '.

APPEND itab1.

CLEAR: 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-wogbtr.

itab1-katyp = ifinal-katyp.

itab1-wogbtr = ifinal-wogbtr.

itab1-perio = ifinal-perio.

itab1-gjahrl = ifinal-gjahrl.

itab1-gjahrh = ifinal-gjahrh.

APPEND itab1.

ENDLOOP.

itab1-katyp = 'AllocatedExpenses(CostelementType Excluding 11,12,01 )'.

itab1-wogbtr = st_all.

itab1-perio = ' '.

itab1-gjahrl = ' '.

itab1-gjahrh = ' '.

APPEND itab1.

CLEAR: ifinal.

-- -calculation for Gross Margin --


itab1-katyp = 'GrossMargin ( Revenue - DirectExpense)'.

st_gross = ( st_rev - st_pc ).

itab1-wogbtr = st_gross.

itab1-perio = ' '.

itab1-gjahrl = ' '.

itab1-gjahrh = ' '.

APPEND itab1.

CLEAR: itab1,ifinal.

--


calculation for Net Margin--

itab1-katyp = 'NetMargin ( GrossMargin - AllocatedCost)'.

itab1-wogbtr = ( st_gross - st_all ).

itab1-perio = ' '.

itab1-gjahrl = ' '.

itab1-gjahrh = ' '.

APPEND itab1.

CLEAR: 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 For UserCommand

&----


  • text

----


FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

data : &IC1 like ok_code.

&IC1 = ok_code.

CASE R_UCOMM.

WHEN '&IC1'.

refresh t_fcat1.

refresh t_subtot1.

IF RS_SELFIELD-FIELDNAME = 'KATYP'.

perform secondarylist.

ENDIF.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDFORM.

&----


*& Form build_sort

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form build_sort.

subtot-spos = 1.

subtot-fieldname = 'KATYP'.

subtot-subtot = 'X'.

subtot-up = 'X'.

subtot-expa = 'X'.

append subtot to t_subtot.

endform. " build_sort

&----


*& Form sel

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sel .

loop at itab_final.

itab_final-ca = p_ca.

itab_final-ccl = s_code-low.

itab_final-cch = s_code-high.

itab_final-pgl = s_pg-low.

itab_final-pgh = s_pg-high.

itab_final-pcl = s_pc-low.

itab_final-pch = s_pc-high.

itab_final-kul = s_ku-low.

itab_final-kuh = s_ku-high.

itab_final-orl = s_or-low.

itab_final-orh = s_or-high.

itab_final-periol = s_pd-low.

itab_final-perioh = s_pd-high.

itab_final-gjahrl = s_year-low.

itab_final-gjahrh = s_year-high.

modify itab_final transporting periol perioh gjahrl gjahrh ca ccl cch pgl pgh pcl pch kul kuh orl orh.

endloop.

ENDFORM. " sel

&----


*& Form secondary

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM secondarylist .

clear itab_final[].

perform get_data1.

perform sel.

PERFORM build_cat1 USING t_fcat1.

perform build_sort1.

PERFORM build_layout.

PERFORM display1.

ENDFORM. " secondary

&----


*& Form build_cat1

&----


  • text

----


  • -->P_T_FCAT text

----


FORM build_cat1 USING temp_fcat TYPE slis_t_fieldcat_alv.

d_fieldcat_wa-fieldname = 'KSTAR'.

d_fieldcat_wa-seltext_m = 'CostElement'.

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 = 'KAGRU'.

d_fieldcat_wa-seltext_m = 'CostElementGroup'.

d_fieldcat_wa-col_pos = 2.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'WOGBTR'.

d_fieldcat_wa-seltext_m = 'AMount'.

d_fieldcat_wa-key = 'X'.

d_fieldcat_wa-do_sum = 'X'.

d_fieldcat_wa-col_pos = 3.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'PERIO'.

d_fieldcat_wa-seltext_m = 'Period'.

d_fieldcat_wa-col_pos = 4.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'GJAHRL'.

d_fieldcat_wa-seltext_m = 'Year from'.

d_fieldcat_wa-col_pos = 5.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'GJAHRH'.

d_fieldcat_wa-seltext_m = 'YearTo'.

d_fieldcat_wa-col_pos = 6.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

ENDFORM. " build_cat1

&----


*& Form get_data1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM get_data1 .

SELECT kokrs gjahr perio kstar bukrs wogbtr

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.

IF NOT itab_coep[] IS INITIAL.

SELECT kokrs prctr khinr

FROM cepc INTO CORRESPONDING FIELDS OF TABLE itab_cepc

FOR ALL ENTRIES IN itab_coep

WHERE kokrs = itab_coep-kokrs.

IF NOT itab_cepc[] IS INITIAL.

SELECT kokrs aufnr prctr bukrs auart autyp

FROM aufk INTO CORRESPONDING FIELDS OF TABLE itab_aufk

for all entries in itab_cepc

where prctr = itab_cepc-prctr

and kokrs = itab_cepc-kokrs.

IF NOT itab_aufk[] IS INITIAL.

SELECT kokrs katyp kstar

FROM cskb INTO CORRESPONDING FIELDS OF TABLE itab_cskb

FOR ALL ENTRIES IN itab_aufk

WHERE kokrs = itab_aufk-kokrs.

IF NOT itab_cskb[] IS INITIAL.

SELECT kokrs kagru

FROM tkv11 INTO CORRESPONDING FIELDS OF TABLE itab_tkv11

  • FOR ALL ENTRIES IN itab_cskb

WHERE kokrs = itab_cskb-kokrs

and kagru in s_ku.

ENDIF.

ENDIF.

ENDIF.

ENDIF.

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-wogbtr = itab_coep-wogbtr.

APPEND itab_final.

CLEAR itab_final.

ENDLOOP.

LOOP AT itab_final .

READ TABLE itab_cepc WITH KEY kokrs = itab_final-kokrs.

IF sy-subrc = 0.

itab_final-prctr = itab_cepc-prctr.

itab_final-khinr = itab_cepc-khinr.

MODIFY itab_final TRANSPORTING prctr khinr.

ENDIF.

READ TABLE itab_aufk WITH KEY kokrs = itab_final-kokrs

prctr = itab_final-prctr.

IF sy-subrc = 0.

itab_final-aufnr = itab_aufk-aufnr.

itab_final-auart = itab_aufk-auart.

MODIFY itab_final TRANSPORTING aufnr auart.

ENDIF.

READ TABLE itab_cskb WITH KEY kstar = itab_final-kstar

aufnr = itab_final-aufnr.

IF sy-subrc = 0.

itab_final-katyp = itab_cskb-katyp.

  • itab_final-aufnr = itab_final-aufnr.

MODIFY itab_final TRANSPORTING katyp.

ENDIF.

READ TABLE itab_tkv11 WITH KEY kokrs = itab_final-kokrs.

IF sy-subrc = 0.

itab_final-kagru = itab_tkv11-kagru.

MODIFY itab_final TRANSPORTING kagru.

ENDIF.

ENDLOOP.

ENDFORM. " get_data1

&----


*& Form display1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display1 .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = gd_repid

  • I_CALLBACK_PF_STATUS_SET = 'SET_PF_STATUS'

I_CALLBACK_USER_COMMAND = 'USER_COMMAND1'

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

  • I_CALLBACK_HTML_TOP_OF_PAGE = ' '

  • I_CALLBACK_HTML_END_OF_LIST = ' '

I_GRID_TITLE = 'Details Of CostElement'

  • I_GRID_SETTINGS =

IS_LAYOUT = gd_layout

IT_FIELDCAT = t_fcat1

IT_SORT = t_subtot1

  • I_SAVE = ' '

  • IT_ADD_FIELDCAT =

TABLES

T_OUTTAB = itab_final

  • 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. " display1

FORM USER_COMMAND1 USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

data : &IC1 like ok_code.

&IC1 = ok_code.

CASE R_UCOMM.

WHEN '&IC1'.

refresh t_fcat2.

refresh t_subtot2.

IF RS_SELFIELD-FIELDNAME = 'KSTAR'.

perform secondary_list2.

endif.

*WHEN 'BACK'.

*leave to screen 0.

*

ENDCASE.

ENDFORM.

&----


*& Form build_sort1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_sort1 .

subtot-spos = 1.

subtot-fieldname = 'KSTAR'.

subtot-subtot = 'X'.

subtot-down = 'X'.

subtot-expa = 'X'.

append subtot to t_subtot1.

ENDFORM. " build_sort1

&----


*& Form build_cat2

&----


  • text

----


  • -->P_T_FCAT1 text

----


FORM build_cat2 USING temp_fcat type slis_t_fieldcat_alv .

d_fieldcat_wa-fieldname = 'PRCTR'.

d_fieldcat_wa-seltext_m = 'ProfitCenter'.

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 = 'KHINR'.

d_fieldcat_wa-seltext_m = 'ProfitCenterGroup'.

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 = 'WOGBTR'.

d_fieldcat_wa-seltext_m = 'AMount'.

d_fieldcat_wa-key = 'X'.

d_fieldcat_wa-do_sum = 'X'.

d_fieldcat_wa-col_pos = 2.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'PERIO'.

d_fieldcat_wa-seltext_m = 'Period'.

d_fieldcat_wa-col_pos = 3.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'GJAHRL'.

d_fieldcat_wa-seltext_m = 'Year from'.

d_fieldcat_wa-col_pos = 4.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'GJAHRH'.

d_fieldcat_wa-seltext_m = 'YearTo'.

d_fieldcat_wa-col_pos = 5.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

ENDFORM. " build_cat2

&----


*& Form secondary_list2

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM secondary_list2 .

perform get_data1.

perform sel.

PERFORM build_cat2 USING t_fcat2.

perform build_sort3.

  • PERFORM build_eve.

*

PERFORM build_layout.

PERFORM display2.

ENDFORM. " secondary_list2

&----


*& Form build_sort3

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_sort3 .

subtot-spos = 1.

subtot-fieldname = 'PRCTR'.

subtot-subtot = 'X'.

subtot-down = 'X'.

subtot-expa = 'X'.

append subtot to t_subtot2.

ENDFORM. " build_sort2

&----


*& Form display2

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display2 .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = gd_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

I_CALLBACK_USER_COMMAND = 'USER_COMMAND2'

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 = 'Profit Center Details'

IS_LAYOUT = gd_layout

IT_FIELDCAT = t_fcat2

IT_SORT = t_subtot2

  • IT_EVENTS =

  • IT_ADD_FIELDCAT =

TABLES

T_OUTTAB = itab_final

  • 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. " display2

&----


*& Form User_Command

&----


  • text

----


FORM USER_COMMAND2 USING R_UCOMM LIKE SY-UCOMM

RS_SELFIELD TYPE SLIS_SELFIELD.

data : &IC1 like ok_code.

&IC1 = ok_code.

CASE R_UCOMM.

WHEN '&IC1'.

refresh t_fcat3.

refresh t_subtot3.

IF RS_SELFIELD-FIELDNAME = 'PRCTR'.

perform secondary_list3.

endif.

*WHEN 'BACK'.

*leave to screen 0.

*

ENDCASE.

ENDFORM.

&----


*& Form secondary_list3

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM secondary_list3 .

clear itab_final[].

perform get_data1.

perform sel.

PERFORM build_cat3 USING t_fcat3.

perform build_sort4.

PERFORM build_layout.

PERFORM display3.

ENDFORM. " secondary_list3

&----


*& Form build_cat3

&----


  • text

----


  • -->P_T_FCAT3 text

----


FORM build_cat3 USING temp_fcat type slis_t_fieldcat_alv.

d_fieldcat_wa-fieldname = 'AUFNR'.

d_fieldcat_wa-seltext_m = 'OrderNumber'.

  • 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 = 'AUART'.

d_fieldcat_wa-seltext_m = 'OrderType'.

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 = 'WOGBTR'.

d_fieldcat_wa-seltext_m = 'AMount'.

d_fieldcat_wa-key = 'X'.

d_fieldcat_wa-do_sum = 'X'.

d_fieldcat_wa-col_pos = 2.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'PERIO'.

d_fieldcat_wa-seltext_m = 'Period'.

d_fieldcat_wa-col_pos = 3.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'GJAHRL'.

d_fieldcat_wa-seltext_m = 'Year from'.

d_fieldcat_wa-col_pos = 4.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

d_fieldcat_wa-fieldname = 'GJAHRH'.

d_fieldcat_wa-seltext_m = 'YearTo'.

d_fieldcat_wa-col_pos = 5.

APPEND d_fieldcat_wa TO temp_fcat.

CLEAR d_fieldcat_wa.

ENDFORM. " build_cat3

&----


*& Form build_sort4

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM build_sort4 .

subtot-spos = 1.

subtot-fieldname = 'AUFNR'.

subtot-subtot = 'X'.

subtot-up = 'X'.

subtot-expa = 'X'.

append subtot to t_subtot3.

ENDFORM. " build_sort4

&----


*& Form display3

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM display3 .

CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'

EXPORTING

I_CALLBACK_PROGRAM = gd_repid

  • I_CALLBACK_PF_STATUS_SET = ' '

  • I_CALLBACK_USER_COMMAND = ' '

I_CALLBACK_TOP_OF_PAGE = 'TOP_OF_PAGE'

I_GRID_TITLE = 'Details of Internal Order'

  • I_GRID_SETTINGS =

IS_LAYOUT = gd_layout

IT_FIELDCAT = t_fcat3

IT_SORT = t_subtot3

  • IT_EVENTS =

  • IT_ADD_FIELDCAT =

TABLES

T_OUTTAB = itab_final

  • 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. " display3

&----


*& Form Top_of_page

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


form top_of_page.

data : uline like sy-uline.

data : wa_header1 type slis_listheader.

uline = sy-uline.

wa_header-typ = 'S'.

wa_header-info = 'Inputs'.

append wa_header to t_header.

clear wa_header.

wa_header-typ = 'S'.

wa_header-info = uline.

append wa_header to t_header.

clear wa_header.

wa_header-typ = 'S'.

wa_header-key = 'Controlling Area:'.

wa_header-info = itab_final-ca.

append wa_header to t_header.

clear wa_header.

wa_header-typ = 'S'.

wa_header-key = ' Year '.

concatenate itab_final-gjahrl 'to' itab_final-gjahrh

into wa_header-info separated by space.

append wa_header to t_header.

clear wa_header.

wa_header-typ = 'S'.

wa_header-key = 'Company Code '.

concatenate itab_final-ccl 'to' itab_final-cch

into wa_header-info separated by space.

append wa_header to t_header.

clear wa_header.

wa_header-typ = 'S'.

wa_header-key = ' Profit Center Group '.

concatenate itab_final-pgl 'to' itab_final-pgh

into wa_header-info separated by space.

append wa_header to t_header.

clear wa_header.

wa_header-typ = 'S'.

wa_header-key = 'Profit Center '.

concatenate itab_final-pcl 'to' itab_final-pch

into wa_header-info separated by space.

append wa_header to t_header.

clear wa_header.

wa_header-typ = 'S'.

wa_header-key = 'Cost Element Group '.

concatenate itab_final-kul 'to' itab_final-kuh

into wa_header-info separated by space.

append wa_header to t_header.

clear wa_header.

wa_header-typ = 'S'.

wa_header-key = ' Internal Order '.

concatenate itab_final-orl 'to' itab_final-orh

into wa_header-info separated by space.

append wa_header to t_header.

clear wa_header.

wa_header-typ = 'S'.

wa_header-info = uline.

append wa_header to t_header.

clear wa_header.

wa_header1-key = 'TillPeriod '.

concatenate itab_final-periol 'To'

itab_final-perioh into wa_header1-info separated by space.

wa_header-typ = 'S'.

concatenate 'From Period ' itab_final-periol

space wa_header1 into wa_header-info separated by space.

append wa_header to t_header.

clear wa_header.

CALL FUNCTION 'REUSE_ALV_COMMENTARY_WRITE'

EXPORTING

IT_LIST_COMMENTARY = t_header

I_LOGO = 'ZVMLOGO'

  • I_END_OF_LIST_GRID =

  • I_ALV_FORM =

.

refresh t_header.

endform. "top_of_page

&----


*& Form sel1

&----


  • text

----


  • --> p1 text

  • <-- p2 text

----


FORM sel1 .

loop at itab1.

itab1-gjahrl = itab_final-gjahrl.

itab1-gjahrh = itab_final-gjahrh.

itab1-bukrs = itab_final-bukrs.

modify itab1 transporting gjahrl gjahrh bukrs.

endloop.

ENDFORM. " sel1