Dynamic internal table

hi,
Hi i have a special requirement.
there are two ztables(z100 and z099)
z099 is as fallows:
seqno heading
1 model
2 product type
3 engine
4 horsepower
and z100 is :
seqno material charvalue
1 backhoe bhmodel
1 loadall llmodel
1 skid ssmodel
2 backhoe bh_product
2 loadall ll_product.
now my requirement is to display a alv report with headings from
z099 ie
alv report:
model producttype engine horsepower (heading of alv display)
(data)
bhmodel bhproduct
llmodel llproduct
and so
now can any one help me to create this kind of alv display:
the heading of each columns in lav should be displayed from rows under the heading field in z099
and data in alv report must be fetched from charval field in z100 table.
pls help me and
note that these ztables may grow in future.
and then the alv display should be downloaded to excel using gui_download.
thanks in advance.
any helpful answer will be rewarded.
this is a urgent issue.
can any one pls code this and send to me.
regards
vamsi

Hi!
Do you mind using ALV list???
If you don't, try this code:
*& Report  ZCAC_TRETA2                                                 *
REPORT  ZCAC_TRETA2                   .
TYPE-POOLS: SLIS.
TYPES: BEGIN OF S_HEADER,
         HEADER1(10),
         HEADER2(15),
       END OF S_HEADER,
       BEGIN OF S_ITEM,
         HEADER1(10),
         ITEM1(5),
         ITEM2(10),
       END OF S_ITEM,
       T_HEADER TYPE STANDARD TABLE OF S_HEADER,
       T_ITEM TYPE STANDARD TABLE OF S_ITEM.
DATA: GT_HEADER TYPE T_HEADER,
      GT_ITEM   TYPE T_ITEM,
      GS_KEYINFO       TYPE SLIS_KEYINFO_ALV,
      GT_FCAT          TYPE SLIS_T_FIELDCAT_ALV.
DATA: L_HEADER TYPE S_HEADER,
      L_ITEM   TYPE S_ITEM.
INITIALIZATION.
*fill test data:
*header:
  L_HEADER-HEADER1 = 'Head1'.
  L_HEADER-HEADER2 = 'blablabla'.
  APPEND L_HEADER TO GT_HEADER.
  L_HEADER-HEADER1 = 'Head2'.
  L_HEADER-HEADER2 = 'blablabla2'.
  APPEND L_HEADER TO GT_HEADER.
*Items:
  L_ITEM-HEADER1 = 'Head1'.
  L_ITEM-ITEM1   = 'Item1'.
  L_ITEM-ITEM2   = 'test, test!'.
  APPEND L_ITEM TO GT_ITEM.
  L_ITEM-ITEM1   = 'Item2'.
  L_ITEM-ITEM2   = 'test, test!'.
  APPEND L_ITEM TO GT_ITEM.
  L_ITEM-HEADER1 = 'Head2'.
  L_ITEM-ITEM1   = 'Item1'.
  L_ITEM-ITEM2   = 'test, test!'.
  APPEND L_ITEM TO GT_ITEM.
  L_ITEM-ITEM1   = 'Item2'.
  L_ITEM-ITEM2   = 'test, test!'.
  APPEND L_ITEM TO GT_ITEM.
  PERFORM F_INIT_ALV.
END-OF-SELECTION.
  CALL FUNCTION 'REUSE_ALV_HIERSEQ_LIST_DISPLAY'
       EXPORTING
*           I_INTERFACE_CHECK        = ' '
*           I_CALLBACK_PROGRAM       =
*           I_CALLBACK_PF_STATUS_SET = ' '
*           I_CALLBACK_USER_COMMAND  = ' '
*           IS_LAYOUT                =
            IT_FIELDCAT              = GT_FCAT
*           IT_EXCLUDING             =
*           IT_SPECIAL_GROUPS        =
*           IT_SORT                  =
*           IT_FILTER                =
*           IS_SEL_HIDE              =
*           I_SCREEN_START_COLUMN    = 0
*           I_SCREEN_START_LINE      = 0
*           I_SCREEN_END_COLUMN      = 0
*           I_SCREEN_END_LINE        = 0
*           I_DEFAULT                = 'X'
*           I_SAVE                   = ' '
*           IS_VARIANT               = ' '
*           IT_EVENTS                =
*           IT_EVENT_EXIT            =
            I_TABNAME_HEADER         = 'GT_HEADER'
            I_TABNAME_ITEM           = 'GT_ITEM'
*           I_STRUCTURE_NAME_HEADER  =
*           I_STRUCTURE_NAME_ITEM    =
            IS_KEYINFO               = GS_KEYINFO
*           IS_PRINT                 =
*           IS_REPREP_ID             =
*      IMPORTING
*           E_EXIT_CAUSED_BY_CALLER  =
*           ES_EXIT_CAUSED_BY_USER   =
       TABLES
            T_OUTTAB_HEADER          = GT_HEADER
            T_OUTTAB_ITEM            = GT_ITEM
*      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.
*&      Form  F_INIT_ALV
FORM F_INIT_ALV.
  PERFORM F_INIT_KEYINFO.
  PERFORM F_INIT_FCAT.
ENDFORM.                    " F_INIT_ALV
*&      Form  F_INIT_KEYINFO
FORM F_INIT_KEYINFO.
  GS_KEYINFO-HEADER01 = 'HEADER1'.
  GS_KEYINFO-ITEM01   = 'HEADER1'.
ENDFORM.                    " F_INIT_LAYOUT
*&      Form  F_INIT_FCAT
FORM F_INIT_FCAT.
  DATA: LS_FCAT TYPE SLIS_FIELDCAT_ALV.
  LS_FCAT-FIELDNAME = 'HEADER1'.
  LS_FCAT-TABNAME   = 'GT_HEADER'.
  APPEND LS_FCAT TO GT_FCAT.
  LS_FCAT-FIELDNAME = 'HEADER2'.
  LS_FCAT-TABNAME   = 'GT_HEADER'.
  APPEND LS_FCAT TO GT_FCAT.
  LS_FCAT-FIELDNAME = 'ITEM1'.
  LS_FCAT-TABNAME   = 'GT_ITEM'.
  LS_FCAT-ROW_POS  = '1'.
  APPEND LS_FCAT TO GT_FCAT.
  LS_FCAT-FIELDNAME = 'ITEM2'.
  LS_FCAT-TABNAME   = 'GT_ITEM'.
  LS_FCAT-ROW_POS  = '2'.
  APPEND LS_FCAT TO GT_FCAT.
ENDFORM.                    " F_INIT_FCAT
Hope it helps!
Regards,
Carlos Constantino.

Similar Messages

  • How to populate data in dynamic internal table

    Hi Expert,
    fyi. My dynamic internal table field is created base on data selected. Eg. select table qpcd has 5 records.  These 5 recods will become fieldname to my dynamic internal table. My dynamic internal table will be
    ...itab
          01
          02
          03
          04
          05
    The 5 records from qpcd is populated in another table call viqmel.  I need to find the occurance of each code in viqmel and populate the number of occurance in itab in each of column.  The final dynamic itab will be like this
    table itab
    01       02     03    04     05   -
    > field name
    2         0        1     0       1    -
    > data
    my source code like below
    Report ZPLYGRND2.
    TABLES: mara, makt.
    TYPE-POOLS: slis, sydes.
    DATA:it_fcat TYPE slis_t_fieldcat_alv,
         is_fcat LIKE LINE OF it_fcat,
         ls_layout TYPE slis_layout_alv.
    DATA: it_fieldcat TYPE lvc_t_fcat,
          is_fieldcat LIKE LINE OF it_fieldcat.
    DATA: new_table TYPE REF TO data,
          new_line TYPE REF TO data,
          ob_cont_alv TYPE REF TO cl_gui_custom_container,
          ob_alv TYPE REF TO cl_gui_alv_grid,
          vg_campos(255) TYPE c,
          i_campos LIKE TABLE OF vg_campos,
          vg_campo(30) TYPE c,
          vg_tables(60) TYPE c.
    types : begin of t_qpcd,
             codegruppe like qpcd-codegruppe,
             code like qpcd-code,
            end of t_qpcd.
    data:wa_qpcd type t_qpcd,
         i_qpcd type standard table of t_qpcd initial size 0.
    FIELD-SYMBOLS: <l_table> TYPE table,
                   <l_line> TYPE ANY,
                   <l_field> TYPE ANY.
    select * into corresponding fields of wa_qpcd from qpcd
    where katalogart = 'D'
    and   codegruppe = 'OOT01'.
    append wa_qpcd to i_qpcd.
    endselect.
    loop at i_qpcd into wa_qpcd.
      is_fcat-fieldname = wa_qpcd-code.
      APPEND is_fcat TO it_fcat.
    endloop.
    LOOP AT it_fcat INTO is_fcat.
        is_fieldcat-fieldname = is_fcat-fieldname.
        is_fieldcat-ref_field = is_fcat-ref_fieldname.
        is_fieldcat-ref_table = is_fcat-ref_tabname.
        APPEND is_fieldcat TO it_fieldcat.
    ENDLOOP.
    *... Create the dynamic internal table
    CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
            it_fieldcatalog = it_fieldcat
        IMPORTING
            ep_table = new_table.
    if sy-subrc = 0.
    endif.
    *... Create a new line
    ASSIGN new_table->* TO <l_table>.
    CREATE DATA new_line LIKE LINE OF <l_table>.
    ASSIGN new_line->* TO <l_line>.
    LOOP AT <l_table> INTO <l_line>.
    ENDLOOP.

    hello dear i m giving u a code in this a dynamic table is made on the basis of table in database , and u can download this data correct it , see it, or even change it....and upload in tht table help full if u dont know the table name...in advance.
    also the code to populate data in dynamic table is in this code like:
    SELECT * FROM (MTABLE_N)
    INTO CORRESPONDING FIELDS OF TABLE <FS_ITAB> .
    look at the whole program .hope this solve ur problem thanks.
    REPORT ZTESTA  MESSAGE-ID ZIMM    .
    TYPES : DATA_OBJECT TYPE REF TO DATA.
    DATA : MITAB TYPE REF TO DATA .
    TYPE-POOLS : SLIS .
    DATA : IT_FIELDCAT TYPE STANDARD TABLE OF SLIS_FIELDCAT_ALV
    WITH HEADER LINE .
    DATA : IT_FIELDCATALOG TYPE LVC_T_FCAT .
    DATA : WA_FIELDCATALOG TYPE LVC_S_FCAT .
    DATA : I_STRUCTURE_NAME LIKE DD02L-TABNAME .
    DATA : I_CALLBACK_PROGRAM LIKE SY-REPID .
    DATA : DYN_LINE TYPE DATA_OBJECT .
    FIELD-SYMBOLS : <FS_ITAB> TYPE STANDARD TABLE .
    DATA : TABLE_NAME_IS_VALID TYPE C .
    DATA : DYNAMIC_IT_INSTANTIATED TYPE C .
    CONSTANTS BUTTONSELECTED TYPE C VALUE 'X' .
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_TABL.
    PARAMETERS : MTABLE_N LIKE RSRD1-TBMA_VAL
    MATCHCODE OBJECT DD_DBTB_16 OBLIGATORY .
    DATA CHECKTABLED.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_FILE.
    PARAMETERS : MFILENAM LIKE RLGRAP-FILENAME .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_DOWN.
    PARAMETERS : P_DOWNLD RADIOBUTTON GROUP GRP1
    USER-COMMAND M_UCOMM .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_CHKF.
    PARAMETERS : P_CHKFIL RADIOBUTTON GROUP GRP1 .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_UPLD.
    PARAMETERS : P_UPLOAD RADIOBUTTON GROUP GRP1 .
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT 5(29) T_SHOW.
    PARAMETERS : P_SHOW_T RADIOBUTTON GROUP GRP1 .
    SELECTION-SCREEN END OF LINE.
    AT SELECTION-SCREEN OUTPUT .
      PERFORM CHECK_FILENAME .
    AT SELECTION-SCREEN.
      IF SY-UCOMM = 'ONLI'.
        CHECKTABLED = MTABLE_N+0(1).
        IF CHECKTABLED NE 'Z'.
          MESSAGE I017.
          LEAVE TO SCREEN 1000.
        ENDIF.
        IF SY-UNAME NE 'KAMESH.K'.
          MESSAGE I023 WITH SY-UNAME.
          LEAVE TO SCREEN 1000.
        ENDIF.
      ENDIF.
      IF SY-UCOMM = 'PRIN'.
        CHECKTABLED = MTABLE_N+0(1).
        IF CHECKTABLED NE 'Z'.
          MESSAGE I017.
          LEAVE TO SCREEN 1000.
        ENDIF.
        IF SY-UNAME NE 'KAMESH.K'.
          MESSAGE I023 WITH SY-UNAME.
          LEAVE TO SCREEN 1000.
        ENDIF.
      ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR MFILENAM .
      PERFORM F4_FOR_FILENAME .
    INITIALIZATION .
      T_TABL = 'Table Name' .
      T_FILE = 'File Name' .
      T_DOWN = 'Download Table' .
      T_CHKF = 'Check File to Upload' .
      T_UPLD = 'Upload File' .
      T_SHOW = 'Show Table Contents' .
    START-OF-SELECTION .
      PERFORM CHECK_TABLE_NAME_IS_VALID .
    END-OF-SELECTION .
      IF TABLE_NAME_IS_VALID EQ ' ' .
        MESSAGE I398(00) WITH 'INVALID TABLE NAME' .
      ELSE .
        PERFORM INSTANTIATE_DYNAMIC_INTERNAL_T .
        CHECK DYNAMIC_IT_INSTANTIATED = 'X' .
        CASE BUTTONSELECTED .
          WHEN P_DOWNLD .
            PERFORM SELECT_AND_DOWNLOAD .
          WHEN P_CHKFIL .
            PERFORM CHECK_FILE_TO_UPLOAD .
          WHEN P_UPLOAD .
            PERFORM UPLOAD_FROM_FILE .
          WHEN P_SHOW_T .
            PERFORM SHOW_CONTENTS .
        ENDCASE .
      ENDIF .
    FORM CHECK_TABLE_NAME_IS_VALID.
      DATA MCOUNT TYPE I .
      TABLES DD02L .
      CLEAR TABLE_NAME_IS_VALID .
      SELECT COUNT(*) INTO MCOUNT FROM TADIR
      WHERE PGMID = 'R3TR'
      AND OBJECT = 'TABL'
      AND OBJ_NAME = MTABLE_N .
      IF MCOUNT EQ 1 .
        CLEAR DD02L .
        SELECT SINGLE * FROM DD02L WHERE TABNAME = MTABLE_N .
        IF SY-SUBRC EQ 0.
          IF DD02L-TABCLASS = 'TRANSP' .
            TABLE_NAME_IS_VALID = 'X' .
          ENDIF .
        ENDIF.
      ENDIF .
    ENDFORM. " CHECK_TABLE_NAME_IS_VALID
    FORM SELECT_AND_DOWNLOAD.
      CLEAR : <FS_ITAB> .
      SELECT * FROM (MTABLE_N)
      INTO CORRESPONDING FIELDS OF TABLE <FS_ITAB> .
      PERFORM CHECK_FILENAME.
      CALL FUNCTION 'WS_DOWNLOAD'
           EXPORTING
                FILENAME                = MFILENAM
                FILETYPE                = 'DAT'
           TABLES
                DATA_TAB                = <FS_ITAB>
           EXCEPTIONS
                FILE_OPEN_ERROR         = 1
                FILE_WRITE_ERROR        = 2
                INVALID_FILESIZE        = 3
                INVALID_TYPE            = 4
                NO_BATCH                = 5
                UNKNOWN_ERROR           = 6
                INVALID_TABLE_WIDTH     = 7
                GUI_REFUSE_FILETRANSFER = 8
                CUSTOMER_ERROR          = 9
                OTHERS                  = 10.
      IF SY-SUBRC EQ 0.
        MESSAGE I398(00) WITH 'Table' MTABLE_N
        'successfully downloaded to '
        MFILENAM .
      ENDIF.
    ENDFORM. " SELECT_AND_DOWNLOAD
    FORM UPLOAD_FROM_FILE.
      DATA : ANS TYPE C .
      DATA : LINES_OF_ITAB TYPE I .
      DATA : MSY_SUBRC TYPE I .
      CALL FUNCTION 'POPUP_TO_CONFIRM_STEP'
           EXPORTING
                TEXTLINE1 = 'Are you sure you wish to upload'
                TEXTLINE2 = 'data from ASCII File to DB table '
                TITEL     = 'Confirmation of Data Upload'
           IMPORTING
                ANSWER    = ANS.
      IF ANS = 'J' .
        PERFORM CHECK_FILENAME.
        CLEAR MSY_SUBRC .
        CALL FUNCTION 'WS_UPLOAD'
             EXPORTING
                  FILENAME                = MFILENAM
                  FILETYPE                = 'DAT'
             TABLES
                  DATA_TAB                = <FS_ITAB>
             EXCEPTIONS
                  CONVERSION_ERROR        = 1
                  FILE_OPEN_ERROR         = 2
                  FILE_READ_ERROR         = 3
                  INVALID_TYPE            = 4
                  NO_BATCH                = 5
                  UNKNOWN_ERROR           = 6
                  INVALID_TABLE_WIDTH     = 7
                  GUI_REFUSE_FILETRANSFER = 8
                  CUSTOMER_ERROR          = 9
                  OTHERS                  = 10.
        MSY_SUBRC = MSY_SUBRC + SY-SUBRC .
        IF SY-SUBRC EQ 0.
          DESCRIBE TABLE <FS_ITAB> LINES LINES_OF_ITAB .
          IF LINES_OF_ITAB GT 0 .
            MODIFY (MTABLE_N) FROM TABLE <FS_ITAB> .
            MSY_SUBRC = MSY_SUBRC + SY-SUBRC .
          ENDIF .
        ENDIF.
        IF MSY_SUBRC EQ 0 .
          MESSAGE I398(00) WITH LINES_OF_ITAB
          'Record(s) inserted in table'
          MTABLE_N .
        ELSE .
          MESSAGE I398(00) WITH
          'Errors occurred No Records inserted in table'
          MTABLE_N .
        ENDIF .
      ENDIF .
    ENDFORM. " UPLOAD_FROM_FILE
    FORM F4_FOR_FILENAME.
      CALL FUNCTION 'WS_FILENAME_GET'
           EXPORTING
                DEF_PATH         = 'C:\'
                MASK             = ',.,..'
                MODE             = '0'
           IMPORTING
                FILENAME         = MFILENAM
           EXCEPTIONS
                INV_WINSYS       = 1
                NO_BATCH         = 2
                SELECTION_CANCEL = 3
                SELECTION_ERROR  = 4
                OTHERS           = 5.
    ENDFORM. " F4_FOR_FILENAME
    FORM CHECK_FILENAME.
      IF MFILENAM IS INITIAL
      AND NOT ( MTABLE_N IS INITIAL )
      AND P_SHOW_T NE BUTTONSELECTED.
        CONCATENATE 'C:\'
        MTABLE_N '.TXT' INTO MFILENAM.
      ENDIF .
    ENDFORM. " CHECK_FILENAME
    FORM INSTANTIATE_DYNAMIC_INTERNAL_T.
      CLEAR DYNAMIC_IT_INSTANTIATED .
      I_STRUCTURE_NAME = MTABLE_N .
      CLEAR IT_FIELDCAT[] .
      CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
           EXPORTING
                I_STRUCTURE_NAME       = I_STRUCTURE_NAME
           CHANGING
                CT_FIELDCAT            = IT_FIELDCAT[]
           EXCEPTIONS
                INCONSISTENT_INTERFACE = 1
                PROGRAM_ERROR          = 2
                OTHERS                 = 3.
      IF SY-SUBRC EQ 0.
        LOOP AT IT_FIELDCAT .
          CLEAR WA_FIELDCATALOG .
          MOVE-CORRESPONDING IT_FIELDCAT TO WA_FIELDCATALOG .
          WA_FIELDCATALOG-REF_FIELD = IT_FIELDCAT-FIELDNAME .
          WA_FIELDCATALOG-REF_TABLE = MTABLE_N .
          APPEND WA_FIELDCATALOG TO IT_FIELDCATALOG .
        ENDLOOP .
        CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
        IT_FIELDCATALOG = IT_FIELDCATALOG
        IMPORTING
        EP_TABLE = MITAB .
        ASSIGN MITAB->* TO <FS_ITAB> .
        DYNAMIC_IT_INSTANTIATED = 'X' .
      ENDIF.
    ENDFORM. " INSTANTIATE_DYNAMIC_INTERNAL_T
    FORM SHOW_CONTENTS.
      CLEAR : <FS_ITAB> .
      SELECT * FROM (MTABLE_N)
      INTO CORRESPONDING FIELDS OF TABLE <FS_ITAB> .
      I_CALLBACK_PROGRAM = SY-REPID .
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
           EXPORTING
                I_CALLBACK_PROGRAM = I_CALLBACK_PROGRAM
                IT_FIELDCAT        = IT_FIELDCAT[]
           TABLES
                T_OUTTAB           = <FS_ITAB>
           EXCEPTIONS
                PROGRAM_ERROR      = 1
                OTHERS             = 2.
    ENDFORM. " SHOW_CONTENTS
    FORM CHECK_FILE_TO_UPLOAD.
      PERFORM CHECK_FILENAME.
      CALL FUNCTION 'WS_UPLOAD'
           EXPORTING
                FILENAME                = MFILENAM
                FILETYPE                = 'DAT'
           TABLES
                DATA_TAB                = <FS_ITAB>
           EXCEPTIONS
                CONVERSION_ERROR        = 1
                FILE_OPEN_ERROR         = 2
                FILE_READ_ERROR         = 3
                INVALID_TYPE            = 4
                NO_BATCH                = 5
                UNKNOWN_ERROR           = 6
                INVALID_TABLE_WIDTH     = 7
                GUI_REFUSE_FILETRANSFER = 8
                CUSTOMER_ERROR          = 9
                OTHERS                  = 10.
      IF SY-SUBRC EQ 0.
        I_CALLBACK_PROGRAM = SY-REPID .
        CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
             EXPORTING
                  I_CALLBACK_PROGRAM = I_CALLBACK_PROGRAM
                  IT_FIELDCAT        = IT_FIELDCAT[]
             TABLES
                  T_OUTTAB           = <FS_ITAB>
             EXCEPTIONS
                  PROGRAM_ERROR      = 1
                  OTHERS             = 2.
      ENDIF .
    ENDFORM. " CHECK_FILE_TO_UPLOAD
    Message was edited by:
            SAURABH SINGH
            SENIOR EXECUTIVE
            SAMSUNG INDIA ELECTRONICS LTD.,NOIDA

  • Logic for retreiving the values from a dynamic internal table

    Hi all,
    I have an issue with the logic to fetch data from a dynamic internal table into fields. let me give you guys an example the sy-tfill = 9 (subject to vary). I need to populate the fields.
    Regards,
    Sukumar

    Hi,
    this is for printing out the info in a dynamic table,
    it will work likewise to insert data.
    PARAMETERS:
      p_tabnam TYPE tabname DEFAULT 'DB_TABLE_NAME'.
    DATA:
      lv_dref TYPE REF TO data,
      ls_dd03l LIKE dd03l,
      lt_fieldname TYPE TABLE OF fieldname,
      ls_fieldname TYPE fieldname.
    FIELD-SYMBOLS:
      <fs> TYPE STANDARD TABLE,
      <wa_comp> TYPE fieldname,
      <wa_data> TYPE ANY,
      <wa_field> TYPE ANY.
    REFRESH lt_fieldname.
    SELECT * FROM dd03l INTO ls_dd03l
                       WHERE as4local = 'A'
                         AND as4vers  = '0000'
                         AND tabname  = p_tabnam
                       ORDER BY position.
      ls_fieldname = ls_dd03l-fieldname.
      APPEND ls_fieldname TO lt_fieldname.
    ENDSELECT.
    IF NOT ( lt_fieldname[] IS INITIAL ).
      CREATE DATA lv_dref TYPE TABLE OF (p_tabnam).
      ASSIGN lv_dref->* TO <fs>.
      SELECT * FROM (p_tabnam) INTO TABLE <fs>.
      WRITE:
        / 'CONTENTS OF TABLE', p_tabnam.
      LOOP AT <fs> ASSIGNING <wa_data>.
        SKIP.
        WRITE:
          / 'LINE', sy-tabix.
        ULINE.
        LOOP AT lt_fieldname ASSIGNING <wa_comp>.
          ASSIGN COMPONENT sy-tabix OF STRUCTURE <wa_data> TO <wa_field>.
          WRITE:
            / <wa_comp>, <wa_field>.
        ENDLOOP.
      ENDLOOP.
    ENDIF.
    grtz
    Koen

  • Distinct values from dynamic internal tabls

    Hi All,
    I have a dynamic internal tables like <dy_table> , i want to get distinct  values from this internal tables,
    how to do that, structure of dynamic internal tables is dynamic acc. to user conditions.
    regards,
    Anuj

    Hi Anuj
    Just try this,
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = tb_fields_for_it
    IMPORTING
    ep_table = gp_dyn_table.
    ASSIGN gp_dyn_table->* TO <gt_table>.
    ASSIGN LOCAL COPY OF INITIAL LINE OF <gt_table> TO <fs_table>.
    LOOP AT tb_output.
    *To assign value for serial number.
    ASSIGN COMPONENT 1 OF STRUCTURE <fs_table> TO <ls_field>.
    <ls_field> = tb_output-sno.
    UNASSIGN <ls_field>.
    *To assign value for Sales Organization.
    ASSIGN COMPONENT 2 OF STRUCTURE <fs_table> TO <ls_field>.
    <ls_field> = tb_output-vkorg.
    UNASSIGN <ls_field>.
    *To assign Rate for its respective Condition type.
    LOOP AT tb_konp WHERE knumh = tb_output-knumh.
    READ TABLE tb_fieldcat1 WITH KEY fieldname = tb_output-kschl.
    IF sy-subrc EQ 0.
    lv_count = tb_fieldcat1-col_pos.
    ASSIGN COMPONENT lv_count OF STRUCTURE <fs_table> TO <ls_field>.
    IF tb_konp-konwa EQ '%'.
    tb_konp-kbetr = tb_konp-kbetr / co_10.
    <ls_field> = tb_konp-kbetr.
    ELSE.
    <ls_field> = tb_konp-kbetr.
    ENDIF.
    ENDIF.
    ENDLOOP.
    lv_count = lv_count + 1.
    APPEND <fs_table> TO <gt_table>.
    CLEAR <fs_table>.
    ENDLOOP.
    Hope this proves helpful to you.

  • How to delete data from dynamic internal table

    Hi,
    I have dynamic internal table and I have some slection screen fields , using these selection screen fields
    (select -options), I have to filter the data? assigning will work with READ , but I have select options not the parametre,
    and also delete will not work for dynamic table..
    as we cannot use assigning with delete..
    So how to do this?
    and one more thing is , I cannot filter the data while selection( in select, I cannot filter the data-> as it's not coming directly from table, it's coming from buffer),
    so now after selection of data, I need to filter the data from dynamic table.
    Is there any way to do this?
    Regards,
    Mrunal

    Hi matt,
    I tried with below code as  you said. But I am getting dump. can you help?
    here is my piece of code.
    FIELD-SYMBOLS: <LS_DATA> type any,
                               <LT_DATA> TYPE table,
                                <L_FIELD> type any.
        ASSIGN <l_buffer_entry>-dataptr->* TO <LS_DATA>.
        ASSIGN <l_buffer_entry>-dataptr->* TO <LT_DATA>.
    LOOP AT <LT_DATA> ASSIGNING <LS_DATA>.
    ASSIGN COMPONENT 'BUKRS' OF STRUCTURE <LS_DATA> TO <L_FIELD>.
    IF <L_FIELD> NOT IN SO_BUKRS.
    DELETE <LT_DATA>.
    ENDIF.
    UNASSIGN <L_FIELD>.
    ASSIGN COMPONENT 'BELNR' OF STRUCTURE <LS_DATA> TO <L_FIELD>.
    IF <L_FIELD> NOT IN SO_BELNR.
    DELETE <LT_DATA>.
    ENDIF.
    UNASSIGN <L_FIELD>.
    ENDLOOP.
    and here is the description of my dump:->>>
    You attempted to access an unassigned field symbol
    (data segment 32772).
    This error may occur for any of the following reasons:
    - You address a typed field symbol before it is set using ASSIGN
    - You address a field symbol that points to a line in an internal table
      that has been deleted
    - You address a field symbol that had previously been reset using
      UNASSIGN, or that pointed to a local field that no longer exists
    - You address a global function interface parameter, even
      though the relevant function module is not active,
      that is it is not in the list of active calls. You can get the list
      of active calls from the this short dump.

  • Column names of a dynamic internal table

    Hi Friends,
    I have a dynamic internal table flowing in my ABAP program and I want to list down the column names of the this dynamic internal table.
    The declaration of this dynamic internal table :
       FIELD-SYMBOLS:
        <l_t_data>         TYPE STANDARD TABLE.
    Can you please tell me how to get the column names?
    Thanks,
    Gaurav

    Hi,
         You can use ABAP Runtime Type Identification to get the column names of the internal table.
    e.g >
    >lo_itab holds reference to description object of internal table whose column names i have to extract.
    >Using method describe_by_data of class cl_abap_typedescr export the field symbol assigned to the table and import the object reference into lo_itab.
    >Then using method get_table_line_type of lo_itab import line type description object reference into lo_line.
    >Check if lo_line is referring to a structure, if yes , downcast it to a object reference lo_struct of type cl_abap_structdescr.
    >The column description of all columns in the structure is stored in 'components' table of cl_abap_structdescr.
         So loop at the table to get all the column names stored in column 'name' of table 'components'.
    Thank You.

  • How to use dynamic internal table when using gui_upload?

    Hi Experts,
    my scenario is like i have header data, item data and serial numbers.
    so with respect to the  quantity in unit of measure ,there will be number of serial numbers..
    i have declared the dynamic internal table,but i am not getting the logic to change the structure accordingly with respect to the flat file entries..
    is it possible to do or its not possible....any suggestion!!!!i have declared like this....
    TYPES: BEGIN OF ty_final,
          bldat TYPE string,      "Document Date
          budat TYPE string,      "Psting Date
          bktxt TYPE string,      "Document Header Text
          werks TYPE string,      "Plant
          lgort TYPE string,      "Storage Location
          matnr TYPE string,      "Material Number
          erfmg TYPE string,      "Quantity in Unit Of Entry
          anln1 TYPE string,      "Asset Number
          anln2 TYPE string,      "Asset Subnumber
          sernr TYPE string,      "serial Number
    END OF ty_final.
    DATA : it_final TYPE TABLE OF ty_final,
           wa_final TYPE ty_final.
    FIELD-SYMBOLS : <fs_final> TYPE table.
    ASSIGN it_final TO <fs_final>.
    after this i called gui upload and passed internal table it_final..
    but i have to change the internal table structure dynamically before the upload function.so that it will match with the flat file...
    Regards
    Karthick

    There are at least two approaches you can use to change/generate new dynamic-structured table. Either with [RTTI + RTTS|https://wiki.sdn.sap.com/wiki/display/Snippets/CreatingFlatandComplexInternalTablesDynamicallyusingRTTI] or using [CL_ALV_TABLE_CREATE|http://www.sdn.sap.com/irj/scn/advancedsearch?query=cl_alv_table_create] . In this one just determine fieldcatalog of current table and change it accordingly, then regenarate table.
    There are plenty of examples in SCN for this. You should not face difficulties applying this.
    Regards
    Marcin

  • How to do parallel processing with dynamic internal table

    Hi All,
    I need to implement parallel processing that involves dynamically created internal tables. I tried doing so using RFC function modules (using starting new task and other such methods) but didn't get success this requires RFC enabled function modules and at the same time RFC enabled function modules do not allow generic data type (STANDARD TABLE) which is needed for passing dynamic internal tables. My exact requirement is as follows:
    1. I've large chunk of data in two internal tables, one of them is formed dynamically and hence it's structure is not known at the time of coding.
    2. This data has to be processed together to generate another internal table, whose structure is pre-defined. But this data processing is taking very long time as the number of records are close to a million.
    3. I need to divide the dynamic internal table into (say) 1000 records each and pass to a function module and submit it to run in another task. Many such tasks will be executed in parallel.
    4. The function module running in parallel can insert the processed data into a database table and the main program can access it from there.
    Unfortunately, due to the limitation of not allowing generic data types in RFC, I'm unable to do this. Does anyone has any idea how to implement parallel processing using dynamic internal tables in these type of conditions.
    Any help will be highly appreciated.
    Thanks and regards,
    Ashin

    try the below code...
      DATA: w_subrc TYPE sy-subrc.
      DATA: w_infty(5) TYPE  c.
      data: w_string type string.
      FIELD-SYMBOLS: <f1> TYPE table.
      FIELD-SYMBOLS: <f1_wa> TYPE ANY.
      DATA: ref_tab TYPE REF TO data.
      CONCATENATE 'P' infty INTO w_infty.
      CREATE DATA ref_tab TYPE STANDARD TABLE OF (w_infty).
      ASSIGN ref_tab->* TO <f1>.
    * Create dynamic work area
      CREATE DATA ref_tab TYPE (w_infty).
      ASSIGN ref_tab->* TO <f1_wa>.
      IF begda IS INITIAL.
        begda = '18000101'.
      ENDIF.
      IF endda IS INITIAL.
        endda = '99991231'.
      ENDIF.
      CALL FUNCTION 'HR_READ_INFOTYPE'
        EXPORTING
          pernr           = pernr
          infty           = infty
          begda           = '18000101'
          endda           = '99991231'
        IMPORTING
          subrc           = w_subrc
        TABLES
          infty_tab       = <f1>
        EXCEPTIONS
          infty_not_found = 1
          OTHERS          = 2.
      IF sy-subrc <> 0.
        subrc = w_subrc.
      ELSE.
      ENDIF.

  • How to create Dynamic internal table with columns also created dynamically.

    Hi All,
    Any info on how to create a dynamic internal table along with columns(fields) also to be created dynamically.
    My requirement is ..On the selection screen I enter the number of fields to be in the internal table which gets created dynamically.
    I had gone thru some posts on dynamic table creation,but could'nt find any on the dynamic field creation.
    Any suggestions pls?
    Thanks
    Nara

    I don't understand ...
    something like that ?
    *   Form P_MODIFY_HEADER.                                              *
    form p_modify_header.
      data : is_fieldcatalog type lvc_s_fcat ,
             v_count(2)      type n ,
             v_date          type d ,
             v_buff(30).
    * Update the fieldcatalog.
      loop at it_fieldcatalog into is_fieldcatalog.
        check is_fieldcatalog-fieldname+0(3) eq 'ABS' or
              is_fieldcatalog-fieldname+0(3) eq 'VAL' .
        move : is_fieldcatalog-fieldname+3(2) to v_count ,
               p_perb2+5(2)                   to v_date+4(2) ,
               p_perb2+0(4)                   to v_date+0(4) ,
               '01'                           to v_date+6(2) .
        v_count = v_count - 1.
        call function 'RE_ADD_MONTH_TO_DATE'
            exporting
              months        = v_count
              olddate       = v_date
            importing
              newdate       = v_date.
        if is_fieldcatalog-fieldname+0(3) eq 'ABS'.
          concatenate 'Quantité 0'
                      v_date+4(2)
                      v_date+0(4)
                      into v_buff.
        else.
          concatenate 'Montant 0'
                      v_date+4(2)
                      v_date+0(4)
                      into v_buff.
        endif.
        move : v_buff to is_fieldcatalog-scrtext_s ,
               v_buff to is_fieldcatalog-scrtext_m ,
               v_buff to is_fieldcatalog-scrtext_l ,
               v_buff to is_fieldcatalog-reptext .
        modify it_fieldcatalog from is_fieldcatalog.
      endloop.
    * Modify the fieldcatalog.
      call method obj_grid->set_frontend_fieldcatalog
           exporting it_fieldcatalog = it_fieldcatalog.
    * Refresh the display of the grid.
      call method obj_grid->refresh_table_display.
    endform.                     " P_MODIFY_HEADER

  • How to create Dynamic Internal table in ALV?

    Hi all,
    I have to create a ALV report based on dynamic internal table. The requirement is that when I enter the months in my selection screen I should get the data relevant to those many months only. For eg if in selection I have given January to March, I should get an ALV output with columns from January to March only.
    Please help me with the coding part as I find it a bit confusing.
    Please reply immediately.
    Regards,
    Bhavani.

    Hi BHAVANI,
    first you have to prapare a field catalog [(see this)|http://help.sap.com/saphelp_470/helpdata/en/52/5f060de02d11d2b47d006094192fe3/frameset.htm]
    and than you can use a Method cl_alv_table_create=>create_dynamic_table
    I hope that help a little.
    Regards Bogdan

  • Create a deep structure for dynamic internal table

    Hi All,
    I am creating a dynamic table using method cl_alv_table_create=>create_dynamic_table.
    The normal structure gets created. but now I want to creat a Deep structure for having information of colors also for each column. So I want to add a COLTAB type LVC_T_SCOL for colors information .
    How should I create this using above method?
    Rgds,
    Madhuri

    I created a zcelltab structure as below. But while creating dynamic internal table, I received the error  with
    'Type "ZCELLTAB" is unknown 68 ZCELLTAB-CELLTAB
    Here is the code.
    DATA: BEGIN OF ZCELLTAB,
             CELLTAB LIKE LVC_S_STYL,
         END OF ZCELLTAB.
    FIELD-SYMBOLS <T_CELLTAB> TYPE LVC_T_STYL.
    DATA : LT_CELLTAB TYPE LVC_T_STYL.
    DATA:  WA_CELLTAB TYPE LINE OF LVC_T_STYL.
    DATA: GT_FCAT1 TYPE LVC_T_FCAT,
               GW_FCAT1 TYPE LVC_S_FCAT,
                GT_FCAT2 TYPE LVC_T_FCAT,
                GW_FCAT2  TYPE LVC_S_FCAT.
    After filling the FCAT1, I added the field in FCAT2  like below
      GT_FCAT2[ ] = GT_FCAT1[ ].
      G_TABIX = G_TABIX + 1.
      GW_FCAT2-INTTYPE = 'C'.
      MOVE G_TABIX TO GW_FCAT2-COL_POS.
      GW_FCAT2-OUTPUTLEN = '10'.
      GW_FCAT2-FIELDNAME = 'T_CELLTAB'.
      GW_FCAT2-TABNAME = 'ZCELLTAB'.
      GW_FCAT2-REF_FIELD = 'CELLTAB'.
      GW_FCAT2-REF_TABLE = 'ZCELLTAB'.
      APPEND GW_FCAT2 TO GT_FCAT2
      CLEAR GW_FCAT2.
    While calling the below method, the error with
    CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
         EXPORTING
          IT_FIELDCATALOG = GT_FCAT2
        IMPORTING
          EP_TABLE        = GT_REQ.
      ASSIGN GT_REQ->* TO <F_TAB>.
      CREATE DATA GWA_REQ LIKE LINE OF <F_TAB>.
      ASSIGN GWA_REQ->* TO <F_WA>.
    LOOP AT ITAB.
    ASSIGN COMPONENT 'MATNR'  OF STRUCTURE <F_WA> TO <F_VAL>
    <F_VAL> = ITAB-MATNR.
    IF ITAB-MATNR IS INITIAL.
    ASSIGN COMPONENT 'T_CELLTAB' OF STRUCTURE <F_WA> TO <T_CELLTAB>
            CLEAR WA_CELLTAB.
            WA_CELLTAB-FIELDNAME = 'MATNR'.
            WA_CELLTAB-STYLE = CL_GUI_ALV_GRID=>MC_STYLE_DISABLED.
            INSERT WA_CELLTAB INTO TABLE <T_CELLTAB>.
    ENDIF.
    APPEND <F_WA> TO <F_TAB>
    ENDLOOP.
    CALL METHOD GR_GRID->SET_TABLE_FOR_FIRST_DISPLAY
            EXPORTING
              I_CONSISTENCY_CHECK  = G_CONSISTENCY_CHECK
              IT_TOOLBAR_EXCLUDING = G_EXCLUDE
              I_SAVE               = G_SAVE
           I_DEFAULT            = 'X'
              IS_LAYOUT            = G_LAYOUT
            CHANGING
              IT_OUTTAB            = <F_TAB>
              IT_FIELDCATALOG      = F_CAT1.
    Please let me know where I was wrong.
    Should I remove the T_CELLTAB as the field name is not mentioned in the structure 'ZCELLTAB'.
    Thanks,
    Kumar.
    Edited by: venn e on May 7, 2010 4:10 PM

  • How to transfer data from a dynamic internal table

    Hi All
    I want to transfer data from a dynamic internal table<dyn_table>
    to a non dynamic internal table itab which should have the same structure as <dyn_table>.
    How can this be done?
    Regards,
    Harshit Rungta

    As stated earlier this can be done only through field symbols...
    You cannot create an non dynamic internal table with ANY structure...using DATA statement
    If the strucutre is defined well and good...you can create an non-dynamic internal table...
    If you do not know the structure then the internal table has to be dynamic...and to be generated using field symbols
    DATA: lv_ref TYPE REF TO data.
    FIELD-SYMBOLS: <fs_dyn_table> TYPE STANDARD TABLE.
    * You create a dynamic internal table...
    CREATE DATA lv_ref LIKE (your_dynamic_internal_table).
    ASSIGN lv_ref->* TO <fs_dyn_table>.
    Now...do the transfer.
    <fs_dyn_table> = "your_dynamic_internal_Table
    Hope it helps!

  • Error while creating a dynamic internal table refers to custom field

    Hi all,
    I am getting the exception TYPE_NOT_FOUND when I try to create a dynamic internal table using:-
    DATA: gr_desc TYPE REF TO cl_abap_typedescr.
    gr_desc = cl_abap_typedescr=>describe_by_name( p_field ).
    The field p_field is a Z-field inside a DB table, (e.g. a user added field in MARA). The statement fails at that point and gives a runtime exception. Any suggestions to how I may solve this problem? Or any alternatives for the same? I guess we face this issue for all custom fields..has SAP released a note for this??
    Thanks..

    that's just the wrong method, you should use DESCRIBE_BY_DATA
    gr_desc = cl_abap_typedescr=>describe_by_data( p_field ).
    Note: DESCRIBE_BY_NAME is to be used for referencing a DDIC type by its name. Example:
    gr_desc = cl_abap_typedescr=>describe_by_name( 'MARA-ZZFIELD' ).

  • Error while creating dynamic internal table.

    Hello Expert,
    While creating a dynamic internal table, it throw an run time error as :
    " LOAD PROGRAM NOT FOUND
      CX_SY_PROGRAM_NOT_FOUND"
    i tried to debug the program, it found this error comes while calling
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    please anyone help me out to resolve this problem.
    what could be the reason of error? and how to avoid it?
    <REMOVED BY MODERATOR>
    thanks in advance.
    ~ shweta.
    Edited by: Alvaro Tejada Galindo on Feb 28, 2008 2:41 PM

    Hi,
    Go through this program.
    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 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.
    Regards,

  • DYNAMIC INTERNAL TABLE CREATION BASED ON THE CONTENT OF ANOTHER INTERNAL TA

    Hi All
    I need to create an internal table at runtime.
    I have a selection screen parameter which is specific to country, Which can take values below
    eg:- IT_AREA for Italy(IT)
    FR_AREA for France(FR)
    IE_AREA for Ireland(IE).....And similary for other countries
    Based on the Above parameter, I need to create Internal Table as below
    DATA: itab TYPE italy_data Occurs 0.
    If I declare as above, Then itab has fields from italy_data. And this internal table i will be sending it to Function Module to get data into it.
    My Requirement is to Create the Internal table itab during runtime for tables italy_data OR france_data OR ireland_data based on selection screen parameter. Tables on Country may have different number of fields in it.
    Can anyone help me on this??

    Hi,
    Here is a sample code to create a dynamic internal table.
    REPORT ytrab03.
    TABLES: mara, makt.
    TYPE-POOLS: slis.
    DATA: it_fcat TYPE slis_t_fieldcat_alv,
    is_fcat LIKE LINE OF it_fcat,
    ls_layout TYPE slis_layout_alv.
    DATA: it_fieldcat TYPE lvc_t_fcat,
    is_fieldcat LIKE LINE OF it_fieldcat.
    DATA: new_table TYPE REF TO data,
    new_line TYPE REF TO data,
    ob_cont_alv TYPE REF TO cl_gui_custom_container,
    ob_alv TYPE REF TO cl_gui_alv_grid,
    vg_campos(255) TYPE c,
    i_campos LIKE TABLE OF vg_campos,
    vg_campo(30) TYPE c,
    vg_tables(60) TYPE c.
    DATA: e_params LIKE zutsvga_alv_01.
    FIELD-SYMBOLS: <l_table> TYPE table,
    <l_line> TYPE ANY,
    <l_field> TYPE ANY.
    PARAMETERS: p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
    is_fcat-fieldname = 'COL01'.
    is_fcat-ref_fieldname = 'MATNR'.
    is_fcat-ref_tabname = 'MARA'.
    APPEND is_fcat TO it_fcat.
    is_fcat-fieldname = 'COL02'.
    is_fcat-ref_fieldname = 'MAKTX'.
    is_fcat-ref_tabname = 'MAKT'.
    APPEND is_fcat TO it_fcat.
    LOOP AT it_fcat INTO is_fcat.
    is_fieldcat-fieldname = is_fcat-fieldname.
    is_fieldcat-ref_field = is_fcat-ref_fieldname.
    is_fieldcat-ref_table = is_fcat-ref_tabname.
    APPEND is_fieldcat TO it_fieldcat.
    CONCATENATE is_fieldcat-ref_table is_fieldcat-ref_field
    INTO vg_campos SEPARATED BY '~'.
    APPEND vg_campos TO i_campos.
    ENDLOOP.
    *... Create the dynamic internal table
    CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
    it_fieldcatalog = it_fieldcat
    IMPORTING
    ep_table = new_table.
    *... Create a new line
    ASSIGN new_table->* TO <l_table>.
    CREATE DATA new_line LIKE LINE OF <l_table>.
    ASSIGN new_line->* TO <l_line>.
    SELECT (i_campos) FROM mara INNER JOIN makt
    ON mara~matnr = makt~matnr
    UP TO p_max ROWS
    INTO TABLE <l_table>.
    LOOP AT <l_table> INTO <l_line>.
    LOOP AT it_fcat INTO is_fcat.
    ASSIGN COMPONENT is_fcat-fieldname
    OF STRUCTURE <l_line> TO <l_field>.
    IF sy-tabix = 1.
    WRITE: /2 <l_field>.
    ELSE.
    WRITE: <l_field>.
    ENDIF.
    ENDLOOP.
    ENDLOOP.
    Regards,
    Karuna.

  • At end of field,  for dynamic internal table entries ?

    Dear All,
    I've data in my dynamic internal table.
    But, to understand in a better way I created a test program with static entries.
    Case 1 -->
    DATA: BEGIN OF itab OCCURS 0,
            year TYPE char4,
            name TYPE char10,
          END OF itab.
    DATA: BEGIN OF itab2 OCCURS 0 ,
            year TYPE char4,
            name TYPE char10,
            count TYPE i,
          END OF itab2.
    DATA: gv_count TYPE i,
          gv_flag TYPE char1.
    itab-name = 'AAAA'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAB'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAC'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAD'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBB'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBA'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBC'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBD'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCC'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCA'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCB'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCD'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCE'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCf'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDD'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDA'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDB'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDC'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDE'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    SORT itab BY year.
    LOOP AT itab.
    * Counter
      gv_count = gv_count + 1.
      AT END OF year.
        itab2-count = gv_count.
        MOVE-CORRESPONDING itab TO itab2.
        APPEND itab2.
        CLEAR gv_count.
        WRITE:/ itab2-name,
        itab2-year,
        itab2-count.
        CLEAR itab2.
        CLEAR gv_flag.
      ENDAT.
    ENDLOOP.
    Now for the above program the Output is :
    Name     Year          Count
    ********** 2005          5
    ********** 2006          6
    ********** 2007          4
    ********** 2008          4
    " Forget about the asterisk values as it's an example !
    The above output is correct, But in my real case the table structure is not like the above .
    The order of the field are in reverse.
    i.e. The internal table is like this :
    Case 2 -->
    DATA: BEGIN OF itab OCCURS 0,
            name TYPE char10,
            year TYPE char4,
          END OF itab.
    DATA: BEGIN OF itab2 OCCURS 0 ,
            name TYPE char10,
            year TYPE char4,
            count TYPE i,
          END OF itab2.
    In this case if I'm using at end of year the output is coming wrong.
    Even on change of is also not working.
    Request you guys to help me out so that I can achieve the same output as of case 1 with the table declaration as of CASE 2.
    Regards,
    Deepu.k

    Hello Rich Heilman,
    Again you came for my rescue ............
    My code for this scenario is like this :
    DATA: BEGIN OF itab OCCURS 0,
            name TYPE char10,
            year TYPE char4,
          END OF itab.
    DATA: BEGIN OF itab2 OCCURS 0 ,
            name TYPE char10,
            year TYPE char4,
            count TYPE i,
          END OF itab2.
    DATA: gv_count TYPE i,
          gv_flag TYPE char1.
    itab-name = 'AAAA'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAB'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAC'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'AAAD'.
    itab-year = '2008'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBB'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBA'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBC'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'BBBD'.
    itab-year = '2007'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCC'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCA'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCB'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCD'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCE'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'CCCf'.
    itab-year = '2006'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDD'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDA'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDB'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDC'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    itab-name = 'DDDE'.
    itab-year = '2005'.
    APPEND itab.
    CLEAR itab.
    SORT itab BY year.
    LOOP AT itab.
    * Counter
      gv_count = gv_count + 1.
      IF sy-tabix GT 1.
        ON CHANGE OF itab-year.
          itab2-count = gv_count.
          MOVE-CORRESPONDING itab TO itab2.
          APPEND itab2.
          CLEAR gv_count.
          WRITE:/ itab2-name,
          itab2-year,
          itab2-count.
          CLEAR itab2.
          CLEAR gv_flag.
        ENDON.
      ENDIF.
    ENDLOOP.
    The Output is :
    DDDC       2005          2
    CCCf       2006          4
    BBBD       2007          6
    AAAD       2008          4
    The above output is wrong.
    Can u correct me where I'm doing wrong ?
    Regards,
    Deepu.K

Maybe you are looking for