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 SELECT conditions in background - problem

Former Member
0 Likes
959

Hello,

I faced a strange problem. I have function module which uses dynamic conditions in SELECT statement. Everything works fine in foreground processing, but in background the function gives no values. You can find a piece of code below. It's a bit long but as mentioned - works fine in foreground, so seems to be non-coding error... I'd be thankful for any ideas...


data: itwa_where_cond(72) occurs 20 with header line,
       wa_where_cond(72) type c,

...


  clear: itwa_where_cond[], itwa_where_cond.
  move 'BZOBJ  = ''0''' to wa_where_cond.
  append wa_where_cond to itwa_where_cond.

  clear wa_where_cond.
  concatenate 'AND KADKY >= ''' l_date_start '''' into wa_where_cond.
  append wa_where_cond to itwa_where_cond.

  clear wa_where_cond.
  concatenate 'AND KADKY <= ''' l_date_end '''' into wa_where_cond.
  append wa_where_cond to itwa_where_cond.

  clear wa_where_cond.
  concatenate 'AND MATNR = ''' wa_matwrk-matnr '''' into wa_where_cond.
  append wa_where_cond to itwa_where_cond.

  clear wa_where_cond.
  concatenate 'AND WERKS = ''' wa_matwrk-werks '''' into wa_where_cond.
  append wa_where_cond to itwa_where_cond.

  clear wa_where_cond.
  concatenate 'AND KOKRS  = ''' pi_kokrs '''' into wa_where_cond.
  append wa_where_cond to itwa_where_cond.

  if not pi_freig is initial.
    clear wa_where_cond.
    concatenate  'AND FREIG =''' pi_freig '''' into wa_where_cond.
    append wa_where_cond to itwa_where_cond.
  endif.
  if not pi_tvers is initial.
    clear wa_where_cond.
    concatenate  'AND TVERS = ''' pi_tvers '''' into wa_where_cond.
    append wa_where_cond to itwa_where_cond.
  endif.
  if not pi_klvar is initial.
    clear wa_where_cond.
    concatenate  'AND KLVAR = ''' pi_klvar '''' into wa_where_cond.
    append wa_where_cond to itwa_where_cond.
  endif.
  if not pi_feh_sta is initial.
    clear wa_where_cond.
    concatenate  'AND FEH_STA = ''' pi_feh_sta '''' into wa_where_cond.
    append wa_where_cond to itwa_where_cond.
  endif.

  if not pi_kkzma is initial.
    clear wa_where_cond.
    concatenate  ' AND KKZMA = ''' pi_kkzma '''' into wa_where_cond.
    append wa_where_cond to itwa_where_cond.
  endif.

  SELECT * FROM  KEKO into corresponding fields of table it_keko
                                         WHERE  (itwa_where_cond).   

Regards,

Grzegorz

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
916

Hi, an alternative is to define a range for each field and fill the ranges.

8 REPLIES 8
Read only

Former Member
0 Likes
917

Hi, an alternative is to define a range for each field and fill the ranges.

Read only

jaideepsharma
Active Contributor
0 Likes
916

Hi,

Can you please share the piece of code where you have defined the internal table it_keko ?

KR Jaideep,

Read only

0 Likes
916

Hi Jaideep,

definition of it_keko is simple:


data: it_keko  type table of keko.

Regards, Gregory

Read only

0 Likes
916

Hi,

You may have to debug the program in background and check where the error lies. Check if the dynamic where condition is being populated correctly and the SY_SUBRC of the select statement. Its also better to try using concatnating using SEPERATED BY SPACE.

Regards,

Vik

Read only

0 Likes
916

Hi Vik,

You may have to debug the program in background and check where the error lies. Check if the dynamic where condition is being populated correctly and the SY_SUBRC of the select statement. Its also better to try using concatnating using SEPERATED BY SPACE.

I'm debugging program by command 'JDBG' after the job has finished execution. All parameters passed to function seem to be correct...

SY-SUBRC NE 0

I'll try later concatnating using SEPERATED BY SPACE but if works in foreground...

Thanks for replies for all of you so far.

Gregory

Read only

Jelena_Perfiljeva
Active Contributor
0 Likes
916

I don't think there is anything wrong with SELECT and it shouldn't matter whether it runs in the background or foreground. You might want to make sure that the program gets the correct parameters - add MESSAGE or WRITE statements to see the parameters in background (job log or spool, depending on which you choose).

P.S. You might want to use CONCATENATE... SEPARATED BY space.

Read only

Former Member
0 Likes
916

hI,

TAKE THIS CODE... HOPE IT WORKS FOR YOU....

clear: itwa_where_cond[], itwa_where_cond.
  move `BZOBJ  = '0'` to wa_where_cond.
  append wa_where_cond to itwa_where_cond.
 
  clear wa_where_cond.
  concatenate `AND KADKY >= '` l_date_start `'`  into wa_where_cond.
  append wa_where_cond to itwa_where_cond.
 
  clear wa_where_cond.
  concatenate `AND KADKY <= '` l_date_end `'` into wa_where_cond.
  append wa_where_cond to itwa_where_cond.
 
  clear wa_where_cond.
  concatenate `AND MATNR = '` wa_matwrk-matnr `'` into wa_where_cond.
  append wa_where_cond to itwa_where_cond.
 
  clear wa_where_cond.
  concatenate `AND WERKS = '` wa_matwrk-werks `'` into wa_where_cond.
  append wa_where_cond to itwa_where_cond.
 
  clear wa_where_cond.
  concatenate `AND KOKRS  = '` pi_kokrs `'` into wa_where_cond.
  append wa_where_cond to itwa_where_cond.
 
  if not pi_freig is initial.
    clear wa_where_cond.
    concatenate  `AND FREIG = '` pi_freig `'` into wa_where_cond.
    append wa_where_cond to itwa_where_cond.
  endif.

  if not pi_tvers is initial.
    clear wa_where_cond.
    concatenate  `AND TVERS = '` pi_tvers `'` into wa_where_cond.
    append wa_where_cond to itwa_where_cond.
  endif.
  if not pi_klvar is initial.
    clear wa_where_cond.
    concatenate  `AND KLVAR = '` pi_klvar `'` into wa_where_cond.
    append wa_where_cond to itwa_where_cond.
  endif.
  if not pi_feh_sta is initial.
    clear wa_where_cond.
    concatenate  `AND FEH_STA = '` pi_feh_sta `'` into wa_where_cond.
    append wa_where_cond to itwa_where_cond.
  endif.
 
  if not pi_kkzma is initial.
    clear wa_where_cond.
    concatenate  `AND KKZMA = '` pi_kkzma `'` into wa_where_cond.
    append wa_where_cond to itwa_where_cond.
  endif.
 
  SELECT * FROM  KEKO into corresponding fields of table it_keko
                                         WHERE  (itwa_where_cond).

REGARDS

SIDDARTH

Read only

Former Member
0 Likes
916

Problem is solved.... Select condition was quite OK. I wrote that all function parameters are passed correct but in fact are not. My authority check didn't work correct in background and gave wrong value for function module. I'm sorry for taking your time and thank you for willingness of help.

Regards,

G.