‎2007 Dec 18 9:48 AM
Hi all,
I have a small requirement where i am trying to enter data into the database table (zdata_12) using the table control screen fields.
But my problem is its not able to get updated into the ztable.
and the moment i press "save" button its getting deleted from the rows.
so below i am providing my code.
<code>
MODULE USER_COMMAND_9001 INPUT.
OK_CODE = SY-UCOMM.
CASE OK_CODE.
WHEN 'SAVE'.
*zdata_12-EMP = IT_EMP-EMPID.
*zdata_12-SUBJECT = IT_EMP-SUBJECT.
*zdata_12-DATE1 = IT_EMP-DAYS1.
IT_EMP-EMPID = IT_EMP-EMPID.
IT_EMP-SUBJECT = IT_EMP-SUBJECT.
IT_EMP-DAYS1 = IT_EMP-DAYS1.
*APPEND IT_EMP.
INSERT ZDATA_12 FROM TABLE IT_EMP. "ACCEPTING DUPLICATE KEYS.
*insert zdata_12.
IF SY-SUBRC = 0.
COMMIT WORK.
ENDIF.
ENDCASE.
ENDMODULE. " USER_COMMAND_9001 INPUT
</code>
This is global data declaration i did with
<code>
DATA: OK_CODE TYPE SY-UCOMM,
SAVE_OK LIKE OK_CODE.
tables : zdata_12.
*types : BEGIN OF ty_EMP ,
EMPID type pa0001-pernr,
SUBJECT(20) type c,
DAYS1(12) type c,
END OF ty_EMP.
DATA: BEGIN OF It_EMP OCCURS 0 ,
EMPID type C,
SUBJECT(20) type c,
DAYS1(12) type c,
END OF IT_EMP.
*DATA : it_emp TYPE STANDARD TABLE OF ty_EMP WITH HEADER LINE.
controls : tbc type tableview using screen '9001'.
</code>
Thanks,
satish
‎2007 Dec 18 9:54 AM
try something like this....
I m not sure why its getting cleared ...may be in PBO it happens..
any way check this code...guess it may help[ u...
data:it_stkr_det type zpp32_stkr_det.
loop at it_sticker_material.
clear zpp32_stkr_det.
if st_header-component is not initial.
it_stkr_det-component = st_header-component.
else.
select single * from zpp31_stkr_mast where
stkr_part_number = it_sticker_material-stkr_part_number and
plant = st_header-werks and
status = space.
if sy-subrc = 0.
it_stkr_det-component = zpp31_stkr_mast-component.
clear zpp31_stkr_mast.
endif.
endif.
it_stkr_det-plant = st_header-werks.
it_stkr_det-zdate = st_header-budat.
it_stkr_det-shift = st_header-bktxt.
it_stkr_det-stkr_part_number = it_sticker_material-stkr_part_number.
it_stkr_det-emp_no = st_header-pernr.
it_stkr_det-issue_qty = it_sticker_material-issue_qty.
it_stkr_det-prod_qty = it_sticker_material-prod_qty.
it_stkr_det-return_qty = it_sticker_material-return_qty.
move it_stkr_det to zpp32_stkr_det.
insert zpp32_stkr_det.
if sy-subrc = 0.
commit work.
else.
rollback work.
exit.
endif.
clear it_stkr_det.
endloop.
‎2007 Dec 18 9:55 AM
Hi satish,
I think check the data is already there in your data base check you key fields in that data base table the key field combination data is already there in your z table check it.
Try like this code this is in my requirment.
MODULE USER_COMMAND_0100 INPUT.
case sy-ucomm.
WHEN 'SUBMIT'.
perform submit_data.
WHEN 'SAVE'.
PERFORM SUBMIT_DATA.
WHEN 'BACK'.
clear w_flag1.
refresh it_timesheet.
clear fs_time.
LEAVE TO SCREEN 1000.
ENDCASE.
if w_app eq 'X'.
message s015 with 'no table entries found'.
endif.
ENDMODULE. " USER_COMMAND_0100 INPUT
FORM submit_data .
Loop at it_timesheet into fs_time.
if fs_time-c_box eq 'X'.
PERFORM MOVE_DATA_TOFTEMP using fs_time.
perform insert_data using fs_time.
endif.
Endloop. " Loop at it_timesheet....
CLEAR fs_time.
refresh it_timesheet.
ENDFORM. " Submit_data
FORM insert_data using p_fs_timesheet like fs_time.
data: w_status(15) type c.
case w_temp1.
when 'SAVE'.
UPDATE ZCL_TIME_DATA1 FROM fs_temp.
if sy-subrc eq 0.
delete it_timesheet index sy-tabix.
message s005.
endif. " If sy-subrc eq
WHEN 'SUB'.
Insert into ZCL_TIME_DATA1 values fs_temp.
if sy-subrc eq 0.
delete it_timesheet index sy-tabix.
message s005.
endif. " If sy-subrc eq 0
endcase.
ENDFORM. " insert_data
Plz Reward if useful,
Mahi.Hi satish,
I think check the data is already there in your data base check you key fields in that data base table the key field combination data is already there in your z table check it.
Plz Reward if useful,
Mahi.
Edited by: Maheswari Chegu on Dec 18, 2007 11:08 AM
‎2007 Dec 18 10:03 AM
Hi,
In PAI of the screen, you need to write modify command.
LOOP AT i_makt.
FIELD i_makt-pick MODULE check.
FIELD i_makt-zmatnr MODULE zmatnr .
ENDLOOP.
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
And then while save is pressed, modify the database table from internal table.
Check this link.