ABAP实例之ALV
*&———————————————————————*
*& Report? ZLG_ALV???????????????????????????????????????????????????? *
*&???????????????????????????????????????????????????????????????????? *
*&———————————————————————*
*& 測試alv各項參數???????????????????????????????????????????????????? *
*& 未完全 – v01 – 20081212???????????????????????????????????????????? *
*& 未完全 – v02 – 20090731???????????????????????????????????????????? *
*&———————————————————————*
*& ALV顯示可以用的FM包括:???????????????????????????????????????????? *
*& 1、REUSE_ALV_GRID_DISPLAY?????????????????????????????????????????? *
*& 2、REUSE_ALV_GRID_DISPLAY_LVC?????????????????????????????????????? *
*& 3、REUSE_ALV_BLOCK_LIST_DISPLAY???????????????????????????????????? *
*&???????????????????????????????????????????????????????????????????? *
*& ALV顯示相關FM包括:???????????????????????????????????????????????? *
*& 1、REUSE_ALV_FIELDCATALOG_MERGE – 制作? 類型的 fieldcatalog???????? *
*& 2、LVC_FIELDCATALOG_MERGE – 制作 LVC_T_FCAT 類型的 fieldcatalog???? *
*& 3、REUSE_ALV_BLOCK_LIST_INIT??????????????????????????????????????? *
*& 4、REUSE_ALV_BLOCK_LIST_APPEND????????????????????????????????????? *
*& 5、REUSE_ALV_EVENTS_GET???????????????????????????????????????????? *
*&???????????????????????????????????????????????????????????????????? *
*&———————————————————————*
*& ALV(REUSE_ALV_GRID_DISPLAY)輸出必須的內容:???????????????????????? *
*& 1、output itab????????????????????????????????????????????????????? *
*& 2、fieldcatalog???????????????????????????????????????????????????? *
*&———————————————————————*
*&????????????????????????? 相關FM注意事項???????????????????????????? *
*& 一、REUSE_ALV_FIELDCATALOG_MERGE??????????????????????????????????? *
*& 1、I_INTERNAL_TABNAME所用的變量對應結構體必須用DATA+BEGIN申明,???? *
*&??? 不可以使用DATA+TYPE line type,否則不會返回Fieldcatalog。??????? *
*& 2、修改了I_INTERNAL_TABNAME對應結構體后,?????????????????????????? *
*&??? 必須/N后重新進去SE38時,才會生效。?????????????????????????????? *
*& 3、程序代碼每行不能太長,不然容易報錯,???????????????????????????? *
*&??? 具體內容見FORM f_fieldcatalog。????????????????????????????????? *
*&???????????????????????????????????????????????????????????????????? *
*&???????????????????????????????????????????????????????????????????? *
*& 二、REUSE_ALV_GRID_DISPLAY????????????????????????????????????????? *
*& 1、使用標準GUI:STANDARD_FULLSCREEN???????????????????????????????? *
*& 2、標準GUI中的&OLO中顯示的列名取決于fieldcatalog中的設置??????????? *
*&???????????????????????????????????????????????????????????????????? *
*& 三、REUSE_ALV_BLOCK_LIST_DISPLAY??????????????????????????????????? *
*& 1、首先用 REUSE_ALV_BLOCK_LIST_INIT 初始化????????????????????????? *
*& 2、然后用 REUSE_ALV_BLOCK_LIST_APPEND 添加需要顯示的ALV???????????? *
*& 3、最后用 REUSE_ALV_BLOCK_LIST_DISPLAY 顯示???????????????????????? *
*&???????????????????????????????????????????????????????????????????? *
*&———————————————————————*
*& 參考自:
*& http://www.itpub.net/viewthread.php?tid=1051462&highlight=ALV%2B%D7%DC%BD%E1
*&———————————————————————*
REPORT? zlg_alv???????????????????????????????? .
*&———————————————————————*
*& 導入??????????????????????????????????????????????????????????????? *
*&———————————————————————*
*include:<ICON>.
*———————————————————————–
*? Instead of statement ‘INCLUDE <icon>.’, please use
*? statement ‘TYPE-POOLS: icon.’ directly.
*———————————————————————–
*&———————————————————————*
*& 類型池引用申明????????????????????????????????????????????????????? *
*&———————————————————————*
TYPE-POOLS:slis.
TYPE-POOLS:icon."代替 include <icon>
*&———————————————————————*
*& 類型定義??????????????????????????????????????????????????????????? *
*&———————————————————————*
*ALV輸出表類型
TYPES:BEGIN OF typ_alv,
?????? icon????????? TYPE icon-id,
?????? box(1)??????? TYPE c,
?????? c10(10)?????? TYPE c,
?????? n10(10)?????? TYPE n,
?????? n5(5)???????? TYPE n,
?????? c???????????? TYPE c,
?????? d???????????? TYPE d,
?????? t???????????? TYPE t,
?????? x???????????? TYPE x,
?????? i???????????? TYPE i,????? "普通I型數字
?????? i2??????????? TYPE i,????? "負數普通顯示
?????? i3??????????? TYPE i,????? "no_sign
?????? i4??????????? TYPE i,????? "負號前置
?????? quantity????? TYPE p DECIMALS 5,"數量
?????? qunit???????? TYPE meins,"數量參考單位
?????? p???????????? TYPE p DECIMALS 5,
?????? cp(33)??????? TYPE c,????? "放置P,32+1?
?????? currency????? TYPE p DECIMALS 5,
?????? cunit???????? TYPE bkpf-waers,
?????? cunit2??????? TYPE c LENGTH 5,
?????? f???????????? TYPE f,
?????? string??????? TYPE string, "內表型類型?
?????? xstring?????? TYPE xstring,"內表型類型?
?????? bname???????? TYPE bname,
?????? bnamel(30)??? TYPE c,???? "與bname對齊方式不同
?????? bnamel2(30)?? TYPE c,???? "熱點
?????? matnr???????? TYPE matnr,??????????????????????????? "F4help – 1
?????? datum???????? TYPE datum,??????????????????????????? "F4help – 2
?????? linecolor(4)? TYPE c,???? "用于保存行顏色代碼
?????? cellcolor???? TYPE slis_t_specialcol_alv,"用于保存單元格顏色代碼
????? END OF typ_alv.
*&———————————————————————*
*& 變量定義??????????????????????????????????????????????????????????? *
*&———————————————————————*
*ALV輸出用內表相關
DATA:itab_alv TYPE STANDARD TABLE OF typ_alv,
???? wa_alv?? TYPE typ_alv.
*ALV Layout相關
DATA:wa_layout TYPE slis_layout_alv.
*ALV Sort相關
DATA:itab_alv_sort TYPE slis_t_sortinfo_alv,
???? wa_alv_sort?? TYPE slis_sortinfo_alv.
*ALV Event相關
DATA:itab_alv_event TYPE slis_t_event,
???? wa_alv_event?? TYPE slis_alv_event.
*ALV Fieldcatalog相關
DATA:itab_alv_fieldcatalog TYPE slis_t_fieldcat_alv,
???? wa_alv_fieldcatalog?? TYPE slis_fieldcat_alv.
*只用于REUSE_ALV_FIELDCATALOG_MERGE
DATA:BEGIN OF cns_alv,
?????? icon????????? LIKE icon-id,"這里只能用like,用type會無效
?????? box(1)??????? TYPE c,
?????? c10(10)?????? TYPE c,
?????? n10(10)?????? TYPE n,
?????? n5(5)???????? TYPE n,
?????? c???????????? TYPE c,
?????? d???????????? TYPE d,
?????? t???????????? TYPE t,
?????? x???????????? TYPE x,
?????? i???????????? TYPE i,
?????? i2??????????? TYPE i,????? "負數
?????? i3??????????? TYPE i,????? "顯示no_sign效果
?????? i4??????????? TYPE i,????? "顯示負號前置效果
?????? quantity????? TYPE p DECIMALS 5,"數量
?????? qunit???????? TYPE meins,"數量參考單位
?????? p???????????? TYPE p,
?????? cp(33)??????? TYPE c,????? "放置P,32+1?
?????? currency????? TYPE p DECIMALS 5,
?????? cunit???????? TYPE bkpf-waers,
?????? cunit2??????? TYPE c LENGTH 5,"貨幣單位沒有被FM加入fieldcatlog中
?????? f???????????? TYPE f,
?????? string??????? TYPE string, "內表型類型?
?????? xstring?????? TYPE xstring,"內表型類型?
?????? bname???????? TYPE bname,
?????? bnamel(30)??? TYPE c,???? "與bname對齊方式不同
?????? bnamel2(30)?? TYPE c,???? "熱點
?????? matnr???????? TYPE matnr,??????????????????????????? "F4help – 1
?????? datum???????? TYPE datum,??????????????????????????? "F4help – 2
?????? linecolor(4)? TYPE c,???? "用于保存行顏色代碼
?????? cellcolor???? TYPE slis_t_specialcol_alv,"用于保存單元格顏色代碼
????? END OF cns_alv.
*隱藏標準按鈕
DATA:itab_alv_excluding?? TYPE slis_t_extab ,
???? wa_alv_excluding???? TYPE slis_extab .
*全局常量
DATA:cns_tabname????????? TYPE slis_tabname? VALUE ‘CNS_ALV’,
???? cns_repid??????????? TYPE sy-repid????? VALUE ‘ZLG_ALV’," sy-repid
???? cns_pf_status_set??? TYPE slis_tabname? VALUE ”,
???? cns_user_command???? TYPE slis_formname VALUE ‘F_USER_COMMAND’,
???? cns_html_top_of_page TYPE slis_formname VALUE ‘F_HTML_TOP_OF_PAGE’,
???? cns_grid_title?????? TYPE lvc_title???? VALUE ‘ALV title’,
???? cns_l(1)???????????? TYPE c???????????? VALUE ‘L’,
???? cns_c(1)???????????? TYPE c???????????? VALUE ‘C’,
???? cns_r(1)???????????? TYPE c???????????? VALUE ‘R’,
???? cns_a(1)???????????? TYPE c???????????? VALUE ‘A’,
???? cns_u(1)???????????? TYPE c???????????? VALUE ‘U’,
???? cns_x(1)???????????? TYPE c???????????? VALUE ‘X’,
???? cns_space(1)???????? TYPE c???????????? VALUE space,
???? cns_half???????????? TYPE i???????????? VALUE ’0.5′.
*全局變量
DATA:g_color_id(1) TYPE c,
???? g_cellcolor?? TYPE slis_specialcol_alv,
???? g_datum?????? TYPE datum,
???? g_flg_alv???? TYPE i,"ALV類型標識
???? g_flg_random? TYPE i."分歧變量
*&———————————————————————*
*& 選擇屏幕??????????????????????????????????????????????????????????? *
*&———————————————————————*
*與form f_check_alv_type相關
PARAMETERS:fagd??? TYPE c RADIOBUTTON GROUP alv DEFAULT ‘X’,"alv grid
?????????? fagdlvc TYPE c RADIOBUTTON GROUP alv,"alv grid lvc
?????????? fabl??? TYPE c RADIOBUTTON GROUP alv."alv block list
*&———————————————————————*
*& 初始化????????????????????????????????????????????????????????????? *
*&———————————————————————*
INITIALIZATION.
? CLEAR:itab_alv_fieldcatalog.
*生成隨機數
? PERFORM f_get_random.
*&———————————————————————*
*& 填充數據及部分設置????????????????????????????????????????????????? *
*&———————————————————————*
START-OF-SELECTION.
*ALV輸出用內表 – 填充
? PERFORM f_get_data.
*&———————————————————————*
*& 設置及顯示????????????????????????????????????????????????????????? *
*&———————————————————————*
END-OF-SELECTION.
*判斷顯示哪種ALV
? PERFORM f_check_alv_type CHANGING g_flg_alv.
*ALV Fieldcatalog – 設置
? PERFORM f_fieldcatalog_all .
*ALV layout – 設置
? PERFORM f_layout_all.
*ALV Sort – 設置
? PERFORM f_sort_all.
*ALV Evnet – 設置
? PERFORM f_event_all.
*ALV GUI – 設置
? PERFORM f_gui_all.
*ALV輸出結果
? PERFORM f_show_alv_all.
*&———————————————————————*
*&????? Form? f_get_data
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_get_data .
? g_datum = sy-datum.
? DO 100 TIMES .
??? CLEAR wa_alv."清空內表型組件(如cellcolor)的值
??? wa_alv-icon??? = ‘@0A@’."red light 可以查看類型池ICON中的值
??? wa_alv-c10???? = sy-index.
??? wa_alv-n10???? = sy-index ** 2.
??? wa_alv-i?????? = sy-index.
??? wa_alv-i2????? = wa_alv-i * -1.
??? wa_alv-i3????? = wa_alv-i2.
??? wa_alv-i4????? = wa_alv-i2 * wa_alv-i * wa_alv-i.
??? CASE sy-index.
????? WHEN 1.
??????? wa_alv-p = 1.
????? WHEN 2.
??????? wa_alv-p = ’1.5436′.
????? WHEN OTHERS.
??????? wa_alv-p = ’0.5436′.
??? ENDCASE.
??? wa_alv-quantity?? = sy-index * 1000.
??? wa_alv-qunit???? = ‘MT’.
??? CASE sy-index.
????? WHEN 1.
??????? wa_alv-qunit???? = ‘MT’.
????? WHEN 2.
??????? wa_alv-qunit???? = ‘MT’.
????? WHEN OTHERS.
??????? wa_alv-qunit???? = ‘KG’.
??? ENDCASE.
??? wa_alv-cp????? = wa_alv-p.
??? wa_alv-currency = 1000.
??? CASE sy-index.
????? WHEN 1.
??????? wa_alv-cunit?? = ‘RMB’.
????? WHEN 2.
??????? wa_alv-cunit?? = ‘CNY’.
????? WHEN OTHERS.
??????? wa_alv-cunit?? = ‘JPY’.
??? ENDCASE.
??? wa_alv-cunit2? = wa_alv-cunit.
??? wa_alv-datum?? = g_datum.
??? g_datum??????? = g_datum + 1.
??? wa_alv-bname?? = sy-uname.
??? wa_alv-bnamel? = sy-uname.
??? wa_alv-bnamel2 = sy-uname.
*–顏色相關
??? PERFORM f_alv_color.
??? APPEND wa_alv TO itab_alv.
? ENDDO .
ENDFORM.??????????????????? " f_get_data
*&———————————————————————*
*&????? Form? f_check_alv_type
*&———————————————————————*
*?????? 判斷顯示哪種ALV
*———————————————————————-*
*????? <–P_FLG_ALV? ALV種類
*———————————————————————-*
FORM f_check_alv_type? CHANGING p_flg_alv.
*———————————————————————-*
*????? 注意修改各個ALL中的CASE語句:
*FORM f_layout_all .
*FORM f_fieldcatalog_all .
*FORM f_sort_all .
*FORM f_gui_all .
*FORM f_show_alv_all .
*———————————————————————-*
? IF fagd = ‘X’.
??? p_flg_alv = 1.
? ELSEIF fagdlvc = ‘X’.
??? p_flg_alv = 2.
? ELSEIF fabl = ‘X’.
??? p_flg_alv = 3.
? ENDIF.
ENDFORM.??????????????????? " f_check_alv_type
*&———————————————————————*
*&????? Form? f_layout_all
*&———————————————————————*
*?????? 各種ALV處理LAYOUT相關設置
*———————————————————————-*
FORM f_layout_all .
? CASE g_flg_alv.
??? WHEN 1 OR 3.
????? PERFORM f_layout CHANGING wa_layout.
??? WHEN 2.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_layout_all
*&———————————————————————*
*&????? Form? f_fieldcatalog_reuse
*&———————————————————————*
*?????? REUSE_ALV_FIELDCATALOG_MERGE
*———————————————————————-*
*????? –>P_REPID? text
*????? –>P_TABNAME? text
*????? <–PT_FIELDCATALOG? text
*———————————————————————-*
*form f_fieldcatalog_reuse? tables
*?????????????????? PT_FIELDCATALOG1 structure wa_alv_fieldcatalog
FORM f_fieldcatalog_reuse USING p_repid???????? TYPE????? sy-repid
??????????????????????????????? p_tabname?????? LIKE????? cns_tabname
?????????????????????? CHANGING pt_fieldcatalog LIKE
????????????????????????????????????????????????? itab_alv_fieldcatalog.
*———————————————————————-*
*即使是注釋也不能太長。
*原因:FM“K_KKB_FIELDCAT_MERGE”以下代碼可能會報錯:
* line:363
*??? read report l_prog_tab_local into l_abap_source.
*??? check sy-subrc eq 0.
*———————————————————————-*
*& 其它功能實現相關處理內容:
*& 1、顏色設置
*& 2、F1幫助
*&
*———————————————————————-*
*& 1、不能使用structure line of:系統提示參數數量不匹配
*&??? 只能使用structure
*& 2、對于REUSE_ALV_FIELDCATALOG_MERGE,只能用changing傳內表,
*&??? 因為tables產生的是帶有表頭的內表參數
*& 3、不同名但同數據元素(數據庫字段)會作為重復而排除
*&??? 但基本類型不會有這個問題
*&———————————————————————*
? CALL FUNCTION ‘REUSE_ALV_FIELDCATALOG_MERGE’
?? EXPORTING
???? i_program_name?????????????? = p_repid
???? i_internal_tabname?????????? = p_tabname
*?? i_structure_name???????????? = ‘ ‘
*?? I_CLIENT_NEVER_DISPLAY?????? = ‘X’
???? i_inclname?????????????????? = p_repid
???? i_bypassing_buffer?????????? = ‘X’"
*?? I_BUFFER_ACTIVE????????????? =
??? CHANGING
????? ct_fieldcat????????????????? = pt_fieldcatalog
?? 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.
? ELSE.
??? LOOP AT pt_fieldcatalog INTO wa_alv_fieldcatalog.
*—–
????? PERFORM f_fieldcatalog_single.
*—–更新
????? MODIFY pt_fieldcatalog FROM wa_alv_fieldcatalog
*???????????????????? TRANSPORTING seltext_l
*????????????????????????????????? emphasize
????????????????????????????????? .
??? ENDLOOP.
? ENDIF.
ENDFORM.??????????????????? " f_fieldcatalog_reuse
*&———————————————————————*
*&????? Form? f_fieldcatalog_all
*&———————————————————————*
*?????? 各種控制ALV列顯示
*———————————————————————-*
FORM f_fieldcatalog_all .
? CASE g_flg_alv.
??? WHEN 1 OR 3.
????? PERFORM f_fieldcatalog_reuse USING??? cns_repid
??????????????????????????????????????????? cns_tabname
?????????????????????????????????? CHANGING itab_alv_fieldcatalog.
??? WHEN 2.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_fieldcatalog_all
*&———————————————————————*
*&????? Form? f_layout
*&———————————————————————*
*?????? 處理LAYOUT相關設置
*———————————————————————-*
*????? <–P_LAYOUT? ALV的LAYOUT結構體變量
*———————————————————————-*
*& 其它功能實現相關處理內容:
*& 1、顏色設置
*& 2、求和(數字、字符型數字)
*&
*———————————————————————-*
FORM f_layout? CHANGING pa_layout LIKE wa_layout.
*types: begin of slis_layout_alv.
*58項?
*???????? dummy,
*???????? no_colhead(1) type c,???????? " no headings
*???????? no_hotspot(1) type c,???????? " headings not as hotspot
*???????? zebra(1) type c,????????????? " striped pattern
*???????? no_vline(1) type c,?????????? " columns separated by space
*???????? no_hline(1) type c,??????? "rows separated by space B20K8A0N5D
*???????? cell_merge(1) type c,???????? " not suppress field replication
*???????? edit(1) type c,?????????????? " for grid only
*???????? edit_mode(1) type c,????????? " for grid only
*???????? numc_sum(1)???? type c,?????? " totals for NUMC-Fields possib.
*???????? no_input(1) type c,?????????? " only display fields
*???????? f2code like sy-ucomm,????????????????????????????? "
*???????? reprep(1) type c,???????????? " report report interface active
*???????? no_keyfix(1) type c,????????? " do not fix keycolumns
*???????? expand_all(1) type c,???????? " Expand all positions
*???????? no_author(1) type c,????????? " No standard authority check
**??????? PF-status
*???????? def_status(1) type c,???????? " default status? space or ‘A’
*???????? item_text(20) type c,???????? " Text for item button
*???????? countfname type lvc_fname,
**??????? Display options
*???????? colwidth_optimize(1) type c,
*???????? no_min_linesize(1) type c,??? " line size = width of the list
*???????? min_linesize like sy-linsz,?? " if initial min_linesize = 80
*???????? max_linesize like sy-linsz,?? " Default 250
*???????? window_titlebar like sy-title,
*???????? no_uline_hs(1) type c,
**??????? Exceptions
*???????? lights_fieldname type slis_fieldname," fieldname for exception
*???????? lights_tabname type slis_tabname, " fieldname for exception
*lights_rollname like dfies-rollname," rollname f. exceptiondocu
*???????? lights_condense(1) type c,??? " fieldname for exception
**??????? Sums
*???????? no_sumchoice(1) type c,?????? " no choice for summing up
*???????? no_totalline(1) type c,?????? " no total line
*???????? no_subchoice(1) type c,?????? " no choice for subtotals
*???????? no_subtotals(1) type c,?????? " no subtotals possible
*???????? no_unit_splitting type c,???? " no sep. tot.lines by inh.units
*???????? totals_before_items type c,?? " diplay totals before the items
*???????? totals_only(1) type c,??????? " show only totals
*totals_text(60) type c,?????? " text for 1st col. in total line
*???????? subtotals_text(60) type c,??? " text for 1st col. in subtotals
**??????? Interaction
*???????? box_fieldname type slis_fieldname, " fieldname for checkbox
*???????? box_tabname type slis_tabname," tabname for checkbox
*???????? box_rollname like dd03p-rollname," rollname for checkbox
*expand_fieldname type slis_fieldname, " fieldname flag ‘expand’
*hotspot_fieldname type slis_fieldname, " fieldname flag hotspot
*???????? confirmation_prompt,????????? " confirm. prompt when leaving
*???????? key_hotspot(1) type c,??????? " keys as hotspot " K_KEYHOT
*???????? flexible_key(1) type c,?????? " key columns movable,…
*???????? group_buttons(1) type c,????? " buttons for COL1 – COL5
*???????? get_selinfos(1) type c,?????? " read selection screen
*???????? group_change_edit(1) type c,? " Settings by user for new group
*???????? no_scrolling(1) type c,?????? " no scrolling
**??????? Detailed screen
*???????? detail_popup(1) type c,?????? " show detail in popup
*???????? detail_initial_lines(1) type c, " show also initial lines
*???????? detail_titlebar like sy-title," Titlebar for detail
**??????? Display variants
*???????? header_text(20) type c,?????? " Text for header button
*???????? default_item(1) type c,?????? " Items as default
**??????? colour
*???????? info_fieldname type slis_fieldname, " infofield for listoutput
*???????? coltab_fieldname type slis_fieldname, " colors
**??????? others
*???????? list_append(1) type c,?????? " no call screen
*???????? xifunckey type aqs_xikey,??? " eXtended interaction(SAPQuery)
*???????? xidirect type flag,????????? " eXtended INTeraction(SAPQuery)
*???????? dtc_layout type dtc_s_layo,? "Layout for configure the Tabstip
*types: end of slis_layout_alv.
**************補完以下參數******************
*???????? dummy,
*–沒有列名行
*???????? no_colhead(1) type c,???????? " no headings
*? pa_layout-no_colhead = ‘X’.
*–
*???????? no_hotspot(1) type c,???????? " headings not as hotspot
*? pa_layout-no_hotspot = ‘X’."效果?
*–在非編輯狀態ALV界面深藍與淺藍色交替顯示行底色
*? pa_layout-zebra = ‘X’.
*–用空格分隔各列,fieldcatalog部分除外。
*?? pa_layout-no_vline = ‘X’.
*–用空格分隔各行
*?? pa_layout-no_hline = ‘X’.
*–
*???????? cell_merge(1) type c,???????? " not suppress field replication
*–ALV處于可編輯狀態,會自動出現最前端的BOX
*? pa_layout-edit? = ‘X’." for grid only
*–
*???????? edit_mode(1) type c,????????? " for grid only
*–是否可以為字符型數字類型求和
*???????? numc_sum(1)???? type c,?????? " totals for NUMC-Fields possib.
*? pa_layout-numc_sum = ‘X’.
*???????? no_input(1) type c,?????????? " only display fields
*–修改“顯示詳細”功能代碼,默認為F2鍵
*???????? f2code like sy-ucomm,
*? pa_layout-layout-f2code = ‘&ETA’."設置成雙擊
*???????? reprep(1) type c,???????????? " report report interface active
*???????? no_keyfix(1) type c,????????? " do not fix keycolumns
*???????? expand_all(1) type c,???????? " Expand all positions
*???????? no_author(1) type c,????????? " No standard authority check
**——–PF-status————————————————–
*–
*???????? def_status(1) type c,???????? " default status? space or ‘A’
*???????? item_text(20) type c,???????? " Text for item button
*???????? countfname type lvc_fname,
**——–Display options——————————————–
*–所有列寬度最優化
*? pa_layout-colwidth_optimize = ‘X’.
*–
*???????? no_min_linesize(1) type c,??? " line size = width of the list
*???????? min_linesize like sy-linsz,?? " if initial min_linesize = 80
*???????? max_linesize like sy-linsz,?? " Default 250
*–ALV窗口標題欄
? pa_layout-window_titlebar = ‘window_titlebar’."like sy-title
*–
*???????? no_uline_hs(1) type c,
**——–Exceptions————————————————-
*???????? lights_fieldname type slis_fieldname," fieldname for exception
*???????? lights_tabname type slis_tabname, " fieldname for exception
*lights_rollname like dfies-rollname," rollname f. exceptiondocu
*???????? lights_condense(1) type c,??? " fieldname for exception
**——–Sums——————————————————-
*???????? no_sumchoice(1) type c,?????? " no choice for summing up
*???????? no_totalline(1) type c,?????? " no total line
*???????? no_subchoice(1) type c,?????? " no choice for subtotals
*???????? no_subtotals(1) type c,?????? " no subtotals possible
*???????? no_unit_splitting type c,???? " no sep. tot.lines by inh.units
*–求和
? pa_layout-totals_before_items = ‘X’." 在ALV最頂端顯示求和結果
*? pa_layout-totals_only???????? = ‘X’."只顯示總和(無效?)
*totals_text(60) type c,?????? " text for 1st col. in total line
*? pa_layout-totals_text???????? = ‘最長60字符,總和’."無效?
*???????? subtotals_text(60) type c,??? " text for 1st col. in subtotals
**——–Interaction————————————————
*???????? box_fieldname type slis_fieldname, " fieldname for checkbox
*???????? box_tabname type slis_tabname," tabname for checkbox
*???????? box_rollname like dd03p-rollname," rollname for checkbox
*expand_fieldname type slis_fieldname, " fieldname flag ‘expand’
*hotspot_fieldname type slis_fieldname, " fieldname flag hotspot
*???????? confirmation_prompt,????????? " confirm. prompt when leaving
*???????? key_hotspot(1) type c,??????? " keys as hotspot " K_KEYHOT
*???????? flexible_key(1) type c,?????? " key columns movable,…
*???????? group_buttons(1) type c,????? " buttons for COL1 – COL5
*???????? get_selinfos(1) type c,?????? " read selection screen
*???????? group_change_edit(1) type c,? " Settings by user for new group
*–無效?
*???????? no_scrolling(1) type c,?????? " no scrolling
*? pa_layout-no_scrolling = ‘X’.
**——–Detailed screen——————————————–
*–是否在彈出窗口中顯示詳細(F2)
*? pa_layout-detail_popup = ‘X’."無效?
*???????? detail_initial_lines(1) type c, " show also initial lines
*–彈出窗口標題欄
*???????? detail_titlebar like sy-title," Titlebar for detail
? pa_layout-detail_titlebar = ‘詳細內容’."系統默認為“細節”
**——–Display variants——————————————-
*???????? header_text(20) type c,?????? " Text for header button
*???????? default_item(1) type c,?????? " Items as default
**——–colour—————————————————–
*—-顏色具體設置見FORM f_get_data、FORM f_alv_color
*–行顏色顯示控制
*? 指定顏色字段指定后fieldcatalog中該字段失效
*? pa_layout-info_fieldname = ‘LINECOLOR’." infofield for listoutput
*–單元格顏色顯示控制
*? 注意該字段為內表,可以添加該行多個字段名
*? pa_layout-coltab_fieldname = ‘CELLCOLOR’.
**——–others—————————————————–
*???????? list_append(1) type c,?????? " no call screen
*???????? xifunckey type aqs_xikey,??? " eXtended interaction(SAPQuery)
*???????? xidirect type flag,????????? " eXtended INTeraction(SAPQuery)
*???????? dtc_layout type dtc_s_layo,? "Layout for configure the Tabstip
ENDFORM.??????????????????? " f_layout
*&———————————————————————*
*&????? Form? f_alv_color
*&———————————————————————*
*?????? ALV顏色相關處理
*———————————————————————-*
FORM f_alv_color .
*———————————————————————-*
*顏色設置的優先級順序從大到小:
*單元格(在內表字段及layout中控制)
*行??? (在內表字段及layout中控制)
*列??? (在fieldcatalog中控制)
*即若同時使用了上述3中更改顏色的方法,則列的顏色會被行的顏色覆蓋掉,而行
*的顏色又會背單元格的顏色覆蓋掉,最終只會顯示出單元格的顏色.
*———————————————————————-*
*& ALV中的顏色代碼共有4位,
*& 第1位是固定為“C”(代表COLOR),
*& 第2位代表是顏色編碼(1到7),
*& 第3位是加強顏色的設置(1表示打開,0表示關閉),
*& 第4位是減弱顏色(1表示打開,0表示關閉),
*& 在強化關閉的情況下,相反的作用是背景和字體的變化。
*& CX00:底色較柔和、前景色為黑色
*& CX01:底色為灰色、前景色為較肉色彩色
*& CX10:底色為強彩色、前景色為黑色
*& CX11:同CX10
*———————————————————————-*
*–行顏色相關
? PERFORM f_row_color.
*–列顏色設置(見fieldcatalog)
*fieldcatalog-emphasize = ‘顏色代碼’.
*–單元格顏色相關
? PERFORM f_cell_color.
ENDFORM.??????????????????? " f_alv_color
*&———————————————————————*
*&????? Form? f_row_color
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_row_color .
*———————————————————————-*
*& 必須在layout的info_fieldname中設置顏色字段名
*& 本例為:layout-info_fieldname = ‘LINECOLOR’.
*———————————————————————-*
? g_color_id = g_color_id + 1 .
? IF g_color_id = 8 .
??? g_color_id = 1 .
? ENDIF .
? CONCATENATE ‘C’ g_color_id ’00′ INTO wa_alv-linecolor .
ENDFORM.??????????????????? " f_row_color
*&———————————————————————*
*&????? Form? f_cell_color
*&———————————————————————*
*?????? 控制單元格顯示顏色
*———————————————————————-*
FORM f_cell_color .
*———————————————————————-*
*& 必須在layout的coltab_fieldname中設置顏色字段名
*& 本例為:coltab_fieldname = ‘CELLCOLOR’.
*———————————————————————-*
*& 可以設置多個字段顯示成不同的顏色
*& 只要向組件cellcolor(內表)中添加多條記錄
*———————————————————————-*
? CLEAR:g_cellcolor.
? CASE wa_alv-c10+8(1).
??? WHEN 1 OR 3 OR 5 OR 7 OR 9.
????? g_cellcolor-fieldname = ‘C10′ . " 要修改顏色的字段名
????? g_cellcolor-color-col = 6 .?????? " 顏色(1-7)
????? g_cellcolor-color-inv = 1 .?????? " 前景字體(int代表背景顏色)
????? APPEND g_cellcolor TO wa_alv-cellcolor .
??? WHEN 2 OR 4 OR 6 OR 8.
????? g_cellcolor-fieldname = ‘C10′ . " 要修改顏色的字段名
????? g_cellcolor-color-col = 5 .?????? " 顏色(1-7)
????? g_cellcolor-color-inv = 1 .?????? " 前景字體(int代表背景顏色)
????? APPEND g_cellcolor TO wa_alv-cellcolor .
??? WHEN OTHERS.
????? g_cellcolor-fieldname = ‘C10′ . " 要修改顏色的字段名
????? g_cellcolor-color-col = 1 .?????? " 顏色(1-7)
????? g_cellcolor-color-inv = 1 .?????? " 前景字體(int代表背景顏色)
????? APPEND g_cellcolor TO wa_alv-cellcolor .
? ENDCASE.
ENDFORM.??????????????????? " f_cell_color
*&———————————————————————*
*&????? Form? f_fieldcatalog_single
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_fieldcatalog_single .
*———————————————————————-*
*& 其它功能實現相關處理內容:
*& 1、顏色設置
*& 2、F1幫助
*& 3、求和
*———————————————————————-*
*types: begin of slis_fieldcat_alv.
*???????? row_pos??????? like sy-curow, " output in row
*???????? col_pos??????? like sy-cucol, " position of the column
*???????? fieldname????? type slis_fieldname,
*???????? tabname??????? type slis_tabname,
*???????? currency(5)??? type c,
*???????? cfieldname???? type slis_fieldname, " field with currency unit
*???????? ctabname?????? type slis_tabname,?? " and table
*???????? ifieldname???? type slis_fieldname, " initial column
*???????? quantity(3)??? type c,
*???????? qfieldname???? type slis_fieldname, " field with quantity unit
*???????? qtabname?????? type slis_tabname,?? " and table
*???????? round????????? type i,??????? " round in write statement
*???????? exponent(3)?????? type c,???? " exponent for floats
*???????? key(1)???????? type c,??????? " column with key-color
*???????? icon(1)??????? type c,??????? " as icon
*???????? symbol(1)????? type c,??????? " as symbol
*???????? checkbox(1)??? type c,??????? " as checkbox
*???????? just(1)??????? type c,??????? " (R)ight (L)eft (C)ent.
*???????? lzero(1)?????? type c,??????? " leading zero
*???????? no_sign(1)???? type c,??????? " write no-sign
*???????? no_zero(1)???? type c,??????? " write no-zero
*???????? no_convext(1)? type c,
*???????? edit_mask????? type slis_edit_mask,??????????????? "
*???????? emphasize(4)?? type c,??????? " emphasize
*???????? fix_column(1)?? type c,?????? " Spalte fixieren
*???????? do_sum(1)????? type c,??????? " sum up
*???????? no_out(1)????? type c,??????? " (O)blig.(X)no out
*???????? tech(1)??????? type c,??????? " technical field
*???????? outputlen????? like dd03p-outputlen,
*???????? offset???????? type dd03p-outputlen,???? " offset
*???????? seltext_l????? like dd03p-scrtext_l, " long key word
*???????? seltext_m????? like dd03p-scrtext_m, " middle key word
*???????? seltext_s????? like dd03p-scrtext_s, " short key word
*???????? ddictxt(1)???? type c,??????? " (S)hort (M)iddle (L)ong
*???????? rollname?????? like dd03p-rollname,
*???????? datatype?????? like dd03p-datatype,
*???????? inttype??????? like dd03p-inttype,
*???????? intlen???????? like dd03p-intlen,
*???????? lowercase????? like dd03p-lowercase,
*???????? ref_fieldname? like dd03p-fieldname,
*???????? ref_tabname??? like dd03p-tabname,
*???????? roundfieldname type slis_fieldname,
*???????? roundtabname?? type slis_tabname,
*???????? decimalsfieldname type slis_fieldname,
*???????? decimalstabname?? type slis_tabname,
*???????? decimals_out(6)?? type c,???? " decimals in write statement
*???????? text_fieldname type slis_fieldname,
*???????? reptext_ddic?? like dd03p-reptext,?? " heading (ddic)
*???????? ddic_outputlen like dd03p-outputlen,
*???????? key_sel(1)???? type c,??????? " field not obligatory
*???????? no_sum(1)????? type c,??????? " do not sum up
*???????? sp_group(4)??? type c,??????? " group specification
*???????? reprep(1)????? type c,??????? " selection for rep/rep
*???????? input(1)?????? type c,??????? " input
*???????? edit(1)??????? type c,??????? " internal use only
*???????? hotspot(1)???? type c,??????? " hotspot
*types: end of slis_fieldcat_alv.
*???????? row_pos??????? like sy-curow, " output in row
*???????? col_pos??????? like sy-cucol, " position of the column
*???????? fieldname????? type slis_fieldname,
*???????? tabname??????? type slis_tabname,
*–
*???????? currency(5)??? type c,
*???????? cfieldname???? type slis_fieldname, " field with currency unit
*???????? ctabname?????? type slis_tabname,?? " and table
? PERFORM f_currency_setting.
*–效果不明
*? perform f_filed_ifieldname.
*–
*???????? quantity(3)??? type c,
*???????? qfieldname???? type slis_fieldname, " field with quantity unit
*???????? qtabname?????? type slis_tabname,?? " and table
? PERFORM f_field_quantity.
*–移動小數位
*???????? round????????? type i,??????? " round in write statement
? PERFORM f_field_round.
*–
*???????? exponent(3)?????? type c,???? " exponent for floats
*–關鍵列
*???????? key(1)???????? type c,??????? " column with key-color
? PERFORM f_field_key.
*–圖標
*???????? icon(1)??????? type c,??????? " as icon
? PERFORM f_field_icon.
*???????? symbol(1)????? type c,??????? " as symbol
*–多選框
*???????? checkbox(1)??? type c,??????? " as checkbox
? PERFORM f_field_checkbox.
*–對齊方式
*???????? just(1)??????? type c,??????? " (R)ight (L)eft (C)ent.
? PERFORM f_field_just.
*–左端補零
*???????? lzero(1)?????? type c,??????? " leading zero
? PERFORM f_field_lzero.
*–沒有符號
*???????? no_sign(1)???? type c,??????? " write no-sign
? PERFORM f_field_nosign.
*–
*???????? no_zero(1)???? type c,??????? " write no-zero
*–
*???????? no_convext(1)? type c,
*–輸出格式控制
*???????? edit_mask????? type slis_edit_mask,
? PERFORM f_field_editmask.
*–列顏色控制
*???????? emphasize(4)?? type c,??????? " emphasize
? PERFORM f_column_color.
*–固定列
*???????? fix_column(1)?? type c,?????? " Spalte fixieren
? PERFORM f_field_fix.
*–單列求和
*???????? do_sum(1)????? type c,??????? " sum up
? PERFORM f_field_dosum.
*–
*???????? no_out(1)????? type c,??????? " (O)blig.(X)no out
*–
*???????? tech(1)??????? type c,??????? " technical field
*–列的字符寬度
*???????? outputlen????? like dd03p-outputlen,
? PERFORM f_field_outputlen.
*–
*???????? offset???????? type dd03p-outputlen,???? " offset
*–列描述設置
*???????? seltext_l????? like dd03p-scrtext_l, " long key word
*???????? seltext_m????? like dd03p-scrtext_m, " middle key word
*???????? seltext_s????? like dd03p-scrtext_s, " short key word
? PERFORM f_field_seltext.
*???????? ddictxt(1)???? type c,??????? " (S)hort (M)iddle (L)ong
*–F1幫助
*???????? rollname?????? like dd03p-rollname,
? PERFORM f_field_f1help.
*–ABAP 字典中的數據類型
*???????? datatype?????? like dd03p-datatype,
*–ABAP 數據類型(C,D,N,…)
*???????? inttype??????? like dd03p-inttype,
*–以字節計的內部長度
*???????? intlen???????? like dd03p-intlen,
*–是否允許輸入小寫字母?
*???????? lowercase????? like dd03p-lowercase,
? PERFORM f_field_lowercase.
*–F4幫助
*???????? ref_fieldname? like dd03p-fieldname,
*???????? ref_tabname??? like dd03p-tabname,
? PERFORM f_field_f4help.
*???????? roundfieldname type slis_fieldname,
*???????? roundtabname?? type slis_tabname,
*???????? decimalsfieldname type slis_fieldname,
*???????? decimalstabname?? type slis_tabname,
*–控制小數位輸出
? PERFORM f_field_decimalsout.
*???????? text_fieldname type slis_fieldname,
*???????? reptext_ddic?? like dd03p-reptext,?? " heading (ddic)
*???????? ddic_outputlen like dd03p-outputlen,
*???????? key_sel(1)???? type c,??????? " field not obligatory
*???????? no_sum(1)????? type c,??????? " do not sum up
*???????? sp_group(4)??? type c,??????? " group specification
*???????? reprep(1)????? type c,??????? " selection for rep/rep
*???????? input(1)?????? type c,??????? " input
*???????? edit(1)??????? type c,??????? " internal use only
? PERFORM f_field_edit.
*–熱點
*???????? hotspot(1)???? type c,??????? " hotspot
? PERFORM f_field_hotspot.
ENDFORM.??????????????????? " f_fieldcatalog_single
*&———————————————————————*
*&????? Form? f_column_color
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_column_color .
*———————————————————————-*
*&
*&
*&
*&
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘F’.
????? wa_alv_fieldcatalog-emphasize = ‘C711′.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_column_color
*&———————————————————————*
*&????? Form? f_field_f1help
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_field_f1help .
*———————————————————————-*
*& 1、可以在ALV的顯示界面將鼠標放到該字段的位置后按F1會彈出該字段的說明
*& 2、指定數據元素之后,可以不指明字段的描述(如SCRTEXT_L、SCRTEXT_M、
*&??? SCRTEXT_S),函數會自動將字段的描述顯示,但是沒有自己指定的靈活。
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘DATUM’.
????? wa_alv_fieldcatalog-rollname = ‘DATUM’." 指定數據元素
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_f1help
*&———————————————————————*
*&????? Form? f_field_f4help
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_field_f4help .
*———————————————————————-*
*& 1、可以在ALV的顯示界面將鼠標放到該字段的位置后按F1會彈出該字段的說明
*& 2、指定數據元素之后,可以不指明字段的描述(如SCRTEXT_L、SCRTEXT_M、
*&??? SCRTEXT_S),函數會自動將字段的描述顯示,但是沒有自己指定的靈活。
*& 3、部分可以支持F4幫助的字段可能會沒有F4HELP效果,例如BNAME
*&??? F4HELP的效果是:單擊后單元格最前端出現小圖標
*& 4、字段不能設置hotspot
*& 5、字段A可以設置成另一個字段B
*&??? 例如,fieldname = ‘BNAME’,ref_fieldname = ‘MATNR’
*&??? 所以和ALV的編輯功能一樣,需要注意輸入后的字段正確性驗證
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘BNAME’.
*F4HELP無效:
*原因:SE11中沒有F4HELP,只有DOMAIN的value table
????? wa_alv_fieldcatalog-ref_fieldname = ‘BNAME’ .
????? wa_alv_fieldcatalog-ref_tabname = ‘USR02′ .
??? WHEN ‘MATNR’.
*F4HELP有效:
????? wa_alv_fieldcatalog-ref_fieldname = ‘MATNR’ .
????? wa_alv_fieldcatalog-ref_tabname = ‘MARA’ .
??? WHEN ‘DATUM’.
????? wa_alv_fieldcatalog-ref_fieldname = ‘GLTGV’ .
????? wa_alv_fieldcatalog-ref_tabname = ‘USR02′ .
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_f4help
*&———————————————————————*
*&????? Form? f_field_seltext
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_field_seltext .
*———————————————————————-*
*& 1、seltext_m 優先級大于 seltext_l
*& 2、如果seltext_m為空,則使用seltext_l中的內容作為列描述
*& 3、seltext_s 可能只能用來做為列提示時的信息,如果seltext_s為空,則用
*&??? 列描述做為列信息顯示
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘I2′.
????? wa_alv_fieldcatalog-seltext_l = ‘普通負數的顯示’.
??? WHEN ‘I3′.
????? wa_alv_fieldcatalog-seltext_l = ‘去掉數字的符號’.
??? WHEN ‘I4′.
????? wa_alv_fieldcatalog-seltext_l = ‘負號前置’.
??? WHEN ‘DATUM’.
??? WHEN ‘BNAME’.
??? WHEN ‘BNAMEL2′.
????? wa_alv_fieldcatalog-seltext_l = ‘熱點’.
??? WHEN OTHERS.
????? wa_alv_fieldcatalog-seltext_l = wa_alv_fieldcatalog-fieldname.
? ENDCASE.
ENDFORM.??????????????????? " f_field_seltext
*&———————————————————————*
*&????? Form? f_field_just
*&———————————————————————*
*?????? 列對齊方式
*———————————————————————-*
FORM f_field_just .
*———————————————————————-*
*& (R)ight (L)eft (C)ent
*& P.S. 列最優化時,看不出效果,拉開列寬后可以看到效果。
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘DATUM’.
????? wa_alv_fieldcatalog-just = cns_c."居中
??? WHEN ‘BNAME’.
????? wa_alv_fieldcatalog-just = cns_r."右對齊
??? WHEN ‘CP’.
????? wa_alv_fieldcatalog-just = cns_r."右對齊
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_just
*&———————————————————————*
*&????? Form? f_field_key
*&———————————————————————*
*?????? 關鍵列
*———————————————————————-*
FORM f_field_key .
*———————————————————————-*
*& 1、固定列,當ALV顯示界面中該字段左側也為關鍵或固定列時,
*&??? 該列固定不動。
*& 2、列底色成為藍色。
*& 3、列寬不優化時,效果明顯。
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘C10′.
????? wa_alv_fieldcatalog-key = ‘X’.
??? WHEN ‘N10′.
*????? wa_alv_fieldcatalog-key = ‘X’."與固定列做對比
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_key
*&———————————————————————*
*&????? Form? f_field_fix
*&———————————————————————*
*?????? 固定列
*———————————————————————-*
FORM f_field_fix .
*———————————————————————-*
*& 1、固定列,當ALV顯示界面中該字段左側也為關鍵或固定列時,
*&??? 該列固定不動。
*& 2、列寬不優化時,效果明顯。
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘N10′.
????? wa_alv_fieldcatalog-fix_column = ‘X’."與關鍵列做對比
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_fix
*&———————————————————————*
*&????? Form? f_field_outputlen
*&———————————————————————*
*?????? 列的字符寬度
*———————————————————————-*
FORM f_field_outputlen .
*———————————————————————-*
*& 在沒有最優化列寬的前提下,顯式指定某列列寬
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘N10′.
????? wa_alv_fieldcatalog-outputlen = 10.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_outputlen
*&———————————————————————*
*&????? Form? f_field_lowercase
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_field_lowercase .
*———————————————————————-*
*&
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘BNAME’.
????? wa_alv_fieldcatalog-lowercase = ‘X’.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_lowercase
*&———————————————————————*
*&????? Form? f_field_dosum
*&———————————————————————*
*?????? 字段求和
*———————————————————————-*
FORM f_field_dosum .
*———————————————————————-*
*& 1、需要設置fieldcatalog-totals_before_items
*& 2、不能對N型求和,除非設置layout-numc_sum = ‘X’
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘N10′.
????? wa_alv_fieldcatalog-do_sum = ‘X’.
??? WHEN ‘I’.
????? wa_alv_fieldcatalog-do_sum = ‘X’.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_dosum
*&———————————————————————*
*&????? Form? f_field_lzero
*&———————————————————————*
*?????? 左端補零
*———————————————————————-*
FORM f_field_lzero .
*———————————————————————-*
*& 1、對數字型無效
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘N10′.
????? wa_alv_fieldcatalog-lzero = ‘X’.
??? WHEN ‘I’.
????? wa_alv_fieldcatalog-lzero = ‘X’."無效
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_lzero
*&———————————————————————*
*&????? Form? f_field_nosign
*&———————————————————————*
*?????? 去除符號顯示
*———————————————————————-*
FORM f_field_nosign .
*———————————————————————-*
*&
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘I3′.
????? wa_alv_fieldcatalog-no_sign = ‘X’.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_nosign
*&———————————————————————*
*&????? Form? f_field_hotspot
*&———————————————————————*
*?????? 設置熱點
*———————————————————————-*
FORM f_field_hotspot .
*———————————————————————-*
*& 1、字符下出現下劃線
*& 2、鼠標移動至該列時,變成手指可點擊形狀
*& 3、單擊即可觸發user_command命令
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘BNAMEL2′.
????? wa_alv_fieldcatalog-hotspot = ‘X’.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_hotspot
*&———————————————————————*
*&????? Form? f_user_command
*&———————————————————————*
*?????? ALV用戶命令
*———————————————————————-*
FORM f_user_command USING p_ucomm??? TYPE sy-ucomm
????????????????????????? p_selfield TYPE slis_selfield.
*———————————————————————-*
*& 1、selfield-sel_tab_field為“fieldcatalog-tabname”-“fieldname”
*———————————————————————-*
*types: begin of slis_selfield,
*???????? tabname type slis_tabname,
*???????? tabindex like sy-tabix,
*???????? sumindex like sy-tabix,
*???????? endsum(1) type c,
*???????? sel_tab_field type slis_sel_tab_field,
*???????? value type slis_entry,
*???????? before_action(1) type c,
*???????? after_action(1) type c,
*???????? refresh(1) type c,
*???????? ignore_multi(1) type c, " ignore selection by checkboxes (F2)
*???????? col_stable(1) type c,
*???????? row_stable(1) type c,
**??????? colwidth_optimize(1) type c,"本項被SAP注釋
*???????? exit(1) type c,
*???????? fieldname type slis_fieldname,
*???????? grouplevel type i,
*???????? collect_from type i,
*???????? collect_to type i,
*?????? end of slis_selfield.
? READ TABLE itab_alv INTO wa_alv INDEX p_selfield-tabindex.
? CHECK sy-subrc = 0.
? CASE p_ucomm.
??? WHEN ‘&IC1′."雙擊
????? CASE p_selfield-sel_tab_field.
??????? WHEN? ‘CNS_ALV-BNAME’.
????????? SET PARAMETER ID ‘XUS’ FIELD wa_alv-bname.
????????? CALL TRANSACTION ‘SU01′ AND SKIP FIRST SCREEN.
????? ENDCASE.
? ENDCASE.
ENDFORM.??????????????????? " f_user_command
*&———————————————————————*
*&????? Form? f_html_top_of_page
*&———————————————————————*
*?????? text
*———————————————————————-*
*????? –>P_CL_DD? text
*———————————————————————-*
FORM f_html_top_of_page USING p_cl_dd TYPE REF TO cl_dd_document.
* 定義登錄用戶的描述
? DATA: l_name TYPE string ,
??????? name_first LIKE adrp-name_first ,
??????? name_last? LIKE adrp-name_last .
* 定義登錄日期
? DATA: l_date TYPE string .
* 定義緩沖區變量
? DATA: m_p TYPE i ,
??????? m_buffer TYPE string .
* 得到登錄用戶的描述
? SELECT SINGLE adrp~name_first
??????????????? adrp~name_last
??? INTO (name_first,name_last)
??? FROM adrp
?? INNER JOIN usr21 ON adrp~persnumber = usr21~persnumber
?? WHERE usr21~bname = sy-uname .
? IF sy-subrc = 0 .
??? CONCATENATE name_last name_first INTO l_name .
? ELSE .
??? l_name = sy-uname .
? ENDIF.
? CLEAR name_first .
? CLEAR name_last .
* 拼接制表日期
? CONCATENATE sy-datum+0(4) ‘.’
????????????? sy-datum+4(2) ‘.’
????????????? sy-datum+6(2)
???????? INTO l_date .
* 開始輸出表頭標題
? m_buffer = ‘<HTML><CENTER><H1>ALV測試</H1></CENTER></HTML>’ .
? CALL METHOD p_cl_dd->html_insert
??? EXPORTING
????? contents = m_buffer
??? CHANGING
????? position = m_p.
* 輸出制表人和制表日期
? CONCATENATE ‘<P ALIGN = CENTER >出表人:’ l_name
??????????? ‘         &’
??????????? ‘nbsp????????????????????  ’
??????????? ‘       ’
??????????? ‘       ’
??????????? ‘           ’
??????????? ‘           ’
??????????? ‘           ’
??????????? ‘           ’
??????????? ‘           ’
??????????? ‘           ’
??????????? ‘           ’
??????????? ‘      ’
??????????? ‘出表日期:’ l_date INTO m_buffer .
? CALL METHOD p_cl_dd->html_insert
??? EXPORTING
????? contents = m_buffer
??? CHANGING
????? position = m_p.
ENDFORM.??????????????????? " f_html_top_of_page
*&———————————————————————*
*&????? Form? f_show_alv_all
*&———————————————————————*
*?????? 各種ALV的顯示
*———————————————————————-*
FORM f_show_alv_all .
? CASE g_flg_alv.
??? WHEN 1.
????? PERFORM f_show_alv.
??? WHEN 2.
??? WHEN 3."垂直方向同屏幕顯示多個ALV
????? PERFORM f_show_alv_bl.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_show_alv_all
*&———————————————————————*
*&????? Form? f_show_alv
*&———————————————————————*
*?????? REUSE_ALV_GRID_DISPLAY
*———————————————————————-*
FORM f_show_alv .
*———————————————————————-*
*FOR I_SAVE
* ‘ ‘ = Display variants cannot be saved
*?? Defined display variants (such as delivered display variants) can
*?? be selected for presentation regardless of this indicator. However,
*?? changes cannot be saved.
* ‘X’ = Standard save mode
*?? Display variants can be saved as standard display variants.
*?? Saving display variants as user-specific is not possible.
* ‘U’ = User-specific save mode
*?? Display variants can only be saved as user-specific.
* ‘A’ = Standard and user-specific save mode
*?? Display variants can be saved both as user-specific and as standard
*?? variants. Users make their choice on the dialog box for saving the
*?? display variant.
*———————————————————————-*
*FOR IT_SORT in FORM f_sort.
*———————————————————————-*
*以下2個參數有部分效果相同,可以穿空值
*???? i_callback_pf_status_set????????? = cns_pf_status_set
*???? it_excluding????????????????????? = itab_alv_excluding
*———————————————————————-*
? CALL FUNCTION ‘REUSE_ALV_GRID_DISPLAY’
?? EXPORTING
*?? I_INTERFACE_CHECK???????????????? = ‘ ‘
*?? I_BYPASSING_BUFFER??????????????? = ‘ ‘
*?? I_BUFFER_ACTIVE?????????????????? = ‘ ‘
???? i_callback_program??????????????? = cns_repid " type SY-REPID
???? i_callback_pf_status_set????????? = cns_pf_status_set
???? i_callback_user_command?????????? = cns_user_command
*?? I_CALLBACK_TOP_OF_PAGE??????????? = ‘ ‘
???? i_callback_html_top_of_page?????? = cns_html_top_of_page
*?? I_CALLBACK_HTML_END_OF_LIST?????? = ‘ ‘
*?? I_STRUCTURE_NAME????????????????? =
*?? I_BACKGROUND_ID?????????????????? = ‘ ‘
???? i_grid_title????????????????????? = cns_grid_title
*?? I_GRID_SETTINGS?????????????????? =
???? is_layout???????????????????????? = wa_layout
???? it_fieldcat?????????????????????? = itab_alv_fieldcatalog
???? it_excluding????????????????????? = itab_alv_excluding
*?? IT_SPECIAL_GROUPS???????????????? =
???? it_sort?????????????????????????? = itab_alv_sort
*?? IT_FILTER???????????????????????? =
*?? IS_SEL_HIDE?????????????????????? =
*?? I_DEFAULT???????????????????????? = ‘X’
???? i_save??????????????????????????? = cns_x " space x u a
*?? IS_VARIANT??????????????????????? =
?? it_events???????????????????????? = itab_alv_event
*?? 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
*?? IT_ALV_GRAPHICS?????????????????? =
*?? IT_HYPERLINK????????????????????? =
*?? IT_ADD_FIELDCAT?????????????????? =
*?? IT_EXCEPT_QINFO?????????????????? =
*?? I_HTML_HEIGHT_TOP???????????????? =
*?? I_HTML_HEIGHT_END???????????????? =
* IMPORTING
*?? E_EXIT_CAUSED_BY_CALLER?????????? =
*?? ES_EXIT_CAUSED_BY_USER??????????? =
?? TABLES
???? t_outtab????????????????????????? = itab_alv
?? 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.??????????????????? " f_show_alv
*&———————————————————————*
*&????? Form? f_sort_all
*&———————————————————————*
*?????? ALV顯示排序
*———————————————————————-*
FORM f_sort_all .
? CASE g_flg_alv.
??? WHEN 1 OR 3.
????? PERFORM f_sort.
??? WHEN 2.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_sort_all
*&———————————————————————*
*&????? Form? f_sort
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_sort .
*———————————————————————-*
*?????? IT_SORT TYPE? SLIS_T_SORTINFO_ALV
*types: begin of slis_sortinfo_alv,
**??????? spos(2) type n,?????????? "本項被SAP注釋
*???????? spos like alvdynp-sortpos,
*???????? fieldname type slis_fieldname,
*???????? tabname type slis_fieldname,
**??????? up(1) type c,???????????? "本項被SAP注釋
**??????? down(1) type c,?????????? "本項被SAP注釋
**??????? group(2) type c,????????? "本項被SAP注釋
**??????? subtot(1) type c,???????? "本項被SAP注釋
*???????? up like alvdynp-sortup,
*???????? down like alvdynp-sortdown,
*???????? group like alvdynp-grouplevel,
*???????? subtot like alvdynp-subtotals,
*???????? comp(1) type c,
*???????? expa(1) type c,
*???????? obligatory(1) type c,
*?????? end of slis_sortinfo_alv.
*———————————————————————-*
*wa_alv_sort-spos?????? = 1.
*wa_alv_sort-fieldname = ‘N10′.
*wa_alv_sort-up??????? = ‘X’.
*wa_alv_sort-subtot??? = ‘X’.
*append wa_alv_sort to itab_alv_sort.
? wa_alv_sort-spos?????? = 1.
? wa_alv_sort-fieldname = ‘BNAME’.
? wa_alv_sort-up??????? = ‘X’.
? wa_alv_sort-subtot??? = ‘X’.
? APPEND wa_alv_sort TO itab_alv_sort.
ENDFORM.??????????????????? " f_sort
*&———————————————————————*
*&????? Form? f_field_icon
*&———————————————————————*
*?????? 設置圖標
*———————————————————————-*
FORM f_field_icon .
*———————————————————————-*
*& 1、ICON字段在fieldcatalog需要的結構體中只能用like定義
*& 2、ICON的值來自于類型池ICON、或者數據庫表ICON
*& 3、如果只是用于顯示紅綠燈圖標,可以使用以下方法:
*&??? ICON(1)? TYPE C,"1:Red; 2:Yellow; 3:Green
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘ICON’.
????? wa_alv_fieldcatalog-icon = ‘X’.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_icon
*&———————————————————————*
*&????? Form? f_field_checkbox
*&———————————————————————*
*?????? 設置多選框
*———————————————————————-*
FORM f_field_checkbox .
*———————————————————————-*
*& 1、需要配合編輯狀態
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘BOX’.
????? wa_alv_fieldcatalog-checkbox = ‘X’.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_checkbox
*&———————————————————————*
*&????? Form? f_field_editmask
*&———————————————————————*
*?????? 效果不明
*———————————————————————-*
FORM f_field_editmask .
*———————————————————————-*
*& 1、可以實現字段顯示效果?的轉換規則
*———————————————————————-*
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘I4′.
*符號前置的一種方法,V后面的_可以任意數量,缺點:沒有數字分割符
????? wa_alv_fieldcatalog-edit_mask = ‘V______’.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_editmask
*&———————————————————————*
*&????? Form? f_gui_all
*&———————————————————————*
*?????? 設置用戶接口相關內容
*———————————————————————-*
FORM f_gui_all .
? CASE g_flg_random.
??? WHEN 1 OR 3.
*ALV 功能鍵 – 設置
????? PERFORM f_fcode_all.
??? WHEN 2.
*自定義工具欄
????? PERFORM f_pfstatus_all.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_gui_all
*&———————————————————————*
*&????? Form? f_fcode_all
*&———————————————————————*
*
*———————————————————————-*
FORM f_fcode_all .
? CASE g_flg_alv.
??? WHEN 1.
????? PERFORM f_fcode.
??? WHEN 2.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_fcode_all
*&———————————————————————*
*&????? Form? f_fcode
*&———————————————————————*
*?????? 設置要隱藏的按鈕的“FCODE”
*———————————————————————-*
FORM f_fcode .
? "&ETA???? :細節
? "&EB9???? :調用報表
? "&REFRESH :刷新
? "&ALL???? :選擇全部
? "&SAL???? :取消選擇全部
? "&OUP???? :按升序排序
? "&ODN???? :按降序排序
? "&ILT???? :設置過濾器
? "&UMC???? :總計
? "&SUM???? :小計
? "&RNT_PREV:打印預覽
? "&VEXCEL? :Microsoft Excel
? "&AQW???? :字處理
? "%PC????? :本地文件
? "%SL????? :郵件收件人
? "&ABC???? :ABC分析
? "&GRAPH?? :圖形
? "&OL0???? :更改布局
? "&OAD???? :選擇布局
? "&AVE???? :保存布局
? "&INFO??? :信息
? wa_alv_excluding-fcode = ‘&AQW’ .
? APPEND wa_alv_excluding TO itab_alv_excluding .
? wa_alv_excluding-fcode = ‘&ABC’ .
? APPEND wa_alv_excluding TO itab_alv_excluding .
? wa_alv_excluding-fcode = ‘&ABC’ .
? APPEND wa_alv_excluding TO itab_alv_excluding .
? wa_alv_excluding-fcode = ‘&OL0′ .
? APPEND wa_alv_excluding TO itab_alv_excluding .
? wa_alv_excluding-fcode = ‘&OAD’ .
? APPEND wa_alv_excluding TO itab_alv_excluding .
? wa_alv_excluding-fcode = ‘&AVE’ .
? APPEND wa_alv_excluding TO itab_alv_excluding .
? wa_alv_excluding-fcode = ‘&INFO’ .
? APPEND wa_alv_excluding TO itab_alv_excluding .
ENDFORM.??????????????????? " f_fcode
*&———————————————————————*
*&????? Form? f_pfstatus_all
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_pfstatus_all .
? CASE g_flg_alv.
??? WHEN 1.
????? PERFORM f_pfstatus.
??? WHEN 2.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_pfstatus_all
*&———————————————————————*
*&????? Form? f_pfstatus
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_pfstatus .
? cns_pf_status_set = ‘F_PF_STATUS_SET’.
ENDFORM.??????????????????? " f_pfstatus
*&———————————————————————*
*&????? Form? f_pf_status_set
*&———————————————————————*
*
*———————————————————————-*
FORM f_pf_status_set USING p_extab TYPE slis_t_extab .
*“分隔符”的插入方法為:
*在需要插入分隔符的方框內選擇菜單
*“Edit”->“Insert”->“Separator line”即可插入分隔符
? SET PF-STATUS ‘ALV_STATUS’ .
ENDFORM.??????????????????? " f_pf_status_set
*&———————————————————————*
*&????? Form? f_get_random
*&———————————————————————*
*?????? 獲得隨機數
*———————————————————————-*
FORM f_get_random .
*———————————————————————-*
*用 QF05_RANDOM_INTEGER 來獲得隨機數, 第一次使用的時候只是獲得種子.
*所以在程序中使用的時候,要在最開始設置種子.
*不然每次獲得的隨機數都一樣
*from:http://blog.chinaunix.net/u2/64493/showart_525094.html
*
*即:QF05_RANDOM_INTEGER第一次運行的結果必定一樣
*RAN_INT參數不是必須的
*———————————————————————-*
? CALL FUNCTION ‘QF05_RANDOM_INTEGER’
?? EXPORTING
???? ran_int_max???????? = 10
???? ran_int_min???????? = 1
* IMPORTING
*?? RAN_INT???????????? = g_flg_random
?? EXCEPTIONS
???? invalid_input?????? = 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.
? CALL FUNCTION ‘QF05_RANDOM_INTEGER’
??? EXPORTING
????? ran_int_max?? = 2
????? ran_int_min?? = 1
??? IMPORTING
????? ran_int?????? = g_flg_random
??? EXCEPTIONS
????? invalid_input = 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.??????????????????? " f_get_random
*&———————————————————————*
*&????? Form? f_field_round
*&———————————————————————*
*?????? 移動小數位?
*———————————————————————-*
FORM f_field_round .
*———————————————————————-*
*& 1、效果類似 WRITE … ROUND r
* WRITE … ROUND r 的效果
*
* Scaled output of a field of type P.
*
* The decimal point is first moved r places to the left (r > 0) or to
* theright (r < 0); this is the same as dividing with the appropriate
* exponent 10**r. The value determined in this way is output with the
* valid number of digits before and after the decimal point. If the
* decimal point is moved to the left, the number is rounded.
*
* For further information about the interaction between the formatting
* options CURRENCY and DECIMALS, see the notes below.
*
*Example
*Effect of different ROUND specifications:
*
*DATA: X TYPE P DECIMALS 2 VALUE ’12493.97′.
*
*WRITE: /X ROUND -2,?? "output: 1,249,397.00
*?????? /X ROUND? 0,?? "output:??? 12,493.97
*?????? /X ROUND? 2,?? "output:?????? 124.94
*?????? /X ROUND? 5,?? "output:???????? 0.12
*
*所以,一般與fieldcatalog中的decimals_out一起使用
*-:放大,-2→數字=數字×100
*+:縮小, 2→數字=數字/100
*———————————————————————-*
*???????? round????????? type i,??????? " round in write statement
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘P’.
????? wa_alv_fieldcatalog-round = -2."小數點偏移位置
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_round
*&———————————————————————*
*&????? Form? f_filed_ifieldname
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_filed_ifieldname .
*———————————————————————-*
*& 1、
*———————————————————————-*
*???????? ifieldname???? type slis_fieldname, " initial column
*內部表字段的字段名稱?
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘P’.
????? wa_alv_fieldcatalog-ifieldname = ”.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_filed_ifieldname
*&———————————————————————*
*&????? Form? f_show_alv_bl
*&———————————————————————*
*?????? 垂直方向同屏幕顯示多個ALV
*———————————————————————-*
FORM f_show_alv_bl .
*———————————————————————-*
*& 1、
*———————————————————————-*
*改自: http://blog.chinaunix.net/u2/64493/showart.php?id=1090105
? CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_INIT’
??? EXPORTING
????? i_callback_program???????????? = cns_repid
*?? I_CALLBACK_PF_STATUS_SET?????? = ‘ ‘
*?? I_CALLBACK_USER_COMMAND??????? = ‘ ‘
*?? IT_EXCLUDING?????????????????? =
??????????? .
*添加第1個ALV
? CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_APPEND’
??? EXPORTING
????? is_layout??????????????????????? = wa_layout
????? it_fieldcat????????????????????? = itab_alv_fieldcatalog
????? i_tabname??????????????????????? = ‘ITAB_ALV’
????? it_events??????????????????????? = itab_alv_event
*?? IT_SORT????????????????????????? =
*?? I_TEXT?????????????????????????? = ‘ ‘
??? TABLES
????? t_outtab???????????????????????? = itab_alv
?? EXCEPTIONS
???? program_error??????????????????? = 1
???? maximum_of_appends_reached?????? = 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.
*添加第2個ALV
? CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_APPEND’
??? EXPORTING
????? is_layout??????????????????????? = wa_layout
????? it_fieldcat????????????????????? = itab_alv_fieldcatalog
????? i_tabname??????????????????????? = ‘ITAB_ALV’
????? it_events??????????????????????? = itab_alv_event
*?? IT_SORT????????????????????????? =
*?? I_TEXT?????????????????????????? = ‘ ‘
??? TABLES
????? t_outtab???????????????????????? = itab_alv
?? EXCEPTIONS
???? program_error??????????????????? = 1
???? maximum_of_appends_reached?????? = 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.
*顯示
? CALL FUNCTION ‘REUSE_ALV_BLOCK_LIST_DISPLAY’
* EXPORTING
*?? I_INTERFACE_CHECK???????????? = ‘ ‘
*?? IS_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?????? =
*?? ES_EXIT_CAUSED_BY_USER??????? =
?? 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.??????????????????? " f_show_alv_bl
*&———————————————————————*
*&????? Form? f_event_all
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_event_all .
*———————————————————————-*
*& 1、
*———————————————————————-*
*types: begin of slis_alv_event,
*??????? name(30),
*??????? form(30),
*????? end of slis_alv_event.
? CASE g_flg_alv.
??? WHEN 1 OR 3.
????? PERFORM f_event.
??? WHEN 2.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_event_all
*&———————————————————————*
*&????? Form? f_event
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_event .
*———————————————————————-*
*& 1、
*———————————————————————-*
? CALL FUNCTION ‘REUSE_ALV_EVENTS_GET’
??? EXPORTING
????? i_list_type???? = 0
??? IMPORTING
????? et_events?????? = itab_alv_event
??? EXCEPTIONS
????? list_type_wrong = 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.??????????????????? " f_event
*&———————————————————————*
*&????? Form? f_field_decimalsout
*&———————————————————————*
*?????? 控制輸出小數位
*———————————————————————-*
FORM f_field_decimalsout .
*———————————————————————-*
*& 1、一般與fieldcatalog中的round字段一起使用
*———————————————————————-*
*???????? decimals_out(6)?? type c,???? " decimals in write statement
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘P’.
????? wa_alv_fieldcatalog-decimals_out = 0."輸出的小數位數
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_decimalsout
*&———————————————————————*
*&????? Form? f_currency_setting
*&———————————————————————*
*?????? 貨幣設置
*———————————————————————-*
*& 1、
*———————————————————————-*
FORM f_currency_setting .
*???????? currency(5)??? type c,
*???????? cfieldname???? type slis_fieldname, " field with currency unit
*???????? ctabname?????? type slis_tabname,?? " and table
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘CURRENCY’.
????? wa_alv_fieldcatalog-cfieldname = ‘CUNIT’.
????? wa_alv_fieldcatalog-ctabname = ‘ITAB_ALV’.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_currency_setting
*&———————————————————————*
*&????? Form? f_field_quantity
*&———————————————————————*
*?????? 數量設置
*———————————————————————-*
*& 1、
*———————————————————————-*
FORM f_field_quantity .
*???????? quantity(3)??? type c,
*???????? qfieldname???? type slis_fieldname, " field with quantity unit
*???????? qtabname?????? type slis_tabname,?? " and table
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘QUANTITY’.
*????? wa_alv_fieldcatalog-quantity = ‘MT’."無效
????? wa_alv_fieldcatalog-qfieldname = ‘QUNIT’.
????? wa_alv_fieldcatalog-qtabname = ‘ITAB_ALV’.
??? WHEN OTHERS.
? ENDCASE.
ENDFORM.??????????????????? " f_field_quantity
*&———————————————————————*
*&????? Form? F_FIELD_EDIT
*&———————————————————————*
*?????? text
*———————————————————————-*
FORM f_field_edit .
? CASE wa_alv_fieldcatalog-fieldname.
??? WHEN ‘MATNR’.
????? wa_alv_fieldcatalog-edit = ‘X’.
??? WHEN OTHERS.
????? wa_alv_fieldcatalog-edit = ”.
? ENDCASE.
ENDFORM.??????????????????? " F_FIELD_EDIT
總結
以上是生活随笔為你收集整理的ABAP实例之ALV的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ABAP--一个不错的函数模块的文档生成
- 下一篇: ABAP 负号 提前