Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Sapscripts

Former Member
0 Likes
1,422

Dear all,

How will I define an integer variable inside my sapscript.?

Best regards,

sinthu

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,386

Hi Sinthu,

The reason for the error is because

1) the summation you are doing is on an integer value or a currency value

2) OUTTAB-VALUE is of type C. There will be compatibility issues...

To eliminate that, just do like this:

1) define the INPUT1 and INPUT as type N like this.

data: INPUT1(10) TYPE N,

INPUT(10) TYPE N.

2) define another variable (say var1) of type c and assign the summed output to this variable so that there won't be any issues in the statement

OUTTAB-VALUE = var1.

<b> I have tried out integer values in my system.. It is working properly.. </b>

FORM ADD_INCOME TABLES IN_TAB STRUCTURE ITCSY OUT_TAB STRUCTURE ITCSY.

DATA: INPUT1(10) TYPE N,

INPUT2(10) TYPE N.

LOOP AT IN_TAB .

IF IN_TAB-NAME = 'VAR'.

INPUT1 = IN_TAB-VALUE.

ELSE.

INPUT2 = IN_TAB-VALUE.

INPUT1 = INPUT1 + INPUT2.

ENDIF.

ENDLOOP.

READ TABLE OUT_TAB INDEX 1.

OUT_TAB-VALUE = VAR.

MODIFY OUT_TAB INDEX 1.

ENDFORM.

In SAPScript, write this code.

/: PERFORM ADD_INCOME IN PROGRAM ZSHAIL_BASIC

/: USING &VAR&

/: USING &ITAB-MY_INCOME

/: CHANGING &VAR&

/: ENDPERFORM.

  • &ITAB-MY_ID(Z)&,,&ITAB-MY_INCOME(Z)&,,&ITAB-MY_NAME(Z)& &VAR(Z)&

Just try it out...

Regards,

SP.

13 REPLIES 13
Read only

sbhutani1
Contributor
0 Likes
1,386

Hi sinthu,

You can use the keyword DEFINE &VAR& = 1.

This will declare a variable in sapscript.

Regards

Sumit Bhutani

Ps reward pts if helpful

Read only

Former Member
0 Likes
1,386

Hi Sinthu,

You can define an integer variable using the keyword <b>DEFINE</b>...

eg:

/: DEFINE &var1& = '0'

Regards,

SP.

Read only

0 Likes
1,386

Hi,

If I need to initilize the variable to 0,

can i write

/: DEFINE &WATOT& = 0 ???

Read only

0 Likes
1,386

SAP online documentation on window types:

Variable window content is regenerated on every new page. The content of a

constant window is generated once and printed on every page.

This means that, for better performance, windows that contain different

information on different pages must be VAR; all others are CONST. The content

of the window is defined in the SAPscript editor.

EXAMPLE....

/: DEFINE &VAR& = 1.

Read only

0 Likes
1,386

Hi again,

I'll put my question more clearly.

I need to modify the standard program for withholding tax. (J_1IEWT_CERT). In the standard pgm, the totals are not getting displayed right now but the amount in words is getting displayed.Our user wants it in figures too.

So, I am doing a perform in the sapscript,without modifying the standard pgm j_1iewt_cert in se38.

I am passing 2 varaibales as follows in the perform statment.

/:DEFINE &WA_TOTAL1& = 0

/:PERFORM TOT1 IN PROGRAM ZEWT

/:USING &PRINTTAB-WT_QSSHH(IC)& &WA_TOTAL1&

/:CHANGING &TOTAL1&

/:ENDPERFORM

For eg, if the value of &PRINTTAB-WT_QSSHH(IC)& = 50,000.00 and &wa_total1& = 0.

Now, when the program ZEWT is being executed, it throws an exception

Unable to interpret "50,000.00 " as a number

Any help will be highly appreciated...

TIA,

sinthu

Read only

0 Likes
1,386

Hi Sinthu,

The syntax of PERFORM statement is

/: PERFORM <form> IN PROGRAM <prog>

/: USING <invar1>

/: USING <invar2>

.

.

/: CHANGING <outvar1>

/: ENDPERFORM

I haven't used two parameters in the same USING statement...

Regards,

SP.

Read only

0 Likes
1,386

Sorry SP, that was a typo error. I have used 2 parameters separately by "USING".

But when my perform statement gets executed i get the error

Unable to interpret "50,000.00 " as a number.

My perform programs is as follows.

FORM TOT1 TABLES INTAB STRUCTURE ITCSY

OUTTAB STRUCTURE ITCSY.

READ TABLE INTAB INDEX 1.

INPUT = INTAB-VALUE.

READ TABLE INTAB INDEX 2.

INPUT1 = INTAB-VALUE.

WATOT1 = INPUT1 + INPUT.

CALL FUNCTION 'Z_CHAR_CURR_CONVERSION'

EXPORTING

AMOUNT = WATOT1

IMPORTING

AMOUNT1 = WATOT1.

READ TABLE OUTTAB INDEX 1.

OUTTAB-VALUE = WATOT1.

MODIFY OUTTAB INDEX 1.

ENDFORM.

Read only

0 Likes
1,386

Dear all,

Me again....

How will i convert a variable with value 50,000.00 to 50000 inside sapscript ???

Awaiting your immediate response...

TIA,

sinthu

Read only

Former Member
0 Likes
1,386

HI

GUD

Note the length specifications of the different fields. For integer types (INT1, INT2, INT4), it must not necessarily be the length defined in the ABAP Dictionary, but can also be the output length specified in the domain.

THANKS

MRUTYUN

Read only

Former Member
0 Likes
1,387

Hi Sinthu,

The reason for the error is because

1) the summation you are doing is on an integer value or a currency value

2) OUTTAB-VALUE is of type C. There will be compatibility issues...

To eliminate that, just do like this:

1) define the INPUT1 and INPUT as type N like this.

data: INPUT1(10) TYPE N,

INPUT(10) TYPE N.

2) define another variable (say var1) of type c and assign the summed output to this variable so that there won't be any issues in the statement

OUTTAB-VALUE = var1.

<b> I have tried out integer values in my system.. It is working properly.. </b>

FORM ADD_INCOME TABLES IN_TAB STRUCTURE ITCSY OUT_TAB STRUCTURE ITCSY.

DATA: INPUT1(10) TYPE N,

INPUT2(10) TYPE N.

LOOP AT IN_TAB .

IF IN_TAB-NAME = 'VAR'.

INPUT1 = IN_TAB-VALUE.

ELSE.

INPUT2 = IN_TAB-VALUE.

INPUT1 = INPUT1 + INPUT2.

ENDIF.

ENDLOOP.

READ TABLE OUT_TAB INDEX 1.

OUT_TAB-VALUE = VAR.

MODIFY OUT_TAB INDEX 1.

ENDFORM.

In SAPScript, write this code.

/: PERFORM ADD_INCOME IN PROGRAM ZSHAIL_BASIC

/: USING &VAR&

/: USING &ITAB-MY_INCOME

/: CHANGING &VAR&

/: ENDPERFORM.

  • &ITAB-MY_ID(Z)&,,&ITAB-MY_INCOME(Z)&,,&ITAB-MY_NAME(Z)& &VAR(Z)&

Just try it out...

Regards,

SP.

Read only

0 Likes
1,386

Hi SP,

Sorry for the delayed response. I tried as you told but how can i sum the variables of type n?

I have defined DATA: INPUT(10) TYPE N,

INPUT1(10) TYPE N,

WATOT1 TYPE N.

as you suggested.

now when i add input + input1 to watot1.

the value of watot1 = 0 where as it should give me 50000.

input = 50000 and input1 = 0.

any solutions ????

Read only

0 Likes
1,386

Hi Sinthu,

Just go through the code that I have sent you...

FORM ADD_INCOME TABLES IN_TAB STRUCTURE ITCSY OUT_TAB STRUCTURE ITCSY.

DATA: INPUT1(10) TYPE N,

INPUT2(10) TYPE N.

LOOP AT IN_TAB .

IF IN_TAB-NAME = 'VAR'.

INPUT1 = IN_TAB-VALUE.

ELSE.

INPUT2 = IN_TAB-VALUE.

INPUT1 = INPUT1 + INPUT2.

ENDIF.

ENDLOOP.

READ TABLE OUT_TAB INDEX 1.

OUT_TAB-VALUE = INPUT1.

MODIFY OUT_TAB INDEX 1.

ENDFORM.

In SAPScript, write this code.

/: PERFORM ADD_INCOME IN PROGRAM ZSHAIL_BASIC

/: USING &VAR&

/: USING &ITAB-MY_INCOME

/: CHANGING &VAR&

/: ENDPERFORM.

  • &ITAB-MY_ID(Z)&,,&ITAB-MY_INCOME(Z)&,,&ITAB-MY_NAME(Z)& &VAR(Z)&

Regards,

SP.

Read only

0 Likes
1,386

Thanks a lot SP.It works now.

Regards,

sinthu