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: 

values in itab1 should be fields in itab2

Former Member
0 Kudos

Hi All,

Kindly help me with the below requirement.

I have a internal table itab1 as below

CODE DESC GROUP COUNT

11 airbrake PA1 1

11 airbrake PA2 0

12 airbrake PA2 1

13 airbrake PA3 1

14 airbrake PA2 1

NOW from this internal table another internal table itab2 should be automatically be defined and the fields

in this internal table should be some fields of itab1 and values of itab1. so the fields will be

CODE DESC PA1 PA2 PA3.... PAn

then this structure should be passed to ALV ....

main problem iam facing here is changing the values of itab1 into fields of itab2.

these values in itab1 are not static they can vary it can be pa1 pa2 pa3 pa4......or pa1 pa3 pa5 etc

depending on these values the itab2 should be created.

Kindly help

Thanks and regards

Sujeer

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

You can declare itab2 with all the fields such as

CODE DESC PA1 PA2 PA3.... PAn

but then you can dynamically call alv depending on feilds in itab1 such that only thoes PA's value should be displayed which are in itab1.

such as

lv_count = 0.

LOOP AT itab1.

PERFORM field_cat USING itab1-group.

ENDLOOP.

FORM field_cat USING xv_group TYPE (itab1-group).

lv_count = lv_count + 1.

i_fieldcat-col_pos = lv_count.

i_fieldcat-seltext_m = xv_group.

APPEND i_fieldcat TO i_fieldcat.

CLEAR i_fieldcat.

ENDFORM. "field_cat

do the declarations properly.

this will definately solve ur problem.

Fill free to ask if any difficulties.

Regards,

Dhan

7 REPLIES 7

Former Member
0 Kudos

Hi Sujeer Shetty ,

If your tab1 and tab2 st. is same , For dynamic display in ALV you have to append the field catalog values on some coditon so the alv will display the appropriate column dynamically.

Regards,

Tarak

Former Member
0 Kudos

Hi,

You can declare itab2 with all the fields such as

CODE DESC PA1 PA2 PA3.... PAn

but then you can dynamically call alv depending on feilds in itab1 such that only thoes PA's value should be displayed which are in itab1.

such as

lv_count = 0.

LOOP AT itab1.

PERFORM field_cat USING itab1-group.

ENDLOOP.

FORM field_cat USING xv_group TYPE (itab1-group).

lv_count = lv_count + 1.

i_fieldcat-col_pos = lv_count.

i_fieldcat-seltext_m = xv_group.

APPEND i_fieldcat TO i_fieldcat.

CLEAR i_fieldcat.

ENDFORM. "field_cat

do the declarations properly.

this will definately solve ur problem.

Fill free to ask if any difficulties.

Regards,

Dhan

Former Member
0 Kudos

Hi,

You can declare itab2 with all the fields such as

CODE DESC PA1 PA2 PA3.... PAn

but then you can dynamically call alv depending on feilds in itab1 such that only thoes PA's value should be displayed which are in itab1.

such as

lv_count = 0.

LOOP AT itab1.

PERFORM field_cat USING itab1-group.

ENDLOOP.

FORM field_cat USING xv_group TYPE (itab1-group).

lv_count = lv_count + 1.

i_fieldcat-col_pos = lv_count.

i_fieldcat-seltext_m = xv_group.

APPEND i_fieldcat TO i_fieldcat.

CLEAR i_fieldcat.

ENDFORM. "field_cat

do the declarations properly.

this will definately solve ur problem.

Fill free to ask if any difficulties.

Regards,

Dhan

0 Kudos

Hi Dhan,

Thanks for your quick reply.

Every thing mentioned by you is fine except 1.

You asked me to declare ITAB2 with fileds like

CODE DESC PA1 PA2 PA3.... PAn

But, how will i declare itab2

itab2's field PA1 PA2 ...etc are based on ITAB1's group's value (pa1 pa2...)

if itab1 has only PA1 and PA2 as value in its group then

itab2 should have fields with PA1 and PA2.

ITAB2's fields are based on itab1's groups value which is never constant

then how can i declare a fixed structure for ITAB2

ITAB2 declaration should be created dynamically based on ITAB1' groups value

for this how should i proceed.

Thanks

Sujeer

0 Kudos

Hi,

You can not declare table dynamically.

So declare itab2 with all possible values of group.

then while populating itab2 those fields which are not in itab1 will be initial.

then depending on groups in itab1 at run time you can display only those field in itab2 in the alv.

regards,

Dhan

Former Member
0 Kudos

Hi Dhan,

For time being i have done that...let me see if i can find some thing else.

Regards

Sujeer

Former Member
0 Kudos

Hi,

Declare the second internal table with complete fields like

CODE DESC PA1 PA2 PA3.... PAn ........

loop at itab1 into wa1.

read table itab2 into wa2 with key fields like code desc .

if sy-subrc ne 0.

MOVE-CORRESPONDING wa1 TO wa2.

CONCATENATE 'itab2-pa' wa_group INTO value.

  • ASSIGN (value) TO <fs>.

  • <fs> = wa-value.

append wa2 to itab2.

endif.

endloop.

Regards,

Suresh.