Application Development and Automation 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: 
Read only

Table Control: How to accept input using a table control?

Former Member
0 Likes
4,089

Hi All,

I have a development where I need to accept inputs from user:

Example:

PLANT MATERIAL BATCH

XX01 44001001 TEST01

XX01 44001001 TEST01

XX01 44002001 TEST02

I know how to display data using Table Control (TC) but I need more info on how to use TC for accepting data then appending it to a table instead of displaying data.

Thanks.

1 ACCEPTED SOLUTION
Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
2,959

Hi,

Refer

it_zekpo is my internal table w/o header line,

wa_zekpo is work area.

Name of input/output fields on screen are:-

wa_zekpo-field1,

wa_zekpo-field2, and so on...

Take a button on the screen with function-code SAVE or in the pf-status take the function code of the standard save button as SAVE.

Use code:-

At screen logic:-


PROCESS BEFORE OUTPUT.
*  MODULE status_8003.
 
  LOOP WITH CONTROL po_tab. "po_tab is table control on screen 8003
    MODULE read_data.
  ENDLOOP.
 
PROCESS AFTER INPUT.
*  MODULE user_command_8003.
 
  LOOP WITH CONTROL po_tab.
    MODULE modify_data.
  ENDLOOP.

  MODULE SAVE_DATA.

In PBO:-


*&---------------------------------------------------------------------*
*&      Module  READ_DATA  OUTPUT
*&---------------------------------------------------------------------*
MODULE read_data OUTPUT.
  READ TABLE it_zekpo INTO wa_zekpo INDEX po_tab-current_line. "po_tab is table control name
 
  data : line_count type i.
 
  describe it_zekpo
  lines line_count.
  po_tab-lines = line_count + 10.
  "to increase the number of lines in table control dynamically
 
ENDMODULE.                 " READ_DATA  OUTPUT

In PAI:-


*&---------------------------------------------------------------------*
*&      Module  MODIFY_DATA  INPUT
*&---------------------------------------------------------------------*
MODULE MODIFY_DATA INPUT.
  MODIFY IT_ZEKPO FROM WA_ZEKPO INDEX po_tab-currentline.
  "this will modify the contents of existing line
ENDMODULE.                 " MODIFY_DATA  INPUT

*&---------------------------------------------------------------------*
*&      Module  SAVE_DATA  INPUT
*&---------------------------------------------------------------------*
MODULE SAVE_DATA INPUT.

  DATA : A LIKE SY-DBCNT.
  OK_CODE = SY-UCOMM.
  CASE OK_CODE.
    WHEN 'SAVE'. "function code for SAVE button
      MODIFY ZEKPO FROM TABLE IT_ZEKPO.
      A = SY-DBCNT.
      IF SY-SUBRC = 0.
        MESSAGE S008 WITH A.
      ENDIF.
  ENDCASE.

ENDMODULE.                 " SAVE_DATA  INPUT

Now when you put in new entries in the table control and perform any user action, the records will be appended to the internal table and when you click SAVE button, the records will be inserted into the DATABASE table as well.

Hope this helps you.

Regards,

Tarun

14 REPLIES 14
Read only

Former Member
0 Likes
2,959

And here's the code:


PROCESS BEFORE OUTPUT.
  MODULE CLEAR_OKCODE.
  MODULE LOAD_TABLECTRL.
  LOOP AT T_TEST INTO WA_TEST WITH CONTROL TC_ID.
    MODULE POPULATE_TABLECTRL.
  ENDLOOP.
* MODULE STATUS_9001.

PROCESS AFTER INPUT.
* MODULE USER_COMMAND_9001.
  LOOP AT T_TEST.
    
  ENDLOOP.

module LOAD_TABLECTRL output.
   SELECT * FROM ZTEST INTO CORRESPONDING FIELDS OF TABLE T_TEST.
endmodule.                 " LOAD_TABLECTRL  OUTPUT

module POPULATE_TABLECTRL output.
  IF sy-stepl = 1.
      TC_ID-lines = TC_ID-top_line + sy-loopc - 1.
  ENDIF.
  MOVE-CORRESPONDING WA_TEST TO Z_TEST.
endmodule.    

Read only

0 Likes
2,959

Well, basically this thread is for Table Control that can accept input instead of displaying it. Thanks.

Read only

venkat_o
Active Contributor
0 Likes
2,959

Hi, <li>Flow logic of the screen

PROCESS BEFORE OUTPUT.
      MODULE status_0100.
      LOOP AT itab WITH CONTROL tabc.
      ENDLOOP.

    PROCESS AFTER INPUT.
      MODULE cancel AT EXIT-COMMAND.
      LOOP AT itab.
        MODULE read_table_control.
      ENDLOOP.
      MODULE user_command_0100.
<li>Code for read_table_control
MODULE read_table_control INPUT.
   MODIFY itab INDEX tabc-current_line."This statement update itab table which is used to show data on table control
 ENDMODULE.
Thanks Venkat.O

Read only

Former Member
0 Likes
2,959

Hi Jaime Cabanban,

To display data in table control , you use a loop in PBO.

Similarily to read data from the table control , you have a loop in PAI.

if you run a loop in PAI , it reads a line from table control and place it in work area then you can append it to internal table.

Assign a value to TC-lines = '20' which enables you to add 20 lines . You can dynamicaly increase it if you want.

This is how you do .

The coding is already given by others.

Read only

I355602
Product and Topic Expert
Product and Topic Expert
0 Likes
2,960

Hi,

Refer

it_zekpo is my internal table w/o header line,

wa_zekpo is work area.

Name of input/output fields on screen are:-

wa_zekpo-field1,

wa_zekpo-field2, and so on...

Take a button on the screen with function-code SAVE or in the pf-status take the function code of the standard save button as SAVE.

Use code:-

At screen logic:-


PROCESS BEFORE OUTPUT.
*  MODULE status_8003.
 
  LOOP WITH CONTROL po_tab. "po_tab is table control on screen 8003
    MODULE read_data.
  ENDLOOP.
 
PROCESS AFTER INPUT.
*  MODULE user_command_8003.
 
  LOOP WITH CONTROL po_tab.
    MODULE modify_data.
  ENDLOOP.

  MODULE SAVE_DATA.

In PBO:-


*&---------------------------------------------------------------------*
*&      Module  READ_DATA  OUTPUT
*&---------------------------------------------------------------------*
MODULE read_data OUTPUT.
  READ TABLE it_zekpo INTO wa_zekpo INDEX po_tab-current_line. "po_tab is table control name
 
  data : line_count type i.
 
  describe it_zekpo
  lines line_count.
  po_tab-lines = line_count + 10.
  "to increase the number of lines in table control dynamically
 
ENDMODULE.                 " READ_DATA  OUTPUT

In PAI:-


*&---------------------------------------------------------------------*
*&      Module  MODIFY_DATA  INPUT
*&---------------------------------------------------------------------*
MODULE MODIFY_DATA INPUT.
  MODIFY IT_ZEKPO FROM WA_ZEKPO INDEX po_tab-currentline.
  "this will modify the contents of existing line
ENDMODULE.                 " MODIFY_DATA  INPUT

*&---------------------------------------------------------------------*
*&      Module  SAVE_DATA  INPUT
*&---------------------------------------------------------------------*
MODULE SAVE_DATA INPUT.

  DATA : A LIKE SY-DBCNT.
  OK_CODE = SY-UCOMM.
  CASE OK_CODE.
    WHEN 'SAVE'. "function code for SAVE button
      MODIFY ZEKPO FROM TABLE IT_ZEKPO.
      A = SY-DBCNT.
      IF SY-SUBRC = 0.
        MESSAGE S008 WITH A.
      ENDIF.
  ENDCASE.

ENDMODULE.                 " SAVE_DATA  INPUT

Now when you put in new entries in the table control and perform any user action, the records will be appended to the internal table and when you click SAVE button, the records will be inserted into the DATABASE table as well.

Hope this helps you.

Regards,

Tarun

Read only

Former Member
0 Likes
2,959

Hi Tarun,

In your PAI code, I debug it in my code code, but it seems like it is not reading the entries in the table control, am I missing something?

Let's say I have 5 entries, so I would expect 5 loops should go through the po_tab right?


PROCESS AFTER INPUT.
  LOOP WITH CONTROL po_tab.
    MODULE modify_data.
  ENDLOOP.

MODULE SAVE_DATA.

Read only

Former Member
0 Likes
2,959

Hi, Are you trying something like this? This is used to take input from the table control into the internal table.


PROCESS AFTER INPUT.
  LOOP WITH CONTROL po_tab.
    MODULE modify_data.
  ENDLOOP.
MODULE SAVE_DATA.


module modify_data input
  if sy-ucomm eq 'SAVE'.
    wa_itab-field1 = ztab-field1.
    wa_itab-field2 = ztab-field2.
    wa_itab-field3 = ztab-field3. 
    append wa_itab to it_tab.
  endif.
endmodule.

Read only

Former Member
0 Likes
2,959

Hi Nitwick, yes you're correct, that's what I'm exactly trying to do - accept input from table control (I don't need to display anything on the table control). But on my debug on the PAI, I can't get/read my input/values I entered.

Thanks.

Read only

Former Member
0 Likes
2,959

Hi,

Lets say your table control has columns namely ztable-field1, ztable-field2. Now if you want to read the input, then in the PAI, just write the code that I have previously mentioned. Debug to see if the screen field has data that you have entered as input. Also check your sy-ucomm value and see whether the code that you want gets triggered.

Read only

Former Member
0 Likes
2,959

Hi Nitwick and everyone,

I apply your code with mine:


*  Z_TABLE is the table
*  T_ITAB is the internal table
*  WA_ITAB is the work area
*  TC_ID is the Table Control Name
*PAI Event
  LOOP WITH CONTROL TC_ID.
    MODULE MODIFY_DATA.
  ENDLOOP.

module MODIFY_DATA input.
  DATA W_DBCNT LIKE SY-DBCNT.

  CASE OK_CODE.
    WHEN 'CREATE'.
        MOVE: Z_TABLE-WERKS TO WA_ITAB-WERKS,
                    Z_TABLE-MATNR TO WA_ITAB-MATNR,
                    Z_TABLE-LICHA   TO WA_ITAB-LICHA,
                    Z_TABLE-LIFNR    TO WA_ITAB-LIFNR.

         APPEND WA_IITAB TO T_ITAB.

         MODIFY Z_TABLE FROM TABLE T_ITAB.

The table control columns, ZTABLE-field1, ZTABLE-field2, and so on, does not contain any values in the debug. It seems like inside the LOOP of Table Control, Moving the Table-Field inside the table control will not allow values to be stored.

Any other suggestions?

Read only

Former Member
0 Likes
2,959

Hi,

-> Check if your OK_CODE = 'CREATE' in your debug mode

-> Did you refer the columns of your tabe control to Dictionary?

-> Are the names of the columns on the table control and the ones in your code the same?

-> Try this


"PAI
LOOP AT T_ITAB.  "Try the change here
    MODULE MODIFY_DATA.
  ENDLOOP.

module MODIFY_DATA input.
  DATA W_DBCNT LIKE SY-DBCNT.
 
  CASE OK_CODE.
    WHEN 'CREATE'.
        MOVE: Z_TABLE-WERKS TO WA_ITAB-WERKS,
                    Z_TABLE-MATNR TO WA_ITAB-MATNR,
                    Z_TABLE-LICHA   TO WA_ITAB-LICHA,
                    Z_TABLE-LIFNR    TO WA_ITAB-LIFNR.
 
         APPEND WA_IITAB TO T_ITAB.

Read only

Former Member
0 Likes
2,959

Hi Nitwick and All,

Yes, OK_CODE's value is 'CREATE'.

Yes I refer to the columns of my table control to the Dictionary.

Yes, all the names of the columns on the table control and the ones in my code are the same.

Thanks. Jun

Edited by: Jaime Cabanban on Nov 10, 2009 6:33 PM

Read only

Former Member
0 Likes
2,959

Hi,

Did you try this change?


"PAI
LOOP AT T_ITAB.  "Try the change here
    MODULE MODIFY_DATA.
  ENDLOOP.

Read only

Former Member
0 Likes
2,959

Hi Nitwick,

Thanks, just rewarded you 10pts., problem solved.

The field-name in my table control-screen painter is not updated/the same as what I indicated in the PAI event on Loop Control.

Regards,

Jun