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 Where Condition for Info Structures

Former Member
0 Likes
743

Hi All,

My Requirement is to read the data from Information Structure(For Ex: S980) entered on selection screen at Run time. User will enter the technical field names of any three Key Figures on Selection Screen. Based on the keyfigures entered on selection screen the data should be selected. I am through with building the dynamic internal table. But how do I put a dynamic where clause in the select query for the keyfigures selected at run time? Kindly suggest me a solution. Please let me know if the information provided is not sufficient.

Best Regards,

Sailaja.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
707

1/ *******************BUILD WHERE CONDITION

DATA:

gt_cond type table of line,

gs_cond type line.

ifIWERKS is NOT initial.

perform append_cond using 'MARD~WERKS' '=' 'IWERKS'.

ENDIF.

if SLGORT is NOT initial.

perform append_cond using 'MARD~LGORT' 'IN' 'ILGORT'.

ENDIF.

2/ ******Subroutine for apend where condition *************

FORM append_cond USING pfield1

pop

pfield2.

if gt_cond[] is initial.

concatenate pfield1 pop pfield2 into gs_cond-line SEPARATED BY space.

else.

concatenate 'AND' pfield1 pop pfield2 into gs_cond-line separated by space.

endif.

append gs_cond to gt_cond.

ENDFORM. " append_cond

3/ ***********************SELECT STATEMENT ******************************************

select * into CORRESPONDING FIELDS OF TABLE OMATNR

from mard inner join MVKE ON MVKEmatnr = mardmatnr

inner join marc on marcmatnr = mardmatnr

and marcwerks = mardwerks

where (gt_cond).

Hi All,

My Requirement is to read the data from Information Structure(For Ex: S980) entered on selection screen at Run time. User will enter the technical field names of any three Key Figures on Selection Screen. Based on the keyfigures entered on selection screen the data should be selected. I am through with building the dynamic internal table. But how do I put a dynamic where clause in the select query for the keyfigures selected at run time? Kindly suggest me a solution. Please let me know if the information provided is not sufficient.

Best Regards,

Sailaja.

4 REPLIES 4
Read only

Former Member
0 Likes
708

1/ *******************BUILD WHERE CONDITION

DATA:

gt_cond type table of line,

gs_cond type line.

ifIWERKS is NOT initial.

perform append_cond using 'MARD~WERKS' '=' 'IWERKS'.

ENDIF.

if SLGORT is NOT initial.

perform append_cond using 'MARD~LGORT' 'IN' 'ILGORT'.

ENDIF.

2/ ******Subroutine for apend where condition *************

FORM append_cond USING pfield1

pop

pfield2.

if gt_cond[] is initial.

concatenate pfield1 pop pfield2 into gs_cond-line SEPARATED BY space.

else.

concatenate 'AND' pfield1 pop pfield2 into gs_cond-line separated by space.

endif.

append gs_cond to gt_cond.

ENDFORM. " append_cond

3/ ***********************SELECT STATEMENT ******************************************

select * into CORRESPONDING FIELDS OF TABLE OMATNR

from mard inner join MVKE ON MVKEmatnr = mardmatnr

inner join marc on marcmatnr = mardmatnr

and marcwerks = mardwerks

where (gt_cond).

Read only

0 Likes
707

Hi Jan,

In the below example the field WERKS and LGORT will not vary everytime.

ifIWERKS is NOT initial.

perform append_cond using 'MARD~WERKS' '=' 'IWERKS'.

ENDIF.

if SLGORT is NOT initial.

perform append_cond using 'MARD~LGORT' 'IN' 'ILGORT'.

ENDIF.

But in my case the Information Structure is selected at run time and even the Key figures of each information structure will vary

every time. The selection of the Key figures is also Dynamic. Based on this criteria I have to build the where clause.

Kindly suggest me a solution for this scenario. Please let me know if the information provided is not clear.

Best Regards,

Sailaja.

Read only

0 Likes
707

Hi,

I am not sure 100% I understand your issue, but if your key are dynamically created and you table where you have list of keyfields, you can use program modification describe in next rows.

You will have set keys they are dynamically created and they are in some table(they have column table/structure and fieldname)

field-symbols: <field> type any

GT_COND_LST

row TABLE NAME FIELDNAME

1 TABLE1 KEYFIELD1

2 TABLE1 KEYFIELD2

3 TABLE1 KEYFIELD3

4 TABLE2 KEYFIELD4

...

1/ *******************BUILD WHERE CONDITION

DATA:

gt_cond type table of line,

gs_cond type line.

loop at GT_COND_LST into GS_COND_LST.

assign (GS_COND_LST-FIELDNAME) into <field>.

if <field> is not initial.

concatenate GS_COND_LST-TABLE '~' GS_COND_LST-FIELDNAME into lv_cond.

perform append_cond using 'MARD~LGORT' 'IN' GS_COND_LST-FIELDNAME.

endif.

endlloop.

2/ ******Subroutine for apend where condition *************

FORM append_cond USING pfield1

pop

pfield2.

if gt_cond[] is initial.

concatenate pfield1 pop pfield2 into gs_cond-line SEPARATED BY space.

else.

concatenate 'AND' pfield1 pop pfield2 into gs_cond-line separated by space.

endif.

append gs_cond to gt_cond.

ENDFORM. " append_cond

3/ ***********************SELECT STATEMENT ******************************************

select * into CORRESPONDING FIELDS OF TABLE OMATNR

from mard inner join MVKE ON MVKEmatnr = mardmatnr

inner join marc on marcmatnr = mardmatnr

and marcwerks = mardwerks

where (gt_cond).

Read only

0 Likes
707

Hi Jan,

Thanks a lot. I have resolved this issue in the following way:

*Build the field catalog for creation of Dynamic Internal Table

*First Keyfigure

wa_dyn_fieldcat-fieldname = p_key1.

wa_dyn_fieldcat-ref_field = p_key1.

wa_dyn_fieldcat-ref_table = p_itab.

APPEND wa_dyn_fieldcat TO gt_dyn_fieldcat.

*Second Keyfigure

wa_dyn_fieldcat-fieldname = p_key2.

wa_dyn_fieldcat-ref_field = p_key2 .

wa_dyn_fieldcat-ref_table = p_itab.

APPEND wa_dyn_fieldcat TO gt_dyn_fieldcat.

*Third Keyfigure

wa_dyn_fieldcat-fieldname = p_key3.

wa_dyn_fieldcat-ref_field = p_key3.

wa_dyn_fieldcat-ref_table = p_itab.

APPEND wa_dyn_fieldcat TO gt_dyn_fieldcat.

*Build the Field Catalog for Dynamic Selection list

*First Keyfigure

wa_mseg_fields = p_key1 .

APPEND wa_mseg_fields TO gt_mseg_fields.

*Second Keyfigure

wa_mseg_fields = p_key2 .

APPEND wa_mseg_fields TO gt_mseg_fields.

*Third Keyfigure

wa_mseg_fields = p_key3 .

APPEND wa_mseg_fields TO gt_mseg_fields.

*Create the dynamic internal table

CALL METHOD cl_alv_table_create=>create_dynamic_table

EXPORTING

it_fieldcatalog = gt_dyn_fieldcat

IMPORTING

ep_table = gt_new_table.

*Create a new line

ASSIGN gt_new_table->* TO <gt_table>.

CREATE DATA wa_new_line LIKE LINE OF <gt_table>.

ASSIGN wa_new_line->* TO <wa_line>.

*Get the data from Dynamic Infostructure

SELECT (gt_mseg_fields)

FROM (p_itab)

INTO TABLE <gt_table>

WHERE matnr IN s_matnr

AND werks IN s_werks

AND vrsio EQ p_vrsio

AND ( spmon IN s_fthrzn OR

spwoc IN s_fthrzn ).

Best Regards,

Sailaja.