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

Table control

Former Member
0 Likes
1,184

Hi,

Please help me with table control.

My Table Control name is TAB_CONTROL..

My Internal Table name is ITAB.

My Database Table name is ZEMPTAB1.

And fields of the database table is A B C D.

And at last the W/Selcolumn property in table control is CH.

I am facing problem with DELETE option in table control .

could any body help me in writing the delete code for the table control.

12 REPLIES 12
Read only

Former Member
0 Likes
1,115

Hi,

Have you used the table control wizard to create the table contol ?

regards,

Advait.

Read only

0 Likes
1,115

No I have not used any wizard the table control is done with out wizard.

Read only

0 Likes
1,115

Hi,

Make sure that your internal table also has a component FLAG(1) type c.

Once you have added this.

Use the code of this subroutine.

Note you will need to delete from database as well .


*&---------------------------------------------------------------------*
*&      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'.
       DELETE <table> INDEX syst-tabix.
       IF sy-subrc = 0.
         <tc>-lines = <tc>-lines - 1.
       ENDIF.
     ENDIF.
   ENDLOOP.

 ENDFORM.                              " FCODE_DELETE_ROW

regards,

Advait

Read only

0 Likes
1,115

Hi Advait,

The exact code I saw when I used tab control with wizard. but the problem is I am not able to under stand the code at all Like as follows:

1> p_table_name

2> p_mark_name

3> l_table_name

4> FIELD-SYMBOLS <tc> TYPE cxtab_control.

5> FIELD-SYMBOLS <table> TYPE STANDARD TABLE.

6> FIELD-SYMBOLS <wa>.

7> FIELD-SYMBOLS <mark_field>.

8> <mark_field>

9> <table>

and lastly is <mark_field> and p_mark_name are same or some different

&----


*& 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'.

DELETE <table> INDEX syst-tabix.

IF sy-subrc = 0.

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

ENDIF.

ENDIF.

ENDLOOP.

ENDFORM. " FCODE_DELETE_ROW

Read only

0 Likes
1,115

Hi Amit,

Since its a subroutine, you will have to call this subroutine and pass the 3 parameters to that subroutine when the ok_code is 'DELE' ( assuming this is ok code for delete )

now :

p_tc_name TYPE dynfnam , this is the name of the control table.

p_table_name This is the name of the internal table that you have declared globally for processing data

p_mark_name This is the name of the field in the global internal table as I mentioned earlier. (lets call it as MARK

So the internal table needs to be defined as follows :


types : begin of types t_table.
mark type xfeld,   "this will be passed to p_mark_name
vbeln type vbeln,
posnr type posnr,
matnr type matnr,
... (so on just an example )

types end of t_table.

data gt_tc_itab type table of t_table.  "this will be passed to p_table_name

*this will be passed to p_tc_name
CONTROLS GT_TBCTRL1 TYPE TABLEVIEW USING SCREEN <screen_no>.

so in the PAI where the table control screen is .

when you check for the ok _code


case ok_code.

when 'DELE'.
perform fcode_delete_row
  using 'GT_TBCTRL1'  'GT_TC_ITAB' 'MARK'.
when 'INSERT'.
perform insert.
endcase.

Now the code is quite simple. All it does is it loops at the internal table, as it has to delete the selected entries, and where ever the mark is 'X' , it will delete that row. Note that the mark will automatically become 'X' when you select the lines on the table control ( one or many ) using the selection column.

regards,

Advait.

Read only

Former Member
0 Likes
1,115

Hi Amit,

While deleting a record from table control, you have to delete it from both internal table and database table.

Are you doing that?.

Thanks,

Arun

Read only

0 Likes
1,115

Yes I am trying to do that, but I am not getting any success in it.

Read only

0 Likes
1,115

Hi Amit,

Have you tried in debug the PAI part of the code.

Is the record getting deleted from Internal table?

What is the sy-subrc value for after delete statement in database datable?.

Can you post the code that you have written in PAI?

Thanks,

Arun

Read only

0 Likes
1,115

IF CH = 'X'.

DELETE ZEMPMAS INDEX SYST-TABIX.

IF SY-SUBRC = 0.

TAB_CONTROL-LINES = TAB_CONTROL-LINES - 1.

ENDIF.

ENDIF.

HERE CH IS w/selcolumn property of the table control.

ZEMPMAS is the database table

TAB_CONTROL is the table control name.

Read only

0 Likes
1,115

Hi Amit,

if your ZEMPMAS is your database table name, then to delete value from the database use following syntax

DELETE from ZEMPMAS where <condition>

The code you have written is for deleting value from Internal table I guess.

So add the above code and check.

Hope this helps you.

Thanks,

Arun

Read only

Former Member
0 Likes
1,115

hi frnds,

form FILL_PACKLIST .

*--- Perform to manuallly generate the Container no.

perform generate_conno.

clear wa_packlist.

wa_packlist-mandt = sy-mandt.

wa_packlist-vbeln = vbrk-vbeln.

wa_packlist-conno = gv_conno.

wa_packlist-shpno = shpno.

wa_packlist-grswt = grswt.

wa_packlist-tarwt = tarwt.

wa_packlist-netwt = netwt.

append wa_packlist to it_packlist.

form INSERT_PACKLIST.

                                              • inserting data to packlist.

insert zpacklist from table it_packlist.

if sy-subrc = 0.

commit work.

else.

leave program.

endif.

i could append the data when debubbing..but am fetching de data......

is my sample code is correct.

Read only

Former Member
0 Likes
1,115

Hi Amit,

In your internal table structure add one field with char and length one say the field is sel .

Now when creating the table control put that fieldname ie. SEL in the select column of the table control.

You might have some button on screen for deletion of table enrty. Then write module in PAI for deletion logic.

E.g.

*****************************************************************

Module DELETE_ENTRY.

If sy-ucomm = 'DEL'. (say the FCODE for the DElete Button)

Delete Itab where SEL = 'X'.

endif.

Endmodule.

********************************************************************

I hope this will help you .

<REMOVED BY MODERATOR>

Edited by: Alvaro Tejada Galindo on Jun 27, 2008 12:47 PM