// Receive company codes from SAP and generate drop-down list function DoAcceptOptions() { var f = document.getElementById(‘cc’); var optlist = f.options; var opt = document.getElementById(‘optionstring’); var s = new Array(); s = opt.value.split(“~~~”); for (var i = 0; i<s.length-1; i +=2) { optlist[optlist.length] = new Option(s[i+1], s[i]); }; }; // Send changed value to SAP screen function cc_select(f) { if (f && typeof(f.value) == 'string') { window.location = "SAP://Company Code:" + f.value + ";"; }; }

 

GuiXT script

The GuiXT deletes the entry field for the company code and displays the HTML page instead. The coordinates in the “View” statement  use negative numbers and decimal places in order to fit the View area correctly into the SAP screen.

Since the SAP screen can come up with a default value for the company code (user specific value or value entered in previous transaction), we need to set the current value of F[Company Code] into the drop-down HTML field.

The first time the drop-down field is displayed, we generate the value list using a separate include file.

The whole GuiXT script:

del F[Company Code] -value
View (-0.5,63.4) (0.5,97.4) “ccdropdown.html” returnwindow=”hwnd_fb01_cc_dropdown” id=”fb01_ccdropdown”

if not V[ccdropdown_initialized]
  include “build_select_companycode.txt”
endif

Set HTML[select_cc] “&F[Company Code]“

 

Generation of the value list

We need an ABAP function module that reads all company codes with their texts from the SAP system. This can be a special function module that you write for this purpose, or you can use a general one like the SAP function “RFC_READ_TABLE”.

In our case here we use a function “Z_S10_SEARCHHELP” that has been written by Synactive as part of the Synactive S10 system (http://www.synactives10.com/s10forum). It reads searchhelp lists from the SAP system and can easily be used in GuiXT scripts.

The script reads all values into a text variable and then sends the values to the HTML page. For performance reasons, 100 entries are concatenated each time into a single string and then sent.

-> For large lists, it is currently not possible to send all values in a single string because of  a capacity limit of the statement length in GuiXT (4000 characters). For this reason, a blocking of 100 values each time is used.

GuiXT script “build_select_companycode.txt”:


// Indicate: initialized
Set V[ccdropdown_initialized] “X”

// read values from SAP
Call “Z_S10_SEARCHHELP” in.SEARCHHELP=”H_T001″ in.COLUMNS=”BUKRS(4),BUTXT(25)” table.DATA=”data”

set V[i] 1
set V[k] 1
set V[cc_option] “”
set Text[options] “”

label cc_next

CopyText fromText=”data” toString=”line” line=&V[i]
if not Q[ok]
  goto cc_done
endif

Set V[cc_code] “&V[line](1-4)”
Set V[cc_text] “&V[line](5-29)”
Set V[cc_option] “&V[cc_code]~~~&V[cc_code] &V[cc_text]~~~”

CopyText fromString=”cc_option” toText=”options” -append

Set V[i] &V[i] + 1
Set V[k] &V[k] + 1
 

// send 100 entries
if V[k=100]
  CopyText fromText=”options” toString=”cc_option”
  set Text[options] “”
  Set HTML[text_optionstring] “&V[cc_option]“
  connectHTML click=”button_AcceptOptions” window=”&V[hwnd_fb01_cc_dropdown]“
  Set V[k] 1
endif

goto cc_next

label cc_done
 

// send remaining entries
CopyText fromText=”options” toString=”cc_option”
set Text[options] “”
Set HTML[text_optionstring] “&V[cc_option]“

connectHTML click=”button_AcceptOptions” window=”&V[hwnd_fb01_cc_dropdown]“

 

Dynamic drop-down entry fields (1)