on 04-25-2006 12:33 PM
I have create a customized table ZMMZNHD
How to add new record in new line, delete record, save record?
***INCLUDE MZ01TOP
DATA DECLARATION FOR TABLECONTROL 'ZTBLMM'
DEFINITION OF DDIC-TABLE
TABLES: ZMMZNHD,t024e,t001.
DATA : ok_code like sy-ucomm,
save_ok TYPE sy-ucomm.
TYPE FOR THE DATA OF TABLECONTROL 'ZTBLMM02'
TYPES: BEGIN OF T_ZTBLMM02,
ZCOUNTER LIKE ZMMZNHD-ZCOUNTER,
MANDT LIKE ZMMZNHD-MANDT,
EKGRP LIKE ZMMZNHD-EKGRP,
MARK LIKE ZMMZNHD-MARK,
END OF T_ZTBLMM02.
INTERNAL TABLE FOR TABLECONTROL 'ZTBLMM02'
DATA: G_ZTBLMM02_ITAB TYPE T_ZTBLMM02 OCCURS 0 WITH HEADER LINE,
G_ZTBLMM02_WA TYPE T_ZTBLMM02, "work area
G_ZTBLMM02_COPIED. "copy flag
DECLARATION OF TABLECONTROL 'ZTBLMM02' ITSELF
CONTROLS: ZTBLMM02 TYPE TABLEVIEW USING SCREEN 1001.
DATA cols LIKE LINE OF ZTBLMM02-cols.
LINES OF TABLECONTROL 'ZTBLMM02'
DATA: G_ZTBLMM02_LINES LIKE SY-LOOPC.
***INCLUDE MZ01O01 .
&----
*& Module STATUS_1000 OUTPUT
&----
text
----
MODULE STATUS_1000 OUTPUT.
SET PF-STATUS 'DISPLAY'.
if sy-tcode = 'YM02'.
SET TITLEBAR 'Display'.
endif.
ENDMODULE. " STATUS_1000 OUTPUT
&----
*& Module STATUS_1001 OUTPUT
&----
text
----
MODULE STATUS_1001 OUTPUT.
SET PF-STATUS 'INITIAL'.
if sy-tcode = 'YM01'.
SET TITLEBAR 'Create'.
endif.
ENDMODULE. " STATUS_1000 OUTPUT
OUTPUT MODULE FOR TABLECONTROL 'ZTBLMM02':
COPY DDIC-TABLE TO ITAB
MODULE ZTBLMM02_INIT OUTPUT.
IF G_ZTBLMM02_COPIED IS INITIAL.
COPY DDIC-TABLE 'ZMMZNHD'
INTO INTERNAL TABLE 'g_ZTBLMM02_itab'
SELECT * FROM ZMMZNHD
INTO CORRESPONDING FIELDS
OF TABLE G_ZTBLMM02_ITAB
WHERE EKORG = ZMMZNHD-EKORG
AND BSART = ZMMZNHD-BSART.
G_ZTBLMM02_COPIED = 'X'.
REFRESH CONTROL 'ZTBLMM02' FROM SCREEN '1001'.
ENDIF.
ENDMODULE.
OUTPUT MODULE FOR TABLECONTROL 'ZTBLMM02':
MOVE ITAB TO DYNPRO
MODULE ZTBLMM02_MOVE OUTPUT.
MOVE-CORRESPONDING G_ZTBLMM02_WA TO ZMMZNHD.
ENDMODULE.
OUTPUT MODULE FOR TABLECONTROL 'ZTBLMM02':
GET LINES OF TABLECONTROL
MODULE ZTBLMM02_GET_LINES OUTPUT.
G_ZTBLMM02_LINES = SY-LOOPC.
ENDMODULE.
&----
*& Module check_field INPUT
&----
text
----
MODULE check_field INPUT.
clear t024e.
SELECT single * FROM T024E
WHERE EKORG = ZMMZNHD-EKORG.
if sy-subrc <> 0.
message e000(zmm) with ' '.
endif.
ENDMODULE. " check_field INPUT
&----
*& Module leave_screen INPUT
&----
text
----
MODULE leave_screen INPUT.
case ok_code.
when 'BACK'.
leave to screen 0.
when 'CANC'.
leave to screen 0.
when 'EXIT'.
leave to screen 0.
endcase.
ENDMODULE. " leave_screen INPUT
&----
*& Module Back_screen INPUT
&----
text
----
MODULE Back_screen INPUT.
case ok_code.
when 'BACK'.
leave to screen 1000.
when 'CANC'.
leave to screen 1000.
when 'EXIT'.
leave to screen 1000.
endcase.
ENDMODULE. " Back_screen INPUT
MODULE CHECK_MARK.
G_ZTBLMM02_ITAB-MARK = ZMMZNHD-MARK.
ENDMODULE.
----
*& Module insert INPUT
&----
text
----
MODULE insert INPUT.
LOOP AT ZTBLMM02-cols INTO W_TABCONCOL
WHERE SCREEN-NAME = '1001'.
W_TABCONCOL-SCREEN-INVISIBLE = 1.
W_TABCONCOL-INVISIBLE = 1.
W_TABCONCOL-SELECTED = 'X'.
MODIFY ZTBLMM02-cols FROM W_TABCONCOL.
ENDLOOP.
save_ok = ok_code.
CLEAR ok_code.
CASE save_ok.
WHEN 'TOGGLE'.
LOOP AT ZTBLMM02-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 ZTBLMM02-cols FROM cols INDEX sy-tabix.
ENDLOOP.
WHEN 'DELE'.
ENDIF.
WHEN 'INSR'.
ENDCASE.
ENDMODULE. " insert INPUT
INPUT MODULE FOR TABLECONTROL 'ZTBLMM02': PROCESS USER COMMAND
*MODULE ZTBLMM02_USER_COMMAND INPUT.
PERFORM USER_OK_TC USING 'T_ZTBLMM02'
'ZMMZNHD'
'FLAG'
CHANGING OK_CODE.
*ENDMODULE.
Hi,
refer this code:
[code* Triggering event according to the user command
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'.
Table Control
© 2005 SAP AG 13
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[/code]
Refer this link:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/abap-code-sam... control in abap.pdf
Regards,
Gayathri
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
anyone have snippets using table control wizard?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Rayblur,
You can use the SAP Help to get an idea of using Table control wizard. Here is the link.
http://help.sap.com/saphelp_nw04/helpdata/en/6d/150d67da1011d3963800a0c94260a5/content.htm
Regards,
SP.
Hi,
refer this code:
[code* Triggering event according to the user command
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'.
Table Control
© 2005 SAP AG 13
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[/code]
Refer this link:
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/abap-code-sam... control in abap.pdf
Regards,
Gayathri
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
91 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.