Sap Condition Update Function Module
Function module to upate condition of Product. Create product using COMPRODSERVICEMAINTAINAPI 2. Get the Product GUID from step 1 and set it to parameters for COMPRODUCTMAINTCONDITIONS. Call function COMPRODUCTMAINTCONDITIONS to update conditions. Call function COMPRODUCTSAVEAPI (I got failed with subrc = 2 at this step but product was created).
When you modularize source code, you place a sequence of ABAP statements in a module. Then, instead of placing all of the statements in your main program, you just call the module.When the program is generated, the source code in the modularization unit is treated as though it were actually physically present in the main program.
In this tutorial you will learn:
Need of Modularization- Improve the structure of the program.
- Easy to read the code
- Easy to maintain the code
- Avoid redundancy and promotes code reuse
- Use of Macros
- Use of include files
- Subroutines
- Function Modules
SAP- ABAP Macro
If you want to reuse the same set of statements more than once in a program, you can include them in a macro.You can only use a macro within the program in which it is defined, and it can only be called in lines of the program following its definition.
Macros can be useful for long calculations or complex WRITE statements.
Sap Create Function Module
Syntax
Macros can use Parameters &N where N = 1,2,3..
Example:-
Output: 2
Include Programs
Include Programs are solely for modularizing source code, and have no parameter interface. Include programs allow you to use the same source code in different programs. They can be useful if you have lengthy data declarations that you want to use in different programs.Syntax
Points to Note
- Include programs cannot call themselves.
- Include programs must contain complete statements.
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.Syntax-
<Subroutine> = Name of the subroutine
<pass> = Parameters being passed
Types of Subroutines
- Internal
- Subroutine defined in same program being called.
- Can access all the data objects declared in the main ABAP/4 program.
- External
- Subroutine defined outside the program being called.
- Need to use the <pass> option or declare data objects in common parts of memory.
<subroutine> = Name of the subroutine
<pass> = Parameters being passed
Data declared in main program is automatically available.
External Subroutines
Points to Note
- Nested calls are allowed in subroutines (i.e. PERFORM within a FORM .. ENDFORM ).
- Recursive calls are also possible.
- To define local data, use the DATA statement after FORM . Each time you enter the subroutine, the data is recreated (with an initial value) and released at the end (from the stack).
- To define global data used within a subroutine, use the LOCAL statement after FORM . The values are saved when you enter the subroutine and then released at the end (from the stack)
Function Modules
Function Modules are general purpose ABAP/4 routines that anyone can use. Infact , there are a large number of standard function Modules available.Function Modules are organized into Function Groups: Collections of logically related functions. A Function module always belongs to a Function Group.
Syntax- Important information Associated with Function Module
- Administration
- Import/Changing/Export parameters.
- Table Parameters/Exceptions.
- Documentation
- Source code - L<fgrp>U01 . <fgrp> is the Function Group
- Global Data - L<fgrp>TOP .Global data for the function group- Accessible across function modules in the function group.
- Main Program - SAPL<fgrp> . Contains the list of all the include files for that function group
To call a function module, use the CALL FUNCTION statement:
Function Groups
Function groups are containers for function modules. Infact, there are a large number of standard Function Groups. All of the function modules in a function group can access the global data of the group.Like executable programs (type 1) and module pools (type M), function groups can contain screens, selection screens, and lists.
Points to Note
- Function Groups cannot be executed.
- The name of a function group can be up to 26 characters long.
- When you create a function group or function module, the main program and include programs are generated automatically.
- Function groups encapsulate data.
- Goto Transaction SE80.
- Select Program in the DropDown.
- Write the name of the Function Group That you want to create. Generally User made Function groups start with 'Z'. e.g. - <Z_FUNCTION_GROUP_NAME> . Hit Enter Key.
- Note that The TOP Include is create by default if the user checks the option of creating a TOP include.
- Create a function Group (say 'ZCAL').
- Create a function module, set the attributes like (Function group, Application, Short Text and Process Type) and Save.
- Include file 'LZCALU01' will have source code of first function module.
- Include file 'LZCALTOP' will have global data.
- Main program 'SAPLZCAL' contains
- Global data Include file 'LZCALTOP'
- Function modules include file 'LZCALUXX'
- User defined Include files 'LZCALF.', 'LZCALO.' and 'LZCALI.'
- Define interface parameters and Exceptions
- Write the source code
- Activate Function Module
- Testing the Function Module - Single Test & Debugging
- Documenting and Releasing a Function Module
Function modules make up a major part of a SAP system, because for years SAP has modularized code using function modules, allowing for code reuse, by themselves, their developers and also by their customers.
Function modules are sub-programs that contain a set of reusable statements with importing and exporting parameters. Unlike Include programs, function modules can be executed independently. SAP system contains several predefined function modules that can be called from any ABAP program. The function group acts as a kind of container for a number of function modules that would logically belong together. For instance, the function modules for an HR payroll system would be put together into a function group.
To look at how to create function modules, the function builder must be explored. You can find the function builder with transaction code SE37. Just type a part of a function module name with a wild card character to demonstrate the way function modules can be searched for. Type *amount* and then press the F4 key.
The results of the search will be displayed in a new window. Sim racing mirror zone. The function modules are displayed in the lines with blue background and their function groups in pink lines. You may look further at the function group ISOC by using the Object Navigator screen (Transaction SE80). You can see a list of function modules and also other objects held in the function group. Let's consider the function module SPELL_AMOUNT. This function module converts numeric figures into words.
Sap Function Module T Code
Creating a New Program
Sap Condition Update Function Module 2
Step 1 − Go to transaction SE38 and create a new program called Z_SPELLAMOUNT.
Step 2 − Enter some code so that a parameter can be set up where a value could be entered and passed on to the function module. The text element text-001 here reads ‘Enter a Value’.
Step 3 − To write the code for this, use CTRL+F6. After this, a window appears where ‘CALL FUNCTION’ is the first option in a list. Enter 'spell_amount' in the text box and click the continue button.
Step 4 − Some code is generated automatically. But we need to enhance the IF statement to include a code to WRITE a message to the screen to say 'The function module returned a value of: sy-subrc” and add the ELSE statement so as to write the correct result out when the function module is successful. Here, a new variable must be set up to hold the value returned from the function module. Let's call this as 'result'.
Following is the code −
Step 5 − The variable which the function module returns is called IN_WORDS. Set up the corresponding variable in the program called ‘result’. Define IN_WORDS by using the LIKE statement to refer to a structure called SPELL.
Step 6 − Save, activate and execute the program. Enter a value as shown in the following screenshot and press F8.
The above code produces the following output −