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 retrieve data from a function module and use it in sap script??

Former Member
0 Kudos

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

8 REPLIES 8

Former Member
0 Kudos

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..

Former Member
0 Kudos

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

0 Kudos

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.

0 Kudos

The print program. FM and include program are all Z programs.

0 Kudos

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

Clemenss
Active Contributor
0 Kudos

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

Former Member
0 Kudos

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.                                 

0 Kudos

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.