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: 

Unable to ADD or DELETE rows in a dialog prog

Former Member
0 Kudos

Hi all,

I am having a requirement in dialog programming where in a table control if anyone enters a value of MATNR the corresponding MATKL and a custom field ZZLIST are diaplayed against that MATNR.

I have two push buttons in the screen- ADD and DELETE.

Now every row has a check box with it.when a user wants to delete a row he needs to tick the check boxes and click on DELETE.The row should be deleted.

If the user clicks on ADD then an extra row should be added.

I applied logic as follows:

    • DELETE

LOOP AT I_MARA INTO WA_MARA.

CASE OK_CODE.

WHEN 'DEL'.

IF WA_MARA-ZZSELECT = 'X'.

WA_MARA-MATNR = ' '.

WA_MARA-MATKL = ' '.

WA_MARA-ZZSELECT = ' '.

WA_MARA-ZZLIST = ' '.

MODIFY I_MARA FROM WA_MARA.

ENDIF.

ENDCASE.

Comments: When i click on DELETE all the entries are getting deleted.

**ADD

WHEN 'ADD'.

LOOP AT I_MARA INTO WA_MARA.

WA_MARA-MATNR = ' '.

WA_MARA-MATKL = ' '.

WA_MARA-ZZSELECT = ' '.

WA_MARA-ZZLIST = ' '.

APPEND WA_MARA TO I_MARA.

ENDLOOP.

Comments: When i click on ADD again all the entries are getting deleted.

Please help me with the logic.

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos
** DELETE

LOOP AT I_MARA INTO WA_MARA.
CASE OK_CODE.
WHEN 'DEL'.

Loop at I_MARA into WA_MARA.
IF WA_MARA-ZZSELECT = 'X'.
Delete i_mara.
ENDIF.
ENDCASE.


**ADD

WHEN 'ADD'.

APPEND initial line TO I_MARA.

Regards,

Gurpreet

4 REPLIES 4

I355602
Advisor
Advisor
0 Kudos

Hi,

Use this way:

At screen logic:-


PROCESS BEFORE OUTPUT.
*  MODULE status_8001.
  
  LOOP WITH CONTROL tab_ctrl.
    MODULE read_data. "<-- read data from internal table to table control
  ENDLOOP.

PROCESS AFTER INPUT.
*  MODULE user_command_8001.
  
  LOOP WITH CONTROL tab_ctrl.
    MODULE modify_data. "<-- modify data from table control to internal table
  ENDLOOP.

  MODULE add_delete_records.

In PAI,


MODULE modify_data.
  MODIFY i_mara FROM wa_mara INDEX tab_ctrl-current_line.
ENDMODULE.

MODULE add_delete_data.
  CASE sy-ucomm.
    WHEN 'DELETE'.
      DELETE FROM i_mara WHERE zzselect = 'X'.
    WHEN 'ADD'.
      "if using same table control with existing entries
      "then whenever you add new row and any user action is performed then
      "internal table is already modified in MODULE modify_data.
      "so i guess no need to add code
  ENDCASE.
ENDMODULE.

Let me know in case of any doubt.

Hope this helps you.

Regards,

Tarun

awin_prabhu
Active Contributor
0 Kudos

Hi,

Try using GET CURSOR LINE lin.

Code:

    • DELETE

GET CURSOR LINE lin. <----- Gets the line number where cursor is placed

LOOP AT I_MARA INTO WA_MARA.

CASE OK_CODE.

WHEN 'DEL'.

IF SY-TABIX = LIN. <------ Check sy-tabix with line number 'lin'.

IF WA_MARA-ZZSELECT = 'X'.

WA_MARA-MATNR = ' '.

WA_MARA-MATKL = ' '.

WA_MARA-ZZSELECT = ' '.

WA_MARA-ZZLIST = ' '.

MODIFY I_MARA FROM WA_MARA.

ENDIF.

EBDIF.

ENDCASE.

Former Member
0 Kudos
** DELETE

LOOP AT I_MARA INTO WA_MARA.
CASE OK_CODE.
WHEN 'DEL'.

Loop at I_MARA into WA_MARA.
IF WA_MARA-ZZSELECT = 'X'.
Delete i_mara.
ENDIF.
ENDCASE.


**ADD

WHEN 'ADD'.

APPEND initial line TO I_MARA.

Regards,

Gurpreet

0 Kudos

Thanx a lot guys for all your help.

Gurmeet , your logic is working fine.thanx again !!