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: 

Problem with data gaetting saved in table

Former Member
0 Kudos

Hi Experts,

Please check the below code and advice me,

SELECT ZP_STOCK ZD_QTY MATNR IDNRK LIFNR FROM ZSUB INTO CORRESPONDING FIELDS 
     OF TABLE IT_ZSUB FOR ALL ENTRIES IN IT_FINAL WHERE MATNR = IT_FINAL-MATNR
                         AND IDNRK = IT_FINAL-IDNRK AND LIFNR = IT_FINAL-LIFNR.
                                                        



  LOOP AT IT_FINAL.
    READ TABLE IT_ZSUB WITH KEY MATNR = IT_FINAL-MATNR
                                IDNRK = IT_FINAL-IDNRK
                                LIFNR = IT_FINAL-LIFNR.
    MOVE IT_ZSUB-ZP_STOCK TO IT_FINAL-ZP_STOCK.
    MOVE IT_ZSUB-ZD_QTY   TO IT_FINAL-ZD_QTY.
    MODIFY IT_FINAL.
  ENDLOOP.

-


FORM USER_COMMAND USING R_UCOMM LIKE SY-UCOMM
               RS_SELFIELD TYPE SLIS_SELFIELD.


  CASE R_UCOMM.
    WHEN '&ENT'.
      LOOP AT IT_FINAL.
        IF IT_FINAL-ZP_STOCK <> 0.
          IT_FINAL-ZD_QTY = IT_FINAL-CLOS - IT_FINAL-ZP_STOCK.
        ELSE.
          IT_FINAL-ZP_STOCK = 0.
        ENDIF.
        MODIFY IT_FINAL.
      ENDLOOP.


    WHEN '&SAVE'.
      LOOP AT IT_FINAL.
        MOVE IT_FINAL-MATNR TO ZSUB-MATNR.
        MOVE IT_FINAL-IDNRK TO ZSUB-IDNRK.
        MOVE IT_FINAL-LIFNR TO ZSUB-LIFNR.
        MOVE IT_FINAL-ZD_QTY TO ZSUB-ZD_QTY.
        MOVE IT_FINAL-ZP_STOCK TO ZSUB-ZP_STOCK.
        MODIFY ZSUB.
      ENDLOOP.

  ENDCASE.
ENDFORM.                    "USER_COMMAND

And in my out put :

-


Finished goods (matnr) - Raw material1*(idnrk) -

Finished goods (matnr) - Raw material2*(idnrk) -

Finished goods (matnr) - Raw material3*(idnrk) - it_sub-zp_stock - it_sub-zd_qty.

-


As above only for the last idnrk ie raw material 3 , it_sub-zp_stock & it_sub-zd_qty is getting saved in table .

Please advice me if there is any resolution for this problem.

Thanks

Karthik

3 REPLIES 3

Former Member
0 Kudos

Hi,

Could you please be a bit more specific with the requirement as to

what are the records in it_zsub, it_final, what is the output you want,

try debugging the code hope the question i asked might help you in debugging the code and getting the result...

Regards,

Siddarth

Former Member
0 Kudos

hi,

Here,

WHEN '&ENT'.
      LOOP AT IT_FINAL.
        IF IT_FINAL-ZP_STOCK  0.
          IT_FINAL-ZD_QTY = IT_FINAL-CLOS - IT_FINAL-ZP_STOCK.
        ELSE.
          IT_FINAL-ZP_STOCK = 0.
        ENDIF.
        MODIFY IT_FINAL.
      ENDLOOP.
 
 
    WHEN '&SAVE'.
      LOOP AT IT_FINAL.
        MOVE IT_FINAL-MATNR TO ZSUB-MATNR.
        MOVE IT_FINAL-IDNRK TO ZSUB-IDNRK.
        MOVE IT_FINAL-LIFNR TO ZSUB-LIFNR.
        MOVE IT_FINAL-ZD_QTY TO ZSUB-ZD_QTY.
        MOVE IT_FINAL-ZP_STOCK TO ZSUB-ZP_STOCK.
        MODIFY ZSUB.
      ENDLOOP.

Instead of looping the table, the other option is..

Carry out the required modifications in the internal table.

Later, update the data base table with the update statement.

UPDATE DBTAB FROM TABLE ITAB.

This way all the modified values in the internal table with similar key fields are reflected in the database table and the others are left over.

Thanks

Sharath

0 Kudos

after update the standard table use

update database table from internal table.

if sy-subrc = 0.

commit work .

else.

Roll back.

endif.

At the time of modfying internal table use index.

modify itab index sy-tabix.

Reagrds,

Prabhudas