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 query problem

vallamuthu_madheswaran2
Active Contributor
0 Likes
370

HI Friends,

I'm creating the following FM. Now my problem is if both the input value is initial i need get all the values. what can i do?

FUNCTION zimport_test.

*"----


""Local interface:

*" IMPORTING

*" REFERENCE(INV_NUM) LIKE VBRK-VBELN OPTIONAL

*" REFERENCE(INV_DATE) LIKE VBRK-FKDAT OPTIONAL

*"----


DATA: BEGIN OF itab OCCURS 0,

vbeln LIKE vbrk-vbeln ,

fkdat LIKE vbrk-fkdat,

END OF itab.

DATA: lv_where(100).

IF inv_num IS NOT INITIAL AND inv_date IS INITIAL.

CONCATENATE 'vbeln = ' '''' inv_num '''' INTO lv_where.

ELSEIF inv_num IS INITIAL AND inv_date IS NOT INITIAL.

CONCATENATE 'fkdat = ' '''' inv_date '''' INTO lv_where.

ELSEIF inv_date IS NOT INITIAL AND inv_num IS NOT INITIAL.

CONCATENATE 'fkdat = ' '''' inv_date '''' ' and vbeln = ' '''' inv_num '''' INTO lv_where.

ELSE.

CONCATENATE 'fkdat = ' inv_date ' and vbeln = ' inv_num INTO lv_where.

ENDIF.

SELECT vbeln fkdat FROM vbrk

INTO CORRESPONDING FIELDS OF TABLE itab

WHERE (lv_where).

WRITE: ' '.

ENDFUNCTION.

Thanks & Reagrds,

Vallamuthu.M

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
341

I am not writing the dynamic query for you but giving you the basic idea how to proceed with your requirement.

>

> I'm creating the following FM. Now my problem is if both the input value is initial i need get all the values. what can i do?

In this case you have to use RANGES while selecting data & not PARAMETERS.

You can try something like this:

DATA: r_vbeln TYPE RANGE OF vbeln_vf,
      w_vbeln LIKE LINE OF r_vbeln,
      r_fkdat TYPE RANGE OF fkdat,
      w_fkdat LIKE LINE OF r_fkdat.

w_vbeln-sign = w_fkdat-sign = 'I'.
w_vbeln-option = w_fkdat-option = 'EQ'.

w_vbeln-low = inv_num.
APPEND w_vbeln TO r_vbeln.

w_fkdat-low = inv_date.
APPEND w_fkdat TO r_fkdat.

You can use the RANGEs R_VBELN & R_FKDAT to select data from VBRK.

BR,

Suhas

PS: Let me warn you that selecting all the records from VBRK is going to be time-consuming.

2 REPLIES 2
Read only

Former Member
0 Likes
341

hi,

can you try this one..

if both the values are initial, set 'fkdat = * ' ' and vbeln = * '.

rgds,

guna.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
342

I am not writing the dynamic query for you but giving you the basic idea how to proceed with your requirement.

>

> I'm creating the following FM. Now my problem is if both the input value is initial i need get all the values. what can i do?

In this case you have to use RANGES while selecting data & not PARAMETERS.

You can try something like this:

DATA: r_vbeln TYPE RANGE OF vbeln_vf,
      w_vbeln LIKE LINE OF r_vbeln,
      r_fkdat TYPE RANGE OF fkdat,
      w_fkdat LIKE LINE OF r_fkdat.

w_vbeln-sign = w_fkdat-sign = 'I'.
w_vbeln-option = w_fkdat-option = 'EQ'.

w_vbeln-low = inv_num.
APPEND w_vbeln TO r_vbeln.

w_fkdat-low = inv_date.
APPEND w_fkdat TO r_fkdat.

You can use the RANGEs R_VBELN & R_FKDAT to select data from VBRK.

BR,

Suhas

PS: Let me warn you that selecting all the records from VBRK is going to be time-consuming.