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

subroutine in script

Former Member
0 Likes
807

how we use subroutine in script

5 REPLIES 5
Read only

Former Member
0 Likes
761

Hello Rahul,

See this sample code.

PERFORM GET_VEND_NAME_MOD IN PROGRAM /RB17/YV_FORMS_PUTAWAY_LIST

USING &LTAK-VBELN&

USING &LTAP-POSNR&

USING &LTAK-LGNUM&

USING &LTAK-BWART&

USING &LTAK-BWLVS&

USING &LTAK-MBLNR&

USING &LTAK-MJAHR&

CHANGING &VEND_NAME&

CHANGING &TRAID&

CHANGING &SHIPPING_UNIT&

CHANGING &VEKP_VKORG&

CHANGING &VEKP_VTWEG&

FORM get_vend_name_mod TABLES in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy .

DATA : z_vbeln LIKE ltak-vbeln,

z_lgnum LIKE ltak-lgnum,

z_bwart LIKE ltak-bwart,

z_bwlvs LIKE ltak-bwlvs,

z_mblnr LIKE ltak-mblnr,

z_mjahr LIKE ltak-mjahr,

z_posnr LIKE ltap-posnr,

l_f_handle LIKE vevw-handle,

l_f_werks LIKE mseg-werks,

l_f_objkey(14) TYPE c,

l_f_stock1(35) TYPE c.

CONSTANTS : l_f_stock(35) TYPE c VALUE 'Stock Transfer from Plant 9060'.

CLEAR : likp,lfa1.

  • Get the delivery number

READ TABLE in_tab WITH KEY name = 'LTAK-VBELN'.

CHECK sy-subrc = 0.

z_vbeln = in_tab-value.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = z_vbeln

IMPORTING

output = z_vbeln.

  • position number

READ TABLE in_tab WITH KEY name = 'LTAP-POSNR'.

CHECK sy-subrc = 0.

z_posnr = in_tab-value.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'

EXPORTING

input = z_posnr

IMPORTING

output = z_posnr.

  • Warehouse number

READ TABLE in_tab WITH KEY name = 'LTAK-LGNUM'.

IF sy-subrc = 0.

z_lgnum = in_tab-value.

ENDIF.

  • Movement type

READ TABLE in_tab WITH KEY name = 'LTAK-BWART'.

IF sy-subrc = 0.

z_bwart = in_tab-value.

ENDIF.

READ TABLE in_tab WITH KEY name = 'LTAK-BWLVS'.

IF sy-subrc = 0.

z_bwlvs = in_tab-value.

ENDIF.

  • Material document number and year

READ TABLE in_tab WITH KEY name = 'LTAK-MBLNR'.

IF sy-subrc = 0.

z_mblnr = in_tab-value.

ENDIF.

READ TABLE in_tab WITH KEY name = 'LTAK-MJAHR'.

IF sy-subrc = 0.

z_mjahr = in_tab-value.

ENDIF.

CONCATENATE z_mblnr z_mjahr INTO l_f_objkey.

IF ( z_lgnum = 'A11' AND z_bwart = '301' AND z_bwlvs = '302' ).

SELECT SINGLE handle INTO l_f_handle FROM vevw

WHERE object = 'MM' AND

objkey = l_f_objkey.

IF sy-subrc EQ 0 AND

NOT l_f_handle IS INITIAL.

SELECT SINGLE * FROM vekp

WHERE handle = l_f_handle.

g_f_exidv = vekp-exidv.

ENDIF.

SELECT SINGLE werks INTO l_f_werks FROM mseg

WHERE

mblnr = z_mblnr AND

mjahr = z_mjahr AND

shkzg = 'H'.

IF sy-subrc EQ 0

AND l_f_werks EQ '9060'.

l_f_stock1 = l_f_stock.

ENDIF.

SELECT SINGLE * FROM likp

WHERE vbeln = z_vbeln .

IF sy-subrc EQ 0 .

SELECT SINGLE * FROM lfa1

WHERE lifnr = likp-lifnr.

ENDIF.

ELSE.

SELECT SINGLE * FROM likp

WHERE vbeln = z_vbeln .

IF sy-subrc EQ 0 .

SELECT SINGLE * FROM lfa1

WHERE lifnr = likp-lifnr.

l_f_stock1 = lfa1-name1.

ENDIF.

SELECT SINGLE vbeln FROM vbfa

INTO vbfa-vbeln

WHERE vbtyp_n = 'X'

AND vbelv = z_vbeln.

SELECT SINGLE * FROM vepo

WHERE venum = vbfa-vbeln.

IF sy-subrc EQ 0 .

SELECT SINGLE * FROM vekp

WHERE venum = vepo-venum.

ENDIF.

IF vekp-exidv IS INITIAL.

SELECT SINGLE * FROM vekp

WHERE vpobj IN ('01','03')

AND vpobjkey = z_vbeln.

g_f_exidv = vekp-exidv.

ENDIF.

ENDIF.

READ TABLE out_tab WITH KEY name = 'VEND_NAME'.

CHECK sy-subrc = 0.

out_tab-value = l_f_stock1.

SHIFT out_tab-value LEFT DELETING LEADING space.

MODIFY out_tab INDEX sy-tabix.

READ TABLE out_tab WITH KEY name = 'TRAID'.

CHECK sy-subrc = 0.

out_tab-value = likp-traid.

SHIFT out_tab-value LEFT DELETING LEADING space.

MODIFY out_tab INDEX sy-tabix.

READ TABLE out_tab WITH KEY name = 'SHIPPING_UNIT'.

CHECK sy-subrc = 0.

out_tab-value = g_f_exidv.

SHIFT out_tab-value LEFT DELETING LEADING space.

SHIFT out_tab-value LEFT DELETING LEADING '0'.

MODIFY out_tab INDEX sy-tabix.

READ TABLE out_tab WITH KEY name = 'VEKP_VKORG'.

CHECK sy-subrc = 0.

out_tab-value = vekp-vkorg.

MODIFY out_tab INDEX sy-tabix.

READ TABLE out_tab WITH KEY name = 'VEKP_VTWEG'.

CHECK sy-subrc = 0.

out_tab-value = vekp-vtweg.

MODIFY out_tab INDEX sy-tabix.

*} INSERT

ENDFORM. "get_vend_name_mod

If useful reward.

Vasanth

Read only

Former Member
0 Likes
761

Hi Rahul,

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.

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.

regards,

keerthi.

Read only

Former Member
0 Likes
761

HI,

In script, you need to write as

Perform <Name> from <Program name> with some parameters... changing parameter.

In driver program you need to call this.

Form <form name> with the parameters...

regards,

Ram

Read only

Former Member
0 Likes
761

Hi rahul,

1. while calling subroutines from sapscripts,

there is a special technique,

which has got its own limitations.

2.

FORM abc

TABLES

in_tab STRUCTURE itcsy

out_tab STRUCTURE itcsy.

ENDFORM.

3. The perform in se38 program should be of the

above format only.

4. We cannot pass internal tables.

5. Rather we need to pass

VARIABLE NAME

VARIABLE VALUE

(see the structure of itcsy in se11)

6. In this form, we have to read

the internal table in_tab

to capture the variable name and its value.

7. Similary, to return the values,

we have to put one record (for each variable)

in out_tab.

regards,

amit m.

Read only

Former Member
0 Likes
761

hi rahul,

check these...

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

hope this helps,

do reward if it helps,

priya.