table controls

Upload: neelima-chowdary

Post on 06-Apr-2018

219 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/3/2019 Table Controls

    1/18

    Table Controls: Examples with Modifications

    The following example processes a table control with LOOP with parallel loop using an internaltable. By using function codes you can sort columns and delete rows from the internal table. The

    ready for input status of the table control fields is controlled using a function code.

    REPORT demo_dynpro_tabcont_loop_at.

    CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.DATA: cols LIKE LINE OF flights-cols,lines TYPE i.

    DATA: ok_code TYPE sy-ucomm,save_ok TYPE sy-ucomm.

    DATA: itab TYPE TABLE OF demo_conn.

    TABLES demo_conn.

    SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.

    LOOP AT flights-cols INTO cols WHERE index GT 2.cols-screen-input = '0'.MODIFY flights-cols FROM cols INDEX sy-tabix.

    ENDLOOP.

    CALL SCREEN 100.

    MODULE status_0100 OUTPUT.SET PF-STATUS 'SCREEN_100'.

    DESCRIBE TABLE itab LINES lines.flights-lines = lines.ENDMODULE.

    MODULE cancel INPUT.LEAVE PROGRAM.

    ENDMODULE.

    MODULE read_table_control INPUT.

    MODIFY itab FROM demo_conn INDEX flights-current_line.ENDMODULE.

    MODULE user_command_0100 INPUT.save_ok = ok_code.CLEAR ok_code.CASE save_ok.

    WHEN 'TOGGLE'.LOOP AT flights-cols INTO cols WHERE index GT 2.

    IF cols-screen-input = '0'.

    http://help.sap.com/SAPhelp_nw04/helpdata/en/9f/dbac5e35c111d1829f0000e829fbfe/frameset.htm
  • 8/3/2019 Table Controls

    2/18

    cols-screen-input = '1'.ELSEIF cols-screen-input = '1'.cols-screen-input = '0'.

    ENDIF.MODIFY flights-cols FROM cols INDEX sy-tabix.

    ENDLOOP.WHEN 'SORT_UP'.READ TABLE flights-cols INTO cols WITH KEY selected =

    'X'.IF sy-subrc = 0.

    SORT itab STABLE BY (cols-screen-name+10) ASCENDING.cols-selected = ' '.

    MODIFY flights-cols FROM cols INDEX sy-tabix.ENDIF.

    WHEN 'SORT_DOWN'.READ TABLE flights-cols INTO cols WITH KEY selected =

    'X'.IF sy-subrc = 0.

    SORT itab STABLE BY (cols-screen-name+10)DESCENDING.

    cols-selected = ' '.MODIFY flights-cols FROM cols INDEX sy-tabix.

    ENDIF.WHEN 'DELETE'.READ TABLE flights-cols INTO cols

    WITH KEY screen-input = '1'.IF sy-subrc = 0.

    LOOP AT itab INTO demo_conn WHERE mark = 'X'.DELETE itab.

    ENDLOOP.ENDIF.

    ENDCASE.ENDMODULE.

    The layout of screen 100 is:

  • 8/3/2019 Table Controls

    3/18

    A resizable table control called FLIGHTS is defined. The fields of the tablecontrol are transferred from the structure DEMO_CONN in the ABAP Dictionary.The first two columns are lead columns. The corresponding fields are outputfields. A title bar, columns headers, and a selection column are created. Thecomponent MARK of type character with length 1 from structure DEMO_CONN isassigned to the selection column. You can select one column and several lines.

    It has the following flow logic:

    PROCESS BEFORE OUTPUT.MODULE status_0100.LOOP AT itab INTO demo_conn WITH CONTROL flights.

    ENDLOOP.

    PROCESS AFTER INPUT.MODULE cancel AT EXIT-COMMAND.LOOP AT itab.

    MODULE read_table_control.ENDLOOP.MODULE user_command_0100.

    A loop is executed at PBO and PAI using the table control FLIGHTS and is also

    executed using the internal table ITAB of the ABAP program. During the PBOloop, no module is called to fill the table control from table ITAB of the ABAPprogram. However, during the PAI loop, a module is called to modify table ITAB.

    At PBO the component LINES of control structure FLIGHTS is filled explicitly withthe current number of rows of the internal table before the PBO loop to install thescroll bar of the table control.

  • 8/3/2019 Table Controls

    4/18

    During the PBO loop, in the module FILL_TABLE_CONTROL the work areaDEMO_CONN is filled with values from the internal table, where the row indexcorresponds to the current row of the table control.

    During the PAI loop, the rows of the internal table, whose row index correspondsto the current row of the table control, are overwritten with the contents of the

    work area DEMO_CONN. User input is transferred from the input fields of thecontrol to the internal table. In particular, the internal table also contains a flag inthe column MARK to indicate whether the row of the table control is selected ornot.

    After the PAI loop, user input is processed in the module USER_COMMAND.The GUI status SCREEN_100 provides the appropriate function codes.

    When the program is called not all of the fields in the table control are ready forinput. The static specifications of the table control in the Screen Painter aremodified before CALL SCREEN in the program. The system uses the tableCOLS in control structure FLIGHTS. All columns with a column position largerthan two are set to not ready for input status in a loop using the table FLIGHT-

    COLS. By choosing the function code TOGGLE, you can change the ready forinput status of the columns.

    The function codes SORT_UP and SORT_DOWN allow you to sort selectedcolumns of the internal table ITAB ascending or descending. The static settingsof the table control allow you to select only a single column. The selected columnis derived from the internal table FLIGHT-COLS. The name of the sort criteria inthe SORT statement is determined dynamically from the component COLS-SCREEN-NAME. The prefix DEMO_CONN- must be removed using an offsetspecification. After sort the selection is undone, and the component SELECTEDin table FLIGHT-COLS is assigned a blank character.

    You can delete selected rows from the internal table ITAB using the function

    code DELETE. First the system checks whether the fields of the table control areready for input. Then all selected rows are deleted in a loop using the internaltable ITAB. Since the table control is read again from the internal table in thePBO loop, the rows on the screen are deleted.

  • 8/3/2019 Table Controls

    5/18

    Back to ABAP Program Stations

    SAP Table Control Example

    This example shows how to build a table control using ABAP. The program

    builds a simple phone list. The code and accompanying screen shots describe

    the entire procedure.

    SCREEN 100

    PROCESS BEFORE OUTPUT.

    MODULE STATUS_0100.

    LOOP WITH CONTROL TCTRL_USERDATA.

    MODULE DISPLAY_USERDATA.

    ENDLOOP.

    MODULE AFTER_LOOPING.

    *

    PROCESS AFTER INPUT.

    MODULE USER_COMMAND_0100.

    LOOP WITH CONTROL TCTRL_USERDATA.

    MODULE EXTRACT_USERDATA.

    ENDLOOP.

    MODULE USER_COMMAND_0100_AFTER_LOOP.

    ZTBLDTOP

    *&---------------------------------------------------------------------*

    *& Include ZTBLDEMO Report ZTBLDEMO *

    *& *

    http://sgstocks.tripod.com/abap.htmhttp://adtrack.ministerial5.com/clicknew/?a=637394http://sgstocks.tripod.com/abap.htm
  • 8/3/2019 Table Controls

    6/18

    *&---------------------------------------------------------------------*

    REPORT ZTBLDEMO MESSAGE-ID AT .

    DATA: BEGIN OF RECORD,

    NAME(30),

    PHONE(20),

    EMAIL(50),

    END OF RECORD.

    DATA: ITAB_PHONELIST LIKE RECORD OCCURS 0 WITH HEADER LINE.

    CONTROLS: TCTRL_PHONELIST TYPE TABLEVIEW USING SCREEN 100.

    DATA: SAVE_CODE(4),

    OK_CODE(4),

    FILENAME LIKE RLGRAP-FILENAME,

    CONFIRMATION,

    SELECTION.

    ZTBLDEMO

    *&---------------------------------------------------------------------*

    *& Report ZUSRDATA *

    *& *

    *&---------------------------------------------------------------------*

    *& *

    *& *

    *&---------------------------------------------------------------------*

  • 8/3/2019 Table Controls

    7/18

    INCLUDE ZTBLDTOP. " global Data

    * INCLUDE ZUSRDO01. " PBO-Modules *

    * INCLUDE ZUSRDI01. " PAI-Modules *

    * INCLUDE ZUSRDF01. " FORM-Routines *

    *&---------------------------------------------------------------------*

    *& Module STATUS_0100 OUTPUT

    *&---------------------------------------------------------------------*

    * text

    *----------------------------------------------------------------------*

    MODULE STATUS_0100 OUTPUT.

    SET PF-STATUS 'FOR100'.

    SET TITLEBAR '100'.

    ENDMODULE. " STATUS_0100 OUTPUT

    *&---------------------------------------------------------------------*

    *& Module DISPLAY_USERDATA OUTPUT

    *&---------------------------------------------------------------------*

    * text

    *----------------------------------------------------------------------*

    MODULE DISPLAY_USERDATA OUTPUT.

    READ TABLE ITAB_PHONELIST INDEX TCTRL_PHONELIST-CURRENT_LINE.

    IF SY-SUBRC EQ 0.

    RECORD-NAME = ITAB_PHONELIST-NAME.

    RECORD-PHONE = ITAB_PHONELIST-PHONE.

    RECORD-EMAIL = ITAB_PHONELIST-EMAIL.

    ELSE.

  • 8/3/2019 Table Controls

    8/18

    EXIT FROM STEP-LOOP.

    ENDIF.

    ENDMODULE. " DISPLAY_USERDATA OUTPUT

    *&---------------------------------------------------------------------*

    *& Module USER_COMMAND_0100 INPUT

    *&---------------------------------------------------------------------*

    * text

    *----------------------------------------------------------------------*

    MODULE USER_COMMAND_0100 INPUT.

    SAVE_CODE = OK_CODE.

    CLEAR OK_CODE.

    CASE SAVE_CODE.

    WHEN 'BACK'.

    CALL FUNCTION 'COPO_POPUP_TO_GOON'

    EXPORTING

    TEXTLINE1 = 'Any modifications will be lost!'

    TEXTLINE2 = 'Are you sure?'

    TITEL = 'Exit The Program'

    IMPORTING

    answer = confirmation.

    if confirmation = 'G'.

    LEAVE PROGRAM.

    ENDIF.

    WHEN 'DELE'.

    CALL FUNCTION 'COPO_POPUP_TO_GOON'

    EXPORTING

    TEXTLINE1 = 'Selected rows will be deleted!'

    TEXTLINE2 = 'Are you sure?'

  • 8/3/2019 Table Controls

    9/18

    TITEL = 'Delete rows'

    IMPORTING

    answer = confirmation.

    IF CONFIRMATION = 'G'.

    REFRESH ITAB_PHONELIST.

    CLEAR ITAB_PHONELIST.

    ENDIF.

    WHEN 'SAVE'.

    REFRESH ITAB_PHONELIST.

    CLEAR ITAB_PHONELIST.

    WHEN 'APND'.

    REFRESH ITAB_PHONELIST.

    CLEAR ITAB_PHONELIST.

    WHEN 'READ'.

    IF NOT FILENAME IS INITIAL.

    CALL FUNCTION 'COPO_POPUP_TO_GOON'

    EXPORTING

    TEXTLINE1 = 'Any modifications will be lost!'

    TEXTLINE2 = 'Are you sure?'

    TITEL = 'Read Another File'

    IMPORTING

    answer = confirmation.

    ENDIF.

    if confirmation = 'G' or

    FILENAME IS INITIAL.

    CALL FUNCTION 'UPLOAD'

    EXPORTING

    FILENAME =

  • 8/3/2019 Table Controls

    10/18

    'c:\temp\fonelist.txt'

    IMPORTING

    ACT_FILENAME = FILENAME

    TABLES

    DATA_TAB = ITAB_PHONELIST.

    ENDIF.

    ENDCASE.

    ENDMODULE. " USER_COMMAND_0100 INPUT

    *&---------------------------------------------------------------------*

    *& Module EXTRACT_USERDATA INPUT

    *&---------------------------------------------------------------------*

    * text

    *----------------------------------------------------------------------*

    MODULE EXTRACT_USERDATA INPUT.

    CASE SAVE_CODE.

    WHEN 'DELE'.

    IF SELECTION IS INITIAL AND

    confirmation = 'G'.

    PERFORM TRANSFER.

    ENDIF.

    WHEN 'SAVE'.

    PERFORM TRANSFER.

    WHEN 'APND'.

    PERFORM TRANSFER.

    ENDCASE.

    ENDMODULE. " EXTRACT_USERDATA INPUT

    *&---------------------------------------------------------------------*

    *& Form TRANSFER

  • 8/3/2019 Table Controls

    11/18

    *&---------------------------------------------------------------------*

    * text

    *----------------------------------------------------------------------*

    * --> p1 text

    *

  • 8/3/2019 Table Controls

    12/18

    APPEND ITAB_PHONELIST. " a blank row being added.

    ENDCASE.

    ENDMODULE. " USER_COMMAND_0100_AFTER_LOOP INPUT

    Field List

    GUI Status

    Objects

  • 8/3/2019 Table Controls

    13/18

    Table Attributes

    Table Columns

  • 8/3/2019 Table Controls

    14/18

  • 8/3/2019 Table Controls

    15/18

    Table Controls in ABAP ProgramsTo handle table controls in ABAP programs, you must declare a control in the declaration part of

    the program for each table control using the following statement:

    CONTROLS ctrl TYPE TABLEVIEW USING SCREEN scr.

    where ctrl is the name of the table control on a screen in the ABAP program. The control allows

    the ABAP program to read the attributes of the table control and to influence the control. Thestatement also declares a deep structure of name ctrl. The data type of the structure

    corresponds to the type CXTAB_CONTROL defined in the type group CXTAB in the ABAPDictionary.

    At runtime the components of the structure contain the attributes of the table control. Several ofthe initial values are determined in the Screen Painter. The initial value for the control ctrl is

    taken from the screen which is determined using the addition USING.

    You can start a screen sequence from an ABAP program using

    REFRESH CONTROL ctrl FROM SCREEN scr.you can initialize a table control at any time with the initial value of a screen scr. Values that are

    not taken from the settings in the Screen Painter, are set to the current status of the table controlat PAI.

    Structure CXTAB_CONTROLThe deep structure CXTAB_CONTROL contains the general attributes of the table control on thehighest level. The component CXTAB_CONTROL is a table of the structure CXTAB_COLUMNand contains the attributes of a column. The component CXTAB_CONTROL-COLS-SCREEN is aflat structure of the same type as system table screen and contains the attributes of the

    individual screen elements.

    Up to component CURRENT_LINE, all attributes of the structure CXTAB_CONTROL in the ABAPprogram can be set to change the table control display on the screen.

    http://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbac9f35c111d1829f0000e829fbfe/frameset.htm
  • 8/3/2019 Table Controls

    16/18

    Components of CXTAB_CONTROLThe structure CXTAB_CONTROL has the following components:

    Component Type (Length) Meaning In the ScreenPainter:

    FIXED_COLS INT4 Number of lead columns. Transferredfrom Screen Painter. Can bechanged in the ABAP program.

    Fixed columns

    LINES INT4 Controls the scroll bar of the tablecontrol. At LOOP without internal

    table, LINES has the initial value zeroand must be set in the program sothat the scroll bar can be used.At LOOP AT itab the system sets

    this component to the number ofrows of the internal table, wheneverthe table control is processed for thefirst time. The initialization event of a

    table control is not determineduniquely. If the corresponding internaltable is not fully created at this event,then the LINES variable receives anincorrect value. If LINES inthe LOOP loop is smaller as the

    number of rows of the internal table,then the table control contains blankrows at the end.

    Therefore you should always set theLINES component explicitly in theABAP program, including at LOOP

    AT itab. In this way you have full

    control over the dimensions of thevertical scroll bar and so can controlthe number of rows that are ready forinput. Initialization should usuallyoccur at PBO directly beforetheLOOP statement for the table

    control.

    TOP_LINE INT4 Top row at next PBO. Set at PAI byposition of the vertical slider box. Canbe changed in the ABAP program.

    CURRENT_LINE INT4 Current line in the loop. Setautomatically in the LOOP loop to the

    value sy-stepl+(TOP_LINE-1). Nochanges allowed in the ABAPprogram.

    LEFT_COL INT4 First displayed horizontal scrollablecolumn after the lead column. Set atPAI by position of the horizontalslider box. LEFT_COL contains theabsolute number of the columnindependent of any column shift by

  • 8/3/2019 Table Controls

    17/18

    the user. Can be changed in theABAP program.

    LINE_SEL_MODE INT4 Row selection mode: 0, 1, 2 for none,one or multiple rows can be selected.Transferred from Screen Painter.Can be changed in the ABAPprogram.

    Row selection

    COL_SEL_MODE INT4 Column selection mode: 0, 1, 2 for none, one or multiple rows can beselected. Transferred from ScreenPainter. Can be changed in theABAP program.

    Column selection

    LINE_SELECTOR CHAR(1) Flag (X or blank) for selectioncolumn. Transferred from ScreenPainter. Can be changed in theABAP program.

    Selection column

    H_GRID CHAR(1) Flag (X or blank) for horizontal

    separators. Transferred from ScreenPainter. Can be changed in theABAP program.

    Separators

    V_GRID CHAR(1) Flag (X or blank) for verticalseparators. Transferred from ScreenPainter. Can be changed in theABAP program.

    Separators

    COLS CXTAB_COLUMN Control table for single columns (seebelow).

    INVISIBLE CHAR(1) Flag (X or blank) for visibility of entiretable control.

    Internal table CXTAB_COLUMN is a component of the structure CXTAB_CONTROL.

    Components of CXTAB_COLUMNEach column of the table control corresponds to a row of the table CXTAB_COLUMN. Theinternal table CXTAB_COLUMN has no header line and the following columns:

    Component Type (Length) Meaning

    SCREEN SCREEN Structure for the attributes of screen elements of thecolumn (see below).

    INDEX INT4 Current position of the column in the table control.Transfered with initial value from Screen Painter. At PAIthe current column configuration of the table control is

    withdrawn. Can be changed in the ABAP program.

    SELECTED CHAR(1) Flag (X or blank) whether column is selected or not. At PAIthe current status of the table control is withdrawn. Can bechanged in the ABAP program.

    VISLENGTH INT4 Visible length of the column. Transferred from ScreenPainter. Can be changed in the ABAP program.

    INVISIBLE CHAR(1) Flag (X or blank) whether column is visible. Transferredfrom Screen Painter. Can be changed in the ABAP

  • 8/3/2019 Table Controls

    18/18

    program.

    The structure screen is a column of the table CXTAB_COLUMN.

    Components of SCREENThe component SCREEN-NAME is the name of the screen element that creates the column. The

    initial values of the remaining components correspond to the attributes of the screen elements inthe Screen Painter. The attributes are transferred from here with initial values. They can bechanged directly in the ABAP program. Note that directly set values can be overwritten bymodifying these attributes usingMODIFY SCREEN within the loop LOOP AT SCREEN.

    Furthermore, note that the attributes of the structure screen are not set with blank characters

    and X, but are set with 0 and 1 as in the normal processing ofscreen.

    Scrolling in Table ControlsScrolling with scroll bars is automatically implemented with table controls, and managed by thesystem. However, the componentctrl-LINES must be set to the required row number before

    editing the table control. This is the case for table controls with or without parallel loops using aninternal table. The component LINES is set implicitly for table controls with parallel loops using aninternal table, although the correct value is not guaranteed (see table above). It is therefore

    recommended that in both instances you set the component LINES explicitly to the number ofrows in the internal table of the ABAP program. You can determine this number from thestatement DESCRIBE TABLE (see the following example).

    The event PAI with an empty function code is triggered when scrolling using scroll bars. When theloops at PAI and PBO are executed, the system sets the component TOP_LINE of the structureCXTAB_CONTROL before PBO, so that the correct row is edited at the loop pass.

    You can easily implement program-controlled vertical scrolling (line by line, page by page, or gotopage) by using the component of the structure CXTAB_CONTROL. Essentially the componentTOP_LINE must be provided with a value. For page by page scrolling, the number of rows to bescrolled during the loop pass can be taken from the system field sy-loopc. sy-loopccontains

    the number of rows currently display, whereas the component LINES of structureCXTAB_CONTROL contains the number of all rows in the table control.

    Cursor Position on Table ControlsAt PBO you can set the cursor on a specific field of a specific row of a table control.

    SET CURSOR FIELD f LINE lin [OFFSET off].

    Using the optional addition OFFSET, you can enter the offset of the cursor in the field as

    described underSetting the Cursor Position.

    At PAI you can read the current cursor position.

    GET CURSOR FIELD f LINE lin ...

    In addition to the information given underFinding Out the Cursor Position, field lin contains

    information on which row of the table control the cursor is currently on. You can also use

    GET CURSOR LINE lin.

    . sy-subrc allows you to check if the cursor is placed in a row of a table control.

    http://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbab6f35c111d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbac0b35c111d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbac0b35c111d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbac0b35c111d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbabf135c111d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbabf135c111d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbab6f35c111d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbac0b35c111d1829f0000e829fbfe/content.htmhttp://help.sap.com/saphelp_nw04s/helpdata/en/9f/dbabf135c111d1829f0000e829fbfe/content.htm