Application Development and Automation 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: 
Read only

Dynamic selection.

0 Likes
415

Hi,

I need some help related to dynamic selection using <b>field symbols</b> in a single select statement.

I elaborate the requirement:

I need to retrieve data from GLPCT.

If user gives the value 01,02,.......14,15,16. in selection screen level.

then i have to retrieve HSL01,HSL02.....HSL14,HSL15,HSL16.

This should be done in a single select statement and i am not supposed get the entire" HSL01,HSL02.....HSL14,HSL15,HSL16." if user gives any of the corresponding.

Can any one send sample code how to write <b>dynamic select statements</b> in ABAP.

Thanks.

Regards.

2 REPLIES 2
Read only

Former Member
0 Likes
377

Hi,

You can write dynamic select as following


data: dyn_select_txt(100).

dyn_select_txt = '<table_field> in ('HSL01', 'HSL02'........)'.

select * from GLPCT into table lt_glpct
where (dyn_select_txt).

you can concatenate values you want in the txt variable that you have declared and use that txt variable in your select statement.

cheers,

Asim

Read only

Former Member
0 Likes
377

Hi,

i m giving syntax for dynamic select stmt:

parameters: p_matnr type mara-matnr.
data: fld_list(70),
        db_table(70),
        itab type table of string.

fld_list =  ' matnr mara ' .
db_table = ' mara '.

concatenate ' matnr = ' ''' p_matnr ''' into conditions.

select ( fld_list ) from ( db_table ) into corrosponding fields of table itab where ( conditions ).

Its really good to use Field symbol for performace improvement as it just points to data and does not copy values ...

e.g.

DATA path LIKE ibipparms-path.

DATA: i_excel LIKE alsmex_tabline OCCURS 0 WITH HEADER LINE.

data: i_fcat type LVC_T_FCAT,
wa_fcat type lvc_s_fcat.

data: fname(10),
I_PTABLE TYPE REF TO DATA.


SELECTION-SCREEN BEGIN OF BLOCK b WITH FRAME TITLE text-001.
PARAMETERS p_path LIKE rlgrap-filename OBLIGATORY.
SELECTION-SCREEN END OF BLOCK b.


FIELD-SYMBOLS: <fs_final> TYPE ANY,
<I_TABLE> type table.


AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_path.
CALL FUNCTION 'F4_FILENAME'
IMPORTING
file_name = path.

p_path = path.


START-OF-SELECTION.


CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
EXPORTING
filename = p_path
i_begin_col = 1
i_begin_row = 1
i_end_col = 256
i_end_row = 65536
TABLES
intern = i_excel.


loop at i_excel where row = '1'.
wa_fcat-ROW_POS = i_excel-row.
wa_fcat-col_pos = i_excel-col.
* concatenate 'COL_' i_excel-col into fname.
wa_fcat-FIELDNAME = I_EXCEL-VALUE.
append wa_fcat to i_fcat.
endloop.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = I_FCAT
IMPORTING
EP_TABLE = I_PTABLE.


Assign i_ptable->* to <i_table>.

perform zf_assign.


End-of-selection.

LOOP AT I_FCAT INTO WA_FCAT .
WRITE: WA_FCAT-FIELDNAME(10).
ENDLOOP.

LOOP AT <I_TABLE> assigning <fs_final>.
WRITE:/ <fs_final>.
ENDLOOP.



*&---------------------------------------------------------------------*
*& Form zf_assign
*&---------------------------------------------------------------------*
* text
*----------------------------------------------------------------------*
* --> p1 text
* <-- p2 text
*----------------------------------------------------------------------*
form zf_assign .

field-symbols: <ls_table>.

ASSIGN LOCAL COPY OF INITIAL LINE OF <I_TABLE> TO <LS_TABLE>.

LOOP AT i_excel WHERE ROW <> 1.

ASSIGN COMPONENT i_excel-col OF STRUCTURE <LS_TABLE> TO <fs_final>.
<fs_final> = i_excel-value.

AT END OF row.
APPEND <LS_TABLE> TO <i_table>.
ENDAT.

ENDLOOP.

Jogdand M B