Skip to Content
0
Former Member
Jul 30, 2009 at 04:06 PM

Insert or Update - Update Fails?

24 Views

Hi Frorums

When I execute this code, the insert works into my table however, the update does not, it causes the program to abort.

FORM UPDATE_ZPRDCOPATOT .
  DATA: LV_SALES LIKE ZPRDCOPATOT-ZGROSSALES,
        LV_COST  LIKE ZPRDCOPATOT-ZINTPRICE.


  TOT_REC-ZPERIOD = GV_PERIOD.
  TOT_REC-ZDISTCHAN = GV_CURR_CHANNEL.
  TOT_REC-ZGROSSALES = GV_TOTAL_SALES.
  TOT_REC-ZINTPRICE = GV_TOTAL_COST.

  SELECT * FROM
    ZPRDCOPATOT WHERE ZPERIOD = GV_PERIOD AND ZDISTCHAN = GV_CURR_CHANNEL.
  ENDSELECT.

  IF sy-subrc = 4.
    INSERT INTO ZPRDCOPATOT VALUES TOT_REC.
  ELSEIF SY-SUBRC EQ 0.
    TOT_REC-ZGROSSALES = TOT_REC-ZGROSSALES + ZPRDCOPATOT-ZGROSSALES.
    TOT_REC-ZINTPRICE = TOT_REC-ZINTPRICE + ZPRDCOPATOT-ZINTPRICE.
    MODIFY TOT_REC.
    UPDATE ZPRDCOPATOT SET
    ZGROSSALES = TOT_REC-ZGROSSALES
    ZINTPRICE  = TOT_REC-ZINTPRICE
    WHERE ZPERIOD = GV_PERIOD AND ZDISTCHAN = GV_CURR_CHANNEL.

  ENDIF.
  CLEAR: GV_TOTAL_SALES, GV_TOTAL_COST.

ENDFORM.                    " UPDATE_ZPRDCOPATOT

Edited by: keith warnock on Jul 30, 2009 6:06 PM