使用动态内表——ALV输出
最近開發(fā)在執(zhí)海關(guān)合同維護(hù)系統(tǒng)時(shí),對進(jìn)口料件的匯總,由于欄位顯示與出口成品的品種多少相關(guān),所以顯示的欄位是不確定的,為此研究了一番。
同樣,在報(bào)關(guān)時(shí),不管是對出口成品還是進(jìn)口料件報(bào)關(guān),欄位顯示都與出口成品品種或進(jìn)口料件品種相關(guān)。在同一行上顯示所有的出口成品或進(jìn)口料件,對于操作人員來說都是一件易操作的表現(xiàn)。
?
程序設(shè)計(jì)要注意事項(xiàng):
第一、?? 每一張合同中出口成品品種數(shù)量的多少確定;
第二、?? 每一種或每類出口成品共同屬性是否具有相同性,比如在進(jìn)口料件匯總表中對于每一類出口成品都有單耗、損耗,數(shù)量,耗邊料數(shù)特性。
第三、?? 進(jìn)口料件匯總表固定列位確定。
第四、?? 動態(tài)創(chuàng)建內(nèi)表區(qū)域。
?
動態(tài)創(chuàng)建報(bào)關(guān)數(shù)量登記表:
?perform?container_free_2.
?perform?create_structure_1?USING?len?'進(jìn)口料件'.
?perform?create_table_display_2.
?perform?ctable_for_atci.
?
form?container_free_2.
???if?not?g_custom_container_2?is?initial?.
?????call?method??g_custom_container_2->free.
?????clear?g_custom_container_2.
???endif.
endform.
?
form?create_structure_1?USING?II?mtart.??"報(bào)關(guān)出口成品相關(guān)處理
??DATA?:?ERTXT?TYPE?string,
?????????ERTTX?TYPE?string,
?????????ERNUM?TYPE?string,
?????????ERIND?TYPE?I.
??clear?it_structure[].
??wa_structure-fieldname?=?'BGDHA'.??"?第一列列名??????報(bào)關(guān)單號
??wa_structure-col_pos???=?1.???????"?表示第一列
??wa_structure-inttype?=?'C'.???????"?數(shù)據(jù)類型
??wa_structure-intlen?=?18.??????????"?長度
??wa_structure-decimals?=?0?.
??wa_structure-ref_table?=?''?.
??wa_structure-ref_field?=?''?.
??wa_structure-coltext?=?'報(bào)關(guān)單號'?.
??wa_structure-seltext?=?'報(bào)關(guān)單號'?.
??wa_structure-just?=?'C'?.
??wa_structure-edit?=?'X'?.
??wa_structure-outputlen?=?18?.
??wa_structure-fix_column?=?'X'?.
??APPEND?wa_structure?TO?it_structure.
??wa_structure-fieldname?=?'BUDAT'.?????????????"報(bào)關(guān)日期
??wa_structure-col_pos???=?2.
??wa_structure-inttype?=?'D'.
??wa_structure-intlen?=?18.
??wa_structure-decimals?=?0?.
??wa_structure-ref_table?=?'ZSD19ATCI'?.
??wa_structure-ref_field?=?'BUDAT'?.
??wa_structure-coltext?=?'日期'?.
??wa_structure-seltext?=?'日期'?.
??wa_structure-just?=?'C'?.
??wa_structure-edit?=?'X'?.
??wa_structure-outputlen?=?12?.
??wa_structure-fix_column?=?'X'?.
??APPEND?wa_structure?TO?it_structure.
??erind?=?2?.
??DO?II?TIMES.
????ernum?=?ernum?+?1?.
????erind?=?erind?+?1.
????CONCATENATE?'ERFMG'?ernum?into?ERTXT.
????CONCATENATE?mtart?ernum?into?ERTTX.
????CONDENSE?ERTXT?NO-GAPS.
????CONDENSE?ERTTX?NO-GAPS.
????wa_structure-fieldname?=?ERTXT.?????????????"報(bào)關(guān)數(shù)量,對應(yīng)每一個出口成品
????wa_structure-col_pos???=?erind.
????wa_structure-inttype?=?'P'.
????wa_structure-intlen?=?13.
????wa_structure-decimals?=?3?.
????wa_structure-ref_table?=?'ZSD19ATCI'?.
????wa_structure-ref_field?=?'ERFMG'?.
????wa_structure-coltext?=?ERTTX?.
????wa_structure-seltext?=?ERTTX?.
????wa_structure-just?=?'R'?.
????wa_structure-edit?=?'X'?.
*????wa_structure-do_sum?=?'X'.
????wa_structure-outputlen?=?13?.
????wa_structure-fix_column?=?''?.
????APPEND?wa_structure?TO?it_structure.
??ENDDO.
endform.
?
?
form?create_table_display_2.
??create?object?g_custom_container_2
?????????exporting?container_name?=?g_container_2.
??create?object?g_grid
?????????exporting?i_parent?=?g_custom_container_2.
endform.
?
form?ctable_for_atci.
???data:?gs_layout?type?lvc_s_layo.
???data:?lt_exclude?type?ui_functions.
???data:?retxt?type?string,
?????????renum?type?string.
???clear?gt_fieldcat[]?.
???clear?it_fieldcat[].
???perform?exclude_tb_functions?changing?lt_exclude.
???perform?cfield_atci?using?''?changing?gt_fieldcat?it_fieldcat.
???perform?f4_alv_field.
???assign?new_table->*?to?<l_table>.
???create?data?new_line?like?line?of?<l_table>.
???assign?new_line->*?to?<l_line>.
???clear?<l_table>[].
???create?data?old_table?like?<l_table>.
???assign?old_table->*?to?<old_table>.
*???<l_table>[]?=?t_sunh[]?.
???loop?at?r_atci.
??????ASSIGN?COMPONENT?'BGDHA'?OF?STRUCTURE?<l_line>?TO?<l_field>.
??????<l_field>?=?r_atci-bgdha.
??????ASSIGN?COMPONENT?'BUDAT'?OF?STRUCTURE?<l_line>?TO?<l_field>.
??????<l_field>?=?r_atci-budat.
??????loop?at?t_atci?where?hname?=?r_atci-hname?and?bgdha?=?r_atci-bgdha?and?budat?=?r_atci-budat.
??????????clear?s_atci.
??????????read?table?s_atci?with?key?hname?=?t_atci-hname?extwg?=?t_atci-extwg.
??????????renum?=?sy-tabix.
??????????concatenate?'ERFMG'?renum?into?retxt.
??????????ASSIGN?COMPONENT?retxt?OF?STRUCTURE?<l_line>?TO?<l_field>.
??????????<l_field>?=?t_atci-erfmg.
??????endloop.
??????INSERT?<l_line>?INTO?TABLE?<l_table>.
???endloop.
???set?handler?z_receiver->handle_before_user_command?for?g_grid.
???set?handler?z_event_double->handle_onf4?for?g_grid.
???call?method?g_grid->register_edit_event
???????????exporting
???????????????i_event_id?=?cl_gui_alv_grid=>mc_evt_enter.
???call?method?g_grid->register_f4_for_fields
??????exporting
????????it_f4?=?lt_f4.
???call?method?g_grid->set_table_for_first_display
??????exporting
???????is_layout????????????=?gs_layout
???????it_toolbar_excluding?=?lt_exclude
???????i_save????????????????????????=?'A'
*???????i_buffer_active???????????????=?'X'
??????changing
*??????IT_SORT??????????=?GB_SORTFLD
???????it_outtab????????????=?<l_table>[]
???????it_fieldcatalog??????=?gt_fieldcat[]
???????it_sort??????????????=?gt_sort?.
??call?method?g_grid->set_ready_for_input?"處于非編輯狀態(tài)
??????????exporting
????????????i_ready_for_input?=?1.
?????call?method?cl_gui_control=>set_focus????"設(shè)置焦點(diǎn)在go_grid?上
?????????exporting
???????????control?=?g_grid?.
??????????<old_table>[]?=?<l_table>[].
??CALL?METHOD?cl_gui_cfw=>flush
????EXCEPTIONS
??????cntl_system_error?=?1
??????cntl_error????????=?2.
endform.?????????"ctable_for_atci
?
form?cfield_atci?using?dab?changing?pt_fieldcat?type?lvc_t_fcat?ft_fieldcat?type?lvc_t_fcat.
?data?:?stnum?type?i.
?clear?lf_fieldcat[].
?loop?at?it_structure?into?wa_structure.
?“宏
???m_fieldcat?wa_structure-fieldname?wa_structure-ref_table??wa_structure-ref_field?wa_structure-coltext?wa_structure-just?wa_structure-edit?wa_structure-outputlen?wa_structure-fix_column.
?endloop.
?loop?at?lf_fieldcat.
???if?lf_fieldcat-fieldname?=?'BGDHA'?OR?lf_fieldcat-fieldname?=?'BUDAT'?.?"設(shè)置關(guān)鍵字段
???????lf_fieldcat-key?=?'X'?.
???????lf_fieldcat-F4AVAILABL?=?'X'.
???????modify?lf_fieldcat?index?sy-tabix.
???endif.
???if?lf_fieldcat-ref_field?=?'ERFMG'.
???????lf_fieldcat-do_sum?=?'X'?.???????????"匯總求和
???????lf_fieldcat-no_zero?=?'X'?.??????????"隱藏零
???????modify?lf_fieldcat?index?sy-tabix.
???endif.
???if?lf_fieldcat-fieldname?=?'ERFMO'.
????????lf_fieldcat-coltext?=?dab.
????????lf_fieldcat-emphasize?=?'C601'?.?????"紅色
???????modify?lf_fieldcat?index?sy-tabix.
???endif.
???if?lf_fieldcat-fieldname?=?'ZJLYL'.
????????lf_fieldcat-emphasize?=?'C601'?.?????"紅色
???????modify?lf_fieldcat?index?sy-tabix.
???endif.
???if?lf_fieldcat-fieldname+0(4)?=?'FLAG'.
????????lf_fieldcat-emphasize?=?'C61'?.?????"深紅色
???????modify?lf_fieldcat?index?sy-tabix.
???endif.
?endloop.
?append?lines?of?lf_fieldcat?to?pt_fieldcat.
?clear?lf_fieldcat[].
?loop?at?it_structure?into?wa_structure.
???st_fieldcat?wa_structure-fieldname?wa_structure-col_pos?wa_structure-inttype?wa_structure-intlen??wa_structure-decimals.
?endloop.
?append?lines?of?lf_fieldcat?to?ft_fieldcat?.
?clear?new_table?.
?call?method?cl_alv_table_create=>create_dynamic_table
??????exporting
????????it_fieldcatalog?=?it_fieldcat
??????importing
????????ep_table????????=?new_table.
endform.??????????????????"cfield_atci
轉(zhuǎn)自:http://blog.chinaunix.net/u1/50618/showart_1915346.html
總結(jié)
以上是生活随笔為你收集整理的使用动态内表——ALV输出的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: ALV列(Column)换到行(Row)
- 下一篇: ABAP OLE相关的应用