Validating number data entry.

Hi there,
I want to validate the data entered (numeric) by the user. I have a customdocument to achieve the same. (the code is below).
What I want to know is - if I have a constructor which accepts the JTextfield as one of the arguments - how do I pass the jTextfield while invoking the class?
I tried using "this" (minus quotes) - but it gave me an error .
Any help is greatly appreciated.
Thanks
class CustomLongStyledDocument extends javax.swing.text.DefaultStyledDocument {
int maxCharacters;
JTextField textfield = null;
public CustomLongStyledDocument(int maxChars) {
maxCharacters = maxChars;
public CustomLongStyledDocument(int maxChars, JTextField txtfld) {
maxCharacters = maxChars;
textfield = txtfld;
public void insertString(int offs, String str, javax.swing.text.AttributeSet a) throws javax.swing.text.BadLocationException {
//This rejects the entire insertion if it would make
//the contents too long. Another option would be
//to truncate the inserted string so the contents
//would be exactly maxCharacters in length.
if ((getLength() + str.length()) <= maxCharacters) {
//super.insertString(offs, str, a);
     if(offs>=maxCharacters) {
return;     
long ltemp = 0;
          try     {          
               ltemp = Long.parseLong(str);
if (ltemp < 1940 || ltemp > 2003) {
textfield.setText("");
return;
          catch(NumberFormatException nfe) {            
java.awt.Toolkit.getDefaultToolkit().beep();
               return;     
          } // string is a number so insert in to textfield     
          super.insertString(offs,str,a);
else
java.awt.Toolkit.getDefaultToolkit().beep();

The code would look something like:
JTextfield textField = new JTextField(4);
CustomLongStyledDocument doc = new CustomLongStyledDocument(4, textField);
Other comments about you class:
1) JTextField uses a PlainDocument so normally you would extend PlainDocument
2) the insertString() method is called for each character typed. You are attempting to do a range check for a date between 1940 - 2003. This test will alway fail because the variable 'str' will only contain a single digit.

Similar Messages

  • How to add a new filed of Personnel number in FB60 data entry screen

    Hello SAP Gurus,
    We want to have a field to populate the Personnel number in all of the posting document entries via FB60. Besides the existing fields such as the "Doc.header text", "reference", "short text", "text" and "assignment" fields etc, are there any other fields that can be used to enter the Personnel number in the document entries? Maybe there're some fields are ready but the fields have been hidden on the data entry screen currently?
    Personnel number is there in the Vendor master data in CoCd data, Accounting Info.
    I checked the Field status group of the Vendor Recon A/c in OBC4 and made the personnel number as Optional from suppressed mode in FSG BS41 under Additional Account Assignment.
    After doing the above, I am still not able to see the personnel number filed in FB60.
    Am I missing anything else due to which I am not able to get the additional filed of personnel number in FB60 screen.
    Any help would be greatly appreciated.

    Hello Dear
    Look FB60 screen has two parts :
    The one in which you enter information related to vendor is Header Level, in this case you already assign Personnel No. in Vendor Master so no field is required as Personnel no. will be picked up from Vendor Master level.
    The Other is line item level is bottom half part, if you want to assign personnel no. at Expense G/L level then if you scroll right you will find a field for Personnel no. If you can't see the field check your setting at OBVV for the field status group you assign to particular Expense G/L.
    Hope you Understood
    Cheers
    IMK

  • ABAP function module to check data is a valid number

    Hi Guys,
    I am parsing a long string from a R3 table to load into BW, and need to verify the incoming data is valid number instead of having some or all charactors so I can load into a quantity field, in BW, it is a Key figure infoObject. The string length is 14.
    For example, if data is 123.34, then the number is valid. If data is 1A23, then it is not valid number.
    Thanks in advance.
    JA

    Hi,
    SAP provides the function BUS_NUMBERFIELD_PAI,
    You pass in a table/field reference that matches the number you want to match to say GLT0-TSLVT (len 15 dec 2) and the string.
    It tells you if the number is valid and will even return a reformatted string.
    I.E.
    123456,78 is valid and formatted as 123,456.99
    123,,456.78 raises AMOUNT_NOT_ALLOWED
    123.456 raises INTERNAL_ERROR as there are too many decimals
    Hope that helps.
    FUNCTION BUS_NUMBERFIELD_PAI .
    *"  IMPORTING
    *"     VALUE(I_TABNAME) LIKE  DD03L-TABNAME (Ex
    *"     VALUE(I_FIELDNAME) LIKE  DD03L-FIELDNAME
    *"     VALUE(I_CURRENCY) LIKE  TCURC-WAERS OPTIONAL
    *"  EXPORTING
    *"     VALUE(E_VALUE_DB)
    *"  CHANGING
    *"     VALUE(C_VALUE_DYNP)
    *"  EXCEPTIONS
    *"      NUMBER_NOT_ALLOWED
    *"      AMOUNT_NOT_ALLOWED
    *"      INTERNAL_ERROR

  • CATS-Data Entry Profile-Unable to Enter Personnel Number

    Hi,
    I am working on CATS. I have created a data entry profile and it is a copy of standard profile HR-ONLY The query is that when I go-to CAT2 the Personnel Number is grayed out meaning I cannot enter the personnel number.
    Kindly, help.
    Regards,
    Garima

    Hi garima dutta
    go to spro-cross application component -time sheet- specific settings for cats regular-cats regular-set up data entry profile.  there you have personnel selection check with your data entry profile whether radio button of time administrator is checked or not.  If it is checked then you check your authorization in su03 give the cvr parameter value as your data entry profile and save it. If you have any doubts please feel free to ask me
    ok
    bye
    Naveen

  • Displaying "N/A" in report fields where Number data is not valid using a formatting formula

    Post Author: Horizon57
    CA Forum: General
    I have many reports which are populated by "Number" data. However, there are certain charts and tables where the number data is not appropriate and the summation of such data does not add value to the report. In these instances I would like to display "N/A", however the formula I am using keeps giving me an error that I need to use a "Number" data type. Please note this is a formatting formula.
    Formatting Formula
    DO{TREND.EPTP1} = 'N/A' AND{TREND.EPTP2} = 'N/A' AND{@Trend %}    = 'N/A'  WHILE {TREND.POS2} = 'TOTAL';
    Can anyone assist me with displaying "N/A"?

    Post Author: V361
    CA Forum: General
    Try this
    DOtotext ( {TREND.EPTP1} ) = 'N/A' ANDtotext ( {TREND.EPTP2} ) = 'N/A' ANDtotext ( {@Trend %} )    = 'N/A'  WHILE {TREND.POS2} = 'TOTAL'; 

  • Problem in iterating through huge number of entries ... memory issue

    I am having large number of entries in lacs.
    I need to check each entry with previous ones , so I need to iterate through the each and every entry previous to current entry.
    Here I have put all the entries in arraylist and I am iterating though this arraylist and validating current entry.
    As I am using the arraylist for storing all the entries , the system is taking lot of memory because I am putting all in the memory.
    Is there anyway to resolve this memory issue?

    If you have a hundred thousand entries, to verify all the entries you would need to compare the later entries with the earlier ones such that:
    Entry 1 = 100,000 accesses
    Entry 2 = 99,999 accesses
    Entry 5 = 99,995 accesses
    Entry 10 = 99,990 accesses
    Entry 99,990 = 10 accesses
    Entry 99,995 = 5 accesses
    Entry 99,999 = 1 access (only to be compared with the 100,000th entry)
    It would then make sense to keep a certain (fixed) amount of entries in memory, those which get accessed the most, then write to file those which get accessed the least frequently. Have a method that can decide, based on the index of the entry, whether to get it from the ArrayList or to read it from the file. That will give you good performance.
    BufferedReader would be a good candidate to read the file, because it can skip more bytes at once should you need a line very late in the file. Also consider using RandomAccessFile and seek(entryNumber * ENTRY_SIZE) if your data can be represented with a fixed size in bytes.
    s
    Edited by Looce at 2009-03-25 20:33:11 GMT [Added BufferedReader advice]

  • Data entry by several users

    Hi,
    we have a situation were several users are potentially working on the same company. At the moment two (or more) users can open the same data entry template (same dimension members), enter data and send it to the database. This creates a problem as one user overwrites what the other has entered.
    Is there a way to lock data once a user has opened a form? This would have to be done on company, category and time level (so, when a user opens a data entry template for company A, category ACTUAL and 2010.DEC no other user should be able to open a data entry template for this combination, or at least any other user opening such a template should get a message saying they cannot send data).
    Thanks,
    Arnold

    Hi,
    Concurrency locking is handled by the system itself and only the parameters like number of individual records to be locked, factors for sparcity check and all can be maintained by developers in BPC through the table UJR_PARAM.
    May be you can have a work around for this like,
    you can create a dummy account for each input schedule and have a button for locking which internally send specific ID value for that user to that account.
    When the user leaves the IS have a button for unlocking which sends a default value say zro to the account.
    So if some other user logs in to the same IS and sends data do a validation check if the value for the dummy account is zero or some other value, if zero he can lock and use it else prevent user from sending data.
    Hope this helps,
    Regards,
    G.Vijaya Kumar

  • APP-AR-12022: A cash receipt with this number,date,amount and customer alre

    Hi,
    There is a caution(Warning message) of Duplicate receipt entery in Oracle AR Receipts entry window which pops up while creating the receipts.
    APP-AR-12022: A cash receipt with this number,date,amount and customer already exists.
    Normally it comes when we enter similar receipt number, net receipt amount and receipt date towice.
    Is it possible to customize the criteria for this caution.
    Thanks.

    You cannot customise this. If you want additional validation at the time of entry/update from forms, you can code special logic in custom pll. But you cannot change the standard functionality.

  • Help reqd on Changing the Valid from "date"  for both BOM & Routing

    Hi all...
    Pls advise me how to do the changing of Valid from "date"....
    Is there any process in CC01 or ECM???....
    pls reply me in detail step format (step by step analysis)....
    I wrongly created in CS01 and CA01 as 05.10.2007 as my valid from date instead of 01.10.2007.....
    How to change to my actual one......
    I dont know how to change it exactly.....as im beginner in SAP...pls take this into consideration...and post ur replies imm.
    Pls reply me in detail....will be rewarded at the end while closing this issue.
    thanks & regards
    sankar

    Dear Sankarbabu,
    IF there's no setting for Date Check in OS54 - Engineering Change Management
    Control Data,then you can create a change number with past dates,and also to
    use the same one for changing BOM.
    Tell me one thing you are saying you want to use ECM.Was the earlier one
    created without BOM was created without an ECN?
    See already if you have created your BOM with an ECN,then remove the date
    check setting which I have mentioned in OS54.
    Now goto T code CC02 ,enter the Change number and give the valid from date as
    01.10.2007.
    After that check in CS03 whether this date(01.10.2007)is getting reflected or not.
    I'm sure this will solve your problem.
    Regards
    Mangal

  • How to select a single row in a report for data entry?

    Hello All, and Greetings.
    I am a newcomer, with no experience in Apex, and in need of help.
    I have to generate a report with some read-only columns and two write columns. These will be the result of a SQL query.
    For the sake of robustness in data entry, a row has to be selected prior to data update. The document specifies that a radiobutton for each row be present, and the corresponding row selected accordingly by clicking its radiobutton. There could be any number of rows returned in the report, which means that the number of radiobuttons will vary dynamically according to the number of returned rows.
    1. So my question is, how do I construct the page to do this? Please remember I am a newbie, so detail will be appreciated.
    2. Another question is, how do I change the fonts and colours of the names displayed along with the listboxes?
    Thank you very much for your attention. Any help will be warmly received.
    With regards,
    Arindam.

    You may find this article useful: http://balusc.blogspot.com/2006/06/using-datatables.html
    P.S: please don't reply with "but I cannot read and write code, I can only drag'n'drop!".

  • Open data slice for data entry and close afterwards

    Dear all,
    I have created one data slice for a characteristic combination country xy in order to prevent the data entry within the data entry query for the user. But for some reason I have to run a planning function in order to summarize some values and write a total value in the characteristic e.g. country xy.
    The planning function brings out an error message because this can not be executed due to the fact that this combination is protected.
    Is there a way to open the data slice before the planning function is writing the data in the cube? I have tried to to this in the Data slice exit, but I do not have an idea how to open the DS, save the data and close the DS again.
    We are running NW BI 7.0. Any ideas would be great.
    Best regards,
    Stefan from Munich/Germany

    I did something like this by creating an FM and calling that FM from a FOX function. I think you will have to use three commands to execute three functions one after the other (and not combine them in one planning sequence) - first one will switch off the data slice, next will be your planning function containing the logic, and the last will switch it back on.
    The FM would be something like below:
    FUNCTION Z_SWITCH_DSLICE.
    *"*"Local Interface:
    *"  IMPORTING
    *"     REFERENCE(I_INFOPROV) TYPE  RSINFOPROV
    *"     REFERENCE(I_DSNR) TYPE  RSPLS_DSNR
    *"     REFERENCE(I_STATUS) TYPE  I
    *** This function imports the name of a real-time Infoprovider and a Data Slice number
    ***        and a parameter I_STATUS. If I_STATUS is 1, data slice is activated
    ***        If I_STATUS is -1, data slice is de-activated
    data wa_ds type rspls_ds.
    select single * from rspls_ds
            into wa_ds
            where infoprov = I_INFOPROV
              AND objvers = 'A'
              AND dsnr = I_DSNR.
    if I_status = 1.
       wa_ds-used = 'X'.
    elseif I_status = -1.
       wa_ds-used = ''.
    endif.
    update rspls_ds from wa_ds.
    ENDFUNCTION.
    The Fox code will be like below -
    CALL FUNCTION Z_SWITCH_DSLICE
        EXPORTING
           I_INFOPROV = <infoprov name>
           I_DSNR = <Data Slice Number>
           I_STATUS = <0 or 1>.

  • Error: No valid complaint data was found in this sales area

    Hi All,
    I am getting below error while delta or request download of customer.
    No valid complaint data was found in this sales area
    Message no. CRM_SPL_BUPA_FRG0010203
    Validation error occurred: Module CRM_BUPA_MAIN_VAL, BDoc type BUPA_MAIN.
    Message no. SMW3018
    Error case:
    ECC-->Customer(Sold to) extended to a sales area and saved.
         CRM-->Business partner gets updated in the CRM properly.
    ECC--> Deletion flag for same customer and same sales area is set. (Deletion flag - "Selected sales area").
         CRM-->Business partner gets updated in the CRM properly and is not shown as extended to the sales area via BP t code.
    ECC-->Deletion flag is removed for the customer.
         CRM--> BDOC fails to update the Partner and goes in error.
    Problem comes when deletion flag is removed in ECC.
    Any help would be highly appreciated.
    Thanks in advance.
    -Ram

    Hi Ram,
    Hope you have not make any field mandatory in the Complaint tab in the sales area section in the BP.
    When you are removing the deletion flag please check if any entry is mandatory in the Complaint tab.
    Hope this will be useful
    Thanks and Regards
    DJ

  • Table for Valid to date in BOM item

    Hi Exeprts,
    Can any one help me on this in which db table Valid to date:DATUB is Updates with reference to Change Number.
    Best Regards,
    Venkata Siva.
    Edited by: venkata siva reddy on Apr 27, 2011 9:28 PM

    Hi
    The Valid-to date will always be set to 31.12.9999. Instead you can get the valid-to date using the below logic.
    -> Get all the BOM from T415A table for the material number into T_T415A
    -->LOOP AT t_t415a.
        ON CHANGE OF t_t415a-matnr OR t_t415a-werks OR t_t415a-stlal.
          IF sy-tabix NE 1.
            MOVE : v_matnr TO t_dates-matnr,
                   v_werks TO t_dates-werks,
                   v_stlan TO t_dates-stlan,
                   v_datuv TO t_dates-datuv,
                   v_stlal  TO t_dates-stlal.
            IF v_matnr NE t_t415a-matnr.
              t_dates-datub = c_99991231.
            ELSE.
              t_dates-datub = t_t415a-datuv - 1.
            ENDIF.
            APPEND t_dates.
            CLEAR :
            v_matnr,
            v_werks,
            v_stlan,
            v_datuv,
            v_stlal.
          ENDIF.
        ENDON.
        v_matnr = t_t415a-matnr.
        v_werks = t_t415a-werks.
        v_stlan = t_t415a-stlan.
        v_datuv = t_t415a-datuv.
        v_stlal = t_t415a-stlal.
      ENDLOOP.
    Regards
    Dhurga

  • How to get the latest and valid BOM item entry from STPO

    hi,
    may i know with what condition we can get the latest and valid BOM item entry from STPO table?
    i have STLNR and IDNRK as a input. But i realized that it would return multiple entry due to the combination of  valid-from and valid till date.
    can i use stlnr,idnrk and stpoz (with the latet counter) to get the latest and valid BOM entry?
    thank you.

    Hi
    You can get the latest BOM either by using the latest valid from date DATUV or latest internal counter STPOZ
    Regards
    Shiva

  • How to find out Number of entries in a Huge Table?

    Hi,
    I would like to know Number of entries in table DFKKOP. when i try to get it through se16, it takes more than 10 minutes in dialogue process so a time out occurs. is there any way to find out number of entries in the table Apart from creating a program for that?
    Please guide me to the solution.
    Thanks,
    Lijo Joseph
    Message was edited by: Lijo Joseph Vazhappilly

    REPORT  YCHATEST                                .
    Data : begin of itab occurs 0.
            include structure tab512.
    data:end of itab.
    data : v_count like sy-index,
           tabname like X030L-TABNAME value 'DFKKOP'.
    CALL FUNCTION 'RFC_GET_TABLE_ENTRIES'
      EXPORTING
        table_name              = tabname
    IMPORTING
       NUMBER_OF_ENTRIES       = v_count
    tables
       entries                 = itab.
    write : v_count.
    Message was edited by: Sekhar

Maybe you are looking for