Skip to Content
author's profile photo Former Member
Former Member

How to use Dynamic Internal table

Hello,

I have a requirement where I need to pick a field from final internal table and display that field as ALV columns and I have to pick another field in the same INternal table to display it as a corresponding value for each header DYNAMICALLY.

lw_fieldcat-col_pos = 1.

lw_fieldcat-tabname = 'T_FINAL'.

lw_fieldcat-fieldname = 'ATTR20A'.

lw_fieldcat-seltext_m = 'SUBSTANCE ID'.

lw_fieldcat-outputlen = '21'.

lw_fieldcat-fix_column = 'X'.

lw_fieldcat-key = 'X'.

APPEND lw_fieldcat TO lt_fieldcat.

CLEAR LW_FIELDCAT.

lw_fieldcat-col_pos = 2.

lw_fieldcat-tabname = 'T_FINAL'.

lw_fieldcat-fieldname = 'PRVSY'.

lw_fieldcat-seltext_m = 'R3 MAT NBR'.

lw_fieldcat-outputlen = '14'.

lw_fieldcat-FIX_COLUMN = 'X'.

lw_fieldcat-key = 'X'.

APPEND lw_fieldcat TO lt_fieldcat.

CLEAR LW_FIELDCAT.

These 2 fields are constant, now i need to display fields dynamically from the field STCTS (for dynamic header) CCNGN (for the value in each header)

In the below code the logic is working to pick appropriate value for each header.

DATA : Y_I_FCAT TYPE LVC_T_FCAT,

Y_WA_FCAT LIKE LINE OF Y_I_FCAT.

DATA : T_NEWFINAL TYPE STANDARD TABLE OF TY_FINAL,

WA_NEWFINAL TYPE TY_FINAL.

LOOP AT T_FINAL INTO WA_FINAL

WHERE STCTS IS NOT INITIAL

CONCATENATE 'SUBID CLASSIFICATION-' WA_FINAL-STCTS

INTO Y_WA_FCAT-FIELDNAME.

  • INTO Y_WA_FCAT-SCRTEXT_M.

APPEND Y_WA_FCAT TO Y_I_FCAT. "Header of column appear as

'SUBID SUBID CLASSIFICATION-AR-HTS'

CLEAR Y_WA_FCAT.

MOVE WA_FINAL-CCNGN TO WA_NEWFINAL-CCNGN. "HERE IT WILL PICK THE VALUE FOR THE ABOVE " HEADER EX : '2345'

&----


*&THIS STATEMENT WILL MOVE THE KEY FIELD TO

*&WA_NEWFINAL.

&----


MOVE WA_FINAL-GUID_PR TO WA_NEWFINAL-GUID_PR.

APPEND WA_NEWFINAL TO T_NEWFINAL.

CLEAR : WA_FINAL,

WA_NEWFINAL.

ENDLOOP.

How should i pass it to the dynamic interanl table and then to the ALV grid filed catlog.

Below is my code for refernce :

**DATA : Y_I_FCAT TYPE LVC_T_FCAT,

        • Y_WA_FCAT LIKE LINE OF Y_I_FCAT.

      • Y_WA_FCAT TYPE LVC_S_FCAT.

      • **DATA : T_NEWFINAL TYPE STANDARD TABLE OF TY_FINAL,

          • WA_NEWFINAL TYPE TY_FINAL.

          **

          *

          *DATA : W_STRING TYPE STRING.

          DATA : WA_FLNAME(32) TYPE C.

          *LOOP AT T_FINAL INTO WA_FINAL

          • WHERE STCTS IS NOT INITIAL

          • AND CCNGN IS NOT INITIAL.

          *

          *ADD 1 TO COUNTER.

          *ENDLOOP.

          *

          *DO COUNTER TIMES.

          *

          *

          LOOP AT T_FINAL INTO WA_FINAL

          WHERE STCTS IS NOT INITIAL

          AND CCNGN IS NOT INITIAL.

          CONCATENATE 'SUBID CLASSIFICATION-' WA_FINAL-STCTS

          • INTO Y_WA_FCAT-FIELDNAME.

          • INTO Y_WA_FCAT-SCRTEXT_M.

          INTO WA_FLNAME.

          Y_WA_FCAT-FIELDNAME = WA_FLNAME.

          Y_WA_FCAT-SELTEXT = WA_FLNAME.

          APPEND Y_WA_FCAT TO Y_I_FCAT.

          CLEAR Y_WA_FCAT.

          • MOVE WA_FINAL-CCNGN TO W_STRING.

          MOVE WA_FINAL-CCNGN TO WA_NEWFINAL-CCNGN.

          &----


          *&THIS STATEMENT WILL MOVE THE KEY FIELD TO

          *&WA_NEWFINAL.

          &----


          MOVE WA_FINAL-GUID_PR TO WA_NEWFINAL-GUID_PR.

          APPEND WA_NEWFINAL TO T_NEWFINAL.

          CLEAR : WA_FINAL,

          WA_NEWFINAL.

          • ENDIF.

          *ENDDO.

          ENDLOOP.

          PERFORM CREATE_DYNAMIC_ITAB.

          *

          LOOP AT Y_I_FCAT INTO Y_WA_FCAT. "IT_FIELDCAT INTO LW_FIELDCAT.

          MOVE : Y_WA_FCAT-SCRTEXT_M TO LW_FIELDCAT-SELTEXT_M,

          *

          Y_WA_FCAT-FIELDNAME TO LW_FIELDCAT-FIELDNAME,

          • Y_WA_FCAT-TABNAME TO LW_FIELDCAT-TABNAME,

          • Y_WA_FCAT-COL_POS TO LW_FIELDCAT-COL_POS,

          Y_WA_FCAT-SCRTEXT_M TO LW_FIELDCAT-SELTEXT_M.

          • Y_WA_FCAT-DATATYPE TO LW_FIELDCAT-DATATYPE,

          • Y_WA_FCAT-INTLEN TO LW_FIELDCAT-INTLEN.

          APPEND LW_FIELDCAT TO LT_FIELDCAT.

          ENDLOOP.

          ENDFORM. " DYNAMIC

          &----


          *& Form CREATE_DYNAMIC_ITAB

          &----


          • text

          ----


          • --> p1 text

          • <-- p2 text

          ----


          FORM CREATE_DYNAMIC_ITAB .

          *

          *DATA : DY_TABLE TYPE REF TO DATA,

          • DY_LINE TYPE REF TO DATA.

          *

          • DATA : Y_LV_COMP TYPE STRING.

          *

          *FIELD-SYMBOLS: <DYN_TABLE> TYPE STANDARD TABLE,

          • <DYN_WA>,

          • <DYN_FIELD>.

          *

          *FIELD-SYMBOLS : <y_fld> TYPE ANY.

          *

          CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

          EXPORTING

          IT_FIELDCATALOG = Y_I_FCAT

          IMPORTING

          EP_TABLE = DY_TABLE.

          IF SY-SUBRC <> 0.

          • MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

          • WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

          ENDIF.

          ASSIGN DY_TABLE->* TO <DYN_TABLE>.

          *CREATE DYNAMIC WORK AREA AND ASSIGN TO FS.

          CREATE DATA DY_LINE LIKE LINE OF <DYN_TABLE>.

          ASSIGN DY_LINE->* TO <DYN_WA>.

          LOOP AT T_FINAL INTO WA_FINAL.

          Y_LV_COMP = 'ATTR20A'.

          ASSIGN COMPONENT Y_LV_COMP OF STRUCTURE <DYN_WA> TO <Y_FLD>.

          <Y_FLD> = WA_FINAL-ATTR20A.

          Y_LV_COMP = 'PRVSY'.

          ASSIGN COMPONENT Y_LV_COMP OF STRUCTURE <DYN_WA> TO <Y_FLD>.

          <Y_FLD> = WA_FINAL-PRVSY.

          Y_LV_COMP = 'PRTXT'.

          ASSIGN COMPONENT Y_LV_COMP OF STRUCTURE <DYN_WA> TO <Y_FLD>.

          <Y_FLD> = WA_FINAL-PRVSY.

          Y_LV_COMP = 'GRVSY'.

          ASSIGN COMPONENT Y_LV_COMP OF STRUCTURE <DYN_WA> TO <Y_FLD>.

          <Y_FLD> = WA_FINAL-GRVSY.

          LOOP AT T_NEWFINAL INTO WA_NEWFINAL

          WHERE GUID_PR = WA_FINAL-GUID_PR.

          CONCATENATE 'SUBID Classification-'

          WA_FINAL-STCTS

          INTO Y_LV_COMP.

          ASSIGN COMPONENT Y_LV_COMP OF STRUCTURE <DYN_WA> TO <Y_FLD>.

          <Y_FLD> = WA_NEWFINAL-CCNGN.

          ENDLOOP.

          APPEND <DYN_WA> TO <DYN_TABLE>.

          FREE : <DYN_WA>, <Y_FLD>.

          ENDLOOP.

          ENDFORM. " CREATE_DYNAMIC_ITA

          ANy suggestion would be apprecaited.

          Regards,

          Kittu

          Add a comment
          10|10000 characters needed characters exceeded

          Assigned Tags

          Related questions

          1 Answer

          • author's profile photo Former Member
            Former Member
            Posted on Dec 22, 2008 at 09:39 AM

            I think I need to put it in more descriptive way...

            I am closing this thread

            Add a comment
            10|10000 characters needed characters exceeded

          Before answering

          You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
          You must be Logged in to submit an answer.

          Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.