Declare variables in function module

hi gurus,
i am making a function module in which i need to make some performs so as to do code reusability. but for that i need to declare variable globally. As i am working wth function modules for the fisrt time. can anyone please help me with that. i dnt want these variables in improt or export parameters.
regards
vibhor

hi vibhor,
there is a tab "display object list" on the top of the sap screen when u r in dat function module. press that.
on the left side of ur screen there will complete lists of object used in fm. in includes there will a top include, declare all the variables u need globally in that top include. u can also create more includes for different performs if u want for modularizing ur program..
regards
palak

Similar Messages

  • Global data declaring/using in Function modules

    Hi,
    I have declared an internal table(say ITAB1) in the top include.Appending the values through FM1(function module).
    I am using the same through FM2 (Tables ITAB1).
    ( Function group is same for both FM1 and FM2 )
    but i am not getting the values in the ITAB1.
    Can anyone help me....
    Thanks in advance
    KB

    Bhavani,
    I don't think it works that way. If you are accessing that variable with in that function module you will be able to access that table.
    As you are calling another function module else where, the execution memory is different and the previous variables will not exist any more. However, if you call function2 with function1 it should work.
    The other way could using the EXPORT and IMPORT commands. Then you should be able to access the data.
    Regards,
    Ravi
    Note : Please reward points, if this helps you.

  • Export, Import and Table declaration in custom function module

    I am creating a custom function module. Parameters needed are export internal table and one data field from the internal table.
    What do i need to fill for 'associated type' for these export parameters since size of the internal table and type for the data field from the internal table vary.

    Hello Albert
    If the function module need not be RFC-enabled then you have many ways to define such dynamic parameters, e.g.:
    FUNCTION ZUS_SDN_DYNAMIC_PARAMS.
    *"*"Local Interface:
    *"  EXPORTING
    *"     REFERENCE(ET_ITAB) TYPE  TABLE
    *"     REFERENCE(ET_ITAB_1) TYPE  ANY
    *"     REFERENCE(ET_ITAB_2)
    *"     REFERENCE(ED_DATA) TYPE  CLIKE
    *"     REFERENCE(ED_DATA_1) TYPE  ANY
    *"     REFERENCE(ED_DATA_2)
    ENDFUNCTION.
    See also: How to return back a structure of dynamic tables in a Function Module
    Regards
      Uwe

  • Passing values to an InternalTable in a  Function Module from WebDynpro

    Hi,
       I have created a model from a function module that has a internal table.I have assigned the  value as a String to the datamodel context element of the internal table as a Line in the node that represents the input for the funtion module.The internal table accepts a value as an input.When i call the execute method on the input node i am not able to pass the value from the Webdynpro to the function module.I have also checked the assignment of the value as a String to the datamodel context element of the internal table as a Line in the node that represents the input for the funtion module and the value was assigned.
    If you can provide me any info on how to pass the internal table from Webdynpro to the function module will be very helpful ..???
    Thanks In Advance,
    Varma.

    Hi Rajendra,
               what u can pass to a function module is the parameter which are in import and tables  of RFC .so u have to declare a variable as a type of your internal table which may be type of   structure or table. then in your RFC u have to copy that into a variable of function module  and go for ur  logic ...

  • Problem when creating sapscript from within function module

    Hi,
    I created a function module which retrieves some master data, creates a sapscript for displaying the data and finally converts the sapscript to an otf. Afterwards the otf is converted to a pdf file.
    The problem is that the pdf file is created but it is empty!
    Here is a piece of the code:
    FUNCTION zhr_display_jobdescrpdf.
    * To access the SAP script output in OTF format.
    struct-tdgetotf = 'X'.
    struct-tdprogram = SY-REPID.
    CALL FUNCTION 'OPEN_FORM'
         EXPORTING
    *           APPLICATION        = 'TX'        " this is SapScript Appl
              device             = 'PRINTER'   " allow output to printer
              dialog             = 'X'         " printer dialog requested
              form               = 'ZHR_JOB_DESCR'       " name of form (SE71)
              language           = 'E'
              OPTIONS            = struct
    CALL FUNCTION 'START_FORM'
    EXPORTING
    *   ARCHIVE_INDEX          =
       form                   = 'ZHR_JOB_DESCR'
       language               = 'E'
    *   STARTPAGE              = ' '
    *   PROGRAM                = ' '
    *   MAIL_APPL_OBJECT       =
    *   IMPORTING
    *   LANGUAGE               =
    CALL FUNCTION 'WRITE_FORM'
         EXPORTING
           element                        = 'TEXT'
           function                       = 'SET'
           type                           = 'BODY'
           window                         = 'MAIN'
    CALL FUNCTION 'END_FORM'
    * IMPORTING
    * RESULT =
    EXCEPTIONS
    CALL FUNCTION 'CLOSE_FORM'
    * IMPORTING
    * RESULT =
    * RDI_RESULT =
    TABLES
    otfdata = datab[]
    EXCEPTIONS
    ENDFUNCTION.
    The content of datab[] is:
    1     //     XHPLJIIID    0700 0000000000
    2     IN     01EZHR_JOB_DESCR   MAIN
    3     OP     DINA4   P 144  240 1683811906000010000100001
    4     IN     02MAIN
    5     EP
    6     //
    So none of the variables that are used in the sapscript were transferred, although they are filled with the correct values when I put a breakpoint on the function 'write_form'. It looks like the sapscript can't access variables that are declared in a function module.
    Putting all the code for creating the sapscript in a report is not an option because then I have to use export/import to/from memory for retrieving the otf data and this doesn't work with the sap portal where the function is called.
    Did anyone had the same or similar problem?
    Greetings,
    Frederik

    Hi,
    Yes my problem is already solved.
    I created a report which creates the sapscript and in my function module I just execute that report.
    So problem solved :-).
    Greetings;
    Frederik

  • Global vairable in Function module

    Hello Friends,
    How to declare a global variable in function module, other than declaring in Function group/data section of function module.
    Regards
    Elini.P

    Hi Elini,
    You can declare the global data after the ENDFUNCTION statement in your function module if you wish, or you can include your own include in the TOP include.
    Actually you can declare global data just about anywhere in your function group as long as its not in between statments like FORM ENDFORM or FUNCTION ENDFUNCTION.
    I agree with Anand, though, why?
    Cheers,
    Brad

  • Need help in inbound function module !

    What is the meaning of this in the inbound function module ?
    WORK_RESULT = C_WF_RESULT_OK.
    In my function module its showing some error !

    Might be a constant C_WF_RESULT_OK is assigned to
    variable WORK_RESULT .
    Please check if they are declared in the function module ..

  • Need help in INBOUND idoc generation function module!

    Can anyone send me the inbound idoc function module !
    i have the outbound code but i need the inbound code

    Might be a constant C_WF_RESULT_OK is assigned to
    variable WORK_RESULT .
    Please check if they are declared in the function module ..

  • Global data declaration in a function group..

    hi,
    i have created a function group and created 2 FM in that. Both use some common data declarations so i declared those variables in the top include of the function group named LZFGXXXTOP.
    is this include automatically recognized in my FM or do i have to include it ? sample statements please ..
    thks

    Sorry Rich, I fail to understand what you are saying.
    in simple terms, i need to have some common data declarations for 2 function modules in a function group. Can u pl outline the steps I need to follow ? also i need to have a common set of form routines (FORM ENDFORM) to be used in these 2 function modules, where do i create these ?
    thks a lot

  • Function Modules required....

    Hi Gems!!
      Can any one help me out by providing Function Modules for Creating Transfer Order and after that FM for confirming it.. as its done in transactions LT01 and LT12 respectively.
    Helpful answers will definitely be rewarded!!!!!

    Hi Susanth,
    Please check as below declared using the function module:
    DATA: l_v_tanum      TYPE tanum.
    "assuming you have data here as per some records
        LOOP AT fp_im_final_sel ASSIGNING <l_fs_final_sel>. 
          READ TABLE fp_i_lqua INTO l_wa_lqua WITH KEY lenum =
                                                    <l_fs_final_sel>-lenum
                                                    BINARY SEARCH.
          IF sy-subrc EQ 0.
            l_wa_lubqu-lqnum    =  <l_fs_final_sel>-lqnum.
            l_wa_lubqu-menge    =  <l_fs_final_sel>-verme.
            APPEND l_wa_lubqu TO l_i_lubqu.
          ENDIF.
        ENDLOOP.
    CALL FUNCTION 'L_TO_CREATE_POSTING_CHANGE'
            DESTINATION 'NONE'
            EXPORTING
              i_lgnum                    = l_wa_mseg_temp-lgnum
              i_ubnum                   = l_wa_mseg_temp-ubnum
              i_squit                      = 'X'
              i_nidru                      = 'X'
              i_update_task           = space
              i_commit_work          = 'X'
              i_bname                    = sy-uname
            IMPORTING
              e_tanum                   = l_v_tanum
            TABLES
              t_lubqu                     = l_i_lubqu
            EXCEPTIONS
              foreign_lock               = 1
              tp_completed                 = 2
              xfeld_wrong                  = 3
              ldest_wrong                  = 4
              drukz_wrong                  = 5
              tp_wrong                     = 6
              squit_forbidden              = 7
              no_to_created                = 8
              update_without_commit        = 9
              no_authority                 = 10
              i_ubnum_or_i_lubu            = 11
              bwlvs_wrong                  = 12
              material_not_found           = 13
              manual_to_forbidden          = 14
              bestq_wrong                  = 15
              sobkz_missing                = 16
              sobkz_wrong                  = 17
              meins_wrong                  = 18
              conversion_not_found         = 19
              no_quants                    = 20
              t_lubqu_required             = 21
              le_bulk_quant_not_selectable = 22
              quant_not_selectable         = 23
              quantnumber_initial          = 24
              kzuap_or_bin_location        = 25
              date_wrong                   = 26
              nltyp_missing                = 27
              nlpla_missing                = 28
              lgber_wrong                  = 29
              lenum_wrong                  = 30
              menge_wrong                  = 31
              menge_to_big                 = 32
              open_tr_kzuap                = 33
              lock_exists                  = 34
              double_quant                 = 35
              quantity_wrong               = 36
              OTHERS                       = 37.
    Try to implement this, if you still have clarification you can get back to me at [email protected]
    Message was edited by:
            Pradeep C

  • Exceptions in Function Modules

    Hi
    How can I create an Exception in a Function Module and Raise that based on some condition? Plz help

    Hi Santo,,,,
    Look into this link ,, where u will get  a clear information on exceptions,,,,,
    http://help.sap.com/saphelp_nw70/helpdata/en/9f/db98fc35c111d1829f0000e829fbfe/content.htm
    http://abapprogramming.blogspot.com/2007/06/lesson-24-function-groups-and-function.html
    In the function module, you can create your own local types and data objects, and call subroutines or other function modules.
    You can make a function module trigger exceptions .
    To do this, you must first declare the exceptions in the interface definition, that is, assign each one a different name.
    In the source code of your function module, you program the statements that trigger an exception under the required condition. At runtime, the function module is terminated when an exception is triggered.
    The changes to exporting and changing parameters are the same as in subroutines. There are two statements that you can use to trigger an exception. In the forms given below, stands for the name of an exception that you declared in the interface. The system reacts differently according to whether or not the exception was listed in the function module call:
    RAISE .
    If the exception is listed in the calling program, the system returns control to it directly. If the exception is not listed, a runtime error occurs.
    MESSAGE () RAISING .
    If the exception is listed in the calling program, the statement has the same effect as RAISE . If it is not listed, the system sends message from message class with type , and no runtime error occurs.
    Function modules differ from subroutines in that you must assume that they will be used by other programmers. For this reason, you should ensure that you complete the steps listed here.
    Documentation (can be translated)
    You should document both your parameters and exceptions with short texts (and long texts if necessary) and your entire function module. The system provides a text editor for you to do this, containing predefined sections for Functionality, Example Call, Hints, and Further Information.
    Work list
    When you change an active function module, it acquires the status active (revised). When you save it, another version is created with the status inactive . When you are working on a function module, you can switch between the inactive version and the last version that you activated. When you activate the inactive version, the previous active version is overwritten.
    Function test
    Once you have activated your function module, you can test it using the built-in test environment in the Function Builder. If an exception is triggered, the test environment displays it, along with any message that you may have specified for it. You can also switch into the Debugger and the Runtime Analysis tool. You can save test data and compare sets of results.
    When you insert a function module call in your program, you should use the Pattern function. Then, you only need to enter the name of the function module (input help is available). The system then inserts the call and the exception handling (MESSAGE statement) into your program.
    You assign parameters by name. The formal parameters are always on the left-hand side of the expressions:
    Exporting parameters are passed by the program. If a parameter is optional, you do not need to pass it. Default values are displayed if they exist.
    Importing parameters are received by the program. All importing parameters are optional.
    Changing parameters are both passed and received. You do not have to list optional parameters.
    Default values are displayed if they exist.
    The system assigns a value to each exception, beginning at one, and continuing to number them sequentially in the order they are declared in the function module definition. You can assign a value to all other exceptions that you have not specifically listed using the special exception OTHERS.
    If you list the exceptions and one is triggered in the function module, the corresponding value is placed in the return code field sy-subrc. If you did not list the exception in the function call, a runtime error or a message occurs, depending on the statement you used in the function module to trigger the exception.
    When you create a function module, you must assign it to a function group. The function group is the main program in which a function module is embedded.
    A function group is a program with type F, and is not executable . The entire function group is loaded in a program the first time that you call a function module that belongs to it.
    The system also triggers the LOAD-OF-PROGRAM event for the function group.
    The function group remains active in the background until the end of the calling program. It is therefore a suitable means of retaining data objects for the entire duration of a program. All of the function modules in a group can access the group's global data.
    Please reward if found helpful,,,,,,,,,,,,,,,,
    Thanks And Regards ,,,,
    Sreekar.Kadiri.

  • Export RANGES to function module

    Can anyone tell, how to pass RANGES to function module.
    i have report program in ,
    DATA : BEGIN OF ITAB OCCURS 0,
               MATNR LIKE MARA-MATNR,
              END OF ITAB.
    SELECT-OPTIONS  : S_MATNR FOR MARA-MATNR.
    I want all the values in S_MATNR in ITAB.
    Note that S_MATNR has any value( Include, Exclude,Between, Equal etc.)

    Hi,
    Define a type in the global data declaration of the function module as follows :
    TYPES : BEGIN OF t_range_matnr,
            sign(1) TYPE c,
            option(2) TYPE c,
            low TYPE mara-matnr,
            high TYPE mara-matnr,
    END OF t_range_werk.
    " Define a table type
    types matnr_tab type t_range_matnr occurs 0.
    Once done, define the importing parameter of t_matnr in the function modules signature, lets call it matnr
    In your program where you would call the function, lets say you have the select option as follows
    SELECT-OPTIONS matnr FOR ekpo-matnr.
    " In the call function simply pass matnr[]
    call function 'select_mara'
    exporting
       matnr = matnr[].
    Done.
    P.S. Do not forget the square brackets.
    regards,
    Advait
    Edited by: Advait Gode on Apr 16, 2009 10:05 AM

  • Function module Global variables not cleared from memory?

    Hi,
    This is may be simple & stupid question ( after posting  4242 posts ):)
    " Declaration in TOP
    data : begin of i_y1yatt occurs 0.
            include structure y1yatt.
    data : end of i_y1yatt.
    types: begin of t_yatt71.
           include structure yatt71.
    types: tcode like sy-tcode.
    types: dflag type c.
    types: end of t_yatt71.
    data : i_yatt71 type standard table of t_yatt71
                   with default key  with header line  initial size 0.
    This is code in the function module.
      loop at i_y1yatt.
        move-corresponding o_y1yatt to i_yatt71.
        if i_y1yatt-werks eq 'N501'.
           move space to i_yatt71-werks.
        endif.
        append i_yatt71. 
        " Here this internal contains the previous entry
        clear i_yatt71.
      endloop.
    This function module is called 25 times in a minute.
    My problem is this
    For example : 1st tranmission is called this fm with 50 records,
    and 2nd tranmission is called fm with 10 records.
    My results are showing
    last record in the 1st transmission is still on the memory while calling 2nd transmission.  ( Here in int table I_YATT71 still contains the 1st transmission's last records during the 2nd tranmission call)
    As per my knowledge if each time calls comes in to fm all gloabl variables get cleared. but some how this not happening.
    Anybody come across this scenario.
    PS. I know i need to use clear statement within the loop as first statement.

    You must understand that when calling a FM, you load the entire function group into memory. IF there are global variables, then they are "alive" for the entire duration of the program execution. Meaning if you call the function numerious times, or even if you call another function within the same function group, the functions still have access to that same global variable space, so it must always be cleared manually by the developer at the required points.  You can not rely on the runtime to clear the global variables at the end of the function call.  So you should clear all you globals as the first operation in your function module call, if that is what is required.
    Is this clear?
    Regards,
    Rich Heilman

  • Function module to calculate Variable-Size Item

    I am creating a report for manual reservation. User wants to calculate quantity of material if he enters size1, size2 and size3. Also he wants that a formula key option to be provided so that he can mention conversion formula. Is there any standard function module to calculate quantity?

    Hi Vishal,
    I've declared two variables
    DATA: LDATE(20),
               LTIME(20).
    CALL FUNCTION 'GET_SYSTEM_TIME_REMOTE'
    IMPORTING
      K_DATE        =
      K_TIME         =
       L_DATE         = LDATE
       L_TIME          = LTIME
    AND IN THE FORM HEADER I'VE GIVEN IT AS,
    WA_HEADER-TYP  = 'S'.
    WA_HEADER-INFO = ': Date'.
    WA_HEADER-KEY  = LDATE.
    APPEND WA_HEADER TO IT_HEADER.
    WA_HEADER-TYP  = 'S'.
    WA_HEADER-INFO = ': Time'.
    WA_HEADER-KEY  = LTIME.
    APPEND WA_HEADER TO IT_HEADER.
    STILL IM NOT GETTING WAT ELSE IS REQUIRED ?

  • Variable problem in a function module

    Hi all,
    I'm writing a function module FM1 via SE37.
    Data A type I.
    Function FM1.
      perform x.
    Endfunction.
    Form x.
    Endform.
    The system warned me that variable A has been defined,
    is that becoz I've defined variable A in another function module within the same function group?

    Hi macy,
    1. If we declare any variable
        before any function defitinoin,
      (just like u have done)
    2. Then, it is as good as
       GLOBAL VARIABLE
    (which can be accessed via all fm in that group)
    3. Hence, your error is coming.
    4. Either give another name to your variable,
      or
      change the POSITION of the variable definition,
      (in the other FM)
    5. ie.
      WRITE BELOW THE FUNCTION DEFITNIION.
      FUNCTION MYFUNC.
      data :a type c. <----
      ENDFUNCTION
    6. not like this.
      data :a type c. <----
      FUNCTION MYFUNC.
      ENDFUNCTION
    regards,
    amit m.
    Message was edited by: Amit Mittal

Maybe you are looking for