Dynamic internal table and dynamic field catalog

hi
i need to decide the number of fields of the internal table at runtime
and then need to pass value to this internal table.
then i need to create the field catalog for this internal table (so here
field catalog is also dynamic) to display in alv.
how to achieve this dynamic internal table creation and dyanmic field catalog generation

Hi Ajay,
  U can use the below code to create a dynamic internal table.
*adding the field names only once for the dynamic table     .
      MOVE 'PRCTR' TO gw_component-name.
      gw_component-type ?= cl_abap_elemdescr=>get_string( ).
      INSERT gw_component INTO TABLE gt_components.
      MOVE 'RCNTR' TO gw_component-name.
      gw_component-type ?= cl_abap_elemdescr=>get_string( ).
      INSERT gw_component INTO TABLE gt_components.
      MOVE 'RACCT' TO gw_component-name.
      gw_component-type ?= cl_abap_elemdescr=>get_string( ).
      INSERT gw_component INTO TABLE gt_components.
      MOVE 'RYEAR' TO gw_component-name.
      gw_component-type ?= cl_abap_elemdescr=>get_string( ).
      INSERT gw_component INTO TABLE gt_components.
      MOVE 'YTDBAL' TO gw_component-name.
      gw_component-type ?= cl_abap_elemdescr=>get_string( ).
      INSERT gw_component INTO TABLE gt_components.
      MOVE 'OBAL' TO gw_component-name.
      gw_component-type ?= cl_abap_elemdescr=>get_string( ).
      INSERT gw_component INTO TABLE gt_components.
*get structure descriptor -> GR_STRUCTDESCR
          gr_structdescr ?= cl_abap_structdescr=>create( gt_components ).
create work area of structure GR_STRUCTDESCR -> GR_WA
          CREATE DATA gr_wa TYPE HANDLE gr_structdescr.
          ASSIGN gr_wa->* TO <gw_wa>.
determine key components -> GT_KEYS
          MOVE lv_value1 TO gw_key-name.
          INSERT gw_key INTO TABLE gt_keys.
create descriptor for internal table -> GR_TABLEDESCR
          gr_tabledescr ?= cl_abap_tabledescr=>create( p_line_type  = gr_structdescr
                                                       p_table_kind = cl_abap_tabledescr=>tablekind_hashed
                                                       p_unique     = abap_true
                                                       p_key        = gt_keys
                                                       p_key_kind   = cl_abap_tabledescr=>keydefkind_user ).
create internal table -> GR_ITAB
          CREATE DATA gr_itab TYPE HANDLE gr_tabledescr.
          ASSIGN gr_itab->* TO <gt_itab>.
          CREATE DATA gr_itab LIKE STANDARD TABLE OF <gw_wa>.
          ASSIGN gr_itab->* TO <gt_sttab>.
Now u r internal table named <gt_sttab> has been created with fields like RCNTR, PRCTR,RACCT, RYEAR etc whatever the field u need u can go ahead and create dynamically.
then by using the table <gt_sttab> u can create u r field catalog.
Regards,
Rose.

Similar Messages

  • Dynamic internal table and dynamic read statements.

    Hi,
    My Scenario :
    I have two dynamic internal tables.
    I am looping at one internal table and trying to read another table.
    In the read statement how do I mention the key dyamically.
    Example code below :
      LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
    read second  dynamic internal table.
      enloop.
    The key which I want use for reading say it is keyed in the selection criteria....
    Also based on the value I read I want to modify the first internal table field value.
    Remember I dont want to explicity mention the key
    How do I do that?
    Thanks
    Krishna.

    Hi
    U need to use the field-symbol, but u can't use a WHERE option, but u need to use the CHECK statament into the second loop:
    LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
        LOOP AT <DYN_TABLE2> ASSIGNING <DYN_WA2>.
            ASSIGN COMPONENT <COMPONENT> OF STRUCTURE   <DYN_WA2> TO <FS>.
            CHECK <FS> IN (=) .......
                ASSIGN COMPONENT <COMPONENT> OF STRUCTURE   <DYN_WA> TO <FS2>.
                <FS2> = .......
                EXIT.
        ENDLOOP.
    ENDLOOP.
    Max

  • How 2 create dynamic internal table and can we pass it to gui_download FM

    HI all,
         How can we create a dynamic internal table?
    I have a requirement where  i have to create an internal table with the no. of fields depending on the selection screen values, i think tat can be possible though dynamic creation only.
             How to solve this issue..?Pointers will be very much useful..
    Thanks
    Sunny.

    hi
    Follow the code it will help you out....
    REPORT  YUSMM_TEXT2                             .
    *TABLES
    TABLES: MARA,    " General Material Data
            MAKT,    " Material Descriptions
            T002.    " Language Keys
    * GLOBAL TYPE-POOL
    TYPE-POOLS : SLIS.
    * GLOBAL TYPES
    TYPES: BEGIN OF TP_LANG ,
             SPRAS LIKE T002-SPRAS,
             LAISO LIKE T002-LAISO,
             SRNO(3) TYPE N,
           END OF TP_LANG.
    TYPES: BEGIN OF TP_MATNR,
             MATNR LIKE MARA-MATNR,
             BEGRU LIKE MARA-BEGRU,
           END OF TP_MATNR.
    * DECLARATION FOR GLOBAL INTERNAL TABLES (WITH INCLUDE STRUCTURE)
    DATA:GT_MAKT    TYPE STANDARD TABLE OF MAKT,  "Materialkurztexte,
         GT_THEAD   TYPE STANDARD TABLE OF THEAD, "SAPscript: Text-Header,
         GT_LINETAB TYPE STANDARD TABLE OF TLINE, "SAPscript: Text-Zeilen,
         GT_T002    TYPE STANDARD TABLE OF T002. "Language key
    DATA: BEGIN OF GV_TEXT_OUTPUT_LINE,
                MATNR LIKE MARA-MATNR,
                BEGRU LIKE MARA-BEGRU,
                MAKTX LIKE MAKT-MAKTX,
                LTXT40(1250) TYPE C,
                SRNO(3) TYPE N,
                SPRAS LIKE T002-SPRAS,
             END OF GV_TEXT_OUTPUT_LINE.
    DATA: GT_MATNR TYPE STANDARD TABLE OF TP_MATNR,
          WA_GT_MATNR TYPE TP_MATNR.
    DATA: GT_LANG TYPE STANDARD TABLE OF TP_LANG,
          WA_GT_LANG TYPE TP_LANG.
    DATA: GT_TEXT_OUTPUT_LINE LIKE STANDARD TABLE OF GV_TEXT_OUTPUT_LINE,
          GT_FIELDCAT         TYPE SLIS_T_FIELDCAT_ALV,
          GV_FIELDCAT         LIKE LINE OF GT_FIELDCAT,
          CT_GT_FIELDCAT_IN LIKE GV_FIELDCAT,
          GS_LAYOUT           TYPE SLIS_LAYOUT_ALV,
          GV_REPID            TYPE SY-REPID.
    DATA: BEGIN OF GV,
            FORMER_ERROR       LIKE  SY-MARKY,     " Fehlermeldung bereits
            FILE_OPEN(1),                          " Flag open file
            REC_LENGTH         TYPE  I,            " record length
            MATNR              TYPE  MARA-MATNR,   " material
            REPID              TYPE  SYST-REPID,
            RETCO              TYPE  SY-SUBRC,
          END OF GV.
    DATA: GV_MAKT             TYPE MAKT,
          GV_T002             TYPE T002,
          GV_LANGU            TYPE THEAD-TDSPRAS.
    * DECLARATION FOR FIELD-SYMBOLS
    FIELD-SYMBOLS: <FS_DATA> TYPE REF TO DATA,
                   <FS_DATA1> TYPE REF TO DATA,
                   <FS_2>    TYPE STANDARD TABLE,
                   <FS_22>   TYPE STANDARD TABLE,
                   <FS_1>,
                   <FS_11>,
                   <F>,
                   <FA>,
                   <LWA_LINE_WA>,
                   <LWA_LINE_WA1>.
    DATA: IT_FLDCAT TYPE LVC_T_FCAT.
    DATA: T_FLDCAT1   TYPE SLIS_T_FIELDCAT_ALV.
    DATA: L_LT TYPE SLIS_LAYOUT_ALV.
    DATA: WA_IT_FLDCAT TYPE LVC_S_FCAT.
    DATA: WA_IT_FLDCAT1 TYPE SLIS_FIELDCAT_ALV.
    DATA: GP_TABLE TYPE REF TO DATA.
    DATA: WA_NEWLINE TYPE REF TO DATA.
    *DECLARATION FOR CONSTANTS
    CONSTANTS:
       BEGIN OF GC,
         TDID_GRUN     TYPE THEAD-TDID     VALUE 'GRUN',
         TDOBJECT_MAT  TYPE THEAD-TDOBJECT VALUE 'MATERIAL',
         ON(01)        TYPE C              VALUE 'X',
         YES(01)       TYPE C              VALUE 'X',
         TXT(25)       TYPE C              VALUE 'MATERIAL DETAILS',
         MAT(25)       TYPE C              VALUE 'MATERIAL NUMBER',
         AUT(25)       TYPE C              VALUE 'AUTHORIZATION GROUP',
         FOUND         TYPE SY-SUBRC       VALUE '00',  " Return-Code
         RC_OK         TYPE SY-SUBRC       VALUE '00',  " Return-Code
         OFF           TYPE SY-SUBRC       VALUE '00',  " return code
         FALSE         TYPE SY-SUBRC       VALUE '00',  " boolean
         TRUE          TYPE SY-SUBRC       VALUE '01',  " boolean
      END OF GC.
    * DECLARATION FOR VARIABLES
    DATA: V(3) TYPE N,
          STR TYPE STRING,
          STR1 TYPE STRING,
          V_VAR(3) TYPE N,
          V_VAR1(3) TYPE N,
          V_FIELDNAME(15) TYPE C,
          V_CHAR(15) TYPE C,
          V_LINES(3) TYPE N,
          MAKTEXT LIKE MAKT-MAKTX,
          LT_DATA        TYPE   REF TO DATA,
          LT_DATA1        TYPE   REF TO DATA,
          LWA_LINE       TYPE   REF TO  DATA,
          LWA_LINE1 TYPE REF TO DATA.
    *SELECTION-SCREEN AND PARAMETERS
    SELECTION-SCREEN: BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-002.
    SELECT-OPTIONS:
    S_MATNR FOR MARA-MATNR,  "MATERIAL NUMBER
    S_MTART FOR MARA-MTART,  "MATERIAL TEXT
    S_LANG FOR MAKT-SPRAS.   "LANGUAGE
    PARAMETER: GP_SIZE TYPE I DEFAULT 200. "DATA LENGTH
    SELECTION-SCREEN: END OF BLOCK A1.
    * AT SELECTION SCREEN
    AT SELECTION-SCREEN.
      IF GP_SIZE < 0.
        MESSAGE E002(00).
      ENDIF.
      IF GP_SIZE > 50000.
        MESSAGE W130(26) WITH TEXT-004.
        SET CURSOR FIELD 'gp_size'.
      ENDIF.
    * INITIALIZATION
    INITIALIZATION.
      GV-REPID = SY-REPID.
    *START-OF-SELECTION
    START-OF-SELECTION.
      PERFORM GET_MARA_DATA
                TABLES
                  GT_TEXT_OUTPUT_LINE
                USING
                  S_MATNR[]
                  S_MTART[]
                  GP_SIZE
                CHANGING
                  GV-RETCO
      PERFORM GET_MAT_TEXT
                 TABLES
                   GT_MAKT
                   GT_TEXT_OUTPUT_LINE
                   GT_THEAD
                   GT_LINETAB
                 USING
                   GC
                   GV-RETCO
                 CHANGING
                   GV_TEXT_OUTPUT_LINE
                   GV_MAKT
      PERFORM GET_LANG.
      PERFORM DYNAMIC_TABLES.
      PERFORM POPULATE_FINAL_TABLE.
      PERFORM POPULATE_DYNAMIC_TABLE.
    * END-OF-SELECTION
    END-OF-SELECTION.
      PERFORM DATA_OUTPUT.
    *&      Form  get_mara_data
    *       Materialdaten lesen
    *      <->ct_gt_text_output_line  Ausgabetabelle
    *      -->it_s_matnr  Parameter Materialnummer
    *      -->it_s_mtart  Parameter Materialart
    *      -->if_gp_size  Parameter Anzahl Materialnummern
    FORM GET_MARA_DATA  TABLES   CT_GT_TEXT_OUTPUT_LINE STRUCTURE
                                       GV_TEXT_OUTPUT_LINE
                        USING    IT_S_MATNR LIKE S_MATNR[]
                                 IT_S_MTART LIKE S_MTART[]
                                 IF_GP_SIZE
                        CHANGING IF_GV-RETCO.                   "#EC *
    * MARA in die Übergabestruktur einlesen
      SELECT MATNR BEGRU
            FROM MARA UP TO IF_GP_SIZE ROWS
            APPENDING CORRESPONDING FIELDS OF TABLE GT_MATNR
                     WHERE MATNR IN IT_S_MATNR
                       AND MTART IN IT_S_MTART.
      IF_GV-RETCO = SY-SUBRC.
    ENDFORM.                    " get_mara_data
    *&      Form  get_mat_text
    *       Kurz- und Langtexte zum Material lesen
    *      <->ct_gt_makt              Materialkurztexte
    *      <->ct_gt_text_output_line  Ausgabetabelle
    *      <->ct_gt_thead             Kopftabelle für ALV
    *      <->ct_gt_linetab           Zeilentabelle für ALV
    *      -->if_gc                   Globale Konstanten
    *      <--cf_gv_text_output_line  Struktur Ausgabetabelle
    *      <--cf_gv_makt              Struktru Materialkurztexte
    FORM GET_MAT_TEXT  TABLES   CT_GT_MAKT             STRUCTURE MAKT
                                CT_GT_TEXT_OUTPUT_LINE STRUCTURE
                                                    GV_TEXT_OUTPUT_LINE
                                CT_GT_THEAD            STRUCTURE THEAD
                                CT_GT_LINETAB          STRUCTURE TLINE
                       USING
                                IF_GC                  LIKE GC
                                IF_GV-RETCO
                       CHANGING CF_GV_TEXT_OUTPUT_LINE LIKE
                                                       GV_TEXT_OUTPUT_LINE
                                CF_GV_MAKT             LIKE GV_MAKT
      DATA: STRG TYPE STRING,
            STRG1(1255) TYPE C.
      IF IF_GV-RETCO = IF_GC-FOUND.
    * Materialkurztexte in alles Sprachen einlesen
        SELECT * FROM MAKT APPENDING TABLE CT_GT_MAKT
                 FOR ALL ENTRIES IN GT_MATNR "ct_gt_text_output_line
                 WHERE MATNR = GT_MATNR-MATNR " ct_gt_text_output_line-matnr
    * Kurztexte in die sprachabhängigen Felder bringen
        LOOP AT GT_MATNR INTO WA_GT_MATNR.
          LOOP AT CT_GT_MAKT INTO CF_GV_MAKT
                 WHERE MATNR = WA_GT_MATNR-MATNR.
            CF_GV_TEXT_OUTPUT_LINE-MATNR = WA_GT_MATNR-MATNR.
            CF_GV_TEXT_OUTPUT_LINE-BEGRU = WA_GT_MATNR-BEGRU.
            CF_GV_TEXT_OUTPUT_LINE-MAKTX = CF_GV_MAKT-MAKTX.
            CF_GV_TEXT_OUTPUT_LINE-SPRAS = CF_GV_MAKT-SPRAS.
    * LANGTEXT
            CLEAR CT_GT_THEAD[].
            CT_GT_THEAD-TDOBJECT = IF_GC-TDOBJECT_MAT.
            CT_GT_THEAD-TDNAME   = WA_GT_MATNR-MATNR.
            CT_GT_THEAD-TDID     = IF_GC-TDID_GRUN.
            CT_GT_THEAD-TDSPRAS  = CF_GV_MAKT-SPRAS.
            CALL FUNCTION 'TEXT_READ'
              EXPORTING
                I_HEADER   = CT_GT_THEAD
                I_READONLY = IF_GC-ON
              IMPORTING
                E_HEADER   = CT_GT_THEAD
              TABLES
                T_LINES    = CT_GT_LINETAB[]
              EXCEPTIONS
                NOTFOUND   = 1.
            IF SY-SUBRC = IF_GC-FOUND.
              LOOP AT  CT_GT_LINETAB.
                STRG = CT_GT_LINETAB-TDLINE.
                IF STRG1 <> ' '.
                  CONCATENATE STRG1 ';' STRG INTO STRG1.
                ELSE.
                  STRG1 = STRG.
                ENDIF.
              ENDLOOP.
              CF_GV_TEXT_OUTPUT_LINE-LTXT40 = STRG1.
              APPEND CF_GV_TEXT_OUTPUT_LINE TO CT_GT_TEXT_OUTPUT_LINE.
              CLEAR CF_GV_TEXT_OUTPUT_LINE.
              STRG1 = ' '.
            ELSE.
              APPEND CF_GV_TEXT_OUTPUT_LINE TO CT_GT_TEXT_OUTPUT_LINE.
            ENDIF.
          ENDLOOP.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " get_mat_text
    *&      Form  data_output
    *       Daten mit ALV ausgeben
    *      <->ct_GT_FIELDCAT          Feldkatalog für ALV
    *      <->ct_gt_text_output_line  Ausgabetabelle
    *      -->P_GS_LAYOUT             Layout für ALV
    *      -->if_gc                   Globale Konstanten
    *      <--cf_GV_REPID             Zur Zeit aufgerufener Reportname
    *      <--cf_gv_fieldcat          Struktur Feldkatalog
    *      <--cf_gv                   Globale Variablen
    FORM DATA_OUTPUT.
      PERFORM FIELDCATBUILD.
      PERFORM LAYOUT.
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          I_CALLBACK_PROGRAM       = GV-REPID
          I_CALLBACK_PF_STATUS_SET = 'EVENT_SET_STATUS_01'
          I_CALLBACK_USER_COMMAND  = 'EVENT_USER_COMMAND'
          IS_LAYOUT                = L_LT
          IT_FIELDCAT              = T_FLDCAT1[]
        TABLES
          T_OUTTAB                 = <FS_2>
        EXCEPTIONS
          PROGRAM_ERROR            = 1
          OTHERS                   = 2.
      IF SY-SUBRC <> GC-FOUND.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " data_output
    *&      Form  fieldcatbuild
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM FIELDCATBUILD. " TABLES   ct_gt_fieldcat_in STRUCTURE gv_fieldcat.
      LOOP AT IT_FLDCAT INTO WA_IT_FLDCAT.
        WA_IT_FLDCAT1-FIELDNAME = WA_IT_FLDCAT-FIELDNAME.
        WA_IT_FLDCAT1-TABNAME =  WA_IT_FLDCAT-TABNAME.
        WA_IT_FLDCAT1-SELTEXT_L = WA_IT_FLDCAT-FIELDNAME.
        APPEND WA_IT_FLDCAT1 TO T_FLDCAT1.
        CLEAR : WA_IT_FLDCAT,WA_IT_FLDCAT1.
      ENDLOOP.
    ENDFORM.                    " fieldcatbuild
    * Form event_set_status_01*
    FORM EVENT_SET_STATUS_01 USING LT_EXCL TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'ABCD' .
    ENDFORM. "EVENT_SET_STATUS_01
    *& Form Name: event_user_command *
    *& Form Desc: For Handling USER_COMMAND *
    FORM EVENT_USER_COMMAND USING
    IF_UCOMM TYPE SY-UCOMM
    IS_SELFIELD TYPE SLIS_SELFIELD.
      CASE IF_UCOMM.
        WHEN 'DOWNLOAD'.
          PERFORM POPULATE_DOWNLOAD_TABLE.
          DATA: L_LENGHT TYPE I.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
              FILENAME              = 'C:data.xls'
              FILETYPE              = 'ASC'
              WRITE_FIELD_SEPARATOR = 'X'
              TRUNC_TRAILING_BLANKS = 'X'
              DAT_MODE              = 'X'
            IMPORTING
              FILELENGTH            = L_LENGHT
            TABLES
              DATA_TAB              = <FS_22>.
          IF SY-SUBRC <> GC-FOUND.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          IF L_LENGHT NE GC-FOUND.
            MESSAGE S398(00) WITH 'DATA downloaded to c:data.xls'.
          ENDIF.
      ENDCASE.
    ENDFORM.                    "event_user_command
    *&      Form  get_lang
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM GET_LANG.
      SELECT SPRAS
               LAISO FROM T002 INTO CORRESPONDING FIELDS OF TABLE GT_LANG
                      WHERE SPRAS IN S_LANG.
      DESCRIBE TABLE GT_LANG LINES V_LINES.
      LOOP AT GT_LANG INTO WA_GT_LANG.
        V = V + 1.
        WA_GT_LANG-SRNO = V.
        MODIFY GT_LANG FROM WA_GT_LANG TRANSPORTING SRNO.
      ENDLOOP.
      LOOP AT GT_LANG INTO WA_GT_LANG.
        CONCATENATE 'MATEDESC-' WA_GT_LANG-LAISO INTO V_FIELDNAME.
        CLEAR WA_IT_FLDCAT.
        WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
        WA_IT_FLDCAT-SELTEXT = V_FIELDNAME.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-INTLEN = 40.
        WA_IT_FLDCAT-TABNAME = '<FS_2>'.
        APPEND WA_IT_FLDCAT TO IT_FLDCAT .
        CLEAR WA_GT_LANG.
      ENDLOOP.
      LOOP AT GT_LANG INTO WA_GT_LANG.
        CONCATENATE 'BASDAT-' WA_GT_LANG-LAISO INTO V_FIELDNAME.
        CLEAR WA_IT_FLDCAT.
        WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-INTLEN = 255.
        WA_IT_FLDCAT-SELTEXT = V_FIELDNAME.
        WA_IT_FLDCAT-TABNAME = '<FS_2>'.
        APPEND WA_IT_FLDCAT TO IT_FLDCAT .
        CLEAR WA_GT_LANG.
      ENDLOOP.
      V_FIELDNAME = 'MATNR'.
      CLEAR WA_IT_FLDCAT.
      WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
      WA_IT_FLDCAT-DATATYPE = 'CHAR'.
      WA_IT_FLDCAT-SELTEXT =  'Matnr'.
      WA_IT_FLDCAT-INTLEN = 18.
      WA_IT_FLDCAT-TABNAME = '<FS_2>'.
      INSERT WA_IT_FLDCAT INTO IT_FLDCAT INDEX 1.
      V_FIELDNAME = 'BEGRU'.
      CLEAR WA_IT_FLDCAT.
      WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
      WA_IT_FLDCAT-DATATYPE = 'CHAR'.
      WA_IT_FLDCAT-SELTEXT =  'BEGRU'.
      WA_IT_FLDCAT-INTLEN = 4.
      WA_IT_FLDCAT-TABNAME = '<FS_2>'.
      INSERT WA_IT_FLDCAT INTO IT_FLDCAT INDEX 2.
    ENDFORM.                    " get_lang
    *&      Form  dynamic_tables
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM DYNAMIC_TABLES.
      ASSIGN LT_DATA TO <FS_DATA>.
    * Creating the Dynamic Internal Table
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = IT_FLDCAT      " Fieldcatalogue
        IMPORTING
          EP_TABLE                  = <FS_DATA>     " Dynamic Internal Table
        EXCEPTIONS
          GENERATE_SUBPOOL_DIR_FULL = 1
          OTHERS                    = 2.
    * Assign Dyn Table To Field Sumbol
      ASSIGN <FS_DATA>->* TO <FS_1>.
    * Assigning the Internal Table TYPE ANY to Standard internal Table
      ASSIGN <FS_1> TO <FS_2>.
    * Creating a Workarea
      CREATE DATA LWA_LINE LIKE LINE OF <FS_2> .
    * Assigning the Content to the workares as a Pointer
      ASSIGN LWA_LINE->* TO <LWA_LINE_WA>.
    ENDFORM.                    " dynamic_tables
    *&      Form  populate_final_table
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM POPULATE_FINAL_TABLE.
      LOOP AT GT_TEXT_OUTPUT_LINE INTO GV_TEXT_OUTPUT_LINE.
        READ TABLE GT_LANG INTO WA_GT_LANG
                  WITH KEY SPRAS = GV_TEXT_OUTPUT_LINE-SPRAS.
        IF SY-SUBRC EQ GC-FOUND.
          GV_TEXT_OUTPUT_LINE-SRNO = WA_GT_LANG-SRNO.
        ENDIF.
        MODIFY GT_TEXT_OUTPUT_LINE FROM GV_TEXT_OUTPUT_LINE.
      ENDLOOP.
    ENDFORM.                    " populate_final_table
    *&      Form  populate_dynamic_table
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM POPULATE_DYNAMIC_TABLE.
      DATA: INDX TYPE SY-TABIX.
      LOOP AT GT_TEXT_OUTPUT_LINE INTO GV_TEXT_OUTPUT_LINE.
        AT NEW MATNR.
          INDX = SY-TABIX.
          ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
          <F> = GV_TEXT_OUTPUT_LINE-MATNR.
          ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA> TO <F>.
          <F> = GV_TEXT_OUTPUT_LINE-BEGRU.
        ENDAT.
        LOOP AT GT_LANG INTO WA_GT_LANG.
          IF GV_TEXT_OUTPUT_LINE-SRNO = WA_GT_LANG-SRNO.
            V_VAR = GV_TEXT_OUTPUT_LINE-SRNO + 2.
            ASSIGN COMPONENT V_VAR OF STRUCTURE <LWA_LINE_WA> TO <F>.
            <F> = GV_TEXT_OUTPUT_LINE-MAKTX.
            V_VAR = GV_TEXT_OUTPUT_LINE-SRNO + V_LINES + 2.
            ASSIGN COMPONENT V_VAR OF STRUCTURE <LWA_LINE_WA> TO <F>.
            <F> = GV_TEXT_OUTPUT_LINE-LTXT40.
          ENDIF.
        ENDLOOP.
        AT END OF MATNR.
          APPEND <LWA_LINE_WA> TO <FS_2>.
          CLEAR <LWA_LINE_WA>.
        ENDAT.
      ENDLOOP.
    ENDFORM.                    " populate_dynamic_table
    *&      Form  LAYOUT
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM LAYOUT.
      CLEAR L_LT.
      L_LT-ZEBRA = GC-YES.
      L_LT-COLWIDTH_OPTIMIZE = 'X'.
      L_LT-WINDOW_TITLEBAR = GC-TXT.
    ENDFORM.                    " LAYOUT
    *&      Form  populate_download_table
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM POPULATE_DOWNLOAD_TABLE.
      ASSIGN LT_DATA1 TO <FS_DATA1>.
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = IT_FLDCAT         " Fieldcatalogue
        IMPORTING
          EP_TABLE                  = <FS_DATA1>  " Dynamic Internal table
        EXCEPTIONS
          GENERATE_SUBPOOL_DIR_FULL = 1
          OTHERS                    = 2.
    * Assign Dyn Table To Field Sumbol
      ASSIGN <FS_DATA1>->* TO <FS_11>.
    * Assigning the Internal Table TYPE ANY to Standard internal Table
      ASSIGN <FS_11> TO <FS_22>.
    * Creating a Workarea
      CREATE DATA LWA_LINE1 LIKE LINE OF <FS_22> .
    * Assigning the Content to the workares as a Pointer
      ASSIGN LWA_LINE1->* TO <LWA_LINE_WA1>.
      DATA: STRN1 TYPE STRING,
            STRN2 TYPE STRING,
            INDX TYPE SY-TABIX.
      ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
      <FA> = GC-MAT.
      ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
      <FA> = GC-AUT.
      LOOP AT GT_LANG INTO WA_GT_LANG.
        V_VAR1 = WA_GT_LANG-SRNO + 2.
        CONCATENATE 'MATERIALDESCRIPTION-'  WA_GT_LANG-LAISO INTO STRN1.
        ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = STRN1.
        V_VAR1 = WA_GT_LANG-SRNO + V_LINES + 2.
        CONCATENATE 'BASICDATA-' WA_GT_LANG-LAISO INTO STRN2.
        ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = STRN2.
      ENDLOOP.
      APPEND <LWA_LINE_WA1> TO <FS_22>.
      CLEAR <LWA_LINE_WA1>.
      APPEND <LWA_LINE_WA1> TO <FS_22>.
      V_VAR1 = 0.
      LOOP AT GT_TEXT_OUTPUT_LINE INTO GV_TEXT_OUTPUT_LINE.
        AT NEW MATNR.
          INDX = SY-TABIX.
          ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
          <FA> = GV_TEXT_OUTPUT_LINE-MATNR.
          ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
          <FA> = GV_TEXT_OUTPUT_LINE-BEGRU.
        ENDAT.
        LOOP AT GT_LANG INTO WA_GT_LANG.
          IF GV_TEXT_OUTPUT_LINE-SRNO EQ WA_GT_LANG-SRNO.
            V_VAR1 = GV_TEXT_OUTPUT_LINE-SRNO + 2.
            ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
            <FA> = GV_TEXT_OUTPUT_LINE-MAKTX.
            V_VAR1 = GV_TEXT_OUTPUT_LINE-SRNO + V_LINES + 2.
            ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
    *        STR = GV_TEXT_OUTPUT_LINE-LTXT40.
    *        SEARCH STR FOR ';'.
    *        DO.
    *          IF SY-SUBRC = 0.
    *            SPLIT STR AT ';' INTO STR1 STR.
    *            <FA> = STR1.
    *            APPEND <LWA_LINE_WA1> TO <FS_22>.
    *            SEARCH STR FOR ';'.
    *            CLEAR <LWA_LINE_WA1>.
    *          ELSE.
    *            EXIT.
    *          ENDIF.
    *        ENDDO.
    *        <FA> = STR.
    *        APPEND <LWA_LINE_WA1> TO <FS_22>.
            <FA> = GV_TEXT_OUTPUT_LINE-LTXT40.
          ENDIF.
        ENDLOOP.
        AT END OF MATNR.
          APPEND <LWA_LINE_WA1> TO <FS_22>.
          CLEAR <LWA_LINE_WA1>.
        ENDAT.
      ENDLOOP.
    ENDFORM.                    " populate_download_table
    thanks
    Nitya

  • Populating two dynamic internal tables and displaying the O/p as ALV

    I want to develop a abap prototype program report for the SD document flow analysis...
    There is a Fm : RV_ORDER_FLOW_INFORMATION in which if we pass the Sales order number it returns the flows as VBFA_TAB.
    I need to populate two dynamic ITAB1 and ITAB2
    the structure of ITAB1 should be like ColNm1....ColNmn
    The values for ColNm1 will be Sales Order ColNm2 as Delivery or smthng else depending on  field vbtyp_n.
    ITAB 2 should have the corresponding values accly to ITAB1.
    Then we need to display in ALV o/p.
    The tables should be populated dynamically.
    Can anybody throw some light on it and plz do write back with sample code to do the logic of it.

    Search in SDN with Dynamic internal tables.
    you get lot of code samples and Discussions related to Dynamic internal tables.
    you can also check with this class CL_ALV_TABLE_CREATE

  • Dynamic Internal Table with Dynamic Fields

    Hi all,
    My scenario is fairly simple----
    --> End user clicks a button on screen and he gets the list of HR tables.
    --> Then selects a table and list of all the fields for that table gets displayed.
    --> He/she selects the fields they want data to be retrieved for.
    So, the requirement is, the dynamic internal table should get created with the fields selected.
    The select statement should only retrieve fields which were selected by the end user
    and from the table selected by the end user.
    I  believe the fields selected by end user can be passed by a variable of  type string.
    something like this---
    select (fields)
    from (p_table)        " Table selected by end user
    into  dynamic internal table.   " should contain columns selected by end user"
    Appreciate your inputs and guidance.
    Warm regards,
    Hari Kiran

    TYPE-POOLS :ABAP.
    Parameters P_TAB      TYPE        DDOBJNAME.
    DATA  : GO_LINE_TYPE  TYPE REF TO CL_ABAP_STRUCTDESCR,
            GO_TABLE_DESC TYPE REF TO CL_ABAP_TABLEDESCR,
            GS_COMPONENTS TYPE        ABAP_COMPONENTDESCR,
            GT_COMPONENTS TYPE        ABAP_COMPONENT_TAB,
            GR_TAB        TYPE REF TO DATA,
            GT_FIELDS  TYPE TABLE OF DFIES WITH HEADER LINE.
    FIELD-SYMBOLS: <GT_TABLE> TYPE TABLE,
                   <GS_TABLE> TYPE ANY,
                   <GV_VALUE> TYPE ANY.
    CALL FUNCTION 'DDIF_FIELDINFO_GET'
      EXPORTING
        TABNAME              = P_TAB
    *   FIELDNAME            = ' '
    *   LANGU                = SY-LANGU
    *   LFIELDNAME           = ' '
    *   ALL_TYPES            = ' '
    *   GROUP_NAMES          = ' '
    *   UCLEN                =
    * IMPORTING
    *   X030L_WA             =
    *   DDOBJTYPE            =
    *   DFIES_WA             =
    *   LINES_DESCR          =
    TABLES
        DFIES_TAB            =  GT_FIELDS
    *   FIXED_VALUES         =
    EXCEPTIONS
       NOT_FOUND            = 1
       INTERNAL_ERROR       = 2
       OTHERS               = 3.
    IF SY-SUBRC <> 0.
    * MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    *         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    LOOP AT GT_FIELDS.
      CLEAR GS_COMPONENTS.
      GS_COMPONENTS-NAME  = GT_FIELDS-FIELDNAME.
      GS_COMPONENTS-TYPE ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_NAME( GT_FIELDS-ROLLNAME ).
      APPEND GS_COMPONENTS TO GT_COMPONENTS.
    ENDLOOP.
    GO_LINE_TYPE  = CL_ABAP_STRUCTDESCR=>CREATE( GT_COMPONENTS ).
    GO_TABLE_DESC = CL_ABAP_TABLEDESCR=>CREATE( GO_LINE_TYPE ).
    CREATE DATA:  GR_TAB TYPE HANDLE GO_TABLE_DESC.
    ASSIGN:  GR_TAB->* TO <GT_TABLE>.
    SELECT * FROM (P_TAB) APPENDING CORRESPONDING FIELDS OF TABLE <GT_TABLE>.
    LOOP AT <GT_TABLE> ASSIGNING <GS_TABLE>.
      NEW-LINE.
      DO.
        ASSIGN COMPONENT SY-INDEX OF STRUCTURE <GS_TABLE> TO <GV_VALUE>.
        IF SY-SUBRC NE '0'.
          EXIT.
        ENDIF.
        WRITE : <GV_VALUE>.
      ENDDO.
    ENDLOOP.

  • Create dynamic internal table with dynamic structure

    I have an internal table itab1 that have 12 amount fields from period1 thru period12.  I need to create a dynamic table with dynamic structure for the  period column if the total amount of each column  is > 0.  Any idea on how to do that? 
    For example if my itab1 has 20 rows and the sum of period1 = 35, sum of period2 = 0, sum of period3 = 5, sum of period4 =0, sum of period5 = 2 then I need to create a dynamic structure for the field column that have the total > 0, i.e  structure struct1 have field period1, period3 and period5 only.  Then I will need to load the data to itab2 from itab1.  Can someone help.
    Thanks.  I am on 4.7 and will upgrade to ERP 6.0 soon.

    go throgh this....
    REPORT  yusmm_text1  NO STANDARD PAGE HEADING
                         LINE-SIZE 199.
    T A B L E S
    TABLES: MARA,
            MAKT,
            THEAD.
    GLOBAL TYPE-POOLS
    TYPE-POOLS : SLIS.
       GLOBAL TYPES
    TYPES : BEGIN OF TP_FINAL,
           MATNR TYPE MARA-MATNR,
           BEGRU TYPE MARA-BEGRU,
           MTART TYPE MARA-MTART,
           MAKTX TYPE MAKT-MAKTX,
           SPRAS TYPE MAKT-SPRAS,
           LTXT(2000)  TYPE C ,
           SRNO TYPE N ,
          END OF TP_FINAL.
    TYPES : BEGIN OF TP_T002,
            SPRAS TYPE T002-SPRAS,
            LAISO TYPE T002-LAISO,
            SRNO TYPE N ,
            END OF TP_T002.
    TYPES : BEGIN OF TP_MARA_MAKT,
            MATNR TYPE MARA-MATNR,
            BEGRU TYPE MARA-BEGRU,
            MTART TYPE MARA-MTART,
            SPRAS TYPE MAKT-SPRAS,
            MAKTX TYPE MAKT-MAKTX,
           END OF TP_MARA_MAKT.
    Types: BEGIN OF tp_matnr,
           matnr TYPE mara-matnr,
           END OF tp_matnr.
       GLOBAL ELEMENTARY VARIABLES
    DATA : gv_date TYPE sy-datum.
    DATA : gv_repid TYPE sy-repid.
    DATA : g_var1(10) TYPE C.
    DATA : gv_index TYPE sy-tabix.
    DATA: gv_strg TYPE string,
          gv_strg1(2000) TYPE C.
    DATA : gv_lang TYPE sy-langu.
    DATA : g_v(3) TYPE N .
    DATA : gv_lines(3) TYPE N .
    DATA : gv_var(3) TYPE N .
    DATA : gv_var1(3) TYPE N.
    DATA: gv_str TYPE STRING.
    DATA: gv_str1 TYPE STRING.
    DATA : gv_li TYPE I,
           gv_lit TYPE I,
           gv_lin TYPE I.
    DATA: g_var11(3) TYPE N,
          gv_li1(3) TYPE N,
          g_var2(3) TYPE N.
    DATA : gv_i1 TYPE I.
    DATA : gv_i TYPE I.
    DATA: gl_lenght TYPE I.
       GLOBAL STRUCTURES
    DATA:   T_NEWTABLE TYPE REF TO DATA,
            T_NEWLINE  TYPE REF TO DATA,
            T_FLDCAT1   TYPE SLIS_T_FIELDCAT_ALV,
            T_FLDCAT   TYPE LVC_T_FCAT,
            WA_IT_FLDCAT TYPE LVC_S_FCAT,
            WA_IT_FLDCAT1 TYPE SLIS_FIELDCAT_ALV,
            WA_COLNO(2) TYPE N,
            WA_FLNAME(5) TYPE C,
            L_LT TYPE SLIS_LAYOUT_ALV.
       GLOBAL INTERNAL TABLES (WITH INCLUDE STRUCTURE)
    DATA : IG_MARA_MAKT TYPE STANDARD TABLE OF TP_MARA_MAKT,
           WG_MARA_MAKT TYPE TP_MARA_MAKT.
    DATA : IG_T002 TYPE STANDARD TABLE OF TP_T002,
           WG_T002 TYPE TP_T002.
    DATA : IG_FINAL TYPE STANDARD TABLE OF TP_FINAL,
           WG_FINAL TYPE TP_FINAL.
    data : IG_MATNR TYPE STANDARD TABLE OF TP_MATNR WITH HEADER  LINE,
           WG_MATNR TYPE TP_MATNR.
    DATA:BEGIN OF IG_THEAD OCCURS 0.
            INCLUDE STRUCTURE THEAD .
    DATA: END OF IG_THEAD.
    DATA:BEGIN OF IG_TLINE OCCURS 0.
            INCLUDE STRUCTURE TLINE  .
    DATA:END OF IG_TLINE.
    FIELD-SYMBOLS
    FIELD-SYMBOLS: <T_DYNTABLE> TYPE STANDARD TABLE,"Dynamic internal
                                                            "tablename
                   <FS_DYNTABLE>,  "Field symbol to create work area
                  <FS_FLDVAL> TYPE ANY.   " Field symbol to assign values
    COMPULSORY
    FIELD-SYMBOLS: <FS_DATA> TYPE REF TO DATA,
                   <FS_DATA1> TYPE REF TO DATA,
                   <FS_2>    TYPE STANDARD TABLE,
                   <FS_22>   TYPE STANDARD TABLE,
                   <FS_1>,
                   <FS_11>,
                   <F>,
                   <FA>,
                   <LWA_LINE_WA>,
                   <LWA_LINE_WA1>.
    ------- Create Dyn Table From FC
    DATA: LT_DATA        TYPE   REF TO DATA,
          LT_DATA1        TYPE   REF TO DATA,
          LWA_LINE       TYPE   REF TO  DATA,
          LWA_LINE1       TYPE   REF TO  DATA,
          LI_FIELD_CAT   TYPE   LVC_T_FCAT,
          LWA_FIELD_CAT  TYPE   LVC_S_FCAT.
       PARAMETERS & SELECT-OPTIONS
    SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS : S_SPRAS FOR MAKT-SPRAS NO INTERVALS  DEFAULT 'EN'
                                                            OBLIGATORY ,
                     S_MATNR FOR MARA-MATNR,
                     S_MTART FOR MARA-MTART.
    PARAMETERS: GP_SIZE TYPE I DEFAULT '200'.
    SELECTION-SCREEN : END OF BLOCK B1.
       INITIALIZATION
    INITIALIZATION.
      gv_repid = sy-repid.
      gv_date = sy-datum.
    AT SELECTION-SCREEN
    AT SELECTION-SCREEN.
      IF GP_SIZE < 0.
       MESSAGE E002(00).
      ENDIF.
      IF GP_SIZE > 50000.
       MESSAGE W130(26) WITH TEXT-004.
        SET CURSOR FIELD 'gp_size'.
      ENDIF.
    START-OF-SELECTION
    START-OF-SELECTION.
      PERFORM FIELDCAT.
      PERFORM LAYOUT.
      PERFORM DATA_FETCH.
      PERFORM READ_DATA_TO_FINAL.
      SORT ig_final BY matnr spras.
      gv_lin = gv_li.
      gv_li = gv_li - 2.
      LOOP AT ig_final INTO wg_final.
        ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'Material Number'.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'Authorization Group'.
        g_VAR11 = wg_final-srno + 2.
        gv_li1 = gv_li1 + 2.
        MOVE : g_var11 TO gv_i1.
        ASSIGN COMPONENT g_var11 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'MatDesc'.
        g_var2 = g_var11 + gv_lines.
        ASSIGN COMPONENT g_var2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'BasicData'.
        APPEND <LWA_LINE_WA1> TO <FS_22>.
        EXIT.
       ENDLOOP.
      LOOP AT ig_final INTO wg_final.
        AT NEW matnr.
          gv_index = sy-tabix.
          ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
          <F> = wg_final-matnr.
          ENDAT.
        AT NEW MATNR.
        GV_INDEX = SY-TABIX.
        ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-matnr.
         ENDAT.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA> TO <F>.
        <F> = wg_final-begru.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-begru.
        gv_var = wg_final-srno + 2.
        gv_li = gv_li + 2.
        MOVE : gv_var TO gv_i.
        ASSIGN COMPONENT gv_var OF STRUCTURE <LWA_LINE_WA> TO <F>.
        <F> = wg_final-maktx.
        ASSIGN COMPONENT gv_var OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-maktx.
        gv_var1 = gv_var + gv_lines  .
        ASSIGN COMPONENT gv_var1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
       <F> = wg_final-ltxt.
        ASSIGN COMPONENT gv_var1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-ltxt.
        AT END OF matnr.
          APPEND <LWA_LINE_WA> TO <FS_2>.
          CLEAR <LWA_LINE_WA>.
        ENDAT.
        AT END OF matnr.
         APPEND <LWA_LINE_WA1> TO <FS_22>.
         CLEAR <LWA_LINE_WA1>.
        ENDAT.
      ENDLOOP.
      PERFORM display..
    *&      Form  data_fetch
          text
    -->  p1        text
    <--  p2        text
    FORM DATA_FETCH .
      SELECT matnr
              from mara up to gp_size rows
             appending corresponding fields of table ig_matnr
             where matnr in s_matnr
             and mtart in s_mtart.
    loop at ig_matnr.
      SELECT  MARA~MATNR
              MARA~BEGRU
              MARA~MTART
              MAKT~SPRAS
              MAKT~MAKTX FROM MARA INNER JOIN MAKT
        ON MARAMATNR = MAKTMATNR
       appending corresponding fields of TABLE ig_mara_makt  UP TO GP_SIZE
    ROWS
        WHERE makt~spras IN s_spras
        AND   mara~matnr IN s_matnr
        AND   mara~mtart IN s_mtart
        AND   mara~matnr EQ ig_matnr-matnr.
        endloop.
      IF sy-subrc = 0.
        SORT ig_mara_makt.
      ENDIF.
    ENDFORM.                    " data_fetch
    *&      Form  read_data_to_final
          text
    -->  p1        text
    <--  p2        text
    FORM READ_DATA_TO_FINAL .
      LOOP AT ig_mara_makt INTO wg_mara_makt .
        wg_final-MATNR = wg_mara_makt-MATNR.
        wg_final-BEGRU = wg_mara_makt-BEGRU.
        wg_final-MTART = wg_mara_makt-MTART.
        wg_final-SPRAS = wg_mara_makt-SPRAS.
        wg_final-MAKTX = wg_mara_makt-MAKTX.
        READ TABLE ig_t002 INTO wg_t002 WITH KEY spras = wg_final-spras.
        IF sy-subrc = 0.
          wg_final-srno = wg_t002-srno.
        ENDIF.
        CLEAR ig_thead[].
        ig_thead-TDOBJECT = 'MATERIAL'.
        ig_thead-TDNAME   = wg_final-matnr.
        ig_thead-TDID     = 'GRUN'.
        ig_thead-TDSPRAS  = wg_final-spras.
        CALL FUNCTION 'TEXT_READ'
          EXPORTING
            I_HEADER   = IG_THEAD
            I_READONLY = 'X'
          IMPORTING
            E_HEADER   = IG_THEAD
          TABLES
            T_LINES    = IG_TLINE[]
          EXCEPTIONS
            NOTFOUND   = 1.
        IF sy-subrc  EQ 0.
          LOOP AT  ig_tline.
            gv_strg = ig_tline-tdline.
            IF gv_strg1 <> ' '.
              CONCATENATE gv_strg1 ';' gv_strg INTO gv_strg1.
            ELSE.
              gv_strg1 = gv_strg.
            ENDIF.
          ENDLOOP.
          wg_final-ltxt = gv_strg1.
          APPEND wg_final TO ig_final.
          CLEAR wg_final.
          gv_strg1 = ' '.
        ELSE.
          APPEND wg_final TO  ig_final.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " read_data_to_final
    " read_data_to_final
    *&      Form  layout
          text
    -->  p1        text
    <--  p2        text
    FORM LAYOUT .
      CLEAR L_LT.
      L_LT-ZEBRA = 'X'.
      L_LT-COLWIDTH_OPTIMIZE = 'X'.
      L_LT-WINDOW_TITLEBAR = 'MATERIAL DETAILS'.
    ENDFORM.                    " layout
    *&      Form  fieldcat
          text
    -->  p1        text
    <--  p2        text
    FORM FIELDCAT .
      SELECT SPRAS
               LAISO FROM t002 INTO  CORRESPONDING FIELDS OF TABLE ig_t002
          WHERE spras IN s_spras.
      DESCRIBE TABLE ig_t002 LINES gv_lines.
      LOOP AT ig_t002 INTO wg_t002.
        g_v = g_v + 1.
        Wg_t002-srno = g_v.
        MODIFY ig_t002 FROM wg_t002 TRANSPORTING SRNO.
      ENDLOOP.
      LOOP AT ig_t002 INTO wg_t002.
        CLEAR WA_IT_FLDCAT.
        MOVE SY-INDEX TO WA_COLNO.
        CONCATENATE 'MD-' wg_t002-LAISO
                          WA_COLNO
                         INTO WA_FLNAME.
        WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-SELTEXT = WA_FLNAME.
        WA_IT_FLDCAT-INTLEN = 250.
        WA_IT_FLDCAT-TABNAME = '<FS_2>'.
        APPEND WA_IT_FLDCAT TO T_FLDCAT.
        CLEAR wg_t002.
        ENDLOOP.
      LOOP AT ig_t002 INTO wg_t002.
        CLEAR WA_IT_FLDCAT.
        MOVE SY-INDEX TO WA_COLNO.
        CONCATENATE 'BD-' wg_t002-LAISO
                           WA_COLNO
                        INTO WA_FLNAME.
        WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-SELTEXT = WA_FLNAME.
        WA_IT_FLDCAT-INTLEN = 250.
        WA_IT_FLDCAT-TABNAME = '<FS_2>'.
        APPEND WA_IT_FLDCAT TO T_FLDCAT.
        CLEAR wg_t002.
        ENDLOOP.
      MOVE 'MATNR' TO WA_FLNAME.
      WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
      WA_IT_FLDCAT-DATATYPE = 'CHAR'.
      WA_IT_FLDCAT-SELTEXT = 'Material No'.
      WA_IT_FLDCAT-INTLEN = 18.
      WA_IT_FLDCAT-TABNAME = '<FS_2>'.
      INSERT WA_IT_FLDCAT INTO T_FLDCAT INDEX 1.
      MOVE 'BEGRU' TO WA_FLNAME.
      WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
      WA_IT_FLDCAT-DATATYPE = 'CHAR'.
      WA_IT_FLDCAT-SELTEXT = 'Authorization Group'.
      WA_IT_FLDCAT-INTLEN = 4.
      WA_IT_FLDCAT-TABNAME = '<FS_2>'.
      INSERT WA_IT_FLDCAT INTO T_FLDCAT INDEX 2.
      DESCRIBE TABLE T_FLDCAT LINES gv_li.
      ASSIGN LT_DATA TO <FS_DATA>.
    Creating the Dynamic Internal Table
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = T_FLDCAT         " Fieldcatalogue
        IMPORTING
          EP_TABLE                  = <FS_DATA>   " Dynamic Internal Table
        EXCEPTIONS
          GENERATE_SUBPOOL_DIR_FULL = 1
          OTHERS                    = 2.
    Assign Dyn Table To Field Sumbol
      ASSIGN <FS_DATA>->* TO <FS_1>.
    Assigning the Internal Table TYPE ANY to Standard internal Table
      ASSIGN <FS_1> TO <FS_2>.
    Creating a Workarea
      CREATE DATA LWA_LINE LIKE LINE OF <FS_2> .
    Assigning the Content to the workares as a Pointer
      ASSIGN LWA_LINE->* TO <LWA_LINE_WA>.
      LOOP AT T_FLDCAT INTO WA_IT_FLDCAT.
        WA_IT_FLDCAT1-FIELDNAME = WA_IT_FLDCAT-FIELDNAME.
        WA_IT_FLDCAT1-TABNAME =  WA_IT_FLDCAT-TABNAME.
        WA_IT_FLDCAT1-SELTEXT_L = WA_IT_FLDCAT-SELTEXT.
       WA_IT_FLDCAT1-REF_TABNAME = 'MARC'.
        APPEND WA_IT_FLDCAT1 TO T_FLDCAT1.
        CLEAR : WA_IT_FLDCAT,WA_IT_FLDCAT1.
      ENDLOOP.
      ASSIGN LT_DATA1 TO <FS_DATA1>.
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = T_FLDCAT         " Fieldcatalogue
        IMPORTING
          EP_TABLE                  = <FS_DATA1>  " Dynamic Internal table
        EXCEPTIONS
          GENERATE_SUBPOOL_DIR_FULL = 1
          OTHERS                    = 2.
    Assign Dyn Table To Field Sumbol
      ASSIGN <FS_DATA1>->* TO <FS_11>.
    Assigning the Internal Table TYPE ANY to Standard internal Table
      ASSIGN <FS_11> TO <FS_22>.
    Creating a Workarea
      CREATE DATA LWA_LINE1 LIKE LINE OF <FS_22> .
    Assigning the Content to the workares as a Pointer
      ASSIGN LWA_LINE1->* TO <LWA_LINE_WA1>.
    ENDFORM.                    " fieldcat
    *&      Form  show
          text
    -->  p1        text
    <--  p2        text
    FORM Display .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
       I_INTERFACE_CHECK                 = ' '
       I_BYPASSING_BUFFER                = ' '
       I_BUFFER_ACTIVE                   = ' '
         I_CALLBACK_PROGRAM                = GV_REPID
        I_CALLBACK_PF_STATUS_SET          = 'PF_STATUS_SET'
        I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
       I_CALLBACK_TOP_OF_PAGE            = ' '
       I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
       I_CALLBACK_HTML_END_OF_LIST       = ' '
       I_STRUCTURE_NAME                  =
       I_BACKGROUND_ID                   = ' '
       I_GRID_TITLE                      =
       I_GRID_SETTINGS                   =
        IS_LAYOUT                         = L_LT
         IT_FIELDCAT                       = T_FLDCAT1[]
       IT_EXCLUDING                      =
       IT_SPECIAL_GROUPS                 =
       IT_SORT                           =
       IT_FILTER                         =
       IS_SEL_HIDE                       =
       I_DEFAULT                         = 'X'
       I_SAVE                            = ' '
       IS_VARIANT                        =
       IT_EVENTS                         =
       IT_EVENT_EXIT                     =
       IS_PRINT                          =
       IS_REPREP_ID                      =
       I_SCREEN_START_COLUMN             = 0
       I_SCREEN_START_LINE               = 0
       I_SCREEN_END_COLUMN               = 0
       I_SCREEN_END_LINE                 = 0
       I_HTML_HEIGHT_TOP                 = 0
       I_HTML_HEIGHT_END                 = 0
       IT_ALV_GRAPHICS                   =
       IT_HYPERLINK                      =
       IT_ADD_FIELDCAT                   =
       IT_EXCEPT_QINFO                   =
       IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
       E_EXIT_CAUSED_BY_CALLER           =
       ES_EXIT_CAUSED_BY_USER            =
        TABLES
          T_OUTTAB                          = <FS_2>
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " display
    FORM PF_STATUS_SET USING RS_EXTAB TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'DISPLAY' .
    ENDFORM. "PF_STATUS_SET
    *& Form Name: user_command *
    *& Form Desc: For Handling USER_COMMAND *
    FORM USER_COMMAND USING IF_UCOMM TYPE SY-UCOMM
                         IS_SELFIELD TYPE SLIS_SELFIELD.
      CASE IF_UCOMM.
        WHEN 'DOWNLOAD'.
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
      TITLEBAR                    = ' '
      DIAGNOSE_OBJECT             = ' '
              TEXT_QUESTION               = 'Data download to excel'
      TEXT_BUTTON_1               = 'Ja'(001)
      ICON_BUTTON_1               = ' '
      TEXT_BUTTON_2               = 'Nein'(002)
      ICON_BUTTON_2               = ' '
      DEFAULT_BUTTON              = '1'
      DISPLAY_CANCEL_BUTTON       = 'X'
      USERDEFINED_F1_HELP         = ' '
      START_COLUMN                = 25
      START_ROW                   = 6
      POPUP_TYPE                  =
    IMPORTING
      ANSWER                      =
    TABLES
      PARAMETER                   =
    EXCEPTIONS
      TEXT_NOT_FOUND              = 1
      OTHERS                      = 2
          IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
        BIN_FILESIZE                  =
              FILENAME                     = 'C:\Material-Text.xls'
             FILETYPE                      = 'ASC'
        APPEND                        = ' '
         WRITE_FIELD_SEPARATOR         = 'X'
        HEADER                        = '00'
         TRUNC_TRAILING_BLANKS         = 'X'
        WRITE_LF                      = 'X'
        COL_SELECT                    = ' '
        COL_SELECT_MASK               = ' '
         DAT_MODE                      = 'X'
       IMPORTING
         FILELENGTH                    = GL_LENGHT
            TABLES
              DATA_TAB                      = <FS_22>
      EXCEPTIONS
        FILE_WRITE_ERROR              = 1
        NO_BATCH                      = 2
        GUI_REFUSE_FILETRANSFER       = 3
        INVALID_TYPE                  = 4
        NO_AUTHORITY                  = 5
        UNKNOWN_ERROR                 = 6
        HEADER_NOT_ALLOWED            = 7
        SEPARATOR_NOT_ALLOWED         = 8
        FILESIZE_NOT_ALLOWED          = 9
        HEADER_TOO_LONG               = 10
        DP_ERROR_CREATE               = 11
        DP_ERROR_SEND                 = 12
        DP_ERROR_WRITE                = 13
        UNKNOWN_DP_ERROR              = 14
        ACCESS_DENIED                 = 15
        DP_OUT_OF_MEMORY              = 16
        DISK_FULL                     = 17
        DP_TIMEOUT                    = 18
        FILE_NOT_FOUND                = 19
        DATAPROVIDER_EXCEPTION        = 20
        CONTROL_FLUSH_ERROR           = 21
        OTHERS                        = 22
          IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          IF GL_LENGHT NE 0.
            MESSAGE S398(00) WITH 'DATA downloaded to EXCEL'.
          ENDIF.
      ENDCASE.
    ENDFORM.                    "user_command
    Thanks

  • Some help needed on dynamic internal tables and field symbols

    Hi,
    I have a dyn internal table <dyn_table_r>.
    One of its fields is kna1-kunnr.
    I have another wa <fs>, with only one field alt_kunnr.
    now i want to modify  the data of <dyn_table_r>-kna1-kunnr from <fs>-alt_kunnr
    How should i do it?
    Regards ,
    Harshit Rungta

    Harshit Rungta:
    You have opened a number of related questions today. I'd like to see the other ones closed before you continue with this one.
    I'll lock this but will re-open it once the others are marked as solved.
    Rob

  • Dynamic internal table with dynamic header

    Hi Members,
    I have created a dynamic report ie In the selection screen i will give set of GL accounts.
    Based on the GL it will separate a col like Sales GL, PF GL , Discount Gl etc. In the header portion  first 3 col is constant ie it  will show the vendor name and material and text remaining col is based on the GL entered in the screen it will cumulate the Total Amount and display accordingly.
    This is working fine in ALV grid display, but i required to download the data to excel , while downloading to excel i am getting only the values without header,
    ie title of the each col not getting . kindly guide me to solve this issue.
    If i entered only sales GLs (100,101,102 ) then  my output should be
    vendor   material    mateial text   100       101      102
    ddddd    11100       Raw salt      2000    1000     2500
    Regards,
    Mee.S

    Hi Meenakshi,
    As per my knowledge two ways of doing it...
    1. when u get the final internal table..check for the fields with not initial...again update the header internal table dynamically..
    2. if you get GL or PF or any such thing you can hardcode the header and display it on to excel..
    Regards,
    Vamshi

  • Modify dynamic internal table from dynamic work area using index...

    ASSIGN w_text TO <fs>.
        ASSIGN w_temp TO <fs1>.
        lint_tab_iw49[] = <tab>.
        lint_tab_iw49_t[] = <tab>.
        DELETE ADJACENT DUPLICATES FROM lint_tab_iw49 COMPARING aufnr.
        LOOP AT lint_tab_iw49 INTO lws_tab_iw49.
          READ TABLE lint_object_tab1 INTO lws_object_tab1
                        WITH KEY aufnr = lws_tab_iw49-aufnr.
          IF sy-subrc EQ 0.
    Collect operations in rows of an internal table.
            w_idx = 1.
            WHILE w_idx < 51.
              w_nn = w_idx.
              CONCATENATE 'lws_object_tab1-ZZOPERN' w_nn INTO w_xx.
              ASSIGN (w_xx) TO <fs>.
              CONCATENATE w_text <fs> INTO w_text SEPARATED BY ','.
              w_idx = w_idx + 1.
            ENDWHILE.
    Split operations into an internal table to get operations in rows.
            SPLIT w_text AT ',' INTO TABLE lint_vornr.
            DELETE lint_vornr WHERE vornr = ' '.
            DESCRIBE TABLE lint_vornr LINES w_lines.
    Collect costs in rows of an internal table
            CLEAR: w_idx, w_nn, w_xx, w_text.
            w_idx = 1.
            WHILE w_idx < 51.
              w_nn = w_idx.
              CONCATENATE 'lws_object_tab1-ZZCOST' w_nn INTO w_xx.
              ASSIGN (w_xx) TO <fs>.
              <fs1> = <fs>.
              CONCATENATE w_text <fs1> INTO w_text SEPARATED BY ','.
              w_idx = w_idx + 1.
            ENDWHILE.
    Split costs into an internal table to get costs in rows.
            SPLIT w_text AT ',' INTO TABLE lint_escost.
            DELETE lint_escost WHERE cost = ' '.
            DESCRIBE TABLE lint_escost LINES w_lines_cost.
           Append lines of lint_escost from 1 to w_lines to lint_escost1.
    Collect currencies in rows of an internal table
            CLEAR: w_idx, w_nn, w_xx, w_text.
            w_idx = 1.
            WHILE w_idx < 51.
              w_nn = w_idx.
              CONCATENATE 'lws_object_tab1-ZZCURR' w_nn INTO w_xx.
              ASSIGN (w_xx) TO <fs>.
              <fs1> = <fs>.
              CONCATENATE w_text <fs1> INTO w_text SEPARATED BY ','.
              w_idx = w_idx + 1.
            ENDWHILE.
    Split costs into an internal table to get costs in rows.
            SPLIT w_text AT ',' INTO TABLE lint_curr.
            DELETE lint_curr WHERE curr = ' '.
            DESCRIBE TABLE lint_curr LINES w_lines_curr.
           Append lines of lint_curr from 1 to w_lines to lint_curr1.
          ENDIF.
          PERFORM update_object_tab_for_iw49n.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " modify_object_tab
    *&      Form  update_object_tab_for_IW49N
          text
    -->  p1        text
    <--  p2        text
    FORM update_object_tab_for_iw49n .
      DATA: lws_temp TYPE string VALUE 'where aufnr = lws_tab_iw49-aufnr',
            lw_index TYPE sy-index.
      READ TABLE <tab> TRANSPORTING NO FIELDS WITH KEY ('AUFNR') =
      lws_tab_iw49-aufnr.
      IF sy-subrc EQ 0.
        lw_index = sy-tabix.
        LOOP AT <tab> INTO <wa1> FROM lw_index.
          IF <wa1>-aufnr NE lws_tab_iw49-aufnr.
            EXIT.
          ELSE.
            CLEAR lw_index.
           lw_index = sy-tabix.
            lw_index = 1.
            WHILE lw_index LE w_lines.
              READ TABLE lint_escost INTO lws_escost INDEX lw_index.
              IF sy-subrc EQ 0.
             lw_index = lw_index + 1.
                <wa1>-zzcost1 = lws_escost-cost.
              ENDIF.
              READ TABLE lint_curr1 INTO lws_curr INDEX lw_index.
              IF sy-subrc EQ 0.
                <wa1>-zzcurr1 = lws_curr-curr.
              ENDIF.
              MODIFY <tab> FROM <wa1> "TRANSPORTING ('ZZCOST1') ('ZZCURR1')
                        INDEX sy-tabix.
              IF sy-subrc EQ 0.
              ENDIF.
              lw_index = lw_index + 1.
            ENDWHILE.
          ENDIF.
        ENDLOOP.
      ENDIF. 
    ENDFORM.                    " update_object
    Hi,
    With referene to the code snippet above I want to modify <tab> from <wa1> on specific indices or with specific where condition.
    Is it achievable... How?
    Many thanks in advance.
    Thanks & Regards,
    Shreya

    You might have to split the code in to two parts to keep the formatting intact.

  • Alv grid using dynamic internal table

    hi i have an internal table
    begin of itab
    equipno like equi-equnr,
    reading like imrg-readg
    uom like imrg-uom
    date like imrg-date
    end of itab.
    and many more fields  in this table the reading, date, uom are dynamic its not fixed there can be five readings and 6 reading etc
    if i get all the data populated into final table  itab. how to display it throgh the alv grid
    i can use fieldsymbols i have seen some documents i want to know how to populate the fieldname s of the dynamic internal table to the field catalog and the values of the dynamic internal table .its a alv grid display pls guide

    Hi,
    Before displaying the records in ALV, you integrate all the fields (Fixed fields as well as variable fields) into one table. To do so you need create one dynamic table. If you already created this dynamic table then in the same way (same sequence) you need to populate the field catalog and use normal FM REUSE_ALV_GRID_DISPLAY to display it.
    If you not aware of how to create this dynamic internal table, please check the below way.
    1. Populate the fixed field into one field catalog(NB. this to create dyn table not ALV).
    *--- Cons Unit
      wa_lvc_cat-fieldname = c_cons.       
      wa_lvc_cat-ref_field = c_rbunit.      
      wa_lvc_cat-ref_table = c_ecmca.   
      append wa_lvc_cat to it_lvc_cat.    
    *--- account description
      wa_lvc_cat-fieldname = c_acctd.
      wa_lvc_cat-ref_field = c_txtmi.
      wa_lvc_cat-ref_table = c_tf101.
      append wa_lvc_cat to it_lvc_cat.
    2. For variable fields you have your own logic based on which you need to display the output. (like loop at one table and make each field as one column). Here one thing need to make sure every time field name should be different. You know in one structure there are 2 fields with same name is not allowed.
    3. next use the below method to create the internal table
    Create a new Table
      call method cl_alv_table_create=>create_dynamic_table
        exporting
          it_fieldcatalog = it_lvc_cat
        importing
          ep_table        = it_new_table.
    Create a new Line with the same structure of the table.
      assign it_new_table->* to <l_table>. " internal table
      create data wa_new_line like line of <l_table>.
      assign wa_new_line->* to <l_line>.  " Work area
    4. To populate the field catalog for ALV use the same sequence. Better while you populated it_lvc_cat for dynamic table also create one lookup table with three fields. (fieldname, Text, col_pos). Here loop into this look up table and populate the ALV field catalog.
    5. Display it using REUSE_ALV_GRID_DISPLAY
    call function 'REUSE_ALV_GRID_DISPLAY'
        exporting
          i_callback_program      = c_rep_name
          i_callback_user_command = 'F_USER_DOUBLE_CLICK'       "SD0K963313
          is_layout               = l_wa_layout
          it_fieldcat             = it_fieldcat
          it_sort                 = it_sort
          i_save                  = l_save
          is_variant              = wa_variant1
          it_events               = it_events
        tables
          t_outtab                = <l_table>
        exceptions
          program_error           = 1
          others                  = 2.
    Thanks
    Subhankar

  • Internal table with Dynamic and Non dynamic fileds

    Hi Experts,
    How to get the internal table with Dynamic and Non-Dynamic Fields.
    Could u please help me.
    Thanks,
    Varun

    Hi,
       Execute the below sample code or analyze it there is appropriate description provided.
    *& Report  ZTEST_PRM_DYN_ALV
    REPORT  ZTEST_PRM_DYN_ALV.
    type-pools: slis.
    field-symbols: <dyn_table> type standard table,
    <dyn_wa>.
    data: alv_fldcat type slis_t_fieldcat_alv,
    it_fldcat type lvc_t_fcat.
    selection-screen begin of block b1 with frame title text-001.
    parameters: p_flds(5) type c.
    selection-screen end of block b1.
    start-of-selection.
    *build the dynamic internal table
    perform build_dyn_itab.
    *write 5 records to the alv grid
    do 5 times.
    perform build_report.
    enddo.
    *call the alv grid.
    perform call_alv.
    *Build_dyn_itab
    form build_dyn_itab.
    data: new_table type ref to data,
    new_line type ref to data,
    wa_it_fldcat type lvc_s_fcat.
    *Create fields .
    clear wa_it_fldcat.
    wa_it_fldcat-fieldname = 'name1'.
    wa_it_fldcat-datatype = 'mara-matnr'.
    wa_it_fldcat-intlen = 5.
    append wa_it_fldcat to it_fldcat .
    *clear wa_it_fldcat.
    wa_it_fldcat-fieldname = sy-index.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-intlen = 5.
    append wa_it_fldcat to it_fldcat .
    do p_flds times.
    clear wa_it_fldcat.
    wa_it_fldcat-fieldname = sy-index.
    wa_it_fldcat-datatype = 'CHAR'.
    wa_it_fldcat-intlen = 6.
    append wa_it_fldcat to it_fldcat .
    enddo.
    *Create dynamic internal table and assign to FS
    call method cl_alv_table_create=>create_dynamic_table
    exporting
    it_fieldcatalog = it_fldcat
    importing
    ep_table = new_table.
    assign new_table->* to <dyn_table>.
    *Create dynamic work area and assign to FS
    create data new_line like line of <dyn_table>.
    assign new_line->* to <dyn_wa>.
    endform.
    *Form build_report
    form build_report.
    data: fieldname(20) type c.
    data: fieldvalue(5) type c.
    data: index(3) type c.
    field-symbols: <fs1>.
    do p_flds times.
    index = sy-index.
    *Set up fieldvalue
    concatenate 'FLD' index into
    fieldvalue.
    condense fieldvalue no-gaps.
    assign component index of structure <dyn_wa> to <fs1>.
    <fs1> = fieldvalue.
    enddo.
    *Append to the dynamic internal table
    append <dyn_wa> to <dyn_table>.
    endform.
    *CALL_ALV
    form call_alv.
    data: wa_cat like line of alv_fldcat.
    *clear wa_cat.
    wa_cat-fieldname = 'matnr'.
    wa_cat-seltext_s = sy-index.
    wa_cat-outputlen = '10'.
    append wa_cat to alv_fldcat.
    do p_flds times.
    clear wa_cat.
    wa_cat-fieldname = sy-index.
    wa_cat-seltext_s = sy-index.
    wa_cat-outputlen = '6'.
    append wa_cat to alv_fldcat.
    enddo.
    *Call ABAP List Viewer (ALV)
    call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
    it_fieldcat = alv_fldcat
    tables
    t_outtab = <dyn_table>.
    endform.
    Hope this will help, reward if found usefull.
    Cheers,
    Ram.

  • How to populate dynamic internal table according to the field names

    Hi ,
          Iam having a dynamic internal table <DYN_TABLE> , it has fields like
    MATNR   MAKTX       MEINS    BISMT     MTART  ...
    Now my requirement is i need to fill them according to the fieldname from another internal table (static) .
    The order of  internal table (static) and dynamic internal are not same. 
    kindly help me.

    Hi,
    Here is the code. Please reward points if helpful.
    REPORT z_dynamic.
    TYPE-POOLS : abap.
    FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                   <dyn_wa>,
                   <dyn_field>.
    DATA: dy_table TYPE REF TO data,
          dy_line  TYPE REF TO data,
          xfc TYPE lvc_s_fcat,
          ifc TYPE lvc_t_fcat.
    SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME.
    PARAMETERS: p_table(30) TYPE c DEFAULT 'T001'.
    SELECTION-SCREEN END OF BLOCK b1.
    START-OF-SELECTION.
      PERFORM get_structure.
      PERFORM create_dynamic_itab.
      PERFORM get_data.
      PERFORM write_out.
    *&      Form  get_structure
          text
    FORM get_structure.
      DATA : idetails TYPE abap_compdescr_tab,
             xdetails TYPE abap_compdescr.
      DATA : ref_table_des TYPE REF TO cl_abap_structdescr.
    Get the structure of the table.
      ref_table_des ?=
          cl_abap_typedescr=>describe_by_name( p_table ).
      idetails[] = ref_table_des->components[].
      LOOP AT idetails INTO xdetails.
        CLEAR xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        APPEND xfc TO ifc.
      ENDLOOP.
    ENDFORM.                    "get_structure
    *&      Form  create_dynamic_itab
          text
    FORM create_dynamic_itab.
    Create dynamic internal table and assign to FS
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ifc
        IMPORTING
          ep_table        = dy_table.
      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>.
    ENDFORM.                    "create_dynamic_itab
    *&      Form  get_data
          text
    FORM get_data.
    Select Data from table.
      SELECT * INTO TABLE <dyn_table>
                 FROM (p_table).
    ENDFORM.                    "get_data
    *&      Form  write_out
          text
    FORM write_out.
    Write out data from table.
      LOOP AT <dyn_table> INTO <dyn_wa>.
        DO.
          ASSIGN COMPONENT  sy-index
             OF STRUCTURE <dyn_wa> TO <dyn_field>.
          IF sy-subrc <> 0.
            EXIT.
          ENDIF.
          IF sy-index = 1.
            WRITE:/ <dyn_field>.
          ELSE.
            WRITE: <dyn_field>.
          ENDIF.
        ENDDO.
      ENDLOOP.
    ENDFORM.                    "write_out

  • Dynamic Internal table values read and assign it back

    Hi All,
            I want to get the internal table field name dynamically and fetch its value and do some calculation and asign the new value to the same field name.
           CONCATENATE '<WA_PIPE>-ZW' v_index INTO v_fld.
            CONDENSE v_fld NO-GAPS.
            FIELD-SYMBOLS <fs> TYPE ANY.
            ASSIGN (v_fld) TO <fs>.
            v_fld1 = <fs> * <wa_pipe>-zrate.
    Now i've the internal table field name as <WA_PIPE>-ZW1 in v_fld and v_fld1 is having the value of the same field.
    How to assign it to the internal table field.
    Thanks.
    Ashok

    *& Report  YY_TEST1
    REPORT  YY_TEST1.
    type-pools: slis.
    field-symbols: <dyn_table> type standard table,
    <dyn_wa>.
    data: it_alvfc type slis_t_fieldcat_alv,
    wa_alvfc type slis_fieldcat_alv,
    it_fldcat type lvc_t_fcat,
    wa_fldcat type lvc_s_fcat.
    selection-screen begin of block b1 with frame title text-001.
      parameters: p_flds(5) type c.
    selection-screen end of block b1.
    start-of-selection.
    *build the dynamic internal table
    perform build_dyn_itab.
    *write 5 records to the alv grid
    do 5 times.
    perform build_report.
    enddo.
    *call the alv grid.
    perform call_alv.
    *Build_dyn_itab
    form build_dyn_itab.
    *Create the dynamic internal table
    data: new_table type ref to data,
    new_line type ref to data.
    *Create fields .
    do p_flds times.
    clear wa_fldcat.
    wa_fldcat-fieldname = sy-index.
    wa_fldcat-datatype = 'CHAR'.
    wa_fldcat-intlen = 5.
    append wa_fldcat to it_fldcat .
    enddo.
    *Create dynamic internal table and assign to FS
    call method cl_alv_table_create=>create_dynamic_table
    exporting
    it_fieldcatalog = it_fldcat
    importing
    ep_table = new_table.
    assign new_table->* to <dyn_table>.
    *Create dynamic work area and assign to FS
    create data new_line like line of <dyn_table>.
    assign new_line->* to <dyn_wa>.
    endform.
    *Form build_report
    form build_report.
    *Fill some values into the dynamic internal table
    data: fieldname(20) type c.
    data: fieldvalue(5) type c.
    data: index(3) type c.
    field-symbols: <fs1>.
    do p_flds times.
    index = sy-index.
    *Set up fieldvalue
    concatenate 'FLD' index into
    fieldvalue.
    condense fieldvalue no-gaps.
    assign component index of structure <dyn_wa> to <fs1>.
    <fs1> = fieldvalue.
    enddo.
    *Append to the dynamic internal table
    append <dyn_wa> to <dyn_table>.
    endform.
    *CALL_ALV
    form call_alv.
    *Build FC for ALV
    loop at it_fldcat into wa_fldcat.
    wa_alvfc-fieldname = wa_fldcat-fieldname.
    wa_alvfc-seltext_s = sy-tabix.
    wa_alvfc-outputlen = wa_fldcat-intlen.
    append wa_alvfc to it_alvfc.
    endloop.
    *Call ABAP List Viewer (ALV)
    call function 'REUSE_ALV_GRID_DISPLAY'
    exporting
    it_fieldcat = it_alvfc
    tables
    t_outtab = <dyn_table>.
    endform.

  • How To Read Field Values Form Dynamic Internal Table

    Hi,
    I Created a dynamic internal table using.
    FIELD-SYMBOLS: <gt_table> TYPE STANDARD TABLE,
                   <wa_gt_table>,
                   <l_fvalue> TYPE ANY.
    This Interanl table is working well, and all values are populated to an ALV.
    Now I try to set a link
    for that I am using below code
          READ TABLE <gt_table> ASSIGNING <l_fvalue> index rs_selfield-tabindex.
          IF sy-subrc EQ 0.
            insplot = <l_fvalue>-prueflos.
    Now it is showing a syntax error :
    the data object <l_fvalue> has no structure and there for no component called prueflos
    Regards
    Nausal

    Hi,
    Refere following code
    Local Field Symbol
      FIELD-SYMBOLS: <lf_any> TYPE ANY.                     "Changed data
      LOOP AT <gf_dyna_table> ASSIGNING <gf_dyna>.
        DO.
          ASSIGN COMPONENT sy-index OF STRUCTURE <gf_dyna> TO <lf_any>.
          IF sy-subrc NE 0.
            EXIT.
          ENDIF.
          IF ls_attach-line IS INITIAL.
            ls_attach-line = <lf_any>.
          ELSE.
            CONCATENATE ls_attach-line <lf_any> INTO ls_attach-line
                                                SEPARATED BY lc_tab.
          ENDIF.
        ENDDO.
        CONCATENATE lc_cret ls_attach-line  INTO ls_attach-line.
      Append Changed Data to attachement table
        APPEND ls_attach TO gt_attach.
      Clear
        CLEAR : ls_attach.
      ENDLOOP.
    Regards,
    Prashant

  • How to add new field into dynamic internal table

    Hello Expert.
    how to add new field into dynamic internal table.
    PARAMETERS: P_TABLE(30).    "table name
    DATA: I_TAB TYPE REF TO DATA.
    FIELD-SYMBOLS: <TAB> TYPE standard TABLE.
    *Create dynamic FS
    create DATA I_TAB TYPE TABLE OF (p_table).
      ASSIGN I_TAB->* TO <TAB>.
    SELECT * FROM (p_table) INTO TABLE <TAB>.
       here i want to add one more field into <TAB> at LAST position and my 
       Field name  =  field_stype     and
       Field type    =  'LVC_T_STYL'
    could you please helpme out .

    Hi,
    Please find the code below.You can add the field acc to your requirement.
    Creating Dynamic internal table
    TYPE-POOLS: slis.
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,  u201C Dynamic internal table name
                   <fs_dyntable>,                     u201C Field symbol to create work area
                   <fs_fldval> type any.              u201C Field symbol to assign values 
    PARAMETERS: p_cols(5) TYPE c.                     u201C Input number of columns
    DATA:   t_newtable TYPE REF TO data,
            t_newline  TYPE REF TO data,
            t_fldcat   TYPE slis_t_fldcat_alv,
            t_fldcat   TYPE lvc_t_fcat,
            wa_it_fldcat TYPE lvc_s_fcat,
            wa_colno(2) TYPE n,
            wa_flname(5) TYPE c. 
    Create fields .
      DO p_cols TIMES.
        CLEAR wa_it_fldcat.
        move sy-index to wa_colno.
        concatenate 'COL'
                    wa_colno
               into wa_flname.
        wa_it_fldcat-fieldname = wa_flname.
        wa_it_fldcat-datatype = 'CHAR'.
        wa_it_fldcat-intlen = 10.
        APPEND wa_it_fldcat TO t_fldcat.
      ENDDO. 
    Create dynamic internal table and assign to FS
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = t_fldcat
        IMPORTING
          ep_table        = t_newtable. 
      ASSIGN t_newtable->* TO <t_dyntable>. 
    Create dynamic work area and assign to FS
      CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
      ASSIGN t_newline->* TO <fs_dyntable>.
    Populating Dynamic internal table 
      DATA: fieldname(20) TYPE c.
      DATA: fieldvalue(10) TYPE c.
      DATA: index(3) TYPE c. 
      DO p_cols TIMES. 
        index = sy-index.
        MOVE sy-index TO wa_colno.
        CONCATENATE 'COL'
                    wa_colno
               INTO wa_flname. 
    Set up fieldvalue
        CONCATENATE 'VALUE' index INTO
                    fieldvalue.
        CONDENSE    fieldvalue NO-GAPS. 
        ASSIGN COMPONENT  wa_flname
            OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
        <fs_fldval> =  fieldvalue. 
      ENDDO. 
    Append to the dynamic internal table
      APPEND <fs_dyntable> TO <t_dyntable>.
    Displaying dynamic internal table using Grid. 
    DATA: wa_cat LIKE LINE OF fs_fldcat. 
      DO p_cols TIMES.
        CLEAR wa_cat.
        MOVE sy-index TO wa_colno.
        CONCATENATE 'COL'
                    wa_colno
               INTO wa_flname. 
        wa_cat-fieldname = wa_flname.
        wa_cat-seltext_s = wa_flname.
        wa_cat-outputlen = '10'.
        APPEND wa_cat TO fs_fldcat.
      ENDDO. 
    Call ABAP List Viewer (ALV)
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_fieldcat = fs_fldcat
        TABLES
          t_outtab    = <t_dyntable>.

Maybe you are looking for

  • Consolidate multiple iphoto libraries

    OK here's the deal. My wife says photos are missing, some have wrong dates, some are the wrong size etc. I reassure her that nothing is missing it's just misplaced. I want to back everything up before I go further. When I search the finder for iphoto

  • Bootcamp vs rEFIt & rEFInd, mbr, gpt

    I've been trying to install Windows 8.1 on Yosemite via Boot Camp Assistant, but got an error: Windows cannot be installed to this disk. The selected disk has a mbr partition table, On EFI system window can only be installed to GPT disks. After fight

  • Safari 6 lost audio in HTML5 videos

    I used to be able to play HTML5 videos in Safari without a problem--but as of the past week or so, I get no audio. I did a couple of courses through Coursera this summer and the HTML5 videos worked fine. But now that I've started new courses, I have

  • MB26 How can I avoid the Manual selection of stocks?

    Dear experts When I use Stock Determination function in MB26 (picking list) the systems (obviously) uses our stock determination rules to determine which stocks to pick. However, when it fails to automatically locate the required stock , it brings th

  • How to fix or stop postgres errors?

    10/5/11 7:41:12.633 PM org.postgresql.postgres: 2011-10-05 19:41:12 PDT FATAL:  could not create log file "/Library/Logs/PostgreSQL.log": Permission denied 10/5/11 7:41:12.634 PM com.apple.launchd: (org.postgresql.postgres[1234]) Exited with code: 1