Skip to Content
author's profile photo Former Member
Former Member

table control

Hi,

PLease send a sample program on table control.

regards,

kb

Add a comment
10|10000 characters needed characters exceeded

Assigned Tags

Related questions

7 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Feb 15, 2008 at 08:12 AM

    Kb,

    This is good standard program..

    "RSDEMO_TABLE_CONTROL"

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 15, 2008 at 08:30 AM

    DATA: BEGIN OF it_xk01 OCCURS 0,

    f1(1),

    f2(5),

    f3(5),

    f4(9),

    f5(9),

    END OF it_xk01.

    DATA: v_count(2) VALUE '00',

    v_koinh(14),

    v_banks(14),

    v_bankn(14),

    v_bankl(14),

    it_bdcdata TYPE STANDARD TABLE OF bdcdata WITH HEADER LINE,

    wa_ctuparams type ctu_params.

    PARAMETERS: p_file TYPE rlgrap-filename OBLIGATORY.

    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.

    PERFORM get_f4.

    START-OF-SELECTION.

    PERFORM upload_data.

    END-OF-SELECTION.

    LOOP AT it_xk01.

    IF it_xk01-f1 = 'H'.

    PERFORM bdc_dynpro USING 'SAPMF02K' '0100'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    'RF02K-KTOKK'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '/00'.

    PERFORM bdc_field USING 'RF02K-KTOKK'

    it_xk01-f2.

    ENDIF.

    IF it_xk01-f1 = 'N'.

    PERFORM bdc_dynpro USING 'SAPMF02K' '0110'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    'LFA1-PSTLZ'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '=VW'.

    PERFORM bdc_field USING 'LFA1-ANRED'

    'Mr'.

    PERFORM bdc_field USING 'LFA1-NAME1'

    it_xk01-f2.

    PERFORM bdc_field USING 'LFA1-SORTL'

    it_xk01-f3.

    PERFORM bdc_field USING 'LFA1-PSTLZ'

    it_xk01-f4.

    PERFORM bdc_field USING 'LFA1-LAND1'

    it_xk01-f5.

    PERFORM bdc_dynpro USING 'SAPMF02K' '0120'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    'LFA1-KUNNR'.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '=VW'.

    ENDIF.

    IF it_xk01-f1 = 'I'.

    v_count = v_count + 1.

    IF v_count le 5.

    CONCATENATE 'LFBK-KOINH(' v_count ')' INTO v_koinh.

    CONCATENATE 'LFBK-BANKS(' v_count ')' INTO v_banks.

    CONCATENATE 'LFBK-BANKN(' v_count ')' INTO v_bankn.

    CONCATENATE 'LFBK-BANKL(' v_count ')' INTO v_bankl.

    CONDENSE v_koinh NO-GAPS.

    CONDENSE v_banks NO-GAPS.

    CONDENSE v_bankl NO-GAPS.

    CONDENSE v_bankn NO-GAPS.

    PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    v_koinh.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '/00'.

    PERFORM bdc_field USING v_banks

    it_xk01-f2.

    PERFORM bdc_field USING v_bankl

    it_xk01-f3.

    PERFORM bdc_field USING v_bankn

    it_xk01-f4.

    PERFORM bdc_field USING v_koinh

    it_xk01-f5.

    else.

    PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    v_koinh.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '=P+'.

    v_count = 1.

    PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    v_koinh.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '/00'.

    CONCATENATE 'LFBK-KOINH(' v_count ')' INTO v_koinh.

    CONCATENATE 'LFBK-BANKS(' v_count ')' INTO v_banks.

    CONCATENATE 'LFBK-BANKN(' v_count ')' INTO v_bankn.

    CONCATENATE 'LFBK-BANKL(' v_count ')' INTO v_bankl.

    CONDENSE v_koinh NO-GAPS.

    CONDENSE v_banks NO-GAPS.

    CONDENSE v_bankl NO-GAPS.

    CONDENSE v_bankn NO-GAPS.

    PERFORM bdc_field USING v_banks

    it_xk01-f2.

    PERFORM bdc_field USING v_bankl

    it_xk01-f3.

    PERFORM bdc_field USING v_bankn

    it_xk01-f4.

    PERFORM bdc_field USING v_koinh

    it_xk01-f5.

    ENDIF.

    ENDIF.

    CLEAR it_xk01.

    ENDLOOP.

    PERFORM bdc_dynpro USING 'SAPMF02K' '0130'.

    PERFORM bdc_field USING 'BDC_CURSOR'

    v_koinh.

    PERFORM bdc_field USING 'BDC_OKCODE'

    '/00'.

    perform bdc_dynpro using 'SAPLSPO1' '0300'.

    perform bdc_field using 'BDC_OKCODE'

    '=YES'.

    wa_ctuparams-DISMODE = 'A'.

    wa_ctuparams-UPDMODE = 'S'.

    wa_ctuparams-DEFSIZE = 'X'.

    CALL TRANSACTION 'XK01' USING it_bdcdata MODE 'A'

    UPDATE 'S'.

    • options from wa_ctuparams.

    • MODE 'A'

    • UPDATE 'S'.

    &----


    *& Form upload_data

    &----


    • text

    ----


    FORM upload_data .

    DATA: lv_infile TYPE string.

    lv_infile = p_file.

    CALL FUNCTION 'GUI_UPLOAD'

    EXPORTING

    filename = lv_infile

    filetype = 'ASC'

    has_field_separator = 'X'

    TABLES

    data_tab = it_xk01.

    IF sy-subrc <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

    ENDIF.

    ENDFORM. " upload_data

    &----


    *& Form get_f4

    &----


    • text

    ----


    FORM get_f4 .

    CALL FUNCTION 'F4_FILENAME'

    EXPORTING

    program_name = syst-cprog

    dynpro_number = syst-dynnr

    • FIELD_NAME = ' '

    IMPORTING

    file_name = p_file.

    ENDFORM. " get_f4

    ----


    • Start new screen *

    ----


    FORM bdc_dynpro USING program dynpro.

    CLEAR it_bdcdata.

    it_bdcdata-program = program.

    it_bdcdata-dynpro = dynpro.

    it_bdcdata-dynbegin = 'X'.

    APPEND it_bdcdata.

    ENDFORM. "BDC_DYNPRO

    ----


    • Insert field *

    ----


    FORM bdc_field USING fnam fval.

    • IF FVAL <> NODATA.

    CLEAR it_bdcdata.

    it_bdcdata-fnam = fnam.

    it_bdcdata-fval = fval.

    APPEND it_bdcdata.

    • ENDIF.

    ENDFORM. "BDC_FIELD

    *H 0302

    *N Sahana Raj 500020 IN

    *I IN ICICI 734897597 xyzz

    *I IN SBH 768346687 fgdggf

    *I IN SBI 345687346fdgry

    *I IN SBH 763846878kyjum

    *I IN HSBC 797893778 ettrtyr

    *I IN HDFC 723678638 rtrggh

    *I IN 4444 435645646 rtyery

    *I IN 3400 763468768 wryrey

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 15, 2008 at 08:41 AM

    Hi,

    Pls refer to the sample program RSDEMO02

    Regards,

    Renjith Michael.

    http://www.sourceveda.com/

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 15, 2008 at 09:37 AM

    PROCESS BEFORE OUTPUT.

    MODULE set_status.

    MODULE get_t_ctrl_lines.

    LOOP AT i_makt WITH CONTROL t_ctrl CURSOR t_ctrl-current_line.

    • Dynamic screen modifications

    MODULE set_screen_fields.

    ENDLOOP.

    *

    PROCESS AFTER INPUT.

    LOOP AT i_makt.

    FIELD i_makt-pick MODULE check.

    FIELD i_makt-zmatnr MODULE zmatnr .

    ENDLOOP.

    MODULE user_command_9000.

    In the program, write the following code.

    PROGRAM SAPMZTC MESSAGE-ID zz.

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

    • Tables Declaration

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

    TABLES: zzz_makt.

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

    • Internal table Declaration

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

    DATA : i_makt TYPE STANDARD TABLE OF zzz_makt WITH HEADER LINE.

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

    • Table control Declaration

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

    CONTROLS: t_ctrl TYPE TABLEVIEW USING SCREEN '9000'.

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

    • Variable Declaration

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

    DATA : flg, "Flag to set the change mode

    ln TYPE i. "No. of records

    &----


    *& Module get_T_CTRL_lines OUTPUT

    &----


    • Populating data

    ----


    MODULE get_t_ctrl_lines OUTPUT.

    SELECT zmatnr zmaktx

    INTO CORRESPONDING FIELDS OF TABLE i_makt

    FROM zzz_makt.

    DESCRIBE TABLE i_makt LINES ln.

    • To make the vertical scroll bar to come on runtime

    t_ctrl-lines = ln + 100.

    ENDMODULE. " get_T_CTRL_lines OUTPUT

    &----


    *& Module USER_COMMAND_9000 INPUT

    &----


    • Triggering event according to the user command

    ----


    MODULE user_command_9000 INPUT.

    DATA :lv_fcode LIKE sy-ucomm, "Function Code

    lv_answer(1) type c. "Storing the answer

    lv_fcode = sy-ucomm.

    CASE lv_fcode.

    WHEN 'CHANGE'.

    • Setting the flag to make the table control in editable mode[excluding

    • primary key].

    flg = 'Y'.

    WHEN 'DELETE'.

    • Setting the flag to make the table control in editable mode after

    • deleting the selected line

    flg = 'Y'.

    • Confirmation of delete

    CALL FUNCTION 'POPUP_TO_CONFIRM'

    EXPORTING

    TITLEBAR = 'Confirm'

    text_question = 'Are you sure to delete from database?'

    TEXT_BUTTON_1 = 'Yes'(001)

    TEXT_BUTTON_2 = 'No'(002)

    IMPORTING

    ANSWER = lv_answer.

    if lv_answer eq '1'.

    • Updating the database table from the internal table

    UPDATE zzz_makt FROM TABLE i_makt.

    • Deleting the selected row from the internal table

    DELETE i_makt WHERE pick = 'X'.

    • Deleting the selected row from the database table

    DELETE FROM zzz_makt WHERE pick = 'X'.

    MESSAGE s005 WITH 'Deleted Successfully'.

    ENDIF.

    WHEN 'SAVE'.

    • Inserting new record or updating existing record in database table

    • from the internal table

    MODIFY zzz_makt FROM TABLE i_makt.

    MESSAGE s005 WITH 'Saved Successfully'.

    WHEN 'BACK'.

    SET SCREEN '0'.

    WHEN 'EXIT' OR 'CANCEL'.

    • Leaving the program

    LEAVE PROGRAM.

    ENDCASE.

    ENDMODULE. " USER_COMMAND_9000 INPUT

    &----


    *& Module set_screen_fields OUTPUT

    &----


    • Setting the screen fields

    ----


    MODULE set_screen_fields OUTPUT.

    LOOP AT SCREEN.

    IF flg IS INITIAL.

    screen-input = 0.

    ELSEIF ( flg EQ 'Y' ).

    IF ( ( screen-name = 'I_MAKT-ZMAKTX'

    OR screen-name = 'I_MAKT-CHECK1' )

    AND t_ctrl-current_line LE ln ) .

    • Making the screen fields as editable

    screen-input = 1.

    ELSEIF ( ( screen-name = 'I_MAKT-ZMATNR' )

    AND t_ctrl-current_line LE ln ).

    • Making the screen field as uneditable

    screen-input = 0.

    ENDIF.

    ENDIF.

    • Modifying the screen after making changes

    MODIFY SCREEN.

    ENDLOOP.

    ENDMODULE. " set_screen_fields OUTPUT

    &----


    *& Module zmatnr INPUT

    &----


    • Appending records to the internal table

    ----


    MODULE zmatnr INPUT.

    MODIFY i_makt INDEX t_ctrl-current_line.

    IF t_ctrl-current_line GT ln.

    READ TABLE i_makt WITH KEY zmatnr = i_makt-zmatnr.

    IF sy-subrc NE 0.

    • Inserting record if it does not exist in database

    APPEND i_makt.

    ELSE.

    MESSAGE i005 WITH 'Material Number' i_makt-zmatnr 'already exists'.

    ENDIF.

    ENDIF.

    ENDMODULE. " zmatnr INPUT

    &----


    *& Module set_status OUTPUT

    &----


    • Setting the GUI status

    ----


    MODULE set_status OUTPUT.

    SET PF-STATUS 'ZSTATUS'.

    SET TITLEBAR 'ZTITLE'.

    ENDMODULE. " set_status OUTPUT

    *&----


    *& Module CHECK INPUT

    *&----


    • Modify the internal table using the current line in table control

    *----


    MODULE check INPUT.

    MODIFY i_makt INDEX t_ctrl-current_line.

    ENDMODULE. " CHECK INPUT

    hope it will be useful.

    Regards,

    Priya.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 15, 2008 at 09:45 AM

    hi kb,

    refer to this for a sample code of dialog program we uses ztable to insert data using screens which contains table control.it may be helpful

    table-controls

    regards,

    sravanthi

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Feb 15, 2008 at 09:50 AM

    hi,

    These are the screen elements used to display tabular data they can be called as screen tables( like STEP LOOP).To use table control we have to create it on the screen using SCREEN PAINTER(SE51) and declare a control variable of TYPE TABLEVIEW using CONTROLS statement in the ABAP program. We have to use LOOP .. ENDLOOP statement in both PBO and PAI with or without AT int_table parameter. IF

    AT int_table parameter is not used than we have to place a MODULE call between the LOOP...ENDLOOP statement to fill the screen table rows from the ABAP program in PBO and program our own scrolling functions

    using OK_CODE field.

    Having a parallel loop(at screen table rows & int table rows) by using parameter

    AT int_table makes the ABAP code simple.

    A special structure of type CXTAB_CONTROL is used to set/get various

    attributes of table control at runtime like CURRENT_LINE ,TOP_LINE.

    ABAP declaration

    CONTROLS: tab_con TYPE TABLEVIEW USING SCREEN nnnn

    Here tab_con is the same name we used in screen for the table control.

    This ABAP statement will declare a control variable that will be used to access

    the table control , and set it's various attributes like number of fixed columns(tab_con-FIXED_COLS) ,total number of records it will display(tab_con-LINES).It is of type CXTAB_CONTROL and is a deep structure(structure containing structures).

    REFRESH CONTROL tab_con FROM SCREEN nnnn

    This ABAP statement will initialize the table control on the screen nnnn to its initial values.

    PBO processing

    In PBO we have to use the screen LOOP ...ENDLOOP statement , with or without

    intenal table.

    LOOP WITH CONTROL tab_con.

    MODULE fill_tab_con.

    ENDLOOP.

    Here a module should be called between the loop endloop statement to transfer

    data from th ABAP program to the screen table through a structure.This module

    should use the CURRENT_LINE attribute of the table control variable to get the

    current screen table record index to read the data from the internal table into a work area.

    e.g.

    READ TABLE int_table INDEX tab_con-CURRENT_LINE

    The record read will be placed in the header line of the internal table and will be available to the similarly named screen fields or if these are different it can be written explicitly. e.g.

    screen_field_name = int_table-field_name

    ...

    .

    LOOP AT int_table INTO workarea WITH CONTROL tab_con CURSOR i FROM

    n1 TO n2.

    ENDLOOP.

    Here the module call is not required to fill the screen table.The CURSOR parameter is a integer of type I indicating which absolute internal table line

    should be the first to display on the table control .FROM n1 TO n2 can be used

    to restrict the starting line and ending line number of the internal table , they are of type SY-TABIX.

    In both cases before the LOOP statement a module should be called which

    is generally for setting of status ,in which we should fill the LINES attribute

    (tab_con-LINES ) of the control with the total number of internal table records,doing this ensures correct and automatic scrolling.

    The ABAP statement DESCRIBE TABLE int_table LINES lines can be used

    to get the total lines in an int table.

    PAI Processing

    We have to use LOOP ... ENDLOOP in PAI so that data can transfer fro table control to ABAP program. If we want to write changes to the data we should

    call a module between the LOOP ... ENDLOOP. The MODULE call to process user commands (SY-UCOM) should be called after the ENDLOOP statement.

    e.g.

    PROCESS AFTER INPUT

    MODULE mod AT EXIT-COMMAND.

    LOOP AT itab_table or LOOP "depending on whether we are using AT int_table

    MODULE modify_int_table.

    ENDLOOP.

    MODULE user_command.

    In the MODULE call modify_int_table we can use

    MODIFY int_table FROM workarea INDEX tab_con-CURRENT_LINE

    or we can use

    int_table-field_name = screen_field_name.

    Hopee this helps , Do reward.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Jan 14, 2009 at 10:09 PM

    thanks

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.