06-24-2013 9:21 AM
Hi Experts,
I want to retrive the data from transparent internal table according to one month gap with exact perticular dates and also show the total in both side right and below as shown below. Please help !
The user will be entering selection option dates and need to show the result acording to perticular dates .
05.05.12 | 05.06.12 | 05.07.12 | Total | |
---|---|---|---|---|
type 1 | 10 | 10 | 10 | 30 |
type 2 | 10 | 10 | 10 | 30 |
total | 20 | 20 | 20 | 60 |
06-24-2013 9:48 AM
Hi,
I would create an internal table dynamically for this and display it with an ALV.
https://scn.sap.com/thread/1386767
I think you can use sum feature of ALV for the Total row line but would have to fill the Total column by yourself.
Best regards,
Guillaume
06-24-2013 9:57 AM
06-24-2013 10:58 AM
Hi,
There was a similar discussion :
https://scn.sap.com/message/14095008#14095008
I add to the program the horizontal sum .
Output:
06-25-2013 11:02 AM
Refer this code u can do it by creating dynamic table
*&---------------------------------------------------------------------*
*& Report ZZ_FI_ACTUAL_BUDGETED_COST
*&
*&---------------------------------------------------------------------*
*& 02.05.2012 Report to display actual and budgeted values of cost
*& centres accordingly to their groups.
*&---------------------------------------------------------------------*
report zz_fi_actual_budgeted_cost.
*&---------------------------------------------------------------------*
*& TABLES
*&---------------------------------------------------------------------*
tables: coep, " CO Object: Line Items (by Period)
setnode, " Lower-level sets in sets
setleaf, " Values in Sets
csks.
*&---------------------------------------------------------------------*
*& INTERNAL TABLES
*&---------------------------------------------------------------------*
data: begin of it_output occurs 10,
kstar type coep-kstar, " Cost Element
ktext type csku-ktext, " Cost Element Texts
bugt type coep-wkgbtr, " Bugeted Value
actl type coep-wkgbtr, " Actual Value
to_bud type coep-wkgbtr, " Total Bugeted Value
to_act type coep-wkgbtr, " TotalActual Value
amount type coep-wkgbtr, " Total Variance Amt
perct(15) type c, " Percentage
setname type setnode-setname, " Cost Center Group
objnr type coep-objnr,
selkz(1),
end of it_output.
* CO Object: Line Items
data: begin of it_coep occurs 10,
kokrs like coep-kokrs,
kstar like coep-kstar,
end of it_coep.
* Cost Elements (Data Dependent on Controlling Area)
data: begin of it_cskb occurs 10,
kokrs like cskb-kokrs,
kstar like cskb-kstar,
end of it_cskb.
* Lower-level sets in sets
data: begin of it_setnode occurs 10.
include structure setnode.
data: end of it_setnode.
* Values in Sets
data: begin of it_setleaf occurs 10.
include structure setleaf.
data: end of it_setleaf.
* Cost Element Texts
data: begin of it_csku occurs 10.
include structure csku.
data: end of it_csku.
* CO Object: Cost Totals for External Postings
data: begin of it_cosp occurs 10.
include structure cosp.
data: end of it_cosp.
* CO Object: Cost Totals for External Postings
data: begin of it_cosp1 occurs 10.
include structure cosp.
data: end of it_cosp1.
data: begin of it_final_alv occurs 10,
kstar like coep-kstar, " Cost Element
kostl like csks-kostl, " Cost Center
ktext like cskt-ktext, " Cost Center Text
actul like coep-wkgbtr, " Actual Cost
plan like cosp-wtg001, " Budeged Cost
end of it_final_alv.
data: begin of it_cskt occurs 10,
kostl like cskt-kostl,
ktext like cskt-kostl,
end of it_cskt.
*&---------------------------------------------------------------------*
*& Declarations
*&---------------------------------------------------------------------*
data: wa_setnode like line of it_setnode.
data: wa_setleaf like line of it_setleaf.
data: gt_fcat type lvc_t_fcat.
data: ls_fcat like line of gt_fcat.
data: wa_string(40) type c.
data: wa_string1(40) type c.
data: wa_name(20) type c.
data: wa_name1(20) type c.
data: wa_index type string.
*----------------------------------------------------------------------*
* ALV Variables
*----------------------------------------------------------------------*
data: lt_tab_type type ref to data,
ls_tab_type type ref to data.
data: gd_name type string.
data: wa_lang type langu,
gd_itab(30),
gd_pf_status(30).
*----------------------------------------------------------------------*
* Field Symbols
*----------------------------------------------------------------------*
field-symbols: <f_wa> type any.
field-symbols: <dyn_wa> type any,
<fs_value> type any.
field-symbols <gd_field> type any.
field-symbols <gd_field1> type any.
field-symbols <gd_selkz> type any.
field-symbols: <fs_table> type standard table.
*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*
selection-screen begin of block b1 with frame title text-001.
parameters: p_kokrs like coep-kokrs default '0100' ,
p_gjahr like coep-gjahr default '2012',
p_per1 like coep-perio default '1',
p_per2 like coep-perio default '12',
p_versn like coep-versn default '0'.
selection-screen end of block b1.
selection-screen begin of block b2 with frame title text-002.
parameters: p_ksgru like rksb1-ksgru.
select-options: s_kostl for csks-kostl.
parameters: p_kagru like rksb1-kagru.
select-options: s_kstar for coep-kstar.
selection-screen end of block b2.
*----------------------------------------------------------------------*
* ALV GRID Variables
*----------------------------------------------------------------------*
type-pools: slis.
data: gd_title type lvc_title,
gd_fieldcat type slis_t_fieldcat_alv,
gd_fieldcat1 type slis_t_fieldcat_alv,
gd_fieldcat2 type slis_t_fieldcat_alv,
wa_fieldcat type slis_fieldcat_alv,
wa_fieldcat1 type slis_fieldcat_alv,
wa_fieldcat2 type slis_fieldcat_alv,
gd_layout type slis_layout_alv,
gd_layout1 type slis_layout_alv,
gd_layout2 type slis_layout_alv,
gd_sort type slis_t_sortinfo_alv,
wa_sort like line of gd_sort,
gd_events type slis_t_event,
gd_extab type slis_t_extab with header line,
gd_event_exit type slis_t_event_exit with header line,
wa_event type slis_alv_event,
wa_event_exit type slis_t_event_exit,
gd_save(1),
gd_repid like sy-repid,
gd_dynnr like sy-dynnr,
gd_param1 like sy-ucomm,
gd_top type slis_t_listheader,
gd_user_command type slis_formname,
wa_top type slis_listheader.
*&---------------------------------------------------------------------*
*& START-OF-SELECTION.
*&---------------------------------------------------------------------*
start-of-selection.
gd_repid = sy-repid.
gd_itab = '<fs_table>'.
gd_user_command = 'USER_COMMAND'.
gd_title = text-t01.
gd_save = 'A'.
perform fetch_data.
perform build_fieldcat.
perform fill_details.
perform assign_data.
perform display_alv.
*&---------------------------------------------------------------------*
*& Form FETCH_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form fetch_data .
* Select Cost Elements
select kokrs
kstar from coep
into table it_coep
where kokrs eq p_kokrs
and perio between p_per1 and p_per2
and versn eq p_versn.
* Select Other Cost Elements
select kokrs
kstar from cskb
into table it_cskb
for all entries in it_coep
where kokrs eq p_kokrs
and kstar ne it_coep-kstar.
loop at it_cskb .
read table it_coep with key kokrs = it_cskb-kokrs.
if sy-subrc eq 0.
move-corresponding it_cskb to it_coep.
append it_coep. " IF sy-subrc EQ 0.
endif.
endloop. " LOOP AT it_cskb .
sort it_coep ascending by kstar.
delete adjacent duplicates from it_coep.
if it_coep[] is not initial.
* Select Cost Element Texts
select * from csku
into table it_csku
for all entries in it_coep
where kstar eq it_coep-kstar
and spras eq 'EN'.
* Select Cost Totals for External Postings
select * from cosp
into table it_cosp1
for all entries in it_coep
where kstar eq it_coep-kstar
and gjahr eq p_gjahr.
endif. " IF it_coep[] IS NOT INITIAL.
if p_ksgru is not initial.
* Select Cost Center Groups
select * from setnode
into table it_setnode
where setname eq p_ksgru
and setclass eq '0101'.
else.
* Select Cost Center Groups
select * from setnode
into table it_setnode .
endif. " IF p_ksgru IS NOT INITIAL.
if it_setnode[] is not initial.
* Select Cost Centers for Cst Center Groups
select * from setleaf
into table it_setleaf
for all entries in it_setnode
where subclass eq it_setnode-subclass
and setname eq it_setnode-subsetname
and valfrom in s_kostl.
else.
* Select Cost Centers for Cst Center Groups
select * from setleaf
into table it_setleaf
where ( setname eq p_ksgru and setclass eq '0101'
or setname eq p_kagru and setclass eq '0102')
and valfrom in s_kostl.
endif. " IF it_setnode[] IS NOT INITIAL.
* Select Cost Center Texts
select kostl
ktext from cskt
into table it_cskt
where kokrs eq p_kokrs.
endform. " FETCH_DATA
*&---------------------------------------------------------------------*
*& Form BUILD_FIELDCAT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form build_fieldcat .
ls_fcat-fieldname = 'KSTAR'.
ls_fcat-scrtext_l = 'GL Code'.
ls_fcat-outputlen = 10.
append ls_fcat to gt_fcat.
clear: ls_fcat.
ls_fcat-fieldname = 'KTEXT'.
ls_fcat-scrtext_l = 'GL Description'.
ls_fcat-outputlen = 20.
ls_fcat-tabname = 'CSKU'.
append ls_fcat to gt_fcat.
clear: ls_fcat.
clear wa_index.
wa_index = 1.
if it_setnode[] is not initial.
loop at it_setnode into wa_setnode.
concatenate 'BUGT' wa_index into wa_name .
translate wa_setnode-subsetname+1 to lower case .
concatenate wa_setnode-subsetname 'Budegeted' into wa_string
separated by space.
ls_fcat-fieldname = wa_name.
ls_fcat-scrtext_l = wa_string.
ls_fcat-outputlen = 15.
append ls_fcat to gt_fcat.
clear: ls_fcat.
concatenate 'ACTL' wa_index into wa_name1 .
translate wa_setnode-subsetname+1 to lower case .
concatenate wa_setnode-subsetname 'Actual' into wa_string1
separated by space.
ls_fcat-fieldname = wa_name1.
ls_fcat-scrtext_l = wa_string1.
ls_fcat-outputlen = 15.
append ls_fcat to gt_fcat.
clear: ls_fcat.
wa_index = wa_index + 1.
endloop. " LOOP AT it_setnode INTO wa_setnode
else.
loop at it_setleaf into wa_setleaf.
on change of wa_setleaf-setname.
concatenate 'BUGT' wa_index into wa_name .
translate wa_setleaf-setname+1 to lower case .
concatenate wa_setleaf-setname 'Budegeted' into wa_string
separated by space.
ls_fcat-fieldname = wa_name.
ls_fcat-scrtext_l = wa_string.
ls_fcat-outputlen = 15.
append ls_fcat to gt_fcat.
clear: ls_fcat.
concatenate 'ACTL' wa_index into wa_name1 .
translate wa_setleaf-setname+1 to lower case .
concatenate wa_setleaf-setname 'Actual' into wa_string1
separated by space.
ls_fcat-fieldname = wa_name1.
ls_fcat-scrtext_l = wa_string1.
ls_fcat-outputlen = 15.
append ls_fcat to gt_fcat.
clear: ls_fcat.
wa_index = wa_index + 1.
endon. " ON CHANGE OF wa_setleaf-setname.
endloop. " LOOP AT it_setleaf INTO wa_setleaf.
endif. " IF it_setnode[] IS NOT INITIAL.
ls_fcat-fieldname = 'TO_BUT'.
ls_fcat-scrtext_l = 'Total Budgeted'.
ls_fcat-outputlen = 15.
append ls_fcat to gt_fcat.
clear: ls_fcat.
ls_fcat-fieldname = 'TO_ACT'.
ls_fcat-scrtext_l = 'Total Actual'.
ls_fcat-outputlen = 15.
append ls_fcat to gt_fcat.
clear: ls_fcat.
ls_fcat-fieldname = 'AMOUNT'.
ls_fcat-scrtext_l = 'Variance Amount'.
ls_fcat-outputlen = 15.
append ls_fcat to gt_fcat.
clear: ls_fcat.
ls_fcat-fieldname = 'PERCT'.
ls_fcat-scrtext_l = 'Variance %'.
ls_fcat-outputlen = 15.
append ls_fcat to gt_fcat.
clear: ls_fcat.
ls_fcat-fieldname = 'SELKZ'.
ls_fcat-no_out = 'X'.
append ls_fcat to gt_fcat.
clear: ls_fcat.
* Build Fieldcatalog for Internal Table
loop at gt_fcat into ls_fcat.
if ls_fcat-fieldname = 'SELKZ'.
wa_fieldcat-no_out = 'X'.
elseif ls_fcat-fieldname = 'KSTAR'.
wa_fieldcat-fieldname = ls_fcat-fieldname .
wa_fieldcat-seltext_l = ls_fcat-scrtext_l.
wa_fieldcat-ddictxt = 'L'.
elseif ls_fcat-fieldname = 'KTEXT'.
wa_fieldcat-fieldname = ls_fcat-fieldname .
wa_fieldcat-seltext_l = ls_fcat-scrtext_l.
wa_fieldcat-ddictxt = 'L'.
elseif ls_fcat-fieldname = 'TO_BUT'.
wa_fieldcat-fieldname = ls_fcat-fieldname .
wa_fieldcat-seltext_l = ls_fcat-scrtext_l.
wa_fieldcat-ddictxt = 'L'.
elseif ls_fcat-fieldname = 'TO_ACT'.
wa_fieldcat-fieldname = ls_fcat-fieldname .
wa_fieldcat-seltext_l = ls_fcat-scrtext_l.
wa_fieldcat-ddictxt = 'L'.
elseif ls_fcat-fieldname = 'AMOUNT'.
wa_fieldcat-fieldname = ls_fcat-fieldname .
wa_fieldcat-seltext_l = ls_fcat-scrtext_l.
wa_fieldcat-ddictxt = 'L'.
elseif ls_fcat-fieldname = 'PERCT'.
wa_fieldcat-fieldname = ls_fcat-fieldname .
wa_fieldcat-seltext_l = ls_fcat-scrtext_l.
wa_fieldcat-ddictxt = 'L'.
elseif ls_fcat-fieldname = 'SETNAME'.
wa_fieldcat-fieldname = ls_fcat-fieldname .
wa_fieldcat-seltext_l = ls_fcat-scrtext_l.
wa_fieldcat-ddictxt = 'L'.
else.
wa_fieldcat-fieldname = ls_fcat-fieldname .
wa_fieldcat-seltext_l = ls_fcat-scrtext_l.
wa_fieldcat-ddictxt = 'L'.
wa_fieldcat-hotspot = 'X'.
endif. " IF ls_fcat-fieldname = 'SELKZ'.
append wa_fieldcat to gd_fieldcat.
clear: wa_fieldcat.
endloop. " LOOP AT gt_fcat INTO ls_fcat.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = gt_fcat
importing
ep_table = lt_tab_type.
assign lt_tab_type->* to <fs_table>.
create data ls_tab_type like line of <fs_table>.
assign ls_tab_type->* to <f_wa>.
endform. " BUILD_FIELDCAT
*&---------------------------------------------------------------------*
*& Form FILL_DETAILS
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form fill_details .
clear: it_output,
it_output[].
data: val type coep-wkgbtr.
data: val1 type coep-wkgbtr.
delete it_cosp1 where objnr+0(2) ne 'KS'.
*
* LOOP AT it_cosp.
* MOVE-CORRESPONDING it_cosp TO it_cosp1.
* APPEND it_cosp1.
* ENDLOOP. " LOOP AT it_cosp.
loop at it_coep.
clear: val,val1.
it_output-kstar = it_coep-kstar.
read table it_csku with key kstar = it_coep-kstar.
if sy-subrc eq 0.
it_output-ktext = it_csku-ktext.
endif. " IF sy-subrc EQ 0.
loop at it_cosp1 where kstar eq it_coep-kstar.
read table it_setleaf with key valfrom = it_cosp1-objnr+6(10).
if sy-subrc eq 0.
if it_cosp1-wrttp eq '04' .
it_output-actl = ( it_cosp1-wkg001 +
it_cosp1-wkg002 +
it_cosp1-wkg003 +
it_cosp1-wkg004 +
it_cosp1-wkg005 +
it_cosp1-wkg006 +
it_cosp1-wkg007 +
it_cosp1-wkg008 +
it_cosp1-wkg009 +
it_cosp1-wkg010 +
it_cosp1-wkg011 +
it_cosp1-wkg012 +
it_cosp1-wkg013 +
it_cosp1-wkg014 +
it_cosp1-wkg015 +
it_cosp1-wkg016 ).
it_output-setname = it_setleaf-setname.
elseif it_cosp1-wrttp eq '01' .
it_output-bugt = ( it_cosp1-wtg001 +
it_cosp1-wtg002 +
it_cosp1-wtg003 +
it_cosp1-wtg004 +
it_cosp1-wtg005 +
it_cosp1-wtg006 +
it_cosp1-wtg007 +
it_cosp1-wtg008 +
it_cosp1-wtg009 +
it_cosp1-wtg010 +
it_cosp1-wtg011 +
it_cosp1-wtg012 ) .
it_output-setname = it_setleaf-setname.
endif. " IF it_cosp1-wrttp EQ '04' .
endif. " IF sy-subrc EQ 0.
collect it_output.
clear: it_output-bugt, it_output-actl.
endloop. " LOOP AT it_cosp1 WHERE kstar EQ it_coep-kstar.
clear it_output.
endloop. " LOOP AT it_coep.
delete it_output where bugt is initial
and actl is initial.
loop at it_coep.
read table it_output with key kstar = it_coep-kstar.
if sy-subrc ne 0.
delete it_coep.
endif. " IF sy-subrc NE 0.
endloop. " LOOP AT it_coep.
endform. " FILL_DETAILS
*&---------------------------------------------------------------------*
*& Form ASSIGN_DATA
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form assign_data .
data: ld_field type string,
ld_value type coep-wkgbtr,
ld_value1 type coep-wkgbtr,
ld_to_val type coep-wkgbtr,
ld_to_val1 type coep-wkgbtr,
ld_total type coep-wkgbtr,
ld_percent(10) type c.
clear: it_coep.
loop at it_coep.
clear: <f_wa>,
ld_value,
ld_value1,
ld_total,
ld_percent,
ld_to_val1,
ld_to_val.
loop at gd_fieldcat into wa_fieldcat.
concatenate '<f_wa>-' wa_fieldcat-fieldname into ld_field.
assign (ld_field) to <gd_field>.
if wa_fieldcat-fieldname eq 'SELKZ'.
elseif wa_fieldcat-fieldname eq 'KSTAR'.
<gd_field> = it_coep-kstar.
elseif wa_fieldcat-fieldname eq 'KTEXT'.
read table it_csku with key kstar = it_coep-kstar.
if sy-subrc eq 0.
<gd_field> = it_csku-ktext.
endif.
elseif wa_fieldcat-fieldname+0(4) eq 'BUGT'.
clear: ld_value.
loop at it_output where kstar eq it_coep-kstar.
translate it_output-setname+1 to lower case.
if wa_fieldcat-seltext_l+0(3) eq it_output-setname+0(3)
and wa_fieldcat-fieldname+0(4) eq 'BUGT'.
ld_value = it_output-bugt + ld_value.
endif.
endloop.
if ld_value is not initial.
<gd_field> = ld_value.
ld_to_val = ld_value + ld_to_val.
endif.
elseif wa_fieldcat-fieldname+0(4) eq 'ACTL'.
clear: ld_value1.
loop at it_output where kstar eq it_coep-kstar.
translate it_output-setname+1 to lower case.
if wa_fieldcat-seltext_l+0(3) eq it_output-setname+0(3)
and wa_fieldcat-fieldname+0(4) eq 'ACTL'.
ld_value1 = it_output-actl + ld_value1.
endif. " IF wa_fieldcat-seltext_l+0(3)
endloop. " LOOP AT it_output WHERE kstar EQ it_coep-kstar.
if ld_value1 is not initial.
<gd_field> = ld_value1.
ld_to_val1 = ld_value1 + ld_to_val1.
endif. " IF ld_value1 IS NOT INITIAL.
elseif wa_fieldcat-fieldname eq 'TO_BUT'.
<gd_field> = ld_to_val.
elseif wa_fieldcat-fieldname eq 'TO_ACT'.
<gd_field> = ld_to_val1.
elseif wa_fieldcat-fieldname eq 'AMOUNT'.
ld_total = ld_to_val1 - ld_to_val .
<gd_field> = ld_total.
elseif wa_fieldcat-fieldname eq 'PERCT'.
if ld_total is not initial and ld_to_val is not initial.
ld_percent = ( ld_total / ld_to_val ) * 100.
<gd_field> = ld_percent.
endif. "IF ld_total IS NOT INITIAL AND ld_to_val IS NOT INITIAL.
endif. " IF wa_fieldcat-fieldname EQ 'SELKZ'.
endloop. " LOOP AT gd_fieldcat INTO wa_fieldcat.
append <f_wa> to <fs_table>.
endloop. " LOOP AT it_coep.
endform. " ASSIGN_DATA
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_alv .
perform manipulate_layout.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
* I_INTERFACE_CHECK = ' '
i_bypassing_buffer = 'X'
* I_BUFFER_ACTIVE = ' '
i_callback_program = gd_repid
* I_CALLBACK_PF_STATUS_SET =
i_callback_user_command = gd_user_command
* I_CALLBACK_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_TOP_OF_PAGE = ' '
* I_CALLBACK_HTML_END_OF_LIST = ' '
* I_STRUCTURE_NAME =
* I_BACKGROUND_ID = ' '
i_grid_title = gd_title
* I_GRID_SETTINGS =
is_layout = gd_layout
it_fieldcat = gd_fieldcat
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
i_save = gd_save
* IS_VARIANT =
* IT_EVENTS =
* 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 = <fs_table>
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_ALV
*&---------------------------------------------------------------------*
*& Form MANIPULATE_LAYOUT
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form manipulate_layout .
gd_layout-zebra = 'X'.
gd_layout-colwidth_optimize = 'X'.
gd_layout-box_fieldname = 'SELKZ'.
gd_layout-box_tabname = 'IT_OUTPUT'.
endform. " MANIPULATE_LAYOUT
*&---------------------------------------------------------------------*
*& Form USER_COMMAND
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* -->PARAM1 text
* -->PARAM2 text
*----------------------------------------------------------------------*
form user_command using param1 type sy-ucomm
param2 type slis_selfield.
case param1.
when '&IC1'. "Hotspot
check: param2-value is not initial.
case param2-fieldname+0(4).
clear: it_final_alv[],
it_final_alv.
when 'BUGT'.
read table <fs_table> into <f_wa> index param2-tabindex.
if sy-subrc eq 0.
assign ('<f_wa>-BUGT') to <gd_field>.
assign ('<f_wa>-KSTAR') to <gd_field1>.
loop at it_cosp1 where kstar eq <gd_field1>
and wrttp eq '01'.
read table it_setleaf with key valfrom =
it_cosp1-objnr+6(10).
if sy-subrc eq 0.
it_final_alv-kstar = it_cosp1-kstar.
it_final_alv-kostl = it_cosp1-objnr+6(10).
it_final_alv-plan = ( it_cosp1-wtg001 +
it_cosp1-wtg002 +
it_cosp1-wtg003 +
it_cosp1-wtg004 +
it_cosp1-wtg005 +
it_cosp1-wtg006 +
it_cosp1-wtg007 +
it_cosp1-wtg008 +
it_cosp1-wtg009 +
it_cosp1-wtg010 +
it_cosp1-wtg011 +
it_cosp1-wtg012 ).
read table it_cskt with key kostl = it_final_alv-kostl.
if sy-subrc eq 0.
it_final_alv-ktext = it_cskt-ktext.
endif. " IF sy-subrc EQ 0.
collect it_final_alv.
clear it_final_alv.
endif. " IF sy-subrc EQ 0.
endloop. " LOOP AT it_cosp1 WHERE kstar EQ <gd_field1>
endif. " IF sy-subrc EQ 0.
perform display_alv2.
when 'ACTL'.
read table <fs_table> into <f_wa> index param2-tabindex.
if sy-subrc eq 0.
assign ('<f_wa>-ACTL') to <gd_field>.
assign ('<f_wa>-KSTAR') to <gd_field1>.
loop at it_cosp1 where kstar eq <gd_field1>
and wrttp eq '04'..
read table it_setleaf with key valfrom =
it_cosp1-objnr+6(10).
if sy-subrc eq 0.
it_final_alv-kstar = it_cosp1-kstar.
it_final_alv-kostl = it_cosp1-objnr+6(10).
it_final_alv-actul = ( it_cosp1-wkg001 +
it_cosp1-wkg002 +
it_cosp1-wkg003 +
it_cosp1-wkg004 +
it_cosp1-wkg005 +
it_cosp1-wkg006 +
it_cosp1-wkg007 +
it_cosp1-wkg008 +
it_cosp1-wkg009 +
it_cosp1-wkg010 +
it_cosp1-wkg011 +
it_cosp1-wkg012 +
it_cosp1-wkg013 +
it_cosp1-wkg014 +
it_cosp1-wkg015 +
it_cosp1-wkg016 ).
read table it_cskt with key kostl = it_final_alv-kostl.
if sy-subrc eq 0.
it_final_alv-ktext = it_cskt-ktext.
endif. " IF sy-subrc EQ 0.
collect it_final_alv.
clear it_final_alv.
endif. " IF sy-subrc EQ 0.
endloop. " LOOP AT it_cosp1 WHERE kstar EQ <gd_field1>
endif. " IF sy-subrc EQ 0.
perform display_alv3.
endcase. " CASE param2-fieldname+0(4).
endcase.
endform. "user_command
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_alv2 .
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = gd_repid
i_internal_tabname = 'IT_FINAL_ALV'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = gd_repid
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
changing
ct_fieldcat = gd_fieldcat1
* EXCEPTIONS
* INCONSISTENT_INTERFACE = 1
* PROGRAM_ERROR = 2
* OTHERS = 3
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
perform manipulate_fieldcatalog.
perform manipulate_layout1.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
* i_callback_pf_status_set = 'PF_STATUS '
* i_callback_user_command = 'USER_COMMAND '
i_grid_title = 'Cost Center Details'
is_layout = gd_layout1
it_fieldcat = gd_fieldcat1
tables
t_outtab = it_final_alv
.
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_ALV2
*&---------------------------------------------------------------------*
*& Form MANIPULATE_FIELDCATALOG
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form manipulate_fieldcatalog .
loop at gd_fieldcat1 into wa_fieldcat1.
case wa_fieldcat1-fieldname.
when 'KSTAR'.
wa_fieldcat1-seltext_l = text-003. " Machine No.
wa_fieldcat1-ddictxt = 'L'.
when 'KOSTL'.
wa_fieldcat1-seltext_l = text-004. " Machine No.
wa_fieldcat1-ddictxt = 'L'.
when 'KTEXT'.
wa_fieldcat1-seltext_l = text-005. " Machine No.
wa_fieldcat1-ddictxt = 'L'.
when 'ACTUL'.
wa_fieldcat2-no_out = 'X'.
when 'PLAN'.
wa_fieldcat1-seltext_l = text-007. " Machine No.
wa_fieldcat1-ddictxt = 'L'.
wa_fieldcat1-do_sum = 'X'.
endcase.
modify gd_fieldcat1 from wa_fieldcat1.
endloop.
endform. " MANIPULATE_FIELDCATALOG
*&---------------------------------------------------------------------*
*& Form MANIPULATE_LAYOUT1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form manipulate_layout1 .
gd_layout1-box_tabname = 'IT_FINAL_ALV'.
gd_layout1-colwidth_optimize = 'X'.
endform. " MANIPULATE_LAYOUT1
*&---------------------------------------------------------------------*
*& Form DISPLAY_ALV3
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form display_alv3 .
call function 'REUSE_ALV_FIELDCATALOG_MERGE'
exporting
i_program_name = gd_repid
i_internal_tabname = 'IT_FINAL_ALV'
* I_STRUCTURE_NAME =
* I_CLIENT_NEVER_DISPLAY = 'X'
i_inclname = gd_repid
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE =
changing
ct_fieldcat = gd_fieldcat2
* EXCEPTIONS
* INCONSISTENT_INTERFACE = 1
* PROGRAM_ERROR = 2
* OTHERS = 3
.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
perform manipulate_fieldcatalog1.
perform manipulate_layout2.
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
i_callback_program = gd_repid
* i_callback_pf_status_set = 'PF_STATUS '
* i_callback_user_command = 'USER_COMMAND '
i_grid_title = 'Cost Center Details'
is_layout = gd_layout2
it_fieldcat = gd_fieldcat2
tables
t_outtab = it_final_alv
.
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_ALV3
*&---------------------------------------------------------------------*
*& Form MANIPULATE_FIELDCATALOG1
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form manipulate_fieldcatalog1 .
loop at gd_fieldcat2 into wa_fieldcat2.
case wa_fieldcat2-fieldname.
when 'KSTAR'.
wa_fieldcat2-seltext_l = text-003. " Machine No.
wa_fieldcat2-ddictxt = 'L'.
when 'KOSTL'.
wa_fieldcat2-seltext_l = text-004. " Machine No.
wa_fieldcat2-ddictxt = 'L'.
when 'KTEXT'.
wa_fieldcat2-seltext_l = text-005. " Machine No.
wa_fieldcat2-ddictxt = 'L'.
when 'ACTUL'.
wa_fieldcat2-seltext_l = text-006. " Machine No.
wa_fieldcat2-ddictxt = 'L'.
wa_fieldcat2-do_sum = 'X'.
when 'PLAN'.
wa_fieldcat2-seltext_l = text-007. " Machine No.
wa_fieldcat2-no_out = 'X'.
endcase.
modify gd_fieldcat2 from wa_fieldcat2.
endloop.
endform. " MANIPULATE_FIELDCATALOG1
*&---------------------------------------------------------------------*
*& Form MANIPULATE_LAYOUT2
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form manipulate_layout2 .
gd_layout2-box_tabname = 'IT_FINAL_ALV'.
gd_layout2-colwidth_optimize = 'X'.
endform. " MANIPULATE_LAYOUT2
06-26-2013 7:34 AM