Internal table with variable no of columns

Hi All,
I have to create an internal table with some fixed columns and rest of the table should be dynamic. The total no of columns depends on a field of some other table. hence, the number of columns of the table are unknown. How to create such a table.
Thanks,
Neha

Execute this program .. we will get a fair idea about how the dyanmic column are populated in the table. Based on that u can write ur sceond table with 92 columns
*& Report  ZTEST009
REPORT  ztest009 NO STANDARD PAGE HEADING LINE-SIZE 60 LINE-COUNT 2(1).
TYPE-POOLS : slis.
TYPES : BEGIN OF internal,
        matnr(18),
        werks(4),
        qtyn(20),
        desc(20) TYPE c,
        qty TYPE i,
        END OF internal.
DATA : it TYPE TABLE OF internal,
       wa TYPE internal.
DATA : fieldcat  TYPE lvc_t_fcat,
       lcat      TYPE lvc_s_fcat,
       final_cat TYPE slis_t_fieldcat_alv,
       fcat      TYPE slis_fieldcat_alv,
       top       TYPE slis_t_listheader,
       events    TYPE slis_t_event,
       layout    TYPE slis_layout_alv.
DATA : newfield  TYPE REF TO data,
       newdata   TYPE REF TO data.
FIELD-SYMBOLS : <fs1>,
                <dynamic_value>,
                <dynamic_cat> TYPE STANDARD TABLE.
START-OF-SELECTION.
  PERFORM popudate.
  PERFORM buildcat.
  PERFORM loadata.
  PERFORM events USING events.
  PERFORM header USING top.
  PERFORM layout.
END-OF-SELECTION.
  PERFORM display.
*&      Form  popudate
      text
-->  p1        text
<--  p2        text
FORM popudate .
  DEFINE popu.
    wa-matnr = &1.
    wa-werks = &2.
    wa-qtyn = &3.
    wa-desc = &4.
    wa-qty = &5.
    append wa to it.
    clear wa.
  END-OF-DEFINITION.
  popu 'material1' 'pla1' 'QTY1' 'quantity1' 100.
  popu 'material1' 'pla1' 'QTY2' 'quantity2' 200.
  popu 'material1' 'pla1' 'QTY3' 'quantity3' 300.
  popu 'material2' 'pla2' 'QTY1' 'quantity1' 400.
  popu 'material2' 'pla2' 'QTY2' 'quantity2' 500.
  popu 'material2' 'pla2' 'QTY3' 'quantity3' 600.
  popu 'material3' 'pla3' 'QTY1' 'quantity1' 700.
  popu 'material3' 'pla3' 'QTY2' 'quantity2' 400.
  SORT it BY matnr.
ENDFORM.                    " popudate
*&      Form  buildcat
      text
-->  p1        text
<--  p2        text
FORM buildcat .
  lcat-fieldname = 'MATNR'.
  lcat-datatype = 'CHAR'.
  lcat-seltext = 'Material'.
  lcat-intlen = 18.
  APPEND lcat TO fieldcat.
  CLEAR lcat.
  lcat-fieldname = 'WERKS'.
  lcat-datatype = 'CHAR'.
  lcat-seltext = 'Plant'.
  lcat-intlen = 4.
  APPEND lcat TO fieldcat.
  CLEAR lcat.
  LOOP AT it INTO wa.
    READ TABLE fieldcat INTO lcat WITH KEY fieldname = wa-qtyn.
    IF sy-subrc <> 0.
      lcat-fieldname = wa-qtyn.
      lcat-datatype = 'CHAR'.
      lcat-seltext = wa-desc.
      lcat-intlen = 10.
      APPEND lcat TO fieldcat.
      CLEAR lcat.
    ENDIF.
  ENDLOOP.
  CLEAR lcat.
  CALL METHOD cl_alv_table_create=>create_dynamic_table
    EXPORTING
   i_style_table             =
      it_fieldcatalog           = fieldcat
   i_length_in_byte          =
    IMPORTING
      ep_table                  = newfield
   e_style_fname             =
EXCEPTIONS
   generate_subpool_dir_full = 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.
  ASSIGN newfield->* TO <dynamic_cat>.
  CREATE DATA newdata LIKE LINE OF <dynamic_cat>.
  ASSIGN newdata->* TO <dynamic_value>.
ENDFORM.                    " buildcat
*&      Form   loadata
      text
-->  p1        text
<--  p2        text
FORM  loadata .
  DATA flag TYPE i.
  LOOP AT it INTO wa.
    flag = 0.
    ASSIGN COMPONENT 'MATNR' OF STRUCTURE <dynamic_value> TO <fs1>.
    <fs1> = wa-matnr.
    ASSIGN COMPONENT 'WERKS' OF STRUCTURE <dynamic_value> TO <fs1>.
    <fs1> = wa-werks.
    CALL FUNCTION 'AIPC_CONVERT_TO_UPPERCASE'
      EXPORTING
        i_input  = wa-qtyn
        i_langu  = sy-langu
      IMPORTING
        e_output = wa-qtyn.
    ASSIGN COMPONENT wa-qtyn OF STRUCTURE <dynamic_value> TO <fs1>.
    <fs1> = wa-qty.
    AT END OF matnr.
      APPEND <dynamic_value> TO <dynamic_cat>.
      CLEAR : <dynamic_value>.
    ENDAT.
    CLEAR : wa.
  ENDLOOP.
ENDFORM.                    "  loadata
**&      Form  display
      text
-->  p1        text
<--  p2        text
FORM display .
  LOOP AT fieldcat INTO lcat.
    fcat-fieldname = lcat-fieldname.
    fcat-outputlen = lcat-intlen.
    fcat-seltext_l = lcat-seltext.
    APPEND fcat TO final_cat.
  ENDLOOP.
  CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
   EXPORTING
     i_callback_program             = sy-repid
  I_CALLBACK_PF_STATUS_SET       = ' '
  I_CALLBACK_USER_COMMAND        = ' '
     is_layout                      = layout
     it_fieldcat                    = final_cat
  IT_SORT                        =
  I_SAVE                         = ' '
  IS_VARIANT                     =
     it_events                      = events
    TABLES
      t_outtab                       = <dynamic_cat>
ENDFORM.                    " display
Regards,
Aswin.

Similar Messages

  • Sorting internal table with variable no of fields

    Hi ,
    I want to sort the internal table with variable no of fields . Every time the  report is run the number of fields as well as the sequence by which the table has to be sorted changes . How to do this .
    regards

    Hi,
    Please try this.
    DATA: BEGIN OF ITAB OCCURS 0,
            F1(4),
          END OF ITAB.
    DATA: BEGIN OF ITAB2 OCCURS 0,
            F1(1),
            F2(1),
            F3(4),
          END OF ITAB2.
    ITAB-F1 = '01AC'.
    APPEND ITAB.
    ITAB-F1 = '02AB'.
    APPEND ITAB.
    ITAB-F1 = '01CD'.
    APPEND ITAB.
    ITAB-F1 = '02CA'.
    APPEND ITAB.
    LOOP AT ITAB.
      ITAB2-F1 = ITAB-F1+2(1).
      ITAB2-F2 = ITAB-F1+3(1).
      ITAB2-F3 = ITAB-F1.
      APPEND ITAB2.
    ENDLOOP.
    SORT ITAB2 BY F1 ASCENDING
                  F2 DESCENDING.
    LOOP AT ITAB2.
      WRITE: / ITAB2-F3.
    ENDLOOP.
    REWARD POINTS IF HELPFUL

  • How create table with variable number of columns?

    I am creating table data in Java. Number of columns is variable. How I can write <table> in UIX.
    Here is code of one of my unsuccessful attempt:
    <provider>
    <!- get table data like DataObjectList-->
    <data name="ReportTableData">
    <method class="app.ReportTableData" method="getTableData"/>
    </data>
    <!- get names of columns like DataObjectList-->
    <data name="ColumnNames">
    <method class="app.ReportTableData" method="getColumnNames"/>
    </data>
    </provider>
    <table data:tableData="@ReportTableData">
    <contents data:childData="@ColumnNames">
    <text data:text="nameColumn"/>
    </contents>
    </table>
    I hoped that I can get cell data by key, where key is name of column. But cells of table contain only names of columns.
    Please help me, where I mistaken?
    Thank you.

    Hi Sergey,
    The UIX table implementation relies on a childData like mechanism internally to iterate over the rows. For instance, when you databind the text attribute of the UINode used to stamp out each column, you are relying on the uix:table iterating over the table data using the data object for the current row when evaluating your column stamp.
    Setting the data:childData attribute on the table's contents element conflicts with UIX's internal iteration over the tableData. For this reason, we don't support specifying a dynamic number of table columns in UIX XML.
    This doesn't mean that you can't do it, there are different strategies. If you've got a finite and known set of columns, you can specify each possible column and then databind the rendered attribute of each one to hide and show it as appropriate. Another, often cleaner approach, is to build this subtree of UINodes in Java code.

  • Display table with variable number of columns

    Hello Forum,
    I'm trying to build an export view of User Management Engine data. I would like to output a table with one row for every user with yes / no fields indicating membership in each of the available groups. Because the number of available groups might change in the future, I can't hardcode the column names for the groups.
    That is, I call a webservice to compute a table, and I get back a table with a variable number of columns.
    When I try to insert the webservice into my VC model, it complains:
    "Port 'Response' was omitted because it includes nested tables, which are not presently supported by Visual Composer"
    You might be interested to know that the business method of my webservice (for testing purposes) looks as follows:
    public String[][] getVariableSizeArray() {
            String[][] ret = new String[10][];
            for (int i = 1; i <= 10; i++) {
                    ret<i> = new String[10];
                    for (int j = 1; j <= 10; j++) {
                            ret<i>[j] = Integer.toString(i * j);
            return ret;
    Any help is appreciated, and points will be awarded for helpful answers,
    Sincerely,
    Florian
    Message was edited by:
            Florian Something

    Hi Florian,
    dynamic data structures are not supported. You can do this with a workaround. If you know the maximum count of your columns then you can add them to the table and hide/unhide them dynamicly via a formula in the hidden condition. Of course in your WS you als need a fix structure of your columns.
    This is not the best solution, I know so far, but it works. This is just one limit of VC.
    Best Regards,
    Marcel

  • Internal Table with variable field lengths

    Hi Guys,
    I have a requirement to populate an internal table whose structure is as follows.
    Internal Table will have 5 lines.
    Line1: 050 char
    Line2: 100 char
    Line3: 100 char
    Line4: 100 char
    Line5: 050 char.
    I have all the required data with me. I just need to populate the table.
    Reward points up for grabs
    Regards,
    Suhas

    Hi,
    Wher do you have the data?
    You can define a work area and internal table of two rows..
    wa-row1 = 'yourdata'
    wa-row2 = 'your data'
    append wa to itab.
    wa-row1 = 'yourdata'
    wa-row2 = 'your data'
    append wa to itab.
    wa-row1 = 'yourdata'
    wa-row2 = 'your data'
    append wa to itab.
    wa-row1 = 'yourdata'
    wa-row2 = 'your data'
    append wa to itab.
    wa-row1 = 'yourdata'
    wa-row2 = 'your data'
    append wa to itab.
    If you have your data in Db table then you need to write a select query..
    select <fields,,,> from DBtable into tableITAb.
    Be clear with your question we can help you...
    rewads if useful,
    regards,
    nazeer

  • Pivot table with variables columns

    I need a helo to pivot table with variable columns,
    I have a pivot table :
    SELECT a.*
    FROM (SELECT codigo_aluno,nome_aluno , id_curso,dia FROM c_frequencia where dia like '201308%') PIVOT (sum(null)   FOR dia IN ('20130805' ,'20130812','20130819','20130826')) a
    but I need to run the select with values for dia , getting from a other table :
    SELECT a.*
    FROM (SELECT codigo_aluno,nome_aluno , id_curso,dia FROM c_frequencia where dia like '201308%') PIVOT (sum(null)   FOR dia IN (
    select dia from v_dia_mes )) a
    thank you

    The correct answer should be "Use the Pivoted Report Region Plugin".
    But, as far as I know, nobody has created/posted that type of APEX plugin.
    You may have to use a Basic Report (not an IR) so that you can use "Function returning SELECT" for your Source.
    You would need two functions:
    One that dynamically generates the Column Names
    One that dynamically generates the SELECT statement
    These should be in a PL/SQL Package so that the later can call the former to ensure that the column data matches the column names.
    i.e. -- no 'SELECT *'
    MK

  • Download internal table with column headings

    Hai Friends,
    How can i download the internal table with column headings?. i used to download and do some manual calculations to cross check the output.

    Hello,
    You can do this with GUI_DOWNLOAD where you can provide seperate table for fieldnames.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
      BIN_FILESIZE                    =
        FILENAME                        =
      FILETYPE                        = 'ASC'
      APPEND                          = ' '
      WRITE_FIELD_SEPARATOR           = ' '
      HEADER                          = '00'
      TRUNC_TRAILING_BLANKS           = ' '
      WRITE_LF                        = 'X'
      COL_SELECT                      = ' '
      COL_SELECT_MASK                 = ' '
      DAT_MODE                        = ' '
      CONFIRM_OVERWRITE               = ' '
      NO_AUTH_CHECK                   = ' '
      CODEPAGE                        = ' '
      IGNORE_CERR                     = ABAP_TRUE
      REPLACEMENT                     = '#'
      WRITE_BOM                       = ' '
      TRUNC_TRAILING_BLANKS_EOL       = 'X'
    IMPORTING
      FILELENGTH                      =
      TABLES                              ---> Table for sending column headings
        DATA_TAB                        =
      FIELDNAMES                      =
    Hope this helps!
    Thanks,
    Augustin.

  • Create dynamic internal table with dynamic structure

    I have an internal table itab1 that have 12 amount fields from period1 thru period12.  I need to create a dynamic table with dynamic structure for the  period column if the total amount of each column  is > 0.  Any idea on how to do that? 
    For example if my itab1 has 20 rows and the sum of period1 = 35, sum of period2 = 0, sum of period3 = 5, sum of period4 =0, sum of period5 = 2 then I need to create a dynamic structure for the field column that have the total > 0, i.e  structure struct1 have field period1, period3 and period5 only.  Then I will need to load the data to itab2 from itab1.  Can someone help.
    Thanks.  I am on 4.7 and will upgrade to ERP 6.0 soon.

    go throgh this....
    REPORT  yusmm_text1  NO STANDARD PAGE HEADING
                         LINE-SIZE 199.
    T A B L E S
    TABLES: MARA,
            MAKT,
            THEAD.
    GLOBAL TYPE-POOLS
    TYPE-POOLS : SLIS.
       GLOBAL TYPES
    TYPES : BEGIN OF TP_FINAL,
           MATNR TYPE MARA-MATNR,
           BEGRU TYPE MARA-BEGRU,
           MTART TYPE MARA-MTART,
           MAKTX TYPE MAKT-MAKTX,
           SPRAS TYPE MAKT-SPRAS,
           LTXT(2000)  TYPE C ,
           SRNO TYPE N ,
          END OF TP_FINAL.
    TYPES : BEGIN OF TP_T002,
            SPRAS TYPE T002-SPRAS,
            LAISO TYPE T002-LAISO,
            SRNO TYPE N ,
            END OF TP_T002.
    TYPES : BEGIN OF TP_MARA_MAKT,
            MATNR TYPE MARA-MATNR,
            BEGRU TYPE MARA-BEGRU,
            MTART TYPE MARA-MTART,
            SPRAS TYPE MAKT-SPRAS,
            MAKTX TYPE MAKT-MAKTX,
           END OF TP_MARA_MAKT.
    Types: BEGIN OF tp_matnr,
           matnr TYPE mara-matnr,
           END OF tp_matnr.
       GLOBAL ELEMENTARY VARIABLES
    DATA : gv_date TYPE sy-datum.
    DATA : gv_repid TYPE sy-repid.
    DATA : g_var1(10) TYPE C.
    DATA : gv_index TYPE sy-tabix.
    DATA: gv_strg TYPE string,
          gv_strg1(2000) TYPE C.
    DATA : gv_lang TYPE sy-langu.
    DATA : g_v(3) TYPE N .
    DATA : gv_lines(3) TYPE N .
    DATA : gv_var(3) TYPE N .
    DATA : gv_var1(3) TYPE N.
    DATA: gv_str TYPE STRING.
    DATA: gv_str1 TYPE STRING.
    DATA : gv_li TYPE I,
           gv_lit TYPE I,
           gv_lin TYPE I.
    DATA: g_var11(3) TYPE N,
          gv_li1(3) TYPE N,
          g_var2(3) TYPE N.
    DATA : gv_i1 TYPE I.
    DATA : gv_i TYPE I.
    DATA: gl_lenght TYPE I.
       GLOBAL STRUCTURES
    DATA:   T_NEWTABLE TYPE REF TO DATA,
            T_NEWLINE  TYPE REF TO DATA,
            T_FLDCAT1   TYPE SLIS_T_FIELDCAT_ALV,
            T_FLDCAT   TYPE LVC_T_FCAT,
            WA_IT_FLDCAT TYPE LVC_S_FCAT,
            WA_IT_FLDCAT1 TYPE SLIS_FIELDCAT_ALV,
            WA_COLNO(2) TYPE N,
            WA_FLNAME(5) TYPE C,
            L_LT TYPE SLIS_LAYOUT_ALV.
       GLOBAL INTERNAL TABLES (WITH INCLUDE STRUCTURE)
    DATA : IG_MARA_MAKT TYPE STANDARD TABLE OF TP_MARA_MAKT,
           WG_MARA_MAKT TYPE TP_MARA_MAKT.
    DATA : IG_T002 TYPE STANDARD TABLE OF TP_T002,
           WG_T002 TYPE TP_T002.
    DATA : IG_FINAL TYPE STANDARD TABLE OF TP_FINAL,
           WG_FINAL TYPE TP_FINAL.
    data : IG_MATNR TYPE STANDARD TABLE OF TP_MATNR WITH HEADER  LINE,
           WG_MATNR TYPE TP_MATNR.
    DATA:BEGIN OF IG_THEAD OCCURS 0.
            INCLUDE STRUCTURE THEAD .
    DATA: END OF IG_THEAD.
    DATA:BEGIN OF IG_TLINE OCCURS 0.
            INCLUDE STRUCTURE TLINE  .
    DATA:END OF IG_TLINE.
    FIELD-SYMBOLS
    FIELD-SYMBOLS: <T_DYNTABLE> TYPE STANDARD TABLE,"Dynamic internal
                                                            "tablename
                   <FS_DYNTABLE>,  "Field symbol to create work area
                  <FS_FLDVAL> TYPE ANY.   " Field symbol to assign values
    COMPULSORY
    FIELD-SYMBOLS: <FS_DATA> TYPE REF TO DATA,
                   <FS_DATA1> TYPE REF TO DATA,
                   <FS_2>    TYPE STANDARD TABLE,
                   <FS_22>   TYPE STANDARD TABLE,
                   <FS_1>,
                   <FS_11>,
                   <F>,
                   <FA>,
                   <LWA_LINE_WA>,
                   <LWA_LINE_WA1>.
    ------- Create Dyn Table From FC
    DATA: LT_DATA        TYPE   REF TO DATA,
          LT_DATA1        TYPE   REF TO DATA,
          LWA_LINE       TYPE   REF TO  DATA,
          LWA_LINE1       TYPE   REF TO  DATA,
          LI_FIELD_CAT   TYPE   LVC_T_FCAT,
          LWA_FIELD_CAT  TYPE   LVC_S_FCAT.
       PARAMETERS & SELECT-OPTIONS
    SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
    SELECT-OPTIONS : S_SPRAS FOR MAKT-SPRAS NO INTERVALS  DEFAULT 'EN'
                                                            OBLIGATORY ,
                     S_MATNR FOR MARA-MATNR,
                     S_MTART FOR MARA-MTART.
    PARAMETERS: GP_SIZE TYPE I DEFAULT '200'.
    SELECTION-SCREEN : END OF BLOCK B1.
       INITIALIZATION
    INITIALIZATION.
      gv_repid = sy-repid.
      gv_date = sy-datum.
    AT SELECTION-SCREEN
    AT SELECTION-SCREEN.
      IF GP_SIZE < 0.
       MESSAGE E002(00).
      ENDIF.
      IF GP_SIZE > 50000.
       MESSAGE W130(26) WITH TEXT-004.
        SET CURSOR FIELD 'gp_size'.
      ENDIF.
    START-OF-SELECTION
    START-OF-SELECTION.
      PERFORM FIELDCAT.
      PERFORM LAYOUT.
      PERFORM DATA_FETCH.
      PERFORM READ_DATA_TO_FINAL.
      SORT ig_final BY matnr spras.
      gv_lin = gv_li.
      gv_li = gv_li - 2.
      LOOP AT ig_final INTO wg_final.
        ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'Material Number'.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'Authorization Group'.
        g_VAR11 = wg_final-srno + 2.
        gv_li1 = gv_li1 + 2.
        MOVE : g_var11 TO gv_i1.
        ASSIGN COMPONENT g_var11 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'MatDesc'.
        g_var2 = g_var11 + gv_lines.
        ASSIGN COMPONENT g_var2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = 'BasicData'.
        APPEND <LWA_LINE_WA1> TO <FS_22>.
        EXIT.
       ENDLOOP.
      LOOP AT ig_final INTO wg_final.
        AT NEW matnr.
          gv_index = sy-tabix.
          ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
          <F> = wg_final-matnr.
          ENDAT.
        AT NEW MATNR.
        GV_INDEX = SY-TABIX.
        ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-matnr.
         ENDAT.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA> TO <F>.
        <F> = wg_final-begru.
        ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-begru.
        gv_var = wg_final-srno + 2.
        gv_li = gv_li + 2.
        MOVE : gv_var TO gv_i.
        ASSIGN COMPONENT gv_var OF STRUCTURE <LWA_LINE_WA> TO <F>.
        <F> = wg_final-maktx.
        ASSIGN COMPONENT gv_var OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-maktx.
        gv_var1 = gv_var + gv_lines  .
        ASSIGN COMPONENT gv_var1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
       <F> = wg_final-ltxt.
        ASSIGN COMPONENT gv_var1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
        <FA> = wg_final-ltxt.
        AT END OF matnr.
          APPEND <LWA_LINE_WA> TO <FS_2>.
          CLEAR <LWA_LINE_WA>.
        ENDAT.
        AT END OF matnr.
         APPEND <LWA_LINE_WA1> TO <FS_22>.
         CLEAR <LWA_LINE_WA1>.
        ENDAT.
      ENDLOOP.
      PERFORM display..
    *&      Form  data_fetch
          text
    -->  p1        text
    <--  p2        text
    FORM DATA_FETCH .
      SELECT matnr
              from mara up to gp_size rows
             appending corresponding fields of table ig_matnr
             where matnr in s_matnr
             and mtart in s_mtart.
    loop at ig_matnr.
      SELECT  MARA~MATNR
              MARA~BEGRU
              MARA~MTART
              MAKT~SPRAS
              MAKT~MAKTX FROM MARA INNER JOIN MAKT
        ON MARAMATNR = MAKTMATNR
       appending corresponding fields of TABLE ig_mara_makt  UP TO GP_SIZE
    ROWS
        WHERE makt~spras IN s_spras
        AND   mara~matnr IN s_matnr
        AND   mara~mtart IN s_mtart
        AND   mara~matnr EQ ig_matnr-matnr.
        endloop.
      IF sy-subrc = 0.
        SORT ig_mara_makt.
      ENDIF.
    ENDFORM.                    " data_fetch
    *&      Form  read_data_to_final
          text
    -->  p1        text
    <--  p2        text
    FORM READ_DATA_TO_FINAL .
      LOOP AT ig_mara_makt INTO wg_mara_makt .
        wg_final-MATNR = wg_mara_makt-MATNR.
        wg_final-BEGRU = wg_mara_makt-BEGRU.
        wg_final-MTART = wg_mara_makt-MTART.
        wg_final-SPRAS = wg_mara_makt-SPRAS.
        wg_final-MAKTX = wg_mara_makt-MAKTX.
        READ TABLE ig_t002 INTO wg_t002 WITH KEY spras = wg_final-spras.
        IF sy-subrc = 0.
          wg_final-srno = wg_t002-srno.
        ENDIF.
        CLEAR ig_thead[].
        ig_thead-TDOBJECT = 'MATERIAL'.
        ig_thead-TDNAME   = wg_final-matnr.
        ig_thead-TDID     = 'GRUN'.
        ig_thead-TDSPRAS  = wg_final-spras.
        CALL FUNCTION 'TEXT_READ'
          EXPORTING
            I_HEADER   = IG_THEAD
            I_READONLY = 'X'
          IMPORTING
            E_HEADER   = IG_THEAD
          TABLES
            T_LINES    = IG_TLINE[]
          EXCEPTIONS
            NOTFOUND   = 1.
        IF sy-subrc  EQ 0.
          LOOP AT  ig_tline.
            gv_strg = ig_tline-tdline.
            IF gv_strg1 <> ' '.
              CONCATENATE gv_strg1 ';' gv_strg INTO gv_strg1.
            ELSE.
              gv_strg1 = gv_strg.
            ENDIF.
          ENDLOOP.
          wg_final-ltxt = gv_strg1.
          APPEND wg_final TO ig_final.
          CLEAR wg_final.
          gv_strg1 = ' '.
        ELSE.
          APPEND wg_final TO  ig_final.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    " read_data_to_final
    " read_data_to_final
    *&      Form  layout
          text
    -->  p1        text
    <--  p2        text
    FORM LAYOUT .
      CLEAR L_LT.
      L_LT-ZEBRA = 'X'.
      L_LT-COLWIDTH_OPTIMIZE = 'X'.
      L_LT-WINDOW_TITLEBAR = 'MATERIAL DETAILS'.
    ENDFORM.                    " layout
    *&      Form  fieldcat
          text
    -->  p1        text
    <--  p2        text
    FORM FIELDCAT .
      SELECT SPRAS
               LAISO FROM t002 INTO  CORRESPONDING FIELDS OF TABLE ig_t002
          WHERE spras IN s_spras.
      DESCRIBE TABLE ig_t002 LINES gv_lines.
      LOOP AT ig_t002 INTO wg_t002.
        g_v = g_v + 1.
        Wg_t002-srno = g_v.
        MODIFY ig_t002 FROM wg_t002 TRANSPORTING SRNO.
      ENDLOOP.
      LOOP AT ig_t002 INTO wg_t002.
        CLEAR WA_IT_FLDCAT.
        MOVE SY-INDEX TO WA_COLNO.
        CONCATENATE 'MD-' wg_t002-LAISO
                          WA_COLNO
                         INTO WA_FLNAME.
        WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-SELTEXT = WA_FLNAME.
        WA_IT_FLDCAT-INTLEN = 250.
        WA_IT_FLDCAT-TABNAME = '<FS_2>'.
        APPEND WA_IT_FLDCAT TO T_FLDCAT.
        CLEAR wg_t002.
        ENDLOOP.
      LOOP AT ig_t002 INTO wg_t002.
        CLEAR WA_IT_FLDCAT.
        MOVE SY-INDEX TO WA_COLNO.
        CONCATENATE 'BD-' wg_t002-LAISO
                           WA_COLNO
                        INTO WA_FLNAME.
        WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
        WA_IT_FLDCAT-DATATYPE = 'CHAR'.
        WA_IT_FLDCAT-SELTEXT = WA_FLNAME.
        WA_IT_FLDCAT-INTLEN = 250.
        WA_IT_FLDCAT-TABNAME = '<FS_2>'.
        APPEND WA_IT_FLDCAT TO T_FLDCAT.
        CLEAR wg_t002.
        ENDLOOP.
      MOVE 'MATNR' TO WA_FLNAME.
      WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
      WA_IT_FLDCAT-DATATYPE = 'CHAR'.
      WA_IT_FLDCAT-SELTEXT = 'Material No'.
      WA_IT_FLDCAT-INTLEN = 18.
      WA_IT_FLDCAT-TABNAME = '<FS_2>'.
      INSERT WA_IT_FLDCAT INTO T_FLDCAT INDEX 1.
      MOVE 'BEGRU' TO WA_FLNAME.
      WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
      WA_IT_FLDCAT-DATATYPE = 'CHAR'.
      WA_IT_FLDCAT-SELTEXT = 'Authorization Group'.
      WA_IT_FLDCAT-INTLEN = 4.
      WA_IT_FLDCAT-TABNAME = '<FS_2>'.
      INSERT WA_IT_FLDCAT INTO T_FLDCAT INDEX 2.
      DESCRIBE TABLE T_FLDCAT LINES gv_li.
      ASSIGN LT_DATA TO <FS_DATA>.
    Creating the Dynamic Internal Table
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = T_FLDCAT         " Fieldcatalogue
        IMPORTING
          EP_TABLE                  = <FS_DATA>   " Dynamic Internal Table
        EXCEPTIONS
          GENERATE_SUBPOOL_DIR_FULL = 1
          OTHERS                    = 2.
    Assign Dyn Table To Field Sumbol
      ASSIGN <FS_DATA>->* TO <FS_1>.
    Assigning the Internal Table TYPE ANY to Standard internal Table
      ASSIGN <FS_1> TO <FS_2>.
    Creating a Workarea
      CREATE DATA LWA_LINE LIKE LINE OF <FS_2> .
    Assigning the Content to the workares as a Pointer
      ASSIGN LWA_LINE->* TO <LWA_LINE_WA>.
      LOOP AT T_FLDCAT INTO WA_IT_FLDCAT.
        WA_IT_FLDCAT1-FIELDNAME = WA_IT_FLDCAT-FIELDNAME.
        WA_IT_FLDCAT1-TABNAME =  WA_IT_FLDCAT-TABNAME.
        WA_IT_FLDCAT1-SELTEXT_L = WA_IT_FLDCAT-SELTEXT.
       WA_IT_FLDCAT1-REF_TABNAME = 'MARC'.
        APPEND WA_IT_FLDCAT1 TO T_FLDCAT1.
        CLEAR : WA_IT_FLDCAT,WA_IT_FLDCAT1.
      ENDLOOP.
      ASSIGN LT_DATA1 TO <FS_DATA1>.
      CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
        EXPORTING
          IT_FIELDCATALOG           = T_FLDCAT         " Fieldcatalogue
        IMPORTING
          EP_TABLE                  = <FS_DATA1>  " Dynamic Internal table
        EXCEPTIONS
          GENERATE_SUBPOOL_DIR_FULL = 1
          OTHERS                    = 2.
    Assign Dyn Table To Field Sumbol
      ASSIGN <FS_DATA1>->* TO <FS_11>.
    Assigning the Internal Table TYPE ANY to Standard internal Table
      ASSIGN <FS_11> TO <FS_22>.
    Creating a Workarea
      CREATE DATA LWA_LINE1 LIKE LINE OF <FS_22> .
    Assigning the Content to the workares as a Pointer
      ASSIGN LWA_LINE1->* TO <LWA_LINE_WA1>.
    ENDFORM.                    " fieldcat
    *&      Form  show
          text
    -->  p1        text
    <--  p2        text
    FORM Display .
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
       EXPORTING
       I_INTERFACE_CHECK                 = ' '
       I_BYPASSING_BUFFER                = ' '
       I_BUFFER_ACTIVE                   = ' '
         I_CALLBACK_PROGRAM                = GV_REPID
        I_CALLBACK_PF_STATUS_SET          = 'PF_STATUS_SET'
        I_CALLBACK_USER_COMMAND           = 'USER_COMMAND'
       I_CALLBACK_TOP_OF_PAGE            = ' '
       I_CALLBACK_HTML_TOP_OF_PAGE       = ' '
       I_CALLBACK_HTML_END_OF_LIST       = ' '
       I_STRUCTURE_NAME                  =
       I_BACKGROUND_ID                   = ' '
       I_GRID_TITLE                      =
       I_GRID_SETTINGS                   =
        IS_LAYOUT                         = L_LT
         IT_FIELDCAT                       = T_FLDCAT1[]
       IT_EXCLUDING                      =
       IT_SPECIAL_GROUPS                 =
       IT_SORT                           =
       IT_FILTER                         =
       IS_SEL_HIDE                       =
       I_DEFAULT                         = 'X'
       I_SAVE                            = ' '
       IS_VARIANT                        =
       IT_EVENTS                         =
       IT_EVENT_EXIT                     =
       IS_PRINT                          =
       IS_REPREP_ID                      =
       I_SCREEN_START_COLUMN             = 0
       I_SCREEN_START_LINE               = 0
       I_SCREEN_END_COLUMN               = 0
       I_SCREEN_END_LINE                 = 0
       I_HTML_HEIGHT_TOP                 = 0
       I_HTML_HEIGHT_END                 = 0
       IT_ALV_GRAPHICS                   =
       IT_HYPERLINK                      =
       IT_ADD_FIELDCAT                   =
       IT_EXCEPT_QINFO                   =
       IR_SALV_FULLSCREEN_ADAPTER        =
    IMPORTING
       E_EXIT_CAUSED_BY_CALLER           =
       ES_EXIT_CAUSED_BY_USER            =
        TABLES
          T_OUTTAB                          = <FS_2>
    EXCEPTIONS
       PROGRAM_ERROR                     = 1
       OTHERS                            = 2
      IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
      ENDIF.
    ENDFORM.                    " display
    FORM PF_STATUS_SET USING RS_EXTAB TYPE SLIS_T_EXTAB.
      SET PF-STATUS 'DISPLAY' .
    ENDFORM. "PF_STATUS_SET
    *& Form Name: user_command *
    *& Form Desc: For Handling USER_COMMAND *
    FORM USER_COMMAND USING IF_UCOMM TYPE SY-UCOMM
                         IS_SELFIELD TYPE SLIS_SELFIELD.
      CASE IF_UCOMM.
        WHEN 'DOWNLOAD'.
          CALL FUNCTION 'POPUP_TO_CONFIRM'
            EXPORTING
      TITLEBAR                    = ' '
      DIAGNOSE_OBJECT             = ' '
              TEXT_QUESTION               = 'Data download to excel'
      TEXT_BUTTON_1               = 'Ja'(001)
      ICON_BUTTON_1               = ' '
      TEXT_BUTTON_2               = 'Nein'(002)
      ICON_BUTTON_2               = ' '
      DEFAULT_BUTTON              = '1'
      DISPLAY_CANCEL_BUTTON       = 'X'
      USERDEFINED_F1_HELP         = ' '
      START_COLUMN                = 25
      START_ROW                   = 6
      POPUP_TYPE                  =
    IMPORTING
      ANSWER                      =
    TABLES
      PARAMETER                   =
    EXCEPTIONS
      TEXT_NOT_FOUND              = 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.
          CALL FUNCTION 'GUI_DOWNLOAD'
            EXPORTING
        BIN_FILESIZE                  =
              FILENAME                     = 'C:\Material-Text.xls'
             FILETYPE                      = 'ASC'
        APPEND                        = ' '
         WRITE_FIELD_SEPARATOR         = 'X'
        HEADER                        = '00'
         TRUNC_TRAILING_BLANKS         = 'X'
        WRITE_LF                      = 'X'
        COL_SELECT                    = ' '
        COL_SELECT_MASK               = ' '
         DAT_MODE                      = 'X'
       IMPORTING
         FILELENGTH                    = GL_LENGHT
            TABLES
              DATA_TAB                      = <FS_22>
      EXCEPTIONS
        FILE_WRITE_ERROR              = 1
        NO_BATCH                      = 2
        GUI_REFUSE_FILETRANSFER       = 3
        INVALID_TYPE                  = 4
        NO_AUTHORITY                  = 5
        UNKNOWN_ERROR                 = 6
        HEADER_NOT_ALLOWED            = 7
        SEPARATOR_NOT_ALLOWED         = 8
        FILESIZE_NOT_ALLOWED          = 9
        HEADER_TOO_LONG               = 10
        DP_ERROR_CREATE               = 11
        DP_ERROR_SEND                 = 12
        DP_ERROR_WRITE                = 13
        UNKNOWN_DP_ERROR              = 14
        ACCESS_DENIED                 = 15
        DP_OUT_OF_MEMORY              = 16
        DISK_FULL                     = 17
        DP_TIMEOUT                    = 18
        FILE_NOT_FOUND                = 19
        DATAPROVIDER_EXCEPTION        = 20
        CONTROL_FLUSH_ERROR           = 21
        OTHERS                        = 22
          IF SY-SUBRC <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
          ENDIF.
          IF GL_LENGHT NE 0.
            MESSAGE S398(00) WITH 'DATA downloaded to EXCEL'.
          ENDIF.
      ENDCASE.
    ENDFORM.                    "user_command
    Thanks

  • Internal table with Import and Export

    Hi All,
    Hi all
    Please let me know the use of <b>Internal table with Import and Export parameters and SET/GET parameters</b>, on what type of cases we can use these? Plese give me the syntax with some examples.
    Please give me detailed analysis on the above.
    Regards,
    Prabhu

    Hi Prabhakar,
    There are three types of memories.
    1. ABAP MEMORY
    2. SAP MEMORY
    3. EXTERNAL MEMORY.
    1.we will use EXPORT/ IMPORT TO/ FROM MEMORY-ID when we want to transfer between ABAP memory
    2. we will use GET PARAMETER ID/ SET PARAMETER ID to transfer between SAP MEMORY
    3. we will use EXPORT/IMPORT TO/FROM SHARED BUFFER to transfer between external memory.
    ABAP MEMORY : we can say that two reports in the same session will be in ABAP MEMORY
    SAP MEMORY: TWO DIFFERENT SESSIONS WILL BE IN SAP MEMORY.
    for ex: IF WE CALL TWO DIFFERENT TRANSACTIONS SE38, SE11
    then they both are in SAP MEMORY.
    EXTERNAL MEMORY: TWO different logons will be in EXTERNAL MEMORY.
    <b>Syntax</b>
    To fill the input fields of a called transaction with data from the calling program, you can use the SPA/GPA technique. SPA/GPA parameters are values that the system stores in the global, user-specific SAP memory. SAP memory allows you to pass values between programs. A user can access the values stored in the SAP memory during one terminal session for all parallel sessions. Each SPA/GPA parameter is identified by a 20-character code. You can maintain them in the Repository Browser in the ABAP Workbench. The values in SPA/GPA parameters are user-specific.
    ABAP programs can access the parameters using the SET PARAMETER and GET PARAMETER statements.
    To fill one, use:
    SET PARAMETER ID <pid> FIELD <f>.
    This statement saves the contents of field <f> under the ID <pid> in the SAP memory. The code <pid> can be up to 20 characters long. If there was already a value stored under <pid>, this statement overwrites it. If the ID <pid> does not exist, double-click <pid> in the ABAP Editor to create a new parameter object.
    To read an SPA/GPA parameter, use:
    GET PARAMETER ID <pid> FIELD <f>.
    This statement fills the value stored under the ID <pid> into the variable <f>. If the system does not find a value for <pid> in the SAP memory, it sets SY-SUBRC to 4, otherwise to 0.
    To fill the initial screen of a program using SPA/GPA parameters, you normally only need the SET PARAMETER statement.
    The relevant fields must each be linked to an SPA/GPA parameter.
    On a selection screen, you link fields to parameters using the MEMORY ID addition in the PARAMETERS or SELECT-OPTIONS statement. If you specify an SPA/GPA parameter ID when you declare a parameter or selection option, the corresponding input field is linked to that input field.
    On a screen, you link fields to parameters in the Screen Painter. When you define the field attributes of an input field, you can enter the name of an SPA/GPA parameter in the Parameter ID field in the screen attributes. The SET parameter and GET parameter checkboxes allow you to specify whether the field should be filled from the corresponding SPA/GPA parameter in the PBO event, and whether the SPA/GPA parameter should be filled with the value from the screen in the PAI event.
    When an input field is linked to an SPA/GPA parameter, it is initialized with the current value of the parameter each time the screen is displayed. This is the reason why fields on screens in the R/3 System often already contain values when you call them more than once.
    When you call programs, you can use SPA/GPA parameters with no additional programming overhead if, for example, you need to fill obligatory fields on the initial screen of the called program. The system simply transfers the values from the parameters into the input fields of the called program.
    However, you can control the contents of the parameters from your program by using the SET PARAMETER statement before the actual program call. This technique is particularly useful if you want to skip the initial screen of the called program and that screen contains obligatory fields.
    Reading Data Objects from Memory
    To read data objects from ABAP memory into an ABAP program, use the following statement:
    Syntax
    IMPORT <f1> [TO <g 1>] <f 2> [TO <g 2>] ... FROM MEMORY ID <key>.
    This statement reads the data objects specified in the list from a cluster in memory. If you do not use the TO <g i > option, the data object <f i > in memory is assigned to the data object in the program with the same name. If you do use the option, the data object <f i > is read from memory into the field <g i >. The name <key> identifies the cluster in memory. It may be up to 32 characters long.
    You do not have to read all of the objects stored under a particular name <key>. You can restrict the number of objects by specifying their names. If the memory does not contain any objects under the name <key>, SY-SUBRC is set to 4. If, on the other hand, there is a data cluster in memory with the name <key>, SY-SUBRC is always 0, regardless of whether it contained the data object <f i >. If the cluster does not contain the data object <f i >, the target field remains unchanged.
    Saving Data Objects in Memory
    To read data objects from an ABAP program into ABAP memory, use the following statement:
    Syntax
    EXPORT <f1> [FROM <g 1>] <f 2> [FROM <g 2>] ... TO MEMORY ID <key>.
    This statement stores the data objects specified in the list as a cluster in memory. If you do not use the option FROM <f i >, the data object <f i > is saved under its own name. If you use the FROM <g i > option, the data objet <g i > is saved under the name <f i >. The name <key> identifies the cluster in memory. It may be up to 32 characters long.
    Check this link.
    http://www.sap-img.com/abap/difference-between-sap-and-abap-memory.htm
    Thanks,
    Susmitha.
    Reward points for helpful answers.

  • How to insert a table with variable rows in smart form

    Hi all,
    How to insert a table with variable rows in smart form?
    Any help would be appreciated.
    Regards,
    Mahesh.

    Hi,
    Right click the mouse->create->table
    If you want 5 columns, you need to declare 5 cells in one line type of the table
    Click on Table -> Details, then do the following
    Line Type 1 2 3 4 5
    L1 2mm 3mm etc
    Here specify the width of the columns as many as you want..
    then in the header/main area of the table, click create Table Line, Rowtype is L1, automatically 5 cells will come,In each cell create a text element, display the variable to be printed there.

  • Text in internal table with HTML tags.

    Hi ,
    I have Text in internal table with HTML tags.
    The text has to be shown in output of smartform as formatted text.
    That is the smartform should READ the HTML TAGS , convert the text accordingly and show in the output as formatted text.
    I dont want to make a webform . This is for NORMAL SPOOL output and NOT for WEB OUTPUT.
    IN SHORT
    :- the text in the internal table is like this ( please ignore the dot in the HTML TAG )--
    <html><.U>this is heading</.U>Line with no break<.br>some content text</.br>
    </html>
    OUTPUT
    <U>this is heading</U>Line with no break<br>some content text</br>
    1)  Can I can get the output and store it as text in a string variable and show in the smartform  ?
    In this case I want to know how to convert  and store in a variable  in sap .
    OR
    2) Can the text element convert the text with HTML TAGS to html formatted output and show it ?
    Regards,
    Jagat

    Hi,
    Use the FM SCP_REPLACE_STRANGE_CHARS and check
    See the
    Converting html special characters to plain characters (e.g. u00FC to u00FC)

  • Create an internal table with the rows of another internal table.

    Hi I want to know if posible to create an internal table structure with the  rows of another internal table?
    ex.
    If in i_tab column A has this values: row 1 = first, row 2 = second, row 3 = third.
    Now I want that the structure of my internal table be: first, second, third

    Hi,
    If you do this way then what will be the difference between the two table anyway?? First internal table has the same structure irrespective of which row you select. and you are going to store the data from each row to the rows of the second internal table. In that case, the structure of the internal table is the same as first table. and it would have same rows.
    Am I missing something here? or you want to declare the internal table with each field being the structure of the first table? In this case you'd have to do a dynamic declaration of data as the first table can have any no of rows then the second table would have any no of fields in the structure.
    Now if you know that your first internal table is going to have a fixed no of rows eg 3 rows then it becomes simple. Do the following then
    Data: begin of second_table occurs 0,
    first type <first_table type>,
    second type <first_table type>,
    third type <first_table type>,
    end of second_table.
    Regards
    Prasenjit

  • Creating Dynamic Internal table with a dynamic name

    Hi,
    I want to create dynamic internal tables with dynamic names.
    For example:
    Suppose I have a table with three fields.
    1. Structure name
    2.Fields
    3.file
    And the structure of the internal table is as follows:
    TYPES:BEGIN OF table_type,
          struct                  TYPE char70,
          fields                   TYPE tt_type OCCURS 0,
          File                      TYPE ttab_type OCCURS 0,
          END OF table_type.
    Suppose I have one record inside my internal table with struct as "STRUCTURE", fields have an internal table content of set of fields and File has some set of records.
    Now I want to create dynamic internal table whose name will be "STRUCTURE" , the fields of the dynamic internal table structure[] will be as in fields, and the records will be as in File.
    Like this if i have 100 records in my internal table then I have to create 100 dynamic internal table dynamically.
    Can anyone suggest how to do this?
    Edited by: Jjammy on Jul 22, 2009 7:52 AM

    Hi,
    Check the sample program and develop your program accordingly.
    <font color=blue><pre>
    REPORT  ztest_notepad.
    *& Declarations
    *Type-pools
    TYPE-POOLS:
          slis.
    *Types
    TYPES:
          ty_fcat      TYPE lvc_s_fcat,
          ty_fcatalog  TYPE slis_fieldcat_alv.
    *Work areas
    DATA:
          wa_fcat      TYPE ty_fcat,
          wa_fcatalog  TYPE ty_fcatalog.
    *Internal tables
    DATA:
          it_fcat      TYPE STANDARD TABLE OF ty_fcat,
          it_fcatalog  TYPE STANDARD TABLE OF ty_fcatalog.
    *Type reference
    DATA:
          it_dyn_tab   TYPE REF TO data,
          wa_newline   TYPE REF TO data.
    *Filed symbols
    FIELD-SYMBOLS:
          <gt_table>   TYPE STANDARD TABLE,
          <fs_dyntable>,
          <fs_fldval>  TYPE ANY,
          <l_field>    TYPE ANY.
    *Variables
    DATA:
          l_fieldname  TYPE lvc_s_fcat-fieldname,
          l_tabname    TYPE lvc_s_fcat-tabname,
          l_fieldtext  TYPE lvc_s_fcat-seltext,
          l_index      TYPE char2.
    "Selection-screen
    PARAMETERS:
             p_colms   TYPE i.
    *& start-of-selection.
    START-OF-SELECTION.
      PERFORM build_fieldcat.
      PERFORM create_dynamic_table.
      DO 20 TIMES.
        DO p_colms TIMES.
          l_index = sy-index.
          CONCATENATE 'FIELD' l_index INTO l_fieldname.
          ASSIGN COMPONENT l_fieldname OF STRUCTURE <fs_dyntable> TO <l_field>.
          <l_field> = sy-index.
        ENDDO.
        INSERT <fs_dyntable> INTO TABLE <gt_table>.
      ENDDO.
      LOOP AT it_fcat INTO wa_fcat.
        PERFORM fieldcatalog1 USING: wa_fcat-fieldname
                                      wa_fcat-tabname
                                      wa_fcat-seltext.
      ENDLOOP.
      CALL FUNCTION 'REUSE_ALV_LIST_DISPLAY'
        EXPORTING
          i_callback_program = 'ZTEST_NOTEPAD'
          it_fieldcat        = it_fcatalog
        TABLES
          t_outtab           = <gt_table>.
    *&      Form  BUILD_FIELDCAT
    FORM build_fieldcat .
      CLEAR: l_fieldname,
             l_tabname,
             l_fieldtext,
             l_index.
      DO  p_colms TIMES.
        CLEAR l_index.
        l_index = sy-index.
        CONCATENATE 'FIELD' l_index INTO l_fieldname.
        CONCATENATE 'Field' l_index INTO l_fieldtext.
        l_tabname = '<GT_TABLE>'.
        PERFORM fieldcatalog USING: l_fieldname
                                    l_tabname
                                    l_fieldtext.
      ENDDO.
    ENDFORM.                    " BUILD_FIELDCAT
    *&      Form  CREATE_DYNAMIC_TABLE
    FORM create_dynamic_table .
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = it_fcat
        IMPORTING
          ep_table        = it_dyn_tab.
      ASSIGN it_dyn_tab->* TO <gt_table>.
    Create dynamic work area and assign to FS
      CREATE DATA wa_newline LIKE LINE OF <gt_table>.
      ASSIGN wa_newline->* TO <fs_dyntable>.
    ENDFORM.                    " CREATE_DYNAMIC_TABLE
    *&      Form  FIELDCATALOG
    FORM fieldcatalog USING field table f_txt.
      wa_fcat-fieldname = field.
      wa_fcat-tabname   = table.
      wa_fcat-seltext = f_txt.
      APPEND wa_fcat TO it_fcat.
      CLEAR  wa_fcat.
    ENDFORM.                    " FIELDCATALOG
    *&      Form  FIELDCATALOG1
    FORM fieldcatalog1 USING field table f_txt.
      wa_fcatalog-fieldname = field.
      wa_fcatalog-tabname   = table.
      wa_fcatalog-seltext_m = f_txt.
      APPEND wa_fcatalog TO it_fcatalog.
      CLEAR  wa_fcatalog.
    ENDFORM.                    " FIELDCATALOG1 </pre>
    </font>
    Thanks
    Venkat.O

  • [Function] Declare a internal table with structure name (entry parameter)

    Hi all,
    I'm explaining my problem :
    I want to create a function with two parameters in entry :
    (IMPORT)  - structure_name with type DD02L-TABNAME
    (TABLES) - t_outtab with empty type
    t_outtab will be in structure_name type.
    Now, in my source function, I want to retrieve all contain of t_outtab in another internal table or field-symbol. I don't know in advance the used structures in my function entries.
    I don't manage to get this contain, cause I can't do :
    DATA : internal_table TYPE structure_name*
    OR
    DATA : internal_table TYPE (structure_name)
    OR used field-symbol
    DATA : internal_table TYPE <fs>*  where <fs> had structure name value.
    To do more later :
    *DATA : line LIKE LINE OF internal_table. *
    *internal_table][ = t_outtab][. *
    And work with this table.
    _ I tried different solutions like : _
    Get the structure of the table.
      ref_table_des ?= cl_abap_typedescr=>describe_by_name( I_STRUCTURE_NAME ).
      idetails[] = ref_table_des->components[].
    Get the first structure table of result table
    LOOP AT idetails INTO xdetails.
        CLEAR: xfc.
        xfc-fieldname = xdetails-name .
        xfc-datatype = xdetails-type_kind.
        xfc-inttype = xdetails-type_kind.
        xfc-intlen = xdetails-length.
        xfc-decimals = xdetails-decimals.
        APPEND xfc TO ifc.
    ENDLOOP.
    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>.
    and retrieve to <dyn_table>[] = t_outtab[].
    the but I don't try the solution. If someone have an idea.
    Thanks and regards.
    Romain
    Edited by: Romain L on May 14, 2009 11:35 AM

    Hi,
    We can acheive this using dynamic internal tables.
    Please find sample below.
    *Creating Dynamic internal table 
      PARAMETERS : p_table(10) TYPE C.
      DATA: w_tabname TYPE w_tabname,            
            w_dref TYPE REF TO data,             
            w_grid TYPE REF TO cl_gui_alv_grid. 
      FIELD-SYMBOLS: <t_itab> TYPE ANY TABLE. 
      w_tabname = p_table. 
      CREATE DATA w_dref TYPE TABLE OF (w_tabname).
      ASSIGN w_dref->* TO <t_itab>.
    * Populating Dynamic internal table 
      SELECT *
        FROM (w_tabname) UP TO 20 ROWS
        INTO TABLE <t_itab>.
    * Displaying dynamic internal table using Grid. 
      CREATE OBJECT w_grid
        EXPORTING i_parent = cl_gui_container=>screen0. 
      CALL METHOD w_grid->set_table_for_first_display
        EXPORTING
          i_structure_name = w_tabname
        CHANGING
          it_outtab        = <t_itab>. 
      CALL SCREEN 100.
    * Scenario 2: 
    *Create a dynamic internal table with the specified number of columns. 
    * Creating Dynamic internal table
    TYPE-POOLS: slis.
    FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE,  u201C Dynamic internal table name
                   <fs_dyntable>,                     u201C Field symbol to create work area
                   <fs_fldval> type any.              u201C Field symbol to assign values 
    PARAMETERS: p_cols(5) TYPE c.                     u201C Input number of columns
    DATA:   t_newtable TYPE REF TO data,
            t_newline  TYPE REF TO data,
            t_fldcat   TYPE slis_t_fldcat_alv,
            t_fldcat   TYPE lvc_t_fcat,
            wa_it_fldcat TYPE lvc_s_fcat,
            wa_colno(2) TYPE n,
            wa_flname(5) TYPE c. 
    * Create fields .
      DO p_cols TIMES.
        CLEAR wa_it_fldcat.
        move sy-index to wa_colno.
        concatenate 'COL'
                    wa_colno
               into wa_flname.
        wa_it_fldcat-fieldname = wa_flname.
        wa_it_fldcat-datatype = 'CHAR'.
        wa_it_fldcat-intlen = 10.
        APPEND wa_it_fldcat TO t_fldcat.
      ENDDO. 
    * Create dynamic internal table and assign to FS
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = t_fldcat
        IMPORTING
          ep_table        = t_newtable. 
      ASSIGN t_newtable->* TO <t_dyntable>. 
    * Create dynamic work area and assign to FS
      CREATE DATA t_newline LIKE LINE OF <t_dyntable>.
      ASSIGN t_newline->* TO <fs_dyntable>.
    *Populating Dynamic internal table 
      DATA: fieldname(20) TYPE c.
      DATA: fieldvalue(10) TYPE c.
      DATA: index(3) TYPE c. 
      DO p_cols TIMES. 
        index = sy-index.
        MOVE sy-index TO wa_colno.
        CONCATENATE 'COL'
                    wa_colno
               INTO wa_flname. 
    * Set up fieldvalue
        CONCATENATE 'VALUE' index INTO
                    fieldvalue.
        CONDENSE    fieldvalue NO-GAPS. 
        ASSIGN COMPONENT  wa_flname
            OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
        <fs_fldval> =  fieldvalue. 
      ENDDO. 
    * Append to the dynamic internal table
      APPEND <fs_dyntable> TO <t_dyntable>.
    * Displaying dynamic internal table using Grid. 
    DATA: wa_cat LIKE LINE OF fs_fldcat. 
      DO p_cols TIMES.
        CLEAR wa_cat.
        MOVE sy-index TO wa_colno.
        CONCATENATE 'COL'
                    wa_colno
               INTO wa_flname. 
        wa_cat-fieldname = wa_flname.
        wa_cat-seltext_s = wa_flname.
        wa_cat-outputlen = '10'.
        APPEND wa_cat TO fs_fldcat.
      ENDDO. 
    * Call ABAP List Viewer (ALV)
      CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
        EXPORTING
          it_fieldcat = fs_fldcat
        TABLES
          t_outtab    = <t_dyntable>.
    Thanks,
    Jyothi
    Edited by: Jyothi on May 14, 2009 11:42 AM
    Edited by: Jyothi on May 14, 2009 11:43 AM

  • How to fill internal table with no data in debugging mode

    Hi all,
             I modified one existing program.Now I want to test it.I am not given test data.So in the middle of my debugging, I found that one internal table with no data.My problem is how to fill that internal table with few records in that debugging mode just as we change contents in debugging mode.If I want to proceed further means that internal table must have some records.
    Please I dont know how to create test data so I am trying to create values temporarily in debugging mode only.
    Thanks,
    Balaji

    Hi,
    In the debugging do the following..
    Click the Table button..
    Double click on the internal table name..
    Then in the bottom of the screen you will get the buttons like CHANGE, INSERT, APPEND, DELETE..
    Use the APPEND button to insert records to the internal table..
    Thanks,
    Naren

Maybe you are looking for

  • Currency translation on future dates in SAP BW-BEX

    Hello All We have a requirement where in user needs to do a currency translation at run time for data in future periods. For example : Savings data on a purchase order .Total savings for PO is $100,000.00 in year/month 2014/008 . We have a from and t

  • Need help with warranty service on ThinkPad Yoga

    Sorry for the seemingly angry headline but I am quite irritated at this point. Around three weeks ago I lost one of the rubber feet off my Thinkpad Yoga 2. After looking on Amazon, the Lenovo store and on Ebay I tried to ask here for advice around tw

  • Macbook opens slowly with progress bar below the logo

    macbook opens slowly with progress bar below the logo, what's happened can it be fixed and how Yosemite OS Thanks

  • I have a situation please suggest some transactional solution.

    hi,     I have two databases one is entry database (DB1) Where entery is done, other database is reporting database (D2). we are trying to transfer data using stored procedure from db1 to db2. the  sp will be scheduled to run after every 20 to 30 sec

  • Exchange Infrastructure T-Spec

    Hi Xi Guru's! I need any technical specification in xi as i have done basic scenarios, I want know how the real time objects will be in Xi, could any one  send me the real time tasks spec or objects, So that it will be more help full to me to get acq