Skip to Content
avatar image
Former Member

values in itab1 should be fields in itab2

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

5 Answers

  • Best Answer
    avatar image
    Former Member
    Oct 17, 2008 at 05:55 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member Former Member

      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

  • avatar image
    Former Member
    Oct 17, 2008 at 05:52 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 17, 2008 at 05:55 AM

    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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 17, 2008 at 10:56 AM

    Hi Dhan,

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

    Regards

    Sujeer

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Oct 17, 2008 at 11:16 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded