2012 May 26 9:18 PM
Hi,
I have a requirement. I am working in a user exit in which there is a table parameter C_T_DATA whose structure is defined at runtime only based on some conditions. Lets say, if cond1 is true, structure will be ABC; else it will be XYZ.
Now, in my code, i need to use SELECT query based on the value populated in internal table. So i wrote the code like below :
DATA : v_where TYPE string.
If cond1 is true.
v_where = 'GUID = C_T_DATA-GUID'.
SELECT partner_guid
from BUT000
into table it_partner
FOR ALL ENTRIES IN c_t_data
WHERE (v_where).
elseif cond2 is true.
v_where = 'VBELN = C_T_DATA-VBELN'.
*----Corresponding Code
endif.
Now, when I am executing the code, I am getting a short dump saying only literals are allowed in dynamic where and not values. So anyone could please help me out to solve this. I found some posts for this but in all those the structure of table was known while in my case it is known at run time only.
Kindly help.
Regards,
Guddan
Hi,
I have a requirement. I am working in a user exit in which there is a table parameter C_T_DATA whose structure is defined at runtime only based on some conditions. Lets say, if cond1 is true, structure will be ABC; else it will be XYZ.
Now, in my code, i need to use SELECT query based on the value populated in internal table. So i wrote the code like below :
DATA : v_where TYPE string.
If cond1 is true.
v_where = 'GUID = C_T_DATA-GUID'.
SELECT partner_guid
from BUT000
into table it_partner
FOR ALL ENTRIES IN c_t_data
WHERE (v_where).
elseif cond2 is true.
v_where = 'VBELN = C_T_DATA-VBELN'.
*----Corresponding Code
endif.
Now, when I am executing the code, I am getting a short dump saying only literals are allowed in dynamic where and not values. So anyone could please help me out to solve this. I found some posts for this but in all those the structure of table was known while in my case it is known at run time only.
Kindly help.
Regards,
Guddan
2012 May 26 10:12 PM
Hi Guddan,
please check this alternative:
DATA:
lt_guid TYPE SORTED TABLE OF OF but00-guid
WITH UNIQUE KEY table_line,
lt_vbeln TYPE SORTED TABLE OF OF vbak-vbeln
WITH UNIQUE KEY table_line.
FIELD-SYMBOLS:
<any> TYPE any,
<data> TYPE any.
LOOP AT c_t_data ASSIGNING <data>.
IF cond1 is true.
ASSIGN COMPONENT 'GUID' OF STRUCTURE <data> to <any>.
INSERT <any> INTO TABLE lt_guid.
ELSE.
ASSIGN COMPONENT 'VBELN' OF STRUCTURE <data> to <any>.
INSERT <any> INTO TABLE lt_vbeln.
ENDIF.
ENDLOOP.
CHECK SY-SUBRC = 0. "avoid select .. for all entries with empty table
IF cond1 is true.
SELECT partner_guid
INTO table it_partner
FROM but000
FOR ALL ENTRIES IN lt_guid
WHERE guid = lt_guid-table_line.
ELSE.
*----Corresponding Code
ENDIF.
DATA:
lt_guid TYPE SORTED TABLE OF OF but00-guid
WITH UNIQUE KEY table_line,
lt_vbeln TYPE SORTED TABLE OF OF vbak-vbeln
WITH UNIQUE KEY table_line.
FIELD-SYMBOLS:
<any> TYPE any,
<data> TYPE any.
LOOP AT c_t_data ASSIGNING <data>.
IF cond1 is true.
ASSIGN COMPONENT 'GUID' OF STRUCTURE <data> to <any>.
INSERT <any> INTO TABLE lt_guid.
ELSE.
ASSIGN COMPONENT 'VBELN' OF STRUCTURE <data> to <any>.
INSERT <any> INTO TABLE lt_vbeln.
ENDIF.
ENDLOOP.
CHECK SY-SUBRC = 0. "avoid select .. for all entries with empty table
IF cond1 is true.
SELECT partner_guid
INTO table it_partner
FROM but000
FOR ALL ENTRIES IN lt_guid
WHERE guid = lt_guid-table_line.
ELSE.
*----Corresponding Code
ENDIF.
Please experts have mercy and enable fixed space font and ABAP syntax highlighting for posting code here. Thank you.
Regards,
Clemens
2012 May 27 10:06 AM
Hi Guddan,
if you look at the ABAP documentation (7.0), it says that the dynamic Where clause is allowed for FOR ALL ENTRIES since 6.10. Please, could you tell us how you defined C_T_DATA?
For information, this code works well, test it on your system:
DATA lt_sflight TYPE TABLE OF sflight.
DATA lt_carrid TYPE TABLE OF s_carr_id.
DATA l_dynamic_where type STRING.
APPEND 'LH' TO lt_carrid.
l_dynamic_where = 'CARRID = LT_CARRID-TABLE_LINE'.
SELECT * FROM sflight
INTO TABLE lt_sflight
FOR ALL ENTRIES IN lt_carrid
WHERE (l_dynamic_where).Regards,
Sandra
2012 May 27 6:22 PM
Hi Sandra,
Table C_T_DATA is defined as a TABLE parameter of a user exit without using any type. That means its structure will be defined at run time only.
Hope it clears the requirement.
Regards,
Guddan
2012 May 27 10:24 PM
Hi Archna,
your problem is rather that there is no valid field in your where clause:
v_where = 'GUID = C_T_DATA-GUID'.
BUT000 has no component GUID, it is PARTNER_GUID.
DATA:
lv_where TYPE string,
lt_partner TYPE TABLE OF but000-partner.
lv_where = 'PARTNER_GUID = C_T_DATA-PARTNER_GUID'.
SELECT partner
INTO TABLE lt_partner
FROM but000
FOR ALL ENTRIES IN c_t_data
WHERE (lv_where).
works perfect in SAP ECC 6.0 SAP_ABA 701 0007
Regards,
Clemens
2012 May 28 5:06 AM
Hi,
Can you paste the error message that appears?
Regards,
Jake
| User | Count |
|---|---|
| 3 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |