This blog has been discontinued (See latest posts)
Tuesday, March 16, 2010 Function Module: Example with Tabular Parameters
VN:F [1.9.22_1171]
Rating: 5.0/5 (8 votes cast)

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:

  1. 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.
  2. 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:

Simple Data Request
Characteristic Value
PPPI_FUNCTION_NAME Z_MX_TAB_SET_COMP_LIST
PPPI_BUTTON_TEXT TEST
PPPI_FUNCTION_DURING_DISPLAY 0
PPPI_TABLE_PARAMETER T_MATNR
PPPI_STRING_VARIABLE T_MAT
PPPI_OPTIONAL_PARAMETER X
PPPI_TABLE_PARAMETER T_BDMNG
PPPI_FLOAT_VARIABLE T_QTY1
PPPI_OPTIONAL_PARAMETER X
PPPI_TABLE_PARAMETER T_MEINS
PPPI_STRING_VARIABLE T_UOM1
PPPI_OPTIONAL_PARAMETER X
PPPI_TABLE_PARAMETER T_ERFMG
PPPI_FLOAT_VARIABLE T_QTY2
PPPI_OPTIONAL_PARAMETER X
PPPI_TABLE_PARAMETER T_ERFME
PPPI_STRING_VARIABLE T_UOM2
PPPI_OPTIONAL_PARAMETER X
PPPI_EXPORT_PARAMETER I_AUFNR
PPPI_STRING_VARIABLE X_ORD
PPPI_OPTIONAL_PARAMETER X
Table:

Repeated Data Request (Table)
Characteristic Value
PPPI_DATA_REQUEST_TYPE REPEATED
PPPI_VARIABLE T_MAT
PPPI_MATERIAL  
PPPI_VARIABLE T_QTY1
PPPI_MATERIAL_QUANTITY  
PPPI_VARIABLE T_UOM1
PPPI_UNIT_OF_MEASURE  
PPPI_VARIABLE T_QTY2
PPPI_MATERIAL_QUANTITY  
PPPI_VARIABLE T_UOM2
PPPI_UNIT_OF_MEASURE  
PPPI_OUTPUT_TEXT Material
PPPI_OUTPUT_VARIABLE T_MAT
PPPI_OUTPUT_TEXT Qty1
PPPI_OUTPUT_VARIABLE T_QTY1
PPPI_OUTPUT_TEXT UoM1
PPPI_OUTPUT_VARIABLE T_UOM1
PPPI_OUTPUT_TEXT Qty2
PPPI_OUTPUT_VARIABLE T_QTY2
PPPI_OUTPUT_TEXT UoM2
PPPI_OUTPUT_VARIABLE T_UOM2

 

Function Module: Example with Tabular Parameters, 5.0 out of 5 based on 8 ratings
Please rate the article:
VN:F [1.9.22_1171]
Rating: 5.0/5 (8 votes cast)
2 Comments Create new comment
  1. Sreekanth's Gravatar Sreekanth
    5.Feb.2015 at 21:18 | Permalink

    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.

  2. Tor's Gravatar Tor
    11.Aug.2010 at 12:26 | Permalink

    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. 🙂

News

This blog has been discontinued!

Archives

Calendar

March 2010
M T W T F S S
1234567
891011121314
15161718192021
22232425262728
293031