Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Pressing Enter On Table control

Former Member
0 Kudos

Hi Friends

I am having a problem with a table control.

I want to use a table control for user input.

I have painted a screen and placed a table control on it.

When i execute the program this screen appears first.Now when i enter some data in the table control and press "ENTER" button(of keyboard) then the data in the table control disappears.

I wants that that after pressing ENTER the data should display(remain) in table control unless until i dont press any submit button of my screen.

(I have created table control with reference to an internal table and all the fields are of input output type.)

9 REPLIES 9

Former Member
0 Kudos

Hi,

You will have to write logic to reflect the changed data on screen to the Internal table. if the data is already there in the Table Control and you are changing the values you will have to include this logic in the Table Control Loop in the PAI.

MODIFY t_schst FROM wa_schst INDEX tc_schst-current_line.

where T_SCHST is the Internal table

WA_SCHST is the Work area

TC_SCHST is the Table Control.

If the data is not present in the Internal table at all and you are inserting new data in the screen , you will have to append data into your Internal Table.

Former Member
0 Kudos

See the following simple ex for table control. Compare with ur program.

PROGRAM ZTEST_TBLCTRL.

***&SPWIZARD: DATA DECLARATION FOR TABLECONTROL 'TC1'

*&SPWIZARD: DEFINITION OF DDIC-TABLE

TABLES: ZFG_SRNO, ZFIH0004.

*&SPWIZARD: TYPE FOR THE DATA OF TABLECONTROL 'TC1'

*TYPES: BEGIN OF T_TC1,

  • ZSRNO LIKE ZFG_SRNO-ZSRNO,

    • SCRNAME LIKE ZFIH0004-SCRNAME,

  • END OF T_TC1.

*TYPES: BEGIN OF T_TC1.

  • STRUCTURE ZFG_SRNO.

  • END OF T_TC1.

*&SPWIZARD: INTERNAL TABLE FOR TABLECONTROL 'TC1'

*DATA: G_TC1_ITAB TYPE T_TC1 OCCURS 0 WITH HEADER LINE,

  • G_TC1_WA TYPE T_TC1. "work area

DATA: G_TC1_ITAB LIKE ZFG_SRNO OCCURS 0 WITH HEADER LINE,

G_TC1_WA LIKE G_TC1_ITAB. "work area

DATA: G_TC1_COPIED. "copy flag

*&SPWIZARD: DECLARATION OF TABLECONTROL 'TC1' ITSELF

CONTROLS: TC1 TYPE TABLEVIEW USING SCREEN 0100.

*&SPWIZARD: LINES OF TABLECONTROL 'TC1'

DATA: G_TC1_LINES LIKE SY-LOOPC.

DATA: OK_CODE LIKE SY-UCOMM,

S_CODE LIKE SY-UCOMM,

MARK.

DATA: T1(10).

*&SPWIZARD: OUTPUT MODULE FOR TC 'TC1'. DO NOT CHANGE THIS LINE!

*&SPWIZARD: COPY DDIC-TABLE TO ITAB

MODULE TC1_INIT OUTPUT.

  • IF G_TC1_COPIED IS INITIAL.

*&SPWIZARD: COPY DDIC-TABLE 'ZFG_SRNO'

*&SPWIZARD: INTO INTERNAL TABLE 'g_TC1_itab'

  • SELECT * FROM ZFG_SRNO

  • INTO CORRESPONDING FIELDS

  • OF TABLE G_TC1_ITAB.

  • G_TC1_COPIED = 'X'.

  • REFRESH CONTROL 'TC1' FROM SCREEN '0100'.

IF T1 <> SPACE.

G_TC1_ITAB-ZSRNO = T1.

CLEAR T1.

APPEND G_TC1_ITAB.

REFRESH CONTROL 'TC1' FROM SCREEN '0100'.

ENDIF.

*TC1-TOP_LINE = 1.

  • ENDIF.

ENDMODULE.

*&SPWIZARD: OUTPUT MODULE FOR TC 'TC1'. DO NOT CHANGE THIS LINE!

*&SPWIZARD: MOVE ITAB TO DYNPRO

MODULE TC1_MOVE OUTPUT.

MOVE-CORRESPONDING G_TC1_WA TO ZFG_SRNO.

  • if sy-subrc ne 0.

*append G_TC1_WA to G_TC1_ITAB.

*endif.

  • READ TABLE G_TC1_ITAB INDEX TC1-CURRENT_LINE.

  • IF SY-SUBRC = 0.

  • G_TC1_WA-ZSRNO = G_TC1_ITAB-ZSRNO.

  • ENDIF.

  • MOVE-CORRESPONDING G_TC1_ITAB TO ZFG_SRNO.

  • REFRESH CONTROL 'TC1' FROM SCREEN '8001'.

tc1-lines = G_TC1_LINES + 100.

ENDMODULE.

*&SPWIZARD: OUTPUT MODULE FOR TC 'TC1'. DO NOT CHANGE THIS LINE!

*&SPWIZARD: GET LINES OF TABLECONTROL

MODULE TC1_GET_LINES OUTPUT.

G_TC1_LINES = SY-LOOPC.

ENDMODULE.

*&SPWIZARD: INPUT MODULE FOR TC 'TC1'. DO NOT CHANGE THIS LINE!

*&SPWIZARD: MODIFY TABLE

MODULE TC1_MODIFY INPUT.

*break-point.

  • MOVE-CORRESPONDING ZFG_SRNO TO G_TC1_ITAB.

  • MODIFY G_TC1_ITAB INDEX TC1-CURRENT_LINE.

  • G_TC1_COPIED = 'X'.

  • REFRESH CONTROL 'TC1' FROM SCREEN '8001'.

**************This is where u have to put the logic************

MOVE-CORRESPONDING ZFG_SRNO TO G_TC1_WA.

MODIFY G_TC1_ITAB

FROM G_TC1_WA

INDEX TC1-CURRENT_LINE.

G_TC1_COPIED = 'X'.

if sy-subrc ne 0.

append G_TC1_WA to G_TC1_ITAB.

endif.

*modify G_TC1_ITAB INDEX TC1-CURRENT_LINE.

ENDMODULE.

&----


*& Module D20XX_INIT OUTPUT

&----


  • text

----


MODULE D20XX_INIT OUTPUT.

*if screen-name = 'ZSRNO'.

  • SCREEN-INPUT = 0.

  • SCREEN-COLOR = 0.

  • MODIFY SCREEN.

  • endif.

ENDMODULE. " D20XX_INIT OUTPUT

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE STATUS_0100 OUTPUT.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

*CLEAR R1_REF.

  • DO 30 TIMES.

  • APPEND G_TC1_ITAB.

  • ENDDO.

DESCRIBE TABLE G_TC1_ITAB LINES TC1-LINES.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module TAB1_INIT OUTPUT

&----


  • text

----


MODULE TAB1_INIT OUTPUT.

ENDMODULE. " TAB1_INIT OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE USER_COMMAND_0100 INPUT.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Module MESSAGE INPUT

&----


  • text

----


MODULE MESSAGE INPUT.

OK_CODE = SY-UCOMM.

S_CODE = OK_CODE.

CLEAR OK_CODE.

if S_CODE = 'DELE'.

loop at G_TC1_ITAB.

  • if G_TC1_ITAB-scrname = 'X'.

  • delete g_tc1_itab.

  • endif.

endloop.

ELSEIF S_CODE = 'SAVE'.

G_TC1_WA-ZSRNO = T1.

MOVE-CORRESPONDING G_TC1_WA TO ZFG_SRNO.

REFRESH CONTROL 'TC1' FROM SCREEN '0100'.

ENDIF.

ENDMODULE. " MESSAGE INPUT

&----


*& Module DELETE_RECORD INPUT

&----


  • text

----


MODULE DELETE_RECORD INPUT.

IF MARK = 'X' AND S_CODE = 'DELE'.

DELETE TABLE G_TC1_ITAB FROM ZFG_SRNO.

DESCRIBE TABLE G_TC1_ITAB LINES TC1-LINES.

ENDIF.

ENDMODULE. " DELETE_RECORD INPUT

*********************Screen modules*********************

PROCESS BEFORE OUTPUT.

*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'TC1'

MODULE TC1_INIT.

*&SPWIZARD: MODULE TC1_CHANGE_TC_ATTR.

*&SPWIZARD: MODULE TC1_CHANGE_COL_ATTR.

LOOP AT G_TC1_ITAB

INTO G_TC1_WA

WITH CONTROL TC1

CURSOR TC1-CURRENT_LINE.

*&SPWIZARD: MODULE TC1_CHANGE_FIELD_ATTR

MODULE TC1_MOVE.

  • MODULE TAB1_INIT.

  • MODULE TC1_GET_LINES.

ENDLOOP.

MODULE D20XX_INIT.

MODULE STATUS_0100.

*

PROCESS AFTER INPUT.

*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TC1'

*BREAK POINT.

LOOP AT G_TC1_ITAB.

CHAIN.

FIELD ZFG_SRNO-ZSRNO.

MODULE TC1_MODIFY ON CHAIN-REQUEST.

  • MODULE TC1_MODIFY.

ENDCHAIN.

MODULE MESSAGE .

MODULE DELETE_RECORD.

ENDLOOP.

MODULE TC1_USER_COMMAND.

*&SPWIZARD: MODULE TC1_CHANGE_TC_ATTR.

*&SPWIZARD: MODULE TC1_CHANGE_COL_ATTR.

MODULE USER_COMMAND_0100.

Former Member
0 Kudos

Hi

I guess something is wrong when u transfer data between the program and the screen

check in ur pbo and pai of the screen that u transfer the data correctly.

Here is an example :

REPORT demo_dynpro_tabcont_loop_at.

CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.

DATA cols LIKE LINE OF flights-cols.

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 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'.

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'.

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.

*flow logic of screen 100

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.

Hope this helps u.

Regards,

Prasanth

  • Reward all helpful replies

0 Kudos

Hi prashant

Actually i am not transffering data from program to screen.

i m fetching the data from the screen back to the internal table, and the i m successfuly getting the same .

But the problem is when i enter some data in table control and press 'Enter' Button, although the data is recording into my internal table but the screen's table control is refreshed means when the user enters some data, he ussualy press enter (this is usual habit of users with SAP screen, they always press enter after putting some entry), then the data he entered in table control is not showing.

The Internal table i m passing to table control is totally blank, it is filled when user enter some data in table control and enter Submit button on the screen...

0 Kudos

Hi,

you need to write code for the ENTER key in the PAI to update the internal table with the user entered data in the table control. For this you need to check function what system is passing. Then with that function code write in the user command and update the internal table with the user entered value.

Br,

Laxmi

Former Member
0 Kudos

Hi sukhjinder singh,

I tried to insert records into an internal table using a table control i.e using table control as an input box.

<b><u>Program code is as follows:</u></b>

&----


*& Module Pool ZTESTTCTRL

*&

&----


*&

*&

&----


PROGRAM ZTESTTCTRL.

ABLES: ZVENDORSTAT1. " USE ANY TRANSP. TABLE OR STRUCTURE

DATA: ITAB TYPE TABLE OF ZVENDORSTAT1 WITH HEADER LINE.

data: okcode type sy-ucomm,

save_okcode type sy-ucomm.

controls: ztc type tableview using screen 143.

----


  • MODULE ztc_getrecord INPUT

----


*

----


module ztc_getrecord input.

move-corresponding itab to itab.

endmodule. "ztc_getrecord INPUT

----


  • MODULE change_0143 INPUT

----


*

----


module change_0143 input.

SAVE_OKCODE = OKCODE.

CLEAR OKCODE.

case save_okcode.

when ' '.

INSERT ITAB INTO TABLE ITAB." INDEX ZTC-CURRENT_LINE.

ENDCASE.

endmodule. "change_0143 INPUT

<u><b>Screen Code:[/</b>u]

PROCESS BEFORE OUTPUT.

*module ztc_initial.

loop at itab with control ztc cursor ztc-current_line.

module ztc_getrecord.

endloop.

MODULE STATUS_0143.

PROCESS AFTER INPUT.

loop at itab.

chain.

field: itab-bukrs,

itab-lifnr,

itab-vendor_type,

itab-status.

module change_0143 on chain-request.

endchain.

endloop.

  • MODULE USER_COMMAND_0143.

It works fine. Hope it solves your problem!!

Former Member
0 Kudos

hi,

To retain the data after u press the 'ENTER' key, check the ok_code for ' ' (SPACE).

Find the no.of lines in the internal table store it in a temporary variable

( for eg FILL ) .

Increment it.

read the internal table into work area for the incremented value .

Append work area to the internal table . ( so tht it doesn disappear ) .

CONTROLS tabctrl TYPE TABLEVIEW USING SCREEN 100.

DATA: ok_code TYPE sy-ucomm,

save_ok TYPE sy-ucomm.

DATA: itab TYPE TABLE OF zvi_tab2,

fill TYPE i.

tables : zvi_tab2 .

select * from zvi_tab2 into table itab .

call screen 100 .

MODULE FILL_TABLE_CONTROL output .

read table itab into zvi_tab2 index tabctrl-current_line.

endmodule .

MODULE USER_COMMAND_0100 .

save_ok = ok_code.

clear ok_code.

<b>case save_ok.

when ' ' .

describe table itab lines fill.

fill = fill + 1 .

read table itab into zvi_tab2 index fill.

append zvi_tab2 to itab.

endcase.</b>

endmodule.

MODULE modify_TABLE_CONTROL input.

MODIFY itab FROM zvi_tab2 INDEX tabctrl-current_line.

endmodule.

flow logic :

PROCESS BEFORE OUTPUT.

  • MODULE STATUS_0100.

LOOP WITH CONTROL tabctrl.

MODULE FILL_TABLE_CONTROL.

ENDLOOP.

PROCESS AFTER INPUT.

MODULE USER_COMMAND_0100.

LOOP WITH CONTROL tabctrl.

MODULE modify_TABLE_CONTROL.

ENDLOOP.

Regards ,

viji

Former Member
0 Kudos

Hi Sukhjinder signh ,

I think u are using Sy-UCOMM, for Function code.

If yes dont go for it , try to make use of OKCODE available in screen element lis Gen. attributes aginst TYPE OK.

In Program declare a Variable of samename and proceed further with that variable.

Always clear varaible for command after it trigger.

Hope this will solve your problem.

Tx

Parthi

Kindly reward point if helpfull.

Former Member
0 Kudos

hi sukhjinder,

in the pai module of the screen

case sy-ucomm.

when 'ENTER'.

CLEAR SY-UCOMM.

leave to screen <screen_number>.

endcase.

note :

where screen_number is the screen number of the same screen wit the table control..

place the above code in a module after the loop in the pai if u want the changes u made in the table to reflect.

else

if u dont want the changes to reflect in the table control place it befor the loop in pai.

all the best!!

Regards,

Aparna