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 wizard with delete/insert button at the top

former_member187651
Active Participant
0 Likes
6,122

Hello Gurus,

   I am using table control wizard in the module pool. I need two button at the top, one for delete and other for update the record. even I need to add new line to the table and save with save button.

I have made table with table control, added two button at top, one for delete and other for update. Now I stuck with very first step, that is button is not deleting the row. I have even debug the code and found one error, but don't know whats the problem. I have even check the SDN but not able to resolve the problem. I am new to Module pool. Please help. I am using se80.

I am pasting the code and showing where I am getting error while debug. Please let me know the basic steps even.

Screen Program:

PROCESS BEFORE OUTPUT.

MODULE SELECT_RECORDS.
*&SPWIZARD: PBO FLOW LOGIC FOR TABLECONTROL 'TBC_9000'
   MODULE TBC_9000_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TBC_9000_CHANGE_COL_ATTR.
   LOOP AT   IT_ZEDUCATION
        INTO WA_ZEDUCATION
        WITH CONTROL TBC_9000
        CURSOR TBC_9000-CURRENT_LINE.
     MODULE TBC_9000_GET_LINES.
*&SPWIZARD:   MODULE TBC_9000_CHANGE_FIELD_ATTR
   ENDLOOP.

  MODULE STATUS_9000.
*
PROCESS AFTER INPUT.
*&SPWIZARD: PAI FLOW LOGIC FOR TABLECONTROL 'TBC_9000'
   LOOP AT IT_ZEDUCATION.
     CHAIN.
       FIELD WA_ZEDUCATION-ZDEGREE.
       FIELD WA_ZEDUCATION-ZFROM.
       FIELD WA_ZEDUCATION-ZTO.
       FIELD WA_ZEDUCATION-ZPERCENT.
       MODULE TBC_9000_MODIFY ON CHAIN-REQUEST.
     endchain.
     FIELD WA_ZEDUCATION-MARK
       MODULE TBC_9000_MARK ON REQUEST.
   ENDLOOP.
   MODULE TBC_9000_USER_COMMAND.
*&SPWIZARD: MODULE TBC_9000_CHANGE_TC_ATTR.
*&SPWIZARD: MODULE TBC_9000_CHANGE_COL_ATTR.

  MODULE USER_COMMAND_9000.

TOP include:


TYPES : BEGIN OF ty_zeducation,
         mark type c,
         zdegree type zeducation-zdegree,
         zfrom type zeducation-zfrom,
         zto type zeducation-zto,
         zpercent type zeducation-zpercent,
         end of ty_zeducation.

  DATA : IT_ZEDUCATION TYPE TABLE OF TY_ZEDUCATION,
         WA_ZEDUCATION TYPE TY_ZEDUCATION.

*&SPWIZARD: DECLARATION OF TABLECONTROL 'TBC_9000' ITSELF
CONTROLS: TBC_9000 TYPE TABLEVIEW USING SCREEN 9000.

*&SPWIZARD: LINES OF TABLECONTROL 'TBC_9000'
DATA:     G_TBC_9000_LINES  LIKE SY-LOOPC.

DATA:     OK_CODE LIKE SY-UCOMM.

PBO Include:

*&---------------------------------------------------------------------*
*&  Include           ZCHTEST6_PBO
*&---------------------------------------------------------------------*

*&SPWIZARD: OUTPUT MODULE FOR TC 'TBC_9000'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: UPDATE LINES FOR EQUIVALENT SCROLLBAR
MODULE TBC_9000_CHANGE_TC_ATTR OUTPUT.
   DESCRIBE TABLE IT_ZEDUCATION LINES TBC_9000-lines.
ENDMODULE.

*&SPWIZARD: OUTPUT MODULE FOR TC 'TBC_9000'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: GET LINES OF TABLECONTROL
MODULE TBC_9000_GET_LINES OUTPUT.
   G_TBC_9000_LINES = SY-LOOPC.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  SELECT_RECORDS  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module SELECT_RECORDS output.

     SELECT
     ZDEGREE
     ZFROM
     ZTO
     ZPERCENT
     UP TO 10 ROWS
     FROM
     ZEDUCATION
     INTO CORRESPONDING FIELDS OF TABLE IT_ZEDUCATION.

endmodule.                 " SELECT_RECORDS  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  STATUS_9000  OUTPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module STATUS_9000 output.
   SET PF-STATUS 'SCREEN9000'.
   SET TITLEBAR 'SCREEN9000'.

endmodule.                 " STATUS_9000  OUTPUT

PAI Include:

*&---------------------------------------------------------------------*
*&  Include           ZCHTEST6_PAI
*&---------------------------------------------------------------------*

*&SPWIZARD: INPUT MODULE FOR TC 'TBC_9000'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MODIFY TABLE
MODULE TBC_9000_MODIFY INPUT.
   MODIFY IT_ZEDUCATION
     FROM WA_ZEDUCATION
     INDEX TBC_9000-CURRENT_LINE.
ENDMODULE.

*&SPWIZARD: INPUT MODUL FOR TC 'TBC_9000'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: MARK TABLE
MODULE TBC_9000_MARK INPUT.
   DATA: g_TBC_9000_wa2 like line of IT_ZEDUCATION.
     if TBC_9000-line_sel_mode = 2
     and WA_ZEDUCATION-MARK = 'X'.
      loop at IT_ZEDUCATION into g_TBC_9000_wa2
        where MARK = 'X'.
        g_TBC_9000_wa2-MARK = ''.
        modify IT_ZEDUCATION
          from g_TBC_9000_wa2
          transporting MARK.
      endloop.
   endif.
   MODIFY IT_ZEDUCATION
     FROM WA_ZEDUCATION
     INDEX TBC_9000-CURRENT_LINE
     TRANSPORTING MARK.
ENDMODULE.

*&SPWIZARD: INPUT MODULE FOR TC 'TBC_9000'. DO NOT CHANGE THIS LINE!
*&SPWIZARD: PROCESS USER COMMAND
MODULE TBC_9000_USER_COMMAND INPUT.
   OK_CODE = SY-UCOMM.
   PERFORM USER_OK_TC USING    'TBC_9000'
                               'IT_ZEDUCATION'
                               'MARK'
                      CHANGING OK_CODE.
   SY-UCOMM = OK_CODE.
ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9000  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
module USER_COMMAND_9000 input.
     SY-UCOMM = OK_CODE.
   CLEAR OK_CODE.

   CASE SY-UCOMM.

   WHEN 'SAVE'.
*   PERFORM data_save.

   WHEN 'BACK'.
   LEAVE TO SCREEN 0.

   WHEN 'EXIT'.
   LEAVE PROGRAM.

   ENDCASE.

endmodule. 

SUB Include:


*&---------------------------------------------------------------------*
*&  Include           ZCHTEST6_SUB
*&---------------------------------------------------------------------*

*----------------------------------------------------------------------*
*   INCLUDE TABLECONTROL_FORMS                                         *
*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  USER_OK_TC                                               *
*&---------------------------------------------------------------------*
  FORM USER_OK_TC USING    P_TC_NAME TYPE DYNFNAM
                           P_TABLE_NAME
                           P_MARK_NAME
                  CHANGING P_OK      LIKE SY-UCOMM.

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
    DATA: L_OK              TYPE SY-UCOMM,
          L_OFFSET          TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

*&SPWIZARD: Table control specific operations                          *
*&SPWIZARD: evaluate TC name and operations                            *
    SEARCH P_OK FOR P_TC_NAME.                            
    IF SY-SUBRC <> 0.       
>>>>>>>>>>>>>>>>>While debugging sy-subrc = 4 and control gets out of it, EXIT.
      EXIT.
    ENDIF.
    L_OFFSET = STRLEN( P_TC_NAME ) + 1.
    L_OK = P_OK+L_OFFSET.
*&SPWIZARD: execute general and TC specific operations                 *
    CASE L_OK.
      WHEN 'INSR'.                      "insert row
        PERFORM FCODE_INSERT_ROW USING    P_TC_NAME
                                          P_TABLE_NAME.
        CLEAR P_OK.

      WHEN 'DELE'.                      "delete row
        PERFORM FCODE_DELETE_ROW USING    P_TC_NAME
                                          P_TABLE_NAME
                                          P_MARK_NAME.
        CLEAR P_OK.

      WHEN 'P--' OR                     "top of list
           'P-'  OR                     "previous page
           'P+'  OR                     "next page
           'P++'.                       "bottom of list
        PERFORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME
                                              L_OK.
        CLEAR P_OK.
*     WHEN 'L--'.                       "total left
*       PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME.
*
*     WHEN 'L-'.                        "column left
*       PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME.
*
*     WHEN 'R+'.                        "column right
*       PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME.
*
*     WHEN 'R++'.                       "total right
*       PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME.
*
      WHEN 'MARK'.                      "mark all filled lines
        PERFORM FCODE_TC_MARK_LINES USING P_TC_NAME
                                          P_TABLE_NAME
                                          P_MARK_NAME   .
        CLEAR P_OK.

      WHEN 'DMRK'.                      "demark all filled lines
        PERFORM FCODE_TC_DEMARK_LINES USING P_TC_NAME
                                            P_TABLE_NAME
                                            P_MARK_NAME .
        CLEAR P_OK.

*     WHEN 'SASCEND'   OR
*          'SDESCEND'.                  "sort column
*       PERFORM FCODE_SORT_TC USING P_TC_NAME
*                                   l_ok.

    ENDCASE.

  ENDFORM.                              " USER_OK_TC

*&---------------------------------------------------------------------*
*&      Form  FCODE_INSERT_ROW                                         *
*&---------------------------------------------------------------------*
  FORM fcode_insert_row
                USING    P_TC_NAME           TYPE DYNFNAM
                         P_TABLE_NAME             .

*&SPWIZARD: 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.
*&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: get looplines of TableControl                              *
    CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_LINES_NAME.
    ASSIGN (L_LINES_NAME) TO <LINES>.

*&SPWIZARD: 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.
*&SPWIZARD: set new cursor line                                        *
    L_LINE = L_SELLINE - <TC>-TOP_LINE + 1.

*&SPWIZARD: insert initial line                                        *
    INSERT INITIAL LINE INTO <TABLE> INDEX L_SELLINE.
    <TC>-LINES = <TC>-LINES + 1.
*&SPWIZARD: set cursor                                                 *
    SET CURSOR LINE L_LINE.

  ENDFORM.                              " FCODE_INSERT_ROW

*&---------------------------------------------------------------------*
*&      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.
        REFRESH CONTROL 'TBC_9000' FROM SCREEN '9000'.
      ENDIF.
    ENDLOOP.

  ENDFORM.                              " FCODE_DELETE_ROW

*&---------------------------------------------------------------------*
*&      Form  COMPUTE_SCROLLING_IN_TC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*      -->P_OK       ok code
*----------------------------------------------------------------------*
  FORM COMPUTE_SCROLLING_IN_TC USING    P_TC_NAME
                                        P_OK.
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
    DATA L_TC_NEW_TOP_LINE     TYPE I.
    DATA L_TC_NAME             LIKE FELD-NAME.
    DATA L_TC_LINES_NAME       LIKE FELD-NAME.
    DATA L_TC_FIELD_NAME       LIKE FELD-NAME.

    FIELD-SYMBOLS <TC>         TYPE cxtab_control.
    FIELD-SYMBOLS <LINES>      TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

    ASSIGN (P_TC_NAME) TO <TC>.
*&SPWIZARD: get looplines of TableControl                              *
    CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_TC_LINES_NAME.
    ASSIGN (L_TC_LINES_NAME) TO <LINES>.


*&SPWIZARD: is no line filled?                                         *
    IF <TC>-LINES = 0.
*&SPWIZARD: yes, ...                                                   *
      L_TC_NEW_TOP_LINE = 1.
    ELSE.
*&SPWIZARD: no, ...                                                    *
      CALL FUNCTION 'SCROLLING_IN_TABLE'
           EXPORTING
                ENTRY_ACT             = <TC>-TOP_LINE
                ENTRY_FROM            = 1
                ENTRY_TO              = <TC>-LINES
                LAST_PAGE_FULL        = 'X'
                LOOPS                 = <LINES>
                OK_CODE               = P_OK
                OVERLAPPING           = 'X'
           IMPORTING
                ENTRY_NEW             = L_TC_NEW_TOP_LINE
           EXCEPTIONS
*              NO_ENTRY_OR_PAGE_ACT  = 01
*              NO_ENTRY_TO           = 02
*              NO_OK_CODE_OR_PAGE_GO = 03
                OTHERS                = 0.
    ENDIF.

*&SPWIZARD: get actual tc and column                                   *
    GET CURSOR FIELD L_TC_FIELD_NAME
               AREA  L_TC_NAME.

    IF SYST-SUBRC = 0.
      IF L_TC_NAME = P_TC_NAME.
*&SPWIZARD: et actual column                                           *
        SET CURSOR FIELD L_TC_FIELD_NAME LINE 1.
      ENDIF.
    ENDIF.

*&SPWIZARD: set the new top line                                       *
    <TC>-TOP_LINE = L_TC_NEW_TOP_LINE.


  ENDFORM.                              " COMPUTE_SCROLLING_IN_TC

*&---------------------------------------------------------------------*
*&      Form  FCODE_TC_MARK_LINES
*&---------------------------------------------------------------------*
*       marks all TableControl lines
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*----------------------------------------------------------------------*
FORM FCODE_TC_MARK_LINES USING P_TC_NAME
                                P_TABLE_NAME
                                P_MARK_NAME.
*&SPWIZARD: EGIN 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: mark all filled 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>.

      <MARK_FIELD> = 'X'.
   ENDLOOP.
ENDFORM.                                          "fcode_tc_mark_lines

*&---------------------------------------------------------------------*
*&      Form  FCODE_TC_DEMARK_LINES
*&---------------------------------------------------------------------*
*       demarks all TableControl lines
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*----------------------------------------------------------------------*
FORM FCODE_TC_DEMARK_LINES USING P_TC_NAME
                                  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: demark all filled 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>.

      <MARK_FIELD> = SPACE.
   ENDLOOP.
ENDFORM.                                          "fcode_tc_mark_lines




1 ACCEPTED SOLUTION
Read only

former_member184675
Active Participant
0 Likes
3,693

Hi,

The code is a little bit hard to follow but I believe that you don't see the row deleted because you select the data in the PBO module.

Normally every PAI module is followed by the PBO module. Even if you delete the table row in the PAI module, then the program enters the PBO module and runs Module SELECT_RECORDS Output thus refreshing your table to it's initial state (After the select).

Try entering a condition at the beginning of the SELECT_RECORDS Module like :

               CHECK IT_ZEDUCATION IS INITIAL.

The code to delete a line in a TC should be like

Screen flow

PBO

module select.             

...

PAI

...

module user_command

Main Program

module select.

check ITAB is initial.

* i would personally put this outside the PBO and before CALL SCREEN statement in the START-OF-SELECTION event.

select * from DBTAB into corresponding fields of table ITAB.

if sy-subrc ne 0.

* user message

endif.

endmodule

module user_command.

case sy-ucomm.

when 'DELETE'.

delete itab where mark eq 'X'.

if sy-subrc ne 0 .

* user message (or do something )

endif.

endcase.

endmodule.

As to the Search statement i don't really see it's use there. Even more SEARCH is an obsolete syntax. Unless you have a valid use for that statement I suggest you comment it.

Although TC Wizard can help you, it can also make your code difficult to read or even have statements that you don't actually need. I recommend you write the entire Screen Flow yourself so the code and the program is more manageable.

Regards,

Andrei


11 REPLIES 11
Read only

Former Member
0 Likes
3,693

Dear mishra ji,

need to check below steps. might be help.

1) put a break point in PAI.

2) select any row of the table and press delete button.

3) on break point. check the internal table.

3) check the line selection field  ( it should be 'X').

4) if you can not see 'X' at the selection line item in internal table.

refer your table row selection field weather it is correct or not.

if problem still persist feel free to ask.

- Avirat Patel

Read only

0 Likes
3,693

Dear Avirat,

As you said I have put breakpoint in PAI and seen that it is taking mark 'X' at the internal table for the selected row. I have seen through debug that it is not getting value of "L_ok" . Below is the code.

Please help.

*&---------------------------------------------------------------------*
*&  Include           ZCHTEST6_SUB
*&---------------------------------------------------------------------*

*----------------------------------------------------------------------*
*   INCLUDE TABLECONTROL_FORMS                                         *
*----------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*&      Form  USER_OK_TC                                               *
*&---------------------------------------------------------------------*
  FORM USER_OK_TC USING    P_TC_NAME TYPE DYNFNAM
                           P_TABLE_NAME
                           P_MARK_NAME
                  CHANGING P_OK      LIKE SY-UCOMM.

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
    DATA: L_OK              TYPE SY-UCOMM,
          L_OFFSET          TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

*&SPWIZARD: Table control specific operations                          *
*&SPWIZARD: evaluate TC name and operations                            *
    SEARCH P_OK FOR P_TC_NAME.
   IF SY-SUBRC <> 0.   >>>>>>>getting value 4
      EXIT.
    ENDIF.
   L_OFFSET = STRLEN( P_TC_NAME ) + 1. >>>>>> getting value 9
   L_OK = P_OK+L_OFFSET. >>>>>>>>> L_OK = blank
*&SPWIZARD: execute general and TC specific operations                 *
    CASE L_OK.
      WHEN 'INSR'.                      "insert row
        PERFORM FCODE_INSERT_ROW USING    P_TC_NAME
                                          P_TABLE_NAME.
        CLEAR P_OK.

      WHEN 'DELE'.                      "delete row
        PERFORM FCODE_DELETE_ROW USING    P_TC_NAME
                                          P_TABLE_NAME
                                          P_MARK_NAME.
        CLEAR P_OK.

      WHEN 'P--' OR                     "top of list
           'P-'  OR                     "previous page
           'P+'  OR                     "next page
           'P++'.                       "bottom of list
        PERFORM COMPUTE_SCROLLING_IN_TC USING P_TC_NAME
                                              L_OK.
        CLEAR P_OK.
*     WHEN 'L--'.                       "total left
*       PERFORM FCODE_TOTAL_LEFT USING P_TC_NAME.
*
*     WHEN 'L-'.                        "column left
*       PERFORM FCODE_COLUMN_LEFT USING P_TC_NAME.
*
*     WHEN 'R+'.                        "column right
*       PERFORM FCODE_COLUMN_RIGHT USING P_TC_NAME.
*
*     WHEN 'R++'.                       "total right
*       PERFORM FCODE_TOTAL_RIGHT USING P_TC_NAME.
*
      WHEN 'MARK'.                      "mark all filled lines
        PERFORM FCODE_TC_MARK_LINES USING P_TC_NAME
                                          P_TABLE_NAME
                                          P_MARK_NAME   .
        CLEAR P_OK.

      WHEN 'DMRK'.                      "demark all filled lines
        PERFORM FCODE_TC_DEMARK_LINES USING P_TC_NAME
                                            P_TABLE_NAME
                                            P_MARK_NAME .
        CLEAR P_OK.

*     WHEN 'SASCEND'   OR
*          'SDESCEND'.                  "sort column
*       PERFORM FCODE_SORT_TC USING P_TC_NAME
*                                   l_ok.

    ENDCASE.

  ENDFORM.                              " USER_OK_TC

*&---------------------------------------------------------------------*
*&      Form  FCODE_INSERT_ROW                                         *
*&---------------------------------------------------------------------*
  FORM fcode_insert_row
                USING    P_TC_NAME           TYPE DYNFNAM
                         P_TABLE_NAME             .

*&SPWIZARD: 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.
*&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: get looplines of TableControl                              *
    CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_LINES_NAME.
    ASSIGN (L_LINES_NAME) TO <LINES>.

*&SPWIZARD: 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.
*&SPWIZARD: set new cursor line                                        *
    L_LINE = L_SELLINE - <TC>-TOP_LINE + 1.

*&SPWIZARD: insert initial line                                        *
    INSERT INITIAL LINE INTO <TABLE> INDEX L_SELLINE.
    <TC>-LINES = <TC>-LINES + 1.
*&SPWIZARD: set cursor                                                 *
    SET CURSOR LINE L_LINE.

  ENDFORM.                              " FCODE_INSERT_ROW

*&---------------------------------------------------------------------*
*&      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.
        REFRESH CONTROL 'TBC_9000' FROM SCREEN '9000'.
      ENDIF.
    ENDLOOP.

  ENDFORM.                              " FCODE_DELETE_ROW

*&---------------------------------------------------------------------*
*&      Form  COMPUTE_SCROLLING_IN_TC
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*      -->P_OK       ok code
*----------------------------------------------------------------------*
  FORM COMPUTE_SCROLLING_IN_TC USING    P_TC_NAME
                                        P_OK.
*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
    DATA L_TC_NEW_TOP_LINE     TYPE I.
    DATA L_TC_NAME             LIKE FELD-NAME.
    DATA L_TC_LINES_NAME       LIKE FELD-NAME.
    DATA L_TC_FIELD_NAME       LIKE FELD-NAME.

    FIELD-SYMBOLS <TC>         TYPE cxtab_control.
    FIELD-SYMBOLS <LINES>      TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

    ASSIGN (P_TC_NAME) TO <TC>.
*&SPWIZARD: get looplines of TableControl                              *
    CONCATENATE 'G_' P_TC_NAME '_LINES' INTO L_TC_LINES_NAME.
    ASSIGN (L_TC_LINES_NAME) TO <LINES>.


*&SPWIZARD: is no line filled?                                         *
    IF <TC>-LINES = 0.
*&SPWIZARD: yes, ...                                                   *
      L_TC_NEW_TOP_LINE = 1.
    ELSE.
*&SPWIZARD: no, ...                                                    *
      CALL FUNCTION 'SCROLLING_IN_TABLE'
           EXPORTING
                ENTRY_ACT             = <TC>-TOP_LINE
                ENTRY_FROM            = 1
                ENTRY_TO              = <TC>-LINES
                LAST_PAGE_FULL        = 'X'
                LOOPS                 = <LINES>
                OK_CODE               = P_OK
                OVERLAPPING           = 'X'
           IMPORTING
                ENTRY_NEW             = L_TC_NEW_TOP_LINE
           EXCEPTIONS
*              NO_ENTRY_OR_PAGE_ACT  = 01
*              NO_ENTRY_TO           = 02
*              NO_OK_CODE_OR_PAGE_GO = 03
                OTHERS                = 0.
    ENDIF.

*&SPWIZARD: get actual tc and column                                   *
    GET CURSOR FIELD L_TC_FIELD_NAME
               AREA  L_TC_NAME.

    IF SYST-SUBRC = 0.
      IF L_TC_NAME = P_TC_NAME.
*&SPWIZARD: et actual column                                           *
        SET CURSOR FIELD L_TC_FIELD_NAME LINE 1.
      ENDIF.
    ENDIF.

*&SPWIZARD: set the new top line                                       *
    <TC>-TOP_LINE = L_TC_NEW_TOP_LINE.


  ENDFORM.                              " COMPUTE_SCROLLING_IN_TC

*&---------------------------------------------------------------------*
*&      Form  FCODE_TC_MARK_LINES
*&---------------------------------------------------------------------*
*       marks all TableControl lines
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*----------------------------------------------------------------------*
FORM FCODE_TC_MARK_LINES USING P_TC_NAME
                                P_TABLE_NAME
                                P_MARK_NAME.
*&SPWIZARD: EGIN 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: mark all filled 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>.

      <MARK_FIELD> = 'X'.
   ENDLOOP.
ENDFORM.                                          "fcode_tc_mark_lines

*&---------------------------------------------------------------------*
*&      Form  FCODE_TC_DEMARK_LINES
*&---------------------------------------------------------------------*
*       demarks all TableControl lines
*----------------------------------------------------------------------*
*      -->P_TC_NAME  name of tablecontrol
*----------------------------------------------------------------------*
FORM FCODE_TC_DEMARK_LINES USING P_TC_NAME
                                  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: demark all filled 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>.

      <MARK_FIELD> = SPACE.
   ENDLOOP.
ENDFORM.                                          "fcode_tc_mark_lines

Read only

0 Likes
3,693

Dear Mishra ji,

as you are getting 'X' mark inside table and still not able to delete line item

then

why don't you put

loop at itab where selectfield eq  'X'.

     delete itab.

endloop.

manual query (in same button - function code).

you can delete record from this solution.

try it.

avirat

Read only

former_member184675
Active Participant
0 Likes
3,694

Hi,

The code is a little bit hard to follow but I believe that you don't see the row deleted because you select the data in the PBO module.

Normally every PAI module is followed by the PBO module. Even if you delete the table row in the PAI module, then the program enters the PBO module and runs Module SELECT_RECORDS Output thus refreshing your table to it's initial state (After the select).

Try entering a condition at the beginning of the SELECT_RECORDS Module like :

               CHECK IT_ZEDUCATION IS INITIAL.

The code to delete a line in a TC should be like

Screen flow

PBO

module select.             

...

PAI

...

module user_command

Main Program

module select.

check ITAB is initial.

* i would personally put this outside the PBO and before CALL SCREEN statement in the START-OF-SELECTION event.

select * from DBTAB into corresponding fields of table ITAB.

if sy-subrc ne 0.

* user message

endif.

endmodule

module user_command.

case sy-ucomm.

when 'DELETE'.

delete itab where mark eq 'X'.

if sy-subrc ne 0 .

* user message (or do something )

endif.

endcase.

endmodule.

As to the Search statement i don't really see it's use there. Even more SEARCH is an obsolete syntax. Unless you have a valid use for that statement I suggest you comment it.

Although TC Wizard can help you, it can also make your code difficult to read or even have statements that you don't actually need. I recommend you write the entire Screen Flow yourself so the code and the program is more manageable.

Regards,

Andrei


Read only

0 Likes
3,693

Hi Andrei,

I have gone with wizard as it gives more flexibility with table control, but of-course, code is hard to understand. For that reason I would like to go with my code. Can you please give me sample code for my scenario, so that I can proceed with that.

Thanks for your suggestion. 

Read only

0 Likes
3,693

Hi Mishra,

Check program :

demo_dynpro_tabcont_loop_at

Now,

I really don't understand the use of the code, because it does nothing but circle around a set of variables with the same value (or the same expected value) and the Form you're calling is only called from one place.

  OK_CODE = SY-UCOMM.

   PERFORM USER_OK_TC USING    'TBC_9000'

                               'IT_ZEDUCATION'

                               'MARK'

                      CHANGING OK_CODE.

FORM USER_OK_TC USING    P_TC_NAME TYPE DYNFNAM
                           P_TABLE_NAME
                           P_MARK_NAME
                  CHANGING P_OK      LIKE SY-UCOMM.

*&SPWIZARD: BEGIN OF LOCAL DATA----------------------------------------*
    DATA: L_OK              TYPE SY-UCOMM,
          L_OFFSET          TYPE I.
*&SPWIZARD: END OF LOCAL DATA------------------------------------------*

*&SPWIZARD: Table control specific operations                          *
*&SPWIZARD: evaluate TC name and operations                            *
    SEARCH P_OK FOR P_TC_NAME.                            
    IF SY-SUBRC <> 0.       

      EXIT.
    ENDIF.
    L_OFFSET = STRLEN( P_TC_NAME ) + 1.
    L_OK = P_OK+L_OFFSET.

Because:

P_OK = OK_CODE = SY-UCOMM = 'DELE'.

P_TC_NAME = 'TBC_9000'.

SEARCH P_OK for P_TC_NAME will return 4 always.

P_OK+9  = blank because DELE is only 4 chars long. You are setting an offest far away from the variable length.

I assume that what you want to achieve by the generated code is to have L_OK = 'DELE'.

But you already have that value in both sy-ucomm and p_ok

So simplify everything:

either use

CASE P_OK.

WHEN 'DELE'

delete itab where selectfield eq 'X'.

ENDCASE.

or

CASE SY-UCOMM.

WHEN 'DELE'.

delete itab where selectfield eq 'X'.

ENDCASE.

-

Andrei

Read only

0 Likes
3,693

Hi Andrei,

I have made some changes to the code, as per your suggestions given.

*&SPWIZARD: Table control specific operations                          *
*&SPWIZARD: evaluate TC name and operations                            *
********   SEARCH P_OK FOR P_TC_NAME.
********   IF SY-SUBRC <> 0.
********     EXIT.
********   ENDIF.
********   L_OFFSET = STRLEN( P_TC_NAME ) + 1.
********   L_OK = P_OK+L_OFFSET.

     L_OK = P_OK.

I have commented the line where the code was no executing. and put directly L_OK = P_OK

Now code is getting executed. Records are getting deleted from internal table i.e IT_ZEDUCATION

but not deleted from ztable i.t ZEDUCATION.

Please let me know why it is doing so. What I need to do  here.

Thanks


Read only

0 Likes
3,693

well that's because you didn't tell the program to delete it from the database.

  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 ZEDUCATION FROM <WA>.  

IF SY-SUBRC <> 0.

*USER MESSAGE.

ELSE.

     DELETE <TABLE> INDEX SYST-TABIX.

ENDIF.


      ENDIF.

ENDLOOP.  


Read only

0 Likes
3,693

Hello Andrei, Thanks for your quick reply.

I have used following code in the program but still records are nor getting deleted from zeducation.

Please let me know where I am wrong.

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.

      IF <MARK_FIELD> = 'X'.
             DELETE ZEDUCATION FROM <WA>.
  
         IF SY-SUBRC <> 0.

             MESSAGE I001(ZCH).

         ELSE.

           DELETE <TABLE> INDEX SYST-TABIX.

         ENDIF.


*       IF SY-SUBRC = 0.
*         <TC>-LINES = <TC>-LINES - 1.
*       ENDIF.
        REFRESH CONTROL 'TBC_9000' FROM SCREEN '9000'.
      ENDIF.
    ENDLOOP.

Read only

0 Likes
3,693

Thanks Andrei Problem solved.

Your suggestions really helped me. I will come to you if I stuck with some point with it, as I am working on it.

Read only

0 Likes
3,693

Dear mishra ji,

all the codes are correct by own logic..

you are requested have a look at my previous post and need little thinking.

my given code sample is fully transparent to understand even beginner can understand...

rest is yours....

thank you.

avirat