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

Global Class: syntax problem

VenkatRamesh_V
Active Contributor
0 Likes
2,983

Hello,

My selection screen  contains following fields.

Company Code  (Mandatory)

year  (Mandatory)      

Doc.date

Poc.date 

Vendor

When I  give  data's for  all the selection screen fields           to global class   select Query  its displaying  Correct values but

When I  give  some  selection screen fields  with blank input  to global class   its displaying  Error   NOT to use 'IN'  So i tried with OR Instead of AND

its  never displaying exact result.

I had done the Following.

Get the values from the selection screen to global class by  FM  RS_REFRESH_FROM_SELECTOPTIONS

In  Attributes  declared  the  fields with   TYPE RANGE OF

Everything Works Fine when i pass the values of  

Company Code,  Year,  Doc.date , Pos.date, Vendor, to global class and i used 'IN' (Not Accepts EQ) .

But if I pass the values of   Company Code,  year,  Pos.date  Vendor its displaying error because of blank Doc.date field so i used OR  Instead of 'AND'  its fetching Wrong values.


Select Query.


SELECT  BUKRS LIFNR UMSKS UMSKZ  AUGDT AUGBL ZUONR GJAHR BELNR BUZEI BUDAT BLDAT CPUDT
         XBLNR SGTXT HKONT SHKZG  DMBTR WRBTR BLART MONAT BSCHL MWSKZ GSBER
  FROM   bsik
  INTO   TABLE it_ven_det
  WHERE  bukrs  IN ven-company_code   AND
                gjahr   IN ven-year                   OR
                 lifnr    IN ven-vendor                OR
                bldat   IN ven-docno                OR
                budat  IN ven-posdate
  

Hope it Understand.

Regards,

Venkat.




1 ACCEPTED SOLUTION
Read only

VenkatRamesh_V
Active Contributor
0 Likes
2,868

Thank you  for replying Felipe.

Kindly suggest me  how to store  the values dynamically  for ranges or some other  methods used to pass the  select option values for the select query without using 'IN'  Global Class.

Attributes.

dataBEGIN OF VEN,
          company_code TYPE RANGE OF T001-bukrs,
          vendor        TYPE RANGE OF lfa1-lifnr,
          year           TYPE RANGE OF bsik-gjahr,
          posdate      TYPE RANGE OF bsik-budat,
          docdate      TYPE RANGE OF bsik-bldat,
          docno        TYPE RANGE OF bsik-belnr,
          END OF ven.


CONSTRUCTOR.


FM RS_REFRESH_FROM_SELECTOPTIONS


Appended  values  to Ven.



Regards,

Venkat.



23 REPLIES 23
Read only

former_member201275
Active Contributor
0 Likes
2,868

Not sure exactly what you want, but I will try.

My suggestion is you try play around with Brackets because your statement as above won't work i.e.:

WHERE  bukrs  IN ven-company_code   AND

              ( gjahr   IN ven-year                   OR

                lifnr    IN ven-vendor                OR

                bldat   IN ven-docno                OR

                budat  IN ven-posdate )


Read only

0 Likes
2,868

Hi Glen,

Thank you for replying.

Given Brackets as you suggested and  passed the  values  for fields bukrs,  gjahr,  bldat and budat.

Displaying Runtime Error.

Short text

    Invalid value in OPTION field of value table for IN itab operator.

Error analysis

The IN  itab operator is used with internal tables which  have following structure :

SIGN(1)  OPTION(2)  LOW like db_field  HIGH like db_field

The Option Should contains  only one  of the following values: 'EQ LE GE CP BT NE LT GT NP NB"

the value is '' ''  not allowed here.

Hope you understand, I kept vendor field blank so its displaying above error.

Regards,

Venkat.

Read only

0 Likes
2,868

Hi Venkat,

     Just reflecting from the error snapshot you have pasted, it indicates you havent populated the option field which is suppose to contain either 'EQ LE GE CP BT NE LT GT NP NB".

You can have a look at the select-option internal table in the debug mode and check if the values (option field) are populated properly.

Thanks & Regards,

Tashi

Read only

0 Likes
2,868

Hi Tashi,

Thank you  for replying.

Program works fine when i  pass  all  values to the selection screen, it displays run  time error when i kept any field blank.

Regards,

Venkat.

Read only

0 Likes
2,868


Hi Venkat,

WHERE  bukrs  IN ven-company_code   AND

                gjahr   IN ven-year                   OR

                 lifnr    IN ven-vendor                OR

                bldat   IN ven-docno                OR

                budat  IN ven-posdate

Are these data object ranges or select options ?

ven-company_code 

ven-year                 

Did you try entering multiple values in the selection screen ?

Regards,

Tashi

Read only

0 Likes
2,868

Hi Tashi,

Thank you  for replying.

I tried already what you suggested but its not fetching exact result.

All fields are select-options.

Regards,

Venkat.

Read only

0 Likes
2,868

Hi Venkat,


why simple if you can do complicated? 🙂


don't see where you pass the select-options to ven structure.


Should be


{code}

SELECT-OPTIONS:

    s_bukrs for t001-bukrs,

...

ven-company_code  = s_bukrs[].


...


SELECT

...

WHERE  bukrs  IN ven-company_code   AND

                gjahr   IN ven-year                   AND

                 lifnr    IN ven-vendor               AND

                bldat   IN ven-docno                AND

                budat  IN ven-posdate

{code}


If you don't enter values, then the selection-table i.e. s_bukrs will have no lines. So ven-company_code will have no lines. An empty selection-table slects all values (no filter).


It is so easy. You don't need any RS_REFRESH_FROM_SELECTOPTIONS or even  FUNCTION 'RSDS_RANGE_TO_WHERE'.


KISS


Regards


Clemens

Read only

0 Likes
2,868

Hi Venkat,

do it as Clemens posted it here. maybe you want to use import-Parameters instead of public attributes for your range-tables. with select-options you should use MOVE <select_option_name>[] to <resp.-Attribute>, because select-Options are tables with header-lines. And do the select with WHERE a in so_a AND b in so_b....

You dont Need those fancy function-modules

regards

Jan Martin

Read only

former_member226225
Contributor
0 Likes
2,868

Hi Venkat Ramesh,

As per my understanding i did like this

(1) I designed the Selection screen with four fields.

       

         Company Code  (Mandatory)

         year  (Mandatory)     

          Doc.date

         Poc.date

         Vendor

(2) in the custom report  i got the selection screen values using FM  RS_REFRESH_FROM_SELECTOPTIONS and retrieved into Selection_table.

(3)  In the global class i created one parameter(selection_table) of type table rsparams.

(4) in the method GET_DATA I looped the Selection_table and prepared range table values are filled by using  field names of the selection screen.

(5) In the Select query i passed range tables directly with the IN Operation and it is working fine.

There are no errors with IN Condtions in the where.

Please try like this.

Thanks & Regards,

Raghunadh Kodali.

Read only

0 Likes
2,868

Hi Raghunadh,

Thank you for replying, if  i pass all values means its working, but if i pass

Company Code  (Mandatory)

  Year  (Mandatory)     

   Doc.date

   Poc.date   leaving Vendor  field blank it displaying run time error.

Regards,

Venkat.

Read only

0 Likes
2,868

Hi Venkat,

In the method have u checked optional for both these fields

Document.date

Posting date

Vendor

Thanks & Regards,

Raghunadh Kodali

Read only

0 Likes
2,868

Hi Raghunadh,

Thank you for replying, Already  given Optional for all fields.

Regards,

Venkat.

Read only

0 Likes
2,868

Hi Venkat,

Can you please post the runtime error what your are getting if the fields are optional.

Thanks & Regards,

Raghunadh Kodali

Read only

Former Member
0 Likes
2,868

You could use a dynamic WHERE clause based on the parameters filled in the selection screen then you just consider the select-options that has values on it. Something like this:

Dynamic where clause - ABAP Development - SCN Wiki

Regards,

Felipe

Read only

VenkatRamesh_V
Active Contributor
0 Likes
2,869

Thank you  for replying Felipe.

Kindly suggest me  how to store  the values dynamically  for ranges or some other  methods used to pass the  select option values for the select query without using 'IN'  Global Class.

Attributes.

dataBEGIN OF VEN,
          company_code TYPE RANGE OF T001-bukrs,
          vendor        TYPE RANGE OF lfa1-lifnr,
          year           TYPE RANGE OF bsik-gjahr,
          posdate      TYPE RANGE OF bsik-budat,
          docdate      TYPE RANGE OF bsik-bldat,
          docno        TYPE RANGE OF bsik-belnr,
          END OF ven.


CONSTRUCTOR.


FM RS_REFRESH_FROM_SELECTOPTIONS


Appended  values  to Ven.



Regards,

Venkat.



Read only

0 Likes
2,868

Hi Venkat, look at the code below, copy to a test program and see how it works and generate a Where clause based in the selection screen (I used the same fields that you're using).


REPORT  ztest.

TABLES: t001, lfa1, bsik.

DATA:gt_params TYPE TABLE OF rsparams,

      gt_ranges TYPE rs_t_rscedst,

      gs_ranges TYPE rscedst,

      gs_params LIKE LINE OF gt_params,

      gv_where  TYPE string.

SELECT-OPTIONS:

   comp_cod FOR t001-bukrs,

   vendor   FOR lfa1-lifnr,

   year     FOR  bsik-gjahr,

   posdate  FOR  bsik-budat,

   docdate  FOR bsik-bldat,

   docno    FOR  bsik-belnr.

CALL FUNCTION 'RS_REFRESH_FROM_SELECTOPTIONS'

   EXPORTING

     curr_report     = sy-repid

   TABLES

     selection_table = gt_params.

LOOP AT gt_params INTO gs_params.

   IF gs_params-sign IS INITIAL AND

      gs_params-option IS INITIAL AND

      gs_params-low IS INITIAL AND

      gs_params-high IS INITIAL.

     CONTINUE.

   ENDIF.

   gs_ranges-fnam = gs_params-selname.

   gs_ranges-sign = gs_params-sign.

   gs_ranges-option = gs_params-option.

   gs_ranges-low = gs_params-low.

   gs_ranges-high = gs_params-high.

   APPEND gs_ranges TO gt_ranges.

ENDLOOP.

CALL FUNCTION 'RSDS_RANGE_TO_WHERE'

  EXPORTING

    i_t_range            = gt_ranges

  IMPORTING

    e_where              = gv_where.

Regards,

Felipe

Read only

0 Likes
2,868

Hi Felipe,

Thank you for replying, i will be checking  it.

Regards,

Venkat

Read only

0 Likes
2,868

Thank you.

Read only

0 Likes
2,868

Hi venkat,

I tried to explain to you that a range table is equal to a (selection) filter. SELECT-OPTIONS defines such a filter, but it is a table with header line. As long as you do not enter anything in the selection screen, an empty selection table is returned.

As soon as you enter something, one more more lines are appended to the selection table and the SIGN and OPTION fields are filled so that they can be interpreted. If you anter a single value in the left field of a SELECT-OPTIONS, the SIGN field gets an 'I' as Includem the OPTION field becomes 'EQ' as equal and the LOW field gets the value entered. This 'filter' the field it is applied to using IN operator. An empty selection table behind the IN operator means 'no filter' - everything gets through.

If you enter a pattern in the SELECT-OPTIONS (i.e. S*), the OPTION field will be CP contains pattern, if you enter a low and a high value, option is BT between to define a range.

You can directly move your select-options tables to the range tables defined. As the system cannot distinguish between the range table and the implicit headerline of the table, you have to put [] behind the select-options name. So only the table without header line is transferred.

Please believe me: You do not need any function modules to get it working as expected.

The function modules recommenden here are useful but not for your purpose.

Regards

Clemens

Read only

0 Likes
2,868

I agree with Clemens, I suggested that approach based that you were already using RS_REFRESH_FROM_SELECTOPTIONS. But I suggest you to at least test Clemens' suggestions and see that it will work as you expect.
Regards,

Felipe

Read only

Former Member
0 Likes
2,868

Hi Venkat,

     If your vendor code is empty, then you set a condition telling that when it is empty, you put all.

Example.

IF VEN-VENDOR IS INITIAL.

    VEN-VENDOR = '%'.

   ENDIF.



Best Regards,

Charlie

Read only

0 Likes
2,868

Hi Charlie,

if you read the whole thread you may discover that this is not correct.

'%' can only be used with database selection using LIKE operator. You will never need this while we have such a powerful instrument as selection tables to be used with IN operator.


OK, it is a bit confusing that a selection table will use * and + do define patterns. What a luck we don't have regular expressions in selection tables (ranges).


Regards


Clemens

Read only

0 Likes
2,868

Hi Clemens,

     Thanks for noticing. I was totally unaware that he was using IN operator for his condition. I agree that '%' can only be used with the LIKE operator as I have tried using such in my program.  I also agree with your solution that an empty selection table returns all values when used in select statement.

Best Regards,
Charlie