cancel
Showing results for 
Search instead for 
Did you mean: 

How to call a subroutine from sap script

Former Member
0 Kudos

hi friends,

Can anybody tell me How to call a subroutine from sap script .

thanks n regards .

Mahesh

Accepted Solutions (0)

Answers (5)

Answers (5)

former_member633146
Discoverer
0 Kudos

/: PERFORM <FORM_NAME> IN PROGRAM <PROGRAM NAME> Fallowed by Actual Parameters.

Thanks

Former Member
0 Kudos

hi,

u can use the below code in Text elements level.

/: PERFORM <subroutine name> IN PROGRAM <prog name>

/: USING

/: CHANGING

Thanks,

Madhukar

Former Member
0 Kudos

Hi..,

n your script use a perform statement and define the form in SE38 program. Use command like in layout

/: PERFORM <NAME> IN PROGRAM ZPROGNAME

/: USING 'VAR1'.

/: USING 'VAR2'

/: CHANGING 'VAR3'

/: ENDPERFORM.

All the parameters passed with USING can be found with their names and values can be found in the internal table IN_TAB.

Note that the system passes the values as character string to the subroutine, since the field Feld VALUE in structure ITCSY has the domain TDSYMVALUE (CHAR 80).

The internal table OUT_TAB contains names and values of the CHANGING parameters in the PERFORM statement.

Goto SE38 transaction and create program ZPROGNAME.

Use the FM SPELL_AMOUNT. this FM is used to give the amount in words

FORM <NAME> TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

*........data declaration

*..............

CALL FUNCTION 'SPELL_AMOUNT'

EXPORTING

AMOUNT = PAMOUNT

  • CURRENCY =

  • FILLER = SPACE

LANGUAGE = 'E'

IMPORTING

IN_WORDS = T_SPELL

EXCEPTIONS

NOT_FOUND = 1

TOO_LARGE = 2

OTHERS = 3.

ENDFORM.

ENDFORM.

regards,

sai ramesh

Former Member
0 Kudos

PERFORM...ENDPERFORM commands in SAPscript as of 3.0C

SAP Note Number: 41302

Symptom

How should the interface syntax for FORM routines look, that is called from SAPscript layout sets using the new Release 3.0C commands PERFORM .. ENDPERFORM?

How are input values or return values treated in the form routine?

Additional key words

PERFORM, ENDPERFORM, SAPscript, user exit

Cause and prerequisites

In the CD online documentation, starting FORM routines from SAPscript is described, but not the precise syntax of the definition of FORM routines in an ABAP/4 program.

Solution

A form routine in ABAP/4, that is called with the command lines:

/: PERFORM form IN PROGRAM prog/: USING &invar1&

/: USING &invar2&.../: CHANGING &outvar1&/: CHANGING &outvar2&.../: ENDPERFORM

must be defined in the ABAP/4 report as follows:

FORM form TABLES IN_TAB STRUCTURE ITCSY OUT_TAB STRUCTURE ITCSY....ENDFORM.

Important:

The variables invar1, invar2, etc., that are passed with '/: USING ...' are SAPscript symbols with any type. Their names and values can be found in the internal table IN_TAB. Remember that the values are transferred to the FORM routine as a character string since the field VALUE owns the domain TDSYMVALUE in the structure ITCSY. Example for the access to variable invar1 in the FORM routine; the value of invar1 is then passed to the variable LOC_INVAR1 in the form routine:

...READ TABLE IN_TAB WITH KEY NAME = 'INVAR1'.LOC_INVAR1 = IN_TAB-VALUE.

Important:

The internal table OUT_TAB contains names and values for the CHANGING parameter in the PERFORM command. These parameters are local Text symbols, that is, character fields.

Example for the return of the variable OUTVAR1 in the FORM routine; the value of outvar1 is given the value from LOC_OUTVAR1:

...READ TABLE OUT_TAB WITH KEY NAME = 'OUTVAR1'.

IF SY-SUBRC = 0. OUT_TAB-VALUE = LOC_OUTVAR1. MODIFY OUT_TAB INDEX SY-TABIX.ENDIF.

Important:

The PERFORM command is not executed within SAPscript replace modules such as TEXT_SYMBOL_REPLACE or TEXT_INCLUDE_REPLACE. The replace modules can only replace symbol values or expand include texts but they cannot interpret SAPscript control commands.

Caution: You should not use number fields (for example, type I) into field ITCSY-VALUE, since these are displayed there right-aligned. To be on the safe side, work with length limitations

Regards

sathish

former_member673464
Active Contributor
0 Kudos

hi..

Calling ABAP Subroutines: PERFORM

You can use the PERFORM command to call an ABAP subroutine (form) from any program, subject to the normal ABAP runtime authorization checking. You can use such calls to subroutines for carrying out calculations, for obtaining data from the database that is needed at display or print time, for formatting data, and so on.

PERFORM commands, like all control commands, are executed when a document is formatted for display or printing. Communication between a subroutine that you call and the document is by way of symbols whose values are set in the subroutine.

The system does not execute the PERFORM command within SAPscript replace modules, such as TEXT_SYMBOL_REPLACE or TEXT_INCLUDE_REPLACE. The replace modules can only replace symbol values or resolve include texts, but not interpret SAPscript control commands.

Syntax in a form window:

/: PERFORM <form> IN PROGRAM <prog>

/: USING &INVAR1&

/: USING &INVAR2&

......

/: CHANGING &OUTVAR1&

/: CHANGING &OUTVAR2&

......

/: ENDPERFORM

INVAR1 and INVAR2 are variable symbols and may be of any of the four SAPscript symbol types.

OUTVAR1 and OUTVAR2 are local text symbols and must therefore be character strings.

The ABAP subroutine called via the command line stated above must be defined in the ABAP report prog as follows:

FORM <form> TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

...

ENDFORM.

The values of the SAPscript symbols passed with /: USING... are now stored in the internal table IN_TAB . Note that the system passes the values as character string to the subroutine, since the field Feld VALUE in structure ITCSY has the domain TDSYMVALUE (CHAR 80). See the example below on how to access the variables.

The internal table OUT_TAB contains names and values of the CHANGING parameters in the PERFORM statement. These parameters are local text symbols, that is, character fields. See the example below on how to return the variables within the subroutine.

From within a SAPscript form, a subroutine GET_BARCODE in the ABAP program QCJPERFO is called. Then the simple barcode contained there (‘First page’, ‘Next page’, ‘Last page’) is printed as local variable symbol.

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,

veeresh