cancel
Showing results for 
Search instead for 
Did you mean: 

Calling a subroutine from SAP script editor.

Former Member
0 Kudos

Hi Experts,

Can anyone tell me what is the syntax for calling a subroutine from SAP Script,

i dont want to call subroutine from my driver program,i want to fetch data dynamically from SAP Script so that same driver program will work for multiple SAP script , each will print different data,

i know that i need to work with ITCSY structure,

can some one give me a sample code for that.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

hi ,

this is the syntax .

Syntax:

/: PERFORM <form> IN PROGRAM <prog>

/: USING &INVAR1&

/: USING &INVAR2&

......

/: ENDPERFORM

i hope it may useful 4 u.

pradeep

Former Member
0 Kudos

Now this is only calling a subroutine from SAP Script,

Main part is, when i define this subroutine in some program,

after definning that subroutine how to transfer that result again back to SAP Script in changing parameter.

i dont know the concept of ITCSY structure,

so i dont know what to write in my program to transfer the value of changing parameter in SAP Script.

Former Member
0 Kudos

Hi,

Basically ITCSY structure has two fields:

NAME and VALUE.

Now when you pass values from SAP script using USING parameter.

Hence say you pass two fields &FIELD1& and &FIELD2& using the USING parameter to the program subroutine and need to get back &FIELD3& calculated back from subroutine you would do this:

/: PERFORM <form> IN PROGRAM zprog

/: USING &FIELD1&

/: USING &FIELD2&

/: CHANGING &FIELD3&

/: ENDPERFORM

the form code in the program zprog would be

FORM <form> TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

...

ENDFORM.

Here

The IN_TAB would have the folowing values

NAME VALUE

FIELD1 <value from script>

FIELD2 <value from script>

The OUT_TAB would ahve the following value

NAME VALUE

FIELD3 <v to be populated>

Then you read the internal tabls IN_TAB with key NAME = 'FIELD1' to get value of field1 and same for field2. then after performing caclulation when you need to return the value you do the following:

READ TABLE OUT_TAB WITH KEY NAME = 'FIELD3'.

IF SY-SUBRC EQ 0.

OUT_TAB-VALUE = <calculate_value>

MODIFY OUT_TAB INDEX SY-TABIX.

ENDIF.

Please refer to a very detailed explanation in help.sap.com here

[link|http://help.sap.com/saphelp_47x200/helpdata/en/d1/803279454211d189710000e8322d00/frameset.htm]

Cheers,

Aditya

Answers (0)