Você está na página 1de 9

from: simon li [sbli@yahoo.

com]
sent: tuesday, november 12, 2002 7:42 pm
to: abap@yahoogroups.com
subject: re: [abap] alv list
thanks for the response.

here is the whole thing below, also i debugged the


code and saw a lot of records in it_summary table, my
other alv-style program worked fine

simon

--------------------------------------------------------
report ztotal_keyed_ads line-size 120 no standard page
heading.

* list based
type-pools : slis.

tables: jhaga, jhap.

*--------------------------- constants
-------------------------------*
* grid list data
constants: gc_formname_top_of_page type slis_formname
value
'top_of_page'.

types: begin of t_summary,


ad_type type jhaga-ur_beleinh, " c(10)
ad_creat type jhaga-erfuser, " c(12)
ad_num type i,
ad_size type i,
end of t_summary.
types: t_tab_summary type t_summary
occurs 0.

types: begin of t_detail,


erfuser type jhaga-erfuser,
avm_nr type jhaga-avm_nr,
pstyv type jhaga-pstyv,
breite type jhaga-breite,
hoehe type jhaga-hoehe,
end of t_detail.

types: t_tab_detail type t_detail


occurs 0.

* alv data
data: gt_list_top_of_page type slis_t_listheader,
* gt_sort type slis_t_sortinfo_alv,
g_user_command type slis_formname value
'user_command',
gt_fieldcat type slis_t_fieldcat_alv,
gs_layout type slis_layout_alv,
gt_events type slis_t_event.

*--------------------- global internal tables


-------------------------*
data: it_summary type t_tab_summary.

*----------------------- selection screen


-----------------------------*
selection-screen begin of block b1 with frame title
text-001.
select-options s_date for jhaga-aendate.
selection-screen end of block b1.

*----------------------------------------------------------------------*
initialization.
move: '20020101' to s_date-low,
'20020102' to s_date-high,
'i' to s_date-sign,
'bt' to s_date-option.

append s_date.

*----------------- start selection


----------------------------------*
start-of-selection.

* intialization
perform fieldcat_init using gt_fieldcat[].

* event
perform eventtab_build using gt_events[].

* heading
perform comment_build using gt_list_top_of_page[].

* sorting
* perform t_sort_build using gt_sort[].

break sli.

*--------- select is-m/am data from database


perform get_data.

* layout festlegen
perform layout_build using gs_layout.

data: g_repid type sy-repid.


g_repid = sy-repid.

call function 'reuse_alv_list_display'


exporting
i_callback_program = g_repid
* i_structure_name =
* i_callback_pf_status_set = g_status
i_callback_user_command = g_user_command
is_layout = gs_layout
it_fieldcat = gt_fieldcat[]
* it_excluding = rt_extab "nur
wenn standardoberfl.
* it_special_groups = gt_sp_group[]
* it_sort = gt_sort[]
* it_filter =
* is_sel_hide =
* i_default = g_default
* i_save = g_save
* is_variant = g_variant
it_events = gt_events[]
* it_event_exit =
* is_print = gs_print
* i_screen_start_column = 0
* i_screen_start_line = 0
* i_screen_end_column = 0
* i_screen_end_line = 0
* importing
* e_exit_caused_by_caller =
tables
t_outtab = it_summary.

end-of-selection.

*---------------------------------------------------------------------*
* form fieldcat_init
*
*---------------------------------------------------------------------*
* aufbau des feldkataloges
*
*---------------------------------------------------------------------*
* --> lt_fieldcat
*
*---------------------------------------------------------------------*
form fieldcat_init using e01_lt_fieldcat type
slis_t_fieldcat_alv.

* ad_type type jhaga-ur_beleinh, "


c(10)
* ad_creat type jhaga-erfuser, "
c(12)
* ad_num type i,
* ad_size type i,
perform pc_fld using:
1 01 'ad_type' 'ad type' 10 ' h'
'it_summary' space,
1 02 'ad_creat' 'created by' 12 ' h'
'it_summary' space,
1 03 'ad_num' 'number ad' 10 ' h'
'it_summary' 'x',
1 04 'ad_size' 'ad size' 10 ' h'
'it_summary' 'x'.
endform.

*&---------------------------------------------------------------------*
*& form pc_fld
*&---------------------------------------------------------------------*
form pc_fld using value(row) type i value(col) type i
value(field) type c value(heading)
type c
value(len) type i value(direction)
type c
value(tabname) type c value(is_sum)
type c.

data : w_fld like line of gt_fieldcat.

clear w_fld.

move: row to w_fld-row_pos,


col to w_fld-col_pos,
field to w_fld-fieldname.

move heading to: w_fld-seltext_l,


w_fld-seltext_m,
w_fld-seltext_s.

move: 'l' to w_fld-ddictxt,


is_sum to w_fld-do_sum.

move: len to w_fld-outputlen,


tabname to w_fld-tabname.

append w_fld to gt_fieldcat.

endform. " pc_fld

*---------------------------------------------------------------------*
* form comment_build
*
*---------------------------------------------------------------------*
* list-kommentare
*
*---------------------------------------------------------------------*
* --> lt_top_of_page
*
*---------------------------------------------------------------------*
form comment_build using lt_top_of_page type
slis_t_listheader.

data: ls_line type slis_listheader.

clear ls_line.
perform create_headline using '21' changing ls_line.
ls_line-typ = 's'.
ls_line-key = ' '.

append ls_line to lt_top_of_page.

endform. " comment_build

*&---------------------------------------------------------------------*
*& form top_standard
*&---------------------------------------------------------------------*
* standard top_of_page
*
*----------------------------------------------------------------------*
form create_headline using offset type stat_offset
changing ls_line type
slis_listheader.
data: w_day type scal-indicator,
w_weekname type t246-langt,
w_shortname(3) type c,
w_datstr type string.

call function 'date_compute_day'


exporting
date = sy-datum
importing
day = w_day.

select single langt into w_weekname from t246


where sprsl = sy-langu and wotnr = w_day.

w_shortname = w_weekname(3).
translate w_shortname+1(2) to lower case.
concatenate '(' w_shortname ')' into w_datstr.

* parameter offset sollte nach den fixen keyspalten


aufsetzen
data: string(120).
clear string.

write: 'date:' to string,


sy-datum dd/mm/yyyy to
string+7(10),
w_datstr to
string+17(5),
',' to
string+22(2),
'time:' to
string+24(7),
sy-uzeit to
string+31(8)
using edit
mask '__:__:__',
',' to
string+39(2),
'user:' to
string+41(6),
sy-uname to
string+47(12).

condense string.
move string to ls_line+offset.
endform. " top_standard

*---------------------------------------------------------------------*
* form eventtab_build
*
*---------------------------------------------------------------------*
* --> lt_events
*
*---------------------------------------------------------------------*
form eventtab_build using lt_events type slis_t_event.
data: ls_event type slis_alv_event.
*
call function 'reuse_alv_events_get'
exporting
i_list_type = 0
importing
et_events = lt_events.

read table lt_events with key name =


slis_ev_top_of_page
into ls_event.

if sy-subrc = 0.
move gc_formname_top_of_page to ls_event-form.
append ls_event to lt_events.
endif.
endform. " eventtab_build

*---------------------------------------------------------------------*
* form t_sort_build
*
*---------------------------------------------------------------------*
* sortierung
*
*---------------------------------------------------------------------*
* --> lt_sort
*
*---------------------------------------------------------------------*
form t_sort_build using lt_sort type
slis_t_sortinfo_alv.
data: ls_sort type slis_sortinfo_alv.
*
ls_sort-fieldname = 'ad_type'.
ls_sort-spos = 1.
ls_sort-up = 'x'.
* ls_sort-subtot = 'x'.
append ls_sort to lt_sort.
*
ls_sort-fieldname = 'ad_creat'.
ls_sort-spos = 2.
ls_sort-up = 'x'.
* ls_sort-subtot = 'x'.
append ls_sort to lt_sort.

endform. " t_sort_build

*---------------------------------------------------------------------*
* form layout_build
*
*---------------------------------------------------------------------*
* layout-gestaltung
*
*---------------------------------------------------------------------*
* <-> ls_layout
*
*---------------------------------------------------------------------*
form layout_build using ls_layout type
slis_layout_alv.

* ls_layout-f2code = p_f2code.
ls_layout-f2code = '&eta'.
ls_layout-key_hotspot = 'x'.
ls_layout-detail_popup = 'x'.
ls_layout-get_selinfos = 'x'.
endform.

*&---------------------------------------------------------------------*
*& form user_comman
*&---------------------------------------------------------------------*
*& user command
*&---------------------------------------------------------------------*
form user_command using ucomm like sy-ucomm
selfield type
slis_selfield.
case ucomm.
when '&ic1'.
clear ucomm.
endcase.
endform.

*---------------------------------------------------------------------*
* form top_of_page
*
*---------------------------------------------------------------------*
* event 'top_of_page'
form top_of_page.
*
call function 'reuse_alv_commentary_write'
exporting
it_list_commentary = gt_list_top_of_page.
endform. " top_of_page

*&---------------------------------------------------------------------*
*& form get_data
*&---------------------------------------------------------------------*
form get_data.

data: w_manuserf type jhak-manuserf,


wa_detail type t_detail,
it_detail type t_detail occurs 0,
wa_summary type t_summary,
w_count type i,
w_size type i.

* sap order
refresh: it_detail.
select erfuser avm_nr pstyv breite hoehe from jhaga
into wa_detail
where ber_termin in s_date and gf_status <> '01'.

* created-by name for an adpower order


if wa_detail-pstyv eq '0013'.

select single manuserf into w_manuserf from jhak


where avm_nr = wa_detail-avm_nr.

data: w_lastname type but000-mc_name1,


w_firstname type but000-mc_name2,
w_partner(10) type n.

translate w_manuserf to upper case. " upper case

if w_manuserf(10) co '1234567890 '.


w_partner = w_manuserf(10).
select single mc_name1 mc_name2 from but000
into (w_lastname, w_firstname)
where partner = w_partner.
else.
data: w_name1 type but000-mc_name1,
w_name2 type but000-mc_name2.

*-- build the query patterns


concatenate: w_manuserf(1) '%' into w_name1,
w_manuserf+1(5) '%' into w_name2.

select single mc_name1 mc_name2 from but000


into (w_lastname, w_firstname)
where mc_name2 like w_name1 " first
name
and mc_name1 like w_name2. " last
name
endif.
if sy-subrc eq 0.
concatenate w_firstname(1) w_lastname(11) into
wa_detail-erfuser.
endif.
endif.

append wa_detail to it_detail.


endselect.

sort it_detail by erfuser.

loop at it_detail into wa_detail.


at new erfuser.
clear: wa_summary, w_size, w_count.

endat.

w_count = w_count + 1.
w_size = w_size + wa_detail-breite *
wa_detail-hoehe.

at end of erfuser.
if wa_detail-pstyv = '0013'.
wa_summary-ad_type = 'adpower'.
else.
wa_summary-ad_type = 'sap'.
endif.

wa_summary-ad_num = w_count.
wa_summary-ad_size = w_size.
wa_summary-ad_creat = wa_detail-erfuser.
append wa_summary to it_summary.
endat.
endloop.
endform. " get_data

Você também pode gostar