Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

select-option in ALV problem.

ciyradyl
Explorer
0 Kudos

I am generating an internal table with help of inner joins but I don't know how am I going to connect the columns with the select-option. Can you help me please? Maybe, I need to combine the tables with for all entries?

*&---------------------------------------------------------------------*
*& Report ZR_AF_LIST_MULTIDOC
*&---------------------------------------------------------------------*
*&
*&---------------------------------------------------------------------*

REPORT zr_af_list_multidoc.

TABLES: vbak, vbap, likp, lips, /scmtms/d_torite, /scmtms/d_torrot.

DATA: lo_alv TYPE REF TO cl_salv_table.


TYPES: BEGIN OF ty_data,
so_vbeln TYPE vbeln_va,
od_vbeln TYPE vbeln_vl,
freight_category TYPE /scmtms/tor_category,
freight_unit TYPE /scmtms/tor_fu_id,
freight_order TYPE /scmtms/tor_to_id,
END OF ty_data.

TYPES: BEGIN OF ty_alv_data,
so_vbeln TYPE vbeln_va,
od_vbeln TYPE vbeln_vl,
freight_unit TYPE /scmtms/tor_fu_id, "/scmtms/tor_id,
freight_order TYPE /scmtms/tor_to_id, "/scmtms/tor_id,
END OF ty_alv_data.

DATA lt_data TYPE STANDARD TABLE OF ty_data.
DATA lt_alv_data TYPE STANDARD TABLE OF ty_alv_data.

SELECTION-SCREEN BEGIN OF BLOCK b11 WITH FRAME.
SELECT-OPTIONS: s_so FOR vbak-vbeln. "Sales Orders
SELECT-OPTIONS: s_od FOR likp-vbeln. "Outbound Deliveries
SELECT-OPTIONS: s_fu FOR /scmtms/d_torrot-tor_id. "Freight Units
SELECT-OPTIONS: s_fo FOR /scmtms/d_torrot-tor_id. "Freight Orders
*SELECT-OPTIONS: s_fsd FOR vbak-vbeln. "Freight Settlement Documents
SELECTION-SCREEN END OF BLOCK b11.

INITIALIZATION.

START-OF-SELECTION.

SELECT
vbak~vbeln AS so_vbeln,
likp~vbeln AS od_vbeln,
torrot~tor_cat AS freight_category,
torrot~tor_id AS freight_unit,
torrot~tor_id AS freight_order
FROM vbak
INNER JOIN vbap ON vbap~vbeln = vbak~vbeln
INNER JOIN lips ON lips~vgbel = vbak~vbeln
INNER JOIN likp ON likp~vbeln = lips~vbeln
INNER JOIN /scmtms/d_torite AS torite ON substring( torite~base_btd_id, 26, 10 ) = likp~vbeln
INNER JOIN /scmtms/d_torrot AS torrot ON torrot~db_key = torite~parent_key
INTO CORRESPONDING FIELDS OF TABLE @lt_data.


SORT lt_data BY so_vbeln.

LOOP AT lt_data INTO DATA(ls_data).
READ TABLE lt_alv_data WITH KEY so_vbeln = ls_data-so_vbeln od_vbeln = ls_data-od_vbeln ASSIGNING FIELD-SYMBOL(<fs_alv_data>).
IF sy-subrc = 0.
CASE ls_data-freight_category.
WHEN 'FU'.
<fs_alv_data>-freight_unit = ls_data-freight_unit.
WHEN 'TO'.
<fs_alv_data>-freight_order = ls_data-freight_order.
WHEN OTHERS.
ENDCASE.
ELSE.
APPEND INITIAL LINE TO lt_alv_data ASSIGNING <fs_alv_data>.
<fs_alv_data>-so_vbeln = ls_data-so_vbeln.
<fs_alv_data>-od_vbeln = ls_data-od_vbeln.
CASE ls_data-freight_category.
WHEN 'FU'.
<fs_alv_data>-freight_unit = ls_data-freight_unit.
WHEN 'TO'.
<fs_alv_data>-freight_order = ls_data-freight_order.
WHEN OTHERS.
ENDCASE.
ENDIF.
ENDLOOP.

TRY.
DATA : lo_functions TYPE REF TO cl_salv_functions_list,
lo_display TYPE REF TO cl_salv_display_settings,
lo_cols TYPE REF TO cl_salv_columns.

cl_salv_table=>factory( IMPORTING r_salv_table = lo_alv
CHANGING t_table = lt_alv_data ).

lo_functions = lo_alv->get_functions( ).
lo_functions->set_all( ).

lo_display = lo_alv->get_display_settings( ).
lo_display->set_list_header( value = 'ALV REPORT ASSIGNMENT').
lo_display->set_striped_pattern( value = 'X' ). " Zebra Design

lo_cols = lo_alv->get_columns( ).
lo_cols->set_optimize( value = 'X').

lo_alv->display( ).
CATCH cx_salv_msg.
ENDTRY.
5 REPLIES 5

raymond_giuseppi
Active Contributor

Add a WHERE clause with IN range_tab in your SELECT statement.

...   WHERE vbap~vbeln IN @s_so
AND likp~vbeln IN @s_od
INTO CORRESPONDING FIELDS OF TABLE @lt_data

0 Kudos



When I try this, it gives this error.

corrected 🙂

0 Kudos

Thank you! I should have tried that before sharing this.

gphadnis2000
Participant
0 Kudos

I found similar issue in one of the stackoverflow threads this might be relevant to yours.

https://stackoverflow.com/questions/54569672/run-time-error-for-dynamic-order-by-clause-static-equiv...