‎2006 Jun 28 10:27 PM
Hi,
I created a module program. My intention is to insert/change/delete entries in the database table ztab through table control and internal table itab.
Ztab has fields mandt, vkorg, kunnr, count. I am attaching the module program code below as well as screen flow logic. I know for sure, there is something wrong with delete operation. But could not figure out why the insert/change operation is also not taking place succesfully. Can you please tell me where you think I am putting wrong step and suggest me the correct code?
Thanks in advance.
PROGRAM zt .
TABLES: ztab.
DATA: BEGIN OF itab OCCURS 10.
DATA: checkbox(1) TYPE c.
INCLUDE STRUCTURE ztab.
DATA: END OF itab.
CONTROLS: tcontrol TYPE TABLEVIEW USING SCREEN '1000'.
DATA: flg,
ln TYPE i.
----
MODULE get_tcontrol_lines OUTPUT *
----
........ *
----
MODULE get_tcontrol_lines OUTPUT.
SELECT vkorg kunnr count
FROM ztab
INTO CORRESPONDING FIELDS OF TABLE itab.
DESCRIBE TABLE itab LINES ln.
tcontrol-lines = ln + 100.
ENDMODULE.
----
MODULE set_status OUTPUT *
----
........ *
----
MODULE set_status OUTPUT.
SET PF-STATUS 'ZSTATUS'.
set titlebar 'ZTITLE'.
ENDMODULE.
----
MODULE USER_COMMAND_1001 input *
----
........ *
----
MODULE user_command_1001 INPUT.
DATA: lv_fcode LIKE sy-ucomm,
lv_fcode1 like sy-ucomm,
lv_answer(1) TYPE c.
lv_fcode = sy-ucomm.
lv_fcode1 = lv_fcode.
clear lv_fcode.
CASE lv_fcode1.
WHEN 'CHANGE'.
flg = 'Y'.
WHEN 'DELETE'.
flg = 'Y'.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Confirm '
DIAGNOSE_OBJECT = ' '
text_question = 'Are you sure?'
text_button_1 = 'Yes'(001)
ICON_BUTTON_1 = ' '
text_button_2 = 'No'(002)
ICON_BUTTON_2 = ' '
DEFAULT_BUTTON = '1'
DISPLAY_CANCEL_BUTTON = 'X'
USERDEFINED_F1_HELP = ' '
START_COLUMN = 25
START_ROW = 6
POPUP_TYPE =
IMPORTING
answer = lv_answer.
IF lv_answer EQ '1'.
UPDATE zdtab FROM itab.
DELETE itab WHERE checkbox = 'X'.
ENDIF.
WHEN 'SAVE'.
MODIFY ztab FROM TABLE itab.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
----
MODULE set_screen_fields_output *
----
........ *
----
MODULE set_screen_fields output.
LOOP AT SCREEN.
IF flg IS INITIAL.
screen-input = 0.
ELSEIF flg EQ 'Y'.
IF ( ( screen-name = 'itab-count'
OR screen-name = 'itab-checkbox' )
AND tcontrol-current_line LE ln ).
screen-input = 1.
ELSEIF ( ( screen-name = 'itab-vkorg'
OR screen-name = 'itab-kunnr' )
AND tcontrol-current_line LE ln ).
screen-input = 0.
ENDIF.
ENDIF.
MODIFY SCREEN.
ENDLOOP.
ENDMODULE.
----
MODULE vkorg INPUT *
----
........ *
----
MODULE vkorg INPUT.
MODIFY itab INDEX tcontrol-current_line.
IF tcontrol-current_line GT ln.
READ TABLE itab WITH KEY kunnr = itab-kunnr.
kunnr = itab-kunnr.
IF sy-subrc NE 0.
APPEND itab.
ENDIF.
ENDIF.
ENDMODULE.
----
MODULE check INPUT *
----
........ *
----
MODULE check INPUT.
modify itab index tcontrol-current_line.
endmodule.
****Statements in screen flow logic
PROCESS BEFORE OUTPUT.
Module set_status.
Module get_tcontrol_lines.
Loop at itab with control tcontrol cursor tcontrol-current_line.
Module set_screen_fields.
endloop.
MODULE STATUS_1001.
*
PROCESS AFTER INPUT.
Loop at itab.
field itab-checkbox module check.
field itab-vkorg module vkorg.
field itab-kunnr module vkorg.
MODULE USER_COMMAND_1000.
endloop.
Message was edited by: nuren hm
‎2006 Jun 28 10:36 PM
Here is your USER_COMMAND module code. Where is the INSERT and CHANGE logic here? There is no WHEN 'INSERT' and in the WHEN 'CHANGE' all you are doing is setting a flag.
MODULE set_status OUTPUT.
SET PF-STATUS 'ZSTATUS'.
set titlebar 'ZTITLE'.
ENDMODULE.
*---------------------------------------------------------------------*
* MODULE USER_COMMAND_1001 input *
*---------------------------------------------------------------------*
* ........ *
*---------------------------------------------------------------------*
MODULE user_command_1001 INPUT.
DATA: lv_fcode LIKE sy-ucomm,
lv_fcode1 like sy-ucomm,
lv_answer(1) TYPE c.
lv_fcode = sy-ucomm.
lv_fcode1 = lv_fcode.
clear lv_fcode.
CASE lv_fcode1.
WHEN 'CHANGE'.
flg = 'Y'.
WHEN 'DELETE'.
flg = 'Y'.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
titlebar = 'Confirm '
* DIAGNOSE_OBJECT = ' '
text_question = 'Are you sure?'
text_button_1 = 'Yes'(001)
* ICON_BUTTON_1 = ' '
text_button_2 = 'No'(002)
* ICON_BUTTON_2 = ' '
* DEFAULT_BUTTON = '1'
* DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
* IMPORTING <b><-- why is this commented
answer = lv_answer.
IF lv_answer EQ '1'.
UPDATE zdtab FROM itab.
DELETE itab WHERE checkbox = 'X'.
ENDIF.
WHEN 'SAVE'.
MODIFY ztab FROM TABLE itab.
WHEN 'CANCEL'.
LEAVE PROGRAM.
ENDCASE.
ENDMODULE.
‎2006 Jun 28 10:39 PM
hi Nuren,
Srinivas is right Importing parameter is commented uncoment that one
i.e,
<b> IMPORTING
answer = lv_answer.</b>
‎2006 Jun 28 10:40 PM
I think that this one problem.
IF lv_answer EQ '1'.
UPDATE zdtab FROM itab.
DELETE itab WHERE checkbox = 'X'.
ENDIF.
I would probably be better to do it like this.
IF lv_answer EQ '1'.
loop at itab where checkbox = 'X'.
delete zdtab from itab.
delete itab.
endloop.
ENDIF.
Also, the user-command module should not be in the LOOP in the screen flow.
PROCESS AFTER INPUT.
Loop at itab.
field itab-checkbox module check.
field itab-vkorg module vkorg.
field itab-kunnr module vkorg.
* There needs to be another module here to handle
* updating the ITAB from the screen.
endloop.
MODULE USER_COMMAND_1000.
REgards,
Rich Heilman
‎2006 Jun 29 4:57 AM
Srinivas,
Change/Insert operations are being worked along with the case 'SAVE'. And thank you and santosh for pointing out comment error. I overlooked that comment before.
Rich,
Thanks for your input.
Your both tips helped.