Function call ALV

Source: Internet
Author: User
Tags html header

Original post address: http://qiqeloveyou.blogbus.com/logs/28050604.html

 

Copyright Notice
: During reprinting, please use hyperlinks to indicate the original source and author information of the article and this statement

Http://qiqeloveyou.blogbus.com/logs/28050604.html

Type-pools slis.

Types: Begin of st_alvoutput,
Weight type ZR2TRAIN-WEIGHT ,"
Weight_c (13 ),
Car_sum type ZR2LIPS_S-CAR_SUM ,"
Uname like SY-UNAME,
Sel (1), "select ID
End of st_alvoutput,

* ----------------------------- ALV define --------------------------------
Data: is_layout type slis_layout_alv, "ALV output style
It_fieldcat type slis_t_fieldcat_alv, "ALV output Header project (internal table)
Wa_fieldcat type slis_fieldcat_alv, "ALV output Header project (work zone)
Wa_repid like sy-repid. "program name

Data: it_events type slis_t_event, "event (internal table)
Wa_events like line of it_events. "event (workspace)

Data: it_list_top_comments type slis_t_listheader,
Wa_list_top_comments like line of it_list_top_comments,
It_list_end_comments type slis_t_listheader,
Wa_list_end_comments like line of it_list_end_comments.

* ************ Sort
Data: wa_sort type slis_sortinfo_alv,
It_sort type slis_t_sortinfo_alv.

* ----------------------------- Macro ------------------------------------
Define add_fieldcat.
Fields in the WA_FIELDCAT-FIELDNAME = & 1. "inner table
WA_FIELDCAT-REPTEXT_DDIC = & 2. "name displayed in ALV
WA_FIELDCAT-JUST = & 3. "Horizontal alignment, l left alignment, r right alignment.
WA_FIELDCAT-NO_OUT = & 4 ."
WA_FIELDCAT-INTLEN = & 5. "width of the output Column
WA_FIELDCAT-EMPHASIZE = & 6. "output background color
Append wa_fieldcat to it_fieldcat.
End-of-definition.

 

* ------------------------ Display format: Content Header --------------------------
Form fieldcat_init.

Wa_repid = sy-repid. "obtain the program name.
IS_LAYOUT-ZEBRA = 'x'. "Color Display
IS_LAYOUT-DETAIL_POPUP = 'x'. "Show Details window
IS_LAYOUT-BOX_FIELDNAME = 'sel '. "flag selected in ALV row
IS_LAYOUT-F2CODE = '& ETA'. "Set the function code to pop up the detail window, which is double-click
IS_LAYOUT-COLWIDTH_OPTIMIZE = 'x'. "optimized column width Option
IS_LAYOUT-DETAIL_TITLEBAR = 'cool '. "Set the title bar of the pop-up window
* IS_LAYOUT-DETAIL_INITIAL_LINES = 'x '."
* Is_layout-no_hline = 'x'. "This sets the line Interval
* Is_layout-no_vline = 'x'. "This sets the column delimiter

Add_fieldcat '''. "The macro definition content is called to display the header.

Endform. "fieldcat_init

* ------------------------- Event --------------------------------
Form set_top_page.
Call function 'reuse _ alv_events_get'
Exporting
I _list_type = 0
Importing
Et_events = it_events. "Get the event table.

Read Table it_events
With key name = slis_ev_top_of_page "header event
Into wa_events.
If sy-subrc = 0.
Move 'alv _ top_of_page 'to the wa_events-form. "form corresponding to the header event
Modify it_events from wa_events index sy-tabix.
Endif.
* Read Table it_events
* With key name = slis_ev_end_of_list
* Into wa_events.
* If sy-subrc = 0.
* Move 'alv _ end_of_page 'to wa_events-form.
* Modify it_events from wa_events index sy-tabix.
* Endif.
Endform. "set_topend_page

* ------------------ Form ------------------------------ corresponding to the header event --------------------------
Form alv_top_of_page.
Clear: it_list_top_comments.

Wa_list_top_comments-typ = 'H'. "H = header, S = selection, A = action
Wa_list_top_comments-key = ''.
Wa_list_top_comments-info = ''.
Append wa_list_top_comments to it_list_top_comments.

Call function 'reuse _ alv_commentary_write'
Exporting
It_list_commentary = it_list_top_comments.

Endform. "alv_top_of_page

* ----------------------- Form ------------------------------ of the HTML Header ----------------------------
Form alv_top_of_page1 using cl_dd type ref to cl_dd_document.
Data: m_p type I.
Data: m_buff type string.
* The header can actually be an HTML file, and you can use the HTML language to control the format.
M_buff = '<HTML> '.
Call method cl_dd-> html_insert
Exporting
Contents = m_buff
Changing
Position = m_p.

M_buff = '<center> <H2> accessory decommissioned varieties summary table </H2> </center> '.
Call method cl_dd-> html_insert
Exporting
Contents = m_buff
Changing
Position = m_p.

Concatenate 'report Date: '000000' to '000000' <br> 'into m_buff.
Call method cl_dd-> html_insert
Exporting
Contents = m_buff
Changing
Position = m_p.

M_buff = 'Call method cl_dd-> html_insert
Exporting
Contents = m_buff
Changing
Position = m_p.
Endform. "alv_top_of_page

* ------------------------- Add the ALV function button --------------------------------
Form set_status using rt_extab type slis_t_extab.
Set PF-STATUS 'alvtest' excluding rt_extab.
Endform. "set_status

* ------------------------ Add button event ---------------------------------
Form user_command using rf_ucomm like sy-ucomm
Rs_selfield type slis_selfield.
Case rf_ucomm.
When 'excel '.
* Perform excel_output.
* Call function 'zpetrochina _ excel_output'
* Exporting
* Excel_template = c_exceltemplate
* Macro = 'write _ cell'
* Exit_program = wa_repid
* Exit_subroutine = 'sub _ addition_excel'
* Tables
* Data_source = it_exceldata.
When' & ic1'. "Double-click
R_ucomm = '& ETA'. "forcibly associate the double-click event to F2
Endcase.
Endform. "user_command

* --------------------------- Call ALV to display --------------------------------

Form output_data.
Perform fieldcat_init.
Perform set_top_page.
* ************ Sort
WA_SORT-FIELDNAME = 'hkont '. "Sort field name
WA_SORT-UP = 'x'. "in ascending order
WA_SORT-SPOS = '01 '.
Append wa_sort to it_sort.
* ************** Endsort
Call function 'reuse _ alv_grid_display'
Exporting
I _callback_program = wa_repid
I _callback_pf_status_set = 'set _ status' "add ALV function button
I _callback_user_command = 'user _ command' "added the button response code.
Is_layout = is_layout "display style
It_sort = it_sort "Sort/control display sort
It_fieldcat = it_fieldcat "Content Header
I _save = 'A' "allows you to save the Variant
* I _callback_html_top_of_page = 'alv _ top_of_page1 '"can be added to headers in HTML format.
* I _callback_html_end_of_list = 'alv _ top_of_page1 '"can be added to the end of an HTML table.
It_events = it_events
Tables
T_outtab =. "data source internal table
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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.