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

please explain me the code

Former Member
0 Likes
634

RANGES : r_matnr FOR mara-matnr .

SELECT lifnr

matnr

INTO CORRESPONDING FIELDS OF TABLE t_data

FROM zdata

WHERE lifnr = p_lifnr.

LOOP AT t_data .

r_matnr-sign = 'I' .

r_matnr-option = 'EQ' .

r_matnr-low = t_data-matnr .

APPEND r_matnr .

ENDLOOP.

SELECT mblnr

matnr

menge

INTO TABLE lt_menge

FROM mseg

FOR ALL ENTRIES IN lt_itab

WHERE mblnr = lt_itab-mblnr

AND matnr IN r_matnr

1 ACCEPTED SOLUTION
Read only

KjetilKilhavn
Active Contributor
0 Likes
582

Hello Madan, it is good you have found the performance & tuning forum. Here you can ask any beginner question you like, as the name indicates the forum is not restricted to performance or tuning related issues.

RANGES is a way of saying you miss the free-ranging shepherd life of previous generations. A very poetic statement to start your program, and a fine way to say that city life is not always a dance on roses.

SELECT denotes exclusivity. Not everyone, just the selected will be eligable for what comes next. Sort of like many religions where you are doomed unless you are a believer. As there are many different religions, we are either doomed in any case (all religions correct) or not doomed at all (all religions mistaken).

As you can see the selected few will be guided INTO a sheltered space and remembered by the program. In order to be among the eligable your life number (lifnr) must be one that has been picked by the gods (p_lifnr).

LOOP should be pretty self-explanatory for a programmer.

APPEND is a mis-spelling. It should be ATTEND. It is important to attend to the ceremonies of your religion if you want to be among the select few.

Finally the polyteistic nature of our world is referenced towards the end of the program, where the materialism of our society is hinted at.

Please don't hesitate to ask for interpretations of the next program you write. We are all here to help you with the basics and don't expect you to spend too much time learning the elementary things on your own.

<i><b>Remember:</b> Please reward all helpful contributions.</i>


Kjetil Kilhavn (Vettug AS) - ABAP developer since Feb 2000, but will probably never be a Rockstar developer
4 REPLIES 4
Read only

Former Member
0 Likes
582

***

  • This part will create a range variable. The range variable acts like Select-Options and

  • contains of the fields:

  • sign

  • options

  • low

  • high

***

RANGES : r_matnr FOR mara-matnr .

***

  • The internal table has perhaps more fields and in an different order than just

  • lifnr

  • matnr.

  • using CORRESPONDING FIELDS will do a name mapping. That means, this

  • table has to have at least fields with the same name.

***

SELECT lifnr

matnr

INTO CORRESPONDING FIELDS OF TABLE t_data

FROM zdata

WHERE lifnr = p_lifnr.

  • Now the report will loop over the just filled table and fill the range

  • object with the material number into the LOW field.

***

LOOP AT t_data .

r_matnr-sign = 'I' .

r_matnr-option = 'EQ' .

r_matnr-low = t_data-matnr .

APPEND r_matnr .

ENDLOOP.

  • in the next step, the code performs another select on an SAP table. This time

  • it uses the ranges variable and another table with the FOR ALL ENTRIES in <itab> to

  • get the values (mblnr, matnr, menge).

*

  • well... there are some limitations on the ranges table within an SQL where condition.

***

SELECT mblnr

matnr

menge

INTO TABLE lt_menge

FROM mseg

FOR ALL ENTRIES IN lt_itab

WHERE mblnr = lt_itab-mblnr

AND matnr IN r_matnr

Read only

Former Member
0 Likes
582

Hello madan,

RANGES : r_matnr FOR mara-matnr .

"""range is being declared for material number

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

SELECT lifnr "Account Number of Vendor or Creditor

matnr "Material number

INTO CORRESPONDING FIELDS OF

TABLE t_data "respective fields of internal table

FROM zdata "Source table

WHERE

lifnr = p_lifnr."p_lifnr is used as selection criterion

"From the naming convention P_lifnr looks like a parameter entered by user

"So all material numbers and A/C numbers for a particular account number are being selected

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

"The following process is defining a range.r_matnr will contain all Material numbers

which are available for the account number P_lifnr

eg:imagine that you have 1,2,3 matnr having LIFNR '001' from ZDATA

then:::::after this loop r_matnr eill contain 1,2,3>

LOOP AT t_data .

r_matnr-sign = 'I' .

r_matnr-option = 'EQ' .

r_matnr-low = t_data-matnr .

APPEND r_matnr .

ENDLOOP.

"select X from Y where matnr IN r_matnr" means

it will select field X from table Y

where material number = '1' or '2' or '3'...(based on matrn in the t_data)

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

you are selecting from MSEG some fields which have material numbers in ZDATA for a particular

account number and which have mblnr values in lt_itab...ie records which have mblnr from lt_itab

and material number from ZDATA for the account number from the database table mseg

SELECT mblnr

matnr

menge

INTO TABLE lt_menge

FROM mseg

FOR ALL ENTRIES IN lt_itab

WHERE mblnr = lt_itab-mblnr

AND matnr IN r_matnr

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

Reward if useful

Regards

Byju

Read only

KjetilKilhavn
Active Contributor
0 Likes
583

Hello Madan, it is good you have found the performance & tuning forum. Here you can ask any beginner question you like, as the name indicates the forum is not restricted to performance or tuning related issues.

RANGES is a way of saying you miss the free-ranging shepherd life of previous generations. A very poetic statement to start your program, and a fine way to say that city life is not always a dance on roses.

SELECT denotes exclusivity. Not everyone, just the selected will be eligable for what comes next. Sort of like many religions where you are doomed unless you are a believer. As there are many different religions, we are either doomed in any case (all religions correct) or not doomed at all (all religions mistaken).

As you can see the selected few will be guided INTO a sheltered space and remembered by the program. In order to be among the eligable your life number (lifnr) must be one that has been picked by the gods (p_lifnr).

LOOP should be pretty self-explanatory for a programmer.

APPEND is a mis-spelling. It should be ATTEND. It is important to attend to the ceremonies of your religion if you want to be among the select few.

Finally the polyteistic nature of our world is referenced towards the end of the program, where the materialism of our society is hinted at.

Please don't hesitate to ask for interpretations of the next program you write. We are all here to help you with the basics and don't expect you to spend too much time learning the elementary things on your own.

<i><b>Remember:</b> Please reward all helpful contributions.</i>


Kjetil Kilhavn (Vettug AS) - ABAP developer since Feb 2000, but will probably never be a Rockstar developer
Read only

0 Likes
582

Hi Kjetil,

10 points for your poetic answer. Made my day.

Will be happy for the rest of the morning.

-1 point if I could give to Madan for such a lazy question. Grrr.

All the best, Mark.