Understanding and updating MIGO defaults in ABAPPosted: July 29, 2014
Posted on SCN at http://scn.sap.com/community/abap/blog/2014/07/28/understanding-and-modifying-migos-defaults-programmatically.
Recently I had a situation where I needed to update MIGOs defaults programatically. I tried to search for a solution but couldn’t see it mentioned anywhere and hence decided to write it down . I hope that it’ll be useful for anyone in a similar situation.
MIGO is a multi-purpose transaction which can be used for various activities in material management – performing goods movements, receipt of purchase order etc. It replaces many older transactions . There are others as well but to list down a few:
- Post a goods receipt to a known purchase order (transaction MB01)
- Change a material document from goods receipts (transaction MB02)
- Display a material document from goods receipts (transaction MB03)
- Cancel a material document from goods receipts (transaction MBST)
To understand why we may need to ever need to modify MIGO defaults, consider the below situation.
– A file arrives for processing in SAP ( say as a batch job ) .
– Initial goods movement is tried using a BAPI. If the processing fails , a user SM35 BDC session is created for processing which can be reprocessed by users ( the users are familiar with MIGO ). A custom transaction for reprocessing is created as the users couldn’t be given access to SM35. SM35 allows you to display and potentially reprocess all sessions which can be tricky if the authorisations are a bit leaky.
The failed sessions can then be processed by a custom transaction – the SM35 sessions are persisted to a temporary table to be used by reprocessing transaction.
Everything looks good in theory : all automatic postings are done in background and any errors can be handled by the custom transaction. However, while the user is performing the reprocessing the MIGO session, something interesting happens – if the user opens a parallel MIGO session and performs some other processing in parallel, the subsequent sessions start to fail in the custom transaction. Users could be processing multiple sessions sequentially and might go away and do some other movements in parallel in MIGO.
Why does this happen ?
MIGO stores user’s defaults trying to optimise the usage so that the user doesn’t have to set the selections – this causes the defaults to be always set whenever you use the transaction. The parallel session which the user opened has overridden the defaults and as a result, subsequent failed sessions have different default values set in the screen even though the BDC recording used in SM35 session was set correctly. User defaults is overriding BDC set values .
Looking at the below image, the BDC session has set values A07 and R10 for action and sub-selection within action.
However, if the user choses something else in a parallel session ( say A05 and a sub-selection ) , it overrides the action default and subsequent SM35 sessions start failing as then MIGO will start with A05 / sub-selection.
MIGO stores user’s defaults in table ESDUS and these defaults correspond to MIGO_FIRSTLINE action. Seeing the below table entries, the settings for the user are:
Default is action = A07
and sub-selection for A07 is R10.
Hence, A07 / R10 will appear for ACTION and sub-selection ( as shown in above image ) .
Show Me The Code:
Now, we know where they’re stored, how to update them ?
Class CL_MMIM_USERDEFAULTS can be used to read and update the parameters. It’s a singleton and hence there should be only instance at a given time. Consequently, if we’re using it we have to ensure the instance is destroyed . This is achieved by FLUSH_ALL method of the class. Above methods are self explanatory and the constructor requires ACTION value.
So I did the following:
– Instantiate the class using ACTION as “MIGO_FIRSTLINE” and set the instance values.
– Set the values:
( i_element = ‘ACTION’
i_active = lv_action ).
– Flush the value to dB and destroy the instance
o_migo_defaults->flush( ). “Save values to dB
o_migo_defaults->flush_all( ). “Destroy this instance as others instance will start producing errors
The table has other values used in MIGO defaults ( e.g. default movement type for an action ) and can be similarly updated.