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
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.
LikeLike
Thanks a lot Jeremy for your sweet words 🙂
Sara
LikeLike
I am sure this piece of writing has touched all the internet people, its really really pleasant piece of
writing on building up new blog.
LikeLike
Interesting help as well as links. I’ve found a few things i think will continue to work. awsome job!!!!
LikeLike
I have been examinating out some of your posts and i can claim nice stuff. I will make sure to bookmark your blog.
LikeLike
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!
LikeLike
Hi! Do you use Twitter? I’d like to follow you if that would be okay. I’m undoubtedly enjoying your blog and look forward to new posts.
LikeLike
Hi
Sorry i dont use twitter
LikeLike
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.
LikeLike
I got what you intend,bookmarked, very nice internet site.
LikeLike
Saved as a favorite, I really like your blog!
LikeLike
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?
LikeLike
I do not even understand how I stopped up here, but I believed this submit was great. I do not recognize who you are but certainly you are going to a famous blogger if you happen to aren’t already 😉 Cheers!
LikeLike
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!
LikeLike
I am impressed with this site, real I am a fan.
LikeLike
Thanks for another informative blog. Where else could I get that kind of information written in such an ideal way? I’ve a project that I’m just now working on, and I’ve been on the look out for such info.
LikeLike
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.
LikeLike
excellent post.Never knew this, thankyou for letting me know.
LikeLike
fantastic post, very informative. I wonder why the other experts of this sector do not notice this. You must continue your writing. I am confident, you have a great readers’ base already!
LikeLike
Woh I enjoy your articles, saved to favorites! .
LikeLike
Wow, superb blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your website is magnificent, as well as the content!
LikeLike
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.
LikeLike
I love the efforts you have put in this, thanks for all the great posts.
LikeLike
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.
LikeLike
It’s hard to find knowledgeable people on this topic, but you sound like you know what you’re talking about! Thanks
LikeLike
F*ckin’ amazing issues here. I am very satisfied to look your article. Thanks so much and i’m looking ahead to contact you. Will you kindly drop me a mail?
LikeLike
Hello there! Would you mind if I share your blog with my facebook group? There’s a lot of people that I think would really enjoy your content. Please let me know. Thank you
LikeLike
I went over this website and I think you have a lot of fantastic info, saved to bookmarks (:.
LikeLike
Very fantastic info can be found on web site. “The American temptation is to believe that foreign policy is a subdivision of psychiatry.” by Robert Francis Kennedy.
LikeLike
I am no longer sure where you are getting your info, however good topic. I must spend a while studying much more or understanding more. Thank you for magnificent information I used to be on the lookout for this info for my mission.
LikeLike
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 🙂
LikeLike
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.
LikeLike
Hey there, You’ve done an incredible job. I will definitely digg it and individually suggest to my friends. I’m confident they will be benefited from this website.
LikeLike
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!
LikeLike
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.
LikeLike
How much of an appealing guide, keep on making better half
LikeLike