how to insert data to custom table in db using selection screen?
Is there standard class or method that can be use or need to create custom class?
requirement: after user give the input in the ADD selection-screen page, and hit the button 'add', data will be insert to the respective custom table in db.
How to proceed from here?
REPORT YTEST3.
tables YNAH_CUS_OBJ_REQ.
tables sscrfields.
type-pools : slis.
"DATA: flag TYPE c.
"DATA it_ucomm TYPE TABLE OF sy-ucomm.
TYPES: BEGIN OF TY_YNAH_CUS_OBJ_REQ, "CREATE STRUCTURE -1
REQID TYPE YNAH_REQ_ID,
REQUESTOR TYPE YNAH_REQUESTOR,
BUSINESS_OWNER TYPE YNAH_BUS_OWN,
FUNCTIONAL_OWNER TYPE YNAH_FUNC_OWN,
REQNUM TYPE YNAH_SERVICE_REQ_NUM,
PROJECT_ID TYPE YNAH_PRO_ID,
SYSTEM_ID TYPE YNAH_SYS_ID,
FUNCTIONAL_AREA TYPE YNAH_FUNC_AREA,
REQUEST_DATE TYPE YNAH_REQ_DATE,
REQUEST_TIME TYPE YNAH_REQ_TIME,
END OF TY_YNAH_CUS_OBJ_REQ.
DATA: IT_YNAH_CUS_OBJ_REQ TYPE TABLE OF TY_YNAH_CUS_OBJ_REQ,
WA_YNAH_CUS_OBJ_REQ TYPE TY_YNAH_CUS_OBJ_REQ.
DATA: it_fcat TYPE slis_t_fieldcat_alv.
DATA: wa_fcat TYPE slis_fieldcat_alv.
DATA MYALV TYPE REF TO CL_SALV_TABLE.
DATA MYFUNCTIONS TYPE REF TO CL_SALV_FUNCTIONS_LIST.
DATA MYCOLUMNS TYPE REF TO CL_SALV_COLUMNS_TABLE.
**********SELECTION-SCREENS*********************
*SELECTION-SCREEN FOR RADIO BUTTON 1
SELECTION-SCREEN BEGIN OF BLOCK menu WITH FRAME TITLE text-000.
selection-screen begin of line.
PARAMETER : P_SEARCH RADIOBUTTON GROUP g1 USER-COMMAND ONE DEFAULT 'X'.
selection-screen comment 7(9) for field p_search.
PARAMETER : P_ADD RADIOBUTTON GROUP g1.
selection-screen comment (9) for field p_add.
selection-screen end of line.
*SELECTION-SCREEN FOR RADIO BUTTON 1
SELECTION-SCREEN BEGIN OF BLOCK rad1 WITH FRAME TITLE text-001.
SELECT-OPTIONS:
s_reqid FOR WA_YNAH_CUS_OBJ_REQ-REQID MODIF ID ONE,
s_req FOR WA_YNAH_CUS_OBJ_REQ-REQUESTOR NO-EXTENSION NO INTERVALS MODIF ID ONE,
s_date FOR WA_YNAH_CUS_OBJ_REQ-REQUEST_DATE MODIF ID ONE.
SELECTION-SCREEN: BEGIN OF LINE,
pushbutton 55(12) BUT1 user-command search MODIF ID ONE.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK rad1.
*SELECTION-SCREEN FOR RADIO BUTTON 2
SELECTION-SCREEN BEGIN OF BLOCK rad2 WITH FRAME TITLE text-002.
PARAMETER:
p_req TYPE TY_YNAH_CUS_OBJ_REQ-REQUESTOR MODIF ID TWO,
p_busown TYPE TY_YNAH_CUS_OBJ_REQ-BUSINESS_OWNER MODIF ID TWO,
p_funown TYPE TY_YNAH_CUS_OBJ_REQ-FUNCTIONAL_OWNER MODIF ID TWO,
p_srvreq TYPE TY_YNAH_CUS_OBJ_REQ-REQNUM MODIF ID TWO,
p_proid TYPE TY_YNAH_CUS_OBJ_REQ-PROJECT_ID MODIF ID TWO,
p_sysid TYPE TY_YNAH_CUS_OBJ_REQ-SYSTEM_ID MODIF ID TWO,
p_funare TYPE TY_YNAH_CUS_OBJ_REQ-FUNCTIONAL_AREA MODIF ID TWO.
SELECTION-SCREEN: BEGIN OF LINE,
pushbutton 55(12) BUT2 user-command add MODIF ID TWO.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK rad2.
SELECTION-SCREEN END OF BLOCK menu.
*---------------------------
AT SELECTION-SCREEN OUTPUT.
*---------------------------
BUT1 = 'SEARCH'.
BUT2 = 'ADD'.
*CLICK OF FIRST RADIO BUTTON
"IF p_search = 'X'.
LOOP AT SCREEN.
IF screen-group1 = 'ONE'.
IF P_SEARCH = 'X'.
screen-invisible = '0'.
screen-active = '1'.
ELSE.
screen-invisible = '1'.
screen-active = '0'.
ENDIF.
MODIFY SCREEN.
ENDIF.
IF screen-group1 = 'TWO'.
IF P_ADD = 'X'.
screen-invisible = '0'.
screen-active = '1'.
ELSE.
screen-invisible = '1'.
screen-active = '0' .
ENDIF.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
at selection-screen. "after processing user input
case SSCRFIELDS.
when 'SEARCH'.
SSCRFIELDS-UCOMM = 'ONLI'.
endcase.
"fetch data using select for SEARCH
START-OF-SELECTION.
SELECT *
FROM YNAH_CUS_OBJ_REQ "Database
INTO CORRESPONDING FIELDS OF TABLE IT_YNAH_CUS_OBJ_REQ "Into internal table
WHERE
REQID in s_reqid and
REQUESTOR in s_req and
REQUEST_DATE in s_date.
TRY.
CALL METHOD CL_SALV_TABLE=>FACTORY
IMPORTING
R_SALV_TABLE = MYALV
CHANGING
T_TABLE = IT_YNAH_CUS_OBJ_REQ.
CATCH CX_SALV_MSG.
ENDTRY.
MYCOLUMNS = MYALV->GET_COLUMNS( ).
MYCOLUMNS->SET_OPTIMIZE( ).
MYFUNCTIONS = MYALV->GET_FUNCTIONS( ).
MYFUNCTIONS->SET_ALL( ).
CALL METHOD MYALV->DISPLAY.
I don't see any INSERT or MODIY statements in your code. You don't need any custom class for that. Check help for these statements.
TABLES YNAH_CUS_OBJ_REQ.
DATA WA TYPE YNAH_CUS_OBJ_REQ.
WA-REQID = '1'.
WA-REQUESTOR = p_req.
WA-BUSINESS_OWNER = p_busown.
...<<<add other fields also>>>
INSERT INTO YNAH_CUS_OBJ_REQ VALUES WA.
Related
I want to get the line where segnam = 'E1IDB02' and sdata starting with BB (-> sdata has a deeper structure. Therefore sdata has the type of the segnam. Thus means for the example further down, the first to rows have the type E1IDB02 and sdata in the third row has the type E1IDKU3. This will be clearer if you see the example coding further down) and then update a field in the structure in sdata.
For example I have following t_edidd-table:
segnam
sdata
E1IDB02
BA 123456 ...
E1IDB02
BB 987654 ...
E1IDKU3
...
One working solution:
FIELD-SYMBOLS: <ls_e1idb02> TYPE e1idb02.
LOOP AT t_edidd ASSIGNING FIELD-SYMBOL(<lv_edidd>) WHERE segnam = 'E1IDB02' AND sdata(2) = 'BB'.
ASSIGN <lv_edidd>-sdata TO <ls_e1idb02> CASTING.
<ls_e1idb02>-fiibkont = `01`.
ENDLOOP.
Or to be a little bit more clear:
FIELD-SYMBOLS: <ls_e1idb02> TYPE e1idb02.
LOOP AT t_edidd ASSIGNING FIELD-SYMBOL(<lv_edidd>) WHERE segnam = 'E1IDB02'.
ASSIGN <lv_edidd>-sdata TO <ls_e1idb02> CASTING.
IF <ls_e1idb02>-fiiquali = 'BB'. "<----
<ls_e1idb02>-fiibkont = `01`.
ENDIF.
ENDLOOP.
I wonder if there is a better solution for this?
What I have in mind is something like this (not working!):
FIELD-SYMBOLS: <ls_e1idb02> TYPE e1idb02.
ASSIGN t_edidd[ segnam = 'E1IDB02' sdata-fiiquali = 'BB' ]-sdata TO <ls_e1idb02> CASTING.
<ls_e1idb02>-fiibkont = `01`.
ASSIGN t_edidd[ segnam = 'E1IDB02' ]-sdata TO <result> CASTING. would work if I only have one entry with segnam = 'E1IDB02' but I need a second condition for sdata starting with BB or sdata field fiiquali of the structure E1IDB02.
What is working is following:
ASSIGN t_edidd[ segnam = 'E1IDB02' sdata(2) = 'BB' ]-sdata TO <ls_e1idb02> CASTING.
<ls_e1idb02>-fiibkont = `01`.
But due I want to cast the type of sdata into the structure e1idb02 getting the first 2 digits of sdata is not intentional in my opinion.
Hope my problem was understandable. If there is any information missing please let me know.
If someone wants to try this by themself I also wrote a unit test for my problem:
METHOD test.
DATA: ls_e1idb02 TYPE e1idb02,
ls_edidd TYPE edidd,
t_edidd TYPE TABLE OF edidd,
t_edidd_exp TYPE TABLE OF edidd.
ls_edidd-segnam = 'E1IDB02'.
ls_e1idb02-fiiquali = 'BA'.
ls_edidd-sdata = ls_e1idb02.
APPEND ls_edidd TO t_edidd.
APPEND ls_edidd TO t_edidd_exp.
ls_edidd-segnam = 'E1IDB02'.
ls_e1idb02-fiiquali = 'BB'.
ls_edidd-sdata = ls_e1idb02.
APPEND ls_edidd TO t_edidd.
ls_e1idb02-fiibkont = `01`.
ls_edidd-sdata = ls_e1idb02.
APPEND ls_edidd TO t_edidd_exp.
zclass->test(
CHANGING
t_edidd = t_edidd
).
cl_abap_unit_assert=>assert_equals(
act = t_edidd
exp = t_edidd_exp
).
ENDMETHOD.
rs_dd_check is a great function to check ddic objects. But the function module does not fit me that i can call it directly because i need to use it on older systems which only have the dialog and you can not export the messages out of the fm.
so i extracted some code out of it (out of perform check_object subroutine) which should be sufficient, and it is, for tables and structures it works!!! But for every other element it's not working. :(
Basically im creating a log and then doing check and then importing from memory id 'CHE' for example CHETABLSFLIGHT into variable/table lt_log
Im sure that for other elements it is creating logs but im not sure if it fill them up...Because lt_log stays empty.
report report name.
data: objname type rsedd0-ddobjname value 'object_name', eg sflighs
eutype type rsdxx-eutype value 'object_type', eg T
enqtype type rsdeo-objtype,
protid type sy-tabix,
titletxt TYPE sprot_i-prot,
actmode TYPE ddrefstruc-mode VALUE 9,
act_res type STANDARD TABLE OF dctablres,
lt_log type STANDARD TABLE OF trlogm .
*TRANSLATE T INTO TABL ETC
call function 'INTERN_TRANSL_EUTYPE' "Sperrtyp
exporting
eutype = eutype
importing
enqueue_type = enqtype.
*CREATING LOG?
call function 'DD_OBJ_PROT_OPEN'
exporting
objectname = objname
objecttype = enqtype
level = 1
device = 'M' "Memory with report RSPUTPRT as frontend
ddfunc = 'CHE'
importing
prid = protid
exceptions
others = 01.
*CHECKING SYNTAX
case eutype .
when 'T'.
titletxt = 'CHECKING TABLES'.
call function 'DD_TABL_ACT'
exporting
device = 'M'
path = ' '
tabname = objname
timer_on = ' '
prid = protid
act_mode = actmode
protname = ''
tables
act_res_tab = act_res
exceptions
others = 03. "Abbruch -> Protokoll anzeigen
when 'V'. "View
titletxt = 'CHECKING VIEWS'.
call function 'DD_VIEW_ACT'
exporting
viewname = objname
get_state = 'M'
act_mode = actmode
prid = protid
protname = ''
exceptions
others = 03.
when others.
endcase.
TRANSLATE OBJNAME USING '/-\-'.
data lv_mem_id(200) type c.
CONCATENATE 'CHE' enqtype objname into lv_mem_id. "EX CHETABLTABLE_NAME
IMPORT lt_log FROM MEMORY ID lv_mem_id.
I have a form with a ComboBox and a button. when the button is clicked, it's event should check that ComboBox has a value before proceeding.
ComboBox has a default value set:
Name=cmbName,
Default Value = "Joe",
RowSource=SELECT name
FROM table
ORDER BY name;
This is what I tried:
Private Sub btnOk_Click()
If (CmbName.ListIndex = -1)Then
Exit Sub
End If
'Do Something
End Sub
But every time I click the button, cmbName.ListIndex does equal -1, and the sub is exited even though there is a default value.
Not sure if I'm misunderstanding something; you can just use the IsNull() function.
If the user has changed the value away from the default value, back to a null value, then this will return True.
Private Sub btnOk_Click()
If IsNull(CmbName.Value) Then
Exit Sub
End If
'Do Something
End Sub
ListIndex is a property of ComboBox. It returns the index of the chosen value in the list. For example: If the first value is selected, comboBox.listIndex = 0. If there is no value, then comboBox.listIndex = -1.
If the user doesn't select a value from the list, then the value is the default "joe".
If the query SELECT name
FROM table
ORDER BY name returns a list in which there is no value "joe", then listIdex will still be -1.
Try:
If (CmbName.ListIndex = -1) And (Trim(CmbName.Value & "") = "")
Will return true if no value was selected and the box is empty.
How do I add icon_date and icon_time like in the transaction SM37 (selection screen in block job start condition)
I am trying this
SELECTION-SCREEN BEGIN OF BLOCK blk_1 WITH FRAME TITLE text-001.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(8) G_DATE FOR FIELD p_sdate .
SELECTION-SCREEN POSITION 25.
PARAMETERS: p_sdate TYPE sy-datum.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK blk_1.
////////////////////////////////////////////
INITIALIZATION.
CONCATENATE TEXT-003 ICON_TIME INTO G_TIME
SEPARATED BY SPACE. " Text-003 = 'Date'
//////////////////////////////////////////////
Output => To #1T#
There are a number of issues in your code:
Your comment variable is named G_DATE, but you're writing to G_TIME.
You're trying to assemble the text for yourself instead of using the standard function.
Your variable G_DATE is too short to store the complete formatted icon and text.
Try this:
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(60) g_date FOR FIELD p_sdate VISIBLE LENGTH 8.
SELECTION-SCREEN POSITION 25.
PARAMETERS p_sdate TYPE sy-datum.
SELECTION-SCREEN END OF LINE.
INITIALIZATION.
CALL FUNCTION 'ICON_CREATE'
EXPORTING
name = 'ICON_DATE'
text = 'Date'
info = 'da date, man'
add_stdinf = ' '
IMPORTING
result = g_date.
I'm having trouble adding dynamically a combo box column to my datagridview (before you ask, yes it must be dynamic and not done in editor).
The main feature is that the combobox cell is different for each row, so it must be done using combo box cell. checkedRows is a datatable.
Name of the datagridview is editCameraTable. It already has a few columns at this point:
'create new column
Dim resComboColumn As New DataGridViewComboBoxColumn _
With {.HeaderText = "Resolution", .ReadOnly = False, .DisplayIndex = 7, .Name = "Resolution", _
.DisplayMember = "Name", .ValueMember = "ID", .DataPropertyName = "ID"}
'add combo box column
EditCameras.editCameraTable.Columns.Insert(17, resComboColumn)
addResCmbBox(checkedRows, resComboColumn)
Pretty straight forward. You'll notice I have the value member, dataproperty name, etc. Here's the addResCmbBox definition:
Public Function addResCmbBox(ByRef DT As DataTable, column As DataGridViewComboBoxColumn)
Dim resolutions As String()
'for each camera
For i As Integer = 0 To DT.Rows.Count - 1
Dim camera As camera = convertDTtoCam(DT, i)
'get the resarray
Select Case DT.Rows(i).Item("Maker").ToString.ToLower
Case "acti"
resolutions = ACTi.GetResArray(camera)
Case Else
resolutions = ACTi.GetResArray(camera)
End Select
'add items to combobox list
Dim comboCell As New DataGridViewComboBoxCell
comboCell.DataSource = resolutions
For j As Integer = 0 To resolutions.Length - 1
'set to current resolution value
If resolutions(j).TrimStart("N") = camera.res Then
comboCell.Value = resolutions(j)
End If
Next
comboCell.DisplayMember = "Name"
comboCell.ValueMember = "ID"
EditCameras.editCameraTable("Resolution", i) = comboCell
Next
Return Nothing
End Function
camera is a structure. I have no problems until I get to the displayMember and value member problem, i.e. the last line starting with "editcameras.editcameratable...".
When doing so, the exception of "The Field Name does not exist" pops up. If I don't assign the displayMember and valueMember, I have no problems. But, I can't get the value selected in the comboBox (it comes back as Null). At runtime, the combobox column has the valuemember and display name as "ID" and "Name".
How can I bind this comboboxcell to the row so that I can later get it's selected value?
UPDATE:
I did as was commented, and created a struct/class that was meant to be the resolution property:
Public Class ResolutionStruct
Property Name As String
Property ID As String
End Class
And within the loop I create a list of this class, and assign the values to it:
Dim resolutionList As New List(Of ACTi.ResolutionStruct)
For j As Integer = 0 To resolutions.Length - 1
Dim resClass As New ACTi.ResolutionStruct
resClass.Name = resolutions(j)
resClass.ID = resolutions(j)
resolutionList.Add(resClass)
Next
'set combocell values
comboCell.DisplayMember = "Name"
comboCell.ValueMember = "ID"
comboCell.DataSource = resolutionList
EditCameras.editCameraTable("Resolution", i) = comboCell
However, the comboboxCell doesn't show any value when it drops down. So, now I've bound the values but it shows nothing. Is there anything else I should be doing so that I get both the holy combo of seeing the values I'm picking AND having them be bound to the data grid view? :D
UPDATE 2
So, mea culpa. I was adding the combobox cell to the wrong column!
So now, it is showing the values. I click a value, and try to grab the selected value as as string:
Dim cmbbox2 As DataGridViewComboBoxCell = editCameraTable("Resolution", i)
resolution(i) = cmbbox2.Selected.ToString()
But it still says it's a null value! Mid build I checked the combobox props. IN fact "selected" is a boolean as false. It has no value, says it has no items as well. Any ideas on why it says it is null?
UPDATE3:
I recently resorted a different column in the table, and the values from the combo box are cleared! I guess it's really never being attached/bound in the first place.
UPDATE4:
Fixed it!!
Apparently this line:
editCameraTable.Sort(editCameraTable.Columns("ID"), System.ComponentModel.ListSortDirection.Ascending)
Caused the table to freak out! I can now get the value (woohoo!)
Right, I'll try to explain this shortly:
DisplayMember and ValueMember are supposed to be set using properties. For example you create a class containing Name and ID
Public Class Test
Property Name as String
Property ID as String
End Class
Create a few of these objects and put them in a list. Set the list as the datasource to the combobox. Now you can access the DisplayMember and ValueMember as you have written it in your code. Value would be the ID and SelectedItem would be the entire class.
What you are doing now is that you are adding a list of strings to the combobox. A String does not contain the Property Name nor ID, so naturally you can't fetch them. See it like this:
To be able to use Value and/or DisplayMember you need to be able to fetch the Property by yourself. In this case:
resolutions(j).Name
or
resolutions(j).ID
This does not work.
But for example you would be able to do this:
resolutions(j).Length
So You would be able to do this, which would display the Length in the combobox:
Combobox.DisplayMember = "Length"
To currently get the value you would have to do:
Combobox.SelectedItem.ToString()
But since you have it in a combobox column My guess is that this won't cut it since you can't fetch the value from the DataGridView.
EDIT: You are still doing this right?
<DataGridView>.Item("Resolution", i) = comboCell
Otherwise you will have empty comboboxes.
EDIT2: No need to fetch value from Combobox, get it from Grid cell instead:
<DataGridView>.Item("Resolution", i).Value
When creating the columns don't forget to set a defaultvalue to the combobox, otherwise it might be Nothing:
comboCell.DisplayMember = "Name"
comboCell.ValueMember = "ID"
comboCell.Value = resolutions(0)