Application Development and Automation 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: 
Read only

EXTERNAL SUBROUTINE IN SAP SCRIPT

Former Member
0 Likes
1,071

CAN ANY PLEASE SEND ME THE CODE OF EXTERNAL SUBROUTINE IN SCRIPT...FOR EXMAPLE TO ADD A FIELD IN SCRIPT

3 REPLIES 3
Read only

Former Member
0 Likes
644

Hi,

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

chk this sample code of driver program:

REPORT ZVKKSCRIPTS1 .

data: v_mat like mara-matnr,

var1 like makt-maktx.

form subroutine tables itab structure itcsy

otab structure itcsy.

read table itab with key name = 'IT_VBAP-MATNR'.

if sy-subrc = 0.

v_mat = itab-value.

select single maktx from makt into var1

where matnr = v_mat and

spras = sy-langu.

if sy-subrc = 0.

read table otab with key name = 'VAR1'.

if sy-subrc = 0.

otab-value = var1.

modify otab index sy-tabix.

endif.

endif.

endif.

endform.

Check these..

http://help.sap.com/saphelp_erp2005/helpdata/en/d1/803279454211d189710000e8322d00/frameset.htm

https://forums.sdn.sap.com/click.jspa?searchID=1737102&messageID=2572731

Regards,

Padmam.

Read only

varma_narayana
Active Contributor
0 Likes
644

HI..

for example we want to pass the KNA1-KUNNR from the layout set to the print program to get the KNA1-NAME1 value using the subroutine.

<b>THIS IS THE SUBROUTINE CALL IN LAYOUTSET TEXT ELEMENTS:</b>

/: DEFINE &NEWFIELD& = ' '

/: PERFORM GET_VAL IN PROGRAM ZPR1

/: USING &KNA1-KUNNR&

/: CHANGING &NEWFIELD&

/: ENDPERFORM

  • RESULT = &NEWFIELD&

<b>SUBROUTINE DEFINITION IN THE PROGRAM: ZPR1</b>

FORM GET_VAL TABLES INTAB STRUCTURE ITCSY

OUTTAB STRUCTURE ITCSY.

DATA : V_NAME1 TYPE KNA1-NAME1.

read table INTAB with key NAME = 'KNA1-KUNNR'.

if sy-subrc = 0.

SELECT SINGLE NAME1

FROM KNA1 INTO (V_NAME1)

WHERE KUNNR = INTAB-VALUE.

if sy-subrc = 0.

read table OUTTAB with key NAME = 'NEWFIELD'.

if sy-subrc = 0.

OUTTAB-VALUE = V_NAME1.

modify OUTTAB index SY-TABIX .

endif.

endif.

endif.

ENDFORM.

Note: here ITCSY is DDIC structure which contains 2 fields\

NAME : Contains the name of the Symobl

VALUE : Contains the value of the Symobl

INTAB contains all the parameter passed thru "USING"

OUTTAB contains all the parameter passed thru "CHANGING"

reward if helpful.

regards.

Read only

Former Member
0 Likes
644

Hi,

Try this :

Use PERFORM from SAPSCRIPT

/: PERFORM BIN_LOCATION IN PROGRAM Z_SAPSCRIPT_PERFORMS

/: USING &RESBD-MATNR&

/: USING &CAUFVD-IWERK&

/: USING &RESBD-LGORT&

/: CHANGING &MARD-LGPBE&

/: ENDPERFORM

-


REPORT z_sapscript_performs.

*----


  • SUBROUTINES FOR CALLING FROM SAPSCRIPTS

*----


FORM bin_location TABLES in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

*----


  • get default bin location from MARD for this material/plant/storage *

  • location

*----


DATA: l_matnr TYPE matnr, "material

l_werks TYPE werks, "plant

l_lgort TYPE lgort, "storage location

l_lgpbe TYPE lgpbe. "bin location

  • Get first parameter in input table.

READ TABLE in_tab INDEX 1.

WRITE in_tab-value TO l_matnr .

  • Get second parameter in input table

READ TABLE in_tab INDEX 2.

MOVE in_tab-value TO l_werks.

  • Get third parameter in input table

READ TABLE in_tab INDEX 3.

MOVE in_tab-value TO l_lgort.

  • read bin location

SELECT SINGLE lgpbe INTO l_lgpbe FROM mard

WHERE matnr = l_matnr

AND werks = l_werks

AND lgort = l_lgort.

IF l_LGPBE IS INITIAL.

l_LGPBE = 'NONE'.

ENDIF.

  • read & update only parameter in output table

READ TABLE out_tab INDEX 1.

out_tab-value = l_lgpbe.

MODIFY out_tab INDEX 1.

ENDFORM.

<b>Reward points</b>

Regards