How to create and call a subroutine from a sapscript…

26 09 2013

Imagine that you need to get more information to be used in a sapscript form and it’s not possible to change the print program.

There is a way to do it by using subroutines of another program.

To do it, you need to modify your sapscript window and add some code as command line:

/:	 	PERFORM test_subroutine IN PROGRAM Z_SAP_SCRIPT_PERFORMS
/:	 	USING &EKKO-EBELN&
/:	 	CHANGING &TEST1&
/:	 	CHANGING &TEST2&
/:	 	ENDPERFORM

And create a program with the same name you’ve indicated before (e.g.: Z_SAP_SCRIPT_PERFORMS) to include your subroutines logic. For instance:

* the IN and OUT parameters go inside in_tab structure itcsy and out_tab structure itcsy:
form test_subroutine tables in_tab structure itcsy
                            out_tab structure itcsy.
                         
* Normal data declaration
  data: l_in1 type string,
        l_out1 type string.
        l_out2 type string.

* Reading parameters from sapscript form:
  read table in_tab index 1.
  move in_tab-value to l_in1 .

* SELECT SOME DATA into l_out1 e l_out2

* Exporting/Returning the selected data to the sapscript form (TEST1 and TEST2 variables, respectively):
  read table out_tab index 1.
  out_tab-value = l_out1.

  modify out_tab index 1.

  read table out_tab index 2.
  out_tab-value = l_out2.

  modify out_tab index 2.

endform.

That’s it!


Actions

Information

Leave a comment