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: 

delete row issue in table control

former_member670450
Participant
0 Kudos

Im doing dialog programming with 2 screens created. First screen contains zebeln field with delete button, second screen contains fields of zekko_03 and table control of zekpo_03. Two issues i encountered:

First, when doing select statement for header it prompt error saying data type not compatible.

Secondly, there are issues with table control delete (delete button function code 'DEL'), i looked up several online not working for my case, including the following logic.

The tables i used are as follows

error1.png

tbl-po-header.png

tbl-po-line.png

*&---------------------------------------------------------------------*
*& Include MZDLGPROG_03_REPORTTOP                   - Module Pool      SAPMZDLGPROG_03_REPORT
*&---------------------------------------------------------------------*
PROGRAM SAPMZDLGPROG_03_REPORT.

DATA : OK_CODE   TYPE SY-UCOMM,
       GT_ZEKKO  TYPE TABLE OF ZEKKO_03,
       GWA_ZEKKO TYPE ZEKKO_03,
       GT_ZEKPO  TYPE TABLE OF ZEKPO_03,
       GWA_ZEKPO TYPE ZEKPO_03,
       GV_EBELN  TYPE ZEBELN_EL,
       MARK TYPE CE_MARK,
       gv_flag TYPE char1.


CONTROLS: TC_ZEKPO TYPE TABLEVIEW USING SCREEN 9002.

DATA: f1 TYPE char1.
*&---------------------------------------------------------------------*
*& Include          MZDLGPROG_03_REPORTO01
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_9001 OUTPUT.
 SET PF-STATUS 'ZSTATUS'.
 SET TITLEBAR 'ZTITLE'.
ENDMODULE.

*&---------------------------------------------------------------------*
*& Module STATUS_9002 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_9002 OUTPUT.
 SET PF-STATUS 'ZSTATUS'.
 SET TITLEBAR 'ZTITLE1'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module FETCH_DATA OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE FETCH_DATA OUTPUT.


if f1 <> 1.

SELECT ebeln lifnr ekorg ekgrp bukrs waers zterm zdesc FROM zekko_03 INTO TABLE gt_zekko. <<<< issue with this select statement 

SELECT SINGLE ebeln lifnr ekorg ekgrp bukrs waers zterm zdesc FROM zekko_03
  INTO CORRESPONDING FIELDS OF gwa_zekko
  WHERE ebeln = gwa_zekko-ebeln.
READ TABLE gt_zekko INTO gwa_zekko INDEX sy-tabix.
SELECT EBELP MATNR werks LGORT menge meins
  INTO CORRESPONDING FIELDS OF TABLE gt_zekpo FROM zekpo_03
   WHERE ebeln = gwa_zekko-ebeln.


if f1 = 1.

  IF sy-tabix is NOT INITIAL.
      DELETE gt_zekko INDEX sy-tabix.
      delete gt_zekpo INDEX sy-tabix.
  ENDIF.
endif.
endif.


ENDMODULE.
*&---------------------------------------------------------------------*
*& Include          MZDLGPROG_03_REPORTI01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9002  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9002 INPUT.
  CASE OK_CODE.
    WHEN 'BACK'.
      SET SCREEN 0.
      LEAVE TO SCREEN 0.

  ENDCASE.

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  MODIFY_IT_ZEKPO  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE MODIFY_GT_ZEKPO INPUT.
  MODIFY gt_zekpo FROM gwa_zekpo
  INDEX TC_ZEKPO-CURRENT_LINE.

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9001 INPUT.

  CASE OK_CODE.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      LEAVE PROGRAM.
    WHEN 'DELETE'.
      IF GWA_ZEKKO-EBELN IS INITIAL .
        MESSAGE 'Please enter document number' TYPE 'E'.
      ELSE.
        CALL SCREEN 9002.
      ENDIF.

    WHEN 'DEL'.
    GET CURSOR LINE sy-tabix.
    f1 = 1.


  ENDCASE.

ENDMODULE.
PROCESS BEFORE OUTPUT.
  MODULE STATUS_9002.
    MODULE fetch_data.
  LOOP AT GT_ZEKPO INTO GWA_ZEKPO WITH CONTROL TC_ZEKPO CURSOR
TC_ZEKPO-CURRENT_LINE.

  ENDLOOP.

PROCESS AFTER INPUT.
loop at gt_zekpo.
  MODULE modify_gt_zekpo.
endloop.
  MODULE USER_COMMAND_9002.
9 REPLIES 9

mateuszadamus
Active Contributor
0 Kudos

Hi arnold92

First issue, the SELECT issue. Your code is as follows:

DATA:
  gt_zekko TYPE TABLE OF zekko_03.

SELECT ebeln lifnr ekorg ekgrp bukrs waers zterm zdesc FROM zekko_03 INTO TABLE gt_zekko. <<<< issue with this select statement 

However, the fields in the ZEKKO_03 are as follows:

EBELN, EKGRP, EKORG, BUKRS, LIFNR, WAERS, ZTERM, ZDESC

Now, when you do a SELECT INTO TABLE statement, system tries to put the fields from the SELECT into table in the order that they are retrieved from the database. In your case system tries to assign fields as follows:

gt_zekko-ebeln = zekko_03-ebeln.
gt_zekko-ekgrp = zekko_03-lifnr.
gt_zekko-ekorg = zekko_03-ekorg.
etc

You see the issue, right? The value of LIFNR field from database is being assigned to the EKRGP field of the GT_ZEKKO table. The fields have a different type hence the error.

Solution to this is either change the sequence of the fields in your SELECT statement to match the fields sequence of the GT_ZEKKO internal table or replace the INTO TABLE with INTO CORRESPONDING FIELDS OF TABLE option.

Second issue, the record not being deleted.

This is your code for the DEL user command.

    WHEN 'DEL'.
      GET CURSOR LINE sy-tabix.
      f1 = 1.
  ENDCASE.

First, I would retrieve the index into a variable that you've created, not to one used by system, because these can be overwritten in after some operations. So something like this:

GET CURSOR LINE gv_tabix.

Second, your code for handling the delete, when F1 = 1, is never executed because it is contained in another IF clause.

if f1 <> 1. 
  SELECT ebeln lifnr ekorg ekgrp bukrs waers zterm zdesc FROM zekko_03 INTO TABLE gt_zekko. <<<< issue with this select statement 

  SELECT SINGLE ebeln lifnr ekorg ekgrp bukrs waers zterm zdesc FROM zekko_03
    INTO CORRESPONDING FIELDS OF gwa_zekko
    WHERE ebeln = gwa_zekko-ebeln.
  READ TABLE gt_zekko INTO gwa_zekko INDEX sy-tabix.
  SELECT EBELP MATNR werks LGORT menge meins
    INTO CORRESPONDING FIELDS OF TABLE gt_zekpo FROM zekpo_03
    WHERE ebeln = gwa_zekko-ebeln.

  if f1 = 1. " <-- at this point condition is always false
    IF sy-tabix is NOT INITIAL.
      DELETE gt_zekko INDEX sy-tabix.
      delete gt_zekpo INDEX sy-tabix.
    ENDIF.
  endif.
endif.

Possible fix would be:

if f1 <> 1. 
  SELECTs...
ELSE. " <-- ELSE instead of IF = 1
  IF gv_tabix is NOT INITIAL.
    DELETE gt_zekko INDEX gv_tabix.
    delete gt_zekpo INDEX gv_tabix.
  endif.
endif.

I hope this helps.

regards,

Mateusz

0 Kudos

Hi Matheusz, thanks for your reply. Ive fixed the first issue

When i tried to delete on the second screen, the delete not reflected once clicked the delete button (function code (DEL))

When i debugged, the gv_tabix shown as 0 (attached picture)

I did it in the following way

*&---------------------------------------------------------------------*
*& Include MZDLGPROG_03_REPORTTOP                   - Module Pool      SAPMZDLGPROG_03_REPORT
*&---------------------------------------------------------------------*

DATA : OK_CODE   TYPE SY-UCOMM,
       GT_ZEKKO  TYPE TABLE OF ZEKKO_03,
       GWA_ZEKKO TYPE ZEKKO_03,
       GT_ZEKPO  TYPE TABLE OF ZEKPO_03,
       GWA_ZEKPO TYPE zekpo_03,
       GV_EBELN  TYPE ZEBELN_EL,
*       MARK TYPE CE_MARK,
       gv_flag TYPE char1.


DATA: f1 TYPE char1,
      gv_tabix TYPE sy-tabix.<br>
*&---------------------------------------------------------------------*
*& Include          MZDLGPROG_03_REPORTO01
*&---------------------------------------------------------------------*

*&---------------------------------------------------------------------*
*& Module STATUS_9001 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_9001 OUTPUT.
 SET PF-STATUS 'ZSTATUS'.
 SET TITLEBAR 'ZTITLE'.
ENDMODULE.

*&---------------------------------------------------------------------*
*& Module STATUS_9002 OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE STATUS_9002 OUTPUT.
 SET PF-STATUS 'ZSTATUS'.
 SET TITLEBAR 'ZTITLE1'.
ENDMODULE.
*&---------------------------------------------------------------------*
*& Module FETCH_DATA OUTPUT
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*
MODULE FETCH_DATA OUTPUT.
if f1 <> 1.

SELECT ebeln lifnr ekorg ekgrp bukrs waers zterm zdesc FROM zekko_03
  INTO CORRESPONDING FIELDS OF TABLE gt_zekko
  WHERE ebeln = gwa_zekko-ebeln.

SELECT SINGLE ebeln lifnr ekorg ekgrp bukrs waers zterm zdesc FROM zekko_03
  INTO CORRESPONDING FIELDS OF gwa_zekko
  WHERE ebeln = gwa_zekko-ebeln.
READ TABLE gt_zekko INTO gwa_zekko INDEX sy-tabix.
SELECT EBELP MATNR werks LGORT menge meins
  INTO CORRESPONDING FIELDS OF TABLE gt_zekpo FROM zekpo_03
   WHERE ebeln = gwa_zekko-ebeln.

ELSE.

  IF gv_tabix is NOT INITIAL.
      DELETE gt_zekko INDEX gv_tabix.
      delete gt_zekpo INDEX gv_tabix.
  ENDIF.
endif.


ENDMODULE.<br>
*&---------------------------------------------------------------------*
*& Include          MZDLGPROG_03_REPORTI01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9002  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9002 INPUT.
  CASE OK_CODE.
    WHEN 'BACK'.
      SET SCREEN 0.
      LEAVE TO SCREEN 0.

  ENDCASE.

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  MODIFY_IT_ZEKPO  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE MODIFY_GT_ZEKPO INPUT.
  MODIFY gt_zekpo FROM gwa_zekpo
  INDEX TC_ZEKPO-CURRENT_LINE.

ENDMODULE.
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9001 INPUT.



  CASE OK_CODE.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      LEAVE PROGRAM.
    WHEN 'DELETE'.
      IF GWA_ZEKKO-EBELN IS INITIAL .
        MESSAGE 'Please enter document number' TYPE 'E'.
      ELSE.
        CALL SCREEN 9002.
      ENDIF.

    WHEN 'DEL'.
    GET CURSOR LINE gv_tabix.
    f1 = 1.
    call SCREEN 9002.


  ENDCASE.

ENDMODULE.

0 Kudos

Here is my first and second screen

0 Kudos

Hi arnold92

Are you sure your code was triggered by the 'DEL' user command and not by the 'DELETE'?

The 'DELETE' would also open the 9002 screen, but does not set the GV_TABIX value.

Regards,
Mateusz

0 Kudos

The 'DEL' button is to delete record (trigger by this), whereas 'DELETE ' is a navigation to second screen, sorry for the confusion.

I did it in the following way

*&---------------------------------------------------------------------*
*& Include          MZDLGPROG_03_REPORTI01
*&---------------------------------------------------------------------*
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9002  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9002 INPUT.
  CASE OK_CODE.
    WHEN 'BACK'.
      SET SCREEN 0.
      LEAVE TO SCREEN 0.

       WHEN 'DEL'.
    GET CURSOR LINE gv_tabix.
    f1 = 1.
    gv_tabix = gwa_zekko-ebeln.       <<< gwa_zekko-ebeln is used for the parameter in the first screen (gv_tabix is declared as type sy-tabix in the Include)


  ENDCASE.

ENDMODULE.

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_9001  INPUT
*&---------------------------------------------------------------------*
*       text
*----------------------------------------------------------------------*
MODULE USER_COMMAND_9001 INPUT.


  CASE OK_CODE.
    WHEN 'BACK' OR 'EXIT' OR 'CANC'.
      LEAVE PROGRAM.
    WHEN 'DELETE'.
      IF GWA_ZEKKO-EBELN IS INITIAL .
        MESSAGE 'Please enter document number' TYPE 'E'.
      ELSE.
        CALL SCREEN 9002.
      ENDIF.

    WHEN 'DISPLAY'.
            IF GWA_ZEKKO-EBELN IS INITIAL .
        MESSAGE 'Please enter document number' TYPE 'E'.
      ELSE.
        CALL SCREEN 9002.
      ENDIF.



  ENDCASE.

ENDMODULE.

0 Kudos

When i tried to debug, the gt_zekpo-ebeln is empty, i am not sure if this has something to do with not being able to delete record when pressing the 'DEL' button in the second screen, or it's another issue..

0 Kudos

Hi arnold92

You cannot assign GWA_ZEKKO-EBELN to GV_TABIX. GV_TABIX expects an integer number which will be the index of the selected record. Not the document's number.

If you want to store the document number then you should define GV_TABIX with a proper type, same as the GWA_ZEKKO-EBELN field has. Changing the name of the variable would be good, too. In this case you will also have to change this part of the code (shown below), because you would have the document number:

DELETE gt_zekko INDEX gv_tabix. 
delete gt_zekpo INDEX gv_tabix.

Regards,

Mateusz

0 Kudos

Hi arnold92

You cannot assign GWA_ZEKKO-EBELN to GV_TABIX. GV_TABIX expects an integer number which will be the index of the selected record. Not the document's number.

If you want to store the document number then you should define GV_TABIX with a proper type, same as the GWA_ZEKKO-EBELN field has. Changing the name of the variable would be good, too. In this case you will also have to change this part of the code (shown below), because you would have the document number:

DELETE gt_zekko INDEX gv_tabix. 
delete gt_zekpo INDEX gv_tabix.

Regards,

Mateusz

0 Kudos

Actually I would like to delete based on selected record (in non editable mode, all the fields and tables i made them to non editable as superior wanted) entered in parameter in the first screen, therefore i used sy-tabix.

Another way i did was using this

 data: gv_ebeln type zekko_03-ebeln

IF gv_ebeln is NOT INITIAL.
      DELETE gt_zekko WHERE ebeln = gwa_zekko-ebeln.
      delete gt_zekpo WHERE ebeln = gwa_zekpo-ebeln.
  ENDIF.<br>

Im not sure if i have missed something else aside from the delete