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: 

How to delete a row from table control

Former Member
0 Kudos
373

I have created a push button on the screen for delete.

its getting stored in ok_code.

'FLAG' is the name of the mark on the table control.

I am getting probs in this line.

I am not getting anything in mark_field.

ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.

The code is:

MODULE tablctrl2_user_command INPUT.

PERFORM user_ok_tc USING 'TABLCTRL2'

'I_ZSKILLEMP'

'FLAG'

CHANGING ok_code.

ENDMODULE.

FORM user_ok_tc USING p_tc_name TYPE dynfnam

p_table_name

p_mark_name

CHANGING p_ok LIKE sy-ucomm.

-BEGIN OF LOCAL DATA----


DATA: l_ok TYPE sy-ucomm,

l_offset TYPE i.

-END OF LOCAL DATA----


  • Table control specific operations *

  • evaluate TC name and operations *

SEARCH p_ok FOR p_tc_name.

IF sy-subrc <> 0.

EXIT.

ENDIF.

l_offset = strlen( p_tc_name ) + 1.

l_ok = p_ok+l_offset.

  • execute general and TC specific operations *

CASE l_ok.

WHEN 'INSR'. "insert row

PERFORM fcode_insert_row USING p_tc_name

p_table_name.

CLEAR p_ok.

WHEN 'DELE'. "delete row

PERFORM fcode_delete_row USING p_tc_name

p_table_name

p_mark_name.

CLEAR p_ok.

FORM fcode_delete_row

USING p_tc_name TYPE dynfnam

p_table_name

p_mark_name .

-BEGIN OF LOCAL DATA----


DATA l_table_name LIKE feld-name.

FIELD-SYMBOLS <tc> TYPE cxtab_control.

FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

FIELD-SYMBOLS <wa>.

FIELD-SYMBOLS <mark_field>.

-END OF LOCAL DATA----


ASSIGN (p_tc_name) TO <tc>.

  • get the table, which belongs to the tc *

CONCATENATE p_table_name '[]' INTO l_table_name. "table body

ASSIGN (l_table_name) TO <table>. "not headerline

  • delete marked lines *

DESCRIBE TABLE <table> LINES <tc>-lines.

LOOP AT <table> ASSIGNING <wa>.

  • access to the component 'FLAG' of the table header *

ASSIGN COMPONENT p_mark_name OF STRUCTURE <wa> TO <mark_field>.

IF <mark_field> = 'X'.

DELETE <table> INDEX syst-tabix.

IF sy-subrc = 0.

<tc>-lines = <tc>-lines - 1.

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM.

6 REPLIES 6

Former Member
0 Kudos
159

Check this link.

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

This will give you some idea eventhough I am not using checkbox there.

i think better u wud have added a one char field to ur table control and in the properties of table control ,go to W/ Sel Column - give this fieldname here like itab1-ch.

now u have to just select the row and press delete ..

demo code is as follows-

module USER_COMMAND_0300 input.

case ok_code.

when 'DELETE'.

READ TABLE tabcontrl-cols INTO cols WITH KEY screen-input = '1'.

if sy-subrc = 0.

LOOP AT itab2 INTO itab1 WHERE CH = 'X'.

DELETE itab2.

ENDLOOP.

endif.

CLEAR OK_CODE.

ENDCASE.

endmodule. " USER_COMMAND_0300 INPUT

0 Kudos
159

But I am using the table control wizard and it is taking care of the code.

So I need not write anything.

But its not working.

Former Member
0 Kudos
159

Hi...

i got the same prob...but got the solution too...

you have to take an internal table of same type of dbase table..and maintain a flag in it...which will be get filled automatically with 'X'.

here is the code..go throug it..

REPORT YH642_DIALOG_TABLECONTROL.

CALL SCREEN 999.

DATA:

W_INDEX TYPE I.

DATA:

W_UCOMM LIKE SY-UCOMM.

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

*&SPWIZARD: DEFINITION OF DDIC-TABLE

TABLES: YH642_RAM.

DATA:

BEGIN OF DDTAB,

TAB_FLAG TYPE C,

MANDT LIKE YH642_RAM-MANDT,

EID LIKE YH642_RAM-EID,

ENAME LIKE YH642_RAM-ENAME,

MOBILE LIKE YH642_RAM-MOBILE,

END OF DDTAB.

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

TYPES: BEGIN OF T_TAB,

TAB_FLAG TYPE C,

MANDT LIKE YH642_RAM-MANDT,

EID LIKE YH642_RAM-EID,

ENAME LIKE YH642_RAM-ENAME,

MOBILE LIKE YH642_RAM-MOBILE,

END OF T_TAB.

*&SPWIZARD: INTERNAL TABLE FOR TABLECONTROL 'TAB'

DATA: G_TAB_ITAB TYPE T_TAB OCCURS 0,

H_TAB_ITAB TYPE T_TAB OCCURS 0,

G_TAB_WA TYPE T_TAB. "work area

DATA: G_TAB_COPIED. "copy flag

*&SPWIZARD: DECLARATION OF TABLECONTROL 'TAB' ITSELF

CONTROLS: TAB TYPE TABLEVIEW USING SCREEN 0999.

*&SPWIZARD: LINES OF TABLECONTROL 'TAB'

DATA: G_TAB_LINES LIKE SY-LOOPC.

DATA: OK_CODE LIKE SY-UCOMM.

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

*&SPWIZARD: COPY DDIC-TABLE TO ITAB

MODULE TAB_INIT OUTPUT.

IF G_TAB_COPIED IS INITIAL.

*&SPWIZARD: COPY DDIC-TABLE 'YH642_RAM'

*&SPWIZARD: INTO INTERNAL TABLE 'g_TAB_itab'

SELECT * FROM YH642_RAM

INTO CORRESPONDING FIELDS

OF TABLE G_TAB_ITAB.

G_TAB_COPIED = 'X'.

H_TAB_ITAB[] = G_TAB_ITAB[].

REFRESH CONTROL 'TAB' FROM SCREEN '0999'.

ENDIF.

ENDMODULE. "TAB_INIT OUTPUT

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

*&SPWIZARD: MOVE ITAB TO DYNPRO

MODULE TAB_MOVE OUTPUT.

MOVE-CORRESPONDING G_TAB_WA TO DDTAB.

ENDMODULE. "TAB_MOVE OUTPUT

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

*&SPWIZARD: GET LINES OF TABLECONTROL

MODULE TAB_GET_LINES OUTPUT.

G_TAB_LINES = SY-LOOPC.

ENDMODULE. "TAB_GET_LINES OUTPUT

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

*&SPWIZARD: MODIFY TABLE

MODULE TAB_MODIFY INPUT.

MOVE-CORRESPONDING DDTAB TO G_TAB_WA.

MODIFY G_TAB_ITAB

FROM G_TAB_WA

INDEX TAB-CURRENT_LINE.

ENDMODULE. "TAB_MODIFY INPUT

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

*&SPWIZARD: PROCESS USER COMMAND

MODULE TAB_USER_COMMAND INPUT.

OK_CODE = SY-UCOMM.

PERFORM USER_OK_TC USING 'TAB'

'G_TAB_ITAB'

'TAB_FLAG'

CHANGING OK_CODE.

SY-UCOMM = OK_CODE.

ENDMODULE. "TAB_USER_COMMAND INPUT

----


  • INCLUDE TABLECONTROL_FORMS *

----


&----


*& Form USER_OK_TC *

&----


FORM USER_OK_TC USING P_TC_NAME TYPE DYNFNAM

P_TABLE_NAME

P_MARK_NAME

CHANGING P_OK LIKE SY-UCOMM.

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA: L_OK TYPE SY-UCOMM,

L_OFFSET TYPE I.

&SPWIZARD: END OF LOCAL DATA----


*&SPWIZARD: Table control specific operations *

*&SPWIZARD: evaluate TC name and operations *

SEARCH P_OK FOR P_TC_NAME.

IF SY-SUBRC <> 0.

EXIT.

ENDIF.

L_OFFSET = STRLEN( P_TC_NAME ) + 1.

L_OK = P_OK+L_OFFSET.

  • L_OK = 'DELE'.

*&SPWIZARD: execute general and TC specific operations *

CASE L_OK.

WHEN 'INSR'. "insert row

PERFORM FCODE_INSERT_ROW USING P_TC_NAME

P_TABLE_NAME.

CLEAR P_OK.

WHEN 'DELE'. "delete row

  • MESSAGE 'Are you really going to delete??' type 'I'.

PERFORM FCODE_DELETE_ROW USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME.

CLEAR P_OK.

WHEN 'P--' OR "top of list

'P-' OR "previous page

'P+' OR "next page

'P++'. "bottom of list

PERFORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME

L_OK.

CLEAR P_OK.

  • WHEN 'L--'. "total left

  • PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME.

*

  • WHEN 'L-'. "column left

  • PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME.

*

  • WHEN 'R+'. "column right

  • PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME.

*

  • WHEN 'R++'. "total right

  • PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME.

*

WHEN 'MARK'. "mark all filled lines

PERFORM FCODE_TC_MARK_LINES USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME .

CLEAR P_OK.

WHEN 'DMRK'. "demark all filled lines

PERFORM FCODE_TC_DEMARK_LINES USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME .

CLEAR P_OK.

  • WHEN 'SASCEND' OR

  • 'SDESCEND'. "sort column

  • PERFORM FCODE_SORT_TC USING P_TC_NAME

  • l_ok.

ENDCASE.

ENDFORM. " USER_OK_TC

&----


*& Form FCODE_INSERT_ROW *

&----


FORM FCODE_INSERT_ROW

USING P_TC_NAME TYPE DYNFNAM

P_TABLE_NAME .

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA L_LINES_NAME LIKE FELD-NAME.

DATA L_SELLINE LIKE SY-STEPL.

DATA L_LASTLINE TYPE I.

DATA L_LINE TYPE I.

DATA L_TABLE_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <LINES> TYPE I.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: get looplines of TableControl *

CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_LINES_NAME.

ASSIGN (L_LINES_NAME) TO <LINES>.

*&SPWIZARD: get current line *

GET CURSOR LINE L_SELLINE.

IF SY-SUBRC <> 0. " append line to table

L_SELLINE = <TC>-LINES + 1.

*&SPWIZARD: set top line *

IF L_SELLINE > <LINES>.

<TC>-TOP_LINE = L_SELLINE - <LINES> + 1 .

ELSE.

<TC>-TOP_LINE = 1.

ENDIF.

ELSE. " insert line into table

L_SELLINE = <TC>-TOP_LINE + L_SELLINE - 1.

L_LASTLINE = <TC>-TOP_LINE + <LINES> - 1.

ENDIF.

*&SPWIZARD: set new cursor line *

L_LINE = L_SELLINE - <TC>-TOP_LINE + 1.

*&SPWIZARD: insert initial line *

INSERT INITIAL LINE INTO <TABLE> INDEX L_SELLINE.

<TC>-LINES = <TC>-LINES + 1.

*&SPWIZARD: set cursor *

SET CURSOR LINE L_LINE.

ENDFORM. " FCODE_INSERT_ROW

&----


*& Form FCODE_DELETE_ROW *

&----


FORM FCODE_DELETE_ROW

USING P_TC_NAME TYPE DYNFNAM

P_TABLE_NAME

P_MARK_NAME .

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA L_TABLE_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <WA>.

FIELD-SYMBOLS <MARK_FIELD>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: delete marked lines *

DESCRIBE TABLE <TABLE> LINES <TC>-LINES.

LOOP AT <TABLE> ASSIGNING <WA>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.

IF <MARK_FIELD> = 'X'.

W_INDEX = SYST-TABIX.

DELETE <TABLE> INDEX SYST-TABIX.

IF SY-SUBRC = 0.

<TC>-LINES = <TC>-LINES - 1.

ENDIF.

ENDIF.

ENDLOOP.

READ TABLE H_TAB_ITAB INDEX W_INDEX INTO G_TAB_WA.

IF SY-SUBRC EQ 0.

MOVE-CORRESPONDING G_TAB_WA TO YH642_RAM.

DELETE YH642_RAM.

ENDIF.

ENDFORM. " FCODE_DELETE_ROW

&----


*& Form COMPUTE_SCROLLING_IN_TC

&----


  • text

----


  • -->P_TC_NAME name of tablecontrol

  • -->P_OK ok code

----


FORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME

P_OK.

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA L_TC_NEW_TOP_LINE TYPE I.

DATA L_TC_NAME LIKE FELD-NAME.

DATA L_TC_LINES_NAME LIKE FELD-NAME.

DATA L_TC_FIELD_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.

FIELD-SYMBOLS <LINES> TYPE I.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get looplines of TableControl *

CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_TC_LINES_NAME.

ASSIGN (L_TC_LINES_NAME) TO <LINES>.

*&SPWIZARD: is no line filled? *

IF <TC>-LINES = 0.

*&SPWIZARD: yes, ... *

L_TC_NEW_TOP_LINE = 1.

ELSE.

*&SPWIZARD: no, ... *

CALL FUNCTION 'SCROLLING_IN_TABLE'

EXPORTING

ENTRY_ACT = <TC>-TOP_LINE

ENTRY_FROM = 1

ENTRY_TO = <TC>-LINES

LAST_PAGE_FULL = 'X'

LOOPS = <LINES>

OK_CODE = P_OK

OVERLAPPING = 'X'

IMPORTING

ENTRY_NEW = L_TC_NEW_TOP_LINE

EXCEPTIONS

  • NO_ENTRY_OR_PAGE_ACT = 01

  • NO_ENTRY_TO = 02

  • NO_OK_CODE_OR_PAGE_GO = 03

OTHERS = 0.

ENDIF.

*&SPWIZARD: get actual tc and column *

GET CURSOR FIELD L_TC_FIELD_NAME

AREA L_TC_NAME.

IF SYST-SUBRC = 0.

IF L_TC_NAME = P_TC_NAME.

*&SPWIZARD: et actual column *

SET CURSOR FIELD L_TC_FIELD_NAME LINE 1.

ENDIF.

ENDIF.

*&SPWIZARD: set the new top line *

<TC>-TOP_LINE = L_TC_NEW_TOP_LINE.

ENDFORM. " COMPUTE_SCROLLING_IN_TC

&----


*& Form FCODE_TC_MARK_LINES

&----


  • marks all TableControl lines

----


  • -->P_TC_NAME name of tablecontrol

----


FORM FCODE_TC_MARK_LINES USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME.

&SPWIZARD: EGIN OF LOCAL DATA----


DATA L_TABLE_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <WA>.

FIELD-SYMBOLS <MARK_FIELD>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: mark all filled lines *

LOOP AT <TABLE> ASSIGNING <WA>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.

<MARK_FIELD> = 'X'.

ENDLOOP.

ENDFORM. "fcode_tc_mark_lines

&----


*& Form FCODE_TC_DEMARK_LINES

&----


  • demarks all TableControl lines

----


  • -->P_TC_NAME name of tablecontrol

----


FORM FCODE_TC_DEMARK_LINES USING P_TC_NAME

P_TABLE_NAME

P_MARK_NAME .

&SPWIZARD: BEGIN OF LOCAL DATA----


DATA L_TABLE_NAME LIKE FELD-NAME.

FIELD-SYMBOLS <TC> TYPE CXTAB_CONTROL.

FIELD-SYMBOLS <TABLE> TYPE STANDARD TABLE.

FIELD-SYMBOLS <WA>.

FIELD-SYMBOLS <MARK_FIELD>.

&SPWIZARD: END OF LOCAL DATA----


ASSIGN (P_TC_NAME) TO <TC>.

*&SPWIZARD: get the table, which belongs to the tc *

CONCATENATE P_TABLE_NAME '[]' INTO L_TABLE_NAME. "table body

ASSIGN (L_TABLE_NAME) TO <TABLE>. "not headerline

*&SPWIZARD: demark all filled lines *

LOOP AT <TABLE> ASSIGNING <WA>.

*&SPWIZARD: access to the component 'FLAG' of the table header *

ASSIGN COMPONENT P_MARK_NAME OF STRUCTURE <WA> TO <MARK_FIELD>.

<MARK_FIELD> = SPACE.

ENDLOOP.

ENDFORM. "fcode_tc_mark_lines

&----


*& Module STATUS_0999 OUTPUT

&----


  • text

----


MODULE STATUS_0999 OUTPUT.

SET PF-STATUS 'SS_STD'.

SET TITLEBAR 'TITLE'.

ENDMODULE. " STATUS_0999 OUTPUT

&----


*& Module USER_COMMAND_0999 INPUT

&----


  • text

----


MODULE USER_COMMAND_0999 INPUT.

DATA:

H_TAB_WA LIKE G_TAB_WA.

CASE W_UCOMM.

WHEN 'BACK'.

LEAVE PROGRAM.

WHEN 'TAB_MODI' OR 'SAVE'.

LOOP AT G_TAB_ITAB INTO G_TAB_WA.

  • FORMAT INPUT OFF.

MOVE-CORRESPONDING G_TAB_WA TO YH642_RAM.

READ TABLE H_TAB_ITAB WITH KEY EID = G_TAB_WA-EID INTO H_TAB_WA.

IF SY-SUBRC EQ 0.

IF G_TAB_WA NE H_TAB_WA.

MODIFY YH642_RAM.

ENDIF.

ELSE.

INSERT YH642_RAM.

ENDIF.

ENDLOOP.

SORT G_TAB_ITAB.

ENDCASE.

*CALL SCREEN 700.

ENDMODULE. " USER_COMMAND_0999 INPUT

Former Member
0 Kudos
159

Need to write modify statement, see the sample code below.

PROCESS AFTER INPUT.

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

LOOP AT G_TC1_ITAB.

CHAIN.

FIELD ZFG_SRNO-ZSRNO.

MODULE TC1_MODIFY ON CHAIN-REQUEST.

ENDCHAIN.

ENDLOOP.

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

*&SPWIZARD: MODIFY TABLE

MODULE TC1_MODIFY INPUT.

MOVE-CORRESPONDING ZFG_SRNO TO G_TC1_WA.

MODIFY G_TC1_ITAB

FROM G_TC1_WA

INDEX TC1-CURRENT_LINE.

ENDMODULE. "TC1_MODIFY INPUT

Former Member
0 Kudos
159

If u delete the particular row from the internal table which u are using for the table control...it will automatically be deleted from table control