Application Development 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: 

Scripts

Former Member
0 Kudos

Whatt are Include programs?

Can you use"if then else","perform" etc statements in sap scripts? if yes, how do we use them?

2 REPLIES 2

Former Member
0 Kudos

yes .

Script Language

Use

You can use the scripting language to embed script elements into the content of e-mail templates. As with the UNIX script languages, a grave accent (`) character is used to begin and close the script elements.

The scripting language used in the GP email templates supports checking conditions, basic mathematical functions, using built-in parameters and accessing context parameters. For more information on how to access context parameters, built-in parameters and the built-in process roles, see Replacements.

The basic syntax of the scripting language is described in this documentation.

Basics of the Script Language

General language elements

Syntax

Description

eval(expression)

Evaluates an expression

exists(expression)

Checks the existence of a context variable

write(expression)

Writes its argument into the content of the e-mail

writeln(expression)

Writes its argument into the content of the e-mail and appends a new line to it

fcount(expression)

Reserved, but not used by GP

` writeln( " This text will be displayed in the email " )`

Flow control elements

Syntax

Description

if (expression) {…} else {…}

C like if command (please note the else branch is not optional, but mandatory)

`i = 1;

if( i == 1 ) { `i is 1

` } else { `i is not 1

` };

switch (expression) {

case expression1: …

break;

case expressionn: …

default: …

}

C like switch command

`i = 1;

while( i < 4 ) {

switch( i ) {

case 1: `with break

` break;

case 2: `no break -> default

`

default: `the default`

}

i = i + 1;

} `

while (expression) {…}

C like while command

`i = 1;

while( i < 4 ) {writeln(i); i = i + 1; }`

loop

Reserved, but not used by GP

loopidx

Reserved, but not used by GP

stop

Stops processing of the file (HTML template file/plain text file containing the script)

String handling functions

Syntax

Description

codejs(string)

Not used by GP

codeurl(string)

Encoding a string into URL encoded string

substr

Returns a substring of the string

len(string)

Returns the length of the string

`writeln( " name@company-emailaddress.com " );

string2 = codeurl( " name@company-emailaddress.com " );

write( string2 )`

Mathematical functions

Syntax

Description

not(number)

Negation

add(number, number)

Addition

sub(number, number)

Subtraction

div(number, number)

Division

mod(number, number)

Mod

mul(number, number)

Multiplication

`writeln( mod( 3, 2 ) );`

Comparison

Syntax

Description

==

Equal

<

Less than

>

Greater than

<=

Less than or equal

>=

Greater than or equal

`i = 1; i2 = 2;

if( i <= i2 ) { ` i < i2

` } else { `i2 > i

` }

i = 2; i2 = 1;

if( i <= i2 ) { ` i < i2

` } else { `i2 > i

` }

i = 2; i2 = 2;

if( i <= i2 ) { ` i <= i2

` } else { `i2 > i

` }

Former Member
0 Kudos

Check this programme a subroutine is coded at the end that is caliing from sap script.

REPORT YPAYER .

TABLES: PAYR.

--


Internal table declaration----

data: z_itab like payr occurs 0 with header line.

data: z_tline like standard table of tline with header line.

-----end of declaration--


data: words type spell.

--


defining selection-screen--

selection-screen:begin of block b1 with frame title t1.

select-options: zbukr for z_itab-zbukr.

select-options: vblnr for z_itab-vblnr.

select-options: hbkid for z_itab-hbkid.

select-options: gjahr for z_itab-gjahr.

selection-screen: end of block b1.

---end-of-screen--


--


start-of-selection--

start-of-selection.

select single znme1 znme2 znme3 znme4 vblnr rwbtr from payr into

corresponding

fields of z_itab where zbukr in zbukr

and vblnr in vblnr

and hbkid in hbkid

and gjahr in gjahr.

end-of-selection.

data: n type i.

loop at z_itab.

describe table z_itab lines n.

endloop.

write: / n.

write: / z_itab-vblnr.

*write: z_itab-vblnr.

----


functon called to convert amount in words -

CALL FUNCTION 'SPELL_AMOUNT'

EXPORTING

AMOUNT = z_itab-rwbtr

CURRENCY = 'INR'

  • FILLER = ' '

LANGUAGE = SY-LANGU

IMPORTING

IN_WORDS = words.

  • EXCEPTIONS

  • NOT_FOUND = 1

  • TOO_LARGE = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'READ_TEXT'

EXPORTING

CLIENT = SY-MANDT

ID = 'F04'

LANGUAGE = 'D'

NAME = '450000007'

OBJECT = 'EKKO'

  • ARCHIVE_HANDLE = 0

  • LOCAL_CAT = ' '

  • IMPORTING

  • HEADER =

TABLES

LINES = Z_TLINE.

  • EXCEPTIONS

  • ID = 1

  • LANGUAGE = 2

  • NAME = 3

  • NOT_FOUND = 4

  • OBJECT = 5

  • REFERENCE_CHECK = 6

  • WRONG_ACCESS_TO_ARCHIVE = 7

  • OTHERS = 8

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

break-point.

write: z_tline-TDLINE.

CALL FUNCTION 'OPEN_FORM'

EXPORTING

  • APPLICATION = 'TX'

  • ARCHIVE_INDEX =

  • ARCHIVE_PARAMS =

DEVICE = 'PRINTER'

DIALOG = 'X'

FORM = 'ZSD_PAYER'

LANGUAGE = SY-LANGU

  • OPTIONS =

  • MAIL_SENDER =

  • MAIL_RECIPIENT =

  • MAIL_APPL_OBJECT =

  • RAW_DATA_INTERFACE = '*'

  • SPONUMIV =

  • IMPORTING

  • LANGUAGE =

  • NEW_ARCHIVE_PARAMS =

  • RESULT =

  • EXCEPTIONS

  • CANCELED = 1

  • DEVICE = 2

  • FORM = 3

  • OPTIONS = 4

  • UNCLOSED = 5

  • MAIL_OPTIONS = 6

  • ARCHIVE_ERROR = 7

  • INVALID_FAX_NUMBER = 8

  • MORE_PARAMS_NEEDED_IN_BATCH = 9

  • SPOOL_ERROR = 10

  • CODEPAGE = 11

  • OTHERS = 12

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

COMMAND = 'PROTECT'

  • EXCEPTIONS

  • UNOPENED = 1

  • UNSTARTED = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'WRITE_FORM'

EXPORTING

ELEMENT = 'ELE'

FUNCTION = 'SET'

TYPE = 'BODY'

WINDOW = 'MAIN'

IMPORTING

PENDING_LINES = Z_ITAB.

  • EXCEPTIONS

  • ELEMENT = 1

  • FUNCTION = 2

  • TYPE = 3

  • UNOPENED = 4

  • UNSTARTED = 5

  • WINDOW = 6

  • BAD_PAGEFORMAT_FOR_PRINT = 7

  • SPOOL_ERROR = 8

  • CODEPAGE = 9

  • OTHERS = 10

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

CALL FUNCTION 'CONTROL_FORM'

EXPORTING

COMMAND = 'ENDPROTECT'

  • EXCEPTIONS

  • UNOPENED = 1

  • UNSTARTED = 2

  • OTHERS = 3

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

*CALL FUNCTION 'WRITE_FORM'

  • EXPORTING

  • ELEMENT = 'ELE1'

  • FUNCTION = 'SET'

  • TYPE = 'BODY'

  • WINDOW = 'HEADER'

  • IMPORTING

  • PENDING_LINES = Z_TLINE.

    • EXCEPTIONS

    • ELEMENT = 1

    • FUNCTION = 2

    • TYPE = 3

    • UNOPENED = 4

    • UNSTARTED = 5

    • WINDOW = 6

    • BAD_PAGEFORMAT_FOR_PRINT = 7

    • SPOOL_ERROR = 8

    • CODEPAGE = 9

    • OTHERS = 10

  • .

*IF SY-SUBRC <> 0.

    • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

    • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

*ENDIF.

CALL FUNCTION 'CLOSE_FORM'

  • IMPORTING

  • RESULT =

  • RDI_RESULT =

  • TABLES

  • OTFDATA =

  • EXCEPTIONS

  • UNOPENED = 1

  • BAD_PAGEFORMAT_FOR_PRINT = 2

  • SEND_ERROR = 3

  • SPOOL_ERROR = 4

  • CODEPAGE = 5

  • OTHERS = 6

.

IF SY-SUBRC <> 0.

  • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

  • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

FORM PREVIOUS_INFO TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

data: z_name1 type payr-znme1.

  • read BILLNO line of inttab

READ TABLE IN_TAB WITH KEY 'z_itab-znme1'.

CHECK SY-SUBRC = 0.

Z_NAME1 = IN_TAB-VALUE.

  • select from vbrp and modify out_tab with new data

SELECT SINGLE * FROM PAYR

WHERE ZNME1 = Z_NAME1.

IF SY-SUBRC = 0.

READ TABLE OUT_TAB with key 'z_vblnr'.

MOVE PAYR-VBLNR TO OUT_TAB-VALUE.

MODIFY OUT_TAB INDEX SY-TABIX.

ELSE.

READ TABLE OUT_TAB INDEX 1.

MOVE 'no data' TO OUT_TAB-VALUE.

MODIFY OUT_TAB INDEX SY-TABIX.

ENDIF.