ABAP Unit for Function Module(Function Group)

Hi, Gurus:
Can we use ABAP Unit to test Function Module(Function Group).
If can, give me a simple example. how to create methods. Thanks.
Regards,

I'm a little unclear about your question, Yunfa.
Do you want to single-test a SE37 function-module? This can be easily done, just hit the F8 button, and it takes you to a single-test environment.
Do you want to test an FM using an ABAP-program? This too is easy to do. To code the FM-call, there's a button called Pattern, in the standard SE38 screen, where you can put in your FM name, and it inserts the relevant code in your program.
Note that if you're testing BAPIs using the single-test environment, the actual document posting will not happen, because that requires a BAPI_COMMIT_WORK call. So, the way to test BAPIs which post documents would be to write an SE38 program, which also calls the commit-bapi.
Hope this answers your question!

Similar Messages

  • ABAP Units for process agents

    I am implementing ABAP Units for process agents.
    I am using abap unit framework for process agents for this.
    I am passing a variant xml with test data, this will create a BO structure, along with xml in the variant, i am also passing the expected bo structure(to be compared).
    But still it dumps...as it says unexpected fields!
    Guide me.
    Thanks a lot.

    Hi Pallavi,
        You can achive this using event based chains.
    1. Create 4 chains to load to 4 CUBEs.
    2. Schedule 4 chains based on 4 events(can create at SM62).
    3. Create an ABAP Program to raise events based on logic and  Create one more process chain and include ABAP program. and schedule this program daily.
    Logic is:
    Based on system data derive quater and correspondingly raise an event.
    <a href="http://sapbwneelam.blogspot.com/2007/09/how-to-start-process-chain-through.html">Sample - how to ... start process chain through an event</a>
    Hope it Helps
    Srini

  • Transporting Function Module & Function group

    Hello All,
    I want some clarification in transporting a FM, FG, Extract Structure.
    First I collected Function Group in a Transport Request (R3TRFUGR********) and collected Function Module in the same request and also the extract structure.
    This Function Group have only one Function Module and 4 Includes (LRSALK01, LRSAXD01, LZ_BI_DS_DATATOP, LZ_BI_DS_DATAUXX, RSAUMAC).
    Do I need to collect these includes separately in the same request or is it enough if i collect only function group and function module and move the request.
    Please let me know.
    Thank you.

    Hi Saptrain,
    the best is always to let the system handle it: As soon as you assign an object (function group, function module, include or whatever) to a package, it will ask for a transport. Create the transport and the transport management system will include in the transport what has to be transported.
    As far as I know (but I never have the question), a function group (R3TR FUGR) will transport everything that is in the function group: All functions, all modules, all includes, screens, texts, status and...I think even test cases
    You will find FUGR in the transport after creating the function group.
    If you change something after releasing the transport, it will transport only the changed objects (i.e. includes)
    Regards,
    Clemens

  • Regarding Function module: function module change numeric to text

    Hi ,
    can any help me what is the function module used for : function module change numeric to text
    suppose:
    if i give :
    Input: 11/12/2007
    Output: 11 December 2007
    What is the FM used for same?
    Plz help me out

    I'm not sure if there is a FM that will directly change Your date to the right format but You can write simple code to do this:
    DATA: lv_subrc LIKE sy-subrc,
          lt_month TYPE TABLE OF t247,
          ls_month TYPE t247,
          lv_odate TYPE string,
          lv_ndate TYPE string,
          lv_char1 TYPE char1.
    lv_odate = '11/12/2007'.
    CALL FUNCTION 'MONTH_NAMES_GET'
      EXPORTING
        language              = sy-langu
      IMPORTING
        return_code           = lv_subrc
      TABLES
        month_names           = lt_month
      EXCEPTIONS
        month_names_not_found = 1
        OTHERS                = 2.
    IF sy-subrc = 0.
      LOOP AT lt_month INTO ls_month WHERE mnr = lv_odate+3(2).
        CONCATENATE lv_odate(2) ls_month-ltx lv_odate+6(4) INTO lv_ndate SEPARATED BY lv_char1.
      ENDLOOP.
    ELSE.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.

  • Want Standard programs in ABAP-HR for Different modules like PA, OM, TM,PY

    Can anyone tell me please what are the Standarad programs available for PA(Personnal planning) OM(Org Management), TM(Time Management), Benefits etc  for loading the data in ABAP-HR .

    have a look on this ..
    http://www.sap-press.de/katalog/buecher/htmlleseproben/gp/htmlprobID-205

  • When making a function module, what is difference between test /unit test

    best regards,

    Hi,
    ABAP Unit Tests
    Structure of Unit Tests
    An ABAP Unit test unit (TU) can be a class, function pool, executable program, or module pool. You can call ABAP Unit for testing individual TUs from the Class Builder (SE24), Function Builder (SE37), ABAP Editor (SE38), and SE80. Mass tests can be carried out from the Code Inspector.
    You organize your tests into classes and then into test methods, which are all part of the TU. The system checks small units within the TU, hence the name ABAP Unit. The aim of a test method is to check whether a unit returns the desired result. For this purpose, there are methods of the service class CL_AUNIT_ASSERT that execute comparisons between target and actual values calculated by a unit. The results of all unit tests of a TU are then shown in the ABAP Unit result display.
    Example
    Let us look at an example to help clarify this. Our minimalist TU is a percentage calculator that delegates this task to a subroutine:
    REPORT  Percentages.
    PARAMETERS: price TYPE p.
    PERFORM minus_ten_percent CHANGING price.
    WRITE price.
    FORM minus_ten_percent CHANGING fprice TYPE p.
      price = fprice * '0.9'.
    ENDFORM.                    "Minus_ten_percent
    We add a test class to the report, which tests whether the subroutine correctly calculates the percentage for a specific value.
    CLASS test DEFINITION FOR TESTING.  "#AU Risk_Level Harmless
    "#AU Duration Short
      PRIVATE SECTION.
        METHODS test_minus_ten_percent FOR TESTING.
    ENDCLASS.                   
    CLASS test IMPLEMENTATION.
      METHOD test_minus_ten_percent.
        DATA: testprice type p value 200.
        PERFORM minus_ten_percent CHANGING testprice.
        cl_aunit_assert=>assert_equals( act = testprice exp = 180
                            msg = 'ninety percent not calculated correctly').
      ENDMETHOD.                   
    ENDCLASS.  
    The test class and the test method TEST_MINUS_TEN_PERCENT are recognized by the tool through the addition FOR TESTING. The additions "#AU RISK_LEVEL HARMLESS and "#AU DURATION SHORT are not optional comments but annotations containing required technical information. With RISK_LEVEL you specify to what extent, if at all, executing the test endangers critical data. The time is specified so that any tests in endless loops are automatically cancelled due to a timeout.
    In the transaction SAUNIT_CLIENT_SETUP, you can make settings for an entire system with regard to the RISKLEVEL of tests and the times assigned to the individual attributes that specify the permitted duration (DURATION: SHORT, MEDIUM, and LONG). For example, in some development systems you will want to prohibit tests that change important data. If the test is cancelled for any reason, it is possible that some data may be left with invalid values or in an inconsistent state. Therefore, you will set the permitted RISKLEVEL suitably low in such systems.
    Service of the Class CL_AUNIT_ASSERT
    As parameters, the service method CL_AUNIT_ASSERT=>ASSERT_EQUALS requires a target value and an actual value, which is the result of the tested calculation; it then compares the two values. The MESSAGE parameter should contain a text that explains what went wrong during the test. You can also pass a parameter with the service method CL_AUNIT_ASSERT=>ASSERT_EQUALS that specifies the severity of the error, as well as a parameter stating how to proceed if the test fails: Should the test method simply continue, or should the current test method, the entire test class, or all tests of the TU be canceled?
    In addition to this method, the class CL_AUNIT_ASSERT also provides other methods, which execute different checks and pass the results to the framework. Most importantly, you should note that you can use the parameters of the methods of the service class CL_AUNIT_ASSERT to control the flow of the whole unit test and include information in the test methods that will later provide you with important details about any errors in the result display.
    ABAP Unit Result Display
    On the left side of the result display, all the tests of your TU are grouped into a task. In our case, this is only one test class with a single method:
    Via the name of the method, you can see what parts of the test method caused errors during the test:
    The message you passed with the service method is displayed at the top. Below that, you can which values diverge and can navigate to the class via the stack line.
    In our example, a closer examination of the code reveals that the input parameter of the report was confused with the change parameter of the subroutine.

  • Unit conversion  function module

    Hi,
    Can anyone give me the details of this function module
    Function Module name: MENGE_UMRECHNEN.
    its urgent.
    Thanks in advance.
    vaibhav

    Hi Vaibhav,
    This function module gives you the provision of conversion of quantities from Base Unit of Measure to any of the Alternative Unit of Measures or vice-versa.
    But this function would be done only for the materials and its limitation would be determined by the data maintained for a material in T006 table.
    Using this FM you can convert a material quantitity of unit 'X' to unit 'Y' only if 'X' and 'Y' are of the same dimension.
    <b>Reward points if this helps,
    Kiran</b>

  • How to log input parameters for Function Modules?

    Hi,
    I need to create a Logging system to trace input parameters for function modules.
    The log functionality could be done by developing a class method or a function module (For example 'write_log'), and calling it within each function module that I want to log. The 'write_log' code should be independent from the interface of the Function Module that I want to log.
    For example, I'd like to write a function/class method that can log both these functions modules:
    Function DummyA
       Input parameters: A1 type char10, A2 type char10.
    Function DummyB
       Input parameters: B1 type char20, B2 type char20, B3 type char20, B4 type Z_MYSTRUCTURE
    Now the questions...
    - Is there a "standard SAP" function that provide this functionality?
    - If not, is there a system variable in which I can access runtime all parameters name, type and value for a particular function module?
    - If not, how can I loop at Input parameters in a way that is independent from the function module interface?
    Thank you in advance for helping!

    check this sample code. here i am capturing only parameters (import) values. you can extend this to capture tables, changin, etc.
    FUNCTION y_test_fm.
    *"*"Local Interface:
    *"  IMPORTING
    *"     REFERENCE(PARAM1) TYPE  CHAR10
    *"     REFERENCE(PARAM2) TYPE  CHAR10
    *"     REFERENCE(PARAM3) TYPE  CHAR10
      DATA: ep TYPE STANDARD TABLE OF rsexp ,
            ip TYPE STANDARD TABLE OF rsimp ,
            tp TYPE STANDARD TABLE OF rstbl ,
            el TYPE STANDARD TABLE OF rsexc ,
            vals TYPE tihttpnvp ,
            wa_vals TYPE ihttpnvp ,
            wa_ip TYPE rsimp .
      FIELD-SYMBOLS: <temp> TYPE ANY .
      CALL FUNCTION 'FUNCTION_IMPORT_INTERFACE'
        EXPORTING
          funcname                 = 'Y_TEST_FM'
    *   INACTIVE_VERSION         = ' '
    *   WITH_ENHANCEMENTS        = 'X'
    *   IGNORE_SWITCHES          = ' '
    * IMPORTING
    *   GLOBAL_FLAG              =
    *   REMOTE_CALL              =
    *   UPDATE_TASK              =
    *   EXCEPTION_CLASSES        =
        TABLES
          exception_list           = el
          export_parameter         = ep
          import_parameter         = ip
    *   CHANGING_PARAMETER       =
          tables_parameter         = tp
    *   P_DOCU                   =
    *   ENHA_EXP_PARAMETER       =
    *   ENHA_IMP_PARAMETER       =
    *   ENHA_CHA_PARAMETER       =
    *   ENHA_TBL_PARAMETER       =
    *   ENHA_DOCU                =
       EXCEPTIONS
         error_message            = 1
         function_not_found       = 2
         invalid_name             = 3
         OTHERS                   = 4
      IF sy-subrc = 0.
        LOOP AT ip INTO wa_ip .
          MOVE: wa_ip-parameter TO wa_vals-name .
          ASSIGN (wa_vals-name) TO <temp> .
          IF <temp> IS ASSIGNED .
            wa_vals-value = <temp> .
          ENDIF .
          APPEND wa_vals TO vals .
        ENDLOOP .
      ENDIF.
    ENDFUNCTION.

  • Process code's function module required for the IDOC Message type PROACT

    Hi,
    I am trying to trigger an IDOC from ME32K transaction which will carry my Contract agreement details to XI. The IDOC I am using for this purpose is PROACT.PROACT01. But I couldn't find the outbound process code / Function module for the process code associated to this IDOC message type.
    Pls help me out....
    Thanks,
    Ram Kalyan

    I checked table EDIFCT for the message type and found this:
    Function module            Function type    Basic type                                      Message Type
    IDOC_INPUT_PROACT          F               PROACT01                                       PROACT
    Oops...I think you are looking for outbound..Ignore

  • BAPI or Function Module for FBCJ Posting of Parked Cash Journal Entries

    Hi Experts,
    A blessed day.
    We have one requirement that requires the creation of Batch Program that will post all the outstanding (status is set in yellow) Cash Journal Entries in transaction FBCJ.
    Hereu2019s the issue, to satisfy the requirement, we either use BDC/Call Transaction OR use a Function Module/BAPI. 
    I would prefer to use Function Module/BAPI.  However, currently thereu2019s only one BAPI available for FBCJ (BAPI_CASHJOURNALDOC_CREATE).  This BAPI can only create cash journal entries BUT DO NOT change the cash journal entry for posting.  The Function Modules (Function Modules of FCJ_POST* series) cannot be used for background processing because of GUI pop-ups. These FMs also donu2019t have the Exceptions functionality for error handling and would not report the Accounting document created from the Cash Journal Entry posting.
    The problem with using BDC/Call Transaction is that it should incorporate line item selection of the cash journal entries, which I havenu2019t tried yet.  Iu2019m not sure if this is possible and if itu2019s possible, how much complexity will it incur.
    If you have the availability, would it be possible if you can help us explore on the potential solutions for this requirement?
    Thanks so much.  God bless!
    Cheers,
    ianne

    You can use RFBIBL00 program for FB01 postings. Go through the program help on how to use this program.
    This program requires a file to be on application server in a certain format.
    You may also refer the program RFBIBLT0 on how the file format should be.
    Hope this helps.
    Thanks,
    SKJ

  • EXTRATOR FOR A MODULE OF FUNCTION STATUS_TEXT_EDIT

    Hi Experts,
    I need to create a DataSource for a module of function STATUS_TEXT_EDIT, but I was a error because I don't have a extraction structure.
    What Can I do to resolve this problem?
    Regards,
    Sérgio Ferreira

    Hi Guys,
    I'd like to know how to create a Extraction Structure for a module function, so as to create the generic datasource?
    Thanks,
    Sérgio Ferreira

  • How to make use of SE37- Function Module & how to find out the table?

    Hi ,
    1.Could anyone help me what's this SE37-Function module is all about,How to make use of this?
    For Eg,If i want to delete a BOM permanently from the system then I have to use the Function module CM_DB_DEL_FROM_ROOT_BOM.
    But after giving the particular name what should i do?
    Please help me.
    2.How to find out the respective table for a particular field sya for T code-COGI, T code MFBF,where its values are getting populated.,Please help in this issue.
    Thanks in adavnce for spending some time
    Raj.S

    Hi Raj
    Function Modules
    Function modules are procedures that are defined in special ABAP programs only, so-called function groups, but can be called from all ABAP programs. Function groups act as containers for function modules that logically belong together. You create function groups and function modules in the ABAP Workbench using the Function Builder.
    Function modules allow you to encapsulate and reuse global functions in the SAP System. They are managed in a central function library. The SAP System contains several predefined functions modules that can be called from any ABAP program. Function modules also play an important role during updating  and in interaction between different SAP systems, or between SAP systems and remote systems through remote communications.
    Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder. The actual ABAP interface definition remains hidden from the programmer. You can define the input parameters of a function module as optional. You can also assign default values to them. Function modules also support exception handling. This allows you to catch certain errors while the function module is running. You can test function modules without having to include them in a program using the Function Builder.
    The Function Builder  also has a release process for function modules. This ensures that incompatible changes cannot be made to any function modules that have already been released. This applies particularly to the interface. Programs that use a released function module will not cease to work if the function module is changed.
    Check this link
    http://help.sap.com/saphelp_nw2004s/helpdata/en/9f/db988735c111d1829f0000e829fbfe/content.htm
    You can execute function module in SE37ie you can perform the activiites defined in the function module by executing it.
    By deleting BOM you mention the FM name in se37 and execute. In some function module it will ask input parameters as developed in the program , you have to give the input parameters and execute.

  • Duplicate Function Modules

    This is quite a complicated problem and Iu2019ve tried to simplify a bit.
    I created a custom FM (Z_FM_1) in a custom function group. When I try to activate it, I get a syntax error u201CINCLUDE  LZRB1$11 - A function already exists with the name Z_FM_2. (Note that itu2019s not the one Iu2019m creating.) I go to the main program, and there is an include for the FM Z_FM_2, but itu2019s in include LZRB1U11, where one would expect it to be. So I open up the ABAP editor and look at include LZRB1$11 and indeed, there is a FM with that name there with just some odd code for importing and exporting parameters..
    A where used list of that include shows that it is not actually used anywhere.
    So far, this is odd enough, but when I go to our QA environment, I find exactly the same situation u2013 same includes, same FMs (except for the one Iu2019m trying to create). But if I do a syntax check, I get no error.
    I canu2019t explain this. Can anyone??
    Hereu2019s some further information that I donu2019t think is relevant, but still odd: I am creating this FM (Z_FM_1) because it exist in our QA environment, but not in DEV. I had tried to recreate it using version management, but there were no versions either for the FM or its include. When I looked at the code that was executing it, it had a different transport than the latest one. I looked at the transport log for the latest two requests and found that they had been exported in the correct sequence (older, then later), but the older one was in QA.
    Rob

    Rob,
    I had faced not same but similar problems with Function Modules and groups when TR were migrated to created temporary systems. I used the repair FG option to fix that.
    You can find the Repair Function Group option in SE37 > Utilities > Repair Function Group. Enter your FG name in the popup. In the next screen it would show if there are any issues with the FG. System would show includes which has issues and can be repaired. Select them and press Repair.
    After this you should be able to create the FM.
    Regards,
    Naimesh Patel

  • Function module with RFC enable

    Hello ABAPers,
    Im a new comer in ABAP and I would like to have a basic knowledge in RFC using a function module/function group..
    I have this project in Travel Dept...I need to connect on a different system using SAP connector...meaning...I will logon to SAP and connect to another system which is VB.net and has a back-end of SQL 2000. After connection I need to select or search a data to that table...for me to get the ticket number.
    Before I tried to connect from VB.net to SAP...and successfully used the SAP connector...now I need the vice versa version of this approach..
    Can anyone help me? please....
    Thanks in advance...Will reward points
    aVaDuDz

    For Basic Understanding just look at RFC_READ_TABLE FM,This will give good example
    Also Check the SM59 Transaction to create RFC Destination
    Please check with below link :
    https://www.sdn.sap.com/irj/sdn/advancedsearch?query=rfc&cat=sdn_wiki
    Thanks
    Seshu

  • Diff between Function Module and subroutine

    sir,
      explain the difference between Function Module and Subroutine.

    Hi Sandeep,
    Subroutines:
       Subroutines are procedures that you can define in any ABAP program and also call from any program. Subroutines are normally called internally, that is, they contain sections of code or algorithms that are used frequently locally. If you want a function to be reusable throughout the system, use a function module.
    Function Modules:
    Function modules are procedures that are defined in function groups (special ABAP programs with type F) and can be called from any ABAP program. Function groups act as containers for function modules that logically belong together. You create function groups and function modules in the ABAP Workbench using the Function Builder.
    Function modules allow you to encapsulate and reuse global functions in the R/3 System. They are stored in a central library.
    Unlike subroutines, you do not define function modules in the source code of your program. Instead, you use the Function Builder.
    Regards,
    Sunil

Maybe you are looking for