cancel
Showing results for 
Search instead for 
Did you mean: 

Setting default Plant in the MDG-M UI

Former Member
0 Kudos

Hi Gurus,

The requirement is to set the Plant as default in the MDG-M UI screen. I have tried to add the default plant in the BADi 'USMD_RULE_SERVICE', Interface 'IF_EX_USMD_RULE_SERVICE~DERIVE_ENTITY'.

CASE id_entitytype.

     
WHEN 'MARCATP'.                                       "#EC NOTEXT

       
IF lines( ct_data ) EQ 1.

         
ASSIGN ct_data TO <lt_data>.

         
LOOP AT <lt_data> ASSIGNING <ls_data>.

           
IF <ls_data> IS ASSIGNED.

              ASSIGN COMPONENT 'WERKS' OF STRUCTURE <ls_data> TO <lv_werks>.

           IF <lv_werks> IS ASSIGNED AND <lv_werks> IS INITIAL.

              GET PARAMETER ID 'RWK' FIELD lv_ref_werks.

                <lv_werks> = lv_ref_werks.

             ENDIF.

           
ENDIF.

         
ENDLOOP.

       
ENDIF.
   
ENDCASE.

The problem is Entity type 'MARCATP' is not getting triggered while the first time Create Material screen appreas. Hence my code is not working.

Can you please help?

Accepted Solutions (1)

Accepted Solutions (1)

bavinash1
Explorer

Hello Arnab,

This can still be achieved by cross entity BAdI. I did this using the below code:

    lv_entity = <Entity>

*   Get the material number from read data

     io_changed_data->read_data(

       EXPORTING

         i_entity               lv_entity   " Entity Type

       IMPORTING

         er_t_data_ins          =   DATA(lr_ins_data" newly added data records

         er_t_data_upd          =   DATA(lr_upd_data" data records changed

     ).

     ASSIGN lr_ins_data->* TO <lt_ins_mat_data>.

     CHECK <lt_ins_mat_data> IS ASSIGNED and <lt_ins_mat_data> IS INITIAL.

     * You might have to add extra condition to make sure you are inserting it only for the first time, check could be, say having insert data for material itself. -> because that happens only when you launch.

    lv_fieldname = <entity>.

     io_model->create_data_reference(

           EXPORTING

             i_fieldname          = lv_fieldname

             i_struct             = if_usmd_gov_api_entity=>gc_struct_key_attr

             i_tabtype            = if_usmd_model_ext=>gc_tabtype_standard

           IMPORTING

             er_data              = DATA(lr_data_tab)

         ).

     ASSIGN lr_data_tab->* TO <lt_new_marc>.

     * Insert the data into the new <lt_new_marc> table

*   Write derived plant data to the material being created.

     io_write_data->write_data(

       EXPORTING

         i_entity            if_mdg_bs_mat_gen_c=>gc_entity_marcbasic

         it_data             = <lt_new_marc>

     ).


But yes, you can achieve your use case by normal rule service BAdI as well.


Best Regards,

Avinash Bolisetty

Former Member
0 Kudos

Hi Avinash,

It really worked. Thanks for your great help!

Arnab

Answers (2)

Answers (2)

bavinash1
Explorer
0 Kudos

Hello Arnab,

Firstly, if you are trying to add data of plant, based on data of another entity plant data ATP, this is not the BAdI that we have to use.

Correct solution, as someone already suggested is to use this cross entity BAdI. We get a better control there. Even if the entity you are looking for isn't getting filled in the first run of check cycle, you get insert data, update -> old and new and delete data wrt to each entity in every run of check cycle. Then, just use something like the below code to add whatever entity data you need to add.

    io_write_data->write_data(

       EXPORTING

         i_entity            if_mdg_bs_mat_gen_c=>gc_entity_mardstor

         it_data             = <lt_new_mard_stor>

     ).


This should definitely address the use case.


In case there's some specific use case because of which you still want to stick to rule service BAdI itself, then we can start with checking

1. if the derivations are set to active for this CR type and CR step.

2. If active at CR Type and CR step level, make sure they are not disabled for the entity in question.

3. Also, rule service isn't a multiple use BAdI. Check if that is having any impact.

and finally, if nothing else is working, you can start with debugging from cl_usmd_conv_som_gov_api->check method and see why your BAdI alone isn't getting triggered.

Hope this helps.

Best Regards,

Avinash Bolisetty

Former Member
0 Kudos

Hi Avinash,

Thanks for your detailed response. My requirement is not to populate Plant based on some value. The requirement is to default Plant to some value so that User can see a default plant when he first open the Create Material screen in MDG. As BRF+ derivation is not working for Plant (it is working for Material Basic data like Base Unit of Measure) I need the BAdi to pre populate the value into the UI.

Rule service BAdi is definitely getting triggered for me, but I don't have the appropriate entity to populate Plant in the first place.

Hope the requirement is clear now. Appreciate your further input.

0 Kudos

try this badi USMD_RULE_SERVICE_CROSS_ET

Former Member
0 Kudos

Thanks Akash for your response. But the problem with this BAdi is it will not trigger for MARCATP entity type until you pass any Plant related data. I need the default plant at the initial screen when user press Create Material button in MDG screen.

0 Kudos

ok , what is the filter value assigned for your badi implementation , it should not be on entity type .

must be on  model = MM , hope this will work

Former Member
0 Kudos

Hi Akash,

Yes, it is on MODEL = MM. But still not working.