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: 

how to do a summarization with a dynamic table.

philippe_gauthier
Participant
0 Kudos

Hello all,

I create my dynamic table for example:

<dyn_tab>

BUKRS | GJAHR | KNDNR | VVP01 | VVP02 | VVP01N1 | VVP02N1

VVP01N1 and VVP02N1 are created by a dynamic calculation and it's corresponding to the field value VVP01 and VVP02 for the year before.

also i have a second dynamic table

<dyn_tab1> with this structure:

BUKRS | GJAHR | KNDNR | VVP01 | VVP02 |

in this table i collect all the data i need to my report. so i have many records with the same data. for my example, we will have these data into <dyn_tab1>.

1010 | 2006 | 1 | 100 | 200

1010 | 2006 | 1 | 100 | 200

1010 | 2006 | 1 | 100 | 200

1010 | 2006 | 1 | 100 | 200

1010 | 2007 | 1 | 100 | 200

1010 | 2007 | 1 | 100 | 200

1010 | 2007 | 1 | 100 | 200

So in first i would like to do the summarization by year. I would like to obtain

1010 | 2006 | 1 | 400 | 800

1010 | 2007 | 1 | 300 | 600

if year = 2006.
<dyn_tab>-VVP01N1 = <dyn_tab>-VVP01

i don't understand which code i have to write

In the second question, i would like to add data into my <dyn_tab> in the goods columns

Thanks for your help

Philippe

Message was edited by:

Philippe Gauthier

1 ACCEPTED SOLUTION

raviprakash
Advisor
Advisor
0 Kudos

Hi Philippe ,

<u><b>ANSWER TO 1ST QUESTION</b></u>

-


<b>* Create another temporary dynamic table in the same way as you created for <DYN_TAB1>

  • This temporary dynamic table has same structure as <DYN-TAB1>. Name is <DYN_TEMP>.

DATA: <fs_tab> type any.

ASSIGN LOCAL COPY OF INITIAL LINE OF <dyn_tab1> TO <fs_tab>.

ASSIGN LOCAL COPY OF INITIAL LINE OF <dyn_temp> TO <fs_temp>.

sort <dyn_tab1> by BUKRS GJAHR KNDNR VVP01 VVP02.

LOOP at <dyn_tab1> into <fs_tab>.

at end of KNDNR.

append <fs_temp> to <DYN_TEMP>.

clear <fs_temp>.

endat.

<fs-temp>-bukrs = <fs-tab>-bukrs.

<fs_temp>-GJAHR = <fs_tab>-GJAHR.

<fs_temp>-KNDNR = <fs_tab>-kndnr.

<fs_temp>-vvp01 = <fs_temp>-vvp01 + <fs_tab>-vvp01.

<fs_temp>-vvp02 = <fs_temp>-vvp02 + <fs_tab>-vvp02.

endloop.

Clear <DYN_TAB1>[].

<DYN_TAB1>[] = <DYN_TEMP>[].

Thus <DYN_TAB1> has now all the aggregate information.</b>

NOTE: Answer to second question is on its way :).

Thanks and regards,

Ravi.

null

9 REPLIES 9

Former Member
0 Kudos

Hi Phillpie,

You need to declare VVP01 & VVP02 type p & then use collect statement.

your problem will be solved.

Try the following code in program:


data: begin of itab occurs 10,
        co(4) type c,
        year(4) type c,
        knd(1)  type c,
        vp01(10) type p,
        vp02(10) type p,
  end of itab.

  itab-co = '1010'.
  itab-year = '2006'.
  itab-knd  = '1'.
  itab-vp01 = 100.
  itab-vp02 = 200.
  collect itab.

  itab-co = '1010'.
  itab-year = '2006'.
  itab-knd  = '1'.
  itab-vp01 = 100.
  itab-vp02 = 200.
  collect itab.

  itab-co = '1010'.
  itab-year = '2006'.
  itab-knd  = '1'.
  itab-vp01 = 100.
  itab-vp02 = 200.
  collect itab.

  itab-co = '1010'.
  itab-year = '2006'.
  itab-knd  = '1'.
  itab-vp01 = 100.
  itab-vp02 = 200.
  collect itab.

  itab-co = '1000'.
  itab-year = '2007'.
  itab-knd  = '1'.
  itab-vp01 = 100.
  itab-vp02 = 200.
  collect itab.

  itab-co = '1000'.
  itab-year = '2007'.
  itab-knd  = '1'.
  itab-vp01 = 100.
  itab-vp02 = 200.
  collect itab.

Reward points if helpful answer.

Ashvender

raviprakash
Advisor
Advisor
0 Kudos

Hi Philippe ,

<u><b>ANSWER TO 1ST QUESTION</b></u>

-


<b>* Create another temporary dynamic table in the same way as you created for <DYN_TAB1>

  • This temporary dynamic table has same structure as <DYN-TAB1>. Name is <DYN_TEMP>.

DATA: <fs_tab> type any.

ASSIGN LOCAL COPY OF INITIAL LINE OF <dyn_tab1> TO <fs_tab>.

ASSIGN LOCAL COPY OF INITIAL LINE OF <dyn_temp> TO <fs_temp>.

sort <dyn_tab1> by BUKRS GJAHR KNDNR VVP01 VVP02.

LOOP at <dyn_tab1> into <fs_tab>.

at end of KNDNR.

append <fs_temp> to <DYN_TEMP>.

clear <fs_temp>.

endat.

<fs-temp>-bukrs = <fs-tab>-bukrs.

<fs_temp>-GJAHR = <fs_tab>-GJAHR.

<fs_temp>-KNDNR = <fs_tab>-kndnr.

<fs_temp>-vvp01 = <fs_temp>-vvp01 + <fs_tab>-vvp01.

<fs_temp>-vvp02 = <fs_temp>-vvp02 + <fs_tab>-vvp02.

endloop.

Clear <DYN_TAB1>[].

<DYN_TAB1>[] = <DYN_TEMP>[].

Thus <DYN_TAB1> has now all the aggregate information.</b>

NOTE: Answer to second question is on its way :).

Thanks and regards,

Ravi.

null

0 Kudos

Hello

I understand how you solve my problem, i have yet one question more.

In my example, I describe my table has. But the reporting is very flexible, so when i collect data, i don't know the exact structure of it.

I write the code follow


LOOP at <dyn_tab1> into <fs_tab>.

at end of KNDNR.

append <fs_temp> to <DYN_TEMP>.
clear <fs_temp>.

endat.

<b>My trouble is now</b>

how can i define the structure of the fields values for the num and quantities fields?

Thanks for your help

Philippe

0 Kudos

Hi Philippe,

I think i understood your problem. Even though you dont know the STRUCTURE of your FIELDS in the table, you can fill them. This is achieved by Jumping the exact location to the location you wish to fill data. Eg:- your sturctre is like:-

BUKRS | GJAHR | KNDNR | VVP01 | VVP02 | VVP01N1 | VVP02N1

(CHAR8) (char4) (Int 4) (int 3) (int 3) (int3) (int3)

Now you can fill data for field KNDNR in two ways:-

1) <fs-tab>-kndnr = 10.

or

2) <fs-tab>+12(*) =10.

In second option it jumps 12 positions from starting position of the workarea and fills it.

Thanks and regards,

Ravi.

0 Kudos

NOTE:

Please use the NUMERIC field as NUMC for Dynamic Fields. This way you can do perform the numeric functions on the field like add substract or aggregate and also jump positions using :-

Eg:-

If <FS_TAB> has a structure name(char12), year(numc4) and we want to have 2004 as value in YEAR field, we can use:-

<fs_tab>+12(*) = '2004'.

This will jump 12 character from the 1st position of Field Symbol <fs_tab> and assign 2004 to YEAR field.

0 Kudos

Hello

Thanks for your help.

So if i understand, i can stock into a an internal table the sructure of my dynamic table by doing something like when i create it.


data: begin of t_struct occurs 0,
          fieldname type fieldname,
          datatype type datatype_b,
          ref_field type LVC_RFNAME,
          ref_table type LVC_RTNAME,
       end of t_struct.

*...code before ...
  loop at it_fildcat
    t_struct-fieldname = it_fildcat-fieldname.
    t_struct-datatype = it_fildcat-datatype.
    t_struct-ref_field = it_fildcat-ref_field.
    t_struct-ref_table = it_fildcat-ref_table.

  endloop.
endform.

with these informations i can struct the line of my dynamic table and to be abble to add data.

What do you think about it ?

thanks for your return,

Philippe

0 Kudos

I change my philosophy of the program so with your help and the new philosophy i solve the trouble;

BR

Philippe

raviprakash
Advisor
Advisor
0 Kudos

Hi Philippe,

Can you elaborate a bit about your second question. I am unable to get what you wish there.

Waiting for the reply :).

Thanks and regards,

Ravi.

0 Kudos

For my second question.

So i have the dynamic table <dyn_temp> with the summarized data.

So I would like to do.

Check the year:

- if it's the current year, the figure into <dyn_temp>-vvP01 into <dyn_table>-VVP01.

- if it's the year before, the figure which is loaded into the VVPnn field, i want to put it into the field VVPnnN1 to my target table, before define the ALV.

Also my dynamic table can have different columns with different name of the fields.

Thanks for your help,

Philippe