Application Development 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: 

rang values

former_member582701
Contributor
0 Kudos

Hello,

I had a function which received a single value (stcdt) and did some operations and consults. Now, i need use same function but i receive a rang of values (in struct: sign, option, low, high).

Before:

SELECT kunnr stcdt

FROM KNA1

INTO TABLE i_client

WHERE stcdt = v_stcdt.

IF NOT i_client[] IS INITIAL.

SELECT kunnr tipo_fra belnr belnr_vs

FROM zficgtd01

INTO TABLE i_cargos

FOR ALL ENTRIES IN i_client

WHERE bukrs = 'COBE' AND

kunnr = i_client-kunnr

etc, etc

The problem is that i don't know how i can use same code with the input rang. I can't use a loop... how many different vaules are there between two limits?

If i use:

SELECT kunnr stcdt

FROM KNA1

INTO TABLE i_client

WHERE stcdt IN rang.

IF NOT i_client[] IS INITIAL.

SELECT kunnr tipo_fra belnr belnr_vs

FROM zficgtd01

INTO TABLE i_cargos

FOR ALL ENTRIES IN i_client

WHERE bukrs = 'COBE' AND

kunnr = i_client-kunnr

In i_client i have all kunnr, and i need separate clients by stcdt.

I think rangs values are not used of intelligent form in this case because i select all kunnr for later use them of independent form depending of stcdt.

Is difficult to explain but do you understands me? Any idea?

Thx in advance

Manel

8 REPLIES 8

Former Member
0 Kudos

Hello Manel,

Why don't you combine table I_CARGOS and I_CLIENT after the second selection by reading all clients from I_CARGOS and getting the relevant STCDT from table I_CLIENT?

Regards,

John.

former_member181962
Active Contributor
0 Kudos

Hi Manel,

This part of the code is correct:

SELECT kunnr stcdt

FROM KNA1

INTO TABLE i_client

WHERE stcdt IN rang.

rang should be declared like this:

ranges: rang for kna1-stcdt.

Then, the z table should have the same field STCDT to group different KUNNR s according to STCDT.

SELECT kunnr <b>STCDT</b> tipo_fra belnr belnr_vs

FROM zficgtd01

INTO TABLE i_cargos

FOR ALL ENTRIES IN i_client

WHERE bukrs = 'COBE' AND

kunnr = i_client-kunnr

REgards,

Ravi

Former Member
0 Kudos

Hi,

U have to define a range table and append teh same with values.

If it is from slection screen then u can use IN s_stcdt.

If u want to use range table:

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.

former_member582701
Contributor
0 Kudos

thx guys, but my problem persists.

John, I have seeing your solution but i think is not possible because i need group kunnr separated by stcdt and in cargos i have all kunnr and in clients all kunnr by stcdt. The problem is that i don't know the number of different stcdt.

Example:

Loop i_cargos

Loop i_client

if i_cargos-kunnr = i_client-kunnr

if i_client-stcdt = 01

append i_cargos1

if i_client-stcdt = 02

append i_cargos2

How many tables i need? I think is absurd group by stcdt through a rang if after you need separate by stcdt. Probably is a bad analysis of the functional.

Thx all.

0 Kudos

Hi Manel,

You are right, you can't define an unfinite number of "Cargo" tables, but what I meant was to add the 'STCDT' field to the table I_CARGOS. The program which is calling this FM then has to split the table up again and this program is also supplying the range to your FM.

Regards,

John.

raviprakash
Advisor
Advisor
0 Kudos

Hi Manel,

I have clearly understood your problem. Please replace your AFTER code by following code. This would solve your problem.

----


Code for Manel -

SELECT kunnr stcdt

FROM KNA1

INTO TABLE i_client

WHERE stcdt IN rang.

check not i_client[] is initial.

  • The following step would put all the kunnr of same stcdt together one after the

  • other.

sort i_client by stcdt.

data: w_client like line of i_client,

i_client_temp like i_client.

loop at i_client into w_client.

on change of w_client-stcdt.

SELECT kunnr tipo_fra belnr belnr_vs

FROM zficgtd01

INTO TABLE i_cargos

FOR ALL ENTRIES IN i_client_temp

WHERE bukrs = 'COBE' AND

kunnr = i_client-kunnr

  • etc, etc.

refresh i_client_temp[].

endon.

append w_client to i_client_temp.

endloop.

--End of code---

Please try the above solution and let me know if you face any problem.

The ABAP statement ON CHANGE OF, would be really helpful here.

NOTE: Please provide points if you are happy with the solution :).

Thanks and regards,

Ravi .

former_member582701
Contributor
0 Kudos

Yep.

Both solutions are good! Thx John and ravi.

I have used your sentence. Easy solution and good operation.

Thx

pd: sorry ravi, my english is not my strongpoint

pd2: i didn't know about the points. Inmediately i vote something

0 Kudos

Not a problem Manel :).

You had clearly stated the problem and so i had not much of problem understanding it.

Thanks and regards,

Ravi .