Hi Karan,
* Uploading the data into the database table
LOOP AT it_tab INTO wa_tab.
ZEXCEL-EMPNAme = wa_tab-EMPName.
ZEXCEL-Designation = wa_tab-Designation.
ZEXCEL-Salary = wa_tab-Salary.
MODIFY ZEXCEL.
The following code is used to modify the Z table [ZEXCEL] from the internal table [it_tab].
LOOP AT it_tab INTO wa_tab.
We do loop on the internal table to work area, as there are more than one records.
ZEXCEL-EMPNAme = wa_tab-EMPName.
ZEXCEL-Designation = wa_tab-Designation.
ZEXCEL-Salary = wa_tab-Salary.
In the above code the value which was moved to the work area is getting assigned to the Z table field.
This is 1:1 mapping.
MODIFY ZEXCEL.
Here your ZEXCEL table is modified means the data is getting stored in your Z table.
if sy-subrc <> 0.
The coding standard says that we should have a sy-subrc check after doing any modification in the database.
Sy-subrc check is nothing but just check which returns a YES or NO. YES means Sy-subrc = 0, and NO means Sy-subrc <> 0.
If the sy-subrc check fails then we want to move the records into an error table, so the below statement is used to move the values of work area into the work area of error table. (but only if the sy-subrc check fails)
MOVE-CORRESPONDING wa_tab to wa_error.
append wa_error to it_error.
Append the work area into the error internal table.
clear wa_error.
Clear is used to clear the work area. Here the error work area is getting cleared.
endif.
clear wa_tab.
Here the work area associated to it_tab is getting cleared.
ENDLOOP.
Now a success message is displayed after the values are getting stored in the Z table.
If the data is getting successfully stored then according to the above logic the error internal table will be blank.
if it_error is initial.
So the above statement checks if the error internal table is initial or not, and the success message is getting raised after that.
message 'all data updated Sucessfully' type 'S'.
else.
and if the error table is not empty then below logic is getting called.
loop at it_error into wa_error.
write:/ wa_error-empname.
endloop.
endif.
Hope I was able to clear your doubts.
Regards,