Internal table declaration - work area and body

Hi all
I have declared my internal table in my program as
data : itab_wa type ZRESULT_LINE,
       itab    type ZRESULT_ROW.
Where ZRESULT_LINE and ZRESULT_ROW are the structure and table types.
Now I want to add
data: TCOLOR TYPE SLIS_T_SPECIALCOL_ALV.
in my internal table declaration. How can I do this. Please remember I need to have work area and body in my internal table as I have used work area and body in my code.
Waiting..............
Message was edited by: Raju Boda

HI,
See the Declarion types of workarea and Internal tables
* Table declaration (old method)
DATA: BEGIN OF tab_ekpo OCCURS 0,             "itab with header line
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
END OF tab_ekpo.
*Table declaration (new method)     "USE THIS WAY!!!
TYPES: BEGIN OF t_ekpo,
  ebeln TYPE ekpo-ebeln,
  ebelp TYPE ekpo-ebelp,
END OF t_ekpo.
DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,      "itab
      wa_ekpo TYPE t_ekpo.                    "work area (header line)
* Build internal table and work area from existing internal table
DATA: it_datatab LIKE tab_ekpo OCCURS 0,      "old method
      wa_datatab LIKE LINE OF tab_ekpo.
* Build internal table and work area from existing internal table,
* adding additional fields
TYPES: BEGIN OF t_repdata.
        INCLUDE STRUCTURE tab_ekpo.  "could include EKKO table itself!!
TYPES: bukrs  TYPE ekpo-werks,
       bstyp  TYPE ekpo-bukrs.
TYPES: END OF t_repdata.
DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0,   "itab
      wa_repdata TYPE t_repdata.                 "work area (header line
you need to maintain same structure for both workarea as well Internal table
Regards
Sudheer

Similar Messages

  • Get the fieldnames of a generic internal table or work area

    Hi All,
           I have one generic work area which I have created in the below manner...
    * ET_DATA itself is a generic table of type ANY...can have any internal table data in it.
    * Create dynamic internal table
      CREATE DATA lv_new_table LIKE et_data.
      ASSIGN lv_new_table->* TO <fs_dyn_table>.
    * Create dynamic work area and assign to fieldsymbol.
      CREATE DATA lv_new_line LIKE LINE OF <fs_dyn_table>.
      ASSIGN lv_new_line->*   TO <fs_dyn_wa>.
    Now...I need to get the field names of this dynamic internal table or work area..
    I have already searched in forum...got many answers..but none them gives me the output.
    Please note that I require the field names and not field position..
    Awaiting your suggestions on how to get field names of this dynamic work area...

      create data wa_ref like line of it_data.
      assign wa_ref->* to <p_data>.
      desc_table ?= cl_abap_tabledescr=>describe_by_data( it_data ).
      desc_struc ?= desc_table->get_table_line_type( ).
      describe field <p_data> type rtty components ncom.
    This one is working in our environment without any error. it_data is an importing parameter in the signature of a method of type any table.

  • Smartform Table; Internal table to work area

    Hi,
    I have created smartform with one table,in that internal table values are not moving into workarea,can anyone solve my issue.

    Hi Bose,
    If you are populating internal table values in progarm and passing this internal table to smartforms
    here is the syntax and declaration to follow
    data : itab_final type standard table of type_final (some type) with header line .
    Pass this under tables in your Z program,
    CALL FUNCTION  'smartform name'
           EXPORTING
              archive_index      = toa_dara
              archive_parameters = arc_params
              vbdkl              = vbdkl
              vbdpl              = vbdpl
              makt               = makt
              qals               = qals
              vbco3              = vbco3
            TABLES
              g_final            = g_final
            EXCEPTIONS
              FORMATTING_ERROR   = 1
              INTERNAL_ERROR     = 2
              SEND_ERROR         = 3
              USER_CANCELED      = 4
              OTHERS             = 5.
    In Smartforms,
    Declare this internal table in form interface under tables as,
    G_FINAL     TYPE     Z_TT_FINAL_COA(table type)
    And work area in global data as,
    WA_G_FINAL     TYPE     ZFINAL_COA (structure)
    Now it can be used used in table control  under data column as
    G_FINAL          INTO                  WA_G_FINAL
    Regards,
    Sagar.

  • I need insert /update/modify  ztable from  internal table or work area

    I have one simple problem.
    TYPES: BEGIN OF t_account,
            acc_no          LIKE zztaccountheader-acc_no,
            cust_id         LIKE zztaccountheader-cust_id,
            acc_type        LIKE zztaccountheader-acc_type,
            od_option       LIKE zztaccountheader-od_option,
            od_limit        LIKE zztaccountheader-od_limit,
            od_issue_date   LIKE zztaccountheader-od_issue_date,
            END OF t_account.
    data: lwa_account TYPE  t_account,
         li_account TYPE STANDARD TABLE OF t_account,
    bu scerrin i am inputing data :
    i want modify updare or insert record into ztable by work area  i put following thing
    MOVE : zztaccountheader-acc_no        TO lwa_account-acc_no,
               zztcustomer-cust_id            TO lwa_account-cust_id,
               zztaccountheader-acc_type      TO lwa_account-acc_type,
               zztaccountheader-od_option     TO lwa_account-od_option,
               zztaccountheader-od_limit      TO lwa_account-od_limit,
               zztaccountheader-od_issue_date TO lwa_account-od_issue_date.
        INSERT   zztaccountheader CLIENT SPECIFIED FROM lwa_account .
        CLEAR lwa_account.
      ENDIF.
    i am etting error
    The type of the database table and work area (or internal table)
    "LWA_ACCOUNT" are not Unicode convertible.
    please solve it

    hi,
    decalre like this.
    tables : zztaccountheader.
    data : t_account like zztaccountheader occurs 0 with header line.
    data: lwa_account TYPE t_account,
    li_account TYPE STANDARD TABLE OF t_account,
    MOVE : zztaccountheader-acc_no TO lwa_account-acc_no,
    zztcustomer-cust_id TO lwa_account-cust_id,
    zztaccountheader-acc_type TO lwa_account-acc_type,
    zztaccountheader-od_option TO lwa_account-od_option,
    zztaccountheader-od_limit TO lwa_account-od_limit,
    zztaccountheader-od_issue_date TO lwa_account-od_issue_date.
    INSERT zztaccountheader CLIENT SPECIFIED FROM lwa_account .
    CLEAR lwa_account.
    ENDIF.
    rgss
    anver
    if hlped mark points

  • Internal table with work area

    hi all,
    data: BEGIN OF it_summ OCCURS 0.
      INCLUDE STRUCTURE yapn_summary.
      data: END OF it_summ.
    data : wa_demo1 type yapn_summary.
    clear wa_demo1.
            wa_demo1-sumr = 'hai'.
    append wa_Demo1 to it_summ.
    WRITE: it_summ-sumr.
    its not get output..
    i want to display for hai using it_summ.
    donot use work area.
    how to change it.?
    reply me soon,
    s.suresh.

    You can't write out an internal table - you can only write out a line (or components of a line) of an internal table.  So you MUST use a work area.  If you use OCCURS 0 then you've a table with a headerline, and so don't need a workarea.  However, later versions of ABAP discourage tables with headerline, and it is preferred to define a specific work area.  So, either:
    data: BEGIN OF it_summ OCCURS 0.
    INCLUDE STRUCTURE yapn_summary.
    data: END OF it_summ.
    clear it_summ.
    it_summ-sumr = 'hai'.
    append wa_Demo1 to it_summ.
    LOOP AT it_summ.
      WRITE: it_summ-sumr.
    ENDLOOP.
    Now, you see here that at some points it_summ refers to the table, and at others to the header-line.  This is ambiguous, and therefore BAD.  It's better to define the table and work area seperately.
    data: it_summ TYPE STANDARD TABLE OF yapn_summary WITH NON-UNIQUE KEY table_line.
    data : wa_demo1 type yapn_summary.
    clear wa_demo1.
    wa_demo1-sumr = 'hai'.
    append wa_Demo1 to it_summ.
    LOOP AT it_summ INTO wa_demo1.
      WRITE: wa_demo1-sumr.
    ENDLOOP.
    matt

  • Error: you cannot create an internal table as work area

    Hi, My code is as follows and when i perform a check it gives the above mentioned error in the select statement.
    TYPES: BEGIN OF t_vbrk,
            vbeln            TYPE vbrk-vbeln,
            vtweg            TYPE vbrk-vtweg,
          END OF t_vbrk.
    DATA vbrktab TYPE TABLE OF t_vbrk.
    SELECT      vbeln
                    vtweg
             FROM   vbrk
             INTO  vbrktab
             FOR ALL ENTRIES IN xxcvb
             WHERE  vbeln       = xxcvb-vbeln.
          INSERT TABLE vbrktab.
        ENDSELECT.
    where xxcvb is another internal table with some key values.

    Hi
    I don't know how you've defined XXCVB, but u should write:
    TYPES: BEGIN OF T_VBRK,
             VBELN TYPE VBRK-VBELN,
             VTWEG TYPE VBRK-VTWEG,
           END OF T_VBRK.
    DATA: VBRKTAB    TYPE TABLE OF T_VBRK,
          WA_VBRKTAB TYPE T_VBRK.
    SELECT VBELN VTWEG FROM VBRK INTO TABLE VBRKTAB
      FOR ALL ENTRIES IN XXCVB
         WHERE VBELN = XXCVB-VBELN.
    LOOP AT VBRKTAB INTO WA_VBRKTAB.
    ENDLOOP.
    Max

  • Difference between work area and internal tables.

    Hi  I wanna know the difference between work area and internal tables.
    what happend if i give with out header line in internal table.
    also how to assosiate work area to internal table in that scenario.

    Hi Balaji..
    The internal table is an ABAP runtime object which has two parts the Body and the header.
    Whereas a work area cannot have a body.. It is mere a field or group of fields which can hold values at runtime..
    In the SAP higher versions mySAP ERP, the use of tables with header line is made obsolete.. But there is absolutely no problem with the same..
    Just think that when you define an internal table with occurs or with header line statement, the system automatically creates a workarea with this table, using which you can access the contents in the bosy of tyhe table.. You can read a record from the table body to this header or add a record in the header to the internal table body..
    When you work with a table ITAB without a header line, you can not use statements like READ TABLE, APPEND, INSERT etc without giving an explicit work area..
    Suppose i have an internal table like:
    DATA : itab TYPE STANDARD TABLE OF t001.
    This table will not have a header with it.
    If you will use APPEND itab. The compilor will give error.
    Here i will create a work area with same structure of the table.
    DATA : e_wa TYPE t001.
    Now i will write:
    APPEND e_wa TO itab.
    READ TABLE itab INTO e_wa WITH KEY xxxxxx
    LOOP AT itab INTO e_wa...           etc..
    In a better approach we use Field symbols with such tables, instead of structures
    FIELD-SYMBOLS: <fs_itab> TYPE t001.
    So,
    LOOP AT itab ASSIGNING <fs_itab>
    READ TABLE itab ASSIGNING <fs_itab> etc.. However we can not use field symbols in few cases..
    I hope this will help you..
    Thanks and Best Regards,
    Vikas Bittera.
    **Points for usefull answers**

  • Work area and internal table

    hi friends,
    Please let me know when do we use work area and when do we use internal table.
    Thanks in advance
    Tina Wilson

    Work areas are used with internal tables.  For example if you have an internal table defined like this.
    data: itab type table of mara.
    This internal table can hold many rows of data, right?  SO say you need to read this data.  Well you will need to LOOP or READ the internal table, since this internal table has no header line(please to put the read data), you need to have a work area to put the data into.
    <b>data: wa like line of itab.</b>
    Loop at itab <b>into wa</b>.
    endloop.
    Now if you defined the internal table with a header line, there is no reason to have the work area and you can just do the same like this.
    data: itab type table of mara <b>with header line</b>.
    Loop at itab.
    endloop.
    It is now best practice to use work areas instead of header lines because in ABAP OO, header lines are not allowed.
    Regards,
    Rich Heilman

  • DIFF: Field string ,Structure and Internal table declaration

    Hai,
           what is the diference between  Field string ,Structure in ABAP program and Internal table declaration and how it will work ?
    Thank you
    ASHOK KUMAR.

    hi,
    Look this u will get a good idea.
    *& Report  ZTYPES                                                      *
    REPORT  ZTYPES                                                  .
    * Table declaration (old method)
    DATA: BEGIN OF tab_ekpo OCCURS 0,             "itab with header line
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
    END OF tab_ekpo.
    *Table declaration (new method)     "USE THIS WAY!!!
    TYPES: BEGIN OF t_ekpo,
      ebeln TYPE ekpo-ebeln,
      ebelp TYPE ekpo-ebelp,
    END OF t_ekpo.
    DATA: it_ekpo TYPE STANDARD TABLE OF t_ekpo INITIAL SIZE 0,      "itab
          wa_ekpo TYPE t_ekpo.                    "work area (header line)
    * Build internal table and work area from existing internal table
    DATA: it_datatab LIKE tab_ekpo OCCURS 0,      "old method
          wa_datatab LIKE LINE OF tab_ekpo.
    * Build internal table and work area from existing internal table,
    * adding additional fields
    TYPES: BEGIN OF t_repdata.
            INCLUDE STRUCTURE tab_ekpo.  "could include EKKO table itself!!
    TYPES: bukrs  TYPE ekpo-werks,
           bstyp  TYPE ekpo-bukrs.
    TYPES: END OF t_repdata.
    DATA: it_repdata TYPE STANDARD TABLE OF t_repdata INITIAL SIZE 0,   "itab
          wa_repdata TYPE t_repdata.                 "work area (header line)
    Regards
    Reshma

  • Basic query regarding work-area and select query

    hi
    dear sdn members,
    thanks too all for solving all my query's up till now
    i am stuck in a problem need help
    1)  why basically work-area has been used ? the sole purpose
    2)  different types of select query ? only coding examples
    note: no links pls
    regards,
    virus

    hi,
    Work Area
    Description for a data object that is particularly useful when working with internal tables or database tables as a source for changing operations or a target for reading operations.
    WORKAREA is a structure that can hold only one record at a time. It is a collection of fields. We use workarea as we cannot directly read from a table. In order to interact with a table we need workarea. When a Select Statement is executed on a table then the first record is read and put into the header of the table and from there put into the header or the workarea(of the same structure as that of the table)of the internal table and then transferred top the body of the internal table or directly displayed from the workarea.
    Each row in a table is a record and each column is a field.
    While adding or retrieving records to / from internal table we have to keep the record temporarily.
    The area where this record is kept is called as work area for the internal table. The area must have the same structure as that of internal table. An internal table consists of a body and an optional header line.
    Header line is a implicit work area for the internal table. It depends on how the internal table is declared that the itab will have the header line or not.
    .g.
    data: begin of itab occurs 10,
    ab type c,
    cd type i,
    end of itab. " this table will have the header line.
    data: wa_itab like itab. " explicit work area for itab
    data: itab1 like itab occurs 10. " table is without header line.
    The header line is a field string with the same structure as a row of the body, but it can only hold a single row.
    It is a buffer used to hold each record before it is added or each record as it is retrieved from the internal table. It is the default work area for the internal table.
    With header line
    SELECT.
    Put the curson on that word and press F1 . You can see the whole documentation for select statements.
    select statements :
    SELECT result
    FROM source
    INTO|APPENDING target
    [[FOR ALL ENTRIES IN itab] WHERE sql_cond]
    Effect
    SELECT is an Open-SQL-statement for reading data from one or several database tables into data objects.
    The select statement reads a result set (whose structure is determined in result ) from the database tables specified in source, and assigns the data from the result set to the data objects specified in target. You can restrict the result set using the WHERE addition. The addition GROUP BY compresses several database rows into a single row of the result set. The addition HAVING restricts the compressed rows. The addition ORDER BY sorts the result set.
    The data objects specified in target must match the result set result. This means that the result set is either assigned to the data objects in one step, or by row, or by packets of rows. In the second and third case, the SELECT statement opens a loop, which which must be closed using ENDSELECT. For every loop pass, the SELECT-statement assigns a row or a packet of rows to the data objects specified in target. If the last row was assigned or if the result set is empty, then SELECT branches to ENDSELECT . A database cursor is opened implicitly to process a SELECT-loop, and is closed again when the loop is ended. You can end the loop using the statements from section leave loops.
    Up to the INTO resp. APPENDING addition, the entries in the SELECTstatement define which data should be read by the database in which form. This requirement is translated in the database interface for the database system´s programming interface and is then passed to the database system. The data are read in packets by the database and are transported to the application server by the database server. On the application server, the data are transferred to the ABAP program´s data objects in accordance with the data specified in the INTO and APPENDING additions.
    System Fields
    The SELECT statement sets the values of the system fields sy-subrc and sy-dbcnt.
    sy-subrc Relevance
    0 The SELECT statement sets sy-subrc to 0 for every pass by value to an ABAP data object. The ENDSELECT statement sets sy-subrc to 0 if at least one row was transferred in the SELECT loop.
    4 The SELECT statement sets sy-subrc to 4 if the result set is empty, that is, if no data was found in the database.
    8 The SELECT statement sets sy-subrc to 8 if the FOR UPDATE addition is used in result, without the primary key being specified fully after WHERE.
    After every value that is transferred to an ABAP data object, the SELECT statement sets sy-dbcnt to the number of rows that were transferred. If the result set is empty, sy-dbcnt is set to 0.
    Notes
    Outside classes, you do not need to specify the target area with INTO or APPENDING if a single database table or a single view is specified statically after FROM, and a table work area dbtab was declared with the TABLES statement for the corresponding database table or view. In this case, the system supplements the SELECT-statement implicitly with the addition INTO dbtab.
    Although the WHERE-condition is optional, you should always specify it for performance reasons, and the result set should not be restricted on the application server.
    SELECT-loops can be nested. For performance reasons, you should check whether a join or a sub-query would be more effective.
    Within a SELECT-loop you cannot execute any statements that lead to a database commit and consequently cause the corresponding database cursor to close.
    SELECT - result
    Syntax
    ... lines columns ... .
    Effect
    The data in result defines whether the resulting set consists of multiple rows (table-like structure) or a single row ( flat structure). It specifies the columns to be read and defines their names in the resulting set. Note that column names from the database table can be changed. For single columns, aggregate expressions can be used to specify aggregates. Identical rows in the resulting set can be excluded, and individual rows can be protected from parallel changes by another program.
    The data in result consists of data for the rows lines and for the columns columns.
    SELECT - lines
    Syntax
    ... { SINGLE }
    | { { } } ... .
    Alternatives:
    1. ... SINGLE
    2. ... { }
    Effect
    The data in lines specifies that the resulting set has either multiple lines or a single line.
    Alternative 1
    ... SINGLE
    Effect
    If SINGLE is specified, the resulting set has a single line. If the remaining additions to the SELECT command select more than one line from the database, the first line that is found is entered into the resulting set. The data objects specified after INTO may not be internal tables, and the APPENDING addition may not be used.
    An exclusive lock can be set for this line using the FOR UPDATE addition when a single line is being read with SINGLE. The SELECT command is used in this case only if all primary key fields in logical expressions linked by AND are checked to make sure they are the same in the WHERE condition. Otherwise, the resulting set is empty and sy-subrc is set to 8. If the lock causes a deadlock, an exception occurs. If the FOR UPDATE addition is used, the SELECT command circumvents SAP buffering.
    Note
    When SINGLE is being specified, the lines to be read should be clearly specified in the WHERE condition, for the sake of efficiency. When the data is read from a database table, the system does this by specifying comparison values for the primary key.
    Alternative 2
    Effect
    If SINGLE is not specified and if columns does not contain only aggregate expressions, the resulting set has multiple lines. All database lines that are selected by the remaining additions of the SELECT command are included in the resulting list. If the ORDER BY addition is not used, the order of the lines in the resulting list is not defined and, if the same SELECT command is executed multiple times, the order may be different each time. A data object specified after INTO can be an internal table and the APPENDING addition can be used. If no internal table is specified after INTO or APPENDING, the SELECT command triggers a loop that has to be closed using ENDSELECT.
    If multiple lines are read without SINGLE, the DISTINCT addition can be used to exclude duplicate lines from the resulting list. If DISTINCT is used, the SELECT command circumvents SAP buffering. DISTINCT cannot be used in the following situations:
    If a column specified in columns has the type STRING, RAWSTRING, LCHAR or LRAW
    If the system tries to access pool or cluster tables and single columns are specified in columns.
    Note
    When specifying DISTINCT, note that you have to carry out sort operations in the database system for this.
    SELECT - columns
    Syntax
    | { {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ... }
    | (column_syntax) ... .
    Alternatives:
    1. ... *
    2. ... {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ...
    3. ... (column_syntax)
    Effect
    The input in columns determines which columns are used to build the resulting set.
    Alternative 1
    Effect
    If * is specified, the resulting set is built based on all columns in the database tables or views specified after FROM, in the order given there. The columns in the resulting set take on the name and data type from the database tables or views. Only one data object can be specified after INTO.
    Note
    If multiple database tables are specified after FROM, you cannot prevent multiple columns from getting the same name when you specify *.
    Alternative 2
    ... {col1|aggregate( col1 )}
    {col2|aggregate( col2 )} ...
    Effect
    A list of column labels col1 col2 ... is specified in order to build the resulting list from individual columns. An individual column can be specified directly or as an argument of an aggregate function aggregate. The order in which the column labels are specified is up to you and defines the order of the columns in the resulting list. Only if a column of the type LCHAR or LRAW is listed does the corresponding length field also have to be specified directly before it. An individual column can be specified multiple times.
    The addition AS can be used to define an alternative column name a1 a2 ... with a maximum of fourteen digits in the resulting set for every column label col1 col2 .... The system uses the alternative column name in the additions INTO|APPENDING CORRESPONDING FIELDS and ORDER BY. .
    Column labels
    The following column labels are possible:
    If only a single database table or a single view is specified after FROM, the column labels in the database table - that is, the names of the components comp1 comp2... - can be specified directly for col1 col2 ... in the structure of the ABAP Dictionary.
    If the name of the component occurs in multiple database tables of the FROM addition, but the desired database table or the view dbtab is only specified once after FROM, the names dbtab~comp1 dbtab~comp2 ... have to be specified for col1 col2 .... comp1 comp2 ... are the names of the components in the structure of the ABAP Dictionary.
    If the desired database table or view occurs multiple times after FROM, the names tabalias~comp1 tabalias~comp2 ... have to be specified for col1 col2 .... tabalias is the alternative table name of the database table or view defined after FROM, and comp1 comp2 ... are the names of the components in the structure of the ABAP Dictionary.
    The data type of a single column in the resulting list is the datatype of the corresponding component in the ABAP Dictionary. The corresponding data object after INTO or APPENDING has to be selected accordingly.
    Note
    If multiple database tables are specified after FROM, you can use alternative names when specifying single columns to avoid having multiple columns with the same name.
    Example
    Read specific columns of a single row.
    DATA wa TYPE spfli.
    SELECT SINGLE carrid connid cityfrom cityto
    INTO CORRESPONDING FIELDS OF wa
    FROM spfli
    WHERE carrid EQ 'LH' AND connid EQ '0400'.
    IF sy-subrc EQ 0.
    WRITE: / wa-carrid, wa-connid, wa-cityfrom, wa-cityto.
    ENDIF.
    Alternative 3
    ... (column_syntax)
    Effect
    Instead of static data, a data object column_syntax in brackets can be specified, which, when the command is executed, either contains the syntax shown with the static data, or is initial. The data object column_syntax can be a character-type data object or an internal table with a character-type data type. The syntax in column_syntax, like in the ABAP editor, is not case-sensitive. When specifying an internal table, you can distribute the syntax over multiple rows.
    If column_syntax is initial when the command is executed, columns is implicitly set to * and all columns are read.
    If columns are specificied dynamically without the SINGLE addition, the resulting set is always regarded as having multiple rows.
    Notes
    Before Release 6.10, you could only specify an internal table with a flat character-type row type for column_syntax with a maximum of 72 characters. Also, before Release 6.10, if you used the DISTINCT addition for dynamic access to pool tables or cluster tables, this was ignored, but since release 6.10, this causes a known exception.
    If column_syntax is an internal table with header line, the table body and not the header line is evaluated.
    Example
    Read out how many flights go to and from a city. The SELECT command is implemented only once in a sub-program. The column data, including aggregate function and the data after GROUP BY, is dynamic. Instead of adding the column data to an internal l_columns table, you could just as easily concatenate it in a character-type l_columns field.
    PERFORM my_select USING `CITYFROM`.
    ULINE.
    PERFORM my_select USING `CITYTO`.
    FORM my_select USING l_group TYPE string.
    DATA: l_columns TYPE TABLE OF string,
    l_container TYPE string,
    l_count TYPE i.
    APPEND l_group TO l_columns.
    APPEND `count( * )` TO l_columns.
    SELECT (l_columns)
    FROM spfli
    INTO (l_container, l_count)
    GROUP BY (l_group).
    WRITE: / l_count, l_container.
    ENDSELECT.
    ENDFORM.
    SELECT - aggregate
    Syntax
    ... { MAX( col )
    | MIN( col )
    | AVG( col )
    | SUM( col )
    | COUNT( DISTINCT col )
    | COUNT( * )
    | count(*) } ... .
    Effect
    As many of the specified column labels as you like can be listed in the SELECT command as arguments of the above aggregate expression. In aggregate expressions, a single value is calculated from the values of multiple rows in a column as follows (note that the addition DISTINCT excludes double values from the calculation):
    MAX( col ) Determines the maximum value of the value in the column col in the resulting set or in the current group.
    MIN( col ) Determines the minimum value of the content of the column col in the resulting set or in the current group.
    AVG( col ) Determines the average value of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.
    SUM( col ) Determines the sum of the content of the column col in the resulting set or in the current group. The data type of the column has to be numerical.
    COUNT( DISTINCT col ) Determines the number of different values in the column col in the resulting set or in the current group.
    COUNT( * ) (or count(*)) Determines the number of rows in the resulting set or in the current group. No column label is specified in this case.
    If you are using aggregate expressions, all column labels that are not listed as an argument of an aggregate function are listed after the addition GROUP BY. The aggregate functions evaluate the content of the groups defined by GROUP BY in the database system and transfer the result to the combined rows of the resulting set.
    The data type of aggregate expressions with the function MAX, MIN or SUM is the data type of the corresponding column in the ABAP Dictionary. Aggregate expressions with the function AVG have the data type FLTP, and those with COUNT have the data type INT4. The corresponding data object after INTO or APPENDING has to be selected accordingly.
    Note the following points when using aggregate expressions:
    If the addition FOR ALL ENTRIES is used in front of WHERE, or if cluster or pool tables are listed after FROM, no other aggregate expressions apart from COUNT( * ) can be used.
    Columns of the type STRING or RAWSTRING cannot be used with aggregate functions.
    When aggregate expressions are used, the SELECT command makes it unnecessary to use SAP buffering.
    Null values are not included in the calculation for the aggregate functions. The result is a null value only if all the rows in the column in question contain the null value.
    If only aggregate expressions are used after SELECT, the results set has one row and the addition GROUP BY is not necessary. If a non-table type target area is specified after INTO, the command ENDSELECT cannot be used together with the addition SINGLE. If the aggregate expression count( * ) is not being used, an internal table can be specified after INTO, and the first row of this table is filled.
    If aggregate functions are used without GROUP BY being specified at the same time, the resulting set also contains a row if no data is found in the database. If count( * ) is used, the column in question contains the value 0. The columns in the other aggregate functions contain initial values. This row is assigned to the data object specified after INTO, and unless count( * ) is being used exclusively, sy-subrc is set to 0 and sy-dbcnt is set to 1. If count( *) is used exclusively, the addition INTO can be omitted and if no data can be found in the database, sy-subrc is set to 4 and sy-dbcnt is set to 0.
    if helpful reward points

  • Dynamic Work Area and field symbol

    Hi All,
    I'm have a big internal table like this
    data: begin of data occurs 0,
    Field01,
    Field02,
    Field03,
    *bucket 1
    Field04,
    Field05,
    Field06,
    *bucket 2
    Field04,
    Field05,
    Field06,
    *bucket 3
    Field04,
    Field05,
    Field06,
    Field 1, 2 3 will be the same for pernr, first last name.
    Field 4, 5, 6 are the same format but different numbers (or values ) in different buckets.
    Each bucket can be shown (or not) based on the condition of a person, for example if that person live in 2 states, it will show 2 bucket with 2 address info inside each.
    I will run this under get pernr to sort out each person who have many address or not.
    Can I use dynamic work area and field symbol here? if I can, how?
    Really appreciate your help with points...

    You can use the ASSIGN COMPONENT ... and than APPEND the work area to the table.
    Check out this sample program:
    REPORT  ZTEST_NP.
    DATA: BEGIN OF ITAB OCCURS 0,
          F1    TYPE I,
          F2    TYPE I,
          F3    TYPE I,
          END   OF ITAB.
    DATA: WA_ITAB LIKE ITAB.
    DATA: L_CNT TYPE I.
    FIELD-SYMBOLS: <F_FLD> TYPE ANY.
    DO 10 TIMES.    " I want 10 reocrds
      CLEAR L_CNT.
      DO 3 TIMES.   " I have 3 fields
        L_CNT = L_CNT + 1.
        ASSIGN COMPONENT L_CNT OF STRUCTURE WA_ITAB TO <F_FLD>.
        <F_FLD> = L_CNT.
      ENDDO.
      APPEND WA_ITAB TO ITAB.
      CLEAR  ITAB.
    ENDDO.
    LOOP AT ITAB INTO WA_ITAB.
      WRITE: / WA_ITAB-F1,
               WA_ITAB-F2,
               WA_ITAB-F3.
    ENDLOOP.
    Regards,
    Naimesh Patel

  • Internal table with same variable and one select query

    Hi,
    I am a new bee here with may be a silly question.
    I have a internal table as below.
    DATA: BEGIN OF IT_ORDERDETAILS OCCURS 0,
            VBELN LIKE VBAK-VBELN,        "Order number
            BSTNK LIKE VBAK-BSTNK,        "customer PO
            ERDAT LIKE VBAK-ERDAT,        " Order created date
            MATNR LIKE VBAP-MATNR,        "Sales order line item
            KWMENG LIKE VBAP-KWMENG,      "Quantity
            D_VBELN like likp-vbeln,      " delivery no
            POSNR like lips-posnr,        " delivery item
            KUNNR LIKE LIKP-KUNNR,        "ship quantity
      END OF IT_ORDERDETAILS.
    Where VBELN field is in VBAK and LIKP table.
    VBELN in VBAK table = order #
    VBELN in LIKP table is = Delivery #
    I want to use join to fetch data in single select query.
    Below is the select query
    SELECT VBAK~VBELN
            VBAK~BSTNK
            VBAK~ERDAT
            VBAP~MATNR
            VBAP~KWMENG
            likp~vbeln
            lips~posnr
            LIPS~VGBEL
          INTO (IT_ORDERDETAILSvbak, IT_ORDERDETAILSbstnk,     IT_ORDERDETAILSerdat, IT_ORDERDETAILSmatnr, IT_ORDERDETAILSkwmeng, IT_ORDERDETAILSd_vbeln,IT_ORDERDETAILSposnr, IT_ORDERDETAILSkunnr)
    FROM VBAK left outer JOIN VBAP ON ( VBAKVBELN = VBAPVBELN )
    left outer JOIN LIPS ON ( VBAKVBELN = LIPSVGBEL )
      join LIKP on ( LIPSVBELN = LIKPVBELN )
    WHERE VBAK~ERDAT IN CR_DATE.
    I am getting error in the query.
    Please suggest.
    Thanks,
    Rajesh

    Hi rajesh.nayakbola,
    although this is not quite the right place for this, let me give you some notes:
    1. Code should be
    formatted as code
    by markin it with mouse and use above &lt;&gt; button.
    2. Internal tables shoult not be declared using OCCURS clause - this is last century style
    3. Internal tables do not need and should not have a header line, they should use TYPES for declaration
    4. Data should not be declared using LIKE: If they refer to dictionary TYPES, use TYPE. LIKE is only mandatory for data objects declared in your program, i.e. DATA IT_some_ORDERDETAILS like IT_ORDERDETAILS.
    5. If you get an error here, never write "I am getting error" but copy and paste the error message fully.
    - The fields in brackets in  the INTO clause never have ~ character, there is no IT_ORDERDETAILS~vbak, only IT_ORDERDETAILS-vbeln
    It could be something like this:
    TYPES:
      BEGIN OF TY_ORDERDETAILS,
      VBELN TYPE VBAK-VBELN, "Order number
      BSTNK TYPE VBAK-BSTNK, "customer PO
      ERDAT TYPE VBAK-ERDAT, " Order created date
      MATNR TYPE VBAP-MATNR, "Sales order line item
      KWMENG TYPE VBAP-KWMENG, "Quantity
      D_VBELN TYPE likp-vbeln, " delivery no
      POSNR TYPE lips-posnr, " delivery item
      KUNNR TYPE LIKP-KUNNR, "ship quantity
    END OF TY_ORDERDETAILS.
    DATA:
      IT_ORDERDETAILS TYPE TABLE OF TY_ORDERDETAILS.
    SELECT VBAK~VBELN
      VBAK~BSTNK
      VBAK~ERDAT
      VBAP~MATNR
      VBAP~KWMENG 
      likp~vbeln AS D_VBELN
      lips~posnr
      LIKP~KUNNR
    INTO CORRSPONDING FIELDS OF TABLE IT_ORDERDETAILS
    FROM VBAK left outer JOIN VBAP ON ( VBAK~VBELN = VBAP~VBELN )
      left outer JOIN LIPS ON ( VBAK~VBELN = LIPS~VGBEL )
      join LIKP on ( LIPS~VBELN = LIKP~VBELN )
    WHERE VBAK~ERDAT IN CR_DATE.
    Regards,
    Clemens

  • Collect in an internal table with keys plant and material

    Hi ,
    I have an output internal table with material , plant and var quantitites .
    I would like to use Collect statement and sum the quantities but do it by plant and material .
    How do I specify that i want to do it on plant or material ?
    Thanks !

    hi here is an example like urs..
    DATA: BEGIN OF seats,
            carrid TYPE sflight-carrid,
            connid TYPE sflight-connid,
            seatsocc TYPE sflight-seatsocc,
          END OF seats.
    DATA seats_tab LIKE HASHED TABLE OF seats
                   WITH UNIQUE KEY carrid connid.
    SELECT carrid connid seatsocc
           FROM sflight
           INTO seats.
      COLLECT seats INTO seats_tab.
    ENDSELECT.
    check for help..
    http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/collect.htm
    regards,
    venkat

  • Internal table with header line and work area.

    data:itab like LIKE bapimepoheader.
    DATA : BEGIN OF it_po_items OCCURS 0.
            INCLUDE STRUCTURE bapimepoitem.
    DATA : END OF it_po_items.
    DATA:it_input         TYPE STANDARD TABLE OF typ_input,
          wa_input         TYPE typ_input,
    LOOP AT it_input INTO wa_input WHERE poind = 'H'.
    CLEAR wa_po_header.
      wa_po_header-doc_type  = wa_input-bsart.
      wa_po_header-comp_code = wa_input-bukrs.
      wa_po_header-vendor    = wa_input-lifnr.
    CLEAR it_po_items.
      it_po_items-po_item = v_itemcount * 10.
      it_po_items-acctasscat = wa_input-knttp.
      it_po_items-material   = wa_input-matnr.
      it_po_items-plant      = wa_input-werks.
      it_po_items-quantity   = wa_input-menge.
      it_po_items-net_price  = wa_input-netpr.
      it_po_items-po_unit    = wa_input-meins.
      it_po_items-free_item  = wa_input-umson.
      it_po_items-tax_code   = wa_input-mwskz.
      it_po_items-gr_ind     = wa_input-wepos.
      it_po_items-gr_non_val = wa_input-weunb.
      it_po_items-incoterms1 = wa_input-inco1.
      it_po_items-incoterms2 = wa_input-inco2.
      it_po_items-vend_mat   = wa_input-idnlf.
      it_po_items-taxjurcode = wa_input-txjcd.
      it_po_items-item_cat   = wa_input-pstyp.
      APPEND it_po_items.
    here my doubt is whether i can move data from work area to internal table in this way?
    whether this is the correct approach or not?

    hii,
    u can define structure and make workarea ,internal table using that structure.
    for example
    types:begin of struct,
             declare all fields,
             end of struct.
    data:wa type struct,
           int_tab type standard table of struct.
    hope this will help u.

  • Declare work area of type = standard table

    Hi All,
    How to declare a workarea of type standard table in ABAP Objects..
    the syntax check of ABAP Objects showing error for the general ABAP Code
    for the same..
    Thanks in Advance, Sudeep..

    Hi Sudeep,
    I had shown the declarations for internal table and work area as well
    if you just want work area
    just use the second statement
    data : is_vbak type vbak. " work area of VBAK
    Regards
    Gopi

Maybe you are looking for

  • Can you use iCloud to sync contacts and still sync google contacts too

    Just switched my contacts over to sync using icloud between my imac, iphone and ipad. Im wondering, can I sync the contacts somehow with google also? Would be great to gave everyting together and have web access to contacts on any computer.

  • Error in creating standby db... need HELP !!!

    Hi, i want to set up a standby db for current production db and i did the following: 1) shutdown the production db; 2) cp $ORACLE_HOME/oradata/testdb/*.dbf(on production) to the the standby db server; 3) startup the production db; 4) create a standby

  • Firefox 5.0 consistently crashes when trying to run a java applet

    Trying to run a program with JAVA webstart, Firefox crashes. Java version is correct (as verified by Java test). repeatable every time. Sometimes does not generate a crash report (50% of time).

  • Help needed for entity bean

    i have this entity bean tat creates a new row in a mysql database... and using mysql query browser i see the record... but when using the bean to retrieve, it gives finderexception... i have to undeploy + redeploy to be able to retrieve the record...

  • Regarding Bex query option

    Hi Friends, I am working in one poc project in that i want to enable the query(Bex Analyzer 7.0 in outlook 2007) for third party vendor. Where user can develop the BO WEBI Query on this Bex Query. Please tell me the option i have to check. Please hel