cancel
Showing results for 
Search instead for 
Did you mean: 

Default From date in travel expence management (FITE_UI_RECEIPT_DETAILS )

Former Member
0 Kudos

Hi All ,

I am new to webdynpro abap . My requirement is to default from date in travel expense management.

Here i am using webdynpro component FITE_UI_RECEIPT_DETAILS and view DETAILS_VIEW .

So i did the coding for testing in method WDDOINIT(). But i am getting runtime error because of NULL object reference (lo_el_receipts ) . How can i resolve this ?? Is it possible to default From date in this method ??

Please see the code which i used .

DATA lo_nd_receipts TYPE REF TO if_wd_context_node.

DATA lo_el_receipts TYPE REF TO if_wd_context_element.

DATA ls_receipts TYPE wd_this->element_receipts.

DATA lv_from_date TYPE wd_this->element_receipts-from_date.

lo_nd_receipts = wd_context->get_child_node( name = wd_this->wdctx_receipts ).

lo_el_receipts = lo_nd_receipts->get_element( ).

IF lo_el_receipts IS INITIAL.

ENDIF.

lv_from_date = '20110504'.

lo_el_receipts->set_attribute(

name = `FROM_DATE`

value = lv_from_date ).

After executing lo_nd_receipts->get_element( ) giving null value. So lo_el_receipts is initial and getiing run time error .

Is this signifies that cannot default ' from date ' using method WDDOINIT ??.Is there any alternative way to get element of node ?? please help..

Thanks in advance..

Regards,

Sijin K P.

Edited by: SIJIN K P on Jul 20, 2011 8:02 AM

Edited by: SIJIN K P on Jul 20, 2011 8:09 AM

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi ,

What ever you did is all correct,we can achieve a defaulted value by hard coding in wddoinit method or giving a value in default field of the attribute.

The above error is not because of what you wrote in the code rather it is because the cardinality of the node might be 0..1 or 0..n,which means the WD Framework will not itself create any element when it is instantiated as node cardinality is 0..1 or 0..n.

So please verify it and change it to 1..1 or 1..n else if you want to declare the cardinality as 0..1 or 0..n then please use the following code to explicitly declare the element/create the element at run time.

lo_nd_node1->create_element( receiving element = lo_el_node1 ).

lo_nd_node1->bind_element(

new_item = lo_el_node1

set_initial_elements = abap_false ).

My node is node1.

Please let me know if you have any issues more.

Former Member
0 Kudos

Hi ,

I did the coding in WDDOMODIFY() method instead of WDDOINIT() and it is updating the values which i want to defaulted .

Here i am updating FROM DATE , TO DATE , EXPENSE TYPE and DESCRIPTION . These fields are mandatory and i am able to defaulted these fields . But the problem is still i am getting messages like 'Required Field From date is empty , Required field To date is empty etc... Can anyone provide me solution for this. Actually i want remove all these messages because all mandatory fields are defaulted here .

Thanks in advance.

Regards ,

Sijil K P.

former_member199125
Active Contributor
0 Kudos

hi,

As per my idea, its better to write the code in wddoinit method, because wddomodify view will trigger for every action. Just try to hard code in wddoinit. If you have issue with wddoinit let me know

Regards

Srinivas

saravanan_narayanan
Active Contributor
0 Kudos

Hello Sijin,

just a clarification, you mentioned that you want to default the values whenever the reciept is created. Shouldn't you be defaulting the values in the create method of the receipt instead of doing it INIT or MODIFY method/

BR, Saravanan

Former Member
0 Kudos

Hi All ,

Actually i am creating an expense claim using Available credit cards . After included this credit card in expense report and if i select this report i need to default the mandatory fields (from date and to date with receipt date of credit card , Expense type with "Other ' and description according to the credit card selected ) . If i try this in WDDOINIT method i will not get receipt date from context and we are not sure which credit card ( Fuel , taxi etc )will select . So i did the code in WDDOMODIFY .

Please see the code ..

declarations ...

lo_nd_receipts = wd_context->get_child_node( name = wd_this->wdctx_receipts ).

  • @TODO handle non existant child

  • IF lo_nd_receipts IS INITIAL.

  • ENDIF.

  • get element via lead selection

lo_el_receipts = lo_nd_receipts->get_element( ).

  • alternative access via index

  • lo_el_receipts = lo_nd_receipts->get_element( index = 1 ).

  • @TODO handle not set lead selection

IF lo_el_receipts IS INITIAL.

lo_el_receipts = lo_nd_receipts->create_element( ).

ENDIF.

lo_el_receipts->get_attribute(

EXPORTING

name = `REC_DATE`

IMPORTING

value = lv_rec_date ).

lo_el_receipts->get_attribute(

EXPORTING

name = `FROM_DATE`

IMPORTING

value = lv_from_date ).

lo_el_receipts->get_attribute(

EXPORTING

name = `TO_DATE`

IMPORTING

value = lv_to_date ).

*

lo_el_receipts->get_attribute(

EXPORTING

name = `CCOMP`

IMPORTING

value = lv_ccomp ).

lo_el_receipts->get_attribute(

EXPORTING

name = `TT_COMSP`

IMPORTING

value = lv_tt_comsp ).

if lv_from_date IS INITIAL.

lv_from_date = lv_rec_date.

lo_el_receipts->set_attribute(

name = `FROM_DATE`

value = lv_from_date ).

endif.

if lv_to_date IS INITIAL .

lv_to_date = lv_rec_date.

lo_el_receipts->set_attribute(

name = `TO_DATE`

value = lv_to_date ).

endif.

if lv_tt_comsp IS INITIAL .

lv_tt_comsp = 'Z'.

lo_el_receipts->set_attribute(

name = `TT_COMSP`

value = lv_tt_comsp ).

endif.

lo_el_receipts->get_attribute(

EXPORTING

name = `DESCRIPT`

IMPORTING

value = lv_descript ).

if lv_ccomp IS NOT INITIAL AND lv_descript IS INITIAL. .

case lv_ccomp.

WHEN 'BP' or 'CL' or 'CT'.

lv_descript = 'Fuel Charge Card Expense'.

WHEN 'TC'.

lv_descript = 'Taxi Charge Card Expense'.

WHEN 'WP'.

lv_descript = 'Purchasing Charge Card Expense'.

ENDCASE.

lo_el_receipts->set_attribute(

name = `DESCRIPT`

value = lv_descript ).

ENDIF.

But still i am getting the messages ' Required field 'From date is empty , etc..

former_member199125
Active Contributor
0 Kudos

Hi..

your coding looks like having loopholes.

See below code.

IF lo_el_receipts IS INITIAL.

lo_el_receipts = lo_nd_receipts->create_element( ).

ENDIF.

lo_el_receipts->get_attribute(

EXPORTING

name = `REC_DATE`

IMPORTING

value = lv_rec_date ).

if element is initial , lv_rec_Date will not contain no value, but you are binding the same null value to another attribute..

if lv_from_date IS INITIAL.

lv_from_date = lv_rec_date. '' so here no value is there.. so you are binding blank value.

lo_el_receipts->set_attribute(

name = `FROM_DATE`

value = lv_from_date ).

endif.

So now modify ur code with proper values.

Former Member
0 Kudos

Hi sanasrinivas ,

Thank you for your reply .

But here lv_from date is from date that i need to get defaulted using lv_rec_date .

lv_rec_date will containes values when i select the receipt . I want to get default From date at this point and it is working fine.

Is there any problem with binding null value to another attribute having null value ?

I used condition if lv_from_date IS INITIAL because user want to edit this field if needed . If i am not using this condition this field will be always getting defaulted with receipt date.

But once after all these mandatory fields updated still i am getting messages like 'Required field from date is empty , etc ...

and i am able to proceed by pressing enter . I want to remove all these messages otherwise user will get confuse.

Is there any solution for this,..

Thanks in advance ,

Sijin K P

saravanan_narayanan
Active Contributor
0 Kudos

Hello Sijin

if you want to clear the messages then you can write the following code


* get message manager
data lo_api_controller     type ref to if_wd_controller.
data lo_message_manager    type ref to if_wd_message_manager.
lo_api_controller ?= wd_this->wd_get_api( ).
call method lo_api_controller->get_message_manager
  receiving
    message_manager = lo_message_manager  .

call method lo_message_manager->clear_messages
  exporting
    including_permanent_msg = ABAP_true
*    only_permanent_msg      = ABAP_FALSE
    .

But I wont prefer this. you mentioned that " if i select this report i need to default the mandatory fields ". Question is how are you selecting this report. Are there any event handler associated with the report selection?. If so can you default the mandatory values there?

BR, Saravanan

Former Member
0 Kudos

Thanks Saravanan .

I did the code in method ONACTIONSELECT_RECEIPT and used above code to remove the error messages .

Now it is working fine.

Thankyou all ..

Regards ,

Sijin K P.

Answers (3)

Answers (3)

saravanan_narayanan
Active Contributor
0 Kudos

Hello Sijin,

When do you want to default the FROM_DATE? do you want to default the FROM_DATE to system date whenever the receipt is created or by default you want to default it to 20110504.

for the first case, you need to follow the suggestion from Srinivas.

for the second case, you can maintain the default value in the context attribute FROM_DATE to 20110504. Go the properties of the FROM_DATE attribute in Context tab and maintain the default value.

hope this helps.

BR, Saravanan

Former Member
0 Kudos

Thanks sanasrinivas .

Right now i am not getting run time error but the date is not getting defaulted.

The date is hard coded only for testing whether it is possible to default the date or not and i need this requirement whenever the receiept is created.

Regards ,

Sijin K P

Edited by: SIJIN K P on Jul 20, 2011 9:01 AM

former_member199125
Active Contributor
0 Kudos

If you write the code in wddoint method, whenever the application triggers so the value will be default.

Or else write the value in "default value "property of attribute.

Regards

Srinivas

former_member199125
Active Contributor
0 Kudos

hi..

DATA lo_nd_receipts TYPE REF TO if_wd_context_node.

DATA lo_el_receipts TYPE REF TO if_wd_context_element.

DATA ls_receipts TYPE wd_this->element_receipts.

DATA lv_from_date TYPE wd_this->element_receipts-from_date.

lo_nd_receipts = wd_context->get_child_node( name = wd_this->wdctx_receipts ).

if lo_nd_receitps is initial.

lo_el_receipts = lo_nd_receipts->create_element( ).

ls_receipts-FROM_DATE = '20110504'.

LO_EL_receipts->SET_STATIC_ATTRIBUTES( EXPORTING STATIC_ATTRIBUTES = LS_receipts ).

LO_ND_receipts->BIND_ELEMENT( NEW_ITEM = LO_EL_receipts

SET_INITIAL_ELEMENTS = ABAP_FALSE ).

endif.

Regards

Srinivas

note :If you have more than one attribute in node receipts.. declare those also in if condition.

like ls_receipts-other attributes name =xxx

Regards

Srinivas

former_member199125
Active Contributor
0 Kudos

hi...

follow like below, if your node is initial, create one element and write the value

DATA lo_nd_receipts TYPE REF TO if_wd_context_node.

DATA lo_el_receipts TYPE REF TO if_wd_context_element.

DATA ls_receipts TYPE wd_this->element_receipts.

DATA lv_from_date TYPE wd_this->element_receipts-from_date.

lo_nd_receipts = wd_context->get_child_node( name = wd_this->wdctx_receipts ).

if lo_nd_receitps is initial.

lo_el_receipts = lo_nd_receipts->create_element( ).

ls_receipts-FROM_DATE = '20110504'.

LO_EL_receipts->SET_STATIC_ATTRIBUTES( EXPORTING STATIC_ATTRIBUTES = LS_receipts ).

LO_ND_receipts->BIND_ELEMENT( NEW_ITEM = LO_EL_receipts

SET_INITIAL_ELEMENTS = ABAP_FALSE ).

Regards

Srinivas