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
716

hi guys,

I have created a ztable and a table control...now i want to bring the records into that table control.Points will awarded for helpful answers..

Reg'

Zeemaaaa....

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
685

Hi

See this and do accordingly

syntax:

CONTROLS .

if you only want to determine the row of the table control. SY´-SUBRC allows you to check if the cursor is placed in a row of a table control.

u need to comment the performs of table control fields and write ur own perform statements. And u have to declare the table control fields as separate internal tables.

Go through this urls.

www.saptechnical.com

www.sap-img.com

Check the below links.

http://www.planetsap.com/howdo_a.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/dbac5135c111d1829f0000e829fbfe/content.htm

http://sap.niraj.tripod.com/id25.html

Reward points if useful

Regards

Anji

7 REPLIES 7
Read only

Former Member
0 Likes
686

Hi

See this and do accordingly

syntax:

CONTROLS .

if you only want to determine the row of the table control. SY´-SUBRC allows you to check if the cursor is placed in a row of a table control.

u need to comment the performs of table control fields and write ur own perform statements. And u have to declare the table control fields as separate internal tables.

Go through this urls.

www.saptechnical.com

www.sap-img.com

Check the below links.

http://www.planetsap.com/howdo_a.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/dbac5135c111d1829f0000e829fbfe/content.htm

http://sap.niraj.tripod.com/id25.html

Reward points if useful

Regards

Anji

Read only

Former Member
0 Likes
685

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.

rgds,

bharat.

Read only

Former Member
0 Likes
685

Hi,

see the examples related to Table Control in SE38

demo_dynpro_tabcont_loop

demo_dynpro_tabcont_loop_at

or look in transaction DWDM

RSDEMO_TABLE_CONTROL

LOOP AT <internal table> CURSOR <scroll-var>

[WITH CONTROL <table-control> ]

[FROM <line1> ] [TO <line2> ].

...<actions>...

ENDLOOP.

This form of LOOP loops through the internal table, performing <actions> for each row. For each internal table row, the system transfers the relevant program fields to or from the corresponding screen table row.

Have a look at below links. It will help you.

http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbac5135c111d1829f0000e829fbfe/content.htm

http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbac1d35c111d1829f0000e829fbfe/content.htm

go through this link which ll give you complete idea about the table control

http://www.sapdevelopment.co.uk/dialog/tabcontrol/tc_basic.htm

http://answers.yahoo.com/question/index?qid=20061119065350AA3mZZl

Check this sample programs

http://www.planetsap.com/online_pgm_main_page.htm

http://sap.niraj.tripod.com/id29.html

http://www.sapdevelopment.co.uk/dialog/tabcontrol/tc_basic.htm

Regards,

Priyanka.

Read only

Former Member
0 Likes
685

Hi ,

check this ,

Working with the table control - Example

Scenario:

Screen 601 has a table control named CTRL_ANVSTED.

The table should be filled with records from the table zanvstedm

For this purpose you use an internal table called TBL_ANVSTED

  • Declare the table control

CONTROLS CTRL_ANVSTED TYPE TABLEVIEW USING SCREEN 601.

*Internal table used to hold data

DATA: TBL_ANVSTED LIKE ZANVSTEDM OCCURS 100 WITH HEADER LINE,

  • Flag for initial reading

Data: FLAG_INITIAL TYPE I VALUE 0.

PROCESS BEFORE OUTPUT.

*----


  • Read data into the table control and the internal table

*----


  • PF status etc.

MODULE INITIALIZE_601.

  • Read data from table anvstedm into internal table tbl_anvsted.

MODULE INIT_TBL_ANVSTED.

  • Fill control with data from ythe internal table

LOOP WITH CONTROL CTRL_ANVSTED.

MODULE FILL_CTRL_ANVSTED.

ENDLOOP.

MODULE INIT_TBL_ANVSTED OUTPUT.

  • Read data from table anvstedm into internal table tbl_anvsted.

IF FLAG_INITIAL = 0.

FLAG_INITIAL = 1.

SELECT * FROM ZANVSTEDM INTO TABLE TBL_ANVSTED.

ENDIF.

ENDMODULE.

MODULE FILL_CTRL_ANVSTED OUTPUT.

  • Fill control with data from the internal table

READ TABLE TBL_ANVSTED INDEX CTRL_ANVSTED-CURRENT_LINE.

IF SY-SUBRC NE 0.

EXIT FROM STEP-LOOP.

ENDIF.

ENDMODULE.

PROCESS AFTER INPUT.

  • Write changes in table control to internal table

LOOP WITH CONTROL CTRL_ANVSTED.

MODULE CTRL_ANVSTED.

ENDLOOP.

MODULE CTRL_ANVSTED INPUT.

  • Write changes in table control to internal table

MODIFY TBL_ANVSTED INDEX CTRL_ANVSTED-CURRENT_LINE.

ENDMODULE.

Using a Table control with an internal table

Table control : TC1

Internal table : it_zsd00003

In the attributes of the table control, select w/SelColumn to get a selection

column on the table control, and give a name (In this example IT_ZSD00003-LINESEL).

Remember to include the field IT_ZSD00003-LINESEL in the

internal table ( linesel(1) type c, ).

When used with an internal table, remember to program

the update functionality of the database tables. Update and

validation can be done when leaving the screen or in PAI using controlname-

current_line (E.g. TC1-current_line ) to indentify the entry in the internal table.

process before output.

module status_0100.

loop at it_zsd00003 with control tc1 cursor tc1-

current_line.

module tc1_set_field_attr. "Optional

endloop.

module status_0100 output.

set pf-status 'SCREEN0100'.

  • OPTIONAL: If it_zsd00003 hasn't allready been filled with

  • data, you can do it the first time PBO is called

module read_data.

  • Setting the number of lines of the table control

describe table it_zsd00003 lines tc1-lines.

  • Optional: Place the cursor on line g_current_line e.g. after a

  • validation error has occured

if not ( g_current_line is initial ).

tc1-top_line = g_current_line.

clear g_current_line.

endif.

endmodule. " STATUS_0100 OUTPUT

module read_data.

if flag is initial.

perform read_data.

flag = 1.

endif.

endmodule.

module tc1_set_field_attr output.

  • Optional: Protect some of the columns on the

  • table control

loop at screen.

if screen-group1 = 'X'.

screen-input = 0.

modify screen.

endif.

endloop.

endif.

endmodule. " tc1_set_field_attr OUTPUT

process after input.

loop at it_zsd00003.

module modify_tc1.

endloop.

module user_command_0100.

module modify_tc1 input.

  • Modify an existing entry

modify it_zsd00003 index tc1-current_line.

  • OR

  • Appending a new entry

append it_zsd00003.

endmodule. " modify_tc1 INPUT

Deleting a single line selected with the selection column:

form delete_record.

loop at it_zsd00003.

if it_zsd00003-linesel = 'X'.

exit.

endif.

endloop.

delete from zsd00003

where zdriftscenter = it_zsd00003-zdriftscenter

.................................

endform.

Sorting a table control

While were on the subject. You may need a sort routine in

case the user selects a column and desires to sort on

its contents. All you need is a sort icon on the

applications toolbar of the screens GUI to return the OK-

code

of 'SORT'. You will need to copy this to the PAI of every

screen and change the name of the module, and the actual

itab for this screen

MODULE SORT_screen100 INPUT.

CASE SAVE_OK_CODE.

WHEN 'SORT'.

LOOP AT T1-COLS INTO WA.

IF WA-SELECTED = 'X' .

SPLIT WA-SCREEN-NAME AT '-' INTO FILE FLD.

SORT itab BY (FLD).

ENDIF.

ENDLOOP.

ENDCASE.

ENDMODULE. " SORT_screen100 INPUT

Tom Quinn

ESRI, Redlands, CA.

Scrolling the table control

Now let's look at scrolling.

(assume that the name of your table control is T1)

In the screen logic you will have:

Loop with control T1.

.

.

module get_Looplines.

Endloop.

Module get_looplines.

Looplines = sy-loopc.

Endmodule.

In the PBO of the screen you will have a module that loads

the itab and determines the total number of lines read.

Module load_itab.

.

. (select database table and

append to itab)

.

describe table itab lines linecount.

Endmodule.

We now have all the values necessary to construct a scroll

module.

MODULE SCROLL INPUT.

CASE SAVE_OK_CODE.

WHEN 'P--'.

T1-TOP_LINE = 1.

WHEN 'P-'.

T1-TOP_LINE = T1-TOP_LINE - LOOPLINES.

IF T1-TOP_LINE < 1.

T1-TOP_LINE = 1.

ENDIF.

WHEN 'P+'.

T1-TOP_LINE = T1-TOP_LINE + LOOPLINES.

IF T1-TOP_LINE > LINECOUNT.

T1-TOP_LINE = LINECOUNT - LOOPLINES + 1.

ENDIF.

WHEN 'P++'.

T1-TOP_LINE = LINECOUNT - LOOPLINES + 1.

ENDCASE.

ENDMODULE. " SCROLL INPUT

Or else you can use the below code

WHEN 'P--'.

CLEAR SY-UCOMM.

CTR1-TOP_LINE = 1.

WHEN 'P-'.

CLEAR SY-UCOMM.

CTR1-TOP_LINE = CTR1-TOP_LINE - LINECOUNT1.

IF CTR1-TOP_LINE < 1.

CTR1-TOP_LINE = 1.

ENDIF.

WHEN 'P+'.

DESCRIBE TABLE ITAB1 LINES N1.

CTR1-TOP_LINE = CTR1-TOP_LINE + LINECOUNT1.

IF CTR1-TOP_LINE > N1.

CTR1-TOP_LINE = N1.

ENDIF.

CLEAR SY-UCOMM.

WHEN 'P++'.

DESCRIBE TABLE ITAB1 LINES N1.

CLEAR SY-UCOMM.

CTR1-TOP_LINE = N1.

..

Other hints for using the table contro

1. Setting the number of lines.

2. Scrolling to a spcefic line.

1. Setting the number of lines.

tc1-lines = 500.

> The problem is not in module scroll_code but rather the

lack of module =

> LINE_COUNT in your PBO. I have found this very reliable

and absolutely =

> necessary in getting the scrolling in table function to

work. This module

> =

> has the following code in it:

>

> module line_count output.

> describe table itab lines tc1-lines.

> endmodule.

2. Scrolling to a spcefic line.

tc1-top_line = 500.

Read only

Former Member
0 Likes
685

Hi,

use the link....

http://www.planetsap.com/howdo_a.htm

http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/dbac5135c111d1829f0000e829fbfe/content.htm

http://sap.niraj.tripod.com/id25.html

also ex-

DATA : OK_CODE_150(20).

DATA: MARK(4).

Controls : TABLE_CONTROL TYPE TABLEVIEW USING SCREEN 150.

DATA : BEGIN OF I_TAB OCCURS 0,

MATNR TYPE MATNR,

MTART TYPE MTART,

MEINS TYPE MEINS,

END OF I_TAB.

*********************************FOR EXIT COMMAND****************************************************

&----


*& Module USER_COMMAND_0150 INPUT

&----


  • text

----


MODULE USER_COMMAND_0150 INPUT.

CASE OK_CODE_150.

WHEN 'EXIT'.

SET SCREEN 0.

LEAVE SCREEN.

ENDCASE.

ENDMODULE. " USER_COMMAND_0150 INPUT

*********************************FATCH DATA ***********************************************************

&----


*& Module STATUS_0150 OUTPUT

&----


  • text

----


MODULE STATUS_0150 OUTPUT.

  • SET PF-STATUS 'xxxxxxxx'.

  • SET TITLEBAR 'xxx'.

REFRESH I_TAB.

SELECT

MATNR

MTART

MEINS

INTO CORRESPONDING FIELDS OF TABLE I_TAB

FROM MARA

WHERE MTART = 'FERT'.

ENDMODULE. " STATUS_0150 OUTPUT

***********************READ IT AND ADD ENTRY IN TABLE CONTROL ONE BY ONE*****************************

&----


*& Module ADD_ENTRIES OUTPUT

&----


  • text

----


MODULE ADD_ENTRIES OUTPUT.

CLEAR I_TAB.

READ TABLE I_TAB INDEX TABLE_CONTROL-CURRENT_LINE.

ENDMODULE. " ADD_ENTRIES OUTPUT

************************READ TABLE-CONTROL***********************************************************

&----


*& Module READ_ENTRIES INPUT

&----


  • text

----


MODULE READ_ENTRIES input.

IF I_TAB-MATNR IS INITIAL.

ENDIF.

ENDMODULE. " READ_ENTRIES INPUT

*****do reward if usefull

Regards,

vijay

Read only

Former Member
0 Likes
685

Hi,

Declare a Internal table type of that Ztable,

Create the Table control and give the fields from that Internal table, so that the recrods from the Internal table will come and sit in the Table control ...

IN PBO event, write a Select statment to retrive the records from the Z table and fill in the Internal table.

then Write the LOOP with Control and ENDLOOP.

Regards

Sudheer

Read only

Former Member
0 Likes
685

Hi,

Check the following code:

Scenario:

Screen 601 has a table control named CTRL_ANVSTED.

The table should be filled with records from the table zanvstedm

For this purpose you use an internal table called TBL_ANVSTED

  • Declare the table control

CONTROLS CTRL_ANVSTED TYPE TABLEVIEW USING SCREEN 601.

*Internal table used to hold data

DATA: TBL_ANVSTED LIKE ZANVSTEDM OCCURS 100 WITH HEADER LINE,

  • Flag for initial reading

Data: FLAG_INITIAL TYPE I VALUE 0.

PROCESS BEFORE OUTPUT.

*----


  • Read data into the table control and the internal table

*----


  • PF status etc.

MODULE INITIALIZE_601.

  • Read data from table anvstedm into internal table tbl_anvsted.

MODULE INIT_TBL_ANVSTED.

  • Fill control with data from ythe internal table

LOOP WITH CONTROL CTRL_ANVSTED.

MODULE FILL_CTRL_ANVSTED.

ENDLOOP.

MODULE INIT_TBL_ANVSTED OUTPUT.

  • Read data from table anvstedm into internal table tbl_anvsted.

IF FLAG_INITIAL = 0.

FLAG_INITIAL = 1.

SELECT * FROM ZANVSTEDM INTO TABLE TBL_ANVSTED.

ENDIF.

ENDMODULE.

MODULE FILL_CTRL_ANVSTED OUTPUT.

  • Fill control with data from the internal table

READ TABLE TBL_ANVSTED INDEX CTRL_ANVSTED-CURRENT_LINE.

IF SY-SUBRC NE 0.

EXIT FROM STEP-LOOP.

ENDIF.

ENDMODULE.

PROCESS AFTER INPUT.

  • Write changes in table control to internal table

LOOP WITH CONTROL CTRL_ANVSTED.

MODULE CTRL_ANVSTED.

ENDLOOP.

MODULE CTRL_ANVSTED INPUT.

  • Write changes in table control to internal table

MODIFY TBL_ANVSTED INDEX CTRL_ANVSTED-CURRENT_LINE.

ENDMODULE.

Hope this helps.

Reward if helpful.

Regards,

Sipra