Skip to Content
0
Former Member
Jul 02, 2007 at 11:34 AM

key fields

20 Views

hi,

iam working on module pool programs.

i have to update a data base table.

for that i have written a code.

it is updating also , but it should not avvept dupliocate key fields.

please help as sson as possible.

below is my code.

DATA: lv_irn3 TYPE zirn.

SELECT MAX( irn ) FROM zfocal_areas

INTO lv_irn3

WHERE bukrs EQ 'GEF'.

lv_irn3 = lv_irn3 + 1.

LOOP AT gt_focal_areas INTO gs_focal_areas WHERE status EQ space.

READ TABLE gt_focal_areas_old INTO gs_focal_areas_old

WITH KEY focal_area = gs_focal_areas-focal_area

status = c_old.

IF sy-subrc NE 0.

IF gs_focal_areas_old-expired_on LT sy-datum.

gs_focal_areas_f-bukrs = c_gef.

gs_focal_areas_f-focal_area = gs_focal_areas-focal_area.

gs_focal_areas_f-focal_desc = gs_focal_areas-focal_desc.

gs_focal_areas_f-expired_by = gs_focal_areas-expired_by.

gs_focal_areas_f-expired_on = gs_focal_areas-expired_on.

gs_focal_areas_f-expired_at = gs_focal_areas-expired_at.

gs_focal_areas_f-upd_user = sy-uname.

gs_focal_areas_f-upd_date = sy-datum.

gs_focal_areas_f-upd_time = sy-uzeit.

gs_focal_areas_f-irn = lv_irn3.

APPEND gs_focal_areas_f TO gt_focal_areas_f.

CLEAR: gs_focal_areas, gs_focal_areas_f.

lv_irn3 = lv_irn3 + 1.

ELSE.

gv_error = 'X'.

MESSAGE 'Focal Area has not expired' TYPE 'E'.

ENDIF.

ELSE.

gs_focal_areas_f-bukrs = c_gef.

gs_focal_areas_f-focal_area = gs_focal_areas-focal_area.

gs_focal_areas_f-focal_desc = gs_focal_areas-focal_desc.

gs_focal_areas_f-expired_by = gs_focal_areas-expired_by.

gs_focal_areas_f-expired_on = gs_focal_areas-expired_on.

gs_focal_areas_f-expired_at = gs_focal_areas-expired_at.

gs_focal_areas_f-upd_user = sy-uname.

gs_focal_areas_f-upd_date = sy-datum.

gs_focal_areas_f-upd_time = sy-uzeit.

gs_focal_areas_f-irn = lv_irn3.

APPEND gs_focal_areas_f TO gt_focal_areas_f.

CLEAR: gs_focal_areas, gs_focal_areas_f.

lv_irn3 = lv_irn3 + 1.

ENDIF.

ENDLOOP.

CHECK NOT gt_focal_areas_f[] IS INITIAL.

  • Modify data base table Zfocal_Areas

MODIFY zfocal_areas FROM TABLE gt_focal_areas_f.

IF sy-subrc EQ 0.

  • Set record status as OLD in all lines of ITAB

gs_focal_areas-status = c_old.

MODIFY gt_focal_areas FROM gs_focal_areas TRANSPORTING status

WHERE status EQ space.

CLEAR gs_focal_areas.

REFRESH gt_focal_areas_f.

*

ELSE.

MESSAGE 'IRN not created' TYPE 'E'.

ENDIF.

please help as soon as possibe.

kirthi,