Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

Add Record, Delete Record, Save Record - Table Control

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.

Tags:
Former Member

Helpful Answer

by
Not what you were looking for? View more on this topic or Ask a question