cancel
Showing results for 
Search instead for 
Did you mean: 

Check Mandatory - II

Former Member
0 Kudos

All,

I want check whether the field is filled or not. In this case its not String ..its Integer.

1. How can I check whether integer value populated or not (Not with zeros, because, by default its filled with zeros,)

2. Also I want to check the values are integer or not.

Thanks ..

BM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

1)First u have to create error message in Message Pool as Type error and enter text like"input field is empty"

2)Then u have to create method check mandatory with parameter "fieldname"

3)create button and also create action for that

4)In onActionButton write code

this.checkmandatory("attributename");

5)write below code in check mandatory as

IWDMessageManager msg3=wdComponentAPI.getMessageManager();

Object avalue1=wdContext.currentContextElement().getAttributeValue(fieldname);

IWDAttributeInfo ainfo2=wdContext.getNodeInfo().getAttribute(fieldname);

if(avalue1 instanceof String)

{

if(((String) avalue1).length() == 0)

{

String fieldLabel=wdContext.getNodeInfo().getAttribute(fieldname).getSimpleType().getFieldLabel();

msg3.reportContextAttributeMessage(wdContext.currentContextElement(),ainfo2,IMessageErrormsg.CHECKINPUT,new Object[]{fieldLabel},true);

}

}

Message was edited by:

Suresh T

Former Member
0 Kudos

Suresh,

As i mentioned, its not string...More over my input field always field with 8 zeros. So length will be always 8. i want to check whether it has some valid inputs not only zeros.

BM

Former Member
0 Kudos

Hi Bharathi,

I think it's better to use String instead if integer type so that u can prompt messages by checking whether it is null or empty string. In this case, u can control the length by creating a dictionary type with maximum length 8 and bind it to this string variable. It is working perfectly for me. The invalid number can be checked as Shriram suggested.

Regards

Fahad Hamsa

Former Member
0 Kudos

Fahad,

Thanks for your reply..In have mapped the field into SAP RFC Model..In SAP the data type is NUMC(8). So i cant change the type in webdynpro... In Dynpro will it be integer or String?

Also as i mentioned earlier, it always filled with 8 Zeros by default...

BM

former_member751941
Active Contributor
0 Kudos

Hi Bharathi,

Try this.

Integer custNum = new Integer(wdContext.currentContextElement().getCustomerNumber());

String cnum_st = custNum.toString();

if (cnum_st.length()== 😎

{

<Put the code that you want to perform>

// wdThis.wdGetTPMCustCompController().getCustomerDetailByNumber(cnum_st);

}

else

{

wdComponentAPI.getMessageManager().reportException("Input Field Should be of 8 characters",false);

}

Regards,

Mithu

Former Member
0 Kudos

Hi Bharati,

This can be solved by avoiding direct mapping with RFC variable. Map ordinary context variable of type String with inputfield. While submit,

convert this value to integer by using

int a=Integer.parseInt("12345678");

Then set this value to the RFC variable by

wdContext.current<nodefromRFC>().set<numVariable>(a);

Regards

Fahad Hamsa

Former Member
0 Kudos

Hi Bharati,

From your explaination what i can understand is the inputfield is alwyas filled with 8 zeros.

You want to check if the input value not empty and it is integer

Now since you dont know what the input is Integer/String

Webdynpro has inbuilt functinality to check if the input value for a field of type integer is integer or not.

And this functionality is called as soon as you trigger the action.

But even then if you want to check it then see the following code.

First check if the input value is integer as explained. If the input value is integer then exception is not thrown.

int i = 0;

boolean isInt = true;

try{

i = Integer.parseInt(wdContext.currentContextElement.getInputValue()));

}catch(NumberFormatException NFE)

{

// if it catches this exception that means the user entered value is not integer. Here you write what you want to do when the user does not enter a integer value

isInt = fasle;

}

// the above is done by webdynpro by default

if(isInt)

{

// check if the integer is zero

if(i=0)

{

// raise exception for value being zero

}

else

{

// cehck if the length is < 8

String str = String.valueOf(i);

if(str.length < 😎

{

// raise excpetion for value not being eight digit

}

}

}

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

For checking wheter a UI element value is filled or not, map it to a context attribute of type Stirng.

Since it is mapped to String type attribute, you can easily check whether it is empty or not as in your former thread.

Then if you want you can check whether it is integer or not as below

try{

int i = Integer.parseInt(wdContext.currentContextElement.getInputValue()));

}catch(NumberFormatException NFE)

{

// if it catches this exception that means the user entered value is not integer. Here you write what you want to do when the user does not enter a integer value

}