Deleting a row in Table control

Question: Hi All,

Can any body help me how to delete a selected row in a table control ?
If any body can forward me some example code will be helpfull for me

Thanks
Ravi

Answer:
The table control wizard which is one of the options on the screen painter will create code to delete / insert lines in a table control for you if you ask it to and I suggest you try it. If your version of SAP doesn't have this option, the bit of code it created for me (with a few small alterations) is attached.

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>.
   FIELD-SYMBOLS <LINE_NUMBER>.
*&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>.
     ASSIGN COMPONENT 'EBELP' OF STRUCTURE <WA> TO <LINE_NUMBER>.

* Only allow them to delete newly entered lines - lines that already
* exist must instead be flagged for deletion.
     IF <MARK_FIELD> = 'X'.
       IF NOT <LINE_NUMBER> IS INITIAL.
          w_error = 'X'.
          w_fld = 'GW_ITEMS-YEAR'.
          w_lin = sy-stepl.
          MESSAGE I096(Z_PREMIS_MESSAGES).
          RETURN.
        ELSE.
          DELETE <TABLE> INDEX SYST-TABIX.
          IF SY-SUBRC = 0.
            <TC>-LINES = <TC>-LINES - 1.
          ENDIF.
        ENDIF.
     ENDIF.

   ENDLOOP.

 ENDFORM.                              " FCODE_DELETE_ROW

Answer:
Hi,

I am working on SAP 3.1I version. Can you please tell me how to use the table control wizard. Can you please give me the Menu path where it is available ?


Thanks
Varma

Answer:
We're using 4.7, SAPGui 6.4 and the graphical screen painter. The table control wizard is one of the buttons on the left hand side of the graphical screen painter screen. If you can't find it here, I guess you may not have it.

The code I pasted looks quite complicated but that is only because it uses field symbols etc to make it generic. I think the basic idea is quite simple. You flag the line you want to delete in the internal table using something like
 modify GT_ITEMS
    from GW_ITEMS
    index TC_ITEMS-current_line
    transporting SELECT.
Then you loop through the itab and delete the flagged records. The PBO then refreshes the screen.
Copyright ?2007 - 2008 www.jt77.com