Auto Incrementing a field in a database table
Hello All,
I have created a database table for generating a unique ID, based on two key fields; Product and Area.
For a particular Product and Area,the ID generated should be unique, and it will be the third field of my table.
Is there any possible way by which i can generate the ID automatically,based on the Product And Area entered? The ID should also be automatically incremented based on the next entry.
Can anyone help me in resolving this problem?
Also, if i am deleting a particular Product and Area, will it be possible to remove the ID generated by it?
Thanks In Advance.
Shino.
Hi,
If you are using a generated maintenance screen and populating the data manually your approach will need to be different.
It could be possible to use a user exit in the generated screen to populate your ID field, but you will face the risk that the user will be able to presumably over-type the ID or enter their own value.
Consider your overall requirement and design, it may be that a generated maintenance sceen is not the most suitable way to build this functionality.
Regards,
Nick
Similar Messages
-
Auto Increment ID Field Table in the Oracle Database (insert new record)
I have been using the MySQL. And the ID field of the database table is AUTO INCREMENT. When I insert a new record into a database table, I can have a statement like:
public void createThread( String receiver, String sender, String title,
String lastPostMemberName, String threadTopic,
String threadBody, Timestamp threadCreationDate,
Timestamp threadLastPostDate, int threadType,
int threadOption, int threadStatus, int threadViewCount,
int threadReplyCount, int threadDuration )
throws MessageDAOSysExceptionand I do not have to put the ID variable in the above method. The table will give the new record an ID number that is equivalent to the ID number of the last record plus one automatically.
Now, I am inserting a new record into an Oracle database table. I am told that I cannot do what I am used to doing with the MySQL database.
How do I revise the createThread method while I have no idea about what the next sequence number shall be?I am still very confused; in particular, the Java part. Let me try again.
// This part is for the database table creation
-- Component primary key sequence
CREATE SEQUENCE dhsinfo_page_content_seq
START WITH 0;
-- Trigger for updating the Component primary key
CREATE OR REPLACE TRIGGER DHSInfoPageContent_INSERT_TRIGGER
BEFORE INSERT ON DHSInfoPageContent //DHSInfoPageContent is the table name
FOR EACH ROW WHEN (new.ID IS NULL) // ID is the column name for auto increment
BEGIN
SELECT dhsinfo_page_content_seq.Nextval
INTO :ID
FROM DUAL;
END;/I am uncertain what to do with my Java code. (I have been working with the MySQL. Changing to the Oracle makes me very confused.
public void updateContent( int groupID, String pageName, int componentID,
String content, Timestamp contentCreationDate )
throws contentDAOSysException
// The above Java statement does not have a value to insert into the ID column
// in the DHSInfoPageContent table
Connection conn = null;
PreparedStatement stmt = null;
// what to do with the INSERT INTO below. Note the paramether ID.
String insertSQL = "INSERT INTO DHSInfoPageContent( ID, GroupID, Name, ComponentID, Content, CreationDate ) VALUES (?, ?, ?, ?, ?, ?)";
try
conn = DBConnection.getDBConnection();
stmt = conn.prepareStatement( insertSQL );
stmt.setInt( 1, id ); // Is this Java statement redundant?
stmt.setInt( 2, groupID );
stmt.setString( 3, pageName );
stmt.setInt( 4, componentID );
stmt.setString( 5, content );
stmt.setTimestamp( 6, contentCreationDate );
stmt.executeUpdate();
catch
finally -
Extracting Values of a Field from a Database Table in SAP ECC System
Hi,
I downloaded Extracting Values of a Field from a Database Table in SAP ECC System Using MII 12.0
senario from sdn. I'm trying to do that senario in MII 12.05. But I have problem with section 6 in page 7 (you can supply senario from sdn)
"6- Under the loop of Repeater, use action u2018Rowu2019 to append just the string part of the WA which will display only values for field u2018Batchu2019"
I did not find WA elemen in Output element of Repeater_0
How can I create WA element?
Thanks.Cemil,
Set up a SAP JCo Interface action block. Use the RFC name RFC_READ_TABLE.
In the link editor map the table to "MARA", set RowCount to something small (20 is good sample size) and create an xml transaction property named FIELDS and copy the following into it:
<?xml version="1.0" encoding="UTF-8"?><FIELDS>
<item>
<FIELDNAME>MATNR</FIELDNAME>
<OFFSET/>
<LENGTH/>
<TYPE/>
<FIELDTEXT/>
</item>
<item>
<FIELDNAME>MTART</FIELDNAME>
<OFFSET/>
<LENGTH/>
<TYPE/>
<FIELDTEXT/>
</item>
<item>
<FIELDNAME>BSTME</FIELDNAME>
<OFFSET/>
<LENGTH/>
<TYPE/>
<FIELDTEXT/>
</item>
<item>
<FIELDNAME>XCHPF</FIELDNAME>
<OFFSET/>
<LENGTH/>
<TYPE/>
<FIELDTEXT/>
</item>
<item>
<FIELDNAME>DATAB</FIELDNAME>
<OFFSET/>
<LENGTH/>
<TYPE/>
<FIELDTEXT/>
</item>
</FIELDS>
Then link the Transaction.FIELDS to SAP_JCo_Interface_0.Request{/RFC_READ_TABLE/TABLES/FIELDS}. You may run into problems with two other fields and optionally they can be removed (set link type to remove xml). I usually remove them initially for testing. The two fields are:
SAP_JCo_Interface_0.Request{/RFC_READ_TABLE/INPUT/NO_DATA}
SAP_JCo_Interface_0.Request{/RFC_READ_TABLE/INPUT/DELIMITER} (or you can set this to something like a semicolon,";" or tilda,"~". I find it easier to caclulate position by length, but that is my own idiosyncrasy.)
Once you get this one working, we can explore how to do filtering on the dataset. Your output should be something like this:
<?xml version="1.0" encoding="utf-8"?>
<RFC_READ_TABLE>
<INPUT>
<DELIMITER />
<NO_DATA />
<QUERY_TABLE>MARA</QUERY_TABLE>
<ROWCOUNT>20</ROWCOUNT>
<ROWSKIPS>0</ROWSKIPS>
</INPUT>
<TABLES>
<DATA>
<item>
<WA>000000000000000023ROH 00000000</WA>
</item>
<item>
<WA>000000000000000038HALB 00000000</WA>
</item>
<item>
<WA>000000000000000043HAWA 00000000</WA>
</item>
<item>
<WA>000000000000000058HIBE 00000000</WA>
</item>
<item>
<WA>000000000000000059HIBE 00000000</WA>
</item>
<item>
<WA>000000000000000068FHMI 00000000</WA>
</item>
<item>
<WA>000000000000000078DIEN 00000000</WA>
</item>
<item>
<WA>000000000000000088FERT 00000000</WA>
</item>
<item>
<WA>000000000000000089FERT 00000000</WA>
</item>
<item>
<WA>000000000000000098HALB 00000000</WA>
</item>
<item>
<WA>000000000000000170NLAG 00000000</WA>
</item>
<item>
<WA>000000000000000178NLAG 00000000</WA>
</item>
<item>
<WA>000000000000000188NLAG 00000000</WA>
</item>
<item>
<WA>000000000000000288HALB 00000000</WA>
</item>
<item>
<WA>000000000000000358HAWA 00000000</WA>
</item>
<item>
<WA>000000000000000359HAWA 00000000</WA>
</item>
<item>
<WA>000000000000000521HAWA 00000000</WA>
</item>
<item>
<WA>000000000000000578FERT 00000000</WA>
</item>
<item>
<WA>000000000000000597HAWA 00000000</WA>
</item>
<item>
<WA>000000000000000598VERP 00000000</WA>
</item>
</DATA>
<FIELDS>
<item>
<FIELDNAME>MATNR</FIELDNAME>
<OFFSET>000000</OFFSET>
<LENGTH>000018</LENGTH>
<TYPE>C</TYPE>
<FIELDTEXT>Material Number</FIELDTEXT>
</item>
<item>
<FIELDNAME>MTART</FIELDNAME>
<OFFSET>000018</OFFSET>
<LENGTH>000004</LENGTH>
<TYPE>C</TYPE>
<FIELDTEXT>Material Type</FIELDTEXT>
</item>
<item>
<FIELDNAME>BSTME</FIELDNAME>
<OFFSET>000022</OFFSET>
<LENGTH>000003</LENGTH>
<TYPE>C</TYPE>
<FIELDTEXT>Purchase Order Unit of Measure</FIELDTEXT>
</item>
<item>
<FIELDNAME>XCHPF</FIELDNAME>
<OFFSET>000025</OFFSET>
<LENGTH>000001</LENGTH>
<TYPE>C</TYPE>
<FIELDTEXT>Batch management requirement indicator</FIELDTEXT>
</item>
<item>
<FIELDNAME>DATAB</FIELDNAME>
<OFFSET>000026</OFFSET>
<LENGTH>000008</LENGTH>
<TYPE>D</TYPE>
<FIELDTEXT>Valid-From Date</FIELDTEXT>
</item>
</FIELDS>
<OPTIONS />
</TABLES>
</RFC_READ_TABLE>
Add a repeater sourced on:
SAP_JCo_Interface_0.Response{/RFC_READ_TABLE/TABLES/DATA/item}
Link your repeater output to a tracer with this:
Repeater_0.Output{/item/WA}
What you will see in each tracer message is a single line of data with all the fields contents concatenated together. You can look up what each field in the string represents by the length of the field as returned in the Response segment of the RFC_READ_TABLE rfc. Then you can parse out the data you are interested in.
Give this a try and let me know how you succeeded.
By the way, I could not find the scenario you referred to. Can you post a link?
Regards,
Mike
Edited by: Michael Appleby on Jan 12, 2009 5:16 PM -
To replace values of one of the field in the database table
How to replace values of one of the field in the database table with a new values? Pls help to solve
Hi
You can use the UPDATE command to update one of the field value in a table
see the UPDATE syntax and use it
but in real time you should not do like this
Regards
Anji -
How to delete data from single field in a database table?
Hi guys,
Plz suggest me How to delete data from single field in a database table?
thnks,
pavanhi
in addition to abv details..chk this:
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb3aef358411d1829f0000e829fbfe/content.htm
http://dev.mysql.com/doc/maxdb/en/34/ee7fbd293911d3a97d00a0c9449261/content.htm
regards,
madhu -
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 Find the Data Type of the Field In a Database Table
Hi Experts,
I'm currently working on a program which needs to find out the data type of the given field in a database table. In addition to accessing DD03L directly, is there any other workaround such as function module to help me achieve this? It would be helpful if a demo example could be provided.
Thanks a lot.Hi,
Use this..
DESCRIBE FIELD dobj TYPE typ.
write typ.
type will contain the data type of the object.
and check this thread also....
Re: How to get datatype of fields in dynamic structures
Cheers,
Simha.
Reward all the helpful answers.. -
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 -
How to find the structure fields data in database tables?
how to find the structure fields data in database tables?
Your question doesn't appear to be Web Dynpro ABAP related. Please only post questions in this forum if they are directly Web Dynpro ABAP related. There are several other more general ABAP related forums.
-
Mapping the CMP Fields with the Database Table using Websphere???
Hi,
How to Map the CMP Fields with the Database Table using Websphere
thru ejb.jar.xml???
Thanks,
JavaCrazyLoverHi,
How to Map the CMP Fields with the Database Table using Websphere
thru ejb.jar.xml???
Thanks,
JavaCrazyLover -
Do you know of a standard tool to compare the fields of 2 database tables?
do you know of a standard tool to compare the fields of 2 database tables? please note i dont want to compare data just the fields.
~SureshHi,
I am not aware any standard tool but you can write custom report to use FM DDIF_FIELDINFO_GET to get fields information of SAP database table.
Call the above FM twice in order to get field names for two different database tables. Then compare the results (table parameter DFIES_TAB) to find out the differences of field names.
Hope this will help ...
Regards,
Ferry Lianto -
How can i update the REMARK field in ADRT database table
Hi all,
How can i update the REMARK field in ADRT database table
By using Function modules or BAPIs
Please reply me fastHi,
you can try this code:
SELECT SINGLE * FROM KNA1 WHERE KUNNR = wa_kunnr.
IF sy-subrc = 0.
CLEAR adrct.
SELECT SINGLE * FROM adrct WHERE addrnumber = kna1-adrnr.
IF sy-subrc = 0.
adrct-remark = wa_remark.
MODIFY adrct.
ENDIF.
ENDIF
best regards,
Thangesh -
Auto populate values in the the database table
Hi All,
I have a requirement where user enter values in one of the ZTransaction. This will update a Ztable. So the new requirement is to add two new columns in the fields, which is completed. Now this two new fields are supposed to auto populate values based upon the key field .
The transaction code is defined with Transaction as SM30 and Default values as
Name of the screen field value
Update X
VIEWNAME "table name which the values are updated".
Please let me know how to do this.
Thank you!!Hi Swetha,
I am unsure of what you are trying to accomplish so I will make a few assumption and perhaps you can find some benefit in it.
I suppose you are trying to add new fields to a custom (Z) database table.
If so then use SE11 to add the two new columns.
After this is complete then rebuild the table maintenance by using the following path: SE11-> Utilities->Table Maintenance Generator. (Remember to double check the Recording Routine Radio button.)
If the user needs fields automatically populated then check the following link. It describes how to use table maintenance events. I suppose you need to use Event 01 and Event 05.
http://help.sap.com/saphelp_nw04/helpdata/en/91/ca9f0ea9d111d1a5690000e82deaaa/frameset.htm
Good luck and reward points if helpful,
AK
Moderator message - Asking for points is against the Forum's RoE
Message was edited by: Suhas Saha -
Hello,
I would like to have a number field to be auto increment. Ho can I do that in Oracle must I use some code for it or can I make the field auto increment by itself.
Thanksuser3311314 wrote:
Hello,
I would like to have a number field to be auto increment. Ho can I do that in Oracle must I use some code for it or can I make the field auto increment by itself.
ThanksIt's a long standing gripe of mine. You must use code, and the appropriate solution is a sequence and a trigger, eg
SASH_CLIENT @ DB10G >create table t(
2 id number not null primary key
3 , c1 char(100));
Table created.
SASH_CLIENT @ DB10G >
SASH_CLIENT @ DB10G >create sequence seq_t;
Sequence created
SASH_CLIENT @ DB10G >
SASH_CLIENT @ DB10G >create or replace trigger bir_t
2 before insert on t
3 for each row
4 begin
5 select seq_t.nextval into :new.id from dual;
6 end;
7 /
Trigger created.
SASH_CLIENT @ DB10G >insert into t(c1) values ('row 1');
1 row created.
SASH_CLIENT @ DB10G >commit;
Commit complete.
SASH_CLIENT @ DB10G >select * from t;
ID C1
1 row 1I'd much prefer
create table t (
id number primary key default seq_t.nextval
, c1 char(100)); -
Creation of key field in a database table
Hi All,
As per my requirement, i have to add few new key fields in an existing table.
Now total number of key fields are 17, but while saving this is giving me an syntax error stating 'According to SAA standard key fields cannot be more that 16'.
I s there any other go? i can not reduce the number of key fields.
Regards,
Pankaj.
Edited by: Pankaj Bist on Sep 5, 2008 3:24 PMHi,
In the se11 transaction,In the menu bar o like this.
Utilites-->Database Utility and the Press the button Activate and Adjust Database.
Note:
Make sure that you total data in the table to be downloaded into ur system.
As ctivate and Adjust Database makes data to be deleted.
Regards,
Rama.
Maybe you are looking for
-
Improvements for IWork for iOS
I write to suggest improving your IWork for ios application. The applications are very good, but lacks some important features that would help iPad -Iphone users to work better. These absences are: NUMBERS: - filters - sort by more criteria - cat
-
Adobe interactive form and workflow attachment
I use an ABAP webdynpro to trigger a WF. The WD is an interactive adobe form step for users to enter data. Then before triggering the WF, I would like to save the form as an PDF form so I can send it to the subsequent work item processors. Is this po
-
Crop in an action, I'm sure it must be easy!
Hi, I'm going round in circles trying to help a friend who wants an action which opens a file, creates a copy, closes the original, allows him to crop the image then puts a set of adjustment layers on it. I've done it all for except for the crop step
-
Tracks switching their library position after I select them to play?
I have my library categorized by "Album" normally. Ever since I upgraded to iTunes 7, if I select any album track that isn't the first on the cd, that track will jump from whatever position it was in to number 2. Sometimes 3 or 4. It's incredibly fru
-
[SOLVED] dwm doesn't compile with moveresize function
I'am trying to compile dwm with moveresize function but I get this error: dwm build options: CFLAGS = -std=c99 -pedantic -Wall -Os -I. -I/usr/include -I/usr/include/X11 -DVERSION="5.7.2" -DXINERAMA LDFLAGS = -s -L/usr/lib -lc -L/usr/lib/X11 -lX11 -L/