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

How to edit and update table control into database?

Former Member
0 Likes
1,167

I am doing table control. Here are my codes:

&----


*& Report ZHERA_TABLE2

*&

&----


*&

*&

&----


REPORT ZHERA_TABLE2.

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

*&SPWIZARD: DEFINITION OF DDIC-TABLE

TABLES: ZHERA.

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

TYPES: BEGIN OF T_ZTABLE_CONTROL,

NAME LIKE ZHERA-NAME,

AGE LIKE ZHERA-AGE,

END OF T_ZTABLE_CONTROL.

*&SPWIZARD: INTERNAL TABLE FOR TABLECONTROL 'ZTABLE_CONTROL'

DATA: G_ZTABLE_CONTROL_ITAB TYPE T_ZTABLE_CONTROL OCCURS 0,

G_ZTABLE_CONTROL_WA TYPE T_ZTABLE_CONTROL. "work area

DATA: G_ZTABLE_CONTROL_COPIED. "copy flag

*&SPWIZARD: DECLARATION OF TABLECONTROL 'ZTABLE_CONTROL' ITSELF

CONTROLS: ZTABLE_CONTROL TYPE TABLEVIEW USING SCREEN 1000.

START-OF-SELECTION.

CALL SCREEN 1000.

*&SPWIZARD: OUTPUT MODULE FOR TC 'ZTABLE_CONTROL'. DO NOT CHANGE THIS LI

*&SPWIZARD: COPY DDIC-TABLE TO ITAB

MODULE ZTABLE_CONTROL_INIT OUTPUT.

IF G_ZTABLE_CONTROL_COPIED IS INITIAL.

*&SPWIZARD: COPY DDIC-TABLE 'ZHERA'

*&SPWIZARD: INTO INTERNAL TABLE 'g_ZTABLE_CONTROL_itab'

SELECT * FROM ZHERA

INTO CORRESPONDING FIELDS

OF TABLE G_ZTABLE_CONTROL_ITAB.

G_ZTABLE_CONTROL_COPIED = 'X'.

REFRESH CONTROL 'ZTABLE_CONTROL' FROM SCREEN '1000'.

ENDIF.

ENDMODULE.

*&SPWIZARD: OUTPUT MODULE FOR TC 'ZTABLE_CONTROL'. DO NOT CHANGE THIS LI

*&SPWIZARD: MOVE ITAB TO DYNPRO

MODULE ZTABLE_CONTROL_MOVE OUTPUT.

MOVE-CORRESPONDING G_ZTABLE_CONTROL_WA TO ZHERA.

ENDMODULE.

Screen 1000 codes:

PROCESS BEFORE OUTPUT.

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

MODULE ZTABLE_CONTROL_INIT.

*&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_TC_ATTR.

*&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_COL_ATTR.

LOOP AT G_ZTABLE_CONTROL_ITAB

INTO G_ZTABLE_CONTROL_WA

WITH CONTROL ZTABLE_CONTROL

CURSOR ZTABLE_CONTROL-CURRENT_LINE.

*&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_FIELD_ATTR

MODULE ZTABLE_CONTROL_MOVE.

ENDLOOP.

  • MODULE STATUS_1000.

*

PROCESS AFTER INPUT.

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

LOOP AT G_ZTABLE_CONTROL_ITAB.

CHAIN.

FIELD ZHERA-NAME.

FIELD ZHERA-AGE.

ENDCHAIN.

ENDLOOP.

*&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_TC_ATTR.

*&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_COL_ATTR.

  • MODULE USER_COMMAND_1000.

Please show me where to put my codes to edit(edit directly on table control fields) and update my table control(using the 'save' button)?

I am doing table control. Here are my codes:

&----


*& Report ZHERA_TABLE2

*&

&----


*&

*&

&----


REPORT ZHERA_TABLE2.

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

*&SPWIZARD: DEFINITION OF DDIC-TABLE

TABLES: ZHERA.

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

TYPES: BEGIN OF T_ZTABLE_CONTROL,

NAME LIKE ZHERA-NAME,

AGE LIKE ZHERA-AGE,

END OF T_ZTABLE_CONTROL.

*&SPWIZARD: INTERNAL TABLE FOR TABLECONTROL 'ZTABLE_CONTROL'

DATA: G_ZTABLE_CONTROL_ITAB TYPE T_ZTABLE_CONTROL OCCURS 0,

G_ZTABLE_CONTROL_WA TYPE T_ZTABLE_CONTROL. "work area

DATA: G_ZTABLE_CONTROL_COPIED. "copy flag

*&SPWIZARD: DECLARATION OF TABLECONTROL 'ZTABLE_CONTROL' ITSELF

CONTROLS: ZTABLE_CONTROL TYPE TABLEVIEW USING SCREEN 1000.

START-OF-SELECTION.

CALL SCREEN 1000.

*&SPWIZARD: OUTPUT MODULE FOR TC 'ZTABLE_CONTROL'. DO NOT CHANGE THIS LI

*&SPWIZARD: COPY DDIC-TABLE TO ITAB

MODULE ZTABLE_CONTROL_INIT OUTPUT.

IF G_ZTABLE_CONTROL_COPIED IS INITIAL.

*&SPWIZARD: COPY DDIC-TABLE 'ZHERA'

*&SPWIZARD: INTO INTERNAL TABLE 'g_ZTABLE_CONTROL_itab'

SELECT * FROM ZHERA

INTO CORRESPONDING FIELDS

OF TABLE G_ZTABLE_CONTROL_ITAB.

G_ZTABLE_CONTROL_COPIED = 'X'.

REFRESH CONTROL 'ZTABLE_CONTROL' FROM SCREEN '1000'.

ENDIF.

ENDMODULE.

*&SPWIZARD: OUTPUT MODULE FOR TC 'ZTABLE_CONTROL'. DO NOT CHANGE THIS LI

*&SPWIZARD: MOVE ITAB TO DYNPRO

MODULE ZTABLE_CONTROL_MOVE OUTPUT.

MOVE-CORRESPONDING G_ZTABLE_CONTROL_WA TO ZHERA.

ENDMODULE.

Screen 1000 codes:

PROCESS BEFORE OUTPUT.

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

MODULE ZTABLE_CONTROL_INIT.

*&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_TC_ATTR.

*&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_COL_ATTR.

LOOP AT G_ZTABLE_CONTROL_ITAB

INTO G_ZTABLE_CONTROL_WA

WITH CONTROL ZTABLE_CONTROL

CURSOR ZTABLE_CONTROL-CURRENT_LINE.

*&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_FIELD_ATTR

MODULE ZTABLE_CONTROL_MOVE.

ENDLOOP.

  • MODULE STATUS_1000.

*

PROCESS AFTER INPUT.

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

LOOP AT G_ZTABLE_CONTROL_ITAB.

CHAIN.

FIELD ZHERA-NAME.

FIELD ZHERA-AGE.

ENDCHAIN.

ENDLOOP.

*&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_TC_ATTR.

*&SPWIZARD: MODULE ZTABLE_CONTROL_CHANGE_COL_ATTR.

  • MODULE USER_COMMAND_1000.

Please show me where to put my codes to edit(edit directly on table control fields) and update my table control(using the 'save' button)?

3 REPLIES 3
Read only

Former Member
0 Likes
646

Hi,

You have to put the following code in the PBO of screen 1000.This code would make the fields editable to make changes in the table control fields directly.

Here there are 3 transactions.For create and change transactions, the fields will be in editable mode and for display transaction,they will be non editable mode.

DESCRIBE TABLE tb_line LINES lin. " tb_line is the name of the internal table for the table control

tcl_item-lines = lin. '' lin hold the number of lines of the internal table

CASE sy-tcode.

WHEN 'ZCREATE09' OR 'ZCHANGE09'.

***Checking if the table control is empty or not***

IF lin NE 0.

LOOP AT SCREEN.

***To make the screen editable****

screen-input = 1.

ENDLOOP.

ELSE.

LOOP AT SCREEN.

IF screen-name CS 'TB_LINE'.

****To make the screen non-editable if no values are present in the

***table control****

screen-input = 0.

MODIFY SCREEN.

ENDIF.

ENDLOOP.

ENDIF.

Once the fields are edited and the save button is pressed,the entered values have to be populated into the Z tables.The code has to written in the PAI of the screen 1000.Here the values from the work area of the internal table are moved into the Z Table. The code will be.

LOOP AT tb_line.

ztm09_ekpo-ebeln = ztm09_ekko-ebeln. "ztm09_ekko and ztm09_ekpo are the names of the Z Tables.

ztm09_ekpo-ebelp = tb_line-ebelp.

ztm09_ekpo-matnr = tb_line-matnr.

ztm09_ekpo-menge = tb_line-menge.

ztm09_ekpo-meins = tb_line-meins.

ztm09_ekpo-netpr = tb_line-netpr.

ztm09_ekpo-waers = tb_line-waers.

*****Update the entries into item table*****

MODIFY ztm09_ekpo.

ENDLOOP.

Reward if helpfull

Thanks,

Kashyap

Read only

Former Member
0 Likes
646

Hi Juz,

For editing table control you don't even to provide a button for edit because the table control will fetch and come in the display mode only so you just put your content in table control where ever you want or change then after modify the content just click save it will update in the database just put your contents in pai just refer the program which i have previously send.

Read only

jayanthi_jayaraman
Active Contributor
0 Likes
646

Hi,

Check this link.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/documents/a1-8-4/table%20c...

I am explaining step-by-step about the table control and database updation here.