cancel
Showing results for 
Search instead for 
Did you mean: 

Dec a varaible in Sap Script

Former Member
0 Kudos

Hi All,

I am working on a sap script, in that particular sap script it's pulling the value in a variable $ &EXTPREM(C), and it's looping through twice and each time it's pulling two diff values...lets say first time it will pull $50 and second time it will pull $90...and now I want to diaplay the total of both these values..I might need to declare a variable and then pass the value into it and then add it...but I am not good with SAP Script...so can you please tell me how can I declare a variable in it and thn how can I do the total...

Thanks,

Rajeev

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi all,

I have defined the this variable in my SAP SCRIPT

/:DEFINE &TOTAL&

when I reach to the following step:

/:&TOTAL& = &MTHPREM(C)&

/:&TOTAL& = &TOTAL& + &TOTAL&

it gives me this message:

Text command &TOTAL& is not defined

Can you please tell me where I am wrong...

Thanks,.

Rajeev

Former Member
0 Kudos

I do not think you can do arithematic operations in scripts....use routines....

If not try declaring your variable like below:

/:DEFINE &LV_COUNT&:= ' ' (Variable can be of any name...)

Former Member
0 Kudos

Hi Narendra,

Thanks for replying...I tried doing /:DEFINE &LV_COUNT&:= ' ' this also..but I am getting the same kind of error

Former Member
0 Kudos

as I have mentioned earlier...arithematic operations in scripts isnt just possible ... comment out that line where u have done the same...and chk it out now...

get a subroutine in place for the same.

Regards,

Narendra.

Former Member
0 Kudos

Thanks for the reply Narendra, can you please tell me how can I write a subroutine to this and thn how can i add that too the sap script...i have never done this before and I will appreciate if you can help me out with this..

Thanks,

Rajeev

Former Member
0 Kudos

Hi,

In Script write like this.

/: PERFORM TOTAL IN PROGRAM Z_MM_R_MMPO

/: Using &TOTAL&

/: Changing &final&

P1 &final&-----it will displays the sum of(50 + 90) total value.

Here Z_MM_R_MMPO is u r subroutine program. Create this in SE38.

after write below code in SE38 program

FORM TOTAL TABLES IN_TAB STRUCTURE ITCSY "#EC *

OUT_TAB STRUCTURE ITCSY. "#EC CALLED

Data : v_final type i,

v_final1 type c.

READ TABLE IN_TAB WITH KEY NAME = 'TOTAL'.

if sy-subrc is initial.

v_final = v_final + IN_TAB-VALUE.

endif.

v_final1 = v_final.

READ TABLE OUT_TAB WITH KEY NAME = 'FINAL'.

if sy-subrc is initial.

OUT_TAB-VALUE = v_final1.

MODIFY OUT_TAB INDEX SY-TABIX.

endif.

ENDFORM.

Former Member
0 Kudos

You should be able to do that from what Usha has quoted...just try it out..remember variables passed to routines will be in char format and those passed back to the script will also b in the same format....itcsy structure will have a char fomat field...jus have a look at the structure...

Answers (0)