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

DIVISION IN SAPSCRIPT

Former Member
0 Likes
1,226

IS THIS SYNTAX CORRECT TO GIVE IN SCRIPT FORM. NOT IN THE DRIVER PROGRAM.

/: DEFINE &TMP&

/: &TMP& = &TABLE1-FIELD1&/&TABLE2-FIELD2&

IS THIS RIGHT?

1 ACCEPTED SOLUTION
Read only

varma_narayana
Active Contributor
0 Likes
883

Hi..

We cannot perform any Arithmetic operations on the Symbols in LAYOUT SET. bcoz they are treated as Character type only.

So you need to Call a subroutine in this case.

In the Text Elements - Call the sub routine

/: DEFINE &TMP&

/: PERFORM F_DIV IN PROGRAM ZREP01

/: USING &TABLE1-FIELD1&

/: USING &TABLE1-FIELD2&

/: CHANGING &TMP&

/: ENDPERFORM

  • Result = &TMP&

In the program ZREP01 define the Subroutine

FORM F_DEV TABLES INTAB STRUCTURE ITCSY

OUTTAB STRUCTURE ITCSY .

DATA : V1 TYPE I,

V2 TYPE I,

RESULT TYPE P DECIMALS 2.

Read Table INTAB INDEX 1.

V1 = INTAB-VALUE.

Read Table INTAB INDEX 2.

V2 = INTAB-VALUE.

CHECK V2 NE 0. "for Division by 0

RESULT = V1 / V2.

WRITE RESULT TO OUTTAB-VALUE LEFT-JUSTIFIED.

MODIFY OUTTAB TRANSPORTING VALUE WHERE NAME = 'TMP'.

ENDFORM.

<b>Reward if Helpful.</b>

5 REPLIES 5
Read only

Former Member
0 Likes
883

Hi!

No, it will not work.

Assigning a Value to a Text Symbol: DEFINE Locate the document in its SAP Library structure

Text symbols acquire their values as a result of explicit assignment. To interactively assign text symbols, in the text editor choose Include ® Symbols ® Text. This method is available for all text symbols belonging to a text module as well as those of the associated form.

Values defined in this way are lost when the transaction is left. If you want to print the text module again, then you must enter the symbol values again. The purpose of the DEFINE command is to provide a means of making this value assignment a permanent part of the text, so that the values are available again when the text module is called again. This command can also be used to re-assign a new value to a text symbol half-way through the text.

Syntax:

/: DEFINE &symbol_name& = 'value'

Example

/: DEFINE &subject& = 'Your letter of 7/3/95'

The value assigned can have a maximal length of 60 characters. It may itself contain other symbols. A symbol contained within the value assigned to another symbol is not replaced with its own value at the point at which the DEFINE command is executed. Rather, this replacement is made when the symbol defined in the DEFINE command is called in the text.

That's all what DEFINE knows.

But you might try to write a small ABAP and call it with a perform:

Definition in the SAPscript form:

/: PERFORM GET_BARCODE IN PROGRAM QCJPERFO

/: USING &PAGE&

/: USING &NEXTPAGE&

/: CHANGING &BARCODE&

/: ENDPERFORM

/

/ &BARCODE&

Coding of the calling ABAP program:

REPORT QCJPERFO.

FORM GET_BARCODE TABLES IN_PAR STUCTURE ITCSY

OUT_PAR STRUCTURE ITCSY.

DATA: PAGNUM LIKE SY-TABIX, "page number

NEXTPAGE LIKE SY-TABIX. "number of next page

READ TABLE IN_PAR WITH KEY ‘PAGE’.

CHECK SY-SUBRC = 0.

PAGNUM = IN_PAR-VALUE.

READ TABLE IN_PAR WITH KEY ‘NEXTPAGE’.

CHECK SY-SUBRC = 0.

NEXTPAGE = IN_PAR-VALUE.

READ TABLE OUT_PAR WITH KEY ‘BARCODE’.

CHECK SY-SUBRC = 0.

IF PAGNUM = 1.

OUT_PAR-VALUE = ‘|’. "First page

ELSE.

OUT_PAR-VALUE = ‘||’. "Next page

ENDIF.

IF NEXTPAGE = 0.

OUT_PAR-VALUE+2 = ‘L’. "Flag: last page

ENDIF.

MODIFY OUT_PAR INDEX SY-TABIX.

ENDFORM.

Regards

Tamá

Read only

varma_narayana
Active Contributor
0 Likes
884

Hi..

We cannot perform any Arithmetic operations on the Symbols in LAYOUT SET. bcoz they are treated as Character type only.

So you need to Call a subroutine in this case.

In the Text Elements - Call the sub routine

/: DEFINE &TMP&

/: PERFORM F_DIV IN PROGRAM ZREP01

/: USING &TABLE1-FIELD1&

/: USING &TABLE1-FIELD2&

/: CHANGING &TMP&

/: ENDPERFORM

  • Result = &TMP&

In the program ZREP01 define the Subroutine

FORM F_DEV TABLES INTAB STRUCTURE ITCSY

OUTTAB STRUCTURE ITCSY .

DATA : V1 TYPE I,

V2 TYPE I,

RESULT TYPE P DECIMALS 2.

Read Table INTAB INDEX 1.

V1 = INTAB-VALUE.

Read Table INTAB INDEX 2.

V2 = INTAB-VALUE.

CHECK V2 NE 0. "for Division by 0

RESULT = V1 / V2.

WRITE RESULT TO OUTTAB-VALUE LEFT-JUSTIFIED.

MODIFY OUTTAB TRANSPORTING VALUE WHERE NAME = 'TMP'.

ENDFORM.

<b>Reward if Helpful.</b>

Read only

Former Member
0 Likes
883

Hi,

It is just a separator... Field1 / Field2....

Read only

Former Member
0 Likes
883

no

this is how u need to give value using define

/: DEFINE &symbol_name& = 'value'

/: DEFINE &symbol1& = 'mail'

/: DEFINE &symbol2& = 'SAP&symbol1&'

/: DEFINE &symbol1& = 'script'

The purpose of the DEFINE command is to provide a means of making this value assignment a permanent part of the text, so that the values are available again when the text module is called again. This command can also be used to re-assign a new value to a text symbol half-way through the text.

Read only

former_member480923
Active Contributor
0 Likes
883

You cannot do mathematical calculation inside the SAPASCript you have to do it in the following way:

define &TMP& := 0.
perform sub_calc_div in ZSCRIPT_DIVISION using &TABLE1-FIELD1&
                                                                          &TABLE2-FIELD2&
                                                            changing &TMP&.
Endperform. 

and inside the Perform Routine u have to write the Logic for division..

Hope That Helps

Anirban M.