Calling a subroutine from SAP SCRIPT form .

In order to call a subroutine program from a SAP Script you have to do 2 things :

1 – write your subroutine which will take values from the script and doing some calculations on them or use them to retrieve another set of values.

2- Calling the subroutine from the SAP Script in order to Pass some values and get newly calculated one.

Here’s an overview to let you know how to write a subroutine and how to call it from your Script …. Enjoy!

** First write your subroutine **

1-      Go to se38

2-      Create a program with type “ subroutine pool “

3-      Add your form in  the subroutine program :

Form (Form_Name) TABLES in_tab  STRUCTURE  itcsy

out_tab STRUCTURE  itcsy.

ENDFORM.

4- Read Values passed from the script to the Subroutine by writing the following code :

READ TABLE  in_tab  WITH KEY  ‘ Type your value name here ‘. “Read Data into internal table (in_tab)

CHECK sy-subrc = 0. “Check if  the record was read successfully.

(your variable name) = in_tab-value. “Take the value from the internal table into a variable

5- Passing Newly calculated values back to the Script by writing the following code :

READ TABLE out_tab WITH KEY ‘ Type your output value in CAPITAL LETTERS ONLY HERE‘. ” Output Parameter”

CHECK sy-subrc = 0. Check if the data was read successfully “

out_tab-value = Your Calculated Value Parameter .

MODIFY out_tab INDEX sy-tabix . ” Passing the values again to the sap script to be displayed

Here’s a demonstrating example to show you how to use the previous code :

Form Calc TABLES in_tab  STRUCTURE  itcsy

out_tab STRUCTURE  itcsy.

READ TABLE  in_tab  WITH KEY  ‘KOMVD_KWERT‘. “Input Parameter”

CHECK sy-subrc = 0.

KOMVD_KWERT_VAR= in_tab-value.

KOMVD_KWERT_VAR = KOMVD_KWERT_VAR  *  1000 / 93889. ” Any desired calculations

READ TABLE out_tab WITH KEY ‘RESULT.” Output Parameter”

CHECK sy-subrc = 0. ” If sy-subrc = 0 then data was read successfully

out_tab-value = KOMVD_KWERT_VAR

MODIFY out_tab INDEX sy-tabix .

ENDFORM.

*********————————————————–*********

** Second calling the Subroutine from the SAP Script **

by opening your SAP Script, right click on the main window then choose edit text and add the following code :

/: PERFORM Form_Name in Subroutine_Name

/: USING &INPUT_PARAMETER&

/: CHANGING &OUTPUT_PARAMETER&

/: ENDPERFORM

Example :

/:     PERFORM Calc IN PROGRAM  Z_Test

/:      USING &KOMVD_KWERT&

/:      CHANGING &RESULT&

/:      ENDPERFORM

or you can define  your parameters first instead of using its technical names directly as follows:

/E    Calc_Line  ” Code Name

/:     DEFINE &INPUT& = &KOMVD-KWERT& “Passing Value from the script to the input parameter in the  program

/:     DEFINE &RESULT& ” Output Parameter key

/:     PERFORM Calc IN PROGRAM (Prog_Name)

/:      USING &INPUT& “Input Parameter”

/:      CHANGING &RESULT& ” Output Parameter”

/:      ENDPERFORM


36 thoughts on “Calling a subroutine from SAP SCRIPT form .

  1. Hi there! Someone in my Myspace group shared this site with us so I came
    to give it a look. I’m definitely enjoying the information. I’m bookmarking and will be tweeting this to my followers!
    Exceptional blog and brilliant design and style.

    Like

  2. you’re really a good webmaster. The web site loading speed is amazing. It seems that you’re doing any unique trick. In addition, The contents are masterpiece. you have done a fantastic job on this topic!

    Like

  3. I do trust all the ideas you’ve presented on your post. They are really convincing and will certainly work. Still, the posts are very short for newbies. May just you please extend them a little from subsequent time? Thank you for the post.

    Like

  4. Thank you, I’ve recently been searching for information about this subject for ages and yours is the best I have found out so far. But, what in regards to the bottom line? Are you certain in regards to the source?

    Like

  5. you’re really a good webmaster. The web site loading speed is incredible. It seems that you’re doing any unique trick. Also, The contents are masterwork. you’ve done a great job on this topic!

    Like

  6. I simply needed to thank you very much all over again. I’m not certain the things that I could possibly have sorted out without the entire ways shown by you about that problem. It had been a hard matter for me personally, but encountering this professional approach you processed that forced me to cry over fulfillment. Now i’m happier for the assistance and as well , trust you really know what a great job you happen to be putting in instructing the mediocre ones all through your web site. I am sure you have never come across any of us.

    Like

  7. of course like your web site but you have to check the spelling on several of your posts. Several of them are rife with spelling problems and I find it very bothersome to tell the truth nevertheless I will certainly come back again.

    Like

  8. Thank you for sharing superb informations. Your website is very cool. I’m impressed by the details that you have on this website. It reveals how nicely you understand this subject. Bookmarked this website page, will come back for extra articles. You, my friend, ROCK! I found simply the info I already searched all over the place and just couldn’t come across. What a great web site.

    Like

  9. Awsome article and straight to the point. I am not sure if this is in fact the best place to ask but do you people have any thoughts on where to employ some professional writers? Thx 🙂

    Like

  10. Thank you for another informative website. The place else may just I am getting that type of information written in such a perfect method? I have a venture that I am just now operating on, and I have been on the look out for such info.

    Like

  11. Wonderful post but I was wondering if you could write a litte more on this subject? I’d be very thankful if you could elaborate a little bit further. Cheers!

    Like

  12. I’ve been surfing online more than 3 hours today, yet I never found any interesting article
    like yours. It is pretty worth enough for me.
    In my view, if all website owners and bloggers made good content as you did, the web will be much more useful than ever before.

    Like

Leave a comment