{"id":755,"date":"2010-03-16T15:38:18","date_gmt":"2010-03-16T14:38:18","guid":{"rendered":"http:\/\/websha.de\/xstepcafe\/?p=755"},"modified":"2018-06-01T06:45:21","modified_gmt":"2018-06-01T04:45:21","slug":"function-module-example-with-tabular-parameters","status":"publish","type":"post","link":"https:\/\/websha.de\/xstepcafe\/2010\/03\/16\/function-module-example-with-tabular-parameters\/","title":{"rendered":"Function Module: Example with Tabular Parameters"},"content":{"rendered":"<p>In this post I would like to demonstrate how to manipulate PI Sheet tables using table parameters in function modules.<\/p>\n<p><!--more--><\/p>\n<h1>Basics<\/h1>\n<p>A PI Sheet table is a repeated data request with a variable number of lines.<\/p>\n<p>In a PI-based PI Sheet this is triggered by the characteristic PPPI_DATA_REQUEST_TYPE and the value &#8216;REPEATED&#8217;. Any variable you define inside\u00a0such 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 (&#8216;Tabular Value&#8217;).<\/p>\n<p>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.<\/p>\n<p>There are two\u00a0possibilities to access data from a tabular variable\/parameter with a function module:<\/p>\n<ol>\n<li>You create a function call <strong>inside<\/strong> the repeated instruction. When you pass the tabular variable\/parameter you should use a <strong>scalar<\/strong> 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.<br \/>\nI do not recommend to use function modules with parameters of type &#8216;TABLES&#8217; \u00a0inside a repeated instruction. This does not mean that it is not working but I simply did not make good experiences with that.<\/li>\n<li>You create a function call <strong>outside<\/strong> the repeated instruction in a separate simple instruction. Then you can pass a <strong>tabular<\/strong> variable\/parameter to a function module parameter of type &#8216;TABLES&#8217;. This means that the entire content of the one-column tabular variable\/parameter is passed to the function module.<\/li>\n<\/ol>\n<p>So let me give you a simpe example of the second possibility.<\/p>\n<h1>Example<\/h1>\n<p>This example I also showed in my <a href=\"http:\/\/websha.de\/xstepcafe\/2010\/03\/05\/xstep-cafe-%e2%80%93-session-19\/\">live session #19<\/a>. 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 <a href=\"http:\/\/websha.de\/xstepcafe\/cafe\/topic-discussion\/comment-page-1\/#comment-42\">topic discussion <\/a>about alternate units of measure when using PI-bases PI Sheets.<\/p>\n<h2>Structures for the Parameter Definition<\/h2>\n<p>To define function module parameters of type &#8216;TABLES&#8217; you need a special structure for each basic data format (character, numeric, date, time).<\/p>\n<p>For a character-like parameter create the structure ZMX_PI_TABLE_CHAR:<\/p>\n<ul>\n<li>Create one line (component): VALUE<\/li>\n<li>Select &#8216;Predefined Type&#8217;<\/li>\n<li>Select &#8216;Data Type&#8217;: &#8216;CHAR&#8217;<\/li>\n<li>Set Length: &#8217;30&#8217;<\/li>\n<\/ul>\n<p>For a numeric parameter create the structure ZMX_PI_TABLE_NUM:<\/p>\n<ul>\n<li>Create one line (component): VALUE<\/li>\n<li>Select &#8216;Predefined Type&#8217;<\/li>\n<li>Select &#8216;Data Type&#8217;: &#8216;DEC&#8217;<\/li>\n<li>Set Length: &#8217;13&#8217; (or more)<\/li>\n<li>Set Decimals: &#8216;3&#8217; (or more)\u00a0<\/li>\n<\/ul>\n<h2>Function Module<\/h2>\n<p>Create the following function module:<\/p>\n<blockquote>\n<pre>FUNCTION z_mx_tab_set_comp_list.\r\n*\"----------------------------------------------------------------------\r\n*\"*\"Local Interface:\r\n*\"  IMPORTING\r\n*\"     REFERENCE(I_RSNUM) TYPE  RSNUM OPTIONAL\r\n*\"     REFERENCE(I_AUFNR) TYPE  AUFNR OPTIONAL\r\n*\"  TABLES\r\n*\"      T_MATNR STRUCTURE  ZMX_PI_TABLE_CHAR OPTIONAL\r\n*\"      T_POSNR STRUCTURE  ZMX_PI_TABLE_CHAR OPTIONAL\r\n*\"      T_BDMNG STRUCTURE  ZMX_PI_TABLE_NUM OPTIONAL\r\n*\"      T_MEINS STRUCTURE  ZMX_PI_TABLE_CHAR OPTIONAL\r\n*\"      T_ERFMG STRUCTURE  ZMX_PI_TABLE_NUM OPTIONAL\r\n*\"      T_ERFME STRUCTURE  ZMX_PI_TABLE_CHAR OPTIONAL\r\n*\"----------------------------------------------------------------------\r\n\r\n  DATA: ls_resb TYPE resb.\r\n\r\n  DELETE t_matnr FROM 1.\r\n  DELETE t_posnr FROM 1.\r\n  DELETE t_bdmng FROM 1.\r\n  DELETE t_meins FROM 1.\r\n  DELETE t_erfmg FROM 1.\r\n  DELETE t_erfme FROM 1.\r\n\r\n* Get reservation information\r\n  SELECT * FROM resb INTO ls_resb\r\n    WHERE aufnr EQ i_aufnr.\r\n\r\n    IF ls_resb-postp EQ 'L'.\r\n\r\n      t_posnr-value = ls_resb-posnr. APPEND t_posnr.\r\n      t_matnr-value = ls_resb-matnr. APPEND t_matnr.\r\n      t_bdmng-value = ls_resb-bdmng. APPEND t_bdmng.\r\n      t_meins-value = ls_resb-meins. APPEND t_meins.\r\n      t_erfmg-value = ls_resb-erfmg. APPEND t_erfmg.\r\n      t_erfme-value = ls_resb-erfme. APPEND t_erfme.\r\n\r\n    ENDIF.\r\n\r\n  ENDSELECT.\r\n\r\nENDFUNCTION.<\/pre>\n<\/blockquote>\n<p>Notes:<\/p>\n<ul>\n<li>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 &#8230; FROM 1).<br \/>\nTherefore 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.<\/li>\n<li>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.\u00a0<\/li>\n<li>If you use such a function module on a table where you also have input fields you should never delete any lines\u00a0once you begin to enter values in those input fields. This would mess up the table. Reading and modifying would be OK though.<\/li>\n<li>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_&#8230; \/ T2_&#8230;)<\/li>\n<\/ul>\n<h2>Process Instructions<\/h2>\n<table style=\"border: none;\">\n<tbody>\n<tr>\n<td style=\"border: none; background-color: #ebead8;\">Simple Instruction with Function Call:<\/p>\n<table cellspacing=\"0\" cellpadding=\"0\">\n<caption>Simple Data Request<\/caption>\n<thead>\n<tr>\n<th>Characteristic<\/th>\n<th>Value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr height=\"17\">\n<td>PPPI_FUNCTION_NAME<\/td>\n<td>Z_MX_TAB_SET_COMP_LIST<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_BUTTON_TEXT<\/td>\n<td>TEST<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_FUNCTION_DURING_DISPLAY<\/td>\n<td>0<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_TABLE_PARAMETER<\/td>\n<td>T_MATNR<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_STRING_VARIABLE<\/td>\n<td>T_MAT<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OPTIONAL_PARAMETER<\/td>\n<td>X<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_TABLE_PARAMETER<\/td>\n<td>T_BDMNG<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_FLOAT_VARIABLE<\/td>\n<td>T_QTY1<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OPTIONAL_PARAMETER<\/td>\n<td>X<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_TABLE_PARAMETER<\/td>\n<td>T_MEINS<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_STRING_VARIABLE<\/td>\n<td>T_UOM1<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OPTIONAL_PARAMETER<\/td>\n<td>X<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_TABLE_PARAMETER<\/td>\n<td>T_ERFMG<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_FLOAT_VARIABLE<\/td>\n<td>T_QTY2<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OPTIONAL_PARAMETER<\/td>\n<td>X<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_TABLE_PARAMETER<\/td>\n<td>T_ERFME<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_STRING_VARIABLE<\/td>\n<td>T_UOM2<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OPTIONAL_PARAMETER<\/td>\n<td>X<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_EXPORT_PARAMETER<\/td>\n<td>I_AUFNR<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_STRING_VARIABLE<\/td>\n<td>X_ORD<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OPTIONAL_PARAMETER<\/td>\n<td>X<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/td>\n<td style=\"border: none; background-color: #ebead8;\">Table:<\/p>\n<table cellspacing=\"0\" cellpadding=\"0\">\n<caption>Repeated Data Request (Table)<\/caption>\n<thead>\n<tr>\n<th>Characteristic<\/th>\n<th>Value<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr height=\"17\">\n<td height=\"17\">PPPI_DATA_REQUEST_TYPE<\/td>\n<td>REPEATED<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_VARIABLE<\/td>\n<td>T_MAT<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_MATERIAL<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_VARIABLE<\/td>\n<td>T_QTY1<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_MATERIAL_QUANTITY<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_VARIABLE<\/td>\n<td>T_UOM1<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_UNIT_OF_MEASURE<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_VARIABLE<\/td>\n<td>T_QTY2<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_MATERIAL_QUANTITY<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_VARIABLE<\/td>\n<td>T_UOM2<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_UNIT_OF_MEASURE<\/td>\n<td>\u00a0<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OUTPUT_TEXT<\/td>\n<td>Material<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OUTPUT_VARIABLE<\/td>\n<td>T_MAT<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OUTPUT_TEXT<\/td>\n<td>Qty1<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OUTPUT_VARIABLE<\/td>\n<td>T_QTY1<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OUTPUT_TEXT<\/td>\n<td>UoM1<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OUTPUT_VARIABLE<\/td>\n<td>T_UOM1<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OUTPUT_TEXT<\/td>\n<td>Qty2<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OUTPUT_VARIABLE<\/td>\n<td>T_QTY2<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OUTPUT_TEXT<\/td>\n<td>UoM2<\/td>\n<\/tr>\n<tr height=\"17\">\n<td height=\"17\">PPPI_OUTPUT_VARIABLE<\/td>\n<td>T_UOM2<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n","protected":false},"excerpt":{"rendered":"<p>Simple example of a function module with tabular parameters to fill or analyze a PI Sheet table.<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_links_to":"","_links_to_target":""},"categories":[52],"tags":[42,41],"_links":{"self":[{"href":"https:\/\/websha.de\/xstepcafe\/wp-json\/wp\/v2\/posts\/755"}],"collection":[{"href":"https:\/\/websha.de\/xstepcafe\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/websha.de\/xstepcafe\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/websha.de\/xstepcafe\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/websha.de\/xstepcafe\/wp-json\/wp\/v2\/comments?post=755"}],"version-history":[{"count":46,"href":"https:\/\/websha.de\/xstepcafe\/wp-json\/wp\/v2\/posts\/755\/revisions"}],"predecessor-version":[{"id":909,"href":"https:\/\/websha.de\/xstepcafe\/wp-json\/wp\/v2\/posts\/755\/revisions\/909"}],"wp:attachment":[{"href":"https:\/\/websha.de\/xstepcafe\/wp-json\/wp\/v2\/media?parent=755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/websha.de\/xstepcafe\/wp-json\/wp\/v2\/categories?post=755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/websha.de\/xstepcafe\/wp-json\/wp\/v2\/tags?post=755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}