cancel
Showing results for 
Search instead for 
Did you mean: 

Populate initial values for one field of a table enhancement

Former Member
0 Kudos

Hi,

I created a table enhancement using AET. I informed a name for a Z table. The Z table and a new Z UI component were successfully generated and I could insert the assignment block for this new UI component successfully in the main view. In the UI Component Workbench I see my Z table in the Context as a Context Node. Everything seems to be correct, and I can insert, edit and delete entries in this table using the Assignment block, and the entries are correctly saved with the parent_id and the object_id.

The problem is that this table must have lines with fixed value for one of the fields (the first field after the object_id) for all documents created depending on the number of lines of a check table, where we will maintain values for this field using a maintenance view. The other fields of the table enhancement must be edited. I can't allow insertion of entries, I can only allow Edit. I could set the field as disabled in the GET_I_<FIELD> method and it worked. And I could hide the buttons Insert and Delete in IF_BSP_WD_DYN_BTN_CONTROL~GET_BUTTONS, and it worked.

But I don't know how to force the table to always start with fixed lines and the fixed values in this field.

What I need is:

Select values of field1 in a check table.

Ex:

ZCHECKTABLE-FIELD1
VALUE1
VALUE2

VALUE3

So, every time a new document is created, the assignment block needs to automatically bring a table like below, with only Edit button. User will fill the other fields and when the document is saved, the 3 lines must be saved in the Z table.

FIELD1
FIELD2
FIELD3
VALUE1
VALUE2
VALUE3


The next time the document is displayed, this initialization will not be necessary, the table must show what was saved, and this part of showing what is in the Z table is working because I tested first using the button Insert to insert lines, saved, closed and then when I open again the document the entries are displayed and I can edit them (So, the AET created all the necessary codes for that). It's only for the first time, to force that the table will always have these lines with field1 saved.

I am new to CRM and to BOL/GenIL, so I am facing difficulties to make this work. I tried to work with method ON_NEW_FOCUS, as this method is called from method CREATE_ZTABLE, I followed How to display a z-table in an assignment block - CRM - SCN Wiki and included new entries in the collection from the Z check table just after the call of super->on_new_focus.

The values are shown (so I had 3 lines with the first field filled) but when I saved the document, the table was not updated. As the wiki was only explaining how to display a Z table, I am sure I'm missing some steps.

Can someone give me any clue?

Thank you so much,

Anne.

Accepted Solutions (1)

Accepted Solutions (1)

nicolas_busson
Active Contributor
0 Kudos

Hello Anne,


First of all: I'd like to thank you. That's one of the best documented question I ever read here on SCN, that shows you really tried to find a solution yourself. You're great.

Now to your point: I just had a look at the wiki you mentioned, and it's dealing with value nodes... so if you copied the lines of coding included in this wiki, that's probably the reason why clicking on save will not persist your data.


In method ON_NEW_FOCUS, you should have something like that:

lr_entity ?= focus_bo.

" Let's get the values for our custom table

lr_children = lr_entity->get_related_enties( <your relationship> ).

if lr_collection is not bound or lr_collection->size( ) eq 0.

  if lr_entity->is_locked( ) eq abap_true.

    " No values + change mode means pre-fill is necessary

    " First entry:

    lr_child = lr_entity->create_related_entity( <your relationship> ).

    lr_child->set_property( ... ).

    lr_collection->add( lr_child ).

    " Do the same for other entries.

  endif.

endif.


me->set_collection (lr_collection ).


Hope that helps.

Regards,

Nicolas.

stephenjohannes
Active Contributor
0 Kudos

Just to play devils advocate and to learn more myself:  Is there any reason why this couldn't be done using the enhnacement spot AXT_RT_TABLES and then using the BADI AXT_RT_TABLES_API instead.  I really hate putting any type of logic in the UI such as defaulting values, so can you avoid this that way?  I apogolize in advance for muddling the waters.

Take care,

Stephen

stephenjohannes
Active Contributor
0 Kudos

Digging further I found this blog on using the BADI approach instead. 


Take care,

Stephen

nicolas_busson
Active Contributor
0 Kudos

Hi Stephen,

Thanks a lot for chiming in!

I do think it's always a better option to add your logic in a BAdI too... but sometimes it just takes too much time to find the right spot for something that will take 2 minutes to implement in UI if that covers 100% of business needs (I know, I'm lazy). And I think this is one of those cases: because as far as I understand, those 3 rows need to be inserted automatically once the document is created... so I'm quite sure AXT BAdIs won't help because they will be called too late in the process (remember that Anne wants to prevent lines from being inserted by end users).

IMHO if this kind of logic is to be executed in background too, we would need to put some coding in a place like "AFTER_CREATE" of the parent object... And I guess CRMV_EVENT would be a good choice if "document" in the initial thread meant "business transaction". But I'm not so sure about that.

Anne, may you please confirm which type of CRM object you are enhancing? Because Stephen is definitely right, maybe you could put your logic somewhere else, that would make it work in every situation (not only when users are creating an object from WebUI).

Cheers,

Nicolas.

Former Member
0 Kudos

Hi Nicolas and Stephen,

  First of all, thank you so much for your support!

  I am enhancing a business transaction, sorry for not mentioning it before. The enhanced object is SERVICE_REQUEST_FOR_CHANGE, the parent_name is BTAdminH and the relation_name is ZAEXT_BOL_RELAT000000, generated by AET.

After reading your replies my understanding of my debugs are much better.

Nicolas, I will try to follow your code and see how it goes.

Again, thank you for the very helpful answers of both of you.

Best regards,

Anne

Answers (0)