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: 

how to use perform statements in sap scripts

Former Member
0 Kudos
1,518

how to use perform statements in sap scripts . and pls send me one progam for this

thnaks

raja

1 ACCEPTED SOLUTION

Former Member
0 Kudos
217

Hi,

/: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 ouput 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

*Hope this will help you

Message was edited by: Palak Limbachiya

5 REPLIES 5

Former Member
0 Kudos
218

Hi,

/: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 ouput 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

*Hope this will help you

Message was edited by: Palak Limbachiya

0 Kudos
217
A sample code of how to use performs in sap scripts.

In script program,

/:PERFORM GET_SBGRP_STEXT IN PROGRAM ZSDSCRIPT
/:USING &GV_MATNR&
/:CHANGING &GV_STEXT&
/:TABLES INPUT_TABLE
/: OUTPUT_TABLE
/:ENDPERFORM


In program ZSDSCRIPT,

form get_sbgrp_stext tables intab structure itcsy
outab structure itcsy.

DATA: LV_MATNR LIKE MARA-MATNR,
LV_TEXT(3) TYPE C VALUE 'ABC'.
clear intab.
read table intab with key name = 'GV_MATNR'.
if sy-subrc = 0.
lv_MATNR = intab-value.
ENDIF.

CLEAR OUTTAB.
READ TABLE OUTAB WITH KEY NAME = 'GV_STEXT'.
IF SY-SUBRC = 0.
OUTAB-VALUE = LV_TEXT.
modify outab index sy-tabix.
ENDIF.

endform.

Former Member
0 Kudos
217

http://www.iconet-ltd.co.uk/sample_entry.php?id=14

REPORT YLSD999A.

DATA W_LENGTH TYPE I.

  • GENERAL PURPOSE SUBROUTINES FOR CALLING FROM SAPSCRIPTS

*----

-


*----

-


FORM DISPLAY_POUND TABLES IN_TAB STRUCTURE ITCSY

OUT_TAB STRUCTURE ITCSY.

DATA: COUNT TYPE P VALUE 16.

DATA: W_VALUE(17) TYPE C. "defined as 7 chars to remove pence

DATA: W_CHAR TYPE C.

DATA: W_DUMMY TYPE C.

DATA: W_CURR(3) TYPE C.

  • Get first parameter in input table.

READ TABLE IN_TAB INDEX 1.

WRITE IN_TAB-VALUE TO W_VALUE .

  • get second parameter in input table

READ TABLE IN_TAB INDEX 2.

MOVE IN_TAB-VALUE TO W_CURR.

IF W_CURR = 'GBP'.

W_CURR = '£'.

ENDIF.

W_LENGTH = STRLEN( W_CURR ).

  • look for first space starting at right.

WHILE COUNT > -1.

W_CHAR = W_VALUE+COUNT(1).

  • W_CHAR = IN_TAB-VALUE+COUNT(1).

IF W_CHAR = ' '.

COUNT = COUNT - W_LENGTH + 1.

W_VALUE+COUNT(W_LENGTH) = W_CURR.

COUNT = -1.

ELSE.

  • W_VALUE+COUNT(1) = W_CHAR.

COUNT = COUNT - 1.

ENDIF.

ENDWHILE.

  • read only parameter in output table

READ TABLE OUT_TAB INDEX 1.

OUT_TAB-VALUE = W_VALUE.

MODIFY OUT_TAB INDEX SY-TABIX.

ENDFORM.

Best Regards,

Vibha

*Please mark all the helpful answers

Former Member

messier31
Active Contributor
0 Kudos
217

Hi Raja,

<b>PERFORM</b> key work is used to include subroutine in sapscript form...

But the processing is lttle bit different form the one we use in ABAP.

Here the paramters passed to form is stored in internal table of name-value table. there are two table one for inbound parameter and other for outbound parameters.

Check out the example below to see how this is used..

<b>Definition in the SAPscript form:</b>

/: PERFORM GET_BARCODE IN PROGRAM QCJPERFO

/: USING &PAGE&

/: USING &NEXTPAGE&

/: CHANGING &BARCODE&

/: ENDPERFORM

/

/ &BARCODE&

<b>Coding of the calling ABAP program:</b>

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.

Hope this is clear to understand...

Enjoy SAP.

Pankaj Singh.