2015 Feb 16 5:06 AM
Hi Experts,
I had written the Following Update Function Module to update the student marks in zstudentmarks based on the name of student imported from main program.
FUNCTION ZF_MARKS .
*"----------------------------------------------------------------------
*"*"Update Function Module:
*"
*"*"Local Interface:
*" IMPORTING
*" VALUE(NAME) TYPE CHAR30
*"----------------------------------------------------------------------
DATA lv_id TYPE int1.
* Getting StudentID Based on name
SELECT SINGLE stud_id
FROM zstudentmaster
INTO lv_id
WHERE stud_name = name.
wa-id = lv_id.
wa-mark1 = 35.
wa-mark2 = 35.
wa-mark3 = 38.
wa-mark4 = 36.
wa-mark5 = 35.
*Inserting into Internal Table
INSERT wa INTO TABLE itab.
*Updating entry in DB
MODIFY zstudentmarks FROM TABLE itab.
COMMIT WORK.
ENDFUNCTION.
While Debugging the record is showing in the internal table. But it is not updating in the database....
Thanx in advance...
2015 Feb 16 8:31 AM
hi pankaj,
may be record is already there and therefore it is not updating.
also for checking the problem
replace
*Updating entry in DB
MODIFY zstudentmarks FROM TABLE itab.
with
*Updating entry in DB
MODIFY zstudentmarks FROM wa.
2015 Feb 16 5:39 AM
Hi Pankaj,
Kindly check whether mark1, mark2, mark3, mark4, mark5 is not a primary key. If it is a primary key, then system wont update the value. In debug mode check the Subrc value in modify statement.
Make sure Itab has the same structure of the Ztable 'zstudentmarks'.
Regards
Rajkumar Narasimman
2015 Feb 16 6:24 AM
Hello Rajkumar N,
The Internal Table and Zstudentmarks has the same structure.
And mark1, mark2, mark3, mark4, mark5 is not a primary key. The primary key is the stud_id.
2015 Feb 16 6:20 AM
Hi,
If you have client field (field having data element MANDT) in the custom table, try to include it in the work area WA.
If there is already an entry in the table with the same primary key(s) as in work area, you will end up getting a data dump with error statement saying 'duplicate record'. Please check if that is the case here.
Hope this helps,
~Athreya
2015 Feb 16 6:27 AM
Hello,
There is no MANDT field in the table.
stud_id is a primary key and i want to update the existing record not inserting another record. It is not giving any error. If I am copying this code to the REPORT program than its working fine and updating the records in database.
2015 Feb 16 7:16 AM
Hi ,
Have you declared your
internal table like this
Data itab type table of zstudentmarks with header line.
And work area
wa like line of itab.
You can select and modify using this
select single * from zstudmarks into wa where stud_name = name.
if ( sy-subrc = 0 ).
* modify the fields you want here
wa-mark1 = 78.
wa-mark2 = 79.
* modify table
modify zstudmarks from wa.
endif.
I hope this helps.
2015 Feb 16 8:32 AM
Sayeh Cyril wrote:
Hi ,
Have you declared your
internal table like this
Data itab type table of zstudentmarks with header line.
And work area
wa like line of itab
First, HEADER LINES are obsolete. Second, if you have a header line, you don't need a work area defined seperately.
2015 Feb 16 7:23 AM
Hi Pankaj,
Can you check that SELECT query again?
Student name is not a key field and in where clause you are using no key fields.
Now you may check for the following things,
1. when you select the Stud_ID based on name, what happens if two same name exist with different Stud_IDs?
2015 Feb 16 8:31 AM
hi pankaj,
may be record is already there and therefore it is not updating.
also for checking the problem
replace
*Updating entry in DB
MODIFY zstudentmarks FROM TABLE itab.
with
*Updating entry in DB
MODIFY zstudentmarks FROM wa.