Dynamic Columms in ALV

Hello.
Can I help me, please!
I have a ALV that has the columns dynamics. Ie, I have a field BURKS (COMPANY) where a set interval. This field is a column of the ALV.
I seem that so many columns BURKS, how I Raisedin the range.
If I put 3 company in screen should appear 3 columms in ALV. If I put  20, should appear 20 columms in ALV for filed BURKS.
Thanks,
Márcia.

Hi,
Welcome to SDN.
By default create your output table with maximum number of field BUKRS. say for example
data : begin of i_output occurs 0.
data : matnr like mara-matnr.
data : bukrs1 like t001w-bukrs.
data : bukrs2 like t001w-bukrs.
data : bukrs100 like t001w-bukrs.
data : end of i_output.
according to your selection screen no of bukrs, at the time of creating field catalog put NO_OUT for balance of bukrs you do not want to display and pass your field catalog and i_output to set_table_first_display method.
or create a dynamic output internal table according to number of bukrs

Similar Messages

  • Dynamic selection in ALV report

    Hi Guru's
    I have cpoied a standatrd program(RFBILA00) into Z-program.
    I need to display the profit centre from dynamic selection in ALV header  output when profit centre is selected.If not no need to display it.
    Please do the needful.
    Thanks,
    Sunil.

    hi,
    Refer to the link,
    http://www.abapcode.info/2007/06/dynamic-selection-on-alv-at-run-time.html
    This may help you.
    Regards
    Sumit Aagrwal

  • Dynamic sort in ALV

    hi all,
    HOw can we write the dynamic sort in ALV.
    regards,
    AJ

    Hi,
    Please find the sample code for dynamic sort in OO ALV
      perform built_sort_table.
    form built_sort_table.
      data ls_sort_wa type lvc_s_sort.
      ls_sort_wa-spos = 1.
      ls_sort_wa-fieldname = 'MATNR'.    "<< here your pass fieldname to sort dynamically
      ls_sort_wa-up = selected.
      ls_sort_wa-subtot = ''.
      append ls_sort_wa to gt_sort.
      ls_sort_wa-spos = 2.
      ls_sort_wa-fieldname = 'STATUS'.  "<< here your pass fieldname to sort dynamically
      ls_sort_wa-up = selected.
      ls_sort_wa-subtot = ''.
      append ls_sort_wa to gt_sort.
    endform.                               " BUILT_SORT_TABLE
        call method grid1->set_table_for_first_display
          exporting
            is_layout                     = gs_layout
            is_variant                    = gs_variant
            i_save                        = 'A'
            it_toolbar_excluding          = i_exclude[]
          changing
            it_outtab                     = i_output[]
            it_fieldcatalog               = i_fieldcat[]
            it_sort                       = gt_sort[]
          exceptions
            invalid_parameter_combination = 1
            program_error                 = 2
            too_many_lines                = 3
            others                        = 4.
    aRs

  • Dynamic columns for ALV/classical

    Hi friends,
    I came across an issue where I need to create an output list based on the selection screen.
    Example: In selection screen if user enters plant 1000 2000 3000 4000 .
    I want the output table having columns 1000 2000 3000 4000 .
    Please help me out how to accomplish this task.  Is  this functionality is possible with ALV..?
    A sample code for this will really help me a lot .. or send me your valuable suggestions..
    Thanks
    Prasead K

    Search sdn for [cl_alv_table_create=>create_dynamic_table|https://www.sdn.sap.com/irj/scn/advancedsearch?query=cl_alv_table_create%3d%3ecreate_dynamic_table&cat=sdn_all], there are already many threads and samples. Basically, you dynamically fill an ALV fieldcatalog, then use the method to create a dynamic internal table from this catalog, fill the internal table and display it.
    Regards

  • Dynamical Call of ALV - No data update

    Hi,
    I tried to use use the ALV dynamically. With dynamically I mean that I that I have diffrent data structures, depending what was selected by the user. The first call of the program is always correct. The data is displayed correctly. But when the data structure is changing, the ALV display is not updated.  For a better understanding I post a extract of my coding:
    <b>1. Creation of Container</b>
    CREATE OBJECT g_custom_container
        EXPORTING              
          container_name              = 'PARENT_CONT'
        EXCEPTIONS
          cntl_error                  = 1
          cntl_system_error           = 2
          create_error                = 3
          lifetime_error              = 4
          lifetime_dynpro_dynpro_link = 5.
      IF sy-subrc <> 0.
        ASSERT 1 = 2.
      ENDIF.
    <b>2.Creation of splitter container</b>
      CREATE OBJECT splitter
         EXPORTING
           parent            = g_custom_container
           rows              = 2
           columns           = 2
        EXCEPTIONS
          cntl_error        = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
        ASSERT 1 = 2.
      ENDIF.
    container_2 = splitter->get_container(
                                row       = 1
                                column    = 2 ).
    <b>3.Dynamic Creation of alv object</b>
      CREATE OBJECT go_grid
        EXPORTING
          i_parent = container_2.
    <b>4. Get Fieldcatalogue</b>
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       = lv_structure_name
        CHANGING
          ct_fieldcat            = lt_fieldcat
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
      IF sy-subrc <> 0.
        ASSERT 1 = 2.
      ENDIF.
    <b>5. Set table for first display</b>
      CALL METHOD go_grid->set_table_for_first_display
    *    EXPORTING
    *      i_structure_name = lv_structure_name
        CHANGING
          it_fieldcatalog  = lt_fieldcat
          it_outtab        = <lt_out_data>.
      CALL METHOD ls_alv_ref-alv_ref->refresh_table_display.
      CALL METHOD cl_gui_cfw=>flush.
    Perhaps someone could help.....
    Best Regards, Edgar

    Hello Edgar
    The following sample report <b>ZUS_SDN_TWO_ALV_GRIDS_8</b> shows how to solve your problem. Please note that for the sake of simplicity I replaced the tree containing the structure names with an ALV list. However, the switch between the different structures is triggered by the <b>DOUBLE_CLICK</b> event.
    I like to add that the integration of the first displayed ALV list (DD02L) into GT_OUTTAB is not really elegant. In addition, with <b>$TMP</b> I marked a problematic part of the coding with respect to your requirement to have the right layout for each displayed ALV list:
    If you have a <b>fixed </b>assignment of <i>tabname -> 4-digit handle</i> then it is ok. I my sample report the layouts only work if you select the tabnames in the very same order.
    Before showing the entire coding I describe crucial parts of the coding:
    [code]TYPES: BEGIN OF ty_s_outtab.
    TYPES: tabname    TYPE tabname.
    TYPES: layout     TYPE lvc_s_layo.
    TYPES: variant    TYPE disvariant.
    TYPES: fcat       TYPE lvc_t_fcat.
    TYPES: data       TYPE REF TO data.
    TYPES: END OF ty_s_outtab.[/code]
    Every time a new structure is selected the corresponding ALV data are stored as new record in GT_OUTTAB which is of line type TY_S_OUTTAB.
    [code]  READ TABLE gt_outtab INTO gs_outtab INDEX 2.
      ASSIGN gs_outtab-fcat    TO <gt_fcat>.
      ASSIGN gs_outtab-data->* TO <gt_outtab>.[/code]
    Since the ALV list data and the fieldcatalog are fully dynamic I use global field-symbols for these data.
    [code]&----
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS_0100'.  " contains push button "DETAIL"
    SET TITLEBAR 'xxx'.
      CALL METHOD go_grid2->set_table_for_first_display
        EXPORTING
          i_structure_name = gs_outtab-tabname
          is_layout        = gs_outtab-layout
          is_variant       = gs_outtab-variant
          i_save           = 'A'
        CHANGING
          it_outtab        = <gt_outtab>
          it_fieldcatalog  = <gt_fcat>
        EXCEPTIONS
          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.
    ENDMODULE.                 " STATUS_0100  OUTPUT[/code]
    The second ALV list which displays the table records is always newly displayed in the PBO module.
    In the event handler method <b>HANDLE_DOUBLE_CLICK</b> we need to do two things:
    - store the current fieldcatalog back to GT_OUTTAB
    - store the name of the new selected table/structure -> trigger PAI
    In routine <b>HANDLE_DB_CLICK</b> we create a new entry for GT_OUTTAB if it does not yet exist. Next we select this entry and display it again as second ALV list.
    [code]
    *& Report  ZUS_SDN_TWO_ALV_GRIDS_8
    *& Description: Display two ALV lists in splitter container (left/right)
    *&              Left ALV list contains DB table names,
    *& right ALV list displays entries of selected DB table
    *& SDN thread: Dynamical Call of ALV - No data update
    *&       Link: https:||Dynamical Call of ALV - No data update
    *& Screen '0100' contains no elements.
    *& ok_code -> assigned to GD_OKCODE
    *& Flow logic:
    PROCESS BEFORE OUTPUT.
       MODULE STATUS_0100.
    PROCESS AFTER INPUT.
       MODULE USER_COMMAND_0100.
    REPORT  zus_sdn_two_alv_grids_8.
    TYPE-POOLS: abap.
    DATA:
      gd_repid         TYPE syst-repid,
      gd_okcode        TYPE ui_func,
      go_docking       TYPE REF TO cl_gui_docking_container,
      go_splitter      TYPE REF TO cl_gui_splitter_container,
      go_cell_left     TYPE REF TO cl_gui_container,
      go_cell_right    TYPE REF TO cl_gui_container,
      go_grid1         TYPE REF TO cl_gui_alv_grid,
      go_grid2         TYPE REF TO cl_gui_alv_grid,
      gs_layout        TYPE lvc_s_layo.
    TYPES: BEGIN OF ty_s_outtab.
    TYPES: tabname    TYPE tabname.
    TYPES: layout     TYPE lvc_s_layo.
    TYPES: variant    TYPE disvariant.
    TYPES: fcat       TYPE lvc_t_fcat.
    TYPES: data       TYPE REF TO data.
    TYPES: END OF ty_s_outtab.
    TYPES: ty_t_outtab  TYPE STANDARD TABLE OF ty_s_outtab
                        WITH DEFAULT KEY.
    DATA:
      gt_dd02l         TYPE STANDARD TABLE OF dd02l,
      gs_outtab        TYPE ty_s_outtab,
      gt_outtab        TYPE ty_t_outtab.
    FIELD-SYMBOLS:
      <gt_fcat>        TYPE lvc_t_fcat,
      <gt_outtab>      TYPE table.
          CLASS lcl_eventhandler DEFINITION
    CLASS lcl_eventhandler DEFINITION.
      PUBLIC SECTION.
        CLASS-DATA:
          md_tabname_selected  TYPE tabname  READ-ONLY.
        CLASS-METHODS:
          handle_double_click FOR EVENT double_click OF cl_gui_alv_grid
            IMPORTING
              e_row
              e_column
              es_row_no
              sender.
    ENDCLASS.                    "lcl_eventhandler DEFINITION
          CLASS lcl_eventhandler IMPLEMENTATION
    CLASS lcl_eventhandler IMPLEMENTATION.
      METHOD handle_double_click.
      define local data
        DATA:
          ls_dd02l       TYPE dd02l,
          ls_outtab      TYPE ty_s_outtab.
        CHECK ( sender = go_grid1 ).
        READ TABLE gt_dd02l INTO ls_dd02l INDEX e_row-index.
        "   Store data of currently displayed ALV list (except for DD02L)
        IF ( md_tabname_selected = space ).
        ELSE.
          READ TABLE gt_outtab INTO ls_outtab
               WITH KEY tabname = md_tabname_selected.  " old
          CALL METHOD go_grid2->get_frontend_fieldcatalog
            IMPORTING
              et_fieldcatalog = ls_outtab-fcat.
          MODIFY gt_outtab FROM ls_outtab INDEX syst-tabix.
        ENDIF.
        md_tabname_selected = ls_dd02l-tabname.  " new selected DB table
      Triggers PAI of the dynpro with the specified ok-code
       cl_gui_cfw=>set_new_ok_code( 'HANDLE_DB_CLICK' ).  " not 4.6c
        CALL METHOD cl_gui_cfw=>set_new_ok_code
          EXPORTING
            new_code = 'HANDLE_DB_CLICK'
         IMPORTING
           RC       =
      ENDMETHOD.                    "handle_double_click
    ENDCLASS.                    "lcl_eventhandler IMPLEMENTATION
    START-OF-SELECTION.
      gd_repid = syst-repid.
      SELECT        * FROM  dd02l INTO TABLE gt_dd02l
             WHERE  tabname LIKE 'KN%1'   OR
                    tabname LIKE 'LF%1'   OR
                    tabname LIKE 'VB%'   OR
                    tabname LIKE 'MAR%'   OR
                    tabname LIKE 'E07%'
             AND    tabclass = 'TRANSP'.  " transparent table
      SORT gt_dd02l BY tabname.
      PERFORM init_controls.
      PERFORM add_first_table.
    Set event handler
      SET HANDLER:
        lcl_eventhandler=>handle_double_click FOR go_grid1.
      READ TABLE gt_outtab INTO gs_outtab INDEX 1.
    Display data
      CALL METHOD go_grid1->set_table_for_first_display
        EXPORTING
          i_structure_name = gs_outtab-tabname
          is_layout        = gs_outtab-layout
        CHANGING
          it_outtab        = gt_dd02l
        EXCEPTIONS
          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.
      READ TABLE gt_outtab INTO gs_outtab INDEX 2.
      ASSIGN gs_outtab-fcat    TO <gt_fcat>.
      ASSIGN gs_outtab-data->* TO <gt_outtab>.
    NOTE: method called in PBO module
    CALL METHOD go_grid2->set_table_for_first_display
       EXPORTING
         i_structure_name = gs_outtab-tabname
         is_layout        = gs_outtab-layout
         is_variant       = gs_outtab-variant
         i_save           = 'A'
       CHANGING
         it_outtab        = <gt_outtab>
         it_fieldcatalog  = <gt_fcat>
       EXCEPTIONS
         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.
    Link the docking container to the target dynpro
      CALL METHOD go_docking->link
        EXPORTING
          repid                       = gd_repid
          dynnr                       = '0100'
         CONTAINER                   =
        EXCEPTIONS
          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.
    NOTE: dynpro does not contain any elements
      CALL SCREEN '0100'.
    Flow logic of dynpro (does not contain any dynpro elements):
    *PROCESS BEFORE OUTPUT.
    MODULE STATUS_0100.
    *PROCESS AFTER INPUT.
    MODULE USER_COMMAND_0100.
    END-OF-SELECTION.
    *&      Module  STATUS_0100  OUTPUT
          text
    MODULE status_0100 OUTPUT.
      SET PF-STATUS 'STATUS_0100'.  " contains push button "DETAIL"
    SET TITLEBAR 'xxx'.
      CALL METHOD go_grid2->set_table_for_first_display
        EXPORTING
          i_structure_name = gs_outtab-tabname
          is_layout        = gs_outtab-layout
          is_variant       = gs_outtab-variant
          i_save           = 'A'
        CHANGING
          it_outtab        = <gt_outtab>
          it_fieldcatalog  = <gt_fcat>
        EXCEPTIONS
          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.
    ENDMODULE.                 " STATUS_0100  OUTPUT
    *&      Module  USER_COMMAND_0100  INPUT
          text
    MODULE user_command_0100 INPUT.
      CASE gd_okcode.
        WHEN 'BACK' OR
             'END'  OR
             'CANC'.
          SET SCREEN 0. LEAVE SCREEN.
      User has pushed button "Display Details"
        WHEN 'HANDLE_DB_CLICK'.
          PERFORM handle_db_click.
        WHEN OTHERS.
      ENDCASE.
      CLEAR: gd_okcode.
    ENDMODULE.                 " USER_COMMAND_0100  INPUT
    *&      Form  HANDLE_DB_CLICK
          text
    -->  p1        text
    <--  p2        text
    FORM handle_db_click.
    define local data
      DATA:
        ld_handle(4) TYPE n,
        ls_outtab    TYPE ty_s_outtab.
      READ TABLE gt_outtab INTO ls_outtab
           WITH KEY tabname = lcl_eventhandler=>md_tabname_selected.
      IF ( syst-subrc NE 0 ).
        CLEAR: ls_outtab.
        ls_outtab-tabname = lcl_eventhandler=>md_tabname_selected.
        CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
        I_BUFFER_ACTIVE              =
          i_structure_name             = ls_outtab-tabname
        I_CLIENT_NEVER_DISPLAY       = 'X'
        I_BYPASSING_BUFFER           =
        I_INTERNAL_TABNAME           =
        CHANGING
          ct_fieldcat                  = ls_outtab-fcat
        EXCEPTIONS
          inconsistent_interface       = 1
          program_error                = 2
          OTHERS                       = 3.
        IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
        ENDIF.
        CREATE DATA ls_outtab-data TYPE TABLE OF (ls_outtab-tabname).
        ASSIGN ls_outtab-data->* TO <gt_outtab>.
        SELECT * FROM (ls_outtab-tabname) UP TO 50 ROWS
          INTO TABLE <gt_outtab>.
        ls_outtab-layout-no_toolbar = abap_false.
        ls_outtab-layout-zebra      = abap_true.
        ls_outtab-layout-smalltitle = abap_true.
        CONCATENATE ls_outtab-tabname ':'
          INTO ls_outtab-layout-grid_title.
        CONCATENATE ls_outtab-layout-grid_title 'Table Records'
          INTO ls_outtab-layout-grid_title
          SEPARATED BY space.
        ls_outtab-variant-report    = gd_repid.
        DESCRIBE TABLE gt_outtab.
        ld_handle = syst-tfill + 1.
        WRITE ld_handle TO ls_outtab-variant-handle.  " $TMP: Problem!!!
        APPEND ls_outtab TO gt_outtab.
      ENDIF.
      " NOTE: read into GLOBAL variable gs_outtab !!!!
      READ TABLE gt_outtab INTO gs_outtab
            WITH KEY tabname = lcl_eventhandler=>md_tabname_selected.
      ASSIGN gs_outtab-fcat    TO <gt_fcat>.
      ASSIGN gs_outtab-data->* TO <gt_outtab>.
    ENDFORM.                    " HANDLE_DB_CLICK
    *&      Form  INIT_CONTROLS
          text
    -->  p1        text
    <--  p2        text
    FORM init_controls .
    Create docking container
      CREATE OBJECT go_docking
        EXPORTING
          parent                      = cl_gui_container=>screen0
          ratio                       = 90
        EXCEPTIONS
          OTHERS                      = 6.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL METHOD go_docking->set_extension
        EXPORTING
          extension  = 99999 " full-size screen
        EXCEPTIONS
          cntl_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.
    Create splitter container
      CREATE OBJECT go_splitter
        EXPORTING
          parent            = go_docking
          rows              = 1
          columns           = 2
         NO_AUTODEF_PROGID_DYNNR =
         NAME              =
        EXCEPTIONS
          cntl_error        = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Get cell container
      CALL METHOD go_splitter->get_container
        EXPORTING
          row       = 1
          column    = 1
        RECEIVING
          container = go_cell_left.
      CALL METHOD go_splitter->get_container
        EXPORTING
          row       = 1
          column    = 2
        RECEIVING
          container = go_cell_right.
      CALL METHOD go_splitter->set_column_mode
        EXPORTING
          mode              = cl_gui_splitter_container=>mode_relative
       IMPORTING
         RESULT            =
        EXCEPTIONS
          cntl_error        = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL METHOD go_splitter->set_column_width
        EXPORTING
          id                = 1
          width             = 25
       IMPORTING
         RESULT            =
        EXCEPTIONS
          cntl_error        = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CALL METHOD go_splitter->set_column_sash
        EXPORTING
          id                = 1
          type              = cl_gui_splitter_container=>type_movable
          value             = cl_gui_splitter_container=>false
       IMPORTING
         RESULT            =
        EXCEPTIONS
          cntl_error        = 1
          cntl_system_error = 2
          OTHERS            = 3.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    Create ALV grids
      CREATE OBJECT go_grid1
        EXPORTING
          i_parent          = go_cell_left
        EXCEPTIONS
          OTHERS            = 5.
      IF sy-subrc <> 0.
      MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
                 WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      CREATE OBJECT go_grid2
        EXPORTING
          i_parent          = go_cell_right
        EXCEPTIONS
          OTHERS            = 5.
      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.                    " INIT_CONTROLS
    *&      Form  ADD_FIRST_TABLE
          text
    -->  p1        text
    <--  p2        text
    FORM add_first_table .
    define local data
      DATA:
        ls_outtab    TYPE ty_s_outtab.
      ls_outtab-tabname = 'DD02L'.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
      EXPORTING
      I_BUFFER_ACTIVE              =
        i_structure_name             = ls_outtab-tabname
      I_CLIENT_NEVER_DISPLAY       = 'X'
      I_BYPASSING_BUFFER           =
      I_INTERNAL_TABNAME           =
      CHANGING
        ct_fieldcat                  = ls_outtab-fcat
      EXCEPTIONS
        inconsistent_interface       = 1
        program_error                = 2
        OTHERS                       = 3.
      IF sy-subrc <> 0.
    *MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
          WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
      GET REFERENCE OF gt_dd02l INTO ls_outtab-data.
      ls_outtab-layout-no_toolbar = abap_false.
      ls_outtab-layout-zebra      = abap_true.
      ls_outtab-layout-smalltitle = abap_true.
      CONCATENATE ls_outtab-tabname ':'
        INTO ls_outtab-layout-grid_title.
      CONCATENATE ls_outtab-layout-grid_title 'Table Records'
        INTO ls_outtab-layout-grid_title
        SEPARATED BY space.
      ls_outtab-variant-report    = gd_repid.
      ls_outtab-variant-handle    = '0002'.
      INSERT ls_outtab INTO gt_outtab INDEX 1.
      ls_outtab-layout-no_toolbar = abap_true.
    ls_outtab-layout-zebra      = abap_true.
    ls_outtab-layout-smalltitle = abap_true.
      ls_outtab-layout-grid_title = 'DB Tables'.
    ls_outtab-variant-report    = gd_repid.
      ls_outtab-variant-handle    = '0001'.
      DELETE ls_outtab-fcat WHERE ( fieldname NE 'TABNAME' ).
      INSERT ls_outtab INTO gt_outtab INDEX 1.
    ENDFORM.                    " ADD_FIRST_TABLE[/code]
    Regards,
      Uwe

  • Dynamic Tabstrip and Alv's

    Hi All,
    My requirement is like that dynamically i have to create tabstrip and in that each tab has Alv table to disply the data.
    Regards,
    Rajesh.

    Hi,
    To dynamically include an ALV additionally, you would have to do the following:
    1. First declare the component usage for the ALV in your component, so that you can instantiate and use the ALV
    2. Within the tab, you will have to dynamically also create a viewcontainerUIelement dynamically (similar way as you have dynamically created the tabstrip) - try using CL_WD_VIEW_CONTAINER_UIELEMENT.
    3. You will have to dynamically embed the ALV component in viewcontainerUIelement created in (2). Try going thru
    http://help.sap.com/saphelp_nw04s/helpdata/en/77/3545415ea6f523e10000000a155106/frameset.htm
    4. Proceed with the ALV as usual.
    Hope this helps.
    Regards,
    Wenonah

  • Show dynamic table in ALV grid

    Hi !
    how do I show a dynamic table in ALV GRID ?
    I used the following commands:
    call method cl_alv_table_create=>create_dynamic_table
      exporting
        it_fieldcatalog = it_fieldcat[]
      importing
        ep_table        = gt_new_table.
      assign gt_new_table->* to <l_table>.
      create data gs_new_line like line of <l_table>.
      assign gs_new_line->* to <l_line>.
    I added records into the table
    Now I got a dynamic table.
    How do I show it in ALV GRID ?
    thanks
      Adi

    Hi,
    Check these links
    Re: Dynamic table
    http://sap.ittoolbox.com/code/d.asp?a=s&d=3038
    http://www.sap4.com/codigo-138.html
    http://www.sapassist.com/code/d.asp?a=s&d=3365
    There is an example in the report BCALV_TABLE_CREATE
    report BCALV_TABLE_CREATE.
    data: ok_code like sy-ucomm,
         g_container type scrfname value 'BCALV_GRID_DEMO_0100_CONT1',
         grid1  type ref to cl_gui_alv_grid,
         g_custom_container type ref to cl_gui_custom_container.
    data: gt_fieldcat type lvc_t_fcat.
    data: gp_table type ref to data.
    field-symbols: <gt_table> type table.
    parameters: n type i.
    if n > 100.
    message a000(0k) with 'N <= 100'.
    endif.
    perform fieldcat_build.
    call method cl_alv_table_create=>create_dynamic_table
                            exporting it_fieldcatalog = gt_fieldcat
                            importing ep_table = gp_table.
    assign gp_table->* to <gt_table>.
    perform fill_table.
    call screen 100.

  • Dynamic column in ALV Report

    Hi,
    We need to display amount fields in the ALV and that fields should be able to display both 3 decimals or 2 decimals at the same time.When we refer this as a character field it is not allowed for totals/subtotals .
    if we refer it as 3 decimals ,it is adding zero for 2 decimal  values.
    if we refer it as 2 decimals ,it is adding rounding off  for 2 decimal  values.
    How can we dynamically refer this field in order to handle both these cases at the same time?
    We tried with reference of CURR ,but no use.
    Any pointers in this regard are highly appreciated.
    Regards,

    Hi Kranti,
    if you want to display amount then you should use amount fields. Then you need another column for the currency displayed. In the field catalog, you reference the amount field to the currensy field using fieldcat component CFIELDNAME.
    Then all values are displayed with the number of decimals defined for the respective currency.
    Additionally, you will get separate subtotal lines for each currency.
    --  asked several times, answered several times --
    What serach term did you use?
    Kind regards,
    Clemens

  • Set Data from a Dynamic Context in ALV

    Hi,
    I've created an dynamic context and have binded the data. When I want to show this data in an dynamicly table with the following code, it works well.
    cl_wd_dynamic_tool=>create_table_from_node( EXPORTING ui_parent      = lo_container
                                                              table_id       = 'DYN_ML_TABLE'
                                                              node           = lo_nd_dyn_ml
                                                    RECEIVING table          = lo_table ).
    Unfortunately when I want to show the context data in an ALV table with the method set_data I will see the structure, but the binded data are lost.
    lo_comp_alv = wd_this->wd_cpuse_usage_alv_dyn_ml( ).
      IF lo_comp_alv->has_active_component( ) IS INITIAL.
        lo_comp_alv->create_component( ).
      ENDIF.
      lo_comp_if_alv = wd_this->wd_cpifc_usage_alv_dyn_ml( ).
      lo_comp_if_alv->set_data( lo_nd_dyn_ml ).
    I've tested an manually created context node with this method, and I will see the data.
    Could anybody help me?
    Best Regards,
    Sascha

    I created the node with rtti. Now, it works:
    "Beschreibung zu interner Tabelle lesen
       lo_tab_descr ?= cl_abap_typedescr=>describe_by_data( it_matchlist ).
       "Zeilentyp zu interner Tabelle ermitteln
       lo_str_descr ?= lo_tab_descr->get_table_line_type( ).
       "Komponente der Zeile ausgeben, welche für die Erstellung der Knotenattribute benötigt werden
       lt_comp = lo_str_descr->get_components( ).
       data: ls_component type cl_abap_structdescr=>component,
             lr_type type ref to cl_abap_datadescr,
             lt_components type cl_abap_structdescr=>component_table,
             lr_structdescr type ref to cl_abap_structdescr.
       "Loop über Komponente und Einfügen in Attributenliste
       loop at lt_comp into ls_comp.
         lv_abs_name = ls_comp-type->absolute_name.
         "Folgende Zeichen werden entfernt: '/TYPE='
         shift lv_abs_name left by 6 places.
         lr_type ?= cl_abap_typedescr=>describe_by_name( p_name = lv_abs_name ).
         ls_component-name = ls_comp-name.
         ls_component-type = lr_type .
         append ls_component to lt_components.
       endloop.
       "Strukturtyp anhand der definierten Kompententen der internen Tabelle erzeugen
       lr_structdescr = cl_abap_structdescr=>create( p_components = lt_components ).
    *  "Neuen Kindknoten anlegen
       lo_nd_dyn_info = lo_nd_root_info->add_new_child_node( name                         = wd_this->gd_matchlist_nd_name
                                                             is_mandatory                 = abap_false
                                                             is_mandatory_selection       = abap_false
                                                             is_multiple                  = abap_true
                                                             is_multiple_selection        = abap_false
                                                             is_singleton                 = abap_false
                                                             is_initialize_lead_selection = abap_true
    *                                                        attributes                   = lt_attributes
                                                             is_static                    = abap_false
                                                             static_element_rtti          = lr_structdescr
                                                             "supply_method                =
                                                             "supply_object                =
                                                             "dispose_method               =
                                                             "dispose_object               =
                                                             "static_element_type          =

  • DISPLAYING -DYNAMIC COLUM  IN ALV ??? READ MESSGAE

    hi friends ,
    Thanks for your reply , here is one question i am displaying my code
    in short .. what i want is to display column dynamically using the
    field-symbols.... can anybody help me with syntax or code i wil be
    thank full to him .i find little code for it on sdn also .
    sdn code,
    1. Create your field catalog either manually or automatically using the function module, LVC_FIELDCATALOG_MERGE.
    Add more rows to the field catalog table (T_FIELDCAT) at run time.
    2. Use the field catalog to create a table dynamically using the method below.
    DATA: T_OUTPUT TYPE REF TO DATA
    FIELD-SYMBOLS: <T_OUTPUT> TYPE TABLE
    Call Method CL_ALV_TABLE_CREATE->CREATE_DYNAMIC_TABLE
    Exporting
    IT_FIELDCATALOG = T_FIELDCAT
    Importing
    EP_TABLE = T_OUTPUT
    ASSIGN T_OUTPUT->* TO <T_OUTPUT>.
    Now the field symbol <T_OUTPUT> is pointing to an output table of the structure that contains the fields which were determined at runtime.
    Now fill this table with the data and pass <T_OUTPUT> to the method SET_TABLE_FOR_FIRST_DISPLAY and the ALV grid should show the data properly.
    here is my code."""" IAM USING SCREEN..HERE
    after the start of selection .
      LOOP AT i_vat.
                IF i_vat-mwskz IS NOT INITIAL.
                       'CALCULATE_TAX_ITEM'
                  i_itaxcom-bukrs = i_vat-bukrs.
                  i_itaxcom-waers = i_vat-waers.
                  i_itaxcom-kposn = i_vat-ebelp.
                  i_itaxcom-mwskz = i_vat-mwskz.
                  i_itaxcom-wrbtr = i_vat-netwr.
                  i_itaxcom-matnr = i_vat-matnr.
                  i_itaxcom-mglme = i_vat-menge.
                  i_itaxcom-werks = i_vat-werks.
                  i_itaxcom-bldat = i_vat-bedat.
                  i_itaxcom-budat = i_vat-bedat.
                  i_itaxcom-lifnr = i_vat-lifnr.
                       i_itaxcom-shkzg = 'H'.
                  i_itaxcom-xmwst = 'X'.
                  i_itaxcom-matkl = i_vat-matkl.
                  i_itaxcom-meins = i_vat-meins.
                  i_itaxcom-mtart = i_vat-mtart.
                       i_itaxcom-land1 = 'IN'.
                       i_itaxcom-ebeln = zxekko-ebeln.
                       i_itaxcom-ebelp = <fs>-ebelp.
                       *end of correction 20.10.2004
                  REFRESH i_otaxcom.
                  CALL FUNCTION 'CALCULATE_TAX_ITEM'
                    EXPORTING
                     i_taxcom                  = i_itaxcom
                   TABLES
                     t_xkomv                   = i_otaxcom.
    LOOP AT  i_otaxcom WHERE kposn = i_vat-ebelp.    "kposn - condition item number 
             READ TABLE i_tcode WITH KEY  ebeln = i_vat-ebeln
                                          ebelp = i_vat-ebelp
                                          kschl = i_otaxcom-kschl.  
                    IF sy-subrc <> 0.
                      IF i_otaxcom-kwert <> 0.
                        i_tcode-kschl =  i_otaxcom-kschl.
                         tcode-ebeln = i_vat-ebeln.     
                        i_tcode-ebelp = i_vat-ebelp.
                        i_tcode-kschl = i_otaxcom-kschl.
                        i_tcode-kwert = i_otaxcom-kwert.
                        APPEND i_tcode.
                      ENDIF.
                    ENDIF.
                  ENDLOOP.
                ENDIF.
              ENDLOOP.
              LOOP AT i_vat.
                count1 = 1.
                LOOP AT i_tcode WHERE ebeln = i_vat-ebeln AND ebelp = i_vat-ebelp.
              Alv_fieldname+5 = count1.
                    ASSIGN COMPONENT Alv_fieldname OF STRUCTURE i_vat
                    TO <fs_value>.
                      IF sy-subrc EQ 0.
                    <fs_value> = i_tcode-kwert.
                     ENDIF.
                 count1 = count1 + 1.
                  MODIFY i_vat.
                ENDLOOP.
              ENDLOOP.
              SELECT DISTINCT kschl
                              vtext
                   INTO CORRESPONDING FIELDS OF TABLE i_tcode1
                   FROM t685t
                   FOR ALL ENTRIES IN i_tcode
                   WHERE kschl = i_tcode-kschl AND
                         kappl = 'TX'          AND
                         spras = sy-langu.
              count1 = 1..
              LOOP AT i_tcode1
    READ TABLE i_tcode WITH KEY  kschl = i_tcode1-kschl .
                IF sy-subrc = 0.
                  CONCATENATE 'BAVAL' count1 INTO fld_name.
                  i_tcode1-text  = fld_name.
                  MODIFY i_tcode1.
                  count1 = count1 + 1.
                ENDIF.
              ENDLOOP.
    PERFORM sort_build USING gt_sort[].
              PERFORM layout_init USING gs_layout.
              PERFORM fieldcatalog_init USING gt_fieldcatalog[] 'EBELN' 'C' 'Documnet No'.
              PERFORM fieldcatalog_init USING gt_fieldcatalog[] 'EBELP' 'C' 'Line Item'.
              PERFORM fieldcatalog_init USING gt_fieldcatalog[] 'WERKS' 'C' 'Plant'.
              PERFORM fieldcatalog_init USING gt_fieldcatalog[] 'LIFNR' 'C' 'Vendor'.
              PERFORM fieldcatalog_init USING gt_fieldcatalog[] 'NAME1' 'C' 'Vendor Name '.
              PERFORM fieldcatalog_init USING gt_fieldcatalog[] 'MATNR' 'C' 'Material'.
              PERFORM fieldcatalog_init USING gt_fieldcatalog[] 'MAKTX' 'C' 'Material Description'.
              PERFORM fieldcatalog_init USING gt_fieldcatalog[] 'MENGE' 'QUAN' 'Order Quantity '.
              PERFORM fieldcatalog_init USING gt_fieldcatalog[] 'NETPR' 'CURR' 'Price  Rate'.
    OR DYNAMIC DISLPLAY.
    BUT I WANT IN FIELD SYMBOL WAY
              LOOP AT i_tcode1.
                PERFORM fieldcatalog_init USING gt_fieldcatalog[] i_tcode1-text  'QUAN'  i_tcode1-vtext.
              ENDLOOP

    Hi Farukh,
    Regarding ALv u can find full details in this below link.This should help u better.
    http://help.sap.com/saphelp_erp2005/helpdata/en/b8/d84f59aac911d295e300a0c9306433/frameset.htm
    In this goto ABAP List viwer to c all the details and functions of ALv.
    Regards,
    Nagarajan.

  • Dynamic columns in ALV report

    halo fellow SAPiens,
    i need to show dynamic columns for a particular material........the scenario is as follows....
    1) there r 7 fixed columns describing the material...
    2)when the material returns back to the plant for some reason , i need to insert a column which shows the date and reason(char) of return.
    3)again after dispatching the material for some reason it comes back again a new column shld be displayed showin the date and reason(char).
    4)if the material doesnt come back...the report shows only 7 columns.
    any solution?

    try <a href="http://www.alvrobot.com.ar/home.php">here</a>  ......its a useful tool for dealing with ALV
    <b>reward points if useful</b>

  • Dynamic Table in ALV

    Hello experts,
    is it possible to call an ALV via ( class cl_salv or fm REUSE_ALV_GRID_DISPLAY) with a dynamic table?
    This dynamic table has for example one fix column for the material number and dynamic colums for additional data.
    One material has 1 additional column, the other material has two additional columns.
    So i need an ALV with 3 columns material add_data1 add_data2 (add_data2 of material one is empty this is ok).
    To build an itab which can handle this is possible i know.

    Hello Benjamin,
    Maybe you already found a solution for this, but if not (or for others looking for a solution), here is a sample program that creates, fills, and displays a dynamic table:
    report ztpar_dynamic_salv.
    parameters: p_colnr type i default 3.
    start-of-selection.
      perform execute.
    form execute.
      data t_table type ref to data.
    ** create dynamic table
      perform create_dynamic_table using p_colnr
                                changing t_table.
    ** fill dynamic table
      perform fill_dynamic_table changing t_table.
    ** display dynamic table
      perform display_table using t_table.
    endform.
    form create_dynamic_table using colnr type i
                           changing table type ref to data.
      data: lo_field type ref to cl_abap_typedescr,
            lo_struct type ref to cl_abap_structdescr,
            lo_table type ref to cl_abap_tabledescr.
      data: t_comp type cl_abap_structdescr=>component_table,
            l_comp like line of t_comp.
      lo_field ?= cl_abap_typedescr=>describe_by_name( 'CHAR10' ).
      do p_colnr times.
        move sy-index to l_comp-name.
        concatenate 'COLUMN' l_comp-name into l_comp-name.
        condense l_comp-name no-gaps.
        l_comp-type ?= lo_field.
        append l_comp to t_comp.
      enddo.
      lo_struct = cl_abap_structdescr=>create( p_components = t_comp p_strict = space ).
      lo_table = cl_abap_tabledescr=>create( lo_struct ).
      create data table type handle lo_table.
    endform.
    form fill_dynamic_table changing table type ref to data.
      field-symbols: <fs_table> type standard table,
                     <fs_line> type any,
                     <fs_field> type any.
      assign table->* to <fs_table>.
      do 5 times.
        append initial line to <fs_table> assigning <fs_line>.
        do.
          assign component sy-index of structure <fs_line> to <fs_field>.
          if sy-subrc ne 0.
            exit.
          endif.
          <fs_field> = sy-index.
        enddo.
      enddo.
    endform.
    form display_table using i_table type ref to data.
      data lo_alv type ref to cl_salv_table.
      field-symbols <fs_tab> type any table.
      assign i_table->* to <fs_tab>.
      try.
          cl_salv_table=>factory(
            importing
              r_salv_table = lo_alv
            changing
              t_table      = <fs_tab> ).
        catch cx_salv_msg.
          message 'Cannot display result!' type 'E'.
      endtry.
      lo_alv->display( ).
    endform.
    Best regards,
    Tanguy

  • Dynamic row in alv.

    i wont to now if i can do it in alv that the row change dynamicly for largest word in the row in the column. thankes.

    hi,
    just try in the layout.
    *&      Form  BUILD_LAYOUT
          Build layout for ALV grid report
    form build_layout.
      gd_layout-no_input          = 'X'.
      gd_layout-colwidth_optimize = 'X'.
      gd_layout-totals_text       = 'Totals'(201).
    gd_layout-totals_only        = 'X'.
    gd_layout-f2code            = 'DISP'.  "Sets fcode for when double
                                            "click(press f2)
    gd_layout-zebra             = 'X'.
    gd_layout-group_change_edit = 'X'.
    gd_layout-header_text       = 'helllllo'.
    endform.                    " BUILD_LAYOUT
    rgds
    anver

  • Dynamic columns in ALV

    Dear Experts,
    I want to display dynamc columns in ALV, how it possible.
    venkey

    create dynamic internal table from field catalog i m sending u some sample code hope it will help u.
    FORM create_dynamic_itab.
    Create dynamic internal table and assign to FS
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = it_fieldcat[]
        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.

  • Dynamic selection in alv

    hai
      How to display a column in alv(Container) in dynamic manner at runtime.
    specify the code if u have.
    thx in advance.

    Hi,
    Herewith i am sending the mdoel report for the DYNAMIC DEMO.
    Kindly go through it the following.
    REPORT  YMS_DYNAMICDEMO
                 NO STANDARD PAGE HEADING
                 MESSAGE-ID zcs_c2c_001.
    type-pools : abap.
    field-symbols: <dyn_table> type standard table,
                   <dyn_wa>,
                   <dyn_field>.
    data: dy_table type ref to data,
          dy_line  type ref to data,
          xfc type lvc_s_fcat,
          ifc type lvc_t_fcat.
    selection-screen begin of block b1 with frame.
    parameters: p_table(30) type c default 'T001'.
    selection-screen end of block b1.
    start-of-selection.
      perform get_structure.
      perform create_dynamic_itab.
      perform get_data.
      perform write_out.
    form get_structure.
    data : idetails type abap_compdescr_tab,
           xdetails type abap_compdescr.
    data : ref_table_des type ref to cl_abap_structdescr.
    Get the structure of the table.
      ref_table_des ?=
          cl_abap_typedescr=>describe_by_name( p_table ).
      idetails[] = ref_table_des->components[].
      loop at idetails into xdetails.
        clear xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        append xfc to ifc.
      endloop.
    endform.
    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.
    form get_data.
    Select Data from table.
      select * into table <dyn_table>
                 from (p_table).
    endform.
    form write_out.
    Write out data from table.
      loop at <dyn_table> into <dyn_wa>.
        do.
          assign component  sy-index
             of structure <dyn_wa> to <dyn_field>.
          if sy-subrc <> 0.
            exit.
          endif.
          if sy-index = 1.
            write:/ <dyn_field>.
          else.
            write: <dyn_field>.
          endif.
        enddo.
      endloop.
    endform.
    Thanks,
    Shankar

Maybe you are looking for