I have defined a list box in my selection screen, as follows:
SELECTION-SCREEN BEGIN OF BLOCK B2 WITH FRAME TITLE ALTITLE1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (30) ALCONT4 FOR FIELD L1.
PARAMETERS: L1 AS LISTBOX VISIBLE LENGTH 20 MODIF ID AOD.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK B2.
Now I need to propose possible values for that list box, how can I do it ?
During the PBO of your screen (for selection screens, the PBO code is defined inside the event block AT SELECTION-SCREEN OUTPUT), you must call the function module VRM_SET_VALUES, passing the name of the field and a list of values.
SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE altitle1.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT (30) alcont4 FOR FIELD l1.
PARAMETERS: l1 AS LISTBOX VISIBLE LENGTH 20 MODIF ID aod.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK b2.
INITIALIZATION.
alcont4 = 'Choose the country'(001).
AT SELECTION-SCREEN OUTPUT.
DATA: lt_value TYPE vrm_values,
ls_value TYPE vrm_value.
ls_value-key = 'DE'.
ls_value-text = 'Germany'.
APPEND ls_value TO lt_value.
ls_value-key = 'FR'.
ls_value-text = 'France'.
APPEND ls_value TO lt_value.
CALL FUNCTION 'VRM_SET_VALUES'
EXPORTING
id = 'L1'
values = lt_value
EXCEPTIONS
id_illegal_name = 1
OTHERS = 2.
Execution:
For information, you can achieve the same result from the database table of countries T005T, by transferring the entries to an intermediate internal table:
DATA: lt_t005t TYPE TABLE OF t005t,
ls_t005t TYPE t005t.
SELECT * FROM t005t
INTO TABLE lt_t005t
WHERE spras = 'E' " English names of countries
AND land1 IN ('FR','DE').
LOOP AT lt_t005t INTO ls_t005t.
ls_value-key = ls_t005t-land1.
ls_value-text = ls_t005t-landx50.
APPEND ls_value TO lt_value.
ENDLOOP.
You may find more information in the SAP Library (the explanations are valid for all kind of screens, the examples are only for classic screens but they may be adapted easily to selection screens): http://help.sap.com/saphelp_470/helpdata/en/9f/dbabe435c111d1829f0000e829fbfe/frameset.htm
Related
I have several fields on a form that absolutely will not display a boolean value which is set to display as Yes/No, the dropdown menu is set to only offer Yes/No as options, but no matter what I do, the values displayed on the form always show True/False instead. Pictures below:
At this point I'm not entirely sure what it is that's causing this, but it's kind of annoying.
If you want to use a ComboBox, set the ComboBox properties as follows
In the data section:
Control Source = <name of your table or query column>
Row Source Type = Value List
Row Source = -1;Yes;0;No ' Alternating values and texts.
Bound Column = 1
Limit To List = Yes
In the format section
Column Count = 2 ' Because we have a value and a text.
Column Widths = 0cm ' This makes the first column invisible.
I have a Data table with an Auto Filter (shown Below).
Sub Tariff_Filter()
Dim columnNumber, tableRow, tableColumn, tableWidth As Integer
Dim tableName, columnName As String
tableName = "Tariff_Table"
columnName = ActiveSheet.Range("A1").Value
'This clears the existing filter
ActiveSheet.ListObjects(tableName).Range.AutoFilter
'Assign some numbers we need to know about the table to check the headers
tableRow = ActiveSheet.ListObjects(tableName).Range.Row
tableColumn = ActiveSheet.ListObjects(tableName).Range.Column
tableWidth = ActiveSheet.ListObjects(tableName).Range.Columns.Count
'If a column title with the specified value does not exist VBA throws an error which we need to catch
On Error GoTo ErrorHandler
'Search through the table column header row to find the specified column and assign the number to columnNumber
columnNumber = Application.WorksheetFunction.Match(columnName, Range(Cells(tableRow, tableColumn), Cells(tableRow, tableColumn + tableWidth)), 0)
'Apply the filter "1" to the found columnNumber
ActiveSheet.ListObjects(tableName).Range.AutoFilter field:=columnNumber, Criteria1:="1"
'Exit the sub otherwise the "error handling" will be provoked
Exit Sub
ErrorHandler:
MsgBox columnName & "Please Specify Required Channel"
End Sub
As i cant seem to figure out how to get my combo-box's to show only the visible cells after filtering the table i was wondering if there is a way i can create a a validation box to show the visible cells or copy the visible data into a seperate table underneath. I can then use the validation box/ secondary table as a focus point for the combo-box's on the user-form.
Thanks in advance
If I'm understanding your question correctly, you would like to have a data-validation drop-down list that updates as the table is filtered and only displays visible items for a given column.
You can do this by using the following formula in Data Validation (I'm assuming your table header row starts in A1 and it's col A you need to display):
=OFFSET($A$2,,,SUBTOTAL(103,TableName[column name]))
This formula expands from the starting cell (A2) by a specified height in number of rows. We are defining the height using SUBTOTAL with function number 103 - this means that the height is defined using COUNTA, but only on visible cells, so it will expand and collapse as the table is filtered.
Be aware: since the height is defined using a counta function, it will only count cells containing data, therefore if you have blanks in your table, the range will not be defined correctly. Also if you have any repeated data, these will be repeated in your drop-down box, this method will not condense them into a neat, unique list.
Hope this is helpful.
D
I've a Z-table which has certain number of records for
now say 15 records. Using these 15 records and based
on 2 fields say group and position I've to create 15
check boxes in selection screen dynamically. If in
future the Z-table records are updated to 25 or 30
records . I need 25-30 check boxes in selection screen
dynamically with out change in the code..
Please help with this problem...
Here's a suggestion. Instead of generating checkboxes from your table lines you could easily populate a dropdown menu or better yet an ALV grid with the values from your table, which can then in turn be selected by the user. Evaluating the user selection programmatically will be easy enough. Plus you won't have to worry about varying dynpro sizes as your table grows further.
Here is a solution with an upper limit of 10 dynamical check boxes on the selection screen with dynamic descriptions and value assignment.
REPORT ztest_check_boxes.
DATA: g_num_check_boxes TYPE i,
g_num_cb_shown TYPE i,
g_first_time TYPE abap_bool VALUE abap_true.
FIELD-SYMBOLS: <cb> TYPE flag,
<text> TYPE any.
PARAMETERS: px_01 AS CHECKBOX MODIF ID cb,
px_02 AS CHECKBOX MODIF ID cb,
px_03 AS CHECKBOX MODIF ID cb,
px_04 AS CHECKBOX MODIF ID cb,
px_05 AS CHECKBOX MODIF ID cb,
px_06 AS CHECKBOX MODIF ID cb,
px_07 AS CHECKBOX MODIF ID cb,
px_08 AS CHECKBOX MODIF ID cb,
px_09 AS CHECKBOX MODIF ID cb,
px_10 AS CHECKBOX MODIF ID cb.
INITIALIZATION.
" Determine the number of checkboxes to show,
" for simplicity I just hard coded this
g_num_check_boxes = 3.
AT SELECTION-SCREEN OUTPUT.
g_num_cb_shown = 0.
LOOP AT SCREEN.
IF screen-group1 EQ 'CB'.
" This will trigger on the check box
" as well as their descriptions
IF g_num_cb_shown LT g_num_check_boxes.
" Need to display this check box
CASE screen-group3.
WHEN 'PAR'.
" This is the check box
" you can set the value here dynamically.
" Should only be done once
IF g_first_time EQ abap_true.
ASSIGN (screen-name) TO <cb>.
IF ( g_num_cb_shown MOD 2 ) EQ 0.
<cb> = 'X'.
ENDIF.
ENDIF.
WHEN 'TXT'.
" This is the text, you could set this with
" data from your database table
ASSIGN (screen-name) TO <text>.
<text> = `Checkbox ` && g_num_cb_shown.
" TXT comes after PAR, so we should do this here
ADD 1 TO g_num_cb_shown.
ENDCASE.
ELSE.
" Need to hide this check box
screen-active = '0'.
MODIFY SCREEN.
ENDIF. " Display?
ENDIF. " Check box?
ENDLOOP. " SCREEN
g_first_time = abap_false.
START-OF-SELECTION.
...
Ok so I am making a sheet where a user would select a value from a dropdown and then needs to see the required parameters based on the selection.
Example:
If i select X from the drop down then three new input fields would be created and formatted as input cells with the parameter as the default value (so the yellowish orange input format with default text explaining what the parameter is -- like start date for one then the next end date)
My start:
Sub test()
If ActiveCell = "setEnrollnet" Then
ActiveCell.Offset(0, 1) = startDate
ActiveCell.Offset(1).EntireRow.Insert
ActiveCell.Offset(1, 1) = 0
ActiveCell.Offset(0, 2) = endDate
ActiveCell.Offset(1).EntireRow.Insert
ActiveCell.Offset(1, 2) = 0
End If
End Sub
This does not work well and it does not apply formatting. I need help figuring out how to do both format and input the correct text based on selection in another cell.
I suggest - for each value in the drop down list - you define the input fields in a seperate sheet, together with field labels and formats. After selection from the drodown, you scan the parameter table and copy whatever is listed for that parameter to your input sheet.
Example (range named InputParams):
ParamVal InputLabel InputField
X StartDate (empty but formatted)
X EndDate (empty but formatted)
Y Foo default_Foo
Y Bar default_Bar
Upon selecting "X" from the dropdown list you walk through InputParams and,
If InputParams(Idx, 1) = DropDownValue Then copy cells InputParams(Index,2) and InputParams(Index,3) to your input range - by default formats are copied along with content.
It is desireable to define a named range also for Input, giving it a size of maximum parameters expected, so that you can clear content and formats with one single statement prior to re-populating this range when walking through the InputParams list.
I am coding up a VBA script to create & email a table of data. And while it does work, it's also ugly. One thing I'd like to do is resize these columns so they don't take up the entire width of the page.
The "autosize column" option would be nice, except I don't see anywhere in the API. Alternatively, I'm open to manually setting the widths of each column. Can someone tell me what code I need to add?
Dim rtNav As NotesRichTextNavigator
Dim rtTbl As NotesRichTextTable
Dim TblHeader_FontStyle As NotesRichTextStyle
Dim TblBody_BackgroundStyle As NotesRichTextStyle
Dim TblHeader_BackgroundStyle As NotesColorObject
Dim TblBody_FontStyle As NotesColorObject
Sub AppendTable()
'Define styles
Set TblHeader_BackgroundStyle = NtSession.CreateColorObject
TblHeader_BackgroundStyle.NotesColor = COLOR_DARK_BLUE
Set TblHeader_FontStyle = NtSession.CreateRichTextStyle
TblHeader_FontStyle.NotesColor = COLOR_WHITE
TblHeader_FontStyle.FontSize = 8
Set TblBody_FontStyle = NtSession.CreateColorObject
TblBody_FontStyle.NotesColor = COLOR_WHITE
Set TblBody_BackgroundStyle = NtSession.CreateRichTextStyle
TblBody_BackgroundStyle.NotesColor = COLOR_BLACK
TblBody_BackgroundStyle.FontSize = 10
'-----------------------------------------------------
'Make table structure
NtBod.AppendTable lRowCount:=1, lColumnCount:=5
Set rtNav = NtBod.CreateNavigator
Set rtTbl = rtNav.GetFirstElement(RTELEM_TYPE_TABLE)
rtTbl.Style = TABLESTYLE_TOP
Call NtBod.AppendStyle(TblHeader_FontStyle)
Call rtTbl.SetColor(TblHeader_BackgroundStyle)
rtNav.FindFirstElement (RTELEM_TYPE_TABLECELL)
'The rest of the procedure to navigate the table and insert the data goes here
There is a parameter in the AppendTable method that lets you specify the style for each column, including the width.
From the AppendTable method documentation:
Call
notesRichTextItem.AppendTable(rows%,
columns% [, labels] [,leftMargin&]
[, rtpsStyleArray] )
Parameters:
rows% Integer. Number of rows in the table.
columns% Integer. Number of columns in the table.
labels Array of type String. Optional. Text of labels for a tabbed
table. The number of array elements
must equal the number of rows.
Omitting this parameter appends a
basic table. Including this parameter
appends a tabbed table.
leftMargin& Long. Optional. Left margin of the table in twips.
Defaults to 1440. The following
constants are available:
RULER_ONE_CENTIMETER (567)
RULER_ONE_INCH (1440)
rtpsStyleArray Array of type NotesRichTextParagraphStyle. Optional.
Creates a table with fixed-width
columns and style attributes as
specified. Omitting this parameter
creates an auto-width table. The
array must contain one element for
each column in the table in sequence.
Explicitly set the first line left
margin and left margin, which control
the start of text relative to the
start of the column, and the right
margin, which controls column width.