Modify Database table
Hi,
I need to modify a single field in a custom database table for more than 1 record.
I need to update from the values in the internal table which has only that single field.
how to acheive this ..Pls help
Thanks
hi delcare work area wa and use
MODIFY dbtab FROM wa statement.
Similar Messages
-
Modifying database table in ALV Grid
Hi all.
I need to be able to modify the database table in ALV Grid. Here's the code. The database table, that is displayed is 'zng_so_head', it's internal table is 'res_tab'. In the program i tried to create a button 'CHANGE' on the ALV-toolbar, but when executing the program there's no such button (why?). What code, screens, screen elements, etc. should be added to this program to provide a possibility of changing data of the database table 'zng_so_head' (i mean changing existing data, adding new lines and saving changes)?
CODE:
& Report ZNG_ALV_TC_EDIT_SIMP&
REPORT ZNG_ALV_TC_EDIT_SIMP.
*-- GLOBAL DATA DECLARATIONS FOR ALV
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
DATA gt_fieldcat TYPE lvc_t_fcat.
DATA gs_layout TYPE lvc_s_layo.
TABLES: zng_so_head, zng_cust, zng_vendors.
*-- STRUCTURE OF INTERNAL TABLE
TYPES: BEGIN OF in_tab,
so_num TYPE zng_so_head-so_num, "type numc
vend_num TYPE zng_so_head-vend_num, "type numc
cust_num TYPE zng_so_head-cust_num, "type numc
so_date TYPE zng_so_head-so_date, "type dats
END OF in_tab.
*-- INTERNAL TABLE HOLDING LIST DATA
DATA res_tab TYPE TABLE OF in_tab WITH HEADER LINE.
*-- FILLING IN INTERNAL TABLE
SELECT hso_num hvend_num hcust_num hso_date
INTO TABLE res_tab FROM zng_so_head AS h.
*& Form prepare_field_catalog
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
ls_fcat-fieldname = 'SO_NUM'.
ls_fcat-inttype = 'N'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'SO_NUM'.
ls_fcat-seltext = 'SO_NUM'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'VEND_NUM'.
ls_fcat-inttype = 'N'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'VEND_NUM'.
ls_fcat-seltext = 'VEND_NUM'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'CUST_NUM'.
ls_fcat-inttype = 'N'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'CUST_NUM'.
ls_fcat-seltext = 'CUST_NUM'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'SO_DATE'.
ls_fcat-inttype = 'D'.
ls_fcat-ref_table = 'zng_so_head'.
ls_fcat-outputlen = '12'.
ls_fcat-coltext = 'SO_DATE'.
ls_fcat-seltext = 'SO_DATE'.
APPEND ls_fcat TO pt_fieldcat.
ENDFORM. "prepare_field_catalog
*& Form display_alv
FORM display_alv.
IF gr_alvgrid IS INITIAL.
CREATE OBJECT gr_ccontainer
EXPORTING container_name = gc_custom_control_name.
CREATE OBJECT gr_alvgrid
EXPORTING i_parent = gr_ccontainer.
PERFORM prepare_field_catalog CHANGING gt_fieldcat.
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = res_tab[]
it_fieldcatalog = gt_fieldcat.
ELSE.
CALL METHOD gr_alvgrid->refresh_table_display.
ENDIF.
ENDFORM. "display_alv
CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive.
ENDCLASS. "lcl_event_handler DEFINITION
CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
MOVE 3 TO ls_toolbar-butn_type.
APPEND ls_toolbar TO e_object->mt_toolbar.
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'change' TO ls_toolbar-quickinfo.
MOVE 'change' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA object_ref TYPE REF TO lcl_event_handler.
START-OF-SELECTION.
CALL SCREEN 100.
MODULE STATUS_0100 OUTPUT
MODULE display_alv OUTPUT.
SET PF-STATUS 'SCREEN_100'.
PERFORM display_alv.
CREATE OBJECT object_ref.
SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
ENDMODULE. "display_alv OUTPUT
MODULE USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK' OR
sy-ucomm = 'EXIT' OR
sy-ucomm = 'CANCEL'.
LEAVE PROGRAM.
ELSE.
CALL METHOD object_ref->handle_toolbar.
ENDIF.
ENDMODULE. "status_0100 INPUT
END OF CODE
Thanks all.Hi,
For the button on the toolbar,here is the code:
CLASS lcl_eh IMPLEMENTATION.
*METHOD: HANDLE_TOOLBAR
*DESCRIPTION: This method provides the necessary detail required to
create an extra button in the toolbar.
METHOD handle_toolbar.
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE 0 TO ls_toolbar-butn_type.
MOVE CHANGETO ls_toolbar-text.
MOVE 'ICON_DETAIL' TO ls_toolbar-icon.
MOVE 'CHANGE' TO ls_toolbar-quickinfo.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar
Also,if you are using the CHANGE button to record changes in the DB,then in the local class that you have defined,you should use the following method and then write the logic:
*METHOD: HANDLE_USER_COMMAND
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'CHANGE'.
CHECK_CHANGED_DATA
REFRESH_TABLE_DISPLAY
Now call the methods that i have given in my previous post.This function code will be checked at the event you click the button 'CHANGE'.I think you have done this in an ELSE condition in the PAI of the screen.Not too sure if it works in the PAI.
Regards,
Beejal
**Reward if this helps -
Modify database table from internal table
Hi All,
I need to update database table from internal table which is having around 30000 records.
I am using MODIFY tabname FROM TABLE int_tabname...
Using this statement, I can modify the databse records very well. But user has some additional requirement.
He wants that the table should be modified from the internal table and after modification we should have the erroneous records to be displayed if any.
e.g. if 1500 records out of 30000 are erroneous then only 28500 records should be updated and 1500 records should be displayed as erroneous records so that the user can correct them and use them again for executing the program.
Is there any FM which imports the database table name and internal table, modifies the database and exports an internal tanle with erroneous records?
Any help will be appriciated,
Regards,
NehaHi
modifying datbase table useing internal table
<b>advises</b> before updating this datbase table plz lock that table to avoid incosistency
write the logic for modifying
Modify the database table as per new dunning procedure
MODIFY fkkvkp FROM TABLE lt_fkkvkp .
and finally unlock the table
<b>example</b>
*To lock table for further operations
constants: lc_tabname TYPE rstable-tabname VALUE 'FKKVKP' . "FKKVKP
CALL FUNCTION 'ENQUEUE_E_TABLE'
EXPORTING
tabname = lc_tabname
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc EQ 0.
To fetch all the contract accounts for customers of the segment
Households/SME.
PERFORM fetch_contract_accounts using lc_tabname .
ENDIF. " IF sy-subrc EQ 0.
*wrote the logic
Modify the database table as per new dunning procedure from internal table
MODIFY fkkvkp FROM TABLE lt_fkkvkp .
*unlock the tbale
CALL FUNCTION 'DEQUEUE_E_TABLE'
EXPORTING
TABNAME = uc_tabname .
<b>Reward if usefull</b> -
Modifying database table through ALV-Grid
Hi all.
I need to modify a database table (ZNG_SO_HEAD) by entering data in ALV-Grid, which displays its internal table (exact copy of ZNG_SO_HEAD), and clicking the button ('CHANGE') on the ALV-toolbar. The ALV is already editable, the button already exists. Here is the code. After changing data in ALV and clicking 'CHANGE' on the toolbar the database table ZNG_SO_HEAD remains unchangeable, but i need to change data in it somehow.
Thanks all.
REPORT zng_alv_tc_edit_simp.
*-- GLOBAL DATA DECLARATIONS FOR ALV
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
DATA gt_fieldcat TYPE lvc_t_fcat.
DATA gs_layout TYPE lvc_s_layo.
TABLES: zng_so_head, zng_cust, zng_vendors.
*-- STRUCTURE OF INTERNAL TABLE
TYPES: BEGIN OF in_tab,
mandt TYPE zng_so_head-mandt,
so_num TYPE zng_so_head-so_num, "type numc
vend_num TYPE zng_so_head-vend_num, "type numc
cust_num TYPE zng_so_head-cust_num, "type numc
so_date TYPE zng_so_head-so_date, "type dats
END OF in_tab.
*-- INTERNAL TABLE HOLDING LIST DATA
DATA res_tab TYPE TABLE OF in_tab WITH HEADER LINE.
*DATA wa_res_tab LIKE LINE OF res_tab.
*-- FILLING IN INTERNAL TABLE
SELECT h~mandt h~so_num h~vend_num h~cust_num h~so_date
INTO TABLE res_tab FROM zng_so_head AS h.
* CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
METHODS:
* to add new functional buttons to the alv toolbar
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive,
* to implement user commands
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_event_handler DEFINITION
* CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
DATA: ls_toolbar TYPE stb_button.
MOVE 3 TO ls_toolbar-butn_type.
CLEAR ls_toolbar.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE icon_change TO ls_toolbar-icon.
MOVE 'change' TO ls_toolbar-quickinfo.
MOVE 'change' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar>
METHOD handle_user_command.
DATA:l_valid TYPE c.
CASE e_ucomm.
WHEN 'CHANGE'.
CALL METHOD gr_alvgrid->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid = 'X'.
MODIFY zng_so_head FROM res_tab.
ENDIF.
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_handler IMPLEMENTATION
DATA object_ref TYPE REF TO lcl_event_handler.
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
>>>>>>done correctly>>>>>>>>>
FORM display_alv.
>>>>>>done correctly>>>>>>>>>
START-OF-SELECTION.
CALL SCREEN 100.
* MODULE STATUS_0100 OUTPUT
MODULE display_alv OUTPUT.
SET PF-STATUS 'SCREEN_100'.
PERFORM display_alv.
CREATE OBJECT object_ref.
SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
SET HANDLER object_ref->handle_user_command FOR gr_alvgrid.
ENDMODULE. "display_alv OUTPUT
* MODULE USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK' OR
sy-ucomm = 'EXIT' OR
sy-ucomm = 'CANCEL'.
LEAVE PROGRAM.
ELSE.
CALL METHOD object_ref->handle_toolbar.
CALL METHOD object_ref->handle_user_command.
ENDIF.
ENDMODULE.Hello Nikolai,
I have written a sample code taking care of all the requirements(button in the toolbar and changes saved in database).I have used SPFLI table and the internal table i_spfli.This code works and the change is also made in the database table.
REPORT SAMPLE.
*-- GLOBAL DATA DECLARATIONS FOR ALV
DATA gr_alvgrid TYPE REF TO cl_gui_alv_grid.
DATA gc_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
DATA gr_ccontainer TYPE REF TO cl_gui_custom_container.
DATA gt_fieldcat TYPE lvc_t_fcat.
DATA gs_layout TYPE lvc_s_layo.
Data:i_spfli type table of spfli.
CLASS lcl_event_handler DEFINITION
CLASS lcl_event_handler DEFINITION.
PUBLIC SECTION.
DATA:l_valid TYPE c.
DATA: ls_toolbar TYPE stb_button.
METHODS:
to add new functional buttons to the alv toolbar
handle_toolbar
FOR EVENT toolbar OF cl_gui_alv_grid
IMPORTING e_object
e_interactive,
to implement user commands
handle_user_command
FOR EVENT user_command OF cl_gui_alv_grid
IMPORTING e_ucomm.
ENDCLASS. "lcl_event_handler DEFINITION
CLASS lcl_event_handler IMPLEMENTATION
CLASS lcl_event_handler IMPLEMENTATION.
METHOD handle_toolbar.
CLEAR ls_toolbar.
MOVE 0 TO ls_toolbar-butn_type.
MOVE 'CHANGE' TO ls_toolbar-function.
MOVE 'ICON_CHANGE' TO ls_toolbar-icon.
MOVE 'change' TO ls_toolbar-quickinfo.
MOVE 'change' TO ls_toolbar-text.
APPEND ls_toolbar TO e_object->mt_toolbar.
ENDMETHOD. "handle_toolbar>
METHOD handle_user_command.
CASE e_ucomm.
WHEN 'CHANGE'.
CALL METHOD gr_alvgrid->check_changed_data
IMPORTING
e_valid = l_valid.
IF l_valid = 'X'.
MODIFY spfli FROM table i_spfli.
ENDIF.
ENDCASE.
ENDMETHOD. "handle_user_command
ENDCLASS. "lcl_event_handler IMPLEMENTATION
START-OF-SELECTION.
DATA object_ref TYPE REF TO lcl_event_handler.
select * from spfli into table i_spfli.
Call screen 100.
MODULE STATUS_0100 OUTPUT
MODULE STATUS_0100 OUTPUT.
SET PF-STATUS 'SCREEN_100'.
PERFORM display_alv.
ENDMODULE. "display_alv OUTPUT
MODULE USER_COMMAND_0100 INPUT
MODULE user_command_0100 INPUT.
IF sy-ucomm = 'BACK' OR
sy-ucomm = 'EXIT' OR
sy-ucomm = 'CANCEL'.
LEAVE PROGRAM.
ENDIF.
ENDMODULE.
*& Form display_alv
FORM display_alv.
*IF gr_alvgrid IS INITIAL.
CREATE OBJECT gr_ccontainer
EXPORTING container_name = gc_custom_control_name.
CREATE OBJECT gr_alvgrid
EXPORTING i_parent = gr_ccontainer.
PERFORM prepare_field_catalog CHANGING gt_fieldcat.
CREATE OBJECT object_ref.
SET HANDLER object_ref->handle_toolbar FOR gr_alvgrid.
SET HANDLER object_ref->handle_user_command FOR gr_alvgrid.
CALL METHOD gr_alvgrid->set_table_for_first_display
EXPORTING
is_layout = gs_layout
CHANGING
it_outtab = i_spfli[]
it_fieldcatalog = gt_fieldcat.
ENDFORM. "display_alv
*& Form prepare_field_catalog
FORM prepare_field_catalog CHANGING pt_fieldcat TYPE lvc_t_fcat.
DATA ls_fcat TYPE lvc_s_fcat.
ls_fcat-fieldname = 'CARRID'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'CONNID'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'DEPTIME'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
ls_fcat-fieldname = 'ARRTIME'.
ls_fcat-ref_table = 'SPFLI'.
ls_fcat-edit = 'X'.
APPEND ls_fcat TO pt_fieldcat.
CLEAR ls_fcat.
endform.
Hope this helps.
Regards,
Beejal -
How to modify DataBase Table with an internal Table
Hi, Friends.
I am coping Data from a Database table to an internal table after modifying data in the internal table I want to modify the db table according to the modification in the internal table. can some one help me out in this way, i am doing this modification in Table Control in Screen programing.
My Code is as follow.
MODULE zfsl_stinf_tc_init OUTPUT.
IF tc_copy IS INITIAL.
SELECT * INTO CORRESPONDING FIELDS OF TABLE it_zfsl_stinf FROM zfsl_stinf.
tc_copy = 'X'.
REFRESH CONTROL 'TC_FOR_ZFSL_STINF' FROM SCREEN '0001'.
ENDIF.
ENDMODULE. " zfsl_stinf_init OUTPUT
*& Module zfsl_stinf_tc_move OUTPUT
text
MODULE zfsl_stinf_tc_move OUTPUT.
MOVE-CORRESPONDING wa_it_zfsl_stinf TO zfsl_stinf.
ENDMODULE. " zfsl_stinf_tc_move OUTPUT
*& Module STATUS_0001 OUTPUT
text
MODULE status_0001 OUTPUT.
SET PF-STATUS 'ZFSL_SCREEN_1ONLY'.
SET TITLEBAR 'xxx'.
ENDMODULE. " STATUS_0001 OUTPUT
*& Module zfsl_stinf_tc_modify INPUT
text
MODULE zfsl_stinf_tc_modify INPUT.
MOVE-CORRESPONDING zfsl_stinf TO wa_it_zfsl_stinf.
MODIFY it_zfsl_stinf FROM wa_it_zfsl_stinf INDEX tc_for_zfsl_stinf-current_line.
_*"" here i have the modified internal table " it_zfsl_stinf "*_
ENDMODULE. " zfsl_stinf_tc_modify INPUT
Kind regards,
FaisalHi
Here you are modifying your dbtable in module pool programming
so better to use work area to modify the database table
example:
data: itab type table of zfsl_stinf .
data: wa_itab type itab.
select single * from zfsl_stinf INTO itab WHERE <condition>
(pass your values to wa_itab.)
modify zfsl_stinf from values of wa_itab.
Regards
Srinivasu -
How to connect infosets & database tables
Hi,
I have connected R/3 system through Crystral report, Now Server name is coming in the list. But am not seen any infosets instead of i found I & Q under my Server name,
Am now to configure this Crystall repport.
When I connect the server it asking the client, username & password. I given all the required inputs. My user ID have SAP_ALL authorization.
Can you explain in brief steps or give me any configuation document link.
Kindly help me.
Thanks
Jibin.Hi,
It is possible to modify database table in bulk.
You can use the following syntax:
=====
Modify dbtab FROM wa -
> To modifiy single record
Modify dbtab FROM TABLE itab -
> To modify bulk records.
Update dbtab FROM wa -
> To modifiy single record
Update dbtab FROM TABLE itab -
> To modify bulk records.
=====
Remember that update command update existing records where as modify comand updates existing records and if the record does not exists, it inserts the record.
Regards,
Saurabh -
hi all
I have a sceen if i will enter the value and press the save button it will add all the value into the database table.
I am doing this using dialog programming.
if anybody have face this prob to upgrade the database table than it would help me a lot
thanks a lot to all
mrutyunHey Hi
For that first either you have to declare internal table or you can use database table work area in the abap editor
after that you need to declare all 5 fields with same name in abap as well as screen painter.
now in the PAI of the screen you have to handle all your 3 pushbuttons with the help of fcoded assigned to them.
the case may be like this
PROCESS AFTER INPUT
CASE OK-CODE.
WHEN 'CREATE'.
ITABNAME-FNAME1 = SCREEN FIELD NAME1
ITABNAME-FNAME2 = SCREEN FIELD NAME2
ITABNAME-FNAME3 = SCREEN FIELD NAME3
ITABNAME-FNAME4 = SCREEN FIELD NAME4
ITABNAME-FNAME5 = SCREEN FIELD NAME5
INSERT <DATABASE TABLE> FROM ITAB.
WHEN 'DISPLAY'.
SELECT SINGLE * FROM DBTAB INTO ITAB.
SCREEN FIELD NAME1 = ITABNAME-FNAME1
SCREEN FIELD NAME2 = ITABNAME-FNAME2 =
SCREEN FIELD NAME3 = ITABNAME-FNAME3
SCREEN FIELD NAME4 = ITABNAME-FNAME4
SCREEN FIELD NAME5 = ITABNAME-FNAME5.
WHEN 'CHANGE'.
ITABNAME-FNAME1 = SCREEN FIELD NAME1
ITABNAME-FNAME2 = SCREEN FIELD NAME2
ITABNAME-FNAME3 = SCREEN FIELD NAME3
ITABNAME-FNAME4 = SCREEN FIELD NAME4
ITABNAME-FNAME5 = SCREEN FIELD NAME5
MODIFY <DATABASE TABLE> FROM ITAB.
ENDCASE.
THANKS -
To modify a field in a database table based record identification by primar
hi
i want to to modify a field in a database table based record identification by primary key filed and two more fields
ie customer (primary key
i want to modify record from intenal table the record existing with primary key field customer
the status field needs to be mofied as " value rolled"
the below code is happening
loop at it_record into wa_Record
wa_inv-customer (primary key) = wa_Record=custome
wa_inv-date = wa_Record-date
...so one
append wa_inv to it_invest
clear wa_inv
endloop.
if not it_invest is initial
modify TABle1 ( this table is data base table which needs to be mofified) based on the primary key field
and also date field and status field which is not primary key.
regards
aroraHi there.
Your requirement is to update a Z Database table from your internal table, right? You have several options:
LOOP AT it_invest INTO wa_inv.
UPDATE dbtable
SET date = wa_inv-date
WHERE prim_key = wa_inv-prim_key
AND any_field = wa_inv-any_field.
ENDLOOP.
or
LOOP AT it_invest INTO wa_inv.
UPDATE dbtable FROM wa_inv. "if wa_inv of same type of dbtable
ENDLOOP.
In the first example, I wrote any field because you can update dbase table, filtering for fields that don't belong to the primary key. However, remember that you will change all records that respect the key you used (so, in your case, use the primary key).
Regards.
Valter Oliveira. -
How to modify or put entry in a particular field of a database table
i want to to modify a field in a database table record identification by primary key fileds
the situatio is like this
there are two primay key in database table
customer number PK
status PK
date
and third field which i want to modify is customer part number.
based on condition that
database table1-cuspip = wa_record-cuspip.
database table1-status <> wa_record-status
and database table-date = wa_record-date
if above is true a particular field the database table for that record
ie customer_part_number = 'FAiled'.
loop at it_record into wa_Record
endloop.
please suggest how to modify the database table record if the avove condition is tru and please give me full working code
regards
AroraDear Nishant,
Use UPDATE function for updating the customer part number.
But please do mention the database table and the keys used for update.
if en entry already exists with the key then the Entry will fail so use MODIFY statement to modify the Consumber Part Number with the specificed keys and transport the modified customer part number and then do COMMIT the changed entry to database.
Hope this helps you in some way.
Encourage others to answer you queries by suitably rewarding them.
Thanks
Venugopal -
Modify the standard records in database table
hi folks,
could u say me , how to modify the standard records(values) in database table.
For example in VBAP is one field like ZWERT(target value) , I wnat to modify the values of this field .
THANKS
KUMARHi,
It's not advisable to modify the standard tables through program. If you want you can do using MODIFY.
MODIFY database_table FROM TABLE itab.
Thanks,
Sri. -
hi ,
can we use modify command in database table .(not update command)
if yes means how to use it . give syntax ..
i want to modify the database table based on internal table i.e
how to do this .
Regards,
kumarHello Kumar,
Always use MODIFY command rather than using INSERT or UPDATE.
When u r using MODIFY command and u can able to update a record and insert a record inside the table.
MODIFY - Change a database table
Variants:
1. MODIFY dbtab. or
MODIFY *dbtab. or
MODIFY (dbtabname) ... ..
2. MODIFY dbtab FROM TABLE itab. or
MODIFY (dbtabname) FROM TABLE itab.
3. MODIFY dbtab VERSION vers. or
MODIFY *dbtab VERSION vers.
Effect
Inserts new lines or updates existing lines in a database table (s. relational database). If a line with the specified primary key already exists, an UPDATE is executed. Otherwise, an INSERT is performed. You can specify the name of the database table either in the program itself in the form MODIFY dbtab ... or at runtime as the contents of the field dbtabname in the form MODIFY (dbtabname) ... . In both cases, the database table must be defined in the ABAP Dictionary. Normally, records are inserted or updated only in the current client. Data can only be inserted or updated using a view, if the view refers to a single table and was created in the ABAP Dictionary with the maintenance status "No restriction".
MODIFY belongs to the Open SQL command set.
When the statement has been executed, the system field SY-DBCNT contains the number of edited lines.
The return code is set as follows:
SY-SUBRC = 0:
All lines were successfully inserted or updated.
SY-SUBRC = 4:
One or more lines could not be inserted or updated.
Notes
You cannot modify a line if there is already a line in the table with identical key field values in a UNIQUE index.
Automatic definition of INSERT and UPDATE is expensive. You should therefore use MODIFY only if you cannot define the INSERT and UPDATE cases yourself in the program.
Since the MODIFY statement does not perform authority checks, you have to program them yourself.
Adding or changing lines with the MODIFY command is only completed after a database commit (see LUW) has been performed. Before the database commit has been performed, any database changes can be reversed with a database rollback (see Programming transactions).
Synchronization of simultanous accesses by several users to the same set of data cannot be guaranteed exclusively with the lock mechanism of the database system. In several cases, you are recommended to use the SAP lock mechanism.
Variant 1
MODIFY dbtab. or
MODIFY *dbtab. or
MODIFY (dbtabname) ... .
Additions:
1. ... FROM wa
2. ... CLIENT SPECIFIED
See Short forms not allowed and * work areas not allowed.
Effect
Inserts a new line or updates an existing line in a database table. If you specify the name of the database table yourself, the primary key for identifying the line to be inserted or updated and the relevant values are taken from the table work area dbtab or *dbtab (see TABLES). If you specify the name of the database table directly, the program must contain a corresponding TABLES statement. If the name of the database table is not determined until runtime, you need to use the addition ... FROM wa.
Example
Insert or change data of the customer Robinson in the current client:
TABLES SCUSTOM.
SCUSTOM-ID = '12400177'.
SCUSTOM-NAME = 'Robinson'.
SCUSTOM-POSTCODE = '69542'.
SCUSTOM-CITY = 'Heidelberg'.
SCUSTOM-CUSTTYPE = 'P'.
SCUSTOM-DISCOUNT = '003'.
SCUSTOM-TELEPHONE = '06201/44889'.
MODIFY SCUSTOM.
Addition 1
... FROM wa
Effect
The values for the line to be inserted or updated are not taken from the table work area dbtab, but from the explicitly specified work area wa. When doing this, the data is read from left to right according to the structure of the table work area dbtab (see TABLES). Since the structure of wa is not taken into account, the work area wa must be at least as wide (see DATA) as the table work area dbtab and the alignment of the work area wa must correspond to the alignment of the table work area. Otherwise, a runtime error occurs.
Note
If a work area is not explicitly specified, the values for the line to be inserted or updated are also taken from the table work area dbtab if the statement is in a FORM or FUNCTION where the table work area is stored in a formal parameter or local variable of the same name.
Addition 2
... CLIENT SPECIFIED
Effect
Switches off automatic client handling. This allows you to edit data across all clients even when dealing with client-specific tables. The client field is treated like a normal table field that can be programmed to accept values in the table work area dbtab or *dbtab where the line to be edited occurs.
The addition CLIENT SPECIFIED must be specified immediately after the name of the database table.
Variant 2
MODIFY dbtab FROM TABLE itab.or MODIFY (dbtabname) FROM TABLE itab.
Addition:
... CLIENT SPECIFIED
Effect
Mass modify: Inserts new lines or updates existing lines of a database table. The primary keys for identifying the lines to be inserted or updated and the relevant values are taken from the internal table itab. The lines of the internal table itab must satisfy the same conditions as the work area wa in addition 1 to variant 1.
Note
If the internal table itab is empty, SY-SUBRC and SY-DBCNT are set to 0.
Addition
... CLIENT SPECIFIED
Effect
As for variant 1.
Variant 3
MODIFY dbtab VERSION vers. or MODIFY *dbtab VERSION vers.
This variant is not allowed in an ABAP Objects context. See VERSION addition not allowed.
Note
This variant is obsolete.
Effect
Inserts a new line or updates an existing line in a database table, the name of which is taken from the field vers at runtime. If no line exists with the specified primary key, an INSERT is executed. Otherwise, an UPDATE is performed. The database table must be defined in the ABAP/4 Dictionary and its name must conform to the naming conventions for R/2 ATAB tables. These stipulate that the name must begin with 'T' and may contain up to four further characters. The field vers must contain the table name without the leading 'T'. Only lines in the current client are inserted or updated. The line to be inserted is taken from the statically specified table work area dbtab or *dbtab.
SY-SUBRC is set to 0 if the line is successfully inserted or updated. SY-SUBRC <> 0 is not possible since any other result causes a runtime error.
Additional help
Inserting or Changing Table Records
If useful reward.
Vasanth -
Regarding modifying database from internal table
Hi ABAP Experts,
I am facing an issue regarding modifying DB table from itab.
All the records of itab are not getting reflected in DB table using Modify statement.
Syntax is as follows -
Locking DB table using enque FM
MODIFY abc FROM TABLE i_abc.
Unlocking DB table using deques FM
Please suggest what could be wrong with this. Helpful suggestion will be appreciated.
Thanks in adv,
AkashHi,
First Delete entries from the table(hope it is a custom table),
for example
DELETE FROM <DatabaseTable name> WHERE <primarykey = 'somevalue'>.
'After deleting those records.....then use insert statement
IF sy-subrc = 0.
INSERT <DatabaseTable name> FROM TABLE <InternalTable name> ACCEPTING DUPLICATE KEYS.
ENDIF.
Thanks & REgards -
Reg:How to delete the column in table control also from database table.
Hi Experts,
Once again thank u all for giving the responses.
one more doubt is how to delete the columns of table control and also the record shold delete from ztable.
With Regards,
Saroja.P.Hi,
If you want to delete the rows in the table control and simultaneously delete it from the database table, then you can implement a 'DELETE' functionality specific to your table control. Have a MARK field (you will find that in the screen attributes of the table control -> give a name for the MARK field, you will find an additional MARK column at the beginning of your table control). You can check whatever rows you want to delete from the table control, call the delete module.
"This portion of code inside the LOOP...ENDLOOP.
IF sy-ucomm eq 'F_DELETE'.
gt_itab2-check = mark. " Store the MARK field status into your internal table's correspoding field 'check'
MODIFY gt_itab INDEX tabcontrol-current_line.
ENDIF.
iF sy-ucomm eq 'DELETE1'.
DELETE gt_itab WHERE check eq 'X'. "Your internal table does not have rows that you want to delete
ENDIF.
Now you can modify your database table using the MODIFY statement.
MODIFY ZDB FROM TABLE gt_itab. -
How to change a field of type CHAR of a database table to DATS
Dear ABAP experts,
I have a database table: ZLT_aztnew with fields M1, M2, K1, K2, A1, A2, P1, P2, S2, D1, D2, STD, BES. All these fields are of type 'Character'. except D2 which is of type DATS. The field D1 is date and is in format DD.MM.YYYY.
I want to convert this field D1 to type DATS so that I can use a date range through 'selection option' to select other data of other fields (M1, M2, K1, K2, A1, A2, P1, P2, S2, D1, STD, BES.) related to field D1 from the database table Zlt_aztnew.
How should I introduce this change (CONVERSION OF D1 CHAR to DATS in the .AZT file upload code itself.
Problem: If I define D1 as Type DATS in database table ZLT_AZTNEW then the UPLOAD fails.
The AZT file upload code is:
Data it_string type stringtab.
Data lv_string type string.
DATA: itab TYPE STANDARD TABLE OF zlt_aztnew.
DATA: wa_tab TYPE zlt_aztnew.
DATA: file_str1 type string.
Data: it_tab TYPE STANDARD TABLE OF file_table,
lw_file LIKE LINE OF it_tab,
gd_subrc TYPE i.
SELECTION-SCREEN begin of block blk with frame title text-100.
SELECTION-SCREEN SKIP 2.
parameters : p_file like rlgrap-filename .
SELECTION-SCREEN end of block blk.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select only Text File'
default_filename = '.azt'
multiselection = 'X'
CHANGING
file_table = it_tab
rc = gd_subrc.
READ TABLE it_tab INTO lw_file INDEX 1.
p_file = lw_file-FILENAME.
Start-of-Selection.
file_str1 = P_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_str1
* filename = '\\10.10.1.92\Volume_1\_projekte\Zeiterfassung-SAP\test.azt'
tables
data_tab = it_string
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT it_string INTO lv_string.
clear wa_tab.
SPLIT lv_string AT ';' INTO wa_tab-M2 wa_tab-k2 wa_tab-A2 wa_tab-P2 wa_tab-S2 wa_tab-D1 wa_tab-STD wa_tab-BES.
Append wa_tab to itab.
Write: sy-uline(120),
/ sy-vline,
2 wa_tab-M2,
11 sy-vline,
13 wa_tab-k2,
25 sy-vline,
27 wa_tab-A2,
32 sy-vline,
34 wa_tab-P2,
39 sy-vline,
41 wa_tab-S2,
46 sy-vline,
48 wa_tab-D1,
60 sy-vline,
62 wa_tab-STD,
72 sy-vline,
74 wa_tab-BES,
120 sy-vline.
ENDLOOP.
DATA: Answer.
UPDATE zlt_aztnew From Table itab.
* INSERT ZLT_aztnew From Table itab accepting duplicate keys.
If sy-subrc NE 0.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TITLEBAR = 'TITLE '
* DIAGNOSE_OBJECT = ' '
text_question = 'Wollen Sie die vorhandenen Inhalte ändern'
TEXT_BUTTON_1 = 'Ja'(001)
* ICON_BUTTON_1 = ' '
TEXT_BUTTON_2 = 'Nein'(002)
* ICON_BUTTON_2 = ' '
DEFAULT_BUTTON = '1'
DISPLAY_CANCEL_BUTTON = 'X'
* USERDEFINED_F1_HELP = ' '
* START_COLUMN = 25
* START_ROW = 6
* POPUP_TYPE =
* IV_QUICKINFO_BUTTON_1 = ' '
* IV_QUICKINFO_BUTTON_2 = ' '
IMPORTING
answer = answer
* TABLES
* PARAMETER =
EXCEPTIONS
TEXT_NOT_FOUND = 1
OTHERS = 2
*IF sy-subrc <> 0.
** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
*ENDIF.
IF Answer = '1'.
WRITE: / 'Die vorhandenen Inhalte war geändernt'.
MODIFY zlt_aztnew From Table itab.
ENDIF.
ENDIF.
TO introduce a date range and pull data from the database table Zlt_AZTNEW--> I wrote the BELOW code SEPARATELY,
but after execution, the error I am getting is: Enter a valid Date (for example, 31.03.2014).
TABLES: ZLT_aztnew.
TYPES: Begin OF ty_AZTN,
M2 TYPE Zlt_AZTNEW-M2,
K2 TYPE Zlt_AZTNEW-K2,
A2 TYPE Zlt_AZTNEW-A2,
P2 TYPE Zlt_AZTNEW-P2,
S2 TYPE Zlt_AZTNEW-S2,
D1 TYPE Zlt_AZTNEW-D1,
STD TYPE Zlt_AZTNEW-STD,
BES TYPE Zlt_AZTNEW-BES,
END OF ty_AZTN.
DATA: gv_datum TYPE d.
DATA: it_aztn TYPE STANDARD TABLE OF ty_aztn with header line.
CALL FUNCTION 'CONVERT_DATE_TO_INTERNAL'
EXPORTING
date_external = zlt_aztnew-D1
* ACCEPT_INITIAL_DATE =
IMPORTING
DATE_INTERNAL = gv_datum
* EXCEPTIONS
* DATE_EXTERNAL_IS_INVALID = 1
* OTHERS = 2
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
SELECT-OPTIONS: s_datum FOR gv_datum.
INITIALIZATION.
s_datum-low = sy-datum.
s_datum-high = sy-datum.
APPEND s_datum.
********** After this further code follows with "SELECT" wherein I want to use the gv_datum as Where condition.
SELECT M2
K2
A2
P2
S2
D1
STD
BES
FROM ZLt_AZTNEW
INTO TABLE it_AZTN
Where D1 = gv_datum.
Please provide me your valuable suggestion to correct any flaw in my code above.
Looking forward for your reply.
Best regards
Chandan KumarDear Rama,
Plz refer the following difference in naming conventions as compared to your suggestion:
it_flat_file --> itab, (internal table for AZT fiel upload and split)
ls_flat_file ---> wa_itab,
Ztable --> Zlt_aztnew2, (Dbase file)
it_ztable ---> it_zlt_aztnew2, (internal table)
ls_ztable --> wa_aztnew2,
I wrote the following code but it is not working. Please also refer the attached screen shot of the database table : ZLT_AZTNEW2.
Data it_string type stringtab.
Data lv_string type string.
DATA: file_str1 type string.
Data: it_tab TYPE STANDARD TABLE OF file_table,
lw_file LIKE LINE OF it_tab,
gd_subrc TYPE i.
TYPES: Begin of Ty_itab,
M2 TYPE Char7,
K2 TYPE Char3,
A2 TYPE Char3,
P2 TYPE Char3,
S2 TYPE Char3,
D1 TYPE Char8,
STD TYPE Char8,
BES TYPE Char80,
END OF ty_itab.
DATA: itab Type Standard Table of ty_itab,
wa_itab Type ty_itab.
DATA: it_zlt_aztnew2 type standard table of Zlt_aztnew2,
wa_aztnew2 TYPE Zlt_aztnew2.
SELECTION-SCREEN begin of block blk with frame title text-100.
SELECTION-SCREEN SKIP 2.
parameters : p_file like rlgrap-filename .
SELECTION-SCREEN end of block blk.
AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
CALL METHOD cl_gui_frontend_services=>file_open_dialog
EXPORTING
window_title = 'Select only Text File'
default_filename = '.azt'
multiselection = 'X'
CHANGING
file_table = it_tab
rc = gd_subrc.
READ TABLE it_tab INTO lw_file INDEX 1.
p_file = lw_file-FILENAME.
Start-of-Selection.
file_str1 = P_file.
CALL FUNCTION 'GUI_UPLOAD'
EXPORTING
filename = file_str1
* filename = '\\10.10.1.92\Volume_1\_projekte\Zeiterfassung-SAP\test.azt'
tables
data_tab = it_string
IF sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT it_string INTO lv_string.
Clear wa_itab.
SPLIT lv_string AT ';' INTO wa_itab-M2 wa_itab-k2 wa_itab-A2 wa_itab-P2 wa_itab-S2 wa_itab-D1 wa_itab-STD wa_itab-BES.
append wa_itab to itab.
Write: sy-uline(120),
/ sy-vline,
2 wa_itab-M2,
11 sy-vline,
13 wa_itab-k2,
25 sy-vline,
27 wa_itab-A2,
32 sy-vline,
34 wa_itab-P2,
39 sy-vline,
41 wa_itab-S2,
46 sy-vline,
48 wa_itab-D1,
60 sy-vline,
62 wa_itab-STD,
72 sy-vline,
74 wa_itab-BES,
120 sy-vline.
ENDLOOP.
LOOP at itab into wa_itab.
CLEAR wa_aztnew2.
wa_aztnew2-D1+0(4) = wa_itab+6(4).
wa_aztnew2-D1+4(2) = wa_itab+3(2).
wa_aztnew2-D1+6(2) = wa_itab+0(2).
Append wa_aztnew2 to it_zlt_aztnew2.
ENDLOOP.
MODIFY Zlt_aztnew2 from table it_zlt_aztnew2.
Looking forward for your suggestiojn.
Regards
Chandan -
Is there a way of Modifying OptionsList Table
Hello,
I am trying to create a metadata field that uses optionlist. Some of the values are longer than 50 varchars, so I wanted to know if there was a way to override the 50 varchars in the OptionsList table. When I try to go to the Configuration Manager and edit the OptionsList table. After allowing me to change the values and clicking ok, I am getting a message saying 'Unable to alter OptionsList table, OptionsList is a system database table'
Is there another way of fixing this problem? Thank in advance for any help.Hi
One way of doing this would be to go to DB and from there modify the length of the column of the table. Also you may have to change the datatype to one that can accommodates such long field lengths.
Alternately create a view on the table that you are going to change and then start tampering with the data on the view.
Thanks
Srinath
Maybe you are looking for
-
Error while Creating SAP Transactional iView
Hi I am trying to create an SAP Transaction iview to connect with SAP CRM system, i selected property WebHTML but i coule notable to connect to that TCode iview. For this i created a System with User Credentials that will map to the back end system.
-
Commitment in Purchase contracts and purchase order
Hi, We are loading contract through LSMW. As account assignment we are just passing the cost center and the account is configure in OKB9. However for some contract the flag is set in items affect commitments and the wrong account is determine. I wan
-
Hi Friends, I need to know whether there is possibility of importing only packages from an exported dump file into another database. If yes,kindly tell me how to do. The problem is I want to retrieve the older version of the package now as we do
-
Iphoto Library: Data Folder versus Originals Folder
Hi. I've been trying to save some space. I realized that I have the same photo stored in 3 different folders: my personal file folder (from where I imported), and within the "iphoto library" in 2 different folders: Originals and Data Folder. I got ri
-
Relation between non-database data blocks?
Hi all, I'm using Oracle Forms Builder 10GR2. I have two data blocks and i want to create a relation between them. They aren't database blocks and when i tried to create a relation between them based on a join condition/joining 2 display items/ i rec