cancel
Showing results for 
Search instead for 
Did you mean: 

Ranges

Former Member
0 Kudos

how to work with ranges in report

Accepted Solutions (1)

Accepted Solutions (1)

former_member181962
Active Contributor
0 Kudos

declaration:

ranges: r_matnr type mara-matnr.

  • Filling ranges is similar to select-options.

r_matnr-low = 'I'.

r_matnr-sign = 'EQ'.

r_matnr-low = '000000000000018'.

append r_matnr.

Usage in Selects

select * from mara into table it_mara

where matnr in r_matnr.

Regards,

Ravi

Answers (3)

Answers (3)

Former Member
0 Kudos

ur option name-high= value

option name-low= value

Former Member
0 Kudos

Hi Jaya,

If ur using ranges plz use the IN keyword in case of FOR.

We can see the coding.

REPORT YCLASSICREPORTING NO STANDARD PAGE HEADING LINE-COUNT 20(5)

LINE-SIZE 88 MESSAGE-ID ZMGSVMR .

TABLES : LFA1.

SELECT-OPTIONS : VENDOR FOR LFA1-LIFNR.

DATA: BEGIN OF ITAB OCCURS 0,

LIFNR LIKE LFA1-LIFNR,

NAME1 LIKE LFA1-NAME1,

ORT01 LIKE LFA1-ORT01,

END OF ITAB.

DATA : FNAME(10) , FVAL(10) TYPE N.

INITIALIZATION .

VENDOR-LOW = 100.

VENDOR-HIGH = 1500.

VENDOR-OPTION = 'BT'.

VENDOR-SIGN = 'I'.

APPEND VENDOR.

AT SELECTION-SCREEN ON VENDOR.

IF VENDOR-LOW < 100 OR VENDOR-HIGH > 1500.

MESSAGE I000(ZMSGVMR) WITH 'enter oroper input'.

ENDIF.

START-OF-SELECTION.

SELECT LIFNR NAME1 ORT01 FROM LFA1 INTO TABLE ITAB WHERE LIFNR IN

VENDOR.

LOOP AT ITAB.

FORMAT COLOR 1.

WRITE : / ' accno' , 'name of vendor' , 'city of vendor' .

WRITE : / ITAB-LIFNR ,SY-VLINE , ITAB-NAME1,SY-VLINE , ITAB-ORT01,

SY-VLINE.

ULINE.

FORMAT COLOR OFF.

ENDLOOP.

SET PF-STATUS 'YVMR'.

AT USER-COMMAND.

CASE SY-UCOMM.

WHEN 'VENDOR'.

GET CURSOR FIELD FNAME VALUE FVAL.

SET PARAMETER ID 'LIF' FIELD FVAL.

CALL TRANSACTION 'XK02' AND SKIP FIRST SCREEN.

ENDCASE.

TOP-OF-PAGE.

WRITE : / 'VENDOR DETAILS ' COLOR 3 .

END-OF-PAGE.

WRITE 😕 'PAGE NO:' , SY-PAGNO COLOR 6.

END OF SELECTION.

See this coding

Here both SELECT-OPTIONS & RANGES works for the same purpose. They both are used for the range selection from selection screen. The main diff. between them is, while we use SELECT-OPTIONS system implicitly creates the select options internal table which contains the fields of SIGN,OPTION,LOW & HIGH. But in case of RANGES, this internal table should be defined explicitly.

Eg. to SELECT-OPTIONS :

-


REPORT YARSELECT.

TABLES YTXLFA1.

SELECT-OPTIONS : VENDOR FOR YTXLFA1-LIFNR.

INITIALIZATION.

VENDOR-LOW = 1000. " It specifies the range starting value.

VENDOR-HIGH = 2000. " It specifies the range ending value.

VENDOR-OPTION = 'BT'. " specifies ranges value is in between.

VENDOR-SIGN = 'I'. "specifies both inclussive.

APPEND VENDOR.

- - - -

- - - -

SELECT LIFNR LAND1 NAME1 FROM LFA1 INTO TABLE ITAB

WHERE LIFNR IN VENDOR.

Eg. to RANGES:

-


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.

-


>

Example:

select-options: bukrs for zstock-bukrs.

Should the user fill in 'ABFI' in BUKRS on the selection screen, BUKRS will look like this:

IEQABFI

This is because BUKRS is set as a table as follows:

begin of bukrs occurs 0,

SIGN(1) type c,

OPTION(2) type c,

LOW like bukrs,

HIGH like bukrs,

end of bukrs.

Now, when you create the following range, it will have the exact same fields set inside its table:

Ranges: bukrs for zstock-bukrs.

The difference is, because ranges doesn't show on the selection screen, you will have to fill it yourself, meaning you will have to fill bukrs-sign, bukrs-option, bukrs-low & bukrs-high all manually.

Some tips:

Sign is always I (for Include) or E (for Exclude)

Option can be a whole range, which includes:

EQ (Equal)

BT (Between))

CP (Contain Pattern)

So let's say you want to have the range check for all company codes not starting with AB, you will set your code as follow:

ranges: bukrs for zstock-bukrs.

bukrs-sign = 'E'. "Exclude

bukrs-option = 'CP'. "Pattern

bukrs-low = 'AB*'. "Low Value

bukrs-high = ''. "High Value

append bukrs.

Always remember to APPEND your range when you fill it, as the WHERE clause checks against the lines of the range table, not against the header line.

Hope this explains it well enough.

-


>

What does SIGN "I" & "E" mean?

The "I" stands for Include, and the "E" for Exclude.

The easiest way to learn how the range selections work is, create the following dummy program:

report dummy.

tables: mara.

select-options: matnr for mara-matnr.

start-of-selection.

loop at matnr.

write: / matnr-sign,

matnr-option,

matnr-low,

matnr-high.

endloop.

Run this program, and fill in a lot of junk into MATNR. Fill in some includes, some excludes, some ranges, etc., and you will soon realise how the system builds ranges (select-options). Once you know that, you can fill your own ranges quickly and efficiently.

Rgds,

P.Naganjana Reddy

Former Member
0 Kudos

check below code....

TABLES: mchb, mch1, mard, mcha, mbew.

************************************************************************

  • Internal Tables

************************************************************************

DATA : xmard LIKE mard OCCURS 0 WITH HEADER LINE,

xmchb LIKE mchb OCCURS 0 WITH HEADER LINE,

xmch1 LIKE mch1 OCCURS 0 WITH HEADER LINE,

xmbew LIKE mbew OCCURS 0 WITH HEADER LINE.

************************************************************************

  • Ranges Tables

************************************************************************

ranges: r_matnr for mara-matnr,

r_WERKS for marc-werks,

r_LGORT for MARD-lgort,

r_CHARG for mch1-charg,

R_ERDAT FOR NAST-ERDAT.

data :w_bwtar LIKE mbew-bwtar,

w_value LIKE mbew-salk3,

w_tclabs LIKE mchb-clabs,

w_tcumlm LIKE mchb-cumlm,

w_tcinsm LIKE mchb-cinsm,

w_tceinm LIKE mchb-ceinm,

w_tcspem LIKE mchb-cspem,

w_tcretm LIKE mchb-cretm,

w_tval TYPE p DECIMALS 2.

  • Filling the Range tables

loop at matnr.

if matnr-high is initial.

r_matnr-sign = 'I'.

r_matnr-option = 'EQ'.

r_matnr-low = matnr-low.

append r_matnr.

else.

r_matnr-sign = 'I'.

r_matnr-option = 'BT'.

r_matnr-low = matnr-low.

r_matnr-high = matnr-high.

endif.

endloop.

loop at WERKS.

if WERKS-high is initial.

r_WERKS-sign = 'I'.

r_WERKS-option = 'EQ'.

r_WERKS-low = WERKS-low.

append r_WERKS.

else.

r_WERKS-sign = 'I'.

r_WERKS-option = 'BT'.

r_WERKS-low = WERKS-low.

r_WERKS-high = WERKS-high.

append r_WERKS.

endif.

endloop.

loop at LGORT.

if LGORT-high is initial.

r_LGORT-sign = 'I'.

r_LGORT-option = 'EQ'.

r_LGORT-low = LGORT-low.

append r_LGORT.

else.

r_LGORT-sign = 'I'.

r_LGORT-option = 'BT'.

r_LGORT-low = LGORT-low.

r_LGORT-high = LGORT-high.

append r_LGORT.

endif.

endloop.

loop at CHARG.

if CHARG-high is initial.

r_CHARG-sign = 'I'.

r_CHARG-option = 'EQ'.

r_CHARG-low = CHARG-low.

append r_CHARG.

else.

r_CHARG-sign = 'I'.

r_CHARG-option = 'BT'.

r_CHARG-low = CHARG-low.

r_CHARG-high = CHARG-high.

append r_CHARG.

endif.

endloop.

  • loop at ERDAT.

if ERDAT-high is initial.

r_ERDAT-sign = 'I'.

r_ERDAT-option = 'EQ'.

r_ERDAT-low = ERDAT-low.

append r_ERDAT.

else.

r_ERDAT-sign = 'I'.

r_ERDAT-option = 'BT'.

r_ERDAT-low = ERDAT-low.

r_ERDAT-high = ERDAT-high.

append r_ERDAT.

endif.

  • endloop.

IF NOT INVENTORY IS INITIAL.

  • Getting data into internal table

IF R_WERKS[] IS INITIAL AND

R_LGORT[] IS INITIAL.

MESSAGE e000(38) WITH 'Plant and Storage location fields are mandatory'.

ELSE.

SELECT * FROM MARD

INTO TABLE XMARD

WHERE MATNR in r_MATNR AND

WERKS in r_WERKS AND

LGORT in r_LGORT AND

( labst > 0 OR

umlme > 0 OR

insme > 0 OR

einme > 0 OR

speme > 0 OR

retme > 0 ).

IF xmard[] IS INITIAL.

MESSAGE e000(38) WITH 'No inventory found. Check selections'.

EXIT.

ENDIF.

  • now, xmard contains all the entries which have inventory

*

  • get those ones that are batch managed

*

SELECT *

INTO TABLE xmchb

FROM mchb FOR ALL ENTRIES IN xmard

WHERE matnr = xmard-matnr

AND werks = xmard-werks

AND lgort = xmard-lgort

AND charg in r_charg

AND ( clabs > 0 OR

cumlm > 0 OR

cinsm > 0 OR

ceinm > 0 OR

cspem > 0 OR

cretm > 0 ).

  • delete those materials from xmard that are batch managed

*

LOOP AT xmard.

READ TABLE xmchb WITH KEY matnr = xmard-matnr

werks = xmard-werks

lgort = xmard-lgort.

CHECK sy-subrc = 0.

DELETE xmard.

ENDLOOP.

  • whatever is left in xmard is non-batch managed inventory, so add the

  • entries to XMCHB so that the inventory is all in one table

*

LOOP AT xmard.

CLEAR xmchb.

xmchb-matnr = xmard-matnr.

xmchb-werks = xmard-matnr. " xmard-werks.

xmchb-lgort = xmard-matnr. " xmard-lgort.

xmchb-charg = xmard-matnr.

xmchb-lvorm = xmard-matnr.

xmchb-clabs = xmard-labst.

xmchb-cumlm = xmard-umlme.

xmchb-cinsm = xmard-insme.

xmchb-ceinm = xmard-einme.

xmchb-cspem = xmard-speme.

xmchb-cretm = xmard-retme.

xmchb-lvorm = xmard-lvorm.

xmchb-chdll = xmard-dlinl.

APPEND xmchb.

ENDLOOP.

  • now, xmchb contains all inventory (batch managed & non-batch managed)

*

  • get the other required data

*

CHECK NOT xmchb[] IS INITIAL.

*

SELECT *

INTO TABLE xmch1

FROM mch1 FOR ALL ENTRIES IN xmchb

WHERE matnr = xmchb-matnr

AND charg = xmchb-charg.

*

SELECT *

INTO TABLE xmbew

FROM mbew FOR ALL ENTRIES IN xmchb

WHERE matnr = xmchb-matnr

AND bwkey = xmchb-werks

AND bwtar = w_bwtar.

LOOP AT xmchb.

READ TABLE xmch1 WITH KEY matnr = xmchb-matnr

charg = xmchb-charg.

IF sy-subrc = 0.

CLEAR: xmch1-vfdat.

ENDIF.

READ TABLE xmbew WITH KEY matnr = xmchb-matnr

bwkey = xmchb-werks.

IF sy-subrc NE 0.

CLEAR: xmbew-stprs, xmbew-peinh.

ENDIF.

IF xmbew-peinh = 0.

w_value = 0.

ELSE.

w_value = ( xmchb-clabs * ( xmbew-stprs / xmbew-peinh ) ) +

( xmchb-cumlm * ( xmbew-stprs / xmbew-peinh ) ) +

( xmchb-cinsm * ( xmbew-stprs / xmbew-peinh ) ) +

( xmchb-ceinm * ( xmbew-stprs / xmbew-peinh ) ) +

( xmchb-cspem * ( xmbew-stprs / xmbew-peinh ) ) +

( xmchb-cretm * ( xmbew-stprs / xmbew-peinh ) ).

ENDIF.

w_tcretm = w_tcretm + xmchb-cretm.

w_tcspem = w_tcspem + xmchb-cspem.

w_tceinm = w_tceinm + xmchb-ceinm.

w_tcinsm = w_tcinsm + xmchb-cinsm.

w_tcumlm = w_tcumlm + xmchb-cumlm.

w_tclabs = w_tclabs + xmchb-clabs.

w_tval = w_tval + w_value.

*populating into final internal table

DATA_RECORD-MATNR = XMCHB-MATNR.

DATA_RECORD-WERKS = XMCHB-WERKS.

DATA_RECORD-LGORT = XMCHB-LGORT.

DATA_RECORD-CHARG = XMCHB-CHARG.

DATA_RECORD-LVORM = XMCHB-LVORM.

DATA_RECORD-CLABS = XMCHB-CLABS. " W_TCLABS.

DATA_RECORD-CUMLM = xmchb-cumlm. " W_TCUMLM.

DATA_RECORD-CINSM = xmchb-cinsm. " W_TCINSM.

DATA_RECORD-CEINM = xmchb-ceinm. " W_TCEINM.

DATA_RECORD-CSPEM = xmchb-cspem. " W_TCSPEM.

DATA_RECORD-CRETM = xmchb-cretm. " W_TCRETM.

DATA_RECORD-VFDAT = XMCH1-VFDAT.

DATA_RECORD-CHDLL = XMCHB-CHDLL.

DATA_RECORD-W_VAL = W_VALUE.

DATA_RECORD-STPRS = XMBEW-STPRS.

DATA_RECORD-PEINH = XMBEW-PEINH.

append data_record.

ENDLOOP.

ENDIF. " IF R_WERKS[] IS INITIAL AND

ELSE. " IF NOT INVENTORY IS INITIAL.

  • Call for ZLIM

SELECT OBJKY " Object key

KSCHL " Message type

PARNR " Message partner

PARVW " Partner function

ERDAT " Date on which status record was created

USNAM " User name

VSTAT " Processing status of message

INTO TABLE OUTPUT_RECORD

FROM NAST

WHERE KAPPL = KAPPL AND

KSCHL = KSCHL AND

SPRAS = SPRAS AND

ERDAT IN R_ERDAT.

ENDIF. " IF NOT INVENTORY IS INITIAL.