開篇無話。
擬從用戶需求、代碼實(shí)現(xiàn)、最終所見所得三方面進(jìn)行闡釋。
第1—— 用戶需求:
假有甲魚哥所需的如下圖所示的業(yè)務(wù)數(shù)據(jù)報(bào)表:(貼圖pict.1)
需求分析過程:
初看得是一個自定義數(shù)據(jù)報(bào)表展示的需求,所需字段描述(字段名)包含:
工單生產(chǎn)工廠(字段:WERKS ),? 工單類型(字段:AUART )
工單編號(字段:AUFNR ),? ? ? ? ? ?產(chǎn)成品物料號(字段:PLNBEZ )
產(chǎn)成品物料描述(字段:MAKTX ), 計(jì)劃完工日期(字段:GLTRS )
計(jì)劃開始日期(字段:GSTRS),? ? ?工單總數(shù)(字段:GAMNG )
已報(bào)工良品數(shù)(字段:GMNGA ),? ? 已報(bào)工廢品數(shù)(字段:XMNGA??)
?工單的系統(tǒng)狀態(tài)(字段:ORSTATUS?)
第2—— ABAP 代碼實(shí)現(xiàn)(完整)??
【SQL 數(shù)據(jù)運(yùn)算獲取部分】
*&---------------------------------------------------------------------*
form getdata.
? clear: git_tab0, wa_tab0.
? select * from afko inner join aufk? on? afko~aufnr = aufk~aufnr? into corresponding fields of? wa_tab0? where
? ? ? ? ? ? ? ? ? aufk~werks in s_werks? and
? ? ? ? ? ? ? ? ? aufk~auart in s_auart? and
? ? ? ? ? ? ? ? ? aufk~aufnr in s_aufnr? and
? ? ? ? ? ? ? ? afko~plnbez in s_plnbez and
? ? ? ? ? ? ? ? afko~gltrs? in? s_gltrs? and
? ? ? ? ? ? ? ? afko~gstrs? in? s_gstrs
? ? ? ? order by? ? aufk~werks? descending? ? afko~gstrs? ? descending? ? ? aufk~aufnr? ? ? descending.
? ? select single? maktx? from? makt into corresponding fields of? wa_tab0 where? makt~matnr =? wa_tab0-plnbez.
? ? select single? gmnga? xmnga? from? afru into corresponding fields of? wa_tab0 where? afru~meilr = 'X'? ? ? ? and
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? afru~aufnr = wa_tab0-aufnr.
? ? perform? get_order_status.
? ? perform? get_unit_conversion.
? ? append wa_tab0? to? git_tab0.
? ? clear wa_tab0.
? endselect.
endform.? ? ? ? ? ? ? ? ? ? "getdata
*&---------------------------------------------------------------------*
■▲▲▲▲▲■完整代碼內(nèi)容:(注釋,后期計(jì)劃無限注釋以便 高2學(xué)生閱讀理解)
REPORT yyyymmdd MESSAGE-ID s05.
tables: afko, "工單表頭數(shù)據(jù)
? ? ? ? aufk, "工單基本數(shù)據(jù)
? ? ? ? makt,? "物料描述表
? ? ? onror.? "工單狀態(tài)描述
types: begin of? ty_gs0,
werks? like aufk-werks,? "工廠
auart? like aufk-auart,? "工單類型
aufnr? like aufk-aufnr,? "工單編號
plnbez like afko-plnbez,? "產(chǎn)成品物料號
maktx? like makt-maktx,? "產(chǎn)成品物料描述
gltrs? like afko-gltrs,? "計(jì)劃完工日期
gstrs? like afko-gstrs,? "計(jì)劃開始日期
gamng? like afko-gamng,? "訂單總數(shù)量
gmein? ? like afko-gmein,? ? "計(jì)量單位轉(zhuǎn)換前
gmeinaft like afko-gmein,? ? "基本計(jì)量單位(轉(zhuǎn)換之后)
orstatus like bsvx-sttxt,? ? "工單狀態(tài)
objnr? ? like onror-objnr,? ? "工單對象號
gmnga? ? like afru-gmnga,? ? "已確認(rèn)良品數(shù)
xmnga? ? like afru-xmnga,? ? "已報(bào)工廢品數(shù)
rowx? ? type c1,? ? ? ? ? ? "整行選中的標(biāo)記
end of ty_gs0.
data:? git_tab0 type standard table of ty_gs0 with non-unique key aufnr,
? ? ? wa_tab0? like line of git_tab0.? ? ? "data:? wa_tab1? type? ty_s1.
type-pools:slis.
data:
? ? ? i_layout? ? ? type? slis_layout_alv,
? ? ? i_fieldcat? ? type? slis_fieldcat_alv,"定義列名工作區(qū)
? ? ? i_fieldcat_alv type? slis_t_fieldcat_alv,"定義列標(biāo)題內(nèi)表
? ? ? i_events? ? ? type? slis_t_event,"alv事件
? ? ? w_events? ? ? like line of i_events,? "定義alv事件的工作區(qū)
? ? ? w_repid? ? ? ? like sy-repid."當(dāng)前程序名
* 選擇屏幕
selection-screen begin of block blk1 with frame title btitle1.
select-options:
s_werks? for? aufk-werks? memory id wer default? '1000' to '3000',? "生產(chǎn)工廠
s_auart for aufk-auart? memory id aua default 'pp01',? "工單類型
s_aufnr for aufk-aufnr? memory id auf,? ? "工單編號
s_plnbez for afko-plnbez memory id pln,? "產(chǎn)成品料號
s_matxt? for makt-maktx? memory id mak,? "產(chǎn)成品物料描述
s_gltrs? for afko-gltrs? memory id glt,? "計(jì)劃完工日期
s_gstrs? for afko-gstrs? memory id gst.? ? "計(jì)劃開始日期
selection-screen end of block blk1.
initialization.
? btitle1 =? '生產(chǎn)工單信息查詢'.
start-of-selection.
? perform getdata.
? perform layout_build.
? perform fieldcat_build.
? perform final_alv_display.
*&---------------------------------------------------------------------*
*&? ? ? Form? getdata
*&---------------------------------------------------------------------*
*? ? ? text
*----------------------------------------------------------------------*
form getdata.
? clear: git_tab0, wa_tab0.
? select * from afko inner join aufk? on? afko~aufnr = aufk~aufnr? into corresponding fields of? wa_tab0? where
? ? ? ? ? ? ? ? ? aufk~werks in s_werks? and
? ? ? ? ? ? ? ? ? aufk~auart in s_auart? and
? ? ? ? ? ? ? ? ? aufk~aufnr in s_aufnr? and
? ? ? ? ? ? ? ? afko~plnbez in s_plnbez and
? ? ? ? ? ? ? ? afko~gltrs? in? s_gltrs? and
? ? ? ? ? ? ? ? afko~gstrs? in? s_gstrs
? ? ? ? order by? ? aufk~werks? descending? ? afko~gstrs? ? descending? ? ? aufk~aufnr? ? ? descending.
? ? select single? maktx? from? makt into corresponding fields of? wa_tab0 where? makt~matnr =? wa_tab0-plnbez.
? ? select single? gmnga? xmnga? from? afru into corresponding fields of? wa_tab0 where? afru~meilr = 'X'? ? ? ? and
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? afru~aufnr = wa_tab0-aufnr.
? ? perform? get_order_status.
? ? perform? get_unit_conversion.
? ? append wa_tab0? to? git_tab0.
? ? clear wa_tab0.
? endselect.
endform.? ? ? ? ? ? ? ? ? ? "getdata
*&---------------------------------------------------------------------*
*&? ? ? Form? unit_exchange
*&---------------------------------------------------------------------*
*? ? ? text
*----------------------------------------------------------------------*
form get_unit_conversion.? "此處通過函數(shù)'CONVERSION_EXIT_CUNIT_OUTPUT'獲取從內(nèi)部值(程序和數(shù)據(jù)庫)到外部值(顯示)的轉(zhuǎn)換
? call function 'CONVERSION_EXIT_CUNIT_OUTPUT'
? ? exporting
? ? ? input? = wa_tab0-gmein
? ? importing
? ? ? output = wa_tab0-gmeinaft.
endform.? ? ? ? ? ? ? ? ? ? "unit_exchange
*&---------------------------------------------------------------------*
*&? ? ? Form? get_order_status
*&---------------------------------------------------------------------*
*? ? ? text
*----------------------------------------------------------------------*
form get_order_status.? " 此處通過函數(shù) 'STATUS_TEXT_EDIT' 獲取工單的系統(tǒng)狀態(tài)
? select single objnr? from? onror? into corresponding fields of? wa_tab0? where? onror~aufnr =? wa_tab0-aufnr.
? call function 'STATUS_TEXT_EDIT'
? ? exporting? "? client = sy-mandt
? ? ? objnr = wa_tab0-objnr? ? ? ? ? ? ? " 單據(jù)號碼
? ? ? spras = 'E'? ? ? ? ? ? ? ? "? BYPASS_BUFFER = ' '
? ? importing
? ? ? line? = wa_tab0-orstatus.? ? " 返回狀態(tài)描述文本
endform.? ? ? ? ? ? ? ? ? ? "get_order_status
*&---------------------------------------------------------------------*
*&? ? ? Form? layout_build
*&---------------------------------------------------------------------*
*? ? ? text
*----------------------------------------------------------------------*
form layout_build.
? i_layout-zebra = 'X'. "ALV表格按斑馬線條紋顯示
? i_layout-colwidth_optimize = 'X'. "將ALV字段寬度設(shè)置為最優(yōu)化
? " i_layout-info_fieldname = 'COLOR'. "設(shè)置顏色FIELD
? i_layout-no_colhead = ''.? ? "顯示列名
? i_layout-box_fieldname = 'ROWX'.
? w_repid = sy-repid.
*"i_layout-info_fieldname = 'COLOR'.? "設(shè)置顏色FIELD
*"i_layout-no_colhead = 'X'.
endform.? ? ? ? ? ? ? ? ? ? "layout_build
*&---------------------------------------------------------------------*
*&? ? ? Form? fieldcat_build
*&---------------------------------------------------------------------*
*? ? ? text
*----------------------------------------------------------------------*
form fieldcat_build.
? define? macron.
? ? i_fieldcat-col_pos = &1.
? ? i_fieldcat-fieldname = &2.
? ? i_fieldcat-seltext_s = &3.
? ? i_fieldcat-lzero = &4.? "字義字段前導(dǎo)以"0"的形式顯示
? ? i_fieldcat-key = &5.
? ? i_fieldcat-hotspot = &6.? "熱點(diǎn)顯示
? ? append i_fieldcat to i_fieldcat_alv.
? ? clear i_fieldcat.
? end-of-definition.
? macron? 1 'WERKS' '生產(chǎn)工廠'? 'X'? ''? ? ''? .
? macron? 2 'AUART' '工單類型' 'X'? ''? ? ''? .
? macron? 3 'AUFNR' '工單編號'? 'X'? ''? ? 'X'? .
? macron? 4 'PLNBEZ' '產(chǎn)成品物料號' 'X'? ''? ? 'X'? .
? macron? 5 'MAKTX' '產(chǎn)成品的物料描述'? 'X'? ''? ? ''? .
? macron? 6 'GLTRS' '計(jì)劃完工日期'? ? 'X'? ''? ? ''? .
? macron? 7 'GSTRS' '計(jì)劃開始日期'? ? 'X'? ''? ? ''? .
? macron? 8 'GAMNG' '工單總數(shù)'? ? 'X'? ''? ? ''? .
? macron? 10 'XMNGA' '報(bào)工廢品數(shù)'? 'X'? ''? ? ''? .
? macron? 9 'GMNGA' '報(bào)工良品數(shù)量'? 'X'? ''? ? ''? .
? macron? 11'GMEINAFT' '計(jì)量單位'? 'X'? ''? ? ''? .
? macron? 12 'ORSTATUS' '工單的系統(tǒng)狀態(tài)'? 'X'? ''? ? ''? .
endform.? ? ? ? ? ? ? ? ? ? "fieldcat_build
*&---------------------------------------------------------------------*
*&? ? ? Form? final_alv_display
*&---------------------------------------------------------------------*
*? ? ? text
*----------------------------------------------------------------------*
form final_alv_display.
? call function 'REUSE_ALV_GRID_DISPLAY'
? ? exporting
? ? ? i_callback_program? ? ? = w_repid
? ? ? is_layout? ? ? ? ? ? ? = i_layout
? ? ? it_fieldcat? ? ? ? ? ? = i_fieldcat_alv[]
? ? ? i_callback_user_command = 'USER_COMMAND' "USER_COMMAND EVENT
? ? tables
? ? ? t_outtab? ? ? ? ? ? ? ? = git_tab0[]? "將內(nèi)表賦值給輸出表
? ? 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.? ? ? ? ? ? ? ? ? ? "final_alv_display
*&---------------------------------------------------------------------*
*&? ? ? Form? user_command
*&---------------------------------------------------------------------*
*? ? ? text
*----------------------------------------------------------------------*
*? ? ? -->I_UCOMM? ? text
*? ? ? -->I_SELFIELD text
*----------------------------------------------------------------------*
form user_command using i_ucomm type sy-ucomm i_selfield type slis_selfield.
? case i_ucomm.
? ? when '&IC1'.? "對于熱點(diǎn)鏈接,所對應(yīng)的動作碼為"&IC1"
? ? ? if i_selfield-fieldname = 'AUFNR' or
? ? ? ? i_selfield-fieldname = 'PLNBEZ'.
? ? ? ? perform call_tran using i_selfield. "調(diào)用自定義事務(wù)
? ? ? endif.
? endcase.
endform.? ? ? ? ? ? ? ? ? ? "user_command
*&---------------------------------------------------------------------*
*&? ? ? Form? call_tran
*&---------------------------------------------------------------------*
*? ? ? text
*----------------------------------------------------------------------*
*? ? ? -->I_SELFIELD text
*----------------------------------------------------------------------*
form call_tran using i_selfield type slis_selfield.
? read table git_tab0? into? wa_tab0? index i_selfield-tabindex.? "i_selfield-tabindex 當(dāng)擊行索引,從內(nèi)表中提取數(shù)據(jù)
? case i_selfield-fieldname.
? ? when 'AUFNR'.
? ? ? set parameter id 'ANR' field wa_tab0-aufnr. " 工單編號的參數(shù)ID 為ANR
? ? ? call transaction 'CO03'."AND SKIP FIRST SCREEN "調(diào)用CO03事務(wù)碼
? ? when? 'PLNBEZ'.
? ? ? set parameter id 'MAT' field wa_tab0-plnbez. " 物料編號的參數(shù)ID 為MAT
? ? ? call transaction 'MM03'."AND SKIP FIRST SCREEN "調(diào)用MM03事務(wù)碼
? endcase.
endform.? ? ? ? ? ? ? ? ? ? "call_tran
第3—— 用戶之所見:(貼圖 pict.2? ? 貼圖 pict.3)
甲魚哥之所見:
查詢結(jié)果:
(~~完完~~)