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

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( ).

Related

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.

How to return value to user from a Search Help Exit

I have a Search Help with many fields to be displayed to the user in order to apply values. I want to get 3 fields APOFASI, SKOPOS, KATDANL from the user.
In the CALLCONTROL-STEP = SELECT in the exit FM, I want to get these values in variables and then to make some selects and find another field APOFASISAP.
I am trying to pass back to the selection fields of the search help the field APOFASSISAP, but the APOFASI field seems to be blank.
The code is:
TYPES: BEGIN OF ty_apofasisap_tr,
apofasisap_tr TYPE zglk_sap_afopasi,
END OF ty_apofasisap_tr.
DATA: it_apofasisap_tr TYPE TABLE OF ty_apofasisap_tr,
wa_apofasisap_tr LIKE LINE OF it_apofasisap_tr.
DATA: lv_apofasi TYPE zglk_kyanr_ap,
lv_skopos TYPE zskopos,
lv_katdanl TYPE zsl_cat_dan,
lv_apofasisap_arx TYPE zglk_sap_afopasi.
lv_apofasi = wa_shlp_selopt-low.
ls_result-apofasi = ''.
IF lv_apofasi <> ''.
wa_shlp_selopt-low = ''.
MODIFY shlp-selopt FROM wa_shlp_selopt INDEX sy-tabix.
ENDIF.
READ TABLE shlp-selopt INTO wa_shlp_selopt WITH KEY shlpfield = 'SKOPOS'.
lv_skopos = wa_shlp_selopt-low.
READ TABLE shlp-selopt INTO wa_shlp_selopt WITH KEY shlpfield = 'KATDANL'.
lv_katdanl = wa_shlp_selopt-low.
SELECT SINGLE apofasisap INTO lv_apofasisap_arx
FROM zsl_glk_apof
WHERE apofasi = lv_apofasi.
SELECT * FROM zsl_glk_apof_tr
WHERE apofasisap_trp = lv_apofasisap_arx.
wa_apofasisap_tr-apofasisap_tr = zsl_glk_apof_tr-apofasisap_tr.
APPEND wa_apofasisap_tr TO it_apofasisap_tr.
ENDSELECT.
wa_shlp_selopt-shlpname = 'ZAPOF_TROP'.
wa_shlp_selopt-shlpfield = 'APOFASISAP'.
wa_shlp_selopt-sign = 'I'.
wa_shlp_selopt-option = 'EQ'.
wa_shlp_selopt-low = wa_apofasisap_tr-apofasisap_tr.
APPEND wa_shlp_selopt TO shlp-selopt.
This code does not replace/add the values to the appropriate fields.
Can someone help on this?
PS. Let me add another code that I wrote with the help of internet. It is in the STEP of DISPLAY.
IF callcontrol-step = 'DISP'.
TYPES: BEGIN OF ls_result,
apofasi LIKE zsl_glk_apof-apofasi,
apofasidate LIKE zsl_glk_apof-apofasidate,
apofasisap LIKE zsl_glk_apof-apofasisap,
apofasi_trp_x LIKE zsl_glk_apof-apofasi_trp_x,
apofasi_tr_x LIKE zsl_glk_apof-apofasi_tr_x,
fek LIKE zsl_glk_apof-fek,
katdanl LIKE zsl_glk_apof-katdanl,
reference LIKE zsl_glk_apof-reference,
skopos LIKE zsl_glk_apof-skopos,
thema LIKE zsl_glk_apof-thema,
type_desc LIKE zsl_glk_apof-type_desc,
ya_first LIKE zsl_glk_apof-ya_first,
END OF ls_result.
DATA: lt_result TYPE STANDARD TABLE OF ls_result.
CLEAR: lt_result, record_tab, record_tab[].
* Read the value that user gave
READ TABLE shlp-selopt INTO wa_shlp_selopt
WITH KEY shlpfield = 'APOFASI'.
lv_apofasi = wa_shlp_selopt-low.
IF lv_apofasi <> ''.
* Clear this value
wa_shlp_selopt-low = ''.
MODIFY shlp-selopt FROM wa_shlp_selopt INDEX sy-tabix.
ENDIF.
* Find the number starting APOFASISAP from the APOFASI text
SELECT SINGLE apofasisap INTO lv_apofasisap_arx
FROM zsl_glk_apof
WHERE apofasi = lv_apofasi.
IF sy-subrc = 0.
* Find the APOFASISAPs which changes the starting one and display the
*fields
SELECT a~apofasi a~apofasidate a~apofasisap
a~apofasi_tr_x a~apofasi_trp_x
a~thema a~fek a~reference a~ya_first
INTO CORRESPONDING FIELDS OF TABLE lt_result
FROM zsl_glk_apof AS a INNER JOIN zsl_glk_apof_tr AS b
ON a~apofasisap = b~apofasisap_tr
WHERE b~apofasisap_trp = lv_apofasisap_arx.
IF sy-subrc = 0.
*Pass them to display the result.
CALL FUNCTION 'F4UT_RESULTS_MAP'
EXPORTING
* SOURCE_STRUCTURE =
apply_restrictions = 'X'
TABLES
shlp_tab = shlp_tab
record_tab = record_tab
source_tab = lt_result
CHANGING
shlp = shlp
callcontrol = callcontrol
EXCEPTIONS
illegal_structure = 1
OTHERS = 2
.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
ENDIF.
FREE lt_result.
ENDIF.
It says NO VALUES FOR THIS SELECTION. The table lt_result contains 11 records.
Thanks again.
I agree with the forespeakers, that provided code is a mess, from which nothing can be figured out.
First of all, use DISP event in SHELP FM exit, not SELECT.
Secondly, you fill the wrong table (or do not show us right filling in the snippet above). In order to pass values back to user you should modify a RECORD_TAB table.
Your code should look something like this (joined selections from zsl_glk_apof and zsl_glk_apof_tr tables):
CHECK callcontrol-step = 'DISP'.
DATA: ls_selopt TYPE ddshselopt. "loc str for shlp-selopt
DATA: BEGIN OF ls_record.
INCLUDE STRUCTURE seahlpres.
DATA: END OF ls_record.
DATA: lv_glk_apof_tr TYPE zsl_glk_apof_tr-apofasisap_tr.
LOOP AT shlp-selopt INTO ls_selopt.
* finding SKOPOS and KATDANL values
CASE ls_selopt-shlpfield.
WHEN 'SKOPOS'.
lv_skopos = ls_selopt-low.
WHEN 'KATDANL'.
lv_katdanl = ls_selopt-low.
WHEN OTHERS.
ENDCASE.
* doing smth
* finding some stuff from Z-tables
SELECT SINGLE tr~apofasisap_tr
FROM zsl_glk_apof AS ap
JOIN zsl_glk_apof_tr AS tr
ON ap~apofasisap = tr~apofasisap_trp
INTO lv_glk_apof_tr
WHERE ap~apofasi = lv_apofasi.
ENDLOOP.
* modify record_tab with the found value lv_glk_apof_tr
LOOP AT record_tab INTO ls_record.
ls_record-string+25(5) = lv_glk_apof_tr. "field shift should be based on your values
ENDLOOP.
Hello and thanks all for your valuable help.
Finally I did it as follow:
if callcontrol-step = 'SELECT'.
get parameter id 'ZAP' field p_apofasi.
get parameter id 'ZSK' field p_skopos.
get parameter id 'ZKATDANL' field p_katdanl.
select single apofasisap into lv_apofasisap_arx
from zsl_glk_apof
where apofasi = p_apofasi and
katdanl = p_katdanl and
skopos = p_skopos.
select * into corresponding fields of table it_apofasisap_tr
from zsl_glk_apof_tr
where apofasisap_trp = lv_apofasisap_arx.
* Display the results to the user
types: begin of ls_result,
apofasi like zsl_glk_apof-apofasi,
apofasidate like zsl_glk_apof-apofasidate,
apofasisap like zsl_glk_apof-apofasisap,
apofasi_trp_x like zsl_glk_apof-apofasi_trp_x,
apofasi_tr_x like zsl_glk_apof-apofasi_tr_x,
katdanl like zsl_glk_apof-katdanl,
skopos like zsl_glk_apof-skopos,
type_desc like zsl_glk_apof-type_desc,
end of ls_result.
data: lt_result type standard table of ls_result.
clear: lt_result, record_tab, record_tab[].
* Fill all the fields of the Search-Help with the data according to the
*selections of the user.
select apofasi apofasidate apofasisap
apofasi_tr_x apofasi_trp_x
katdanl skopos type_desc
into corresponding fields of table lt_result
from zsl_glk_apof
for all entries in it_apofasisap_tr
where apofasisap = it_apofasisap_tr-apofasisap_tr and
apofasi_tr_x = 'X'. "lv_apofasi_tr_x.
call function 'F4UT_RESULTS_MAP'
tables
shlp_tab = shlp_tab
record_tab = record_tab
source_tab = lt_result
changing
shlp = shlp
callcontrol = callcontrol
exceptions
illegal_structure = 1
others = 2.
if sy-subrc = 0.
callcontrol-step = 'DISP'.
else.
callcontrol-step = 'EXIT'.
endif.
endif.
Regards
Elias

Why is this dropdown not populating?

I have three dropdowns; the second one (Members) populates based on what's in the first (Units), and the third one (Customers) SHOULD populate based on what's in the second; but it doesn't.
Here's the query that works in LINQPad (returns a list of Company names):
select distinct companyname from customers C left join members M on M.MemberNo = C.MemberNo where M.MemberNo = '052' order by companyname
...but does not work in the following code:
'Populate the Members dropdown
Dim selectedUnit As String = DropDownListUnits.Text
Dim membersDT As DataTable
sql = "select distinct shortname, M.memberno from members M left join memberunitproducts mup on M.MemberNo = mup.MemberNo where unit = '" + selectedUnit + "' order by shortname"
retDS = sqlDAL.runSQLDataSet(sql)
membersDT = retDS.Tables(0)
DropDownListMembers.DataSource = membersDT
DropDownListMembers.DataTextField = "shortname"
DropDownListMembers.DataValueField = "memberno"
DropDownListMembers.DataBind()
'Populate the Customers dropdown
Dim selectedMember As String = DropDownListMembers.DataValueField
Dim customersDT As DataTable
sql = "select distinct companyname from customers C left join members M on M.MemberNo = C.MemberNo where M.MemberNo = '" + selectedMember + "' order by companyname"
retDS = sqlDAL.runSQLDataSet(sql)
customersDT = retDS.Tables(0)
DropDownListCustomers.DataSource = customersDT
DropDownListCustomers.DataTextField = "companyname"
DropDownListCustomers.DataValueField = "companyname"
DropDownListCustomers.DataBind()
The third (Customers) dropdown remains unpopulated when this runs - why?
It's probably not needed, but here is the code for the first ("Units") dropdown:
'Populate the Units dropdown
Dim unitsDT As DataTable
sql = "Select distinct unit from masterunits where abs(active) = 1"
retDS = sqlDAL.runSQLDataSet(sql)
unitsDT = retDS.Tables(0)
DropDownListUnits.DataSource = unitsDT
DropDownListUnits.DataTextField = "unit"
DropDownListUnits.DataValueField = "unit"
DropDownListUnits.DataBind()
What am I missing or doing wrong?
I had to change this:
Dim selectedMember As String = DropDownListMembers.DataValueField
...to this:
Dim selectedMember As String = DropDownListMembers.SelectedItem.Value

SQL statement return results into ALV table

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.

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'