Summation in SAP Script

To sum values in sap script, I did the following:

1-      Go to se38

2-      Create a program with type subroutine pool

3-      Add the following function to your program :

form calc_sum TABLES in_tab  STRUCTURE itcsy

out_tab STRUCTURE itcsy.

data: Sum_kwert LIKE komvd-kwert.

Read Data into internal table (in_tab)

READ TABLE in_tab WITH KEY ‘KOMVD_KWERT’.

CHECK sy-subrc = 0.

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

 “Do your Calculation here , for example summation .

 “Pass the calculated value to the script

READ TABLE out_tab WITH KEY ‘SUM_KWERT’.

CHECK sy-subrc = 0.

out_tab-value = (Your Calculated Value).

MODIFY out_tab INDEX sy-tabix .

endform.                    “calc_sum

--------------------------------------------
Then open your SAP Script , right click on the main window then choose edit text
Then open your SAP Script, right click on the main window then choose edit text and add the following code :

/E                         Sum_Line

/:                            DEFINE &KOMVD_KWERT& = &KOMVD-KWERT&

/:                            DEFINE &SUM_KWERT&

/:                            PERFORM CALC_SUM IN PROGRAM Z_LVSKOMMIL1_PROG

/:                            USING &KOMVD_KWERT&

/:                            CHANGING &SUM_KWERT&

/:                            ENDPERFORM

Advertisements

4 thoughts on “Summation in SAP Script

  1. Waldo On June 4, 2017 / 11:04 AM

    Great post. I was checking constantly this blog and I am impressed! Extremely useful information specifically the last part 🙂 I care for such info much. I was looking for this particular info for a very long time. Thank you and good luck.

    Like

    • menoshet June 6, 2017 / 9:16 AM

      Thank you so much 🙂

      Like

  2. joel September 23, 2017 / 11:55 AM

    Prachtvolle Fragen, Sie haben gerade ein Emblem gewonnen.

    Like

  3. king kong September 29, 2017 / 8:24 PM

    I’m truly enjoying the design and layout of your site. It’s a very easy on the eyes
    which makes it much more pleasant for me to come here and visit more
    often. Did you hire out a developer to create your theme?

    Outstanding work!

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s