Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Need to show the Sy-dbcnt in FM.

divsmart
Participant
0 Kudos

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.
3 REPLIES 3

sathyags
Active Participant
0 Kudos

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.

Sandra_Rossi
Active Contributor

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.

0 Kudos

lines( tabname ) will give the no. of lines present in the internal table name