Purpose
Implement and call up your own function module

Solution

  1. Check whether there is a BAPI that already fulfills your needs
    You can use the transactions BAPI (BAPI Explorer) and SE37 (Function Builder) to search for a suitable  BAPI or another RFC enabled SAP function module
  2. Design the function interface using IMPORT, EXPORT and TABLE parameters
    We suggest you use the external format for all parameters, for example allow customer numbers which do not necessarily contain leading zeros, or use the external form of material numbers, since the UI and GuiXT use the external formats. Perform the inbound and outbound conversions within your function module.
  3. Implement the function and test it with the SE37 test environment.
    You can store test data in the SE37 test environment which is practical during the implementation and testing of more complex functions
  4. Don't forget to set the "Remote-Enabled Mode" in SE37, "Attributes"
  5. Try out the function in a  test InputScript
  6. Use the call in your GuiXT scripts and InputScripts


Example

Transaction LS02N (Change Storage Bin) contains blocking indicators and a blocking code:

We want to add a small textbox so that the user can enter an explanatory text for the blocking:

The GuiXT script defines the text entry field as Textbox:

BoxSize G[Status] (9,78)
Text
(19,2) "Comment"
TextBox (19.5,1.4) (22.5,61.4) name="ls02n.blockingreason"

(see below for full GuiXT script)

In the SAP DataDictionary we add a field ZZBLOCKINGREASON in table LAGP:

As you see, the maximum size is 400 characters. If longer texts are needed we can use an SAP long text instead of defining the field within data LAGP.

Next, we write two function modules for reading and updating the variable:

Z_READ_LAGP_BLOCKINGREASON


Z_UPDATE_LAGP_BLOCKINGREASON

 

In the GuiXT script we read the text

// read blocking reason text
 
Call "Z_READ_LAGP_BLOCKINGREASON" _
  
in.LGNUM="&F[LAGP-LGNUM]" _
  
in.LGTYP="&F[LAGP-LGTYP]" _
  
in.LGPLA="&F[LAGP-LGPLA]" _
  
table.BLOCKINGREASON="ls02n.blockingreason"

When the user saves the storage bin data, we call up an InputScript:

// save, include blocking reason text
 On
"/11" fCode="/0" process="update_blockingreason.txt"

which updates the blocking reason text:


InputScript
"update_blockingreason.txt"

Screen
SAPML01S.0400

// update blocking reason text
Call "Z_UPDATE_LAGP_BLOCKINGREASON" _
  in.LGNUM="&F[LAGP-LGNUM]" _
  in.LGTYP="&F[LAGP-LGTYP]" _
  in.LGPLA="&F[LAGP-LGPLA]" _
  out.ERRMSG="errmsg" _
  table.BLOCKINGREASON="ls02n.blockingreason"

if V[errmsg]
 
Message "E: &V[errmsg]" -statusline
  Enter
else

  // Process Update
  Enter "/11"

endif

As you see, we first execute "/0" (Enter) and do the update after the Enter, so that our text update is not carried out when there are any error messages concerning the data entered by the user. On the other hand, if the /11 aborts with an error message, our text would already be updated. Pobably we can live with this situation. If not, we can first perform the "/11",  then check the success message and if it is ok call up our text update function.

GuiXT script "sapml01s.e0400"

// clear variables ls02n.xxxx if new transaction
if not V[_transactionid=&V[ls02n.transactiond]]
  Clear V[ls02n.*]
  Clear text[ls02n.*]
  Set V[ls02n.transactiond] "&V[_transactionid]"
endif

// key fields
Set
V[ls02n.lgnum] "&F[LAGP-LGNUM]"
Set V[ls02n.lgtyp] "&F[LAGP-LGTYP]"
Set V[ls02n.lgpla] "&F[LAGP-LGPLA]"

if V[ls02n.lgnum] and _
  
V[ls02n.lgtyp] and _
  
V[ls02n.lgpla] and _
  
not V[ls02n.readtext=X]

  // read blocking reason text
  Call "Z_READ_LAGP_BLOCKINGREASON" _
   
in.LGNUM="&F[LAGP-LGNUM]" _
   
in.LGTYP="&F[LAGP-LGTYP]" _
   
in.LGPLA="&F[LAGP-LGPLA]" _
   
table.BLOCKINGREASON="ls02n.blockingreason"

  // indicate: text read
  Set V[ls02n.readtext] "X"

endif

// data entry possible?
if I[LAGP-SPGRU]
  Set V[ls02.readonly] ""
else
  Set V[ls02.readonly] "-readOnly"
endif

BoxSize G[Status] (9,78)
Text (19,2) "Comment"
TextBox (19.5,1.4) (22.5,61.4) _
   name=
"ls02n.blockingreason" _
 
"&V[ls02.readonly]"

// shift standard fields below the text box
pos T[Stock per storage bin] (24,1)
pos P[First Page] (33,33)
pos P[Previous Page] (33,37)
pos P[Next Page] (33,41)
pos P[Last Page] (33,45)
pos P[Stor.unit] (33,16)
pos P[Quant] (33,1)

// on save, include blocking reason text
On "/11" fCode="/0" process="update_blockingreason.txt"

Components
InputAssistant