Check field data type
Hey,
Im trying to determin the value of a JTextField.
I want to test if the data in the field is either
a) a String
b) a Date
c) a numeric
How would i do this?
Any example code of tutorials would be great
thanks in advance
Dave
you're advocating exception handling for this?
advocating expecting exceptions? normally if
someone suggested this, I'd dismiss it as amateur
ramblings, but I know that doesn't apply to you. what
gives?Simplicty. To find out whether it's a valid int, you could of course use a regex to check for sign and all-digits,and then check the amount of digits for the maximum length - and if the String is as long as MAX_VALUE (or MIN_VALUE), you'll need to check each digit whether its equal or smaller than MAX_VALUE's.
And then you parseInt() it.
And for dates, it will be even worse.
So you're going to write a hell of a lot of code that ends up doing what you'd do anyway, and in once case you have neat although avoidable "error" handling, while in the other case you're left with a lot of work, potential bugs and people cursing at you.
If you're really a purist, a NumberFormatException should never occur. But I'm at least a bit more pragmatic.
Similar Messages
-
Unicode - "DMBTR" must be a character-type field (data type C,N,D or T)
Greetings Experts!
I am trying to convert legacy code to Unicode for a current ERP6.0 reinstallation and have encountered the syntax error "DMBTR" must be a character-type field (data type C,N,D or T)
The field is part of a structure and the fields attributes are as follows:
COMPONENT = DMBTR
COMPONENT TYPE = DMBTR
DATA TYPE = CURR
LENGTH = 13
DECIMALS = 2
DESCRIPTION = Amount in Local Currency
The code in question is as follows:-
macro Move_Zoned.
Converts a numeric variable to zoned format and moves it to a
target variable.
DEFINE move_zoned.
&1 - source variable
&2 - Number of Decimal Places
&3 - 'To'
&4 - Target Variable.
write &1 to w_zoned no-grouping decimals &2.
condense w_zoned.
Remove the Decimal Points.
search w_zoned for '...'.
while sy-subrc = 0.
move sy-fdpos to w_to_point.
if w_to_point = 0.
w_to_point = 1.
endif.
compute w_from_point = sy-fdpos + 1.
concatenate w_zoned+0(w_to_point)
w_zoned+w_from_point
into w_zoned.
search w_zoned for '...'.
endwhile.
shift w_zoned right deleting trailing space.
translate w_zoned using ' 0'.
call function 'Z_TRANSLATE_ZONED_DECIMALS'
exporting
i_input = w_zoned
importing
i_output = w_zoned
exceptions
x_invalid_zoned_char = c_invalid_zoned_char
x_numeric_info_lost = c_numeric_info_lost
others = c_other_zoned_error.
Get the length of the recipient field so we don't truncate the
numbers....
describe field &4 length w_flength in character mode.
describe field &4 type w_type.
describe field w_zoned length w_zoned_len in character mode.
if w_zoned_len <= w_flength.
move w_zoned to &4.
shift &4 right deleting trailing space.
translate &4 using ' 0'.
else.
Get the start position....
If it's a packed field allow for values up to 6 figures
compute w_zoned_len = w_zoned_len - w_flength.
if w_type = 'P'.
subtract 2 from w_zoned_len.
clear w_type.
endif.
move w_zoned+w_zoned_len &3 &4.
endif.
END-OF-DEFINITION. "Move_zoned
LOOP AT t_single_kunnr.
move_zoned t_single_kunnr-postamt 2
to t_single_kunnr-dmbtr.
DIVIDE t_single_kunnr-dmbtr BY 100.
MODIFY t_single_kunnr.
ENDLOOP.
Is there a solution to get past this syntax error as I would rather not change the datatype of the field in the structure.
Much Obliged
Elphick.Type X is not allowed in Unicode. When a field is declared as Type X with Value u201809u2019 or any other value, it can be resolved by using classes.
Before Unicode
CONSTANTS: c_hex TYPE x VALUE '09'.
Resolution:
Itu2019s work for any value of x.
First a temporary field of Type c should declare. Following class will convert Type x variable into type c.
Example:
CONSTANTS: c_hex TYPE x VALUE '09'.
DATA: LV_TEMP TYPE STRING.
DATA: LV_TMP TYPE C.
TRY.
CALL METHOD CL_ABAP_CONV_IN_CE=>UCCP
EXPORTING
UCCP = c_hex
RECEIVING
CHAR = LV_TMP .
CATCH CX_SY_CONVERSION_CODEPAGE.
CATCH CX_PARAMETER_INVALID_TYPE.
CATCH CX_SY_CODEPAGE_CONVERTER_INIT.
ENDTRY.
CONCATENATE I_OUTPUT-BKTXT I_OUTPUT-BVORG
I_OUTPUT-BUDAT I_OUTPUT-MESSAGE INTO
SEPARATED BY LV_TMP.
I_BUFFER = LV_TEMP.
CLEAR LV_TEMP.
CLEAR LV_TMP.
OR
Note: It works only for type x value 09.
CLASS cl_abap_char_utilities DEFINITION LOAD.
CONSTANTS: c_hex TYPE c VALUE
abap_char_utilities=>HORIZONTAL_TAB. -
Suppose we have 4 fields , data type u0093 DATS u0094 for those fields how do you
Hi Experts,
How we decide particular field map to particular info object. Suppose we have 4 fields , data type DATS for those fields how do you decide the InfoObject 0calday
have to map.
thanks®ards
pradeepHi Pradeep,
It merely depends upon ur requirement.
If u r having 4 dats fields and is it up to ur requirement to map one of that obj to the 0calday. -
Issue with field data type NUMBER(22,5) while updating field data.
Hi,
I have a field with data type NUMBER(22,5).
While inserting or updating field data it should take 17 digit and after decimal point 5 digit total 22 digit.
I set 22 for maximumLength property of messageTextInput field.
While updating field I am getting following problems,
1) I provide the value as 1234567890123456789012 (22 digit) and click apply button.
then I got error message as
Error
मैकेनाइजड दो पहिया/तीन पहिया वाहन - Value 1234567890123460000000 exceeds the maximum allowed value (NUMERIC (22, 5))
2)then I insert 12345678901234567.1234 (17 digit before decimal point and 4 digit after decimal point and it didn't accept 5 digit after decimal point) and click apply button.
It insert the value as 12345678901234600 (value changed after Apply)
The I tried with simple SQL insert statement to insert data and it successfully insert 12345678901234567.12345 value.
Any item property I missed here to set?
Please suggest.
Thanks & Regards,
Sagarikahi
according to
" then I insert 12345678901234567.1234 (17 digit before decimal point and 4 digit after decimal point and it didn't accept 5 digit after decimal point) and click apply button.
It insert the value as 12345678901234600 (value changed after Apply)"
this statement ,it seems that it is definitely applying round or somthing like that function in the code before inserting value in the table("try with select round(12345678901234567.1234 ) from dual u will get the same result = 123456789012345600 ") ,
bcz u r able to insert the same directely into the table using insert statement so kindely have look on the code if something like this is not happening there.try to check code in related EOimpl class
try to to use debugging mode ,and the 23 char problem is related to maximum lenghth of text box make it 23 it will get resolved and u will be able to enter 17 digits with 5 digits after decimal point
thanx pratap -
How to check the data type dynamically
hi all
my requirement is like this in one screen field which is of character type user is inputing data .
now while saving to the database i have to apply one external check for this data if it is integer type or not
as this data on the screen is refrenced to the database so i can not change the data type on the screen itself .
i have to check it externally from PAI ....... would any one please help on this
Thanks and regards
PappsHi
Thanks again you are right i missed the space one ..
but Now another problem...
I have tried that but in that case even user can input data by mistake like this
123 4 but this is not an integer it should also give error as this is also not a correct integer ...
as par asi think . we have to aain check if there is any spaces in the data provided i guess or
is there any other procedure ? -
I have rows coming in with three column values I need on the export, I don't want to change the export process that is in place ...and I can't change the import formats...
I would like to concatenate them and put them in the "Amount" field...can this be done?
Suggestions?
JzYou won't be able to do it in the Amount field because without using some sort of seperator i can't see how you will parse the values out later and this will give you issues at import with non numeric data type exceptions. Also if you can't change import formats you are extremely limited as this is where any sort of data manipulation is traditionally done.
Edited by: SH on May 13, 2011 8:39 PM -
Hi,
Please let me know if the Data Type- STRG (Char string,variable length) is allowed for RF Screen.
I want to use a field with Defined Len = 1000 CHAR & visible Len = 1.
Pls let me know if you hv some other solution also...
Regards,
RushikeshI'm not familiar with module pool programs and their impossibilities ??
but I guess the transfer of data or retrieving of data is the same whether youi have a selection screen or not.
in the selection screen all data is gathered in a range. you can also create and fill a range you're self
look at datatype ranges for more info
example
ranges: h_arbid for crhd-objid occurs 0 .
you can now define
h_arbid-option = 'I'.
h_arbid-sign = 'BT'. "means between or EQ for single value
h_arbid-low = 'start 1'.
h_arbid-high = 'start 10'.
append h_arbid.
you can also add more ranges to the same selection.
h_arbid-option = 'I'.
h_arbid-sign = 'BT'. "means between or EQ for single value
h_arbid-low = 'start 20'.
h_arbid-high = 'start 30'.
if you pass it on to you're select statement it is
select * from table where arbid IN h_arbid.
so you get all the records from 1 till 10 and 20 till 30
kind regards
arthur -
Creating Custom fields (data type QUAN) using EEWB
Hi all
I tried to create two customised fields using EEWB for CRM Opportunity:
1. Projected Volume (data type 'QUAN', length 13, 3 decimal places)
2. Projected Unit (data type 'UNIT')
In the SAP-generated tables, I have set the reference table field for 'Projected Volume' to point to 'Projected Unit'. However, I encountered errors that is related to Table Buffering and Restricted Transport for the Projected Volume field.
If I were to change the data type to 'NUMC', field generation is ok. Does anyone know to resolve this issue? I need the Projected Volume field to be of data type 'QUAN' since decimal place is required.
Thanks for your advice!SAP Note 746227 has addressed this issue. I will close this question.
-
JCo getting truncated value from SAP when field data type is RAW
We are trying to fetch data from a SAP-AII table by using JCo using the RFC RFC_READ_TABLE.
We are getting incomplete data when the data type of the column is RAW in a particular table.A typical case is:
Table Name: /AIN/DM_DEVCTR
Field : CLIENT Type: CLNT Length:3 Value: 100 (SAP Generated)
Field: DEVCTR_GUID Type:RAW Length:16 Value: 306F50F53805ED488DE9797AC86B5728 (SAP Generated)
Filed: DEVCTR_ID Type:CHAR Length:128 Value: KDEVICECONTROLLER (User input)
For the fields CLIENT and DEVCTR_ID we get the entire value (including blank spaces) but for DEVCTR_GUID we get only 16 characters whereas SAP-AII stores a value that is 32 characters in length. How do we fetch the actual value instead of the truncated value?
Sample code is attached.
try {
mConnection = JCO.createClient("100", // SAP client
"User", // userid
"Password", // password
"EN", // language
"SAP", // host name
"00"); // system number
mConnection.connect();
if (mConnection == null) {
System.out.println("Connection to SAP Server failed.");
mRepository = new JCO.Repository("User", mConnection);
ftemplate = mRepository.getFunctionTemplate("RFC_READ_TABLE");
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
JCO.Function function = ftemplate.getFunction();
JCO.ParameterList importParamList = function.getImportParameterList();
importParamList.setValue("/AIN/DM_DEVCTR", "QUERY_TABLE");
importParamList.setValue(";", "DELIMITER");
JCO.Table tableData = function.getTableParameterList().getTable("DATA");
JCO.Table fields = function.getTableParameterList().getTable("FIELDS");
mConnection.execute(function);
if (tableData.getNumRows() > 0) {
do {
for (JCO.FieldIterator e = tableData.fields(); e
.hasMoreElements();) {
JCO.Field field = e.nextField();
String str = field.getString();
String[] values = str.split(";");
for(int i = 0; i < values.length; i++){
System.out.println(values<i>);
} while (tableData.nextRow());
} else {
System.out.println("No results found");
mConnection.disconnect();Hi Kaanu,
You have to modify your java code.
String val = new String( field.getByteArray());
PS: Please reward points for helpful answer or problem resolved. -
A field is given data type is Table icon in Function Module
Hi Experts,
I am developing HCM Reports for that I have one Function Module to retrive data from Source.
One of my Requirement is to Display One of the fields below
Field Name:
Sucessfull Candidate
Vijay
Raju
Ram
to display like this in my Function Module this fields Data Type is selected Table Icon
I think because of this the field Sucessfull Candidate is not display in Data Sources.
quires:
1. what is the procedure to get data in Reporting like above requirement.
2. what I will do to appairing the field in Data sources
3.any changes in Function Module
Regards
Vijaythanks for all participants
-
Checking table columns and data type before inserting
I have some data coming from different sources and want to insert the data from those files into multiple tables.
Before inserting the data I like to perform a check on data type, length, null etc so that I can avoid errors at the time of insert. If there is any problem with the data then I do not want to perform the insert and report the problems.
ThanksIf you have 10gR2 (10.2.0.4) you could use DML_ERROR_LOGGING.
Read about it here, see the examples: http://tkyte.blogspot.com/2005/07/how-cool-is-this.html
In short: it avoids errors during your transactions, afterwards you know which records failed and why.
It's more or less the same functionality:
your goal:
check before transactions and avoid the insert of 'bad' records. (extra code, extra maintenance, more chance of bugs)
dml_err_logging:
insert 'bad' records during transaction automatically into a dedicated error table including error message.
Edited by: hoek on Mar 24, 2009 6:56 PM -
How to get data type of variable in program..
Hi ABAP Guru.
I need to know how to get data type of variable or any structure field.. because I got short dump when use command REPLACE ALL OCCURANCE ... with variable/structure field that has data type I or P, I think it should be used with data type CHAR only, So I need to check the data type first.
Please give me your advice
Thank you all.
Nattapash C.data : v_value type i,
v_char(10) type c.
v_value = 10.
move v_value to v_char.
REPLACE ALL OCCURRENCES of '#' from v_char....
Best regards,
Prashant -
Change Date Type Description and Re Arrange
Dear Expert,
I would like to change description of each date type in block date and arrange date rows as new sequence in IC Web Client, I try to do it on t-code BSP_DLC_SDESIG_DL but I cannot, the transaction allow to adjust only field STRUCT.APPT_TYPE_DESCR description , I would like to change each date value description in this structure and arrange them. Have anyone used to do this? Please suggest me.
Best Regards,
Krin
Edited by: Krin Thongkam on Aug 3, 2010 11:22 AMHi,
If you mean the Dates assignment block; this is populated by the date profile assigned to your transaction type.
Go to SPRO --> CRM --> Transactions --> Basic Settings. You can find which date profile is used for your transaction type in the detailed view.
Then go to SPRO --> CRM --> Basic Functions --> Date Management --> Define Date Profile. Here you can check which date types are used in your profile. You can rename these using SPRO --> CRM --> Basic Functions --> Date Management --> Define Date Types, Duration Types and Date Rules. I think the sequence of the dates is determined alphabetically on date type. -
4.0 EA1 - Data Modeler does not show columns data types correctly
Data Modeler shows all columns data types as 'unknown'.
Hi,
you need to check "system data types" directory and it contents. Its default location in SQL Developer is sqldeveloper\sqldeveloper\extensions\oracle.datamodeler\types
Check "Preferences>Data Modeler>Default system data types directory" setting. If it's empty then copy defaultdomains.xml from previous installation to directory above.
If it's not empty then you need to copy types.xml and defaultRDBMSSites.xml from default location to directory set as "Default system data types directory".
Philip -
Table in Smartforms cannot use data type CURR
Hello everyone,
I have trouble with Smartform
in Main window , I want to show data in table.
in main area of table .
I want to show data of amount in document (BSEG-DMBTR)
in text of main area. I add work area W_LINE_ITEM-DMBTR.(declare W_LINE_ITEM TYPE BSEG in Global definitions)
but when i execute report program I got error message "W_LINE_ITEM-DMBTR Unknown in form"
it's appear error for data type CURR only, for data type CHAR. it is OK.
Is Smartform can show data type Curr ?
what should i do to solve problem ?
Please help.Hi,
The best way wud be just to use the "Currency/Quan. Fields" tab...
In Global definition,, go in "Currency/Quan. Fields" tab -> declare the the field as below for W_LINE_ITEM-DMBTR,,
Field Name Reference Field Data type
W_LINE_ITEM-DMBTR BSEG-DMBTR CURR
Rgs,
Lokesh.
Maybe you are looking for
-
Can't Scan to Win 10 Network Folder from HP MFP
Hi - I have an HP MFP M425dw printer/fax/scanner on a small wired Lan, (all my devices are 192.168.0.xxx) I have Win 10 TP on a pc, and Win 10 Server TP on another box I can scan from my MFP's Control Panel, to a share on my WD NAS, also to a share
-
Problem in workflow with WF-BATCH
Hi All, we have a problem in the workflow user WF-BATCH where the validity was expired and the workflow stopped working. we found the problem after a day and extended the validity and the workflow started working again. But all the interfaces related
-
How to write on Video in PXI-FarlapMode
I must write a message on video for applications that playing in PXI that work in FarlapMode,so without an graphics interface how windows!!!!
-
Question on syntax for role portion (LH side) of the credential
I am concerned about syntax for the role portion (the stuff to the left of the "@" sign). Specifically, what are the illegal characters? Can I use dashes and periods? And I presume I can intermix alpha and numeric characters, and I need to know if th
-
How does Verizon resolve customer Service issues?
I've spent the last 4 hours having no service. Talked to different representatives on the phone and made 2 trips to the store to figure out what was wrong with my device and I keep getting different answers, none of them the same. How do they respond