06-05-2010 11:56 AM
I have a report program, which calls a function module. This function module internally calls an include program. In this program, I have a variable which is to be used in the sap script. How can I send this variable to the sap script
06-05-2010 12:02 PM
2 things..
if it is a z function module you can add a export parameter so as to get the required variable...
if it is a z include, then you can export that variable from the include and import it any where you want with the same session..
06-05-2010 12:06 PM
Hi,
Include programs are like part of report of function module. Any variable in side it can be directly assessable to the program including it. Hence you view it in your FM.
Now create an exporting parameter in FM and assign it the value of variable in Source code of FM.
exp_para = inc_vari ...... in source code
You can catch this value in your report program.
I hope it solves your problem.
regards,
Rohit
Edited by: Kumar_rohitkg on Jun 5, 2010 4:37 PM
06-05-2010 12:38 PM
When I checked the value of that variable in FM, its displaying 0. So it means , the value of the variable is not passed from include program to FM.
06-05-2010 12:43 PM
06-05-2010 1:41 PM
Hi,
you said "This function module internally calls an include program". This not clear: Program sources of type 'I' (Include) can not be called. They may be included in a report program, module pool or function group and FORMs or METHODs defined in the include may be called from program, form, method or function.
If the called unit stores a value in a variable, this variable must be returned explicitly to the caller (i.e. changing parameter of a form routine) or it must be declared globally (i.e. in the top include of the function group).
You may call you function module and step in debugger to the processing called in the include. Watch where your desrired value is determined and how it is passed to the calling function module and then back to the print program.
Find out where it gets lost.
Regards
Clemens
06-05-2010 12:33 PM
Hi reshma,
please let us know how the sapscript form is triggered.
Passing data to sapscript can be done in two ways:
If the value exists in a global field (variable or structure) of the program triggering the sapscript form (print program), the value can be accesses directly in the sapscript form (i.e. &VAR&).
If the value does not exist in a global field (variable or structure) of the program triggering the sapscript form (print program), the print program can not be changed (SAP standard program), you can make use of [Calling ABAP Subroutines: PERFORM |http://help.sap.com/erp2005_ehp_04/helpdata/EN/d1/803279454211d189710000e8322d00/frameset.htm]in the sapscript form.
If the print program is in customer name space (i.e. Z program), it is more performant and better transparancy to provide the value in the print program. You can call your Z-function and EXPORT the value to a global field defined in the program.
If the print program is SAP standard, use the sapscript PERFORM approach in yolur sapscript form.
If both pront program and sapscript form are SAP standard, you will may decide to copy sapscript form to customer name space and modify it.
Regards,
Clemens
06-05-2010 12:46 PM
Hi,
In your case, Include prog is part of FM, no need to treat it as an Entity.
Now, Your Answer -
In SCRIPT - IN Page Window -->
PERFORM GET_MVAT_TIN IN PROGRAM Z_SCRIPT_PERFORMS_ABAPDB3
USING &VBDKR-KUNRE&
CHANGING &STCD1&
CHANGING &STCD2&
ENDPERFORM
IF &STCD1& <> ' '
<B>MVAT Number :</> &STCD1&
ENDIF
Then go to SE38 --> Creat prog with type - Subroutine pool
In that Write FORM statement for this PERFORM.
FORM get_mvat_tin TABLES inttab STRUCTURE itcsy
outtab STRUCTURE itcsy.
DATA : v_kunre TYPE kna1-kunnr,
v_stcd1 TYPE kna1-stcd1,
v_stcd2 TYPE kna1-stcd2.
LOOP AT outtab.
CLEAR outtab-value.
MODIFY outtab.
ENDLOOP.
READ TABLE inttab INDEX 1.
v_kunre = inttab-value.
IF v_kunre CA sy-abcde.
ELSE.
UNPACK v_kunre TO v_kunre.
ENDIF.
" Here You can take your Funcion module ***************************
SELECT SINGLE stcd1 stcd2 FROM kna1 INTO (v_stcd1, v_stcd2)
WHERE kunnr = v_kunre.
IF sy-subrc = 0.
READ TABLE outtab INDEX 1.
WRITE v_stcd1 TO outtab-value.
MODIFY outtab INDEX 1.
READ TABLE outtab INDEX 2.
WRITE v_stcd2 TO outtab-value.
MODIFY outtab INDEX 2.
ENDIF.
ENDFORM.
06-05-2010 12:51 PM
The Report program, FM and include program were all SAP standard prorgams, which I have customized and made them as Z prorgams. Now the field which I wanted is in include prorgam and I want to pass this field directly to the Sapscript.