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.
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
Step 3: Map the structure(ls_source_syntax) based on T-Code
Step 4: Dynamically fields, table, where get mapped based on T-code as shown in the image
Case 1: T-Code: ZLIFNR – Vendor details for particular vendor.
Step1: Pass the input and execute
Output:
Case 2: T-Code: ZKUNNR – Customer details
Step1: Pass the input and execute
Output:
Conclusion:
With the source syntax, we can construct select query dynamically based on our requirement to make more flexible instead of traditional approach.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 19 | |
| 19 | |
| 11 | |
| 10 | |
| 8 | |
| 7 | |
| 7 | |
| 6 | |
| 5 | |
| 5 |