Skip to Content
author's profile photo Former Member
Former Member

Table control Access fields

Hi All,

I have 2 queries regarding table control.

<b>1.</b> Is it possible to access the table control changed text from screen? How?

Here I have to display the data in table control & when user selects change the changed text is to be saved in data base table when user selects save after making the changes.

<b>2.</b>How to enable only one selected row for updation.

Here if I say change all the rows are enabled for change mode.

Thanks & Regards,

Dilip

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

3 Answers

  • Best Answer
    Posted on Aug 01, 2005 at 08:20 AM

    Hi,

    To make selected rows for editable mode,

    MODULE set_screen_fields OUTPUT.

     LOOP AT SCREEN.
           IF ( ( screen-name = 'I_MAKT-ZMAKTX'
                 OR screen-name = 'I_MAKT-CHECK1' )
                AND <b>t_ctrl-current_line</b> LE ln ) .
    * Making the screen fields as editable
            screen-input = 1.
    ELSEIF ( ( screen-name = 'I_MAKT-ZMATNR' )
                     AND t_ctrl-current_line LE ln ).
    * Making the screen field as uneditable
            screen-input = 0.
          ENDIF.
        MODIFY SCREEN.
      ENDLOOP.
    ENDMODULE.                 " set_screen_fields  OUTPUT
    

    Here is the sample code for table control.

    PROCESS BEFORE OUTPUT.
    
      MODULE set_status.
    
      MODULE get_t_ctrl_lines.
      LOOP AT i_makt WITH CONTROL t_ctrl CURSOR t_ctrl-current_line.
    * Dynamic screen modifications
        MODULE set_screen_fields.
      ENDLOOP.
    
    *
    PROCESS AFTER INPUT.
    
      LOOP AT i_makt.
        FIELD i_makt-pick MODULE check.
        FIELD i_makt-zmatnr MODULE zmatnr .
      ENDLOOP.
    
      MODULE user_command_9000.
    
    
    In the program, write the following code.
    
    PROGRAM SAPMZTC MESSAGE-ID zz.
    
    * Tables Declaration
    TABLES: zzz_makt.
    
    * Internal table Declaration
    DATA : i_makt TYPE STANDARD TABLE OF zzz_makt WITH HEADER LINE.
    
    * Table control Declaration
    CONTROLS: t_ctrl TYPE TABLEVIEW USING SCREEN '9000'.
    
    * Variable Declaration
    DATA : flg,           "Flag to set the change mode
           ln TYPE i.     "No. of records
    
    MODULE get_t_ctrl_lines OUTPUT.
      SELECT zmatnr zmaktx
             INTO CORRESPONDING FIELDS OF TABLE i_makt
             FROM zzz_makt.
      DESCRIBE TABLE i_makt LINES ln.
    * To make the vertical scroll bar to come on runtime
      t_ctrl-lines = ln + 100.
    ENDMODULE.                 " get_T_CTRL_lines  OUTPUT
    
    MODULE user_command_9000 INPUT.
      DATA :lv_fcode LIKE sy-ucomm,    "Function Code
            lv_answer(1) type c.       "Storing the answer
      lv_fcode = sy-ucomm.
      CASE lv_fcode.
        WHEN 'CHANGE'.
    * Setting the flag to make the table control in editable mode[excluding
    * primary key].
          flg = 'Y'.
        WHEN 'DELETE'.
    * Setting the flag to make the table control in editable mode after
    * deleting the selected line
          flg = 'Y'.
    * Confirmation of delete
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
             TITLEBAR       = 'Confirm'
             text_question  = 'Are you sure to delete from database?'
             TEXT_BUTTON_1  = 'Yes'(001)
             TEXT_BUTTON_2  = 'No'(002)
            IMPORTING
             ANSWER         =  lv_answer.
          if lv_answer eq '1'.
    * Updating the database table from the internal table
            UPDATE zzz_makt FROM TABLE i_makt.
    * Deleting the selected row from the internal table
            DELETE i_makt WHERE pick = 'X'.
    * Deleting the selected row from the database table
            DELETE FROM zzz_makt WHERE pick = 'X'.
            MESSAGE s005 WITH 'Deleted Successfully'.
          ENDIF.
        WHEN 'SAVE'.
    * Inserting new record or updating existing record in database table
    * from the internal table
          MODIFY zzz_makt FROM TABLE i_makt.
          MESSAGE s005 WITH 'Saved Successfully'.
        WHEN 'BACK'.
          SET SCREEN '0'.
        WHEN 'EXIT' OR 'CANCEL'.
    * Leaving the program
          LEAVE PROGRAM.
      ENDCASE.
    ENDMODULE.                 " USER_COMMAND_9000  INPUT
    
    MODULE set_screen_fields OUTPUT.
      LOOP AT SCREEN.
        IF flg IS INITIAL.
          screen-input = 0.
        ELSEIF ( flg EQ 'Y' ).
          IF ( ( screen-name = 'I_MAKT-ZMAKTX'
                 OR screen-name = 'I_MAKT-CHECK1' )
                AND t_ctrl-current_line LE ln ) .
    * Making the screen fields as editable
            screen-input = 1.
          ELSEIF ( ( screen-name = 'I_MAKT-ZMATNR' )
                     AND t_ctrl-current_line LE ln ).
    * Making the screen field as uneditable
            screen-input = 0.
          ENDIF.
        ENDIF.
    * Modifying the screen after making changes
        MODIFY SCREEN.
      ENDLOOP.
    ENDMODULE.                 " set_screen_fields  OUTPUT
    
    MODULE zmatnr INPUT.
      MODIFY i_makt INDEX t_ctrl-current_line.
      IF t_ctrl-current_line GT ln.
        READ TABLE i_makt WITH KEY zmatnr = i_makt-zmatnr.
        IF sy-subrc NE 0.
    * Inserting record if it does not exist in database
          APPEND i_makt.
        ELSE.
         MESSAGE i005 WITH 'Material Number' i_makt-zmatnr 'already exists'.
        ENDIF.
      ENDIF.
    ENDMODULE.                 " zmatnr  INPUT
    
    MODULE set_status OUTPUT.
      SET PF-STATUS 'ZSTATUS'.
      SET TITLEBAR  'ZTITLE'.
    ENDMODULE.                 " set_status  OUTPUT
    
    MODULE check INPUT.
      MODIFY i_makt INDEX t_ctrl-current_line.
    ENDMODULE.                 " CHECK  INPUT

    Hope it helps.If so,kindly reward points.Otherwise get back.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2005 at 07:48 AM

    Hi,

    1, To access the changed fields in the table control, declare an internal table with the same name as table control and the fields (inside the internal table) same as the table control fields(probably, u could have used such an internal table for poping up the data to the table control).

    Now, Use the Loop at <internal table> statement in the PAI, which gets the data from the table control row by row and places in the header of the internal table. Then use the modify statement to update the internal table.

    2, Check the SCREEN structure for the particular columnname and make the INPUT field as 1 for enabling updation.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Aug 01, 2005 at 09:10 AM

    Hi,

    1. It is possible to access the data from the table

    control.

    Declare a same internal table like Table control, so that data will be automatically available in that.

    2. In order to make the field editable,

    Loop at screen.

    Check for the table control field with field name and make it editable using "Screen_input = 1".

    endloop.

    Cheers,

    Venkat

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.