Call (Report-)Function from Class Method to change screen title

1.4k Views Asked by At

I wanna change my titlebar in a dynpro when a specific class method is triggered. So I thought I could call a function in my report, where my dynpro is located, which changes uses the 'SET TITLE' to change the titlebar content.

Is this possible and how exactly? Or is there even a better way?

Thanks!

2

There are 2 best solutions below

0
On

Use SET TITLEBAR during the PBO processing - it doesn't matter if it is used from a method, a FORM or the module directly. I'd recommend having one single SET TITLEBAR statement that is always called at the same point in the control flow instead of littering the code with SET TITLEBAR statements for better maintainability.

0
On

Recently I needed to implement something similar so I defined a class hierarchy where I created an abstract class with a method 'CALL_DYNPRO'. This method is intended to load an specific dynpro in the concrete classes.

So, depending on an action I defined internally I generate the appropriate instance and then the method 'CALL_DYNPRO' loads the dynpro I created with their own gui statuses and titles.

The following is more or less the code I created.

********************************* The abstract class
class lc_caller definition abstract.
  public section.
    methods: call_dynpro.
endclass.

class lc_caller implementation.
  method call_dynpro.
  endmethod.
endclass.

********************************* The concrete classes
class lc_caller_01 definition inheriting from lc_caller.
  public section.
    methods: call_dynpro redefinition.
endclass.

class lc_caller_01 implementation.
  method call_dynpro.
    call screen 101.
  endmethod.
endclass.

class lc_caller_02 definition inheriting from lc_caller.
  public section.
    methods: call_dynpro redefinition.
endclass.

class lc_caller_02 implementation.
  method call_dynpro.
    call screen 102.
  endmethod.
endclass.

********************************* Factory    
class caller definition.
  public section.
  class-methods call importing i_type type char01 
                returning value(r_instance) type ref to lc_caller.
endclass.

class caller implementation.
  method call.
    data: caller1 type ref to lc_caller_01,
          caller2 type ref to lc_caller_02.
    case i_type.
      when '0'.
        create object caller1.
        r_instance = caller1.
      when '1'.
        create object caller2.
        r_instance = caller2.
      when others.
    endcase.
  endmethod.
endclass.

start-of-selection.
data obj type ref to lc_caller.
obj = caller=>call( '0' ).
obj->call_dynpro( ).

This is the code inside the PBOs.

Dynpro 101

module status_0101 output.
  set pf-status 'FORM1'.
  set titlebar 'VER'.
endmodule.

Dynpro 102

module status_0102 output.
  set pf-status 'FORM2'.
  set titlebar 'TRA'.
endmodule.

If tomorrow I need to call another dynpro I create it and then code the concrete class to load it.

Very straightforward and works very nice.

Hope it helps.