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

select query. pls help

Former Member
0 Likes
792

Hi all

Here is a query.pls help me

in the o/p i need to get 5 fields for ekpo-menge ( i mean 5 different columns in the output are required ) ie. quantity of po in jan in a different column, like wise for feb, mar...may. similarly i need to get the netpr and peinh 5 times each for corresponding months. in this case how to define the internal table and how to write the select query? pls tell me.

do i need to do like te folowing?

data: begin of itab occurs 0,

menge1 type ekpo-menge,

menge2 type ekpo-menge,

menge3 type ekpo-menge,

menge4 type ekpo-menge,

menge5 type ekpo-menge,

netpr1 type ekpo-netpr,

netpr2 type ekpo-netpr,

netpr3 type ekpo-netpr,

netpr4 type ekpo-netpr,

netpr5 type ekpo-netpr,

end of itab.

then how to write the select query for this?

pls tell me

thanks in advance

6 REPLIES 6
Read only

Former Member
0 Likes
746

I will suggest you to write a single select query specifying the required condition in where clause and get the data into one internal table. From this internal table append the data in columns of your final internal table that u have defined.

I hope it helps.

Best Regards,

Vibha

*Please mark all the helpful answers

Read only

0 Likes
746

hi

thanks for the solution. do i need to declare the mnege feld 5 times/

this is wht i wanted to know

thanks

Read only

0 Likes
746

If you need the fields as columns then u can declare it 5 times.

Read only

Former Member
0 Likes
746

Hi,

First define an internal table with menge and netpr alone.

then

Select menge netpr
          from ekpo
          into table i_ekpo
         where ....

Then u loop at the table based on month and date move it to the final table of the structure defined by u.

Then append the values to the itab.

Hope this helps.

Read only

0 Likes
746

hi

thanks for the answer

i am not clear abt it

do u mean to say that there is no need to declare mnege 5 times or netpr 5 times?

in loop how can i do it?

pls can u send me sample code

thanks a lot

Read only

Former Member
0 Likes
746
Hi,

DATA: begin of i_ekpo,
           menge........
           netpr............
           date ..........
          end of i_ekpo.

Select menge netpr date
          from ekpo
          into table i_ekpo
         where ....

if sy-subrc = 0.
 LOOP AT i_ekpo.
v_month = i_ekpo-date+4(2).
 CASE v_month.
 WHEN '01'
  itab-menge1 = i_ekpo-menge.
 ..................
  itab-menge5 = i_ekpo-menge.
  itab-netpr1 = i_ekpo-netpr.
  itab-netpr5 = i_ekpo-netpr.
 WHEN '02'.
  itab-menge1 = i_ekpo-menge.
 ..................
  itab-menge5 = i_ekpo-menge.
  itab-netpr1 = i_ekpo-netpr.
  itab-netpr5 = i_ekpo-netpr.
 WHEN '03'.
  itab-menge1 = i_ekpo-menge.
 ..................
  itab-menge5 = i_ekpo-menge.
  itab-netpr1 = i_ekpo-netpr.
  itab-netpr5 = i_ekpo-netpr.
...
 WHEN '12'.
  itab-menge1 = i_ekpo-menge.
 ..................
  itab-menge5 = i_ekpo-menge.
  itab-netpr1 = i_ekpo-netpr.
  itab-netpr5 = i_ekpo-netpr.

ENDCASE.
 APPEND itab.
ENDLOOP.

Please be more specific with some sample outputs how is should be.