Copyright 2024 - BV TallVision IT

You can call a routine in any program from a Sapscript window element, using theĀ PERFORM ... ENDPERFORM statements. How does this work ? Read on...

First of all, please realize that this is an effective way to slow down Sapscript processing - using routines is a potential performance killer. Nevertheless it can be very useful. Here's an example that is used to compose a name of an SO10 text that needs to be included, so your text is e.g. company code specific.

First of all, set up a bit of Sapscript coding that defines 2 variables and calls the routine. This will be embedded in the Sapscript logic (SE71).

/: DEFINE &SO10_TEXTNAME& = ''
/: PERFORM COMPOSE_TEXTNAME IN PROGRAM ZHR_SAPSCRIPT_HELPER
/:   USING &MHNK-BUKRS&
/:   CHANGING &SO10_TEXTNAME&
/: ENDPERFORM.
/* Now show the text as (English) longtext: 
/: INCLUDE &SO10_TEXTNAME& OBJECT TEXT ID ST LANGUAGE EN

Note the lack of dots, Sapscript is quite picky about this. The assumption on this example is that structure MHNK is already available. The routine will pick up parameters, apply some processing and set returning parameters. Not in the usual FORM .. ENDFORM manner, but using a parameter list - like so:

FORM COMPOSE_TEXTNAME
  TABLES 
    in_tab STRUCTURE itcsy
    out_tab STRUCTURE itcsy.   
* The in_tab and out_tab internal tables are name/value sets with 
* the incoming and outgoing parameters. 

  data: lw_itcsy_in type itcsy,
   lw_itcsy_out type itcsy.

  READ TABLE in_tab INDEX 1 into lw_itcsy_in. 
  IF sy-subrc = 0 and name = 'MHNK-BUKRS'.
    READ TABLE out_tab INDEX 1 into lw_itcsy_out.  
    concatenate 'LONGTEXT_' lw_itcsy_in-value 'FOOTER' into 
      lw_itcsy_out-value. 
    MODIFY out_tab FROM lw_itcsy_out INDEX 1.
  ENDIF.

ENDFORM. 

Summarizing: your routine can do anything it needs to do in Abap. Parameters are to be picked up from IN_TAB and results are to be passed on to OUT_TAB. That's all there is to this. Don't expect an Object Oriented addition on this - backwards compatibility has it's limits.