Display a production order

Production orders are an essential part of planning and management. Since not every product is always in stock, a new customer order may initiate a production order. The following example makes this information available for the CIS mobile user by way of an add-on.     



Production order details unfolded
Step 1:
Display placeholders for add-ons

Go to the CIS mobile settings and activate the test output for add-ons. Then navigate to the position in CIS mobile where you want to have the additional information displayed, in this example the detailed view of a customer order. The orange placeholders will be replaced immediately, the yellow ones will show more information when the user clicks on a (+) button.
A production order won't always exist for a product so we will only show a (+) button if one does exist. To do so we have to implement a method "BuildOrderPositionButtons2" in the add-on project "s10cisaddon.sln".


Activate placeholders for add
-ons



Positions for potential add-ons

Step 2:
Keys for the request

Click on one of the colored placeholders to display a list of all keys and their values that are available in this position. In order to request data from the SAP system we need the order number (VBELN), the item number (POSNR) and of course the customer number (KUNNR). All keys displayed here are available in a dictionary object in VB.net. 


Keys required for a production order

Step 3:
Implement in VB.net

The name of the method in VB.net consist of "Build" + the name of the placeholder.  The signature looks like this:

VB.net
 ' Position to Order Addon 
    Public Function BuildOrderPositionButtons2(ByVal keys As _
                     Dictionary(Of String, String), _ 
	ByRef buttons As String) As String

The parameter "keys" refers to a dictionary object containing the required key-value pairs. A textstring "buttons" is used to define another (+) button to unfold more details about the production order e.g. the components and processes. 
Step 3.1:
Is a production order available?

We read table "AUFK" to check whether or not there is a production order. To do so we first have to create a new class "aufk" in the S10 repository. Click on "create from SAP table" to let the repository generate the class for you. Please change the assembly name to "s10addon" and add "database='sap' " to the signature of the class. Then include the generated .vb file into the vb.net addonproject "s10addon.sln".


Display tables and views with SE11



Generate classes with the s10 repository



Configure the class for the add
-on project


Define
object of class "aufk" in the repository


We use the S10 repository to create the objects. This can also be done within the VB.net coding. We use folder (array) and count the number of elements after requesting the data from the SAP system to determine whether there is any production order.

VB.net
        ' where-condition for SAP Select
        Dim where As String = ""
        where &= " KDAUF = '" & _
                     GetItem(keys, "VBELN").PadLeft(10, "0") & "'"
        where &= " AND KDPOS = '" & GetItem(keys, "POSNR") & "'"


        productionorders.Clear()
        productionorders.RfcDatabaseSelect(where)

        ' Check, if production order is available 
        ' Yes? Then create (+) button    
        If productionorders.Count > 0 Then

            ' Texts from addon.texts.txt
            Dim buttonText As String = ic.MessageText("PORD")
            Dim processingMessage As String = ic.MessageText("PORD_MSG1")

            'Define (+)Button 
            buttons = "ProductionOrder|" & buttonText & "|" & processingMessage

        End If

Recommended: Index for table aufk

In order to speed up data-access you can create an index for table aufk in SE11 using only those fields which are needed for the add-on.



Creating a new index for table AUFK
Result of step 3.1

The (+) button to display details of a production order is now only available for item 20 and not for item 10. In the following step we will request the data appropriate to the a selected production order.


The new add
-on is highlighted in yellow

Step 4:
Production order details

In step 3.1 we have made it possible for the user to unfold some additional information about a production order:

VB.net
            'Define (+)Button 
            buttons = "ProductionOrder|" & buttonText _
                                   & "|" & processingMessage

Now we have to implement the method "BuildProductionOrder" that requests the information about the production order from the SAP system and returns it as a HTML5 formatted text string.

Please see the example code in the add-on project. The procedure is almost the same as in step 3.1 except that some of the data is read via the SAP GUI scripting interface:

VB.net
        ' read some values with sapgui-scripting
        Dim dic As New Dictionary(Of String, String)
        ReadWithSapGui_ProductionOrder(productionorder.aufnr, dic)

We will have a look at this in the following step.
Step 4.1:
SAP GUI Scripting interface

We assume that the SAP GUI Scripting interface is already configured and ready to use. Please see the installation manual if this is not the case.
Using the interface is quite simple: After logging on to the SAP system (lines 7 to 10) you can start transactions and read values from inputfields or even a whole table.

Hint: In many cases the required data is placed on several tabs. They can be activated by using the corresponding transaction code. You can use the recorder of GuiXT for input scripts to determine those TCodes.

NB: Requesting data with this interface is usually far slower than using RFC calls or BAPIs. Please see the documentation for more details and a comparison of the possible access points.

VB.net
   Public Sub ReadWithSapGui_ProductionOrder(ByVal AUFNR As String, _ 
      ByRef dic As Dictionary(Of String, String))

        'SAP-Connectionsettings saved in config-textfile
        ReadSapSettings()

        'Logon to SAP-GUI
        If addon.sapgui Is Nothing Then
            addon.sapgui = New sapguisession(sapconnect, _
                                 sapconnectclient, sapconnectuser, _ 
            sapconnectpassword, ic.Session.Language)
            addon.sapgui.Logon()
        End If

        Dim sapgui As sapguisession = addon.sapgui

        ' Start transaktion CO03
        sapgui.Enter("/nCO03")

        ' Enter number of productionorder
        sapgui.SetField("CAUFVD-AUFNR", AUFNR)
        sapgui.Enter()

        'Collect some data
        dic.Add("GWEMG", sapgui.GetField("CAUFVD-GWEMG")) 'Delivered
        dic.Add("GASMG", sapgui.GetField("CAUFVD-GASMG")) 'Total scrap
        dic.Add("APROZ", sapgui.GetField("CAUFVD-APROZ")) 'scrap in %
        dic.Add("MIMEZ", sapgui.GetField("CAUFVD-MIMEZ")) 'Expected 
        'Goto Tab "Assignment"
        sapgui.Enter("=KOAL")

        'Collect some data
        dic.Add("DISPO", sapgui.GetField("CAUFVD-DISPO"))  'MRP Contr.
        dic.Add("DSNAM", sapgui.GetField("T024D-DSNAM"))   'Name of MRP
        dic.Add("FEVOR", sapgui.GetField("CAUFVD-FEVOR"))  'Supervisor
        dic.Add("T024F-TXT", sapgui.GetField("T024F-TXT")) 'Description
Step 5:
Displaying a diagram

This add-on not only displays details about the production order but also shows the relevant list of operations and components. We define two (+) buttons to make this information available to the user:

VB.net
                Dim buttonText1 As String = ic.MessageText("PORD_OPER")
        Dim buttontext2 As String = ic.MessageText("PORD_COMP")

        Dim processingMessage1 As String = ic.MessageText("PORD_OPERMSG")
        Dim processingMessage2 As String = ic.MessageText("PORD_COMPMSG")

        buttons = "ProductionOrderOperations|" & buttonText1 & _
                                 "|" & processingMessage1 _
        & ",ProductionOrderComponents|" & buttontext2 & "|" _
           & processingMessage2


NB: In line 7 two buttons are defined in one string, seperated by a comma.

In addition to this information we want to offer the user a Gantt chart. To do so we define another button referring to a method that will create an image file with the diagram using the ChartDirector tool (or any other image creating tool).


VB.net
        ' Create (+)Button to show GanttDiagram
        buttons = "ProductionOrderOperationsDiagram|" & _
                       ic.MessageText("PORD_DIAGSCHED") & "|" _ 
        & ic.MessageText("PORD_DIAGCREATE")

    'Create Ganttchart with tool ChartDirector
    Public Function BuildProductionOrderOperationsDiagram(ByVal keys As 
                                            Dictionary _ 
           (Of String, String), ByRef buttons As String) As String

        'Define path for imagefile
        Dim outputpath = ic.Session.RootPath + "\" + _
                              ic.Session.TempPath + _
                             "\charts\" + ic.Session.User

        'Create path if it does not exist
        System.IO.Directory.CreateDirectory(outputpath)

        <...>


        'Let ChartDirector create the diagram-imagefile
        Dim img As System.Drawing.Image
        img = c.makeImage()

        'Save image to disk
        img.Save(outputpath + "\" + "diagram_" + timestamp + ".png", _ 
        System.Drawing.Imaging.ImageFormat.Png)

        ' Create img-tag in html-code 
        Dim htmlstring As String = ""
        htmlstring = "<img alt='' src='../../../" + _
                               ic.Session.TempPath + "/charts/" _
        + ic.Session.User + "/diagram_" + timestamp + ".png'>"

        Return htmlstring


    End Function

Result of step 5


No buffers in this production order!