Application Development 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: 

Dynamic where clause: Urgent

Former Member
0 Kudos

Hi,

I am facing a problem with data retrieval in a BADI with dynamic where clause.

I have a variable defined as:

data: lv_where_condn TYPE string.

I concatenate the data in the string based on the user's input and perform the following select:

SELECT *

FROM zd_apo_prodvar1

INTO TABLE lt_data

WHERE (lv_where_condn).

The sy-subrc returns a value 4 although there is data in the system for the users data input.

Earlier it used to give a short dump which I have now take care of with the catch statement.

SAP has suggested the following:

This problem happens if an attempt was made to bind or define a variable character string with a buffer length less than the two-byte minimum requirement. Please check the variable definition in your custom code and increase the buffer size or use a different type.

Any inputs will b appreciated in declaring the dats type for lv_where_condn.

cheers

Aveek

25 REPLIES 25

Former Member
0 Kudos

Take a look at this thread

Regards,

Ravi

Note - Please mark the helpful answers

Former Member
0 Kudos

Hi ,

Declare your LV_WHERE_CONDITION as below

DATA:BEGIN OF LV_WHERE_CONDITION OCCURS 0.

INCLUDE STRUCTURE RSDWHERE.

DATA: END OF LV_WHERE_CONDITION.

RSDWHERE is a line for dynamic where conditions

APPEND your where condition to this table and use it it should work.

Regards,

Raghavendra

0 Kudos

Hi,

There is no structure by the name RSDWHERE in APO or R/3. Is there any alternative structure I can use.

cheers

Aveek

former_member186741
Active Contributor
0 Kudos

how is lt_data defined? if it's not exactly as zd_apo_prodvar1 you could have problems.

0 Kudos

Hi,

lt_data is defined as:

TYPES:

lt_data TYPE STANDARD TABLE OF zd_apo_prodvar1.

cheers

Aveek

0 Kudos

hi,

check this sample ..

REPORT  ZDYNAMIC_SELECT                         .

TABLES: VBAK.

DATA: CONDITION TYPE STRING.
DATA: BEGIN OF ITAB OCCURS 0,
VBELN LIKE VBAK-VBELN,
POSNR LIKE VBAP-POSNR,
END OF ITAB.

SELECT-OPTIONS: S_VBELN FOR VBAK-VBELN.

CONCATENATE 'VBELN' 'IN' 'S_VBELN.'
INTO CONDITION SEPARATED BY SPACE.

SELECT VBELN POSNR FROM VBAP INTO TABLE ITAB
WHERE (CONDITION).

LOOP AT ITAB.
WRITE 'hello'.
ENDLOOP.

Regards

vijay

0 Kudos

surely lt_data must be defined after 'data' not 'types'... it would get a syntax error otherwise.

Former Member
0 Kudos

Hi !

It must be defined as follows:

DATA: where_clause TYPE STRING

As you did so it would be helpful to post what the string contains in runtime !

Regards

Rainer

Some points would be fine if that helped you....

0 Kudos

Hi,

I have defined the lv_where_condn as type string.

DATA : lv_where_condn TYPE string.

But I still get the exception raised when I concatenate and use it in my select statement.

Any inputs will be appreciated.

The exception that is raised is:

catch CX_SY_OPEN_SQL_DB.

cheers

Aveek

0 Kudos

Hi aveek,

i too faced the same problem , but this exceptions is in Older versions , it will give that exception in 4.6C or below, if you run it in 4.7 above it will work. first check your version. and if it is 4.6c then you have go with other solution that you can find in this thread by Rich using Subroutine pool generation.

Regards

vijay

Former Member
0 Kudos

Hi !

Is the where condition very long ?

There will be an error if the condition containes many values and the generated SQL-Statemend becomes to lage...

0 Kudos

as Rainer said before, what are the contents of the string when it dumps?

Former Member
0 Kudos

Hi Aveek,

Sorry the structure is RSDSWHERE.

You can have a look at standard program RFKORDJ4.

search for BSI_WHERE is a dynamic where condition.

Regards,

Raghavendra

former_member186741
Active Contributor
0 Kudos

previous versions of r/3 expected the dynamic sql to be declared like this:

DATA:

BEGIN OF it_sql OCCURS 0,

text(72),

END OF it_sql,

maybe you have to use that approach.

0 Kudos

Hi,

The code returns sy-subrc = 4 for the wher condition:

( BRFAM = 'L&M' ) AND ( ITPCK = '25' ) AND ( MKLEN = 'KS' ) AND ( MKTGR = 'SE04' ) AND PARPR IN LR_MATNR

If I take out the BRFAM field from the string the program works fine.

Looking forward to your inputs.

cheers

Aveek

Former Member
0 Kudos

Hi !

Can you post the SE11 definition of the table on wigh the data ist beeing selected ?

AND... maybe you can a a SE16 extract of the table...

0 Kudos

The data is in the table and it is a view.

The contents are in the view and just one field BRFAM seems to create an issue.

The table is quite long in order to dump the definition in SDN.

cheers

Aveek

Former Member
0 Kudos

hi,

When.

SY-SUBRC = 4:

The result table is empty.

check the content in your table where there is any record for that condition.

Regards,

Tanveer.

Mark helpful answers

Message was edited by: Tanveer Shaikh

Former Member
0 Kudos

What is the BRFAM field content in the table? is it L&M or something else? can u try with LIKE (BRFAM like %L&%) and check??

0 Kudos

Hi,

The value is L&M and i tried your option but it does not work. Loking forward to your inputs.

cheers

Aveek

0 Kudos

it seems like it's a bug with sql....

maybe it's getting confused because of the embedded '&'- you could try defining a constant or variable with that value(L&M)and pass that to the sql.

..and have you tried putting the L&M at the end of the sql??

0 Kudos

Hi,

Using the where clause for example:

( BRFAM LIKE '%L&%' ) AND PARPR IN LR_MATNR

does not retrieve any value in ABAP Objects but returns a value in the custom program created in se38.

Any inputs will be appreciated.

cheers

Aveek

0 Kudos

Hi,

I have been able to take care of this problem now.

However I am facing another issue:

The BADI Implementation has a method loc_prod_value_list.

Here there is a changing parameter ct_value_list defined as type standard table.

In the BADI there is a statement:

create data lv_line like line of ct_value_list.

lv_line is defined as type ref to data.

I need to figure out where in the class implementation the changing parameter is populated.

cheers

Aveek

0 Kudos

Hi Aveek,

could you put something in the thread to explain how you solved it, it may help someone else with a similar problem, and issue any points if appropriate.

Put your latest question in a new thread. Sorry I can't help you with that one.

0 Kudos

Hi,

The problem was elsewhere in the ABAP Objects: See the link although I have not provided the answer as it may not be appropriate for the forum. I have found SAP Notes for the issues and am curently looking into it.

cheers

Aveek

You can check this link for the problem.