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

urgent

Former Member
0 Likes
1,096

Hi Experts,

I have a requirement to select data for different condition types from a condition table. For that, I have to write a select statement in such a way that I can pass the selected condition types in the where condition of the select query. The way we write in SQL. E.g. select * from t_city where city in (delhi, kol,mum,chennai).

But we don't write like that in ABAP. So how to build the range table for a select statement. I want to build a range table for condition types.How to go about writing the following query in ABAP:

select * from condition_table where condition_records in(cond_type1, cond_type2).

If I want to fulfill the range table using a macro because of reusability how to go about it?

Thanks and Regards,

Sangeeta.

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,010

HI,

SEE THIS CODIN THIS MIGHT SATISFY YOUR REQUIREMENT

SELECT-OPTIONS : s_matnr FOR mara-matnr.

TYPES : BEGIN OF ty_mara,

matnr TYPE matnr,

mtart TYPE mtart,

END OF ty_mara.

TYPES : BEGIN OF TY_MARC,

MATNR TYPE MATNR,

WERKS TYPE WERKS_D,

END OF TY_MARC.

TYPES : tt_mara TYPE STANDARD TABLE OF ty_mara,

TT_MARC TYPE STANDARD TABLE OF TY_MARC.

DATA : it_mara TYPE tt_mara WITH HEADER LINE,

IT_MARC TYPE TT_MARC WITH HEADER LINE.

SELECT matnr

mtart

FROM mara

INTO TABLE it_mara

WHERE matnr IN s_matnr.

IF IT_MARA IS NOT INITIAL.

SELECT MATNR

WERKS

FROM MARC

INTO TABLE IT_MARC

FOR ALL ENTRIES IN IT_MARA

WHERE MATNR EQ IT_MARA-MATNR.

Hi Experts,

I have a requirement to select data for different condition types from a condition table. For that, I have to write a select statement in such a way that I can pass the selected condition types in the where condition of the select query. The way we write in SQL. E.g. select * from t_city where city in (delhi, kol,mum,chennai).

But we don't write like that in ABAP. So how to build the range table for a select statement. I want to build a range table for condition types.How to go about writing the following query in ABAP:

select * from condition_table where condition_records in(cond_type1, cond_type2).

If I want to fulfill the range table using a macro because of reusability how to go about it?

Thanks and Regards,

Sangeeta.

6 REPLIES 6
Read only

Former Member
0 Likes
1,010

Hi,

Check the coding.

This is not in accordance to condition types but would give you a fairly good idea about how to build ranges.

RANGES:R_LAND FOR IFLO-TPLNR.

SELECT-OPTIONS:S_LAND FOR KNA1-LAND1 NO INTERVALS .

LOOP AT S_LAND.

R_LAND-SIGN = 'I'.

R_LAND-OPTION = 'CP'.

R_LAND-LOW = s_land-low..

APPEND R_LAND.

clear r_land.

ENDLOOP.

Regards,

Suruchi Mahajan

Read only

Former Member
0 Likes
1,010

Hi,

U can give range of values inside open and closed brackets within ' '.

or U can build one range table like Ranges : S_matnr ...

Regards,

Nandha

Read only

Former Member
0 Likes
1,011

HI,

SEE THIS CODIN THIS MIGHT SATISFY YOUR REQUIREMENT

SELECT-OPTIONS : s_matnr FOR mara-matnr.

TYPES : BEGIN OF ty_mara,

matnr TYPE matnr,

mtart TYPE mtart,

END OF ty_mara.

TYPES : BEGIN OF TY_MARC,

MATNR TYPE MATNR,

WERKS TYPE WERKS_D,

END OF TY_MARC.

TYPES : tt_mara TYPE STANDARD TABLE OF ty_mara,

TT_MARC TYPE STANDARD TABLE OF TY_MARC.

DATA : it_mara TYPE tt_mara WITH HEADER LINE,

IT_MARC TYPE TT_MARC WITH HEADER LINE.

SELECT matnr

mtart

FROM mara

INTO TABLE it_mara

WHERE matnr IN s_matnr.

IF IT_MARA IS NOT INITIAL.

SELECT MATNR

WERKS

FROM MARC

INTO TABLE IT_MARC

FOR ALL ENTRIES IN IT_MARA

WHERE MATNR EQ IT_MARA-MATNR.

Read only

Former Member
0 Likes
1,010

HI.

REPORT YARRANGE.

TABLES YTXLFA1.

RANGES: VENDOR FOR YTXFLA1-LIFNR.

- - - -

- - - --

- - - -

SELECT LIFNR LAND1 NAME1 FROM LFA1 INTO TABLE ITAB

WHERE LIFNR IN VENDOR.

Here with RANGES user has to design an internal table with fields -

SIGN,OPTION,LOW and HIGH EXPLICITLY.

Rewards all helpfull answers.

Regards.

Jay

Read only

Former Member
0 Likes
1,010

RANGES r_vbtyp FOR vbfa-vbtyp_n.

INITIALIZATION.

  • Include the list of document categories for document check

CLEAR r_vbtyp.

REFRESH r_vbtyp.

r_vbtyp-low = 'K'.

r_vbtyp-option = 'EQ'.

r_vbtyp-sign = 'I'.

APPEND r_vbtyp.

r_vbtyp-low = 'O'.

r_vbtyp-option = 'EQ'.

r_vbtyp-sign = 'I'.

APPEND r_vbtyp.

r_vbtyp-low = 'S'.

r_vbtyp-option = 'EQ'.

r_vbtyp-sign = 'I'.

APPEND r_vbtyp.

Etc....

SELECT vbeln posnv vbelv posnn vbtyp_n vbtyp_v fplnr fpltr FROM vbfa

INTO TABLE t_vbfa_r

FOR ALL ENTRIES IN t_alv1

WHERE vbelv = t_alv1-vbeln AND

<b>NOT vbtyp_n IN r_vbtyp.</b>

Read only

Former Member
0 Likes
1,010

Sangeeta,

U can use SQL as you have mentioned like :

select * from t_city where city in ( 'delhi', 'kol','mum','chennai' )

But using a range is preferrable here because u can add another city

straight in range rather than disturbing the sql stmt .

u can define a range

Range : ra_city like city .

loop,.,

ra_city-f1 = 'delhi'.

append ra_city .

clear ra_city .

endloop.

~ Laxmi

  • Reward all helpful answers