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: 

TABLE CONTROL

Former Member
0 Kudos
153

Hi

help me in creating table control. after drag and drop of table control in to the screen what are the steps to be followed ?

1 ACCEPTED SOLUTION

Former Member
0 Kudos
112

Hi,

Hope this step by step e.g. will help u a lot.

Refer program :

After draging control to screen give a name. give gui status.

Define it in program as :

controls table type tableview using screen 100.

Then in screen flow logic create codes like this :

process before output.
  module  init.
  module fill_itab.
  loop with control table.
    module transp_itab.
    module lines.
  endloop.

process after input.
  module exit at exit-command.
  module check_pai.
  loop with control table.
    module check_table.
  endloop.
  module check_all.
  module scroll.

Create modules like this:

report demo_dynpro_table_control_1  message-id sabapdocu.

data: begin of itab occurs 10,
        mark,
        col1 type i,
        col2 type i,
      end of itab.


data ok_code type sy-ucomm.
data ok_save type sy-ucomm.
data tab_lines type i.
data step_lines type i.
data offset type i.

controls table type tableview using screen 100.

call screen 100.

module init output.
  set pf-status 'BASIC'.
endmodule.

module fill_itab output.
  describe table itab lines tab_lines.
  if tab_lines = 0.
    do 40 times.
      itab-col1 = sy-index.
      itab-col2 = sy-index ** 2.
      append itab.
    enddo.
    describe table itab lines tab_lines.
    table-lines = tab_lines.
  endif.
endmodule.

module transp_itab output.
  read table itab index table-current_line.
endmodule.

module lines output.
  step_lines = sy-loopc.
endmodule.

module exit input.
  leave program.
endmodule.

module check_pai input.
  ok_save = ok_code. clear ok_code.
  message s888 with 'TOP_LINE: ' table-top_line
                    ', LINES: '  step_lines.
endmodule.

module check_table input.
  case ok_save.
    when 'MARK'.
      if itab-mark = 'X'.
        message i888 with 'Zeile' table-current_line 'markiert'.
      endif.
    when 'SETM'.
      modify itab index table-current_line.
  endcase.

endmodule.

module check_all input.
  case ok_save.
    when 'ALLM'.
      loop at itab.
        if itab-mark = 'X'.
          message i888 with 'Zeile' sy-tabix 'markiert'.
        endif.
      endloop.
    when 'DELE'.
      loop at itab.
        if itab-mark = 'X'.
          itab-mark = ' '.
          modify itab.
        endif.
      endloop.
  endcase.
endmodule.

module scroll input.
  case ok_save.
    when 'PGDO'.
      offset = table-lines - step_lines.
      if table-top_line lt offset.
        table-top_line = table-top_line + step_lines.
      endif.
    when 'PGUP'.
      offset = step_lines.
      if table-top_line gt offset.
        table-top_line = table-top_line - step_lines.
      else.
        table-top_line = 1.
      endif.
    when 'PGLA'.
      table-top_line = table-lines - step_lines + 1.
    when 'PGTO'.
      table-top_line = 1.
  endcase.
endmodule.

Jogdand M B

14 REPLIES 14

Former Member
0 Kudos
112

first thing is u have to declare the table control as

CONTROLS <table name> TYPE TABLEVIEW USING SCREEN scr.

and then call the screen using screen no..

Reward if useful..

Reg'

Zeemaaaa......

former_member196299
Active Contributor
0 Kudos
112

Hi Ganesh ,

Here you go with the complete steps :

open se51, choose the icon like a table for table control . drag it and then place it in your screen . click on F6 and you will get a screen where youi need to provide the table name / field name that ( fields ) you are going to use in the screen and table control. after giving the ztable name click on get it from dictionary . you will get the list of available fields in a table. next choose the fields you wish to place in the table control , and if you want to place all fields in your table control then select every fields . after this you will get a structure which you should drag place inside the table control area .

double click on the table control , set the proper attributes, tickmark the horizontal and vertical scroll bars to appear in your TC in the screen . save , check and activate ..

following are the sample code you should follow to display datas in your table control ..

write the following code in the flow logic of the screen ............

process before output.

module tc_01_init.

loop at g_tc_01_itab

into g_tc_01_wa

with control tc_01

cursor tc_01-current_line.

module tc_01_move.

module tc_01_get_lines.

endloop.

module status_0001.

process after input.

loop at g_tc_01_itab.

chain.

field sflight-carrid.

field sflight-connid.

field sflight-fldate.

module tc_01_modify on chain-request.

endchain.

endloop.

module tc_01_user_command.

Write the following code in your Zmodulepool program !!

program z_tst_mpool_tc_01.

data: begin of l_tab_sflight occurs 10,

carrid like sflight-carrid,

connid like sflight-connid,

fldate like sflight-fldate,

end of l_tab_sflight.

tables: sflight.

types: begin of t_tc_01,

carrid like sflight-carrid,

connid like sflight-connid,

fldate like sflight-fldate,

end of t_tc_01.

data: g_tc_01_itab type t_tc_01 occurs 0,

g_tc_01_wa type t_tc_01. "work area

data: g_tc_01_copied. "copy flag

controls: tc_01 type tableview using screen 0001.

data: g_tc_01_lines like sy-loopc.

data: ok_code like sy-ucomm.

include z_tst_mpool_tc_01_pbo .

include z_tst_mpool_tc_01_pai .

include z_tst_mpool_tc_01_incl01 .

include z_tst_mpool_tc_01_status_0001.

include Z_TST_MPOOL_TC_01_PBO .

  • inside include

module tc_01_init output.

if g_tc_01_copied is initial.

select * from sflight

into corresponding fields

of table g_tc_01_itab.

g_tc_01_copied = 'X'.

refresh control 'TC_01' from screen '0001'.

endif.

endmodule.

module tc_01_move output.

move-corresponding g_tc_01_wa to sflight.

endmodule.

module tc_01_get_lines output.

g_tc_01_lines = sy-loopc.

endmodule.

Hope this helps .....

for any further clarification respond back ..

Reward if helpful

Regards,

Ranjita

0 Kudos
112

hi ranjita

i am not getting the "selection column" in table control.what to do

0 Kudos
112

go to the attributes of the table control , tick mark the w/sel colomn field and provide a variable name with char 1 . you will get it in your TC .

Regards,

Ranjita

0 Kudos
112

Hi Ganesh,

I easiest way of creating table control is creating table control wizard, but make sure that before creating table control the final internal table shoud be declared which the table control is referred.

when u use the wizard it automatically writes the necessary code for the table control.

just try out once...

hope this helps.

Regards,

Line

0 Kudos
112

Ganesh,

Which selection column you want, as per my understanding I understood that u need to select some records from the displayed records in the table control.

For that u need to declare a vairable in the internal table with char 1 and then it will automatically reflects in the table control if you are using wizard.

If you have already created the table control then just select the check box from the tool bar and drop in the table control.

and need to write the coding for the selected records.

Regards,

Line

Former Member
0 Kudos
112

Former Member
0 Kudos
112

hi

the easy way to create a table control is use table control wizard icon.

it will give all the steps needed for creating table ctrl....

it will only generate the code according with the data given by us during creation...

just try out once...

hope this helps.

Former Member
0 Kudos
112

Hi

Check if this is helpful

REPORT demo_dynpro_tabcont_loop.

CONTROLS flights TYPE TABLEVIEW USING SCREEN 100.

DATA: ok_code TYPE sy-ucomm,

save_ok TYPE sy-ucomm.

DATA: itab TYPE TABLE OF demo_conn,

fill TYPE i.

TABLES demo_conn.

DATA: lines TYPE i,

limit TYPE i.

SELECT * FROM spfli INTO CORRESPONDING FIELDS OF TABLE itab.

CALL SCREEN 100.

MODULE status_0100 OUTPUT.

SET PF-STATUS 'SCREEN_100'.

DESCRIBE TABLE itab LINES fill.

flights-lines = fill.

ENDMODULE.

MODULE fill_table_control OUTPUT.

READ TABLE itab INTO demo_conn INDEX flights-current_line.

ENDMODULE.

MODULE cancel INPUT.

LEAVE PROGRAM.

ENDMODULE.

MODULE read_table_control INPUT.

lines = sy-loopc.

MODIFY itab FROM demo_conn INDEX flights-current_line.

ENDMODULE.

MODULE user_command_0100 INPUT.

save_ok = ok_code.

CLEAR ok_code.

CASE save_ok.

WHEN 'NEXT_LINE'.

flights-top_line = flights-top_line + 1.

limit = fill - lines + 1.

IF flights-top_line > limit.

flights-top_line = limit.

ENDIF.

WHEN 'PREV_LINE'.

flights-top_line = flights-top_line - 1.

IF flights-top_line < 0.

flights-top_line = 0.

ENDIF.

WHEN 'NEXT_PAGE'.

flights-top_line = flights-top_line + lines.

limit = fill - lines + 1.

IF flights-top_line > limit.

flights-top_line = limit.

ENDIF.

WHEN 'PREV_PAGE'.

flights-top_line = flights-top_line - lines.

IF flights-top_line < 0.

flights-top_line = 0.

ENDIF.

WHEN 'LAST_PAGE'.

flights-top_line = fill - lines + 1.

WHEN 'FIRST_PAGE'.

flights-top_line = 0.

ENDCASE.

ENDMODULE.

Regards

Dinesh

Former Member
0 Kudos
113

Hi,

Hope this step by step e.g. will help u a lot.

Refer program :

After draging control to screen give a name. give gui status.

Define it in program as :

controls table type tableview using screen 100.

Then in screen flow logic create codes like this :

process before output.
  module  init.
  module fill_itab.
  loop with control table.
    module transp_itab.
    module lines.
  endloop.

process after input.
  module exit at exit-command.
  module check_pai.
  loop with control table.
    module check_table.
  endloop.
  module check_all.
  module scroll.

Create modules like this:

report demo_dynpro_table_control_1  message-id sabapdocu.

data: begin of itab occurs 10,
        mark,
        col1 type i,
        col2 type i,
      end of itab.


data ok_code type sy-ucomm.
data ok_save type sy-ucomm.
data tab_lines type i.
data step_lines type i.
data offset type i.

controls table type tableview using screen 100.

call screen 100.

module init output.
  set pf-status 'BASIC'.
endmodule.

module fill_itab output.
  describe table itab lines tab_lines.
  if tab_lines = 0.
    do 40 times.
      itab-col1 = sy-index.
      itab-col2 = sy-index ** 2.
      append itab.
    enddo.
    describe table itab lines tab_lines.
    table-lines = tab_lines.
  endif.
endmodule.

module transp_itab output.
  read table itab index table-current_line.
endmodule.

module lines output.
  step_lines = sy-loopc.
endmodule.

module exit input.
  leave program.
endmodule.

module check_pai input.
  ok_save = ok_code. clear ok_code.
  message s888 with 'TOP_LINE: ' table-top_line
                    ', LINES: '  step_lines.
endmodule.

module check_table input.
  case ok_save.
    when 'MARK'.
      if itab-mark = 'X'.
        message i888 with 'Zeile' table-current_line 'markiert'.
      endif.
    when 'SETM'.
      modify itab index table-current_line.
  endcase.

endmodule.

module check_all input.
  case ok_save.
    when 'ALLM'.
      loop at itab.
        if itab-mark = 'X'.
          message i888 with 'Zeile' sy-tabix 'markiert'.
        endif.
      endloop.
    when 'DELE'.
      loop at itab.
        if itab-mark = 'X'.
          itab-mark = ' '.
          modify itab.
        endif.
      endloop.
  endcase.
endmodule.

module scroll input.
  case ok_save.
    when 'PGDO'.
      offset = table-lines - step_lines.
      if table-top_line lt offset.
        table-top_line = table-top_line + step_lines.
      endif.
    when 'PGUP'.
      offset = step_lines.
      if table-top_line gt offset.
        table-top_line = table-top_line - step_lines.
      else.
        table-top_line = 1.
      endif.
    when 'PGLA'.
      table-top_line = table-lines - step_lines + 1.
    when 'PGTO'.
      table-top_line = 1.
  endcase.
endmodule.

Jogdand M B

Former Member
0 Kudos
112

GO through the below link. Verrrrrry useful.

Download the file via this link.

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/abap/abap-code-sam...

Hope this will solve ur problem..

<b><u>Dont forget to reward all the useful replies</u></b>

Sudheer

Former Member
0 Kudos
112

Hi,

PROGRAM ZBHTCTRL.

TABLES: LFA1, EKKO.

DATA: OKCODE1 LIKE SY-UCOMM,

OKCODE2 LIKE SY-UCOMM.

CONTROLS TABC TYPE TABLEVIEW USING SCREEN 1001.

DATA: BEGIN OF ITAB OCCURS 0,

MANDT LIKE EKKO-MANDT,

EBELN LIKE EKKO-EBELN,

BSTYP LIKE EKKO-BSTYP,

BSART LIKE EKKO-BSART,

END OF ITAB.

MODULE USER_COMMAND_1000 INPUT.

CASE OKCODE1.

WHEN 'BACK'.

SET SCREEN 0.

WHEN 'NEXT'.

SET SCREEN 1001.

SELECT * FROM EKKO INTO CORRESPONDING FIELDS OF TABLE ITAB WHERE

LIFNR = LFA1-LIFNR.

ENDCASE.

ENDMODULE. " USER_COMMAND_1001 INPUT

MODULE MOVE_DATA OUTPUT.

EKKO-MANDT = ITAB-MANDT.

EKKO-EBELN = ITAB-EBELN.

EKKO-BSTYP = ITAB-BSTYP.

EKKO-BSART = ITAB-BSART.

ENDMODULE. " MOVE_DATA OUTPUT

MODULE USER_COMMAND_1001 INPUT.

CASE OKCODE2.

WHEN 'BACK'.

SET SCREEN 1000.

ENDCASE.

ENDMODULE. " USER_COMMAND_1001 OUTPUT

MODULE STATUS_1001 OUTPUT.

SET PF-STATUS 'MENU'.

SET TITLEBAR 'TIT'.

ENDMODULE. " STATUS_1001 OUTPUT

MODULE STATUS_1000 OUTPUT.

SET PF-STATUS 'DMENU'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_1000 OUTPUT

FORM ON_CTMENU_FORM1 USING CMENU TYPE REF TO CL_CTMENU.

CALL METHOD CMENU->LOAD_GUI_STATUS

EXPORTING

PROGRAM = ' ZBHTCTRL'

STATUS = 'CMENU'

MENU = CMENU.

CALL METHOD CMENU->ADD_FUNCTION

EXPORTING

FCODE = 'RX'

TEXT = 'RECIEVE'.

ENDFORM.

FLOW LOGIC:

PROCESS BEFORE OUTPUT.

MODULE STATUS_1000.

*

PROCESS AFTER INPUT.

MODULE USER_COMMAND_1000.

PROCESS BEFORE OUTPUT.

MODULE STATUS_1001.

LOOP AT ITAB WITH CONTROL TABC CURSOR TABC-TOP_LINE.

MODULE MOVE_DATA.

ENDLOOP.

*

PROCESS AFTER INPUT.

MODULE USER_COMMAND_1001.

LOOP AT ITAB.

ENDLOOP.

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

inserting rows:

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

FORM INSERT_ROW USING TABCTRL TYPE DYNFNAM TABLE_DISP.

  • 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.

  • END OF LOCAL DATA

ASSIGN (TABCTRL) TO <TC>.

  • get the table, which we are displaying in table control

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

ASSIGN (L_TABLE_NAME) TO <TABLE>.

  • get number of lines of Table Control

CONCATENATE TABCTRL '-LINES' INTO L_LINES_NAME.

ASSIGN (L_LINES_NAME) TO <LINES>.

  • 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.

  • set new cursor line

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

  • insert initial line

INSERT INITIAL LINE INTO <TABLE> INDEX L_SELLINE.

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

  • &set cursor

SET CURSOR LINE L_LINE.

ENDFORM.

rgds,

bharat.