Updating database table from an internal table
Hi All,
I am updating a database table from an internal table.
I am changing the non-key fields in that table.
when I check sy-subrc = 4.
Record already exists, because I am changing non-key fields of the
database table.
Is there any addition like to accept the duplicate keys with update.
Alternatively, I have used Modify, It is adding new record,
Again, I have search the old record and use Delete on the database table.
Thanks & Regards,
Kalyan Chandramouli
SAP ABAP Consultant
Hi,
You are right, the field which I am trying to change is a part of primary key.
Because, sy-subrc = 4. says,
No line with specified primary key exits in the database table.
I have a Z-tabel, with Kunnr Vkorg Matnr Bzirk Bztxt Split_percentage
In this table primary key consists of KunnrVkorgMatnr+Bzirk.
I am able to change the Split_percentage using UPDATE.
Now, my client want to change Bzirk, Bztxt also in the table.
How can I Go.
Thanks & Regards,
Kalyan Chandramouli
SAP ABAP Consultant
Similar Messages
-
I have 1 million records in application server and I want to update database table from that.
Is UPDATE statement the best technique to do it.
Just wanted to know if there is any other better tehcniques.
Also i want to write the errors to job log. How can we do that?
Regards,
DNPIf they are all new records or all changes, it would be best to use INSERT or UPDATE. You will also want to do mass inserts/changes using an internal table. Since you have so many records, you will probably have to do this in chunks in order to avoid dumping on the rollback area.
Rob -
Doubt in updating database table
hi all
i want to modify values ztable from a internal table ....
for eg : the ztable contains matnr and accept_qty
matnr qty
mat01
mat02
i need to modify qty of the table .. i am using where condition (ie modify where matnr = ) but where condition is not working for database tables .... how to proceed with this ..
thanks
lokeshhi,
before that :- modify statemnt will modify a record if there is record having the same key like that of record in work area.
if there is no record in itab with key of work area record, it will insert a new record in itab.
look this sample code.
*modify internal table
loop at itab into wa.
wa-field1 = data1.
wa-field2 = data2.
wa-field 3= data3.
modify itab from wa transporting field1 field2 field3 where key_field = wa-keyfield. "there shuld not be any chang in key field.
endloop.
*now update database table
*work area and data base structure shuld be same type
if itab[] is not initial.
modify ztable from table itab.
endif.
rgds
anver
if hlped pls mark points -
How to update database table !!!
hi all,
Please advice how to update database table with certain cndition needs to be checked.
Please consider below scenario.
have used enqueu and dequeue function to lock entries and also i have used BAPI so considering that return parameter . i want to update table
/tdk/st0027.
1. I want to update database table
2. there are certain condition needs to be checked like ,
loop at it_final into wa_final.
th_return-type = 'S'.
if th_final-vbeln = /tdk/st0027-vbeln and
th_final-posnr = /tdk/st0027-posnr and
th_final-etenr = /tdk/st0027-sdslno.
above condition which i need to check .and need to append below system fields need to be appended in table.
th_final-prstsind = '20'.
th_final-chgdate = g_date.
th_final-chgtime = g_uzeit.
th_final-chgprog = g_cprog.
th_final-chguser = g_uname.
append th_final to td_final.
update /tdk/st0027 FROM th_final.
endif.
endloop.
but i am getting error saying that "The type od database table and work area (TH_FINAL) are not unicode convertible"?
I am not able to understandwhat would be the solution for this ?
Thanks and regards,
Prasad K. NAralkarThe error occurs in the UPDATE statement included in the code. In this statement it is seen that there is a mismatch of structure defined for the DDIC table /tdk/st0027 and that of your work area th_final.
try to create a structure w.r.t the DDIC table.
Eg: DATA: wa_temp TYPE /tdk/st0027.
MOVE-CORRESPONDING th_final TO wa_temp.
Then try to UPDATE using the temporary work area i.e wa_temp which has structure similar to that of the database table. -
Enqueue and Dequeue before updating Database table
Hi all,
We are updating database tables using INSERT, MODIFY and UPDATE statements. Since many people will be running the application at the same time we need to lock the table before updating database table. So we need to use ENQUEUE and DEQUEUE functionality for this purpose.
Can any plz explain what are the steps we should follow now?
Thanks in advance.Hi,
Any Database access should carefully handled as multiple applications may be accessing the database at the same time. To read a record from the database you don't need to implement a lock, but to write you need not only locks but also ideally should use the Update Function Modules to comply SAP "All or Nothing" Principle. This will prevent data inconsistency of the database and the data will be proper state. You need to use the COMMIT WORK and ROLLBACK WORK in you code to handle the consistency part of the database.
The best design approach would be seperate the Database Layer completely from the business layers. This will make your code robust and easy to maintain.
As, for the Locking Concepts, you will get multiple resources from SDN as how to create Locks and implement the Locking modules in your code. But more than that what matters is why and how to implement the SAP Locking concepts to make your application run better.
Have a look at the following link
http://help.sap.com/saphelp_nw70/helpdata/en/cf/21eea5446011d189700000e8322d00/content.htm
Hope this helps.
Thanks,
Samantak. -
How to update database table from Internal Table
hi experts,
Can anyone please assist me in inserting records to a database table from an Internal Table
whose structures are identical.
Thanks in Advance,
Sudhaa............Hi Sudha,
Here are some example of update and insert:
UPDATE SFLIGHT SET PLANETYPE = 'A310'
PRICE = PRICE - '100.00'
WHERE CARRID = 'LH' AND CONNID = '0402'.
This example overwrites the contents of the PLANETYPE column with A310 and decreases the value of the PRICE column by 100 for each entry in SFLIGHT where CARRID contains u2018LHu2019 and CONNID contains u2018402u2019.
TABLES SPFLI.
DATA WA TYPE SPFLI.
MOVE 'AA' TO WA-CARRID.
MOVE '0064' TO WA-CONNID.
MOVE 'WASHINGTON' TO WA-CITYFROM.
UPDATE SPFLI FROM WA.
MOVE 'LH' TO SPFLI-CARRID.
MOVE '0017' TO SPFLI-CONNID.
MOVE 'BERLIN' TO SPFLI-CITYFROM.
UPDATE SPFLI.
CARRID and CONNID are the primary key fields of table SPFLI. All fields of those lines where the primary key fields are "AA" and "0064", or "LH" and "0017", are replaced by the values in the corresponding fields of the work area WA or the table work area SPFLI.
DATA: ITAB TYPE HASHED TABLE OF SPFLI
WITH UNIQUE KEY CARRID CONNID,
WA LIKE LINE OF ITAB.
WA-CARRID = 'UA'. WA-CONNID = '0011'. WA-CITYFROM = ...
INSERT WA INTO TABLE ITAB.
WA-CARRID = 'LH'. WA-CONNID = '1245'. WA-CITYFROM = ...
INSERT WA INTO TABLE ITAB.
WA-CARRID = 'AA'. WA-CONNID = '4574'. WA-CITYFROM = ...
INSERT WA INTO TABLE ITAB.
UPDATE SPFLI FROM TABLE ITAB.
This example fills a hashed table ITAB and then overwrites the lines in SPFLI that have the same primary key (CARRID and CONNID) as a line in the internal table.
Insert statement :
TABLES SPFLI.
DATA WA TYPE SPFLI.
WA-CARRID = 'LH'.
WA-CITYFROM = 'WASHINGTON'.
INSERT INTO SPFLI VALUES WA.
WA-CARRID = 'UA'.
WA-CITYFROM = 'LONDON'.
INSERT SPFLI FROM WA.
SPFLI-CARRID = 'LH'.
SPFLI-CITYFROM = 'BERLIN'.
INSERT SPFLI.
If the database table does not already contain a line with the same primary key as specified in the work area, the operation is completed successfully and SY-SUBRC is set to 0. Otherwise, the line is not inserted, and SY-SUBRC is set to 4.
Regards,
Premraj kaushik -
Updating database table from internal table
I am updating the database table from internal table for this is have used the following syntax
Update kna1 from table itab.
And it is giving error message as the work are itab is not long enough.
Please help me.Hi,
Refer this code
*& Form SUB_READ_UPDATE_BSEG
text
FORM sub_read_update_bseg.
IF NOT it_final[] IS INITIAL.
LOOP AT it_final INTO wa_final.
UPDATE bseg SET zuonr = wa_final-ccnum
WHERE bukrs EQ wa_final-bukrs
AND belnr EQ wa_final-vbeln
AND rfzei EQ wa_final-rfzei
AND saknr NE ' '.
ENDLOOP.
*--Message data updated successfully
MESSAGE i888 WITH text-002.
LEAVE LIST-PROCESSING.
ELSE.
*--Message No data found
MESSAGE i888 WITH text-003.
LEAVE LIST-PROCESSING.
ENDIF.
ENDFORM. " SUB_READ_UPDATE_BSEG
Regards,
PRashant -
Update database table from a work area
hi!
I have a workarea that is like the corresponding database table. There are a lot of fields so I dont want to update each field with an UPDATE but instead I want to do som sort of:
UPDATE dbase_table
FROM work_area
WHERE dbase_table-primary_key = work_area-primary_key
I could only find a statement called UPDATE dbase_table FROM work_area but I dont understand how without specifying a WHERE clause it knows which rows to update.
regards
BaranUPDATE dbtab FROM wa. or
UPDATE (dbtabname) FROM wa.
Extras:
1. ... CLIENT SPECIFIED
2. ... CONNECTION con
Effect
Changes one single line in a database table, using a primary key to identify the line and taking the values to be changed from the specified work area, wa. The data is read out of wa from left to right, matching the line structure of the database table dbtab. The structure of wa remains unchanged. This means that wa must be at least as wide (see DATA) as the line structure of dbtab, and have the same alignment. Otherwise, a runtime error occurs.
If either the database table, dbtab, or the work area, wa, contain Strings, wa must be compatible with the line structure of dbtab.
Example
Changing the telephone number of the customer with customer number '12400177' in the current client:
DATA wa TYPE scustom.
SELECT SINGLE * FROM scustom INTO wa
WHERE id = '12400177'.
wa-telephone = '06201/44889'.
UPDATE scustom FROM wa.
When the command has been executed, the system field SY-DBCNT contains the number of updated lines (0 or 1).
Examples
Update discount for the customer with the customer number '00017777' to 3 percent (in the current client):
DATA: wa TYPE scustom.
SELECT SINGLE * FROM scustom INTO wa
WHERE id = '00017777'.
wa-discount = '003'.
UPDATE scustom FROM wa.
The Return Code is set as follows:
SY-SUBRC = 0:
The specified line has been updated.
SY-SUBRC = 4:
The system could not update any line in the table, since there is no line with the specified primary key.
BR< JAcek -
How to update database table with this new internal table
hi
i have a internal table having 8 records and it contains one record which was modified by user
not i want this new record to be updated to the database table which was modified by the user
how to do it pls suggest?
i want to use index for comarision as using index will not have any problems like promary key etc
like i want to capture the index for this table which was modified thr recoed index and use thi record indext to modify the database table
or any other suggestion
regards
nishantHi Nishant,
Have an additional field in a table to indicate a change with which you avoid in updating the record modified by user.
Regards,
Madhu. -
Need help in updating database table from screen fields
Hi,
Can anyone tell me how to update the database table with the entries given in the fields of a screen ?...a procedure-wise explanation would be very helpful.
Thank you.
Moderator message: sorry, no beginner forums here, please search for available information or attend training.
locked by: Thomas Zloch on Aug 12, 2010 3:16 PMHi,
Can anyone tell me how to update the database table with the entries given in the fields of a screen ?...a procedure-wise explanation would be very helpful.
Thank you.
Moderator message: sorry, no beginner forums here, please search for available information or attend training.
locked by: Thomas Zloch on Aug 12, 2010 3:16 PM -
Updating database table from co11n transaction ?
I got a requirement to add two new addional fields and want to save it in the standard table for reporting purpose. I follwed the steps like :
1. I created new fields in the table AFRU using appending struture. and activated it using se14.
2. I created a project and entered the enhancment (CONFPP07) and i created the screen-exit. then i declared thse two fields in the include : ZXCOFTOP. once i activated the screen exit it appeared in the CO11N TCODE but when i enter some values in this fields , its getting stored in the variable but i dont know how to store this value in the table AFRU .
3. for updating i used the exit CONFPP05 and my would be like AFRUD_TAB-ZZSHIF = CAPTAIN.
but the problem is its not getting updated in the database table AFRU.
should i have to use module ...endmodule in ( SAPLCORU_S - 900 screen , exit : CONFPP07 ) and write code... , like the we follow
for ztransaction or how should i solve this issue ?So, according to your code, it means that :
1) your screen field is WA_AFRUD-ZZSHIF
2) WA_AFRUD is declared as global (in ZXCOFTOP)
Is that true?
In PAI: EXIT_SAPLCORU_S_101, you should only do:
move wa_afrud-zzshif to es_afrud-zzshif.
In Exit : EXIT_SAPLCORF_105, you have to replace 'A'
LOOP AT AFRUD_TAB.
AFRUD_TAB-ZZSHIF = *wa_afrud-zzshif.* "'A'
MODIFY AFRUD_TAB.
ENDLOOP.
Note that LOOP AT is problable not the good coding (I think that this exit has to remain empty), it was just a test to check it works
Did you think to activate your project in CMOD? (you have to activate both project, and the exits)
Are you sure your exit is called. Did you debug it?
See also Note 12831 (program SAPRSMODCHECK) to check there is no problem between project/exits
Edited by: Sandra Rossi on Oct 17, 2008 6:59 PM -
Updating database table from co11n ?
I have added two fields in transaction co11n.....now i want to store these data in the database table .i have used the exit CONFPP07.....where and how should i write the code...can everyone give me some tips to do this ?
Hi,
You have to write the code in the below func module exits:
EXIT_SAPLCORU_S_100 : Transfer Data from SAPLCORU_S to Customer-Defined Screen
Use just move-corresponding <Func Module Paramters> To <Include strucutre of your table wherre customer fields are appended>
EXIT_SAPLCORU_S_101 : Return Data from Customer-Defined Screen to SAPLCORU_S
Use just move-corresponding ES_AFRUD To screen fields
Regards
Shiva -
Hi,
My requirement is to update the table EBAN(Purchase Requisition). Let us suppose that there are 3 items in the purchase requisition. If I make any changes to any of the item, the other two items need to be updated with the same changes. I am using a MODIFY....FROM <Internal Table> statement to update the changes in the database,
Now the problem is if I am making any changes in the 3rd item and press save, the database gets updated for 2nd and 3rd item only but the 1st item is not modified in the database.
If I make changes to the 1st item, then the modifications are done to 1st, 2nd and 3rd item and is working fine. The problem is when I make changes to 2nd or 3rd item then the 1st item does not get updated. I tried using update statement, locking table EBAN using ENQUEUE_E_TABLE but nothing worked.
I tried to use MODIFY...FROM <Workarea> inside a loop but it didn't work.
Kindly suggest.
Regards,
Amit BeheraHi
After modifying u append that values work area to internal table. -
Updating database tables.
hii,
i worked on it and got the selected data into internal table now could you tell me the exact code to update the datbase table with this data in this scenario : i have two fields in databse tabel one being primary key and against which every time i have to update second field from the value selected by user.
please tell me the exact code to update the database table from this internal table.hi,
its abap coding only.
use insert, update or modify statement.
i.e
insert table ztable from itab.
but it is advisable do not use these statement directly,
You can create Perform on commit. and use FM in update task
Yogesh N
Edited by: Yogesh N on Aug 25, 2008 6:15 AM -
Hi,
I am trying to use class CL_ALV_CHANGED_DATA_PROTOCOL to update a database table from an ALV grid.
I have used program BCALV_EDIT_04 as an example.
I am able to successfully processed inserted or deleted lines using the attributes
MT_DELETED_ROWS
MT_INSERTED_ROWS
but I also want to process modified lines.
I was just wondering whether anyone out there has some example code for this.
I can see that there are the following attributes available
MT_MOD_CELLS
MP_MOD_ROWS.
I would ideally like to use MP_MOD_ROWS rather than MT_MOD_CELLS but it is not clear to me what type MP_MOD_ROWS is.
If anyone has any example code for this sort of thing, please let me know.
Thanks,
Rubyhi Ruby,
Yes we can use that *data reference variable *.
It is a variable( something comparable to a pointer ) that points to a int table( table with changed contents )
which ll be created at run-time based on the data type ot the internal table that we pass to the parameter it_outtab of method set_table_for_first_display ...
assign er_data_changed->mp_mod_rows->* to a field-symbol and use it...
Check the below code for example -> method refresh_changed_data
screen flow logic.
PROCESS BEFORE OUTPUT.
MODULE pbo.
PROCESS AFTER INPUT.
MODULE pai.
main program.
* CLASS lcl_event_responder DEFINITION *
CLASS lcl_event_responder DEFINITION.
PUBLIC SECTION.
DATA : ls_changed_cell TYPE lvc_s_modi,
lv_language TYPE spras..
METHODS refresh_changed_data FOR EVENT data_changed
OF cl_gui_alv_grid
IMPORTING er_data_changed
e_ucomm.
ENDCLASS. "event_responder DEFINITION
TYPES tt_makt TYPE STANDARD TABLE OF makt.
DATA: go_handler TYPE REF TO lcl_event_responder,
go_grid TYPE REF TO cl_gui_alv_grid,
gt_fieldcat TYPE lvc_t_fcat,
gv_language TYPE spras VALUE 'E',
gt_outtab TYPE tt_makt,
gs_tableline TYPE LINE OF tt_makt.
FIELD-SYMBOLS : <changed_rows> TYPE tt_makt.
CALL SCREEN 100.
* MODULE PBO OUTPUT *
MODULE pbo OUTPUT.
SET PF-STATUS 'BASIC'.
PERFORM create_and_init_alv CHANGING gt_outtab[]
gt_fieldcat.
ENDMODULE. "pbo OUTPUT
* MODULE PAI INPUT *
MODULE pai INPUT.
LEAVE PROGRAM.
ENDMODULE. "pai INPUT
FORM create_and_init_alv CHANGING pt_outtab LIKE gt_outtab[]
pt_fieldcat TYPE lvc_t_fcat.
CHECK go_grid IS NOT BOUND.
CREATE OBJECT go_grid
EXPORTING
i_parent = cl_gui_container=>default_screen.
PERFORM build_display_table.
PERFORM build_fieldcat CHANGING pt_fieldcat.
go_grid->set_table_for_first_display( CHANGING it_fieldcatalog = pt_fieldcat
it_outtab = pt_outtab ).
go_grid->set_ready_for_input( 1 ).
* raises the 'data_changed' event when we select another cell/any action after changing the data
go_grid->register_edit_event( EXPORTING i_event_id = cl_gui_alv_grid=>mc_evt_enter ).
CREATE OBJECT go_handler.
SET HANDLER go_handler->refresh_changed_data FOR go_grid.
ENDFORM. "CREATE_AND_INIT_ALV
FORM build_display_table.
FREE gt_outtab.
SELECT * FROM makt UP TO 20 ROWS INTO TABLE gt_outtab WHERE spras EQ gv_language.
ENDFORM. "build_display_table
FORM build_fieldcat CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'MAKT'
CHANGING
ct_fieldcat = pt_fieldcat.
LOOP AT pt_fieldcat INTO ls_fcat.
ls_fcat-edit = abap_true.
MODIFY pt_fieldcat FROM ls_fcat.
ENDLOOP.
ENDFORM. "build_fieldcat
* CLASS event_responder IMPLEMENTATION *
CLASS lcl_event_responder IMPLEMENTATION.
METHOD refresh_changed_data.
ASSIGN er_data_changed->mp_mod_rows->* TO <changed_rows>.
LOOP AT <changed_rows> INTO gs_tableline.
BREAK-POINT.
ENDLOOP.
ENDMETHOD. "click
ENDCLASS. "event_responder IMPLEMENTATION
Cheers,
Jose.
Maybe you are looking for
-
Airport or ISP/Modem problem?
Hello, I bought my Airport Express 802.11n base station about a month ago, and since then I have gone through a lot of customer service hotlines (Apple and ISP) trying to figure out what is/are causing my problems. The problems are (In order of most
-
Mac pro DVD Writer + DVD Studio pro + Toshiba HD-EP10 - HD DVD Player !!
Hi there.. I tried to make a short HD project in 4.7GB DVD by Mac pro Standard DVD Writer and i tried to play it in Toshiba HD-EP10 - HD DVD Player ( it gives msg ... the disc not contained DVD format and cannot be played ) so what is the mistake whi
-
Outgoing Payment Issues - No matching records found (ODBC - 2028)
Hi Experts, I am trying to create the add-on which automatically create Check payment against the vendor for the AP invoice and i am getting the issue, "No matching records found (ODBC - 2028)". To know the exact reason of the issue i hardcode invoi
-
Need help on integrating htmldb with asp/jsp/php
Hello there, we have a few existing htmldb applications running at the moment, and now we would like to develop some asp/jsp/php applications. However there is one issue we still haven't solved yet, which is the SESSION(Login) problem. We don't know
-
I need to know the file I need to delete in order to stop getting a message that says I have a newer version installed when I try and reinstall my printer. I have deleted all HP software on my computer and I still get the message. Please help.