SQL statement return results into ALV table - abap

I am fairly new to ABAP and wrote a SQL statement to return a list of items into an ALV. However when I execute the program, it returns nothing. Below is the code I wrote. I created a table type to show only the columns I needed in the results.
REPORT Z_DISPLAY_RESULTS.
TYPES: BEGIN OF t_Display,
foodItem TYPE foodList-foodItem,
foodDescription TYPE foodList-foodDescription,
END OF t_Display.
DATA: it_Display TYPE STANDARD TABLE OF t_Display INITIAL SIZE 0,
wa_Display TYPE t_Display,
wa_Display1 LIKE LINE OF it_Display.
START-OF-SELECTION.
SELECT foodItem foodDescription
FROM foodList INTO TABLE it_Display
WHERE foodID = '00001'.
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
* I_INTERFACE_CHECK = ' '
* I_BYPASSING_BUFFER =
* I_BUFFER_ACTIVE = ' '
* I_CALLBACK_PROGRAM = ' '
* I_CALLBACK_PF_STATUS_SET = ' '
* I_CALLBACK_USER_COMMAND = ' '
I_STRUCTURE_NAME = 'foodList'
* IS_LAYOUT =
* IT_FIELDCAT =
* IT_EXCLUDING =
* IT_SPECIAL_GROUPS =
* IT_SORT =
* IT_FILTER =
* IS_SEL_HIDE =
* I_DEFAULT = 'X'
* I_SAVE = ' '
* IS_VARIANT =
* IT_EVENTS =
* IT_EVENT_EXIT =
* IS_PRINT =
* IS_REPREP_ID =
* I_SCREEN_START_COLUMN = 0
* I_SCREEN_START_LINE = 0
* I_SCREEN_END_COLUMN = 0
* I_SCREEN_END_LINE = 0
* IR_SALV_LIST_ADAPTER =
* IT_EXCEPT_QINFO =
* I_SUPPRESS_EMPTY_DATA = ABAP_FALSE
* IMPORTING
* E_EXIT_CAUSED_BY_CALLER =
* ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = it_Display
* EXCEPTIONS
* PROGRAM_ERROR = 1
* OTHERS = 2
.
IF SY-SUBRC <> 0.
ENDIF.

Don't learn obsolete stuff - use the new class-based API.
Double-check whether the table is actually filled using the debugger.
I_STRUCTURE_NAME refers to a global DDIC type. If you're using a local type, you will probably need to supply the field catalog yourself - with this obsolete function module. With the new class-based API, this is not (no longer?) needed.

Related

Add or Update data in Checkbox + Radiobutton Visual basic

Okay, this is my problem; I have code like this:
Private Sub process_Click(sender As Object, e As EventArgs) Handles hitung.Click
If radiobuttonplus.Checked = True Then
Me.h1.Text = Val(txt1.Text) + Val(txt5.Text)
Me.h2.Text = Val(txt2.Text) + Val(txt6.Text)
Me.h3.Text = Val(txt3.Text) + Val(txt7.Text)
Me.h4.Text = Val(txt4.Text) + Val(txt8.Text)
result = (h1.Text * h4.Text) - (h2.Text * h3.Text)
resultdeterminan.Text = result
ElseIf checkboxadjoint.Checked = True Then
Me.a1.Text = 1 * (Val(Me.h4.Text))
Me.a2.Text = -1 * (Val(Me.h3.Text))
Me.a3.Text = -1 * (Val(Me.h2.Text))
Me.a4.Text = 1 * (Val(Me.h1.Text))
result = (a1.Text * a4.Text) - (a2.Text * a3.Text)
resultdeterminan.Text = result
resultadjoint.Text = result
End if
End Sub
As you can see, radiobuttonplus has data underneath it and checkbuttonadjoint also has data below it.
I use checkbuttonadjoint to update data from radiobuttonplus.
Initially, there were no problems regarding radiobuttonplus, because I tried to successfully display all the data in radiobuttonplus; however, the problem arose when I clicked radiobutton + ticked checkbuttonadjoint. The data in checkbuttonadjoint is not displayed and does not update the data from radiobuttonplus.
Because you have ElseIf, when the first If is executed the second block will never be executed. If you want both to execute then change ElseIf to simply If. You'll need to add an End If before that to close off the first block.
So when you're all done, it'd look like this:
Private Sub process_Click(sender As Object, e As EventArgs) Handles hitung.Click
If radiobuttonplus.Checked = True Then
Me.h1.Text = Val(txt1.Text) + Val(txt5.Text)
Me.h2.Text = Val(txt2.Text) + Val(txt6.Text)
Me.h3.Text = Val(txt3.Text) + Val(txt7.Text)
Me.h4.Text = Val(txt4.Text) + Val(txt8.Text)
result = (h1.Text * h4.Text) - (h2.Text * h3.Text)
resultdeterminan.Text = result
End If
If checkboxadjoint.Checked = True Then
Me.a1.Text = 1 * (Val(Me.h4.Text))
Me.a2.Text = -1 * (Val(Me.h3.Text))
Me.a3.Text = -1 * (Val(Me.h2.Text))
Me.a4.Text = 1 * (Val(Me.h1.Text))
result = (a1.Text * a4.Text) - (a2.Text * a3.Text)
resultdeterminan.Text = result
resultadjoint.Text = result
End If
End Sub

Why values are not displayed for some columns of an ALV List?

I am trying to create an ALV report with list display but some of the contents are not displaying in the output list. I created a classical report and an ALV report with grid display and I was successful. But this list display is creating a problem.
I've included the REUSE_ALV_LIST_DISPLAY function, with the right internal table name. I've debugged and all my data is coming in the final internal table correctly but it is not displaying in output list:
Here is my code (note that the flight demo data is to be generated via the program SAPBC_DATA_GENERATOR, once):
REPORT ztest.
SELECT scarr~carrid, spfli~connid
FROM scarr INNER JOIN spfli ON scarr~carrid = spfli~carrid
INTO TABLE #DATA(it_f).
DATA(it_fcat) = VALUE slis_t_fieldcat_alv(
( tabname = 'SCARR'
fieldname = 'CARRID'
seltext_l = 'Carrier code'
col_pos = 1
outputlen = 20 )
( tabname = 'SPFLI'
fieldname = 'CONNID'
seltext_l = 'Connection ID'
col_pos = 2
outputlen = 20 ) ).
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = it_fcat
TABLES
t_outtab = it_f.
In a simple ALV table, you don't have to fill the component TABNAME of the field catalog. TABNAME is only needed for the hierarchical-sequential lists (function module REUSE_ALV_HIERSEQ_LIST_DISPLAY for instance) which are an output of two tables.
If you omit it, or if you give the same value (any value) for all columns, you will get a correct output:
Code with the correction:
SELECT scarr~carrid, spfli~connid
FROM scarr INNER JOIN spfli ON scarr~carrid = spfli~carrid
INTO TABLE #DATA(it_f).
DATA(it_fcat) = VALUE slis_t_fieldcat_alv(
( " do not fill TABNAME // tabname = 'SCARR'
fieldname = 'CARRID'
seltext_l = 'Carrier code'
col_pos = 1
outputlen = 20 )
( " do not fill TABNAME // tabname = 'SPFLI'
fieldname = 'CONNID'
seltext_l = 'Connection ID'
col_pos = 2
outputlen = 20 ) ).
CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
EXPORTING
it_fieldcat = it_fcat
TABLES
t_outtab = it_f.
EDIT: I see that you two already solved the problem in comments.
As Sandra wrote, you could try using cl_salv_table. It should look like this:
cl_salv_table=>factory(
* EXPORTING
* list_display = if_salv_c_bool_sap=>true
* r_container =
* container_name =
IMPORTING
r_salv_table = DATA(lr_alv)
CHANGING
t_table = it_f
).
lr_alv->display( ).

How to assign notification to work order through BAPI?

I would like to assign a notification to a work order. The following does not work:
* Fill method structure
ls_methods-refnumber = 1.
ls_methods-method = 'SAVE'.
APPEND ls_methods TO lt_methods.
ls_methods-refnumber = 1.
ls_methods-objecttype = 'OBJECTLIST'.
ls_methods-method = 'CHANGE'.
ls_methods-objectkey = '000480000020'.
APPEND ls_methods TO lt_methods.
ls_methods-refnumber = 1.
ls_methods-objecttype = 'HEADER'.
ls_methods-method = 'CHANGE'.
ls_methods-objectkey = '000480000020'.
APPEND ls_methods TO lt_methods.
* Fill header structure
ls_header-orderid = '000480000020'.
ls_header-notif_no = '100000356980'.
APPEND ls_header TO lt_header.
* Fill header up structure
ls_header_up-orderid = '000480000020'.
ls_header_up-notif_no = '100000356980' .
APPEND ls_header_up TO lt_header_up.
* Fill object list structure
ls_object_list-notif_no = '100000356980'.
APPEND ls_object_list TO lt_object_list.
* Fill object list up structure
ls_object_list_up-processing_ind = 'X'.
APPEND ls_object_list_up TO lt_object_list_up.
CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
it_methods = lt_methods
it_header = lt_header
it_header_up = lt_header_up
it_objectlist = lt_object_list
it_objectlist_up = lt_object_list_up
return = lt_return .
For OBJECTLIST I would actually need something like an 'ADD' method. Any ideas are appreciated.
The following works for me:
ls_methods-refnumber = 1.
ls_methods-objecttype = 'OBJECTLIST'.
ls_methods-method = 'CREATE'.
ls_methods-objectkey = '000480000020'.
APPEND ls_methods TO lt_methods.
* Fill method structure
ls_methods-refnumber = 1.
ls_methods-method = 'SAVE'.
ls_methods-objecttype = ''.
ls_methods-objectkey = '000480000020'.
APPEND ls_methods TO lt_methods.
* Fill object list structure
ls_object_list-notif_no = '100000356980'.
APPEND ls_object_list TO lt_object_list.
* Fill object list up structure
ls_object_list_up-processing_ind = 'X'.
APPEND ls_object_list_up TO lt_object_list_up.
CALL FUNCTION 'BAPI_ALM_ORDER_MAINTAIN'
TABLES
it_methods = lt_methods
it_objectlist = lt_object_list
it_objectlist_up = lt_object_list_up
return = lt_return.

Getting Error:Table variables and insert 'fieldnames' do not match. while exporting data from matlab to sql

I am getting the Error using database.jdbc.connection/fastinsert (line 140)
Table variables and insert 'fieldnames' do not match. error while exporting data from matlab to sql. Can you please help me out.
Below is my code.
conn = database('rScenariosDB','NCAT\aabhaler','','Vendor','Microsoft SQL Server','Server','A0030110GB6S942','AuthType','Windows','portnumber',1433);
for i = 1 : rScenarioCnt
if rScenario{i}.status == 1
ECostMax(i) = rScenario{i}.ECostMax;
CO2EmisMax(i) = rScenario{i}.CO2EmisMax;
ECost(i) = rScenario{i}.YearAlloc.ECost;
CO2Emis(i) = rScenario{i}.YearAlloc.CO2Emis ;
EmisCostYear(i) = rScenario{i}.YearAlloc.EmisCostYear ;
CO2EmisYear(i) = sum(rScenario{i}.YearAlloc.CO2EmisYear);
end
end
rId = 1 : rScenarioCnt ;
colnames={'rScenarioId' ,'ECostMax' , ' CO2EmisMax','ECost' ,'CO2Emis', 'EmisCostYear', 'CO2EmisYear' };
data = table(rId',ECostMax',CO2EmisMax',ECost',CO2Emis',EmisCostYear', CO2EmisYear','VariableNames',colnames);
tablename = 'rScenarios';
fastinsert(conn,tablename,colnames,data);
curs=exec(conn,'select * from [dbo].[rScenarios]');
curs=fetch(curs);
disp(curs.Data);
close(curs);
close(conn);

How to read the position value given the cost center

I want to read the position using this FM HRWPC_RPT_COSTCENTER_EVALPATH where the cost center is given.
There are 3 result tables. from which table I can read the position value ?
here how I call the FM:
DATA i_hrrootob TYPE TABLE OF hrrootob.
DATA w_hrrootob LIKE LINE OF i_hrrootob.
DATA i_object_tab TYPE TABLE OF objec.
DATA w_object_tab LIKE LINE OF i_object_tab.
data i_STRUC TYPE TABLE OF STRUC.
w_hrrootob-otype = 'K'.
w_hrrootob-objid = w_orgdata-costcenter_key-costcenter.
APPEND w_hrrootob TO i_hrrootob.
CALL FUNCTION 'HRWPC_RPT_COSTCENTER_EVALPATH'
EXPORTING
depth = 0
evpath = 'KOSTDIUP'
* PLVAR = 01
* BEGDA = SY-DATUM
* ENDDA = SY-DATUM
* LEVEL = 1
TABLES
root_objects = i_hrrootob
result_objec = i_object_tab
result_struc = i_STRUC
EXCEPTIONS
NO_OBJECTS_FOUND = 1
OTHERS = 2
.
I got it by myself.
The result table result_objec has the value in the field stext, where the obtype ='S'