Application Development Blog Posts
Learn and share on deeper, cross technology development topics such as integration and connectivity, automation, cloud extensibility, developing at scale, and security.
cancel
Showing results for 
Search instead for 
Did you mean: 
marc_augustin2
Active Participant

In standard, SAP provides several BAdIs and user exits to enhance applications or include custom logic flows into standard reports and dynpros. Most of the time these enhancing possibilities are sufficient, but there might come a time when a BAdI or user exit should be used, but the method’s or form’s signature isn't sufficient. One might use variables, present in the calling routine but not passed inside the current method.

To overcome this issue, there is a way called “dirty assign” that can be used. From within any abap program, class method or form, it is possible to get access to the variables of the calling routine.

The main thing about a dirty assign is using a field symbol and assigning this to a variable of the calling routine. I once had to implement a custom function for indirect evaluation of wage types in infotype 8 in HCM. SAP provides a BAdI where customer specific evaluation methods can be defined. The evaluation I had to do was based on the current activity rate of the employee, entered on the screen. As this value isn't yet saved and the value isn't passed to my BAdI’s method, I had to use a dirty assign to fetch the entered values on the dynpro.

Looking at the code in my method now, I first hat to declare a field symbol:

FIELD-SYMBOLS: <ptr> TYPE prelp.

After looking through the code of infotyp 8, I realized that the values entered on the dynpro are present in the variable cprel at PAI time, which is a copy of the infotype’s structure, filled with data.

Using an assign on the field symbol, assigning the value of the CPREL field from the calling routine gave me all I needed:

ASSIGN ('(MP000800)CPREL') TO <ptr>.

The value in brackets (here MP000800) is the name of the calling program, the variable is in, followed by CPREL, the name of the needed variable. I now had the CPREL data in my field symbol and could build my evaluation routine based on the values entered on the dynpro.

This method can almost be used in any custom code, one only have to find the name of the calling routine and the variable that should be used. Debugging is here a great help, also for evaluating if the dirty assign works correctly and gives the needed values.

As this is applicable to variables, also whole tables can be "fetched". For that, the working area has to be defined first, the field symbol has to be of type "ANY TABLE". Say we have a table called it_0008 inside MP000800, the dirty assign for that table would look like the following:

DATA: wa_0008 TYPE PA0008.

FIELD-SYMBOLS: <ptr_table> TYPE AND TABLE.

ASSIGN ('(MP000800)IT_0008[]') TO <ptr_table>.

After that assign, we have the internal table it_0008 of MP000800 in our field-symbol and can loop over it:

LOOP AT <ptr_table> INTO wa_0008.

ENDLOOP.