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

How to change Fields positions Dynamically in Internal table Structure....??

0 Likes
2,280

Hi friends,

I have to Change Structure Fields position dynamically in Internal table.....

Ex. Structure.

types: begin of ty_stru,

werks   type werks,

lifnr      type lifnr,

name   type name1,

amoun type dmbtr,

end begin of ty_stru.

data: it_stru type table of ty_stu,

        wa_stru type  ty_stu.

My Requirement is, i have to get sum of Amount in 2 cases(2 type O/P)

Output 1) Sum of All Plants.   : In Diff Plants there ll be Same Vendor.

Output 2) Sum of All Vendors.

Is there any options to change Structure Fields Positions Dynamically....

To Use Control Break Command: At End

Thanks & Regards,

Bhargav D.

1 ACCEPTED SOLUTION
Read only

former_member730258
Participant
0 Likes
1,971

DATA: it_stru    type table of ty_stu,

         it_werks type hashed table of ty_stu with unique key werks,   "Contains total per plant

         it_lifnr type hashed table of ty_stu with unique key lifnr,          "Contains total per vendor

         wa_stru type ty_stu,   

         lv_lifnr   type lifnr.

LOOP AT it_stru INTO wa_stru.

  lv_lifnr = wa_stru-lifnr.

  CLEAR: wa_stru-lifnr, wa_stru-name.

  COLLECT wa_stru INTO lt_werks.    

  CLEAR wa_stru-werks.

  wa_stru-lifnr = lv_lifnr.

  COLLECT wa_stru INTO lt_lifnr.

ENDLOOP.

Hi friends,

I have to Change Structure Fields position dynamically in Internal table.....

Ex. Structure.

types: begin of ty_stru,

werks   type werks,

lifnr      type lifnr,

name   type name1,

amoun type dmbtr,

end begin of ty_stru.

data: it_stru type table of ty_stu,

        wa_stru type  ty_stu.

My Requirement is, i have to get sum of Amount in 2 cases(2 type O/P)

Output 1) Sum of All Plants.   : In Diff Plants there ll be Same Vendor.

Output 2) Sum of All Vendors.

Is there any options to change Structure Fields Positions Dynamically....

To Use Control Break Command: At End

Thanks & Regards,

Bhargav D.

11 REPLIES 11
Read only

FredericGirod
Active Contributor
0 Likes
1,971

Hi,

I think you have a very bad idea.

Stop playing with AT END.

Just create two internal table with Plants / Vendors and the amount. And play witth the COLLECT statement. That will be more simpler, more faster ...

(or create a copy of your table, clear the field you didn't want, and play witht the AT END)

regards

Fred

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,971

I think this is a very good example of how we can use HASHED TABLEs (because the key - Plant, CoCd, Vendor is unique).


Just create two internal table with Plants / Vendors and the amount. And play witth the COLLECT statement.

I would define different hashed tables (statically/dynamically using RTTC) using the relevant field on which the summation has to be done & fill them using COLLECT.

BR,

Suhas

Read only

0 Likes
1,971

I never used this kind of tables, maybe it's a good idea to post a good doc/example

regards

Fred

Read only

0 Likes
1,971

Hi,

I like to define only on structure for this requirement...

with diff internal tables......

Actual Requirement is

Selection ScreenTotal Sales for Month
.PeriodI/P
1Radio Buttons1Company
2Radio Buttons2Plant
3Radio Buttons3Division
4Radio Buttons4Vendor
They want O/P
If  Radio Buttons1Company1AmountQty
"Company2AmountQty
"Company3AmountQty
"Company4AmountQty
If  Radio Buttons2Plant1AmountQty
"Plant2AmountQty
"Plant3AmountQty
If  Radio Buttons3Division1AmountQty
"Division2AmountQty
"Division3AmountQty
If  Radio Buttons4Vendor1AmountQty
"Vendor2AmountQty
"Vendor3AmountQty
"Vendor4AmountQty
"Vendor5AmountQty

Thanks & Regards,

Bhargav D.

Read only

Former Member
0 Likes
1,971

Hello,

Will it be an ALV Grid output?

If so, the user already can do the summation himself.

If you have to do the summation in ABAP, you can define another internal table having just "werks, lifnr, amount" and do the summation in a loop.

Regards

Ali Murat

Read only

0 Likes
1,971

Hi,

I like to define only on structure for this requirement...

with diff internal tables......

Actual Requirement is

Selection ScreenTotal Sales for Month
.PeriodI/P
1Radio Buttons1Company
2Radio Buttons2Plant
3Radio Buttons3Division
4Radio Buttons4Vendor
They want O/P
If  Radio Buttons1Company1AmountQty
"Company2AmountQty
"Company3AmountQty
"Company4AmountQty
If  Radio Buttons2Plant1AmountQty
"Plant2AmountQty
"Plant3AmountQty
If  Radio Buttons3Division1AmountQty
"Division2AmountQty
"Division3AmountQty
If  Radio Buttons4Vendor1AmountQty
"Vendor2AmountQty
"Vendor3AmountQty
"Vendor4AmountQty
"Vendor5AmountQty

Thanks & Regards,

Bhargav D.

Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
1,971

Is this is a classical report or an ALV?

If the latter, why can't you use the subtotal functionality?

Read only

0 Likes
1,971

If that's the case just declare a simple structure like below. Then pass the values based on your radio button selection.

TYPES:

BEGIN OF ty,

  field TYPE char18,

  amount TYPE dmbtr,

ENDIF.

Read only

former_member730258
Participant
0 Likes
1,972

DATA: it_stru    type table of ty_stu,

         it_werks type hashed table of ty_stu with unique key werks,   "Contains total per plant

         it_lifnr type hashed table of ty_stu with unique key lifnr,          "Contains total per vendor

         wa_stru type ty_stu,   

         lv_lifnr   type lifnr.

LOOP AT it_stru INTO wa_stru.

  lv_lifnr = wa_stru-lifnr.

  CLEAR: wa_stru-lifnr, wa_stru-name.

  COLLECT wa_stru INTO lt_werks.    

  CLEAR wa_stru-werks.

  wa_stru-lifnr = lv_lifnr.

  COLLECT wa_stru INTO lt_lifnr.

ENDLOOP.

Read only

Former Member
0 Likes
1,971

Hi Bhargav,

If u want to use single structure , then Dynamic  table help u to do so.

But it became complex program .

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

     EXPORTING

       IT_FIELDCATALOG =

     IMPORTING

       EP_TABLE        = .

Regards

Alok

Read only

former_member186413
Participant
0 Likes
1,971

In that case, it's bad ideas to declare structure at the begging. If I were you , I would rather use RTTS to play with.

Best Regards.