cancel
Showing results for 
Search instead for 
Did you mean: 

what is the purpose of subroutines used in scripts

Former Member
0 Kudos

hii guru's

im new to this forum

plz give me some info regarding subroutines used in scripts

in what cases do we use them and hw to use them

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

thank u

regards

Jaipal

former_member196280
Active Contributor
0 Kudos

If you don't have the driver program in your control and want to fetch values that is not in the scope of Form/layout we use subroutine to fetch the values from table.

Ex: You want to fetch values from Ztable and display in the form.

BUt driver program is not in your control, Use Subroutine to fetch the values of Z table.

I hope this info is useful to you.

Reward points.

Regards,

SaiRam

Former Member
0 Kudos

Hi Jaipal reddy,

welcome to SDN world.

the main purpose of subroutines in script is to pass the values to print program and return with changed values.

suppose based on material number we want to fetch the plant then pass that meterial number to program. In that program we will write select statement and fetch plant from table and put into one seperate variable. Now pass that variable to script again.

Hope got the point.

Hope this helps you. Reply for queries, shall post the updates.

Regards.

Kumar.

Former Member
0 Kudos

Hi Jaipal,

When you are using a standard print program u will not be change it.

But if you want to do some programming then u can do that in a subroutine written in a different program and call that subroutine from your SAPSCRIPT.

Please see the details below.

You can call an ABAP subroutine from SapScript using the PERFORM statment. You can use this to get data without havning to cnahge the print program. In the examole below NAME is retreived from table SCUSTOM.

SapScript

/:DEFINE &CUST& = '00000021'.

/:PERFORM GET_NAME IN PROGRAM Z_BC460_EX4_HF

/: USING &CUST&

/: CHANGING &NAME&

/:ENDPERFORM.

Dear &NAME&

The ABAP routine

The ABAP routine could be defined as follows:

IMPORTANT: The structure itcsy must be used for the parameters.

REPORT Z_HENRIKF_SCRIPT_FORM .

TABLES scustom.

FORM get_name tables in_tab structure itcsy out_tab structure itcsy.

read table in_tab index 1.

select single * from scustom

where id = in_tab-value.

if sy-subrc = 0.

read table out_tab index 1.

move scustom-name to out_tab-value.

modify out_tab index sy-tabix.

else.

read table out_tab index 1.

move 'No name' to out_tab-value.

modify out_tab index sy-tabix.

endif.

    • You could also fill the output parameter table this way

  • READ TABLE out_par WITH KEY 'NAME1'.

  • out_par-value = l_name1.

  • MODIFY out_par INDEX sy-tabix.

ENDFORM.

Note that if you use more than one parameter you must use Using or Changing before every parameter !

/: PERFORM <form> IN PROGRAM <prog>

/: USING &INVAR1&

/: USING &INVAR2&

......

/: CHANGING &OUTVAR1&

/: CHANGING &OUTVAR2&

......

/: ENDPERFORM

<b>Please reward if this helps.</b>

Thanks,

Nagendranatha Reddy Y

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.

<b>Syntax in a form window:</b>

<b>/: 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.</b>

Regards

Sudheer