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: 

SAP Scripts

Former Member
0 Kudos

Ho we can use subroutines in SAP scripts

Can anyoine help with some examples

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

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.

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.

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.

Reward if it helps..

Regards,

Omkar.

4 REPLIES 4

Former Member
0 Kudos

Hi,

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.

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.

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.

Reward if it helps..

Regards,

Omkar.

Former Member
0 Kudos

Hi,

for calling subroutines in script form by using PERFORM --- ENDPERFORM control commandS..

/:PERFORM <name> IN PROGRAM <program_name>

/:USING <parameter>

/:CHANGING <parameter>

/:ENDPERFORM

while calling subroutine you must pass one parameter only for one line.

you mus specifies the program name in which subroutine is available.

while declaring subroutine, you must define subroutine formal parameters of type structure ITCSY, otherwise error will be raised..

FORM <name> TABLES <input> STRUCTURE ITCSY

<output> STRUCTURE ITCSY.

here write the logic...

ENDFORM.

Refer this link

http://aiokeh.wdf.sap.corp:50000/SAPIKS2/contentShow.sap?_SCLASS=IWB_STRUCT&_SLOIO=D2CB3D07455611D18...

Regards,

Priyanka.

Former Member
0 Kudos

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.

Syntax in a form window:

/: PERFORM <form> IN PROGRAM <prog>

/: USING &INVAR1&

/: USING &INVAR2&

......

/: CHANGING &OUTVAR1&

/: CHANGING &OUTVAR2&

......

/: ENDPERFORM

Regards,

Suruchi

varma_narayana
Active Contributor
0 Kudos

Hi..

Calling Subroutine from Layout set.

Detailed procedure:

1. IN THE LAYOUT SET MAIN WINDOW

/: TOP

/E ELE_TOP

/: DEFINE &PAGE_TOTAL& = '0'

/: ENDTOP

/: MAIN

/E E

/: PERFORM GET_PAGE_TOTAL IN PROGRAM <YOUR PRINT PROGRAM>

/: USING &STVBAK-NETWR&

/: CHANGING &PAGE_TOTAL&

/: ENDPERFORM

/: BOTTOM

  • 'Page total for NETWR = ' , &PAGE_TOTAL&

/: ENDBOTTOM

CREATE THIS SUBROTINE IN YOUR PROGRAM

FORM GET_PAGE_TOTAL

TABLE INTAB STRUCTURE ITCSY

OUTTAB STRUCTURE ITCSY.

DATA : L_AMT TYPE P DECIMALS 2,

L_TOTAL TYPE P DECIMALS 2.

Read Table INTAB with KEY NAME = 'STVBAK-NETWR'.

IF SY-SUBRC = 0.

L_AMT = INTAB-VALUE.

ENDIF.

Read Table OUTTAB with KEY NAME = 'PAGE_TOTAL'.

IF SY-SUBRC = 0.

L_TOTAL = OUTTAB-VALUE.

ADD L_AMT TO L_TOTAL.

WRITE L_TOTAL TO OUTTAB-VALUE LEFT-JUSTIFIED.

MODIFY OUTTAB INDEX SY-TABIX.

ENDIF.

ENDFORM.

<b>Reward if Helpful</b>