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,345

Can any one help me to get data from table control to internal table?

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,303

HI Chandu

If you want to use a table control, you will need to create a screen.

In your report....

start-of-selection.

perform get_data. " Get all your data here

call screen 100. " Now present to the user.

Double click on the "100" in your call screen statement. This will forward navigate you to the screen. If you have not created it yet, it will ask you if you want to create it, say yes. Go into screen painter or layout of the screen. Use the table control wizard to help you along the process. It will write the code for you. Since it is an output only table control, it will be really easy with not a lot of code.

A better way to present the data to the user would be to give it in a ALV grid. If you want to go that way, it is a lot easier. Here is a sample of the ALV function module. You don't even have to create a screen.

report zrich_0004

no standard page heading.

type-pools slis.

data: fieldcat type slis_t_fieldcat_alv.

data: begin of imara occurs 0,

matnr type mara-matnr,

maktx type makt-maktx,

end of imara.

  • Selection Screen

selection-screen begin of block b1 with frame title text-001 .

select-options: s_matnr for imara-matnr .

selection-screen end of block b1.

start-of-selection.

perform get_data.

perform write_report.

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

  • Get_Data

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

form get_data.

select maramatnr maktmaktx

into corresponding fields of table imara

from mara

inner join makt

on maramatnr = maktmatnr

where mara~matnr in s_matnr

and makt~spras = sy-langu.

endform.

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

  • WRITE_REPORT

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

form write_report.

perform build_field_catalog.

  • CALL ABAP LIST VIEWER (ALV)

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

it_fieldcat = fieldcat

tables

t_outtab = imara.

endform.

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

  • BUILD_FIELD_CATALOG

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

form build_field_catalog.

data: fc_tmp type slis_t_fieldcat_alv with header line.

clear: fieldcat. refresh: fieldcat.

clear: fc_tmp.

fc_tmp-reptext_ddic = 'Material Number'.

fc_tmp-fieldname = 'MATNR'.

fc_tmp-tabname = 'IMARA'.

fc_tmp-outputlen = '18'.

fc_tmp-col_pos = 2.

append fc_tmp to fieldcat.

clear: fc_tmp.

fc_tmp-reptext_ddic = 'Material'.

fc_tmp-fieldname = 'MAKTX'.

fc_tmp-tabname = 'IMARA'.

fc_tmp-outputlen = '40'.

fc_tmp-col_pos = 3.

append fc_tmp to fieldcat.

endform.

Regards

Laxmi

8 REPLIES 8
Read only

Former Member
0 Likes
1,303

Check demo programs

DEMO_DYNPRO_TABLE_CONTROL_1

DEMO_DYNPRO_TABLE_CONTROL_2

Read only

Former Member
0 Likes
1,303

HI Chandu,

It is better if you get the fields (In layout design) from the program when you create your table control).

If you chose the button get from program, then you can use the internal table in your program directly in your table control.

This way you may not explicitly transfer data from the TC into itab.

Regards,

Ravi

Read only

Former Member
0 Likes
1,303

hi chandu,

take the fields of table control from the internal table declared in the program.( by selecting GET FROM PROGRAM)

TABLES: kna1,knbk.

DATA: v_kunnr LIKE kna1-kunnr.

DATA: v_check TYPE c.

DATA: BEGIN OF it_knbk OCCURS 0,

banks LIKE knbk-banks,

bankl LIKE knbk-bankl,

bankn LIKE knbk-bankn,

bkont LIKE knbk-bkont,

koinh LIKE knbk-koinh,

chk TYPE c,

END OF it_knbk.

DATA: v_ucomm TYPE sy-ucomm,

v_dynnr TYPE sy-dynnr.

DATA: l_index TYPE sy-index.

data: count type i.

CONTROLS: tc1 TYPE TABLEVIEW USING SCREEN 0200.

&----


*& Module STATUS_0100 OUTPUT

&----


  • text

----


MODULE status_0100 OUTPUT.

SET PF-STATUS 'ABC'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0100 OUTPUT

&----


*& Module USER_COMMAND_0100 INPUT

&----


  • text

----


MODULE user_command_0100 INPUT.

v_ucomm = sy-ucomm.

CASE v_ucomm.

WHEN 'DISP' OR 'CHNG'.

IF v_kunnr <> space.

SELECT banks

bankl

bankn

bkont

koinh

FROM knbk

INTO TABLE it_knbk

WHERE kunnr = v_kunnr.

LEAVE TO SCREEN '0200'.

ENDIF.

WHEN 'BACK'.

LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE. " USER_COMMAND_0100 INPUT

&----


*& Module MOD_KUNNR INPUT

&----


  • text

----


MODULE mod_kunnr INPUT.

IF NOT v_kunnr IS INITIAL.

SELECT SINGLE

kunnr

FROM kna1

INTO v_kunnr

WHERE kunnr = v_kunnr.

IF sy-subrc <> 0.

MESSAGE e000(zz) WITH 'INCORRECT CUSTOMER NUMBER'.

ENDIF.

ENDIF.

IF v_kunnr IS INITIAL.

MESSAGE e000(zz) WITH 'PLEASE ENTER A VALUE'.

ENDIF.

ENDMODULE. " MOD_KUNNR INPUT

&----


*& Module STATUS_0200 OUTPUT

&----


  • text

----


MODULE status_0200 OUTPUT.

SET PF-STATUS 'ABC1'.

  • SET TITLEBAR 'xxx'.

ENDMODULE. " STATUS_0200 OUTPUT

&----


*& Module SCREENMOD OUTPUT

&----


  • text

----


MODULE screenmod OUTPUT.

IF v_ucomm = 'DISP'.

LOOP AT SCREEN.

screen-input = 0.

MODIFY SCREEN.

ENDLOOP.

ELSE."if v_UCOMM = 'CHNG'.

LOOP AT SCREEN.

IF screen-group1 = 'G1'.

screen-input = 0.

ELSE.

screen-input = 1.

ENDIF.

MODIFY SCREEN.

ENDLOOP.

endif.

if sy-ucomm = 'INSE'.

loop at screen.

IF ( tc1-current_line <> tc1-lines ).

screen-input = 0.

else.

screen-input = 1.

modify screen.

endif.

endloop.

endif.

ENDMODULE. " SCREENMOD OUTPUT

&----


*& Module EXIT2 INPUT

&----


  • text

----


MODULE exit2 INPUT.

LEAVE TO SCREEN 0.

ENDMODULE. " EXIT2 INPUT

&----


*& Module modify INPUT

&----


  • text

----


MODULE modify INPUT.

IF v_check = 'X'.

it_knbk-chk = 'X'.

MODIFY it_knbk index tc1-current_line.

ELSE.

CLEAR it_knbk-chk .

ENDIF.

ENDMODULE. " modify INPUT

&----


*& Module USER_COMMAND_0200 INPUT

&----


  • text

----


MODULE user_command_0200 INPUT.

v_ucomm = sy-ucomm.

CASE v_ucomm.

WHEN 'DELE'.

DELETE it_knbk where chk eq 'X'.

DESCRIBE TABLE it_knbk LINES tc1-lines.

WHEN 'INSE'.

CLEAR it_knbk.

APPEND it_knbk.

DESCRIBE TABLE it_knbk LINES tc1-lines.

WHEN 'LIST'.

LEAVE TO LIST-PROCESSING AND RETURN TO SCREEN '0200'.

WRITE 'Report'.

WHEN 'BACK'.

LEAVE TO SCREEN '0100'.

ENDCASE.

ENDMODULE. " USER_COMMAND_0200 INPUT

&----


*& Module validate INPUT

&----


  • text

----


module validate input.

IF IT_KNBK IS INITIAL.

MESSAGE E000(ZZ) WITH 'A BLANK LINE CANNOT BE SAVED'.

ENDIF.

endmodule. " validate INPUT

hope this helps,

priya.<b></b><b></b><b></b><b></b><b></b>

Read only

Former Member
0 Likes
1,303

Hi,

When you design the layout and click on the get from program fields and drag them and place in to the layout then those internal table fields will be acted as interface work area.. So you need not explicitly transfer the data to an internal table.

Please reward if it is helpful.

Regards,

Sampath.

Read only

0 Likes
1,303

hi

i did the same thing but when i am inserting data from internal table to database i am seeing that all the values are becoming zeros.i tried to print the values of the internaltable into the textbox but i am getting null values.

plese help me.

Read only

Former Member
0 Likes
1,303

Hi,

Check the Demo programs <b>RSDEMO02

RSDEMO_TABLE_CONTROL</b>

Regards

vijay

Read only

rahulkavuri
Active Contributor
0 Likes
1,303

In this code below we change the data in the internal table using table control

*&---------------------------------------------------------------------*
*&  Include           Z50660_TRANPRACI01                               *
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Module  STATUS_0400  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE STATUS_0400 OUTPUT.
  SET PF-STATUS 'CMST'.
*  SET TITLEBAR 'xxx'.

ENDMODULE.                 " STATUS_0400  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  SET_COMMON_STAT  INPUT
*&---------------------------------------------------------------------*
*       TO SET COMMON STATUS
*----------------------------------------------------------------------*
MODULE SET_COMMON_STAT INPUT.

IF R1 = 'X'.
  V_SUBSCR = '0200'.
ELSE.
  V_SUBSCR = '0300'.
ENDIF.

CASE SY-UCOMM.

WHEN 'DISPLAY'.
    CLEAR SY-UCOMM.
    FLAG1 = 'X'.
    CLEAR FLAG2.
    CALL SCREEN 0400.

<b>WHEN 'CHANGE'.
    CLEAR SY-UCOMM.
    FLAG2 = 'X'.
    CLEAR FLAG1.
    CALL SCREEN 0400.</b>
WHEN 'BACK' OR 'EXIT' OR 'CANCEL'.
  CLEAR SY-UCOMM.
  LEAVE TO SCREEN 0.

ENDCASE.

ENDMODULE.                 " SET_COMMON_STAT  INPUT
*&---------------------------------------------------------------------*
*&      Module  CHECK_INPUT  INPUT
*&---------------------------------------------------------------------*
*       TO CHECK THE GIVEN SELECTION CRITERIA
*----------------------------------------------------------------------*
MODULE CHECK_INPUT INPUT.

IF V_VBELN IS INITIAL.
   MESSAGE E000(ZZ) WITH 'PLEASE ENTER A VALID SALES'
                         'DOCUMENT NUMBER'.
 ELSEIF V_VKORG IS INITIAL.
   MESSAGE E000(ZZ) WITH 'PLEASE ENTER A VALID SALES'
                         'ORGANIZATION'.

   ELSEIF V_VTWEG IS INITIAL.
    MESSAGE E000(ZZ) WITH 'PLEASE ENTER A VALID'
                         'DISTRIBUTION CHANNEL'.
   ELSE.
   SELECT SINGLE * FROM VBAK
          WHERE VBELN = V_VBELN
            AND VKORG = V_VKORG
            AND VTWEG = V_VTWEG.
    IF SY-SUBRC <> 0.
     MESSAGE I000(ZZ) WITH 'NO RECORDS FOR GIVEN SEARCH CRITERIA'.
    ENDIF.
ENDIF.

ENDMODULE.                 " CHECK_INPUT  INPUT
*&---------------------------------------------------------------------*
*&      Module  POPULATE_HEADER  INPUT
*&---------------------------------------------------------------------*
*       TO POPULATE HEADER DATA
*----------------------------------------------------------------------*
MODULE POPULATE_HEADER INPUT.

  SELECT SINGLE VBELN ERDAT ERNAM VBTYP WAERK
                FROM VBAK
                INTO  (V1_VBELN,V_ERDAT,V_ERNAM,V_VBTYP,V_WAERK)
                WHERE VBELN = V_VBELN.

ENDMODULE.                 " POPULATE_HEADER  INPUT
*&---------------------------------------------------------------------*
*&      Module  POPULATE_ITEM  INPUT
*&---------------------------------------------------------------------*
*       TO POULATE ITEM DETAILS
*----------------------------------------------------------------------*
MODULE POPULATE_ITEM INPUT.

SELECT VBELN POSNR MATNR MATKL NETWR
             FROM VBAP
             INTO TABLE IT_VBAP
             WHERE VBELN = V_VBELN.

ENDMODULE.                 " POPULATE_ITEM  INPUT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0400  INPUT
*&---------------------------------------------------------------------*
*       CODE FOR INSERT AND MODIFY  BUTTONS
*----------------------------------------------------------------------*
MODULE USER_COMMAND_0400 INPUT.

IF SY-UCOMM = 'MOD'.
   CLEAR SY-UCOMM.
   FLAG3 = 'X'.
ENDIF.


ENDMODULE.                 " USER_COMMAND_0400  INPUT
*&---------------------------------------------------------------------*
*&      Module  MODIFY_IT_VBAP  INPUT
*&---------------------------------------------------------------------*
*       TO MODIFY INTERNAL TABLE
*----------------------------------------------------------------------*
MODULE MODIFY_IT_VBAP INPUT.

<b>IF FLAG3 = 'X'.
 MODIFY IT_VBAP INDEX TC-CURRENT_LINE.
  MOVE-CORRESPONDING IT_VBAP TO WA_VBAP.
 MODIFY VBAP FROM WA_VBAP.
ENDIF.</b>
ENDMODULE.                 " MODIFY_IT_VBAP  INPUT

If u need the full code of dialog programming please let me know

Read only

Former Member
0 Likes
1,304

HI Chandu

If you want to use a table control, you will need to create a screen.

In your report....

start-of-selection.

perform get_data. " Get all your data here

call screen 100. " Now present to the user.

Double click on the "100" in your call screen statement. This will forward navigate you to the screen. If you have not created it yet, it will ask you if you want to create it, say yes. Go into screen painter or layout of the screen. Use the table control wizard to help you along the process. It will write the code for you. Since it is an output only table control, it will be really easy with not a lot of code.

A better way to present the data to the user would be to give it in a ALV grid. If you want to go that way, it is a lot easier. Here is a sample of the ALV function module. You don't even have to create a screen.

report zrich_0004

no standard page heading.

type-pools slis.

data: fieldcat type slis_t_fieldcat_alv.

data: begin of imara occurs 0,

matnr type mara-matnr,

maktx type makt-maktx,

end of imara.

  • Selection Screen

selection-screen begin of block b1 with frame title text-001 .

select-options: s_matnr for imara-matnr .

selection-screen end of block b1.

start-of-selection.

perform get_data.

perform write_report.

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

  • Get_Data

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

form get_data.

select maramatnr maktmaktx

into corresponding fields of table imara

from mara

inner join makt

on maramatnr = maktmatnr

where mara~matnr in s_matnr

and makt~spras = sy-langu.

endform.

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

  • WRITE_REPORT

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

form write_report.

perform build_field_catalog.

  • CALL ABAP LIST VIEWER (ALV)

call function 'REUSE_ALV_GRID_DISPLAY'

exporting

it_fieldcat = fieldcat

tables

t_outtab = imara.

endform.

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

  • BUILD_FIELD_CATALOG

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

form build_field_catalog.

data: fc_tmp type slis_t_fieldcat_alv with header line.

clear: fieldcat. refresh: fieldcat.

clear: fc_tmp.

fc_tmp-reptext_ddic = 'Material Number'.

fc_tmp-fieldname = 'MATNR'.

fc_tmp-tabname = 'IMARA'.

fc_tmp-outputlen = '18'.

fc_tmp-col_pos = 2.

append fc_tmp to fieldcat.

clear: fc_tmp.

fc_tmp-reptext_ddic = 'Material'.

fc_tmp-fieldname = 'MAKTX'.

fc_tmp-tabname = 'IMARA'.

fc_tmp-outputlen = '40'.

fc_tmp-col_pos = 3.

append fc_tmp to fieldcat.

endform.

Regards

Laxmi