Enterprise Resource Planning Blog Posts by Members
cancel
Showing results for 
Search instead for 
Did you mean: 
snekha
Discoverer
0 Likes
2,086

Introduction:

This blog intends dynamic fields or table selection in select query based on the condition. My requirement is to show vendor or customer details based on T-code. A traditional approach is to use conditional statement (IF .. ELSE)  to determine fields, table and where condition. However, there is an alternative and dynamic approach by utilizing source syntax which eliminates reductant code

Step 1: Declare type as below image.

snekha_0-1741939131329.png

Step 2: Declare internal table as common for both vendor or customer details.
Note: Inline declaration in select query is not possible in source syntax

snekha_1-1741939131330.png

Step 3: Map the structure(ls_source_syntax) based on T-Code

  1. Column - Based on T-code map the required fields.
  2. Source - Based on T-Code map the required table.
  3. Where – based on T-Code map the selection option

snekha_2-1741939131342.png

Step 4: Dynamically fields, table, where get mapped based on T-code as shown in the image

snekha_3-1741939131344.png

Case 1: T-Code: ZLIFNR – Vendor details for particular vendor.

Step1: Pass the input and execute

snekha_4-1741939131345.png

Output:

snekha_5-1741939131346.png

 

Case 2: T-Code: ZKUNNR – Customer details

Step1: Pass the input and execute

snekha_6-1741939131347.png

Output:

snekha_7-1741939131347.png

Conclusion:

With the source syntax, we can construct select query dynamically based on our requirement to make more flexible instead of traditional approach.