Table Control example

Source: Internet
Author: User
The main functions of table control are implemented, which can be used as an example reference. The functions are editable and can be switched. Select a record and click the button to display details, add records, and delete records, select all records, select all records with the cursor, unselect all, sort, row selection column, column uneditable, fixed column, table control title, paging function, the value of field B is displayed based on the value of field a. If the value of a field is XXX, it cannot be edited. I believe that these functions can meet most development requirements.

Main program code:
Data: OK _code type sy-ucomm,
Save_ OK type sy-ucomm.
Data: l_field type char50,
Rochelle line type I.

Types: Begin of ty_spfli,
Carrid type spfli-carrid,
Connid type spfli-connid,
Countryfr type spfli-countryfr,
Cityfrom type spfli-cityfrom,
Airpfrom type spfli-airpfrom,
Mask (1 ),
End of ty_spfli.

Data g_lines type I.
Data SP2 type table of ty_spfli with header line.

Data SP1 type ty_spfli.

Select * into corresponding fields of table SP2 from spfli.

Controls content type tableview using screen 100.
Content-top_line = 1.
Content-lines = lines (SP2 ).

Call screen 100.

Loop at SP2.
Write:/sp2-carrid, sp2-connid, sp2-countryfr, sp2-cityfrom.
Endloop.

*----------------------------------------------------------------------*
* Module status_0100 output
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
Module status_0100 output.
Set PF-STATUS 'sta '.
Endmodule. "status_0100 output

*----------------------------------------------------------------------*
* Module user_command_0100 Input
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
Module user_command_0100 input.
Save_ OK = OK _code.
Clear OK _code.
Case save_ OK.
When 'exit '.
Leave to screen 0.
When 'sWith '.
Perform f_switch.
When 'sort _ up '.
Perform f_sort using 'up '.
When 'sort _ low '.
Perform f_sort using 'low '.
When 'detail '.
Perform f_detail.
When 'P --'.
Perform f_page using save_ OK.
When 'P -'.
Perform f_page using save_ OK.
When 'P + '.
Perform f_page using save_ OK.
When 'P ++ '.
Perform f_page using save_ OK.
When 'select '.
Perform f_select using 'select '.
When 'block '.
Perform f_select using 'block '.
When 'desselect '.
Perform f_select using 'desselect '.
When 'insert '.
Perform f_row using 'insert '.
When 'delete '.
Perform f_row using 'delete '.
Endcase.
Endmodule. "user_command_0100 Input

*----------------------------------------------------------------------*
* Module filltab output
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
Module filltab output.
Read Table SP2 into SP1 index content-current_line.
Endmodule. "filltab output

*----------------------------------------------------------------------*
* Module readtab Input
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
Module readtab input.
G_lines = sy-loopc.
Modify SP2 from SP1 index content-current_line.
Endmodule. "readtab Input

*----------------------------------------------------------------------*
* Module chang_val Input
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
Module chang_val input.
Data lwa_cols like line of content-cols.

Loop at content-cols into lwa_cols.
If lwa_cols-screen-name = 'sp1-countryfr'
And sp1-countryfr = 'A '.
Sp1-cityfrom = 'sdsd '.
Modify SP2 from SP1 index content-current_line.
Endif.
Endloop.
Endmodule. "chang_val Input

*----------------------------------------------------------------------*
* Module get_cursor Input
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
Module get_cursor input.
Get cursor field l_field line l_line.
Endmodule. "get_cursor Input

*----------------------------------------------------------------------*
* Module set_cursor output
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
Module set_cursor output.
Set cursor field l_field line l_line.
Endmodule. "set_cursor output

*----------------------------------------------------------------------*
* Module set_editable
*----------------------------------------------------------------------*
*
*----------------------------------------------------------------------*
Module set_editable output.
Loop at screen.
If screen-name = 'sp1-cityfrom '.
If sp1-cityfrom = 'sdsd '.
Screen-input = 0.
Modify screen.
Endif.
Endif.
Endloop.
Endmodule. "set_editable

*&---------------------------------------------------------------------*
* & Form f_page
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> Code text
*----------------------------------------------------------------------*
Form f_page using code type sy-ucomm.
Data: I type I,
J type I.
Case code.
When 'P --'.
Content-top_line = 1.
When 'P -'.
Content-top_line = content-top_line-g_lines.
If content-top_line <= 0.
Content-top_line = 1.
Endif.
When 'P + '.
Content-top_line + g_lines.
J = content-lines-g_lines + 1.
If j <= 0.
J = 1.
Endif.
If I <= J.
Content-top_line = I.
Else.
Content-top_line = J.
Endif.
When 'P ++ '.
Content-top_line = content-lines-g_lines + 1.
If content-top_line <= 0.
Content-top_line = 1.
Endif.
Endcase.
Endform. "f_page

*&---------------------------------------------------------------------*
* & Form f_switch
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
Form f_switch.
Data lwa_cols like line of content-cols.

Loop at content-cols into lwa_cols where index> 2.
If lwa_cols-screen-input = 0.
Lwa_cols-screen-input = 1.
Else.
Lwa_cols-screen-input = 0.
Endif.
Modify content-cols from lwa_cols index sy-tabix.
Endloop.
Endform. "f_switch

*&---------------------------------------------------------------------*
* & Form f_sort
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> Code text
*----------------------------------------------------------------------*
Form f_sort using code.
Data: str1 type string,
Str2 type string,
Lwa_cols like line of content-cols.

Read Table content-cols into lwa_cols with key selected = 'x '.

If sy-subrc = 0.
Split lwa_cols-screen-name at '-' into str1 str2.
If code = 'up '.
Sort SP2 stable by (str2) ascending.
Elseif code = 'low '.
Sort SP2 stable by (str2) descending.
Endif.
Lwa_cols-selected = ''.
Modify content-cols from lwa_cols transporting selected where selected = 'x '.
Endif.
Endform. "f_sort

*&---------------------------------------------------------------------*
* & Form f_detail
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
Form f_detail.
Read Table SP2 into SP1 with key mask = 'x '.

If sy-subrc = 0 and sp1-mask = 'x '.
Call function 'popup _ to_display_text'
Exporting
Textline1 = sp1-carrid
Textline2 = sp1-connid.
Endif.
Endform. "f_detail

*&---------------------------------------------------------------------*
* & Form f_select
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> Code text
*----------------------------------------------------------------------*
Form f_select using code.
Case code.
When 'select '.
Sp1-mask = 'x '.
Modify SP2 from SP1 transporting mask where mask is initial.
When 'block '.
Sp1-mask = 'x '.
Modify SP2 from SP1 index l_line transporting mask.
When 'desselect '.
Sp1-mask = ''.
Modify SP2 from SP1 transporting mask where mask = 'x '.
Endcase.
Endform. "f_select

*&---------------------------------------------------------------------*
* & Form f_row
*&---------------------------------------------------------------------*
* Text
*----------------------------------------------------------------------*
* --> Code text
*----------------------------------------------------------------------*
Form f_row using code.
Data lwa_cols like line of content-cols.
Data: l_int type I,
Lt_cols like table of l_int.
Case code.
When 'insert '.
Insert initial line into SP2 index l_line.
When 'delete '.
Delete SP2 where mask = 'x '.
Endcase.
Endform. "f_row

Code of screen 100:
Process before output.
Module status_0100.
Loop with control content.
Module filltab.
Module set_editable.
Endloop.
Module set_cursor.

Process after input.
Loop with control content.
Module readtab.
Module chang_val.
Endloop.
Module get_cursor.
Module user_command_0100.

Gui status settings

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.