This video tutorial is a comprehensive guide on how to create a function module in ABAP that returns a table type. The instructor uses a specific example where a function module is created to return a list of materials assigned to a given material type. The function module is designed to take the material type as an input and return a table containing the material and material type as output. The tutorial also covers how to utilize the created function module in a program.
Key topics covered in the video session:
- Creating a Function Module: The instructor begins by creating a function module named ‘GFM_Material List’. This function module contains one import parameter, ‘Material Type’, and is designed to return a table output.
- Defining the Output Table: The output table ‘LT_Material’ is defined in the function module. The associated type for this table is a global structure that needs to be created separately. This structure will contain two fields: ‘Material’ and ‘Material Type’.
- Creating a Structure: A structure named ‘GST_FM_Material’ is created in the Data Dictionary (transaction code SE11). This structure contains two fields, ‘Material’ and ‘Material Type’, with their respective data elements copied from the MARA table.
- Writing the Source Code: The source code for the function module is written. A SELECT statement is used to fetch the ‘Material’ and ‘Material Type’ fields from the MARA table. The fetched data is stored in the ‘LT_Material’ table. The SELECT statement is conditioned to fetch only the data related to the given ‘Material Type’.
- Testing the Function Module: The function module is tested by providing ‘T01’ as the input for ‘Material Type’. The function module successfully returns a table containing all materials assigned to ‘T01’. The function module is also tested with a ‘Material Type’ that does not exist in the MARA table, and as expected, it returns an empty table.
- Utilizing the Function Module in a Program: The instructor demonstrates how to utilize the created function module in a program. A selection screen is created to take ‘Material Type’ as input. The function module is called in the program, and the output is displayed on the screen.
- Debugging the Program: The instructor uses the debugging tool to step through the program and explain how the function module works. The function module reads the ‘Material Type’ input, fetches the corresponding data from the MARA table, and returns it as a table output.
The tutorial concludes with the instructor emphasizing the importance of understanding how to create and utilize function modules in ABAP.