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: 

dynamic select of unknown fields

Former Member
0 Kudos

Hello,

I just started abap last monday and I'm still very new in it. I have a problem and i would appreciate if some one could detaily tell me how I could solve this problem. I have search in this forum but I haven't found any thing close to what I really want to do.

Many contracts could be tied to a single projet and also many payments could be tied to a single contract.

I am looking for a way so that I could dynamically determine the number of all contracts belonging to a particular project. There is a table called <u>prps</u> in sap. this table contains all projects data. There is also another table called <u>prhi</u> which contains all the contracts to a project. The field in prps is <u>prps-posid</u> for the the project number. The contract field in prhi is <u>prhi-posnr</u>

I have put all the project numers in a <u>range r_projetnr</u> for <u>prhi-up</u>.

Now my problem is how could I dynamically select all the contracts belonging to a project.

I would appreciate any tips on how to do this.

Thanks

Claudi

6 REPLIES 6

Former Member
0 Kudos

make a join querry on PRPS & PRHI comparig common fields (e.g. proj number)

in where condition give FOR ALL ENTRIES IN RANGE_R_PROJETNR

Former Member
0 Kudos

hmmm i dont see any necessity for dynamics here.

data:    lt_prhi     type table of prhi.

Select * from prhi
into table lt_prhi
where posnr = HERE COMES YOUR PROJECT NUMBER OF WHICH YOU WANT TO SELECT ALL CONTRACTS.

there you go, all the project belonging to that project are now in your internal table lt_prhi.

Message was edited by:

Florian Kemmer

Former Member
0 Kudos

Hi Tim,

I am still not sure of ur question.

Do u want to select different fields dynamically and the their data OR dynamically select data for a single field u know??

What is it ?

Please answer.

0 Kudos

Thanks you all for your respond. I think I need to be more precise. I have all the project numbers packed in a range <u>r_projectnr.</u>

With all the project numbers packed in a range I have selected all the contracts already like this:

data: lt_prhi
 SELECT * FROM prhi INTO CORRESPONDING FIELDS OF TABLE lt_prhi
   WHERE up IN r_projectnr.
  IF sy-subrc <> 0.
    EXIT.
  ELSE.
* out put the data dynamically to alv output.
clear w_output.
CLEAR w_output.
* t_output is my output structure which already has some fields among them the projectnr.
* I have already selected the projectnr and outputed it to
* t_output.
    LOOP AT t_ouput INTO w_output.
      CLEAR w_prhi.
      w_tabix_1 = 0.

      SORT lt_prhi.
      LOOP AT t_prhi INTO w_prhi WHERE psphi = w_output-projectnr.
        w_tabix_1 = w_tabix_1 + 1.

        CASE w_tabix_1.
WHEN 1.
*   assign first contract to t_output
            w_outpu-contractnr1           = w_prhi-posnr.
* some more constants data come here
 WHEN 2.
            w_output-contractnr2          = w_prhi-posnr.
* some more constant data would come here.
WHEN 3. 
.................
WHEN 4
.....................
ENDCASE

This way may be good if only a certain number of contracts are expected to be outputed. But in a case like mine where I want to output all contracts belonging to a particular project, I need a dynamic way of doing this. I have a structure defined with 4 contracts but I would also need to know a way of dynamically expanding this structure depending on the number of contracts found in one project. I hope this explains my difficult situation as a freshman in abap.

Thank you

Claudi Tim

Message was edited by:

Tim claudi

Message was edited by:

Tim claudi

Message was edited by:

Tim claudi

Former Member
0 Kudos

WHY dont use SELECT -OPTIONS???

<b>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.</b>

Former Member
0 Kudos

hi,

make a join querry on PRPS & PRHI

select field1 field2 etc from prhi FOR ALL ENTRIES IN RANGE_R_PROJETNR

where posid = RANGE_R_PROJETNR-posid into tble i_prhi