Dynamic internal table for ALV output

Hi,
I am looking for a simple & efficient sample code for an ALV report output with dynamic columns. Can someone please help!
Thanks,
JS

Here is a small example. This is pretty old code, and it uses the FM approach.
report zrich_0001.
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.
Have to split this code into two postings to keep formatting.
Regards,
Rich Heilman
Edited by: Rich Heilman on Jun 23, 2009 11:59 AM

Similar Messages

  • Dynamic Internal Table for reading data from external file

    Hello All,
    The task was to create a internal table with dynamic columns,
    Actually this is my first task in the WebAS 6.20, my program is based on input file provided by user with certain effort. this file can have different effort for a one yr to five year frame..
    I needed to read the raw data from file, based on months create a internal table to hold the data, after this i need to validate the data...
    I have browsed thru dynamic internal table topic, but couldn't find any dynamic appending structure, the dynamic structure would contains 12 month fileds.
    can any one help me in getting my task completed..
    Thanks
    Kumar

    Hi,
    I see that you posted the same question a couple of days ago at Dynamic Internal Table for reading data from external file Didn't Charles's response address your problem?
    Regards

  • 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

  • Subtotals in dynamic internal table using alv grid

    hi experts i have created one dynamic table.  The requirement is to display the subtotals in the output using reuse_alv_grid.
    Dynamic itab (field-symbols) and ALV event BEFORE_LINE_OUTPUT
    the above is the thread related and could any one please provide the sample code for this task.
    can any one post the solution for that.
    rewards points will be awarded.
    khazi

    * ASSINING STRUCTURE FOR FILD CATLOGS
    DATA: DYN_TABLE    TYPE REF TO DATA,
          DYN_LINE     TYPE REF TO DATA,
          LS_FIELDCAT TYPE LVC_S_FCAT,
          LT_FIELDCAT TYPE LVC_T_FCAT.
      LOOP AT LT_DMTAB INTO LS_DMTAB.
        CLEAR LS_FIELDCAT.
        LS_FIELDCAT-FIELDNAME = LS_DMTAB-SDATE .
        LS_FIELDCAT-DATATYPE  = 'DEC'.
        LS_FIELDCAT-INTTYPE   = 'P'.
        LS_FIELDCAT-INTLEN    = '16' .
        LS_FIELDCAT-DECIMALS  = '03'.
        LS_FIELDCAT-JUST      = 'C'.
        APPEND LS_FIELDCAT TO LT_FIELDCAT.
      ENDLOOP.
    *& For grouping the table rows for Under Line
      LS_FIELDCAT-FIELDNAME = 'ULFIELD' .
      LS_FIELDCAT-DATATYPE  = 'INT'.
      LS_FIELDCAT-INTTYPE   = 'P'.
      LS_FIELDCAT-INTLEN    = '2' .
      LS_FIELDCAT-DECIMALS  = ''.
      APPEND LS_FIELDCAT TO LT_FIELDCAT.
      "* Create dynamic internal table and assign to Field-Symbol
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG = LT_FIELDCAT
        IMPORTING
          EP_TABLE        = DYN_TABLE.
      IF SY-SUBRC <> 0.
        MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                  WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      ASSIGN DYN_TABLE->* TO <LT_AREA_F>.
      "* Create dynamic work area and assign to Field Symbol
      CREATE DATA DYN_LINE LIKE LINE OF <LT_AREA_F>.
      ASSIGN DYN_LINE->* TO <LS_AREA_F>.
    You check in Field cat level you will get  Check Sub total field will exist
    Thanks and regards
    Jogu

  • Passing dynamic internal table into ALV

    I have made one ALV report where i had created one button 'GENERATE'.  ON CLICKING THIS BUTTON the data in the ALV report is downloaded to excel file.
    i have used this:-
    CALL METHOD cl_gui_frontend_services=>file_save_dialog
        EXPORTING
          window_title         = l_title
          default_extension    = 'XLS'
          initial_directory    = 'C:\'
        CHANGING
          filename             = filename
          path                 = path
          fullpath             = fullpath
          user_action          = user_action
        EXCEPTIONS
          cntl_error           = 1
          error_no_gui         = 2
          not_supported_by_gui = 3
          OTHERS               = 4.
      IF sy-subrc <> 0.
        EXIT.
      ENDIF.
    Check which button is pressed
      IF user_action <> cl_gui_frontend_services=>action_ok.
        EXIT.
      ENDIF.
    Download error data collected from the internal table
      CALL METHOD cl_gui_frontend_services=>gui_download
        EXPORTING
          filename                = fullpath
          filetype                = 'ASC'
          write_field_separator   = '#'
         codepage                = '4103'
         write_bom               = c_true
        CHANGING
          data_tab                = gi_final
        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
          not_supported_by_gui    = 22
          error_no_gui            = 23
          OTHERS                  = 24.
    If selection is successful
      IF sy-subrc EQ 0.
        MESSAGE s004 . " File  created successfully
      ELSE.
        MESSAGE i005 . " File is not created successfully
      ENDIF.
    In the table i have passed the internal table . this is working fine.
    <b>But,
    The problem is if i want to display the data in diferent layout based on selection screen criteria the data downloaded are same as default layout.
    how to pass a dynamic internal table in the
    CALL METHOD cl_gui_frontend_services=>gui_download</b>

    Hi    ,
    here is the Program for  Download  
    REPORT yrs_download_transport_request.
    PARAMETERS:
      p_reqest TYPE trkorr OBLIGATORY,
      p_folder(255) TYPE c LOWER CASE, p_sepr OBLIGATORY.
    DATA:
      folder TYPE string,
      retval LIKE TABLE OF ddshretval WITH HEADER LINE,
      fldvalue LIKE help_info-fldvalue,
      transdir TYPE text255,
      filename(255),
      trfile(20) TYPE c,
      datatab TYPE TABLE OF text8192 WITH HEADER LINE,
      len TYPE i,
      flen TYPE i.
    TYPE-POOLS: sabc, stms, trwbo.
    INITIALIZATION.
      CONCATENATE sy-sysid 'K*' INTO p_reqest.
      IF sy-opsys = 'Windows NT'.
        p_sepr = ''.
      ELSE.
        p_sepr = '/'.
      ENDIF.
    *  CALL FUNCTION 'WSAF_BUILD_SEPARATOR'
    *       IMPORTING
    *            separator                  = p_sepr
    *       EXCEPTIONS
    *            separator_not_maintained   = 1
    *            wrong_call                 = 2
    *            wsaf_config_not_maintained = 3
    *            OTHERS                     = 4.
    *  IF sy-subrc NE 0.
    *    MESSAGE s001(00)
    *      WITH
    *      'Unable to find out the separator symbol for the system.'(011).
    *  ENDIF.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_reqest.
      DATA:
        tt_system TYPE TABLE OF tmscsys WITH HEADER LINE,
        es_selected_request TYPE trwbo_request_header,
        es_selected_task TYPE trwbo_request_header,
        iv_organizer_type TYPE trwbo_calling_organizer,
        is_selection TYPE trwbo_selection.
      iv_organizer_type = 'W'. is_selection-reqstatus = 'R'.
      CALL FUNCTION 'TR_PRESENT_REQUESTS_SEL_POPUP'
        EXPORTING
          iv_organizer_type   = iv_organizer_type
          is_selection        = is_selection
        IMPORTING
          es_selected_request = es_selected_request
          es_selected_task    = es_selected_task.
      p_reqest = es_selected_request-trkorr.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_folder.
      DATA: title TYPE string.
      title = 'Select target folder'(005).
      CALL METHOD cl_gui_frontend_services=>directory_browse
        EXPORTING
          window_title    = title
        CHANGING
          selected_folder = folder
        EXCEPTIONS
          cntl_error      = 1
          error_no_gui    = 2
          OTHERS          = 3.
      CALL FUNCTION 'CONTROL_FLUSH'
        EXCEPTIONS
          cntl_system_error = 1
          cntl_error        = 2
          OTHERS            = 3.
      p_folder = folder.
    AT SELECTION-SCREEN ON p_reqest.
      DATA: request_info TYPE stms_wbo_request,
            request_infos TYPE stms_wbo_requests.
      REFRESH request_infos.
      CALL FUNCTION 'TMS_MGR_READ_TRANSPORT_REQUEST'
        EXPORTING
          iv_request                 = p_reqest
          iv_header_only             = 'X'
        IMPORTING
          et_request_infos           = request_infos
        EXCEPTIONS
          read_config_failed         = 1
          table_of_requests_is_empty = 2
          system_not_available       = 3
          OTHERS                     = 4.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
                WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CLEAR request_info.
      READ TABLE request_infos INTO request_info INDEX 1.
      IF sy-subrc NE 0
      OR request_info-e070-trkorr IS INITIAL.
        MESSAGE e398(00) WITH 'Request'(006) p_reqest 'not found'(007).
      ELSEIF request_info-e070-trstatus NE 'R'.
        MESSAGE e398(00)
        WITH 'You must release request'(008)
             request_info-e070-trkorr
             'before downloading'(009).
      ENDIF.
    START-OF-SELECTION.
      folder = p_folder.
      CONCATENATE p_reqest+3(7) '.' p_reqest(3) INTO trfile.
      CALL FUNCTION 'RSPO_R_SAPGPARAM'
        EXPORTING
          name   = 'DIR_TRANS'
        IMPORTING
          value  = transdir
        EXCEPTIONS
          error  = 0
          OTHERS = 0.
      PERFORM copy_file USING 'cofiles' trfile.
      trfile(1) = 'R'.
      PERFORM copy_file USING 'data' trfile.
      trfile(1) = 'D'.
      PERFORM copy_file USING 'data' trfile.
    * FORM copy_file *
    * --> SUBDIR * * --> FNAME *
    FORM copy_file USING subdir fname.
      DATA:
        auth_filename TYPE authb-filename,
        gui_filename TYPE string.
      CONCATENATE transdir subdir fname
        INTO filename
        SEPARATED BY p_sepr.
      REFRESH datatab.
      CLEAR flen.
      auth_filename = filename.
      CALL FUNCTION 'AUTHORITY_CHECK_DATASET'
        EXPORTING
          activity         = sabc_act_read
          filename         = auth_filename
        EXCEPTIONS
          no_authority     = 1
          activity_unknown = 2
          OTHERS           = 3.
      IF sy-subrc <> 0.
        FORMAT COLOR COL_NEGATIVE.
        WRITE: / 'Read access denied. File'(001),
                  filename.
        FORMAT COLOR OFF. EXIT.
      ENDIF.
      OPEN DATASET filename FOR INPUT IN BINARY MODE.
      IF sy-subrc NE 0.
        FORMAT COLOR COL_TOTAL.
        WRITE: / 'File open error'(010), filename.
        FORMAT COLOR OFF. EXIT.
      ENDIF.
      DO.
        CLEAR len.
        READ DATASET filename INTO datatab LENGTH len.
        flen = flen + len.
        IF len > 0. APPEND datatab. ENDIF.
        IF sy-subrc NE 0.
          EXIT.
        ENDIF.
      ENDDO.
      CLOSE DATASET filename.
      CONCATENATE p_folder '' fname INTO gui_filename.
      CALL METHOD cl_gui_frontend_services=>gui_download
        EXPORTING
          bin_filesize            = flen
          filename                = gui_filename
          filetype                = 'BIN'
        CHANGING
          data_tab                = datatab[]
        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                  = 24.
      IF sy-subrc = 0.
        WRITE: / 'File'(002), filename, 'downloaded. Length'(003), flen.
      ELSE.
        FORMAT COLOR COL_NEGATIVE.
        WRITE: / 'File download error. Filename:'(004), filename.
        FORMAT COLOR OFF.
      ENDIF.
    ENDFORM. "copy_file
    Reward  points if it is usefull....
    Girish

  • Passing the Dynamic Internal Table as the Output Parameter of the FM...

    Hi,
    How can we pass the internal table as the output from the Function Module TABLES parameter.
        SELECT * FROM TVRO BYPASSING BUFFER INTO TABLE <ltable>.
    Now I need to pass the dynamic internal table <ltable> as the output in the function module.
    Thanks!
    Puneet.

    I can't use TVRO as the table type. The Table name is as the Input. This program will download the contents of the table and create an app server file. It can be for any database table.
    so i want the output of this FM should be the data from that table. So what should be the TABLE type.
    like in  a program i will use:::
      FIELD-SYMBOLS: <ltable> TYPE ANY TABLE,
                     <l_line> TYPE ANY,
                     <l_field> TYPE ANY.
        SELECT * FROM (p_table) BYPASSING BUFFER INTO TABLE <ltable>.
    That is my requirement.

  • Two Internal Tables for ALV Grid

    Hi Gurus,
    I have a little problem here. I have a report to display cost of production. The rows is about 50 displaying amount in dollars (currency fields). I have this in ALV Grid. But my problem is that the last 4 lines of the report are not currency fields like the others, they are quantity fields.
    How can i go about to display this last 4 lines in this ALV Grid. They are from different internal tables off course because of the data type.
    In short. I just want to display these 2 internal tables in an ALV Grid.
    Thanks in Advance.

    Hi,
    u can use ALV Block list to display 2 ALV.
    Reffer to the below code.
    DATA: v_layout TYPE slis_layout_alv.
      DATA: ls_print TYPE slis_print_alv.
      PERFORM build_fieldcatalog.
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_INIT'
        EXPORTING
          i_callback_program             = sy-repid
    *     I_CALLBACK_PF_STATUS_SET       = ' '
    *     I_CALLBACK_USER_COMMAND        = ' '
    *     IT_EXCLUDING                   =
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
        EXPORTING
          is_layout                        = v_layout
          it_fieldcat                      = it_fcat_nlei
          i_tabname                        = 'IT_NLEI_ALV'
          it_events                        = it_event_nlei
    *     IT_SORT                          =
    *     I_TEXT                           = ' '
        TABLES
          t_outtab                         = it_nlei_alv
        EXCEPTIONS
          program_error                    = 1
          maximum_of_appends_reached       = 2
          OTHERS                           = 3.
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_APPEND'
        EXPORTING
          is_layout                        = v_layout
          it_fieldcat                      = it_fcat_vbrp
          i_tabname                        = 'IT_VBRP_ALV'
          it_events                        = it_event_vbrp
    *     IT_SORT                          =
    *     I_TEXT                           = ' '
        TABLES
          t_outtab                         = it_vbrp_alv
       EXCEPTIONS
         program_error                    = 1
         maximum_of_appends_reached       = 2
         OTHERS                           = 3.
      ls_print-no_print_selinfos  = 'X'.   " Display no selection infos
      ls_print-no_print_listinfos = 'X'.   " Display no listinfos
      ls_print-reserve_lines      = 2.     " Lines reserved for end of page
      CALL FUNCTION 'REUSE_ALV_BLOCK_LIST_DISPLAY'
        EXPORTING
    *     I_INTERFACE_CHECK             = ' '
          is_print                      = ls_print
    *     I_SCREEN_START_COLUMN         = 0
    *     I_SCREEN_START_LINE           = 0
    *     I_SCREEN_END_COLUMN           = 0
    *     I_SCREEN_END_LINE             = 0
    *   IMPORTING
    *     E_EXIT_CAUSED_BY_CALLER       =
    *     ES_EXIT_CAUSED_BY_USER        =
       EXCEPTIONS
         program_error                 = 1
         OTHERS                        = 2

  • Dynamic internal table Created from current classic ALV layout?

    Hi,
    Currently I have a dynamic ALV column output who's number of columns is dependent on t_output.
    ALV Sample:
    MANTR    WK1   WK2  WK3 ...
    10001        10       20      30
    10002        5         10      15
    I see this option, Get the ALV output, so this includes the header column name and its corresponding entries (which is easier.
    Question here: How can I create a dynamic internal table for it_fieldcat  of my ALV?  Is there any FM or method?
    If it will be a method, can you provide more details (I'm not that much yet familiar with method concept in ABAP)
    *Note: I am not creating a dynamic table out of SELECT statements
    Thanks.
    Regards,
    Jaime

        PERFORM f_0600-init_alv_layout     USING t_alv_layout.
        PERFORM f_0700-init_field_catalog  USING t_alv_fcat[]. "Populates the ALV Field Catalog
        PERFORM f_0800-build_alv_comment   USING t_alv_list_top_of_page[]. "title header of the report
        PERFORM f_0900-fill_alv_sort_fields.
        PERFORM f_1000-build_alv_display.
    FORM f_0700-init_field_catalog USING us_vit_alv_fcat1 TYPE slis_t_fieldcat_alv.
      DATA:  w_vit_alv_fcat TYPE slis_fieldcat_alv.
      CLEAR w_vit_alv_fcat.
      MOVE : c_vit_output TO w_vit_alv_fcat-tabname,
             c_matnr      TO w_vit_alv_fcat-fieldname,
             c_material   TO w_vit_alv_fcat-seltext_l,
             c_x          TO w_vit_alv_fcat-fix_column,
             c_x          TO w_vit_alv_fcat-key.
      APPEND w_vit_alv_fcat TO us_vit_alv_fcat1.
      CLEAR w_vit_alv_fcat.
      MOVE : c_vit_output   TO w_vit_alv_fcat-tabname,
             c_maktx        TO w_vit_alv_fcat-fieldname,
             c_material_dis TO w_vit_alv_fcat-seltext_l.
      APPEND w_vit_alv_fcat TO us_vit_alv_fcat1.
      CLEAR: w_vit_alv_fcat.
      MOVE : c_vit_output   TO w_vit_alv_fcat-tabname,
             c_meins        TO w_vit_alv_fcat-fieldname,
             c_uom TO w_vit_alv_fcat-seltext_l.
      APPEND w_vit_alv_fcat TO us_vit_alv_fcat1.
      CLEAR: w_vit_alv_fcat.
      MOVE : c_vit_output   TO w_vit_alv_fcat-tabname,
             c_lifnr        TO w_vit_alv_fcat-fieldname,
             c_vendor       TO w_vit_alv_fcat-seltext_l.
      APPEND w_vit_alv_fcat TO us_vit_alv_fcat1.
      CLEAR w_vit_alv_fcat.
      MOVE : c_vit_output TO w_vit_alv_fcat-tabname,
             c_name1      TO w_vit_alv_fcat-fieldname,
             c_vendorname TO w_vit_alv_fcat-seltext_l.
      APPEND w_vit_alv_fcat TO us_vit_alv_fcat1.
      CLEAR w_vit_alv_fcat.
      MOVE : c_vit_output TO w_vit_alv_fcat-tabname,
             c_dispo      TO w_vit_alv_fcat-fieldname,
             c_mrp_cont   TO w_vit_alv_fcat-seltext_l.
      APPEND w_vit_alv_fcat TO us_vit_alv_fcat1.
      CLEAR w_vit_alv_fcat.
      MOVE : c_vit_output TO w_vit_alv_fcat-tabname,
             c_stprs      TO w_vit_alv_fcat-fieldname,
             c_std_price  TO w_vit_alv_fcat-seltext_l.
      APPEND w_vit_alv_fcat TO us_vit_alv_fcat1.
      CLEAR w_vit_alv_fcat.
      MOVE : c_vit_output TO w_vit_alv_fcat-tabname,
             c_st_pck     TO w_vit_alv_fcat-fieldname,
             c_st_pck_sz  TO w_vit_alv_fcat-seltext_l.
      APPEND w_vit_alv_fcat TO us_vit_alv_fcat1.
      CLEAR w_vit_alv_fcat.
      MOVE : c_vit_output TO w_vit_alv_fcat-tabname,
             c_kanban     TO w_vit_alv_fcat-fieldname,
             c_kanbanqty  TO w_vit_alv_fcat-seltext_l.
      APPEND w_vit_alv_fcat TO us_vit_alv_fcat1.
    * To display 26 weeks historical consumptions:
      CLEAR w_vit_alv_fcat.
      UNASSIGN <fs_hwk_date>.
      LOOP AT t_hwk_date ASSIGNING <fs_hwk_date>.
        MOVE c_vit_output TO w_vit_alv_fcat-tabname.
        CONCATENATE c_hwk <fs_hwk_date>-calender_wk
        INTO         w_vit_alv_fcat-seltext_l.
        CONCATENATE c_hwk <fs_hwk_date>-index
        INTO         w_vit_alv_fcat-fieldname.
        APPEND w_vit_alv_fcat TO us_vit_alv_fcat1.
      ENDLOOP.
    Edited by: Jaime Cabanban Jr on Apr 24, 2009 3:06 PM

  • To pass internal table data(including subtotal) to dynamic internal table

    here i am displaying the dynamic internal table in alv grid.
    i followed like this but i am unable to get the subtotal form the internal table.
    LOOP AT ITAB1. " assigning <fs_itab1>.
        ASSIGN COMPONENT 'RACCT' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
        <DYN_FIELD> = ITAB1-RACCT.
        ASSIGN COMPONENT 'ERGSL' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
        <DYN_FIELD> = ITAB1-ERGSL.
        ASSIGN COMPONENT 'TEXT' OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
        <DYN_FIELD> = ITAB1-TEXT.
        I = 4.
        CLEAR COMP_ITAB.
        LOOP AT COMP_ITAB.
          ASSIGN COMPONENT I OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
         LOOP AT ITAB WHERE RACCT = ITAB1-RACCT.
           IF ITAB-RBUKRS EQ COMP_ITAB-RBUKRS.
          IF ITAB1-RBUKRS EQ COMP_ITAB-RBUKRS.
            <DYN_FIELD> = ITAB1-REPVAL.
            SUB_TOT = ITAB1-REPVAL.
          ELSE.
            <DYN_FIELD> = 0.
            SUB_TOT = 0.
          ENDIF.
         ENDLOOP.
          I = I + 1.
          TOTAL = TOTAL + SUB_TOT.
        ENDLOOP.
        ASSIGN COMPONENT I OF STRUCTURE <DYN_WA> TO <DYN_FIELD>.
        <DYN_FIELD> = TOTAL.
        APPEND <DYN_WA> TO <DYN_TABLE>.
        CLEAR <DYN_WA>.
        TOTAL = 0.
      ENDLOOP.
    Thanks,
    sridhar.

    Hi Rakesh,
    We pass internal tables for the smartform are shown in bold in below code,
    CALL FUNCTION LF_FM_NAME
        EXPORTING
          ARCHIVE_INDEX      = TOA_DARA
          ARCHIVE_PARAMETERS = ARC_PARAMS
          CONTROL_PARAMETERS = LS_CONTROL_PARAM
          MAIL_RECIPIENT     = LS_RECIPIENT
          MAIL_SENDER        = LS_SENDER
          OUTPUT_OPTIONS     = LS_COMPOSER_PARAM
          USER_SETTINGS      = ' '               
          ZXEKKO             = L_DOC-XEKKO
          ZXPEKKO            = L_DOC-XPEKKO
          ZNAST              = NAST
        IMPORTING
          DOCUMENT_OUTPUT_INFO = IT_DOCUMENT
          JOB_OUTPUT_INFO      = IT_OUTPUT_INFO
          JOB_OUTPUT_OPTIONS   = IT_JOB_OUTPUT
        <b>TABLES
          L_XEKPO            = L_DOC-XEKPO[]
          L_XEKPA            = L_DOC-XEKPA[]
          L_XPEKPO           = L_DOC-XPEKPO[]
          L_XEKET            = L_DOC-XEKET[]
          L_XTKOMV           = L_DOC-XTKOMV[]
          L_XEKKN            = L_DOC-XEKKN[]
          L_XEKEK            = L_DOC-XEKEK[]
          L_XKOMK            = L_XKOMK</b>  
    EXCEPTIONS
          FORMATTING_ERROR   = 1
          INTERNAL_ERROR     = 2
          SEND_ERROR         = 3
          USER_CANCELED      = 4
          OTHERS             = 5.
    Regards,
    Azaz Ali.

  • Need ALV LIST for displaying Dynamic Internal Tables

    Hi Guys,
                     I have some thing like 2 Dynamic internal tables.
    Say 1st Internal table will be filled based on some condition.
    say 2nd table will be filled based on some condition.
    When appending the 1st Internal table, if that internal table is filled it creates another internal table of same kind and continues so on until some condition.
    In the same way when appending the 2nd Internal table, if that internal table is filled it creates another internal table of same kind and continues so on until some condition.
    My requirement is I need to display all these Internal tables in the output.
    The output should look something like
    1st Internal Table
    some gap
    2nd Internal Table
    some gap
    so on...................
    Is there any standard ALV List, to display all these Internal Tables in such a way.
    Thanks,
    Prasad.

    Hi.
    One thing more here is code which get 10 records from 2 tables and then show them in ALV.
    first when u execute it will show data from ist table.
    when u go back (F3) then it will sow data from 2nd table.
    But if u want to show both ALV on the same screen then u will have to use screen programin and using class u will have to create container and then have to do it.
    But as i above mentioned. that sample code is as below.
    REPORT ztn_test LINE-COUNT 100.
      data: itab_ref type ref to data.
      data: hstr type lvc_title.
    data: tabname like DD02T-TABNAME.
       tabname = 'MARA'. " First Table
      create data itab_ref type standard table of (tabname).
      field-symbols: <itab> type standard table.
      assign itab_ref->* to <itab>.
      select * UP TO 10 ROWS from (tabname) into corresponding fields of table <itab>.
      perform showalv.
       tabname = 'KNA1'. " 2nd Table
      create data itab_ref type standard table of (tabname).
      "field-symbols: <itab> type standard table.
      assign itab_ref->* to <itab>.
      select * UP TO 10 ROWS from (tabname) into corresponding fields of table <itab>.
      perform showalv.
    form showalv.
    " to show that data in alv
      type-pools: slis.
      data: myalv type ref to cl_gui_alv_grid,    "ALV Grid
            fieldcat type slis_t_fieldcat_alv,    "Field Catalog Table
            ls_fcat type slis_fieldcat_alv,       "Line of Field catalog.
            ls_heading type slis_listheader,      "Line of Heading.
            layout type slis_layout_alv,          "layout of ALV for Heading and Logo.
            event type slis_t_event,              "Event Raising to Display Heading.
            event_str type slis_alv_event.        "Event String.
    type-pools: slis.
    data: heading type slis_t_listheader.       "List Heading.
      if heading[] is initial.
        ls_heading-typ = 'H'.
        ls_heading-info = 'HR: Master Data Change History'.
        append ls_heading to heading.
      endif.
    *  ls_heading-typ = 'A'.
    *  ls_heading-info = ''.
    *  APPEND ls_heading TO heading.
    *                          ALV DISPLAY                        *
    *******Making Layout of ALV
      layout-zebra = 'X'.
      layout-colwidth_optimize = 'X'.
    *Calling function to raise event to display heading and icon above ALV
      call function 'REUSE_ALV_EVENTS_GET'
       exporting
         i_list_type           = 0
       importing
         et_events             = event[]
    * EXCEPTIONS
    *   LIST_TYPE_WRONG       = 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.
    ******calling TOP_OF_PAGE Event
      read table event with key name = 'TOP_OF_PAGE' into event_str.
      if sy-subrc = 0.
        move: 'TOP_OF_PAGE' to event_str-form.
        modify event from event_str index sy-tabix.
      endif.
    **** Now use this Fuction to display ALV without any Screen Programming.
      call function 'REUSE_ALV_GRID_DISPLAY'
       exporting
    *   I_INTERFACE_CHECK                 = ' '
    *   I_BYPASSING_BUFFER                = ' '
    *   I_BUFFER_ACTIVE                   = ' '
         i_callback_program                = 'SAPLZFSL_HR_UTILS' "sy-cprog
    *   I_CALLBACK_PF_STATUS_SET          = ' '
    *   I_CALLBACK_USER_COMMAND           = ' '
    *   I_CALLBACK_TOP_OF_PAGE            = ' '
    *   I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
    *   I_CALLBACK_HTML_END_OF_LIST       = ' '
         i_structure_name                  = tabname
    *   I_BACKGROUND_ID                   = ' '
         i_grid_title                      = hstr   "Heading of ALV Grid.
    *   I_GRID_SETTINGS                   =
         is_layout                         = layout
    *   it_fieldcat                       = fieldcat[]
    *   IT_EXCLUDING                      =
    *   IT_SPECIAL_GROUPS                 =
    *   IT_SORT                           =
    *   IT_FILTER                         =
    *   IS_SEL_HIDE                       =
         i_default                         = 'X'
         i_save                            = 'X'
    *   IS_VARIANT                        =
         it_events                         = event[]
    *   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                          = <itab>
    * 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.

  • Problem with grid display in ALV for dynamic internal tables

    Hi,
    I am using dynamic internal tables in my program. To display it in grid format after populating it, I have used the following class and method. Here Im getting sy-subrc = 0 but, the grid is not getting displayed. Can some one pls help me with this.,
    DATA: W_GRID TYPE REF TO CL_GUI_ALV_GRID.
    DATA: w_tabname TYPE w_tabname.
    CREATE OBJECT W_GRID
    EXPORTING I_PARENT = CL_GUI_CONTAINER=>SCREEN0.
    CALL METHOD W_GRID->SET_TABLE_FOR_FIRST_DISPLAY
      EXPORTING
       I_BUFFER_ACTIVE               =
       I_BYPASSING_BUFFER            =
       I_CONSISTENCY_CHECK           =
        I_STRUCTURE_NAME              = W_TABNAME
       IS_VARIANT                    =
       I_SAVE                        =
       I_DEFAULT                     = 'X'
       IS_LAYOUT                     =
       IS_PRINT                      =
       IT_SPECIAL_GROUPS             =
       IT_TOOLBAR_EXCLUDING          =
       IT_HYPERLINK                  =
       IT_ALV_GRAPHICS               =
       IT_EXCEPT_QINFO               =
       IR_SALV_ADAPTER               =
      CHANGING
        IT_OUTTAB                     = <FS_1>
        IT_FIELDCATALOG               = LT_FIELDCATALOG2
       IT_SORT                       =
       IT_FILTER                     =
      EXCEPTIONS
        INVALID_PARAMETER_COMBINATION = 1
        PROGRAM_ERROR                 = 2
        TOO_MANY_LINES                = 3
        others                        = 4
    IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
               WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Here, <FS_1> is the field symbol of table type and it holds all my data. and LT_FIELDCATALOG2  is the structure of my fieldcatalog
    Thanks and Regards,
    Avinash

    Hi Avinash,
    Either use parameter
    I_STRUCTURE_NAME = W_TABNAME
    or
    IT_FIELDCATALOG = LT_FIELDCATALOG2
    Both are not required.
    At the end of ur program simply use a write statement like below. Your program will work.
    IF SY-SUBRC 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
    WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    Write /.      <----
    Thanks,
    Edited by: Sap Fan on Oct 6, 2009 7:17 AM

  • To create a deep structure for dynamic internal table.

    Hello
    My ALV has fields which are defined dynamically during execution.
    so, i did it in the following way,
    Declared Field symbolds, DREF and fieldcatalog as,
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,
                  <fs_dyntable>.
    DATA:   dref_dyntab    TYPE REF TO data,
            dref_dynwa     TYPE REF TO data.
    DATA: ts_fieldcatalog TYPE lvc_t_fcat.
    DATA: wa_fieldcatalog TYPE lvc_s_fcat.
    Updated Fieldcatalog dynamically as,
    *function module to read segment structure
        CALL FUNCTION 'SEGMENT_READ'
          EXPORTING
            segmenttyp           = v_segment_name
          TABLES
            segmentstructure     = ts_seg_structure
          EXCEPTIONS
            no_authority         = 1
            segment_not_existing = 2
            OTHERS               = 3.
        IF sy-subrc <> 0.
          CASE sy-subrc.
            WHEN '1'.
              MESSAGE e024.
              STOP.
            WHEN '2'.
              MESSAGE e025 WITH v_segment_name.
              STOP.
            WHEN OTHERS.
              MESSAGE e023.
          ENDCASE.
        ENDIF.
    *FETCH FIELDS FROM STRUCTURE OF SEGMENT AND CREATE FIELDCATALOG FOR
    EACH FIELD OF SEGMENT (DYNAMIC FIELD CATALOG)
        LOOP AT ts_seg_structure INTO wa_seg_structure.
          ADD 1 TO v_counter.
          wa_fieldcatalog-fieldname = wa_seg_structure-fieldname.
          wa_fieldcatalog-col_pos   = v_counter.
          wa_fieldcatalog-ref_table = wa_seg_structure-segtyp.
          APPEND wa_fieldcatalog TO ts_fieldcatalog.
          CLEAR wa_fieldcatalog.
        ENDLOOP.
    and generated dynamic internal table using fieldcatalog as,
    *--Method to get the structure of table using fieldcatalog.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = ts_fieldcatalog
        IMPORTING
    *--Variable of type REF TO DATA.
          ep_table        = dref_dyntab.
      IF sy-subrc <> 0.
        MESSAGE e023.
      ENDIF.
    *--Dynamic internal tables required when show segments selected
      IF p_selseg IS NOT INITIAL.
        ASSIGN dref_dyntab->* TO <t_dyntable>.
    *--Create dynamic work area and assign to FS
      CREATE DATA dref_dynwa LIKE LINE OF <t_dyntable>.
        ASSIGN dref_dynwa->* TO <fs_dyntable>.
    And then i populated this <t_dyntable> which is being passed as data-table to method
    CL_GUI_ALV_GRID => SET_TABLE_FOR_FIRST_DISPLAY
    for ALV grid Display along with above used filedcatalog ts_fieldcatalog.
    Things are fine till here, but now i have the requirement to edit selected rows of the ALV display..
    As you might be aware, we need a field
            TS_STYLEROW  TYPE lvc_t_styl, (i.e, a field of type 'h' and we can say as an internal table inside an internal table or else as a deep structure)
    in the output internal table <t_dyntable> to meet our requirement.
    My issue is about declaring one such field of type 'h' in this dynamically created internal table ''<t_dyntable>".
    I tried in the following way by adding one such field to fieldcatalog :
    *Field for Styling
      ADD 1 TO v_counter.
      wa_fieldcatalog-fieldname   = 'TS_STYLEROW'.
      wa_fieldcatalog-tabname     = 'TS_STYLE'.
      wa_fieldcatalog-col_pos     = v_counter.
      wa_fieldcatalog-no_out      = 'X'.
      wa_fieldcatalog-inttype     = 'h'.      " I even mentioned this
      APPEND wa_fieldcatalog TO ts_fieldcatalog.
      CLEAR  wa_fieldcatalog.
    But this is creating a field of type 'C' in the table <t_dyntable> instead of what i was expecting
    Guyz and respected,
    Please advice me with the solution or ur ideas....
    Note : The overall requirement is create a deep structure for dynamically generated internal table.
    Your help is highly appreciated and unforgettable..!!!!!!!

    hi,
    Dynamic append
    Dynamic internal table
    Dynamic internal table
    dynamic columns in ALV
    Variant for dynamic selection
    thanks

  • ALV rows to column dynamic internal table

    Hello People ,
    I am stuck in a report which displays an output in ALV as follows :-
    bukrs | kntyp | konto | knfix  | period     | element    | emeng  | emein
    1000  | 10      | 1100 | berlin | 11.2011  |      AG      |  0.148    | kgAG
    1000  | 10      | 1100 | berlin | 11.2011  |      AU      | 0.104    | kgAU
    1000  | 10      | 1100 | berlin | 11.2011  |      GA     | 0.207    | kgGA
    And this table has many values corresponding to element AG,AU and GA respectively . For example , there would be many element AG's with many "EMENG" values . Similarly for AU and GA .
    MY question :- I am asked to make AG , AU , GA as 3 different fields which should show the value "EMENG" under respective elements . Like :-
    bukrs | kntyp | konto | knfix  | period     |   AG       |   AU      |  GA     |    emein
    1000  | 10      | 1100 | berlin | 11.2011  |   0.148    |   0.104  |  0.207 |    kgAG
    That should be my output . ( elements replaced by AG , AU and GA which comes from a Metal table ZXXXX where
    metal no. 1 = AU
    metal no. 2 = AG
    metal no. 3 = GA
    If there is any metal added to it would be metal no. 4 ,5,6,7 .... so on ) and then that should be added as a field in our report .. So that has to be DYNAMIC .
    I am unable to move on with problem . Pls suggest ? I am pasting my report here ...
    FORM select_table_gt_bb CHANGING p_gt_bb.
      TABLES : zpam_as .
      DATA : i_zpam_as TYPE TABLE OF zpam_as ,
             wa_zpam_as LIKE LINE OF i_zpam_as ,
             i_tcurr TYPE TABLE OF tcurr ,
             wa_tcurr LIKE LINE OF i_tcurr,
             zt_as TYPE TABLE OF zpam_as.
      SELECT * FROM zpam_as INTO TABLE gt_as
             WHERE bukrs   EQ bukrs
               AND kntyp   IN kntyp
               AND konto   IN konto
               AND knfix   IN knfix
               AND buper   IN buper
               AND element IN element
               AND ameng   IN ameng
               AND ashkz   IN ashkz
               AND emeng   IN emeng
               AND eshkz   IN eshkz
               AND emein   IN emein.
      SELECT * FROM zpam_tcurr INTO TABLE gt_tcurr.
      IF sy-subrc IS INITIAL.
        LOOP AT gt_tcurr INTO gw_tcurr.
         SELECT * FROM tcurr INTO wa_tcurr WHERE fcurr = gw_tcurr-fcurr AND
         tcurr = tcurr.
          ENDSELECT.
          APPEND wa_tcurr TO i_tcurr.
          DELETE ADJACENT DUPLICATES FROM i_tcurr.
        ENDLOOP.
      ENDIF.
      IF i_tcurr IS NOT INITIAL.
        LOOP AT gt_as INTO gw_as.
    CLEAR sy-subrc.
    LOOP AT i_tcurr
    INTO wa_tcurr
    WHERE   fcurr = gw_as-emein.
            gw_as-tcurr = wa_tcurr-tcurr.
            gw_as-ukurs = wa_tcurr-ukurs.
            gw_as-total = abs( gw_as-emeng ) * wa_tcurr-ukurs.
            APPEND gw_as TO zt_as.
          ENDLOOP.
          IF sy-subrc <> 0.
            gw_as-tcurr = 'None'.
            gw_as-ukurs = ''.
            gw_as-total = ''.
            APPEND gw_as TO zt_as.
          ENDIF.
        ENDLOOP.
        REFRESH gt_as.
        LOOP AT zt_as INTO gw_as.
          APPEND gw_as TO gt_as.
        ENDLOOP.
      ENDIF.
    ENDFORM.
    Priority normalized
    Edited by: Rob Burbank on Dec 28, 2011 3:44 PM

    Hey,
    But after understanding my question correctly , you sure that dynamic internal table is the solution for it ?

  • 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

  • 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

  • What is the best way to stack DAQ aquired data in labview?

    I'm developing an application to work with an M-series daq card and labview 8.5 to output a signal and then record on 8 differential inputs for a short period of time (~10 ms). I need to stack my data, however, because the incoming signal will be ver

  • Problem with opening of the file in CV03N

    Hi, I had the file in DIR as I check in CV03N, I am not able to open the file. help is appreciated in finding what may be the problem. Regards,

  • How to fire a schema trigger from outside the schema

    A user is using an ad hoc tool similar to SQL Developer called PeopleSoft Application Designer. He creates a connection to the db, then issues an alter session set current_schema = 'restricted_schema'. The connected user does not have direct privileg

  • Events in cwgraph Control array

    I have created a control array of cwgraph at run time. Now all the properties are accesible but I am unable to fire events (with index) on cwgraph.... please help.

  • Password Reset on Device

    How do I reset my password on my device?