Generic function displaying alv grid for undefined structure

Hi experts,
I'm doing my first steps on abap development (Totally noob).
I'm writing some little reports based on simple selections (1 or 2 tables).
In every report, I've defined a structure (internal table) that i'm displaying with an ALV Grid.
In every report, I need to create a catalog for my structure in order to make the alv grid working.
What I would like to do is :
Create a function that receives a undefined structure (for all my reports) as a parameter.
This function sould create the catalog for the coresponding structure and call the alv grid function to display the data's contained in this structure.
The goal is : In every report, I would like to use this function to show the selected data's without taking care of catalogs, alv grid, etc...
Is it possible ?
I really don't see how I can do that... Does anybody already tried something like that ?
Thank you for your help
Regards
Quentin

Hi,
In this method Pass the structure name-
CALL METHOD gh_grid->set_table_for_first_display
EXPORTING
I_BUFFER_ACTIVE =
I_BYPASSING_BUFFER =
I_CONSISTENCY_CHECK =
I_STRUCTURE_NAME = "<- here pass the structure
IS_VARIANT =
I_SAVE =
I_DEFAULT = 'X'
IS_LAYOUT = "<-Layout variable if using layout
IS_PRINT =
IT_SPECIAL_GROUPS =
IT_TOOLBAR_EXCLUDING =
IT_HYPERLINK =
IT_ALV_GRAPHICS =
IT_EXCEPT_QINFO =
CHANGING
it_outtab = gt_line[]
it_fieldcatalog = gt_fieldcat
IT_SORT =
IT_FILTER =
EXCEPTIONS
invalid_parameter_combination = 1
program_error = 2
too_many_lines = 3
OTHERS = 4

Similar Messages

  • Like SM30 ,table should be display in editable ALV Grid(for Dynamic DB )

    Hi Friends,
    plese help me how to display  ALV grid in editable mode for differnt types of data base tables.
    same as like SM30 transaction.
    Moderator message: please search for available information/documentation/previous discussions before asking.
    Edited by: Thomas Zloch on Nov 11, 2010 6:40 PM

    Hi,
    In SLIS_T_FIELDCAT_ALV you specify the field as edit = X.
    Give it as mentioned, where you assign fieldname and positions etc.
    Thanks&Regards

  • How does the SORT function in ALV grid work?

    Hi,
    I have a report for which the o/p is displayed in ALV grid format.There is one column in the O/p strcuture which is "No of days".Based on certain conditions,i need to display the value for some of the days as Negative e.g. " - 45".Becasuse of this,I have declared the field for the "No of days" of the type "CHAR".
    Now when i sort(using ALV grid SORT function) the list on basis of this column,it doesnt give me the correct o/p.
    CAN anyone tell me how do i handle this?I want the list to be sorted correctly on basis of the "No of days" column.
    Thanks!

    This is your Fourth Cross Posting in last three days on same issue!!
    CHAR type column doesnt work for SORT function in ALV grid!
    How to sort a column of type CHAR
    I dont,ve link for your Fourth Thread on same,though i'm short memory loss.

  • Hide some cells while displaying ALV GRID !

    Hi guyz!
        Back with lill query,
        While displaying ALV GRID using REUSE_ALV_GRID... FMs ,i need to hide
        some cells by default, when the lists is generated.But those cells should
        be  availble to be displayed by the user from ALV layout settings.
        Please advise
    Thanks
    jahan

    Hi, Check for fm documentation.
    Only relevant if layout parameter
    LAYOUT-GET_SELINFOS of IMPORTING structure IS_LAYOUT is set.
    Complex type for modifying information displayed on the selection dialog box:
    mode:              'R' = Only entries passed in internal table
                              IS_SEL_HIDE-T_ENTRIES are output on
                              the dialog box. Selection information
                              obtained by the list tool by reading the
                              selection screen again (only if the report
                              is called with selection screen) are
                              replaced by the entries passed.
                       'S' = The selection information obtained by the
                              list tool by reading the selection screen
                              of the calling report again, are modified
                              by the entries of table
                              IS_SEL_HIDE-T_ENTRIES.
    t_entries:         Table with selection information
    t_entries-mode:   'A' = Display selection information of the current
                             table row on the information dialog box.
                      'D' = Do not display selection information of the
                             the Select option or of parameter SELNAME
                             on the dialog box.
    t_entries-selname: (required only if t_entries-mode = 'D')
                       name of Select option or parameter
    The following table fields are only required if t_entries-mode = 'A'. They contain the selection information to be added.
    t_entries-field:  DDIC field name of the field for which selection
                       information is to be displayed
    t_entries-table:  DDIC table name of t_entries-field.
    t_entries-stext:  Field description on the information dialog box.
                      If t_entries-field and t_entries-table were
                      filled, this text is taken from the DDIC.
    t_entries-valuf:  Selection condition from-value (external format)
    t_entries-valut:  Selection condition to-value (external format)
    t_entries-sign0:  (I)nclusive (E)xclusive
    t_entries-optio:  All values of the option field of the Select
                      option are allowed.
    The remaining fields are used internally and are irrelevant to the caller.
    aRs

  • Which alv-grid for own build

    Hi,
    how and what kind of ALV i must use to build own ALV-List (columns with content i create).
    For understanding:
    to test it, i will counting something and show that in a new column (counter). But i dont find any way to do that. In one thread i read "cl_salv_table", in the next "cl_gui_alv_grid", then "fieldcatalog" and so on... i'm confused at the moment.
    the only answer i need is:
    1. what are the correct way... cl_gui_alv_grid, cl_salv_table, ... i will find a way to create a list like my own conceivabilities. not a classic one.. a new one.
    Thats my code, but i dont know how i can create any new column (with a name i give and content i create [anywhere in code - till now not in snipped])
    *&amp;---------------------------------------------------------------------*
    *&amp; Report  ZMW_TESTOBJECTS2
    *&amp;
    *&amp;---------------------------------------------------------------------*
    *&amp;
    *&amp;
    *&amp;---------------------------------------------------------------------*
    REPORT  zmw_testobjects2.
    *&amp;---------------------------------------------------------------------*
    *&amp; Global Declarations
    *&amp;---------------------------------------------------------------------*
    TABLES: tabelle1,
            tabelle2,
            tabelle3.
    * SELECTION-SCREEN                                                     *
    SELECTION-SCREEN BEGIN OF BLOCK choices WITH FRAME.
    PARAMETERS:
      l_field1 TYPE tabelle1-field1 OBLIGATORY,
      l_field2 TYPE tabelle2-field2 OBLIGATORY,
      l_field3 TYPE tabelle2-field3,
      l_field4 TYPE tabelle1-field4.
    SELECTION-SCREEN END OF BLOCK choices.
    *&amp;---------------------------------------------------------------------*
    *&amp; Class Test Definition
    *&amp;---------------------------------------------------------------------*
    CLASS test_class DEFINITION.
      PUBLIC SECTION.
        CLASS-METHODS: read_data,
                       fill_list.
      PRIVATE SECTION.
          TYPES: BEGIN OF struc_out_table1,
                  field3 LIKE tabelle2-field3,
                  field2 LIKE tabelle2-field2,
                  field4 LIKE tabelle1-field4,
                  field1 LIKE tabelle1-field1,
                  field5 LIKE tabelle3-field5,
                 END OF struc_out_table1.
        CLASS-DATA: it_out_table1   TYPE TABLE OF   struc_out_table1,
                    ctl_salv_list   TYPE REF TO     cl_salv_table,
                    ctl_salv_exc    TYPE REF TO     cx_salv_msg.
    ENDCLASS.                    "test_class DEFINITION
    *&amp;---------------------------------------------------------------------*
    *&amp; Class Test Implementation
    *&amp;---------------------------------------------------------------------*
    CLASS test_class IMPLEMENTATION.
    *&amp;---------------------------------------------------------------------*
    *&amp; Method read_data
    *&amp;---------------------------------------------------------------------*
      METHOD read_data.
        SELECT tabelle2~field2 tabelle2~field3 tabelle1~field1
           FROM tabelle2
              INNER JOIN tabelle1
                ON tabelle2~field3 = tabelle1~field3
                INTO CORRESPONDING FIELDS OF TABLE it_out_table1
                  WHERE    tabelle1~field1 = l_field1
                  AND      tabelle2~field2 = l_field2
                  ORDER BY tabelle2~field3.
            CALL METHOD fill_list.
      ENDMETHOD.                    "read_data
    *&amp;---------------------------------------------------------------------*
    *&amp; Method fill_list
    *&amp;---------------------------------------------------------------------*
      METHOD fill_list.
        TRY.
          cl_salv_table=>factory(
            EXPORTING
              list_display = 'X'
            IMPORTING
              r_salv_table = ctl_salv_list
            CHANGING
              t_table      = it_out_table1
                      ctl_salv_list->display( ).
        CATCH cx_salv_msg INTO ctl_salv_exc.
          MESSAGE ctl_salv_exc TYPE 'I'
            DISPLAY LIKE 'E'.
        ENDTRY.
      ENDMETHOD.
    ENDCLASS.                    "test_class IMPLEMENTATION
    START-OF-SELECTION.
      test_class=>read_data( ).

    Hi Marc,
    You may use any of the above ALVs. Either should suit your requirements.
    If I understand you correctly, you want to add an extra column in the displayed ALV grid/table. The values to be displayed in this additional column are not present in the Tables, but you want to calculate the values at runtime.
    As you know already, the ALV needs a field-catalog  [FC] and  a table storing the data [IT].
    Please do the following.
    1. Create a local structure (LS) having the relevant database tables and your new columns. You can't use a DB structure if all the columns you want to show are not present in the DB structure.
    2. Create a internal table with line type LS. This table (IT) has to be passed to the ALV.
    3. Manually fill the columns in the IT as you need it.
    If you are using FM 'REUSE_ALV_FIELDCATALOG_MERGE' to build your field-catalog, your problem is solved here.  Instead of the DB structure, you have to pass your own structure to this FM.
    However, if you are using manual creation of the FC, you'll need to append additional rows to the FC manually.
    Cheers!
    Abhinava

  • Using ALV Grid for data Input

    Hi experts.
    Can someone assist me with information on using ALV grid for data input. Please give a simple example if possible.
    I am mainly interested in the part in which we can transfer data from the grid changing the internal table's data.

    Try this code:
    REPORT z_demo_alv_jg.
    TYPE-POOLS                                                          *
    TYPE-POOLS: slis.
    INTERNAL TABLES/WORK AREAS/VARIABLES                                *
    DATA: i_fieldcat TYPE slis_t_fieldcat_alv,
          i_index TYPE STANDARD TABLE OF i WITH HEADER LINE,
          w_field TYPE slis_fieldcat_alv,
          p_table LIKE dd02l-tabname,
          dy_table TYPE REF TO data,
          dy_tab TYPE REF TO data,
          dy_line TYPE REF TO data.
    FIELD-SYMBOLS                                                       *
    FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
                   <dyn_wa> TYPE ANY,
                   <dyn_field> TYPE ANY,
                   <dyn_tab_temp> TYPE STANDARD TABLE.
    SELECTION SCREEN                                                    *
    PARAMETERS: tabname(30) TYPE c,
                lines(5)  TYPE n.
    START-OF-SELECTION                                                  *
    START-OF-SELECTION.
    Storing table name
      p_table = tabname.
    Create internal table dynamically with the stucture of table name
    entered in the selection screen
      CREATE DATA dy_table TYPE STANDARD TABLE OF (p_table).
      ASSIGN dy_table->* TO <dyn_table>.
      IF sy-subrc <> 0.
        MESSAGE i000(z_zzz_ca_messages) WITH ' No table found'.
        LEAVE TO LIST-PROCESSING.
      ENDIF.
    Create workarea for the table
      CREATE DATA dy_line LIKE LINE OF <dyn_table>.
      ASSIGN dy_line->* TO <dyn_wa>.
    Create another temp. table
      CREATE DATA dy_tab TYPE STANDARD TABLE OF (p_table).
      ASSIGN dy_tab->* TO <dyn_tab_temp>.
      SORT i_fieldcat BY col_pos.
    Select data from table
      SELECT * FROM (p_table)
      INTO TABLE <dyn_table>
      UP TO lines ROWS.
      REFRESH <dyn_tab_temp>.
    Display report
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program       = sy-repid
          i_structure_name         = p_table
          i_callback_user_command  = 'USER_COMMAND'
          i_callback_pf_status_set = 'SET_PF_STATUS'
        TABLES
          t_outtab                 = <dyn_table>
        EXCEPTIONS
          program_error            = 1
          OTHERS                   = 2.
      IF sy-subrc <> 0.
      ENDIF.
    *&      Form  SET_PF_STATUS
          Setting custom PF-Status
         -->RT_EXTAB   Excluding table
    FORM set_pf_status USING rt_extab TYPE slis_t_extab.
      SET PF-STATUS 'Z_STANDARD'.
    ENDFORM.                    "SET_PF_STATUS
    *&      Form  user_command
          Handling custom function codes
         -->R_UCOMM      Function code value
         -->RS_SELFIELD  Info. of cursor position in ALV
    FORM user_command  USING    r_ucomm LIKE sy-ucomm
                               rs_selfield TYPE slis_selfield.
    Local data declaration
      DATA: li_tab TYPE REF TO data,
            l_line TYPE REF TO data.
    Local field-symbols
      FIELD-SYMBOLS:<l_tab> TYPE table,
                    <l_wa>  TYPE ANY.
    Create table
      CREATE DATA li_tab TYPE STANDARD TABLE OF (p_table).
      ASSIGN li_tab->* TO <l_tab>.
    Create workarea
      CREATE DATA l_line LIKE LINE OF <l_tab>.
      ASSIGN l_line->* TO <l_wa>.
      CASE r_ucomm.
      When a record is selected
        WHEN '&IC1'.
        Read the selected record
          READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX
          rs_selfield-tabindex.
          IF sy-subrc = 0.
          Store the record in an internal table
            APPEND <dyn_wa> TO <l_tab>.
          Fetch the field catalog info
            CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
              EXPORTING
                i_program_name         = 'Z_DEMO_PDF_JG'
                i_structure_name       = p_table
              CHANGING
                ct_fieldcat            = i_fieldcat
              EXCEPTIONS
                inconsistent_interface = 1
                program_error          = 2
                OTHERS                 = 3.
            IF sy-subrc = 0.
            Make all the fields input enabled except key fields*
              w_field-input = 'X'.
              MODIFY i_fieldcat FROM w_field TRANSPORTING input
              WHERE key IS INITIAL.
            ENDIF.
          Display the record for editing purpose
            CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
              EXPORTING
                i_callback_program    = sy-repid
                i_structure_name      = p_table
                it_fieldcat           = i_fieldcat
                i_screen_start_column = 10
                i_screen_start_line   = 15
                i_screen_end_column   = 200
                i_screen_end_line     = 20
              TABLES
                t_outtab              = <l_tab>
              EXCEPTIONS
                program_error         = 1
                OTHERS                = 2.
            IF sy-subrc = 0.
            Read the modified data
              READ TABLE <l_tab> INDEX 1 INTO <l_wa>.
            If the record is changed then track its index no.
            and populate it in an internal table for future
            action
              IF sy-subrc = 0 AND <dyn_wa> <> <l_wa>.
                <dyn_wa> = <l_wa>.
                i_index = rs_selfield-tabindex.
                APPEND i_index.
              ENDIF.
            ENDIF.
          ENDIF.
      When save button is pressed
        WHEN 'SAVE'.
        Sort the index table
          SORT i_index.
        Delete all duplicate records
          DELETE ADJACENT DUPLICATES FROM i_index.
          LOOP AT i_index.
          Find out the changes in the internal table
          and populate these changes in another internal table
            READ TABLE <dyn_table> ASSIGNING <dyn_wa> INDEX i_index.
            IF sy-subrc = 0.
              APPEND <dyn_wa> TO <dyn_tab_temp>.
            ENDIF.
          ENDLOOP.
        Lock the table
          CALL FUNCTION 'ENQUEUE_E_TABLE'
            EXPORTING
              mode_rstable   = 'E'
              tabname        = p_table
            EXCEPTIONS
              foreign_lock   = 1
              system_failure = 2
              OTHERS         = 3.
          IF sy-subrc = 0.
          Modify the database table with these changes
            MODIFY (p_table) FROM TABLE <dyn_tab_temp>.
            REFRESH <dyn_tab_temp>.
          Unlock the table
            CALL FUNCTION 'DEQUEUE_E_TABLE'
              EXPORTING
                mode_rstable = 'E'
                tabname      = p_table.
          ENDIF.
      ENDCASE.
      rs_selfield-refresh = 'X'.
    ENDFORM.                    "user_command

  • Display ALV GRID Using Dynamic Internal Table

    Hi all,
    I try to display ALV Grid using Dynamic Internal Table, but when i activate my program, i get an error message "DYN_TABLE" is not type-compatible with formal parameter "IT_OUTTAB". ( DYN_TABLE is my Dynamic Itab).
    Anybody can help me how to passing Dynamic Itab into ALV Grid ?? Of ALV Grid only accept static Itab ??
    Thanks,

    Hi Vijay,
    It's doesn't work, and make new error "Formal parameter "IT_OUTTAB[]" does not exist. However, the parameter "IT_OUTTAB" has a similar name."
    Because the method is:
    CALL METHOD <ref. var. to CL_GUI_ALV_GRID>->set_table_for_first_display
    EXPORTING
    I_BUFFER_ACTIVE = <any type (ANY)>
    I_STRUCTURE_NAME = <string of type DD02L-TABNAME>
    IS_VARIANT = <structure of type DISVARIANT>
    I_SAVE = <var. of type CHAR01>
    I_DEFAULT = <var. of type CHAR01>
    IS_LAYOUT = <structure of type LVC_S_LAYO>
    IS_PRINT = <structure of type LVC_S_PRNT>
    IT_SPECIAL_GROUPS = <internal table of type LVC_T_SGRP>
    IT_TOOLBAR_EXCLUDING = <internal table of type UI_FUNCTIONS>
    IT_HYPERLINK = <internal table of type LVC_T_HYPE>
    IT_ALV_GRAPHICS = <internal table of type DTC_T_TC>
    CHANGING
    IT_OUTTAB = <internal table>
    IT_FIELDCATALOG = <internal table of type LVC_T_FCAT>
    IT_SORT = <internal table of type LVC_T_SORT>
    IT_FILTER = <internal table of type LVC_T_FILT>
    Thanks,

  • How can I call functionality of ALV Grid by event of button outside grid?

    Hello,
    How can I call functionality of ALV Grid by event of button located outside ALV Grid? For example how to fire printing of this ALV Grid by button click elsewhere on the screen (not in toolbar of ALV Grid).
    Best regards,
    Josef Motl

    hi Motl,
    these are steps to create a button in ALV and trigger an event from it..
    1.Use the parameter i_callback_pf_status_set in the function module REUSE_ALV_GRID_DISPLAY
    i_callback_program = gd_repid
    i_callback_pf_status_set = 'SET_PF_STATUS'
    form set_pf_status using rt_extab type slis_t_extab.
    set pf-status 'NEWALVSTATUS'.
    endform.
    You have to copy the standard ALV pf stauts to 'NEWALVSTATUS' and add your button.
    2.You have to do the following to process the new button click.
    i_callback_user_command = 'USER_COMMAND'
    form user_command using i_ucomm like sy-ucomm
    is_selfield type slis_selfield.
    case i_ucomm.
    3. to copy the standard pf status to a new one.go to the ALV screen and take the menu System -> Status.  Then look for the standard pf status. Copy this to Z range and then add your new button.
    reward points if helpful
    regards
    satesh

  • Reg. can we display alv grid using field groups (extracts)

    Hi,
    can we display alv grid using field groups (extracts). is this possible. i have to develop a blocked alv.
    tnks
    Yerukala Setty

    No, you will need the data in an internal table to use ALV.
    Cheers
    Allan

  • Problem in displaying Alv grid output  using oops........

    hi,
    i have two problems in displaying ALV grid output Using Oops.
    1) How to modify the fieldcatalog after we getting a field catalog using general FM.
    2) initialy it is displaying 13 fields but there are 63 fields .
       eventhough we chage the layout to 63 fields it is displaying only 13 fields , these 13 fields may be different based on our selection but count  of displayed fileds are same . how can display 63 fields at a time .

    Hi,
    You can chnage using below code:
    loop at gt_fieldcat.
    if <gt_fieldcat-field_name> = 'FIELDNAME'.
    endif.
    modify gt_fieldcat.
    clear gt_fieldcat.
    endloop.
    Make sure that all the field should not have no_out = 'X' and tech = 'X'.
    Thanks,
    Sriram Ponna.

  • Hotspot click for only some rows in ALV grid for a particular column ?

    Hi there,
            In ALV grid, we can make Hotspot enable for all rows in a specified column
    by specifying in the fieldcatalog with Hotspot attribute set as true.
    But I want to enable Hotspot only for certain rows in the particular column. I tried with MC_STYLE4_LINK , but I didnt got the required result.
    So , how could I achieve that in ALV grid.
    Points would be rewarded for helpful answers.
    Regards,
    Anil .

    Hi,
    You can do it for a column. Please refer to the code snippet below,
      DATA : it_fcat TYPE lvc_t_fcat,
             wa_fcat LIKE LINE OF it_fcat.
    CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
       EXPORTING
      I_BUFFER_ACTIVE              =
         i_structure_name             = 'SMMW_ALERTS_ICON_S'
      I_CLIENT_NEVER_DISPLAY       = 'X'
      I_BYPASSING_BUFFER           =
      I_INTERNAL_TABNAME           =
        CHANGING
          ct_fieldcat                  = it_fcat
       EXCEPTIONS
         inconsistent_interface       = 1
         program_error                = 2
         OTHERS                       = 3
    LOOP AT it_fcat INTO wa_fcat.
      IF wa_fcat-fieldname = 'STATUS'.
        wa_fcat-hotspot = 'X'.
        MODIFY it_fcat FROM wa_fcat.
        CLEAR wa_fcat.
      ENDIF.
    ENDLOOP.
    CALL METHOD l_obj_alv_grid->set_table_for_first_display
          EXPORTING
        i_structure_name              = 'SMMW_ALERTS_ICON_S'
       CHANGING
            it_outtab                     = lt_alerts_st
            it_fieldcatalog               = it_fcat.
    In the above replace the structure 'SMMW_ALERTS_ICON_S' with your structure and column 'STATUS' with your desired column.
    Hope this helps,
    Regards,
    Vinodh

  • How to display ALV grid in a graphical display??

    Hello All,
    I want to display the ALV grid output in graphical format. I did not see any particular Function code or event in ALV for graphs. Hence I designed a PF status myself. But when I use the Function module "Graph_2D", it gives me an error.
    Can you guys suggest which is the best Function module to display the ALV output in graphical format?
    Regards,
    Abhishek
    P.S: Points will be awarded to the answers which will solve the issue

    This piece of code is giving graphical output , u can check it in ur machine.
    REPORT  ZSKC_GRAPH.
    data : begin of itab occurs 0,
            day type i,
            val type i,
           end   of itab.
    start-of-selection.
      do 5 times.
        clear itab.
        itab-day = sy-index.
        itab-val = sy-index + ( sy-index * sy-index ).
        append itab.
      enddo.
      CALL FUNCTION 'GRAPH_2D'
        TABLES
          DATA                     = itab
       EXCEPTIONS
         GUI_REFUSE_GRAPHIC       = 1
         OTHERS                   = 2
      IF SY-SUBRC <> 0.
    *    Give some message.
      ENDIF.
    You just pass ur internal table to this Function module - Do you need to display column captions etc ?? In that case you will have to use GRAPH_MATRIX_2D.

  • Re-Displaying ALV Grid

    This is a follow-up to a question I posed earlier regarding my inability to get the ALV grid to display with a new table name.
    Can anyone tell me what I need to do to get it to re-display with the new table name?
    To use it, you enter a table name in the editor screen.  Screens 100 and 200 are just custom containers with no other attributes.
    Thanks (and points) for any help!
    PROGRAM zz_temp.
    TYPES: BEGIN OF type_text_lines,
      line(2048) TYPE c,
    END OF type_text_lines.
    DATA: g_editor             TYPE REF TO cl_gui_textedit,
          g_r_editor_container TYPE REF TO cl_gui_custom_container,
          g_r_alv_grid         TYPE REF TO cl_gui_alv_grid ,
          g_r_alv_container TYPE REF TO cl_gui_custom_container ,
          g_container          TYPE scrfname VALUE 'ALV_CUSTOM_CONTROL_0200' ,
          g_t_text_lines       TYPE TABLE OF type_text_lines,
          g_t_fcat             TYPE lvc_t_fcat,
          g_ok_code            TYPE sy-ucomm,
          g_save_ok            TYPE sy-ucomm,
          g_repid              TYPE sy-repid,
          l_tab(20)            TYPE c.
    FIELD-SYMBOLS <struc>  TYPE ANY.
    FIELD-SYMBOLS <tab>    TYPE table.
    DATA s_ref             TYPE REF TO data.
    DATA t_ref             TYPE REF TO data.
    START-OF-SELECTION.
      CALL SCREEN 100.
    FORM runsql.
      CONCATENATE LINES OF g_t_text_lines INTO l_tab.
      CREATE DATA s_ref      TYPE (l_tab).
      CREATE DATA t_ref      TYPE TABLE OF (l_tab).
      ASSIGN t_ref->*    TO <tab>.
      SELECT * FROM (l_tab) INTO TABLE <tab>.
      CALL SCREEN 200.
    ENDFORM."
    MODULE pbo OUTPUT.
      CASE sy-dynnr.
        WHEN '0100'.
          IF g_editor IS INITIAL.
            SET PF-STATUS 'MAIN100'.
            g_repid = sy-repid.
            CREATE OBJECT g_r_editor_container
            EXPORTING
              container_name = 'TEXTEDITOR1'
            EXCEPTIONS
              cntl_error = 1
              cntl_system_error = 2
              create_error = 3
              lifetime_error = 4
              lifetime_dynpro_dynpro_link = 5.
            CREATE OBJECT g_editor
            EXPORTING
              parent = g_r_editor_container
              wordwrap_mode = cl_gui_textedit=>wordwrap_at_fixed_position
            EXCEPTIONS
              OTHERS = 1.
          ENDIF.
        WHEN '0200'.
          PERFORM create_alv_grid.
      ENDCASE.
    ENDMODULE."
    MODULE pai INPUT.
      g_save_ok = g_ok_code.
      CASE g_save_ok.
        WHEN 'BACK'.
        WHEN 'EXIT'.
        WHEN 'CANCEL'.
          PERFORM exit_program.
        WHEN 'RUNSQL'.
          CALL METHOD g_editor->get_text_as_r3table
            IMPORTING
              table  = g_t_text_lines
            EXCEPTIONS
              OTHERS = 1.
          PERFORM runsql.
      ENDCASE.
    ENDMODULE."
    FORM create_field_catalog.
      DATA: l_structure_name LIKE  dd02l-tabname.
      CLEAR g_t_fcat.
      l_structure_name = l_tab.
      CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'
        EXPORTING
          i_structure_name       = l_structure_name
          i_bypassing_buffer     = 'X'
        CHANGING
          ct_fieldcat            = g_t_fcat
        EXCEPTIONS
          inconsistent_interface = 1
          program_error          = 2
          OTHERS                 = 3.
    ENDFORM."
    FORM create_alv_grid.
      DATA:        l_s_layout      TYPE lvc_s_layo.
      CLEAR: g_r_alv_container,
             g_r_alv_grid.
      PERFORM create_field_catalog.
      CREATE OBJECT g_r_alv_container
             EXPORTING container_name = g_container.
      CREATE OBJECT g_r_alv_grid
             EXPORTING i_parent = g_r_alv_container.
      CALL METHOD g_r_alv_grid->set_table_for_first_display
        EXPORTING
          is_layout          = l_s_layout
          i_bypassing_buffer = 'X'
        CHANGING
          it_outtab          = <tab>
          it_fieldcatalog    = g_t_fcat.
      CALL METHOD g_r_alv_grid->refresh_table_display.
    ENDFORM."
    FORM exit_program.
      CALL METHOD cl_gui_cfw=>flush
        EXCEPTIONS
          OTHERS = 1.
      LEAVE PROGRAM.
    ENDFORM."

    Hello Bjorn
    I would recommend a few changes:
    (1) Create the container and ALV grid instance for screen '200' only once (in a PBO module of screen '200' using a switch:
    CHECK ( g_r_alv_container IS INITIAL ).
    (2) Call method SET_TABLE_FOR_FIRST_DISPLAY in a PBO module of screen '200'. Perhaps add a "flush" to this PBO module, too.
    Regards
       Uwe

  • Subtotal in ALV grid for a particular type and Grand total in ALV

    Hi,
    I need to have sub total for a particular type(eg: goods, services).. and grand total at end in ALV grid..
    ALV output required as below:
    Type     VAT registration number     Country      Total Gross Amounts       Total Tax Amounts       Total Amount, ex-tax
    Goods     ATU12345678     AT                  222.42      0         222.42
    Goods     NL123456789B02     NL               3,417.00      0      3,417.00
         Goods Total                    3,639.42                -         3,639.42
    Services     ATU12345678     AT               2,342.34      0      2,342.34
    Services     NL123456789B02     NL                  223.33      0         223.33
         Services Total                    2,565.67                -         2,565.67
         Grand Total                    6,205.09                -         6,205.09
    Let me as to how to achieve the above type in ALV grid...
    Regards
    Shiva

    check this link..
    Grand Totals in ALV grid disply function module
    or do like this..
    REPORT  ZALVTESTFORSUBTOTAL.
    tables:pa0008.
    type-pools:slis.
    types:begin of ty_pa0008,
          pernr like pa0008-pernr,
          begda like pa0008-begda,
          endda like pa0008-endda,
          ansal like pa0008-ansal,
          lga01 like pa0008-lga01,
          bet01 like pa0008-bet01,
          end of ty_pa0008.
    data:it_pa0008 type standard table of ty_pa0008 with header line.
    data:it_fieldcat type SLIS_T_FIELDCAT_ALV,
         wa_fieldcat type slis_fieldcat_alv,
         it_layout type slis_layout_alv,
         WA_events TYPE slis_alv_event,
         it_events TYPE slis_t_event.
    select-options:s_pernr for pa0008-pernr.
    start-of-selection.
    perform getD_data.
    perform disp_alv.
    *&      Form  getD_data
          text
    -->  p1        text
    <--  p2        text
    form getD_data .
    select pernr
           begda
           endda
           ansal
           lga01
           bet01
           from pa0008
           into table it_pa0008
           where pernr in s_pernr.
    sort it_pa0008 by pernr begda descending.
    endform.                    " getD_data
    *&      Form  disp_alv
          text
    -->  p1        text
    <--  p2        text
    form disp_alv .
    wa_fieldcat-fieldname = 'PERNR'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Personnel no'.
    *WA_FIELDCAT-no_subtotals = 'X'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'BEGDA'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Start date'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'ENDDA'.
    wa_FIELDCAT-REPTEXT_DDIC = 'End date'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'ANSAL'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Annula salary'.
    wa_fieldcat-do_sum = 'X'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'LGA01'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Wage Type'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    wa_fieldcat-fieldname = 'BET01'.
    wa_FIELDCAT-REPTEXT_DDIC = 'Amount for wagetype'.
    append wa_fieldcat to it_fieldcat.
    clear wa_fieldcat.
    DATA: sort TYPE slis_sortinfo_alv,
    it_sort TYPE slis_t_sortinfo_alv.
    sort-fieldname = 'PERNR'.
    sort-subtot = 'X'.
    SORT-UP = 'X'.
    APPEND sort TO it_sort.
    *sort-fieldname = 'BEGDA'.
    *SORT-NO_SUBTOTS = 'X'.
    *APPEND sort TO it_sort.
    IT_layout-totals_text = 'total text'.
    IT_layout-subtotals_text = 'Subtotal text'.
    *WA_EVENTS-NAME = 'SUBTOTAL TEXT'.
    *WA_EVENTS-FORM = 'SUBTOTAL TEXT'.
    *APPEND WA_EVENTS TO IT_EVENTS.
    CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
    EXPORTING
       I_CALLBACK_PROGRAM             = sy-repid
       IS_LAYOUT                      = it_LAYOUT
       IT_FIELDCAT                    = IT_FIELDCAT
       it_sort                        = it_sort
      it_events                      = it_events
       TABLES
        t_outtab                       = it_pa0008 .
    endform.                    " disp_alv

  • Urgent : Problem with Editable  ALV Grid  for Quantity and Currency Fields

    Hi All,
    I am using Editable ALV Grid display and have quantity and value as editable fields in the display.
    When user changes these values these values are not changing properly .
    For the quantity field the domain is MENG13 with 3 deciamal places and here  if we enter 500 it takes it as 0.500   .
    The same problem is for the currency field. Here the Domain is WERT7 with 3 decimal places.
    Here also it takes last 2 digits after decimal places by default.
    Please advice how to get proper values in this case from ALV editable fields.
    Thanks and Regards
    Harshad
    Edited by: Harshad Rahirkar on Dec 25, 2007 7:39 AM

    for all the currency field , it will display like that only.
    u have to manipulate uin program before displaying.
    if they are giving 500, in program multiply with 100 and move it to table.
    when u are getting from table, divinde and display.
    this is what I am doing.
    Reward if helpfull.

Maybe you are looking for