In this post I would like to demonstrate how to manipulate PI Sheet tables using table parameters in function modules.
Basics
A PI Sheet table is a repeated data request with a variable number of lines.
In a PI-based PI Sheet this is triggered by the characteristic PPPI_DATA_REQUEST_TYPE and the value ‘REPEATED’. Any variable you define inside such a process instruction is a tabular value (PI). With XSteps you just set the type in the group node (where you also set the title of the table). Tabular parameters are defined in the XStep to which the repeated instruction belongs by setting a flag in the parameter definition (‘Tabular Value’).
Having a tabular variable/parameter does not necessarily means that there must be an visible output of that element. This may happen when you take the value of an input field by a function module inside the table instruction and return another value which valuates that hidden variable/parameter. A hidden tabular value could be a status flag that indicates that the line is ready to be completed maybe triggering a command.
There are two possibilities to access data from a tabular variable/parameter with a function module:
- You create a function call inside the repeated instruction. When you pass the tabular variable/parameter you should use a scalar parameter type in the function module (not a table parameter). Then the value passed is the value of the current line where the function module is called.
I do not recommend to use function modules with parameters of type ‘TABLES’ inside a repeated instruction. This does not mean that it is not working but I simply did not make good experiences with that. - You create a function call outside the repeated instruction in a separate simple instruction. Then you can pass a tabular variable/parameter to a function module parameter of type ‘TABLES’. This means that the entire content of the one-column tabular variable/parameter is passed to the function module.
So let me give you a simpe example of the second possibility.
Example
This example I also showed in my live session #19. It shows how to create a table of all components with the quantities in material base unit and BOM unit. The initial reason to set up this example was a question from the topic discussion about alternate units of measure when using PI-bases PI Sheets.
Structures for the Parameter Definition
To define function module parameters of type ‘TABLES’ you need a special structure for each basic data format (character, numeric, date, time).
For a character-like parameter create the structure ZMX_PI_TABLE_CHAR:
- Create one line (component): VALUE
- Select ‘Predefined Type’
- Select ‘Data Type’: ‘CHAR’
- Set Length: ’30’
For a numeric parameter create the structure ZMX_PI_TABLE_NUM:
- Create one line (component): VALUE
- Select ‘Predefined Type’
- Select ‘Data Type’: ‘DEC’
- Set Length: ’13’ (or more)
- Set Decimals: ‘3’ (or more)
Function Module
Create the following function module:
FUNCTION z_mx_tab_set_comp_list. *"---------------------------------------------------------------------- *"*"Local Interface: *" IMPORTING *" REFERENCE(I_RSNUM) TYPE RSNUM OPTIONAL *" REFERENCE(I_AUFNR) TYPE AUFNR OPTIONAL *" TABLES *" T_MATNR STRUCTURE ZMX_PI_TABLE_CHAR OPTIONAL *" T_POSNR STRUCTURE ZMX_PI_TABLE_CHAR OPTIONAL *" T_BDMNG STRUCTURE ZMX_PI_TABLE_NUM OPTIONAL *" T_MEINS STRUCTURE ZMX_PI_TABLE_CHAR OPTIONAL *" T_ERFMG STRUCTURE ZMX_PI_TABLE_NUM OPTIONAL *" T_ERFME STRUCTURE ZMX_PI_TABLE_CHAR OPTIONAL *"---------------------------------------------------------------------- DATA: ls_resb TYPE resb. DELETE t_matnr FROM 1. DELETE t_posnr FROM 1. DELETE t_bdmng FROM 1. DELETE t_meins FROM 1. DELETE t_erfmg FROM 1. DELETE t_erfme FROM 1. * Get reservation information SELECT * FROM resb INTO ls_resb WHERE aufnr EQ i_aufnr. IF ls_resb-postp EQ 'L'. t_posnr-value = ls_resb-posnr. APPEND t_posnr. t_matnr-value = ls_resb-matnr. APPEND t_matnr. t_bdmng-value = ls_resb-bdmng. APPEND t_bdmng. t_meins-value = ls_resb-meins. APPEND t_meins. t_erfmg-value = ls_resb-erfmg. APPEND t_erfmg. t_erfme-value = ls_resb-erfme. APPEND t_erfme. ENDIF. ENDSELECT. ENDFUNCTION.
Notes:
- Any tabular variable/parameter in a PI Sheet table is initially created with one empty line (since each initial table has at least one line at the beginning). If you simply add your content to it you leave the first line empty. Therefore I removed these lines initially (DELETE … FROM 1).
Therefore my intention here is only to call this function module once initially (you could do it on event DOCUMENT.GENERATED). If you want to call such a function module frequently you should think of a more performant way of handling these tables. - You can enhance this example by doing some calculations and returning also a scalar value that you then display above (or below) your table. On example would be to calculate the total sum of all components taking different unit of measure into account.
- If you use such a function module on a table where you also have input fields you should never delete any lines once you begin to enter values in those input fields. This would mess up the table. Reading and modifying would be OK though.
- If you create a function module that handles data from multiple tables then I recommend to give all parameters a prefix to identify to which table that parameter belongs (e.g. T1_… / T2_…)
Process Instructions
Simple Instruction with Function Call:
|
Table:
|
Please rate the article: |
Hello,
I am trying to pass a tabular numeric value from Xsteps to custom function module.When i do a check in the standard Xsteps it throws and error “”You cannot use variable LT_QTY for table parameter IT_BATCH_QTY”.Any idea on why this error could be.
This is super useful for me.
In my project they have a weighing operation where different components are added into the same bag on the scale. They do this without doing tare one the scale. I will develop this function module to calculate a running sum for the component quanitities which the operators can check against. 🙂