2023 Jul 05 12:06 PM
Hi,
I need to show the Sy-dbcnt count in Export parameters, If User pass the multiple values.
But , here i am getting only 1 record as updated. Please guidance what mistake here.
IF it_price_stage IS NOT INITIAL.
SELECT * FROM zmm_price_stage INTO TABLE it_stage FOR ALL ENTRIES IN it_price_stage
WHERE zm_sub_market_code EQ it_price_stage-zm_sub_market_code AND
zm_price_plan EQ it_price_stage-zm_price_plan AND
zm_feature_code EQ it_price_stage-zm_feature_code.
IF it_stage IS NOT INITIAL.
* CLEAR it_stage.
ENDIF.
LOOP AT it_price_stage INTO DATA(ls_price).
READ TABLE it_stage INTO DATA(ls_stage) WITH KEY zm_sub_market_code = ls_price-zm_sub_market_code
zm_price_plan = ls_price-zm_price_plan
zm_feature_code = ls_price-zm_feature_code.
IF sy-subrc = 0 .
IF ls_price-zm_fromdate > ls_stage-zm_fromdate.
ls_stage-zm_fromdate = ls_price-zm_fromdate - 100000.
ELSEIF ls_price-zm_fromdate < ls_stage-zm_fromdate.
ls_stage-zm_fromdate = ls_price-zm_fromdate.
ENDIF.
ENDIF.
MODIFY zmm_price_stage FROM ls_price.
IF sy-subrc IS INITIAL.
COMMIT WORK.
ENDIF.
ENDLOOP.
ev_message = sy-dbcnt.
CONDENSE ev_message.
CONCATENATE TEXT-001 ev_message INTO ev_message.
ELSE.
ev_message = TEXT-002.
ENDIF.
CLEAR: ls_price , ls_stage.
2023 Jul 05 3:35 PM
You are only updating one record at a time in the DB. You can either 1. collect them in an internal table and use MODIFY <db_table> FROM TABLE <itab> or 2. Have a local variable to count the individual updates and use that as a counter.
2023 Jul 05 4:55 PM
As sathya.gunasekaran6 said, you did a mistake in your code:
MODIFY zmm_price_stage FROM ls_price.
IF sy-subrc IS INITIAL.
COMMIT WORK.
ENDIF.
ENDLOOP.
ev_message = sy-dbcnt.
You are reading sy-dbcnt only once after many MODIFY, hence you get only the information about the last MODIFY.
Instead you should do something like this:
MODIFY zmm_price_stage FROM ls_price.
IF sy-subrc IS INITIAL.
lv_total_dbcnt = lv_total_dbcnt + sy-dbcnt.
COMMIT WORK.
ENDIF.
ENDLOOP.
ev_message = lv_total_dbcnt.
NB: you can hardcode "1" instead of SY-DBCNT because you only update 1.
2023 Jul 06 9:38 AM
lines( tabname ) will give the no. of lines present in the internal table name