Get_component_list

Hi there,
I'm using the FM 'GET_COMPONENT_LIST' to get the fields of a IT, but it's not working, I'm in 4.7
Not even in SE37 it's working.
there some restriction to use it in 4.7, or someone know another way to get the fields of a internal table?
Alexandre Nogueira

Here is a sample program.  Implement it in your system.  Does it work?
report zrich_0003.
types: begin of type_item,
       f1(3),
       f2(3),
       f3(3),
       f4(3),
       end of type_item.
types: begin of type_data,
       data(800),
       end of type_data.
data:  lineitems type table of type_item with header line,
       t_output type table of type_data with header line,
       fieldlist type table of rstrucinfo with header line,
       fieldsym  type table of rfieldlist with header line.
data:  syrepid type sy-repid.
data:  fieldname like fieldlist-compname,
       data_line type type_data.
field-symbols : <fs1> type any,
                <fs2> type any.
lineitems-f1 = 'a1'.
lineitems-f2 = 'a2'.
lineitems-f3 = 'a3'.
lineitems-f4 = 'a4'.
append lineitems.
lineitems-f1 = 'b1'.
lineitems-f2 = 'b2'.
lineitems-f3 = 'b3'.
lineitems-f4 = 'b4'.
append lineitems.
lineitems-f1 = 'c1'.
lineitems-f2 = 'c2'.
lineitems-f3 = 'c3'.
lineitems-f4 = 'c4'.
append lineitems.
lineitems-f1 = 'd1'.
lineitems-f2 = 'd2'.
lineitems-f3 = 'd3'.
lineitems-f4 = 'd4'.
append lineitems.
syrepid = sy-repid.
* Gets all of the global data types.
call function 'GET_GLOBAL_SYMBOLS'
     exporting
          program   = syrepid
     tables
          fieldlist = fieldsym.
* gets all of the components of a structure
call function 'GET_COMPONENT_LIST'
     exporting
          program    = syrepid
          fieldname  = 'lineitems'
     tables
          components = fieldlist.
format color 3.
loop at lineitems assigning <fs2> .
  loop at fieldlist.
    fieldname = fieldlist-compname .
    assign component  fieldname  of structure <fs2> to <fs1>.
    concatenate data_line <fs1> into data_line .
  endloop.
  append data_line to t_output.
  clear data_line.
endloop.
loop at t_output.
  write:/ t_output.
endloop.
Regards,
Rich Heilman

Similar Messages

  • Issue in GUI_DOWNLOAD

    Hi Experts,
    We are using GUI_DOWNLOAD function module to download data into presentation server in ECC6.
    DATA: T_DATX(300) OCCURS 500 WITH HEADER LINE.
    T_DATX is the one we are passing to FM which contains data to be downloaded.
    In 4.7 version, we have used DATA: _T(1) TYPE x VALUE '09' as field seperator.
    but its not accepting in ECC6 after upgrade. so to overcme this, we have used DATA: T(1) TYPE C VALUE CLABAP_CHAR_UTILITIES=>VERTICAL_TAB. but still its not downloading properly into cells in the excel sheet.
    its downloading single record into single cell. How come I overcome this.
    Pls advice. I have given the below code for your reference.
    DATA: T_DATX(300) OCCURS 500 WITH HEADER LINE.
    Modification ECC 6.0 Release Upgrade START *
    DATA: _T(1) TYPE x VALUE '09'.
      DATA: T(1) TYPE C VALUE CLABAP_CHAR_UTILITIES=>VERTICAL_TAB.
    Modification ECC 6.0 Release Upgrade END *
    *data: _t(1) type c value ';'.
      DATA: _REPID LIKE SY-REPID
           ,_COMP  LIKE RSTRUCINFO OCCURS 10 WITH HEADER LINE
           ,_IDX   LIKE SY-TABIX
           ,F_TYPE(1)
      FIELD-SYMBOLS: <FS>.
      _REPID = SY-REPID.
      CALL FUNCTION 'GET_COMPONENT_LIST'
           EXPORTING
                PROGRAM    = _REPID
                FIELDNAME  = TABNAME
           TABLES
                COMPONENTS = _COMP
           EXCEPTIONS
                OTHERS     = 1.
      LOOP AT _COMP.
        CONCATENATE T_DATX _COMP-COMPNAME T INTO TDATX.
      ENDLOOP.
      APPEND T_DATX.
      CLEAR T_DATX.
      LOOP AT T_EX.
        _IDX = 1.
        ASSIGN COMPONENT IDX OF STRUCTURE TEX TO <FS>.
        DO.
          CONCATENATE T_DATX <FS> T INTO TDATX.
          _IDX = _IDX + 1.
          ASSIGN COMPONENT IDX OF STRUCTURE TEX  TO <FS> .
          IF SY-SUBRC <> 0. EXIT. ENDIF.
        ENDDO.
        APPEND T_DATX.
        CLEAR T_DATX.
      ENDLOOP.
    Regards,
    Sujatha

    Hi Sujatha,
    As suggested by previous poster, you should use horizontal tab as a separator (or a comma) to get a tab-delimited/CSV type format that you can open in Excel. However, instead of building the output table yourself as text lines, I'd simply pass the actual output table to function GUI_DOWNLOAD in parameter DATA_TAB, use table FIELD_NAMES for the column headers (looks like you want those based on your coding) and then set the FILE_TYPE parameter to 'DAT'.
    Best wishes, harald

  • Fields in an internal table

    How to find number of fields in an internal table ?
    my requirement is i have 20 internal tables and the data is being uploaded into an application server. so how to find no of fields in a particular internal table

    concatenate all the fields and move them to final internal table , call the function module "GET_COMPONENT_LIST" and pass the work area of the final internal table in the parameter fieldname
    ***For getting no of FIELDS in an internal table ********
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        PROGRAM          = syrepid
        FIELDNAME        = 't_payr'
      TABLES
        COMPONENTS       = fieldlist.
    describe table fieldlist lines pyr_no_fields.
    ********end of getting no of fields**********
    TRANSFER wa_mat_out_head TO P_FNAME.
    LOOP AT GT_PAYR.
    MOVE:  GT_payr-LIFNR TO T_payr-lifnr,
           GT_payr-ZBUKR TO T_payr-zbukr,
           GT_payr-LAUFD TO T_payr-LAUFD,
           GT_payr-CHECT TO T_payr-CHECT,
           GT_payr-RWBTR TO T_payr-RWBTR.
    Concatenate T_payr-lifnr  t_payr-zbukr T_payr-laufd T_payr-chect
                T_payr-rwbtr into wa_mat_out-rec SEPARATED by ',' .

  • How can I load a flat file into a ZTABLE dynamically

    I need to create a program which can Load a ZTABLE from a flat file structure (delimited and fixed options required).  We have many ZTables where this will be required so I was hoping to do it dynamically somehow.  Otherwise I will have to create one ABAP for every ZTable we have to load.
    My Inputs should be
    PARAMETERS:  p_ztable TYPE ddobjname,         "Z Table Name
                 p_infile(132) LOWER CASE,        "File Name
                 p_delim(1).                      "Delimiter
      I know that I can read the file by using gui_upload
        CALL FUNCTION 'GUI_UPLOAD'
        EXPORTING
          filename                = c_infile
          has_field_separator     = p_delim
        TABLES
          data_tab                = indata
        EXCEPTIONS
          file_open_error         = 1
          file_read_error         = 2
            OTHERS                  = 9.
    I know that  I can split the contents of this file (if a delimiter is used).  However I will not know the actual field names of the table until runtime as to what to fields to split it into.  In the example below I have the actual table (t_rec) and each of the fields (pernr, lgart, etc) in the code but each table I
    need to load will be different – it will have a different # of fields as well.
    FORM read_data_pc.
      LOOP AT indata.
        PERFORM splitdata USING indata.
        APPEND t_rec.
        CLEAR t_rec.
      ENDLOOP.
    ENDFORM.
    FORM splitdata USING p_infile.
       SPLIT p_infile AT p_delim INTO
            t_rec-pernr                 "Employee #
            t_rec-lgart                 "Wage Type
            t_rec-begda                 "Effective date
            t_rec-endda.                 "End date
      ENDFORM.                       
    Once I split the data into the fields then I can just look and insert the record.
    Does anyone have any ideas?  Specific code examples would be great if you do.  Thx!!

    Hi janice,,
    Try this sample code where you can upload data from a flat file into the internal table.
    REPORT  z_test.
    TABLES: mara.
    FIELD-SYMBOLS : <fs> .
    DATA : fldname(50) TYPE c.
    DATA : col TYPE i.
    DATA : cmp LIKE TABLE OF rstrucinfo WITH HEADER LINE.
    DATA: progname LIKE sy-repid,
    dynnum LIKE sy-dynnr.
    DATA itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
    DATA: BEGIN OF ZUPLOAD1_T OCCURS 0 ,
             matnr like mara-matnr,
             ersda like mara-ersda,
             ernam like mara-ernam,
             laeda like mara-laeda,
          END OF ZUPLOAD1_T.
    *DATA: ZUPLOAD1_T LIKE mara OCCURS 0 WITH HEADER LINE.
    DATA: wa_data LIKE TABLE OF  ZUPLOAD1_T WITH HEADER LINE.
    selection-screen
    SELECTION-SCREEN: BEGIN OF BLOCK blk WITH FRAME TITLE text-001.SELECTION-SCREEN : SKIP 1. PARAMETERS : p_file LIKE rlgrap-filename.SELECTION-SCREEN : SKIP 1.SELECTION-SCREEN : END OF BLOCK blk
    . AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    F4 Value for File
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'   EXPORTING
                          PROGRAM_NAME        = SYST-REPID
                          DYNPRO_NUMBER       = SYST-DYNNR
                          FIELD_NAME          = ' '
         static              = 'X'
                          MASK                = ' '
        CHANGING      file_name           = p_file   EXCEPTIONS     mask_too_long       = 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.
    START-OF-SELECTION.
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE' 
    EXPORTING    filename                      = P_FILE   
    i_begin_col                   = 1   
    i_begin_row                   = 1   
    i_end_col                     = 5   
    i_end_row                     = 12507 
         tables   
       intern                        = ITAB
    EXCEPTIONS  
            INCONSISTENT_PARAMETERS       = 1  
            UPLOAD_OLE                    = 2  
           OTHERS                        = 3.          .
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'GET_COMPONENT_LIST' 
    EXPORTING  
        program          = SY-REPID   
        fieldname        = 'ZMARA' 
           tables   
           components       = CMP.
    LOOP AT itab.    AT NEW row.     
    IF sy-tabix = 1.        APPEND ZUPLOAD1_T.     
    ENDIF.   
    ENDAT.   
    col = itab-col.   
    READ TABLE cmp INDEX col.  
    CONCATENATE 'ZUPLOAD1_T-' cmp-compname INTO fldname.  
    ASSIGN (fldname) TO <fs>.  
    <fs> = itab-COL.  
      APPEND ZUPLOAD1_T.  ENDLOOP.
    DELETE ZUPLOAD1_T where matnr eq space.
    LOOP AT ZUPLOAD1_T INTO wa_data.
    insert mara from  wa_data .
        WRITE: / ZUPLOAD1_T-matnr, 20 ZUPLOAD1_T-ersda , 45 ZUPLOAD1_T-ernam, 55 ZUPLOAD1_T-laeda.
    *HERE IAM JUST CHECKING I NEED TO UPDATE A ZTABLE
      ENDLOOP.
    insert ZMARA FROM table itab ACCEPTING DUPLICATE KEYS.
    I have tried it for mara.Please let me know whether it was helful.
    Regards,
    Kannan

  • Fieldnames in GUI_Download function module

    Dear All,
    In the following code im passing the parameter it_fieldnames into 'c:/text.txt' file along with the data but im not able to get the fieldnames in to it, it is getting only data from the it_final. can any1 tell me what is the problem.
    call function 'GUI_DOWNLOAD'
        exporting
          filename                = 'c:/text.txt'"p_fname
          filetype                = 'ASC'
         append                  = 'X'
          write_field_separator   = 'X'
        tables
          data_tab                = it_final
          fieldnames              = it_fieldnames
        exceptions
          file_write_error        = 1
          no_batch                = 2
          gui_refuse_filetransfer = 3
          invalid_type            = 4
          no_authority            = 5.
      case sy-subrc.
        when 0.
        when 1.
          write : / 'Error in opening file ', fname.
        when 2.
          write : / 'Error in writing file ', fname.
        when 3.
          write : / 'The file type is not valid'.
        when others.
          write : / 'The file could not be transferred'.
      endcase.
    endform.                    " f_submit_layout
    *&      Form  VEND_FIELDNAMES
          text
    form tab_fieldnames.
      it_fieldnames-name = 'Sl No'.
      append it_fieldnames.
      it_fieldnames-name = 'Credit Acc'.
      append it_fieldnames.
      it_fieldnames-name = 'credit Doc'.
      append it_fieldnames.
      it_fieldnames-name = 'Credit Ref'.
      append it_fieldnames.
      it_fieldnames-name = '           '.
      append it_fieldnames.
      it_fieldnames-name =   'Amount'.
      append it_fieldnames.
      it_fieldnames-name =   'SSI'.
      append it_fieldnames.
      it_fieldnames-name =   'Debit Bankcode'.
      append it_fieldnames.
      it_fieldnames-name =   'Debit BrCode'.
      append it_fieldnames.
      it_fieldnames-name =   'Debit Acc'.
      append it_fieldnames.
      it_fieldnames-name =   'Debit Cheque'.
      append it_fieldnames.
      it_fieldnames-name =   '            '.
      append it_fieldnames.
      it_fieldnames-name =   ' '.
      append it_fieldnames.
      it_fieldnames-name =   'Batch date'.
      append it_fieldnames.
      it_fieldnames-name =   '          '.
      append it_fieldnames.
    endform.                    "VEND_FIELDNAMES
    Thanks a lot,
    Santosh Kotra.

    Hi santosh,
    1. Exactly for the same purpose
    2. There is an independent subroutine (FORM)
       in my program,
       which will download any table,
       to the specified filename
       (along with FIELDNAMES)
    3. just copy paste
    4.
    report abc.
    data : itab like table of t001 with header line.
    select * from t001 into table itab.
    perform mydownload tables itab using 'D:\t001.txt'.
    INDEPENDENT FORM
    form mydownload tables ptab using filename.
    DAta
      DATA : components     LIKE     rstrucinfo OCCURS 0 WITH HEADER LINE.
      DATA : allfields(300) TYPE c.
      DATA : fld(100) TYPE c.
      data : begin of htab occurs 0,
             allfields(300) type c,
             end of htab.
    Get component list
      CALL FUNCTION 'GET_COMPONENT_LIST'
        EXPORTING
          program    = sy-repid
          fieldname  = 'ITAB'
        TABLES
          components = components.
    construct
      LOOP AT components.
        CONCATENATE   components-compname
      CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO fld.
        CONCATENATE allfields fld INTO allfields .
      ENDLOOP.
      htab-allfields = allfields.
      append htab.
    download first field list
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
      BIN_FILESIZE                    =
          FILENAME                        = 'D:\t001.txt'
         WRITE_FIELD_SEPARATOR           = 'X'
        TABLES
          DATA_TAB                        = htab
    then download file data
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
      BIN_FILESIZE                    =
        FILENAME                        = filename
        APPEND                          = 'X'
       WRITE_FIELD_SEPARATOR           = 'X'
      TABLES
        DATA_TAB                        = ptab
      endform.
    regards,
    amit m.

  • Download using GUI_download

    Hi all,
    i am trying to download the internal table which have 10 field, into the EXCEL file,
    at the same time i wanted into the downloaded file
    field name also appear....how can we do that,,
    while downloading its appearing in a one column,
    i want to shift the every field in different column,
    Any idea about that how i will acheive this
    Thanks for your help..
    Manish

    Hi manish,
    1. For the same purpose
       i have developed an INDEPENDENT SUBROUTINE/FORM
       in which we pass just two things :
        a) itab
        b) file name with full path
    2. It then downloads the file
       (ALONG WITH THE FIELD NAMES AT THE TOP)
      (We have to use GUI_DOWNLOAD two times,
       once for downloading data,
       and once for downloading the field names separated
        by tab)
    3. Just copy paste in new program.
    report abc.
    data : itab like table of t001 with header line.
    select * from t001 into table itab.
    perform mydownload tables itab using 'D:\t001.txt'.
    INDEPENDENT FORM
    form mydownload tables ptab using filename.
    DAta
      DATA : components     LIKE     rstrucinfo OCCURS 0 WITH HEADER LINE.
      DATA : allfields(300) TYPE c.
      DATA : fld(100) TYPE c.
      data : begin of htab occurs 0,
             allfields(300) type c,
             end of htab.
    Get component list
      CALL FUNCTION 'GET_COMPONENT_LIST'
        EXPORTING
          program    = sy-repid
          fieldname  = 'ITAB'
        TABLES
          components = components.
    construct
      LOOP AT components.
        CONCATENATE   components-compname
      CL_ABAP_CHAR_UTILITIES=>HORIZONTAL_TAB INTO fld.
        CONCATENATE allfields fld INTO allfields .
      ENDLOOP.
      htab-allfields = allfields.
      append htab.
    download first field list
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
      BIN_FILESIZE                    =
          FILENAME                        = 'D:\t001.txt'
         WRITE_FIELD_SEPARATOR           = 'X'
        TABLES
          DATA_TAB                        = htab
    then download file data
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
      BIN_FILESIZE                    =
        FILENAME                        = filename
        APPEND                          = 'X'
       WRITE_FIELD_SEPARATOR           = 'X'
      TABLES
        DATA_TAB                        = ptab
      endform.
    regards,
    amit m.

  • Dynamic columns in report... NON ALV REPORT

    Hey Guys,
    I have a internal table which has abt 50 columns now i wanna show only the columns that have any value in it...
    Now this is not an ALV report... this is a basic report....
    So anyideas as to where i can start  on this.... i dont want to write if conditions...
    i am tryin to make this as elegent as possible...
    all help will be appreciated
    Thanks

    Hi,
    Try this..
    In this example..I have an internal table with the columns MATNR, WERKS, LGORT & MENGE...The ITAB is having value only for matnr and werks..It will print only MATNR and WERKS in the output..
    <b>* Data declarations.</b>
    DATA: BEGIN OF itab OCCURS 0,
            matnr  TYPE matnr,
            werks  TYPE werks_d,
            lgort  TYPE mard-lgort,
            menge  TYPE ekpo-menge,
          END OF itab.
    DATA: BEGIN OF itab_desc OCCURS 0,
            compname(30),
            text(20),
          END OF itab_desc.
    DATA: v_repid TYPE syrepid.
    DATA: t_comp  LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.
    FIELD-SYMBOLS: <fs>.
    DATA: t_allowed_fields(30) OCCURS 0 WITH HEADER LINE.
    <b>* Program.</b>
    v_repid = sy-repid.
    <b>* Sample data.</b>
    itab-matnr = 'TEST'.   itab-lgort = '0001'.APPEND itab.
    itab-matnr = 'TEST12'. itab-lgort = '0001'.APPEND itab.
    itab-matnr = 'TEST123'.itab-lgort = '0001'.APPEND itab.
    <b>* Store the columns texts.</b>
    itab_desc-compname = 'MATNR'. itab_desc-text = 'Material'.
    APPEND itab_desc.
    itab_desc-compname = 'WERKS'. itab_desc-text = 'Plant'.
    APPEND itab_desc.
    itab_desc-compname = 'LGORT'. itab_desc-text = 'Sto. Loc'.
    APPEND itab_desc.
    itab_desc-compname = 'MENGE'. itab_desc-text = 'Quantity'.
    APPEND itab_desc.
    <b>* Get the components for that internal table.</b>
    CALL FUNCTION 'GET_COMPONENT_LIST'
         EXPORTING
              program    = v_repid
              fieldname  = 'ITAB'
         TABLES
              components = t_comp.
    <b>* Get the columns that has some value.</b>
    LOOP AT t_comp.
      LOOP AT itab.
        ASSIGN COMPONENT t_comp-compname OF STRUCTURE itab TO <fs>.
        IF NOT <fs> IS INITIAL.
          EXIT.
        ENDIF.
      ENDLOOP.
    Allowed columns.
      IF NOT <fs> IS INITIAL.
        t_allowed_fields = t_comp-compname.
        APPEND t_allowed_fields.
      ENDIF.
    ENDLOOP.
    <b>* Print the Header.</b>
    LOOP AT t_allowed_fields.
      READ TABLE t_comp WITH KEY compname = t_allowed_fields.
      READ TABLE itab_desc WITH KEY compname = t_allowed_fields.
      WRITE: AT (t_comp-olen) itab_desc-text COLOR COL_HEADING.
    ENDLOOP.
    <b>* Print the data.</b>
    LOOP AT itab.
      WRITE: / space.
      LOOP AT t_allowed_fields.
        READ TABLE t_comp WITH KEY compname = t_allowed_fields.
        ASSIGN COMPONENT t_comp-compname OF STRUCTURE itab TO <fs>.
        WRITE: AT (t_comp-olen) <fs>.
      ENDLOOP.
    ENDLOOP.
    Thanks,
    Naren

  • Field name retrieval from field symbols after assigning to field in a struc

    We have an internal table of about 100 columns. First 7 of them have key values and other fields are data fields. Out of remaining 93 fields, any 2 to 3 fields have data stored in it in each record. Using field symbols in a loop (93 fixed iterations), we are identifying which fields has a data in it. Once we identify the field, how do we retrieve the name of the field / column of the table. We are performing further processing based on name of the field.
    Any ideas how to get the name of the column assigned to field symbols?
    sample raw code piece is as below:
    clear n.
    Do 93 times.
      n = n + 1.
      assign component n of structure itab to <fs>.
      if not <fs> is initial.
       Get name of the field in cfname.
        perform process_record using cfname.
      endif.
    enddo.
    Thanks.
    Regards.

    Hi,
    Try this..use the function module GET_COMPONENT_LIST to get the fields of the internal table and store it in an internal table ITAB_COMP..
    Then use READ TABLE ITAB_COMP INDEX sy-index..
    You can get the field name from the work area..
    Thanks,
    Naren

  • Dynamic Table Creation using RTTS - Question on Issue

    I am using the RTTS services to dynamically create a table.  However, when I attempt to use the get_components method it does not return all the components for all tables that I am working with.
    Cases and End Results
    1) Created structure in data dictionary – get_components works.
    2) Pass PA0001, P0001 or T001P to get_components and I do not receive the correct results.  It only returns a small subset of these objects.  The components table has all the entries; however, the get_components method only returns about 4 rows.
    Can you explain this and point me to the correct logic sequence? I would like the logic to work with all tables.
    Code excerpt below:
    The logic for the get components works for case 1, but not case 2. When I pass into this method a "Z" custom table or structure name for parameter “structure_name” and the get_components() method executes and returns the correct results. However, when I pass in any of the objects listed above in case 2, the get_components method does not return the correct number of entries. When I check typ_struct which is populated right before the get_components line, I see the correct number of components in the components table. 
    method pb_add_column_headings .
      constants: c_generic_struct type c length 19 value 'ZXX_COLUMN_HEADINGS'.
      data: cnt_lines      type sytabix,
            rf_data        type ref to data,
            typ_field      type ref to cl_abap_datadescr,
            typ_struct     type ref to cl_abap_structdescr,
            typ_table      type ref to cl_abap_tabledescr.
      data: wa_col_headings type ddobjname.
      data: rf_tbl_creation_exception type ref to 
                                      cx_sy_table_creation,
            rf_struct_creation_exception type ref to
                                      cx_sy_struct_creation.
      data: t_comp_tab type
                       cl_abap_structdescr=>component_table,
            t_comp_tab_new      like t_comp_tab,
            t_comp_tab_imported like t_comp_tab.
      field-symbols: <fs_comp> like line of t_comp_tab,
                     <fs_col_headings_tbl> type any table.
    **Get components of generic structure
      wa_col_headings = c_generic_struct.
      typ_struct ?= cl_abap_typedescr=>describe_by_name(
                                       wa_col_headings ).
      T_COMP_TAB = typ_struct->get_components( ).
    **Determine how many components in imported structure.
      typ_struct ?= cl_abap_typedescr=>describe_by_name(
                                        structure_name ).
      t_comp_tab_imported = typ_struct->get_components( ).
      cnt_lines = lines( t_comp_tab_imported[] ).

    Hi Garton,
    1. GET_COMPONENT_LIST
       Use this FM.
       It gives all fieldnames.
    2. Use this code (just copy paste)
    REPORT abc.
    DATA : cmp LIKE TABLE OF rstrucinfo WITH HEADER LINE.
    DATA : pa0001 LIKE TABLE OF pa0001 WITH HEADER LINE.
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        program    = sy-repid
        fieldname  = 'PA0001'
      TABLES
        components = cmp.
    LOOP AT cmp.
      WRITE :/ cmp-compname.
    ENDLOOP.
    regards,
    amit m.

  • Transfer intenal table to file

    Hi abaers,
    i need to transfer the internal table data to file,,this file to create in application server.
    internal table lineitems contains 100 fields...
    i tried in the following method: but 100 fields i have to move each and evry field to t_output-data.. so it is becoming complex.
    data: begin of t_output occurs 0,
         data(800),
       end of t_output.
    loop at lineitems.
    t_output-data(4) = lineitems-COMP_CODE.
    t_output-data+4(10) = lineitems-VENDOR.
    append t_output.
    clear t_output.
    endloop.
       open dataset filename for output in text mode encoding default.
       loop at t_output.
          transfer t_output-data to filename.
         clear t_outpu-data.
       endloop.
       close dataset filename.
    endif.
    is there any other method to do direct transfer from internal table to file..

    Hi,
    I think FM: GET_COMPONENT_LIST would be very useful to u.
    i have attached the complete code and it's working absolutely fine with me.
    Code **********
    types: begin of type_item,
            f1(3),
            f2(3),
            f3(3),
            f4(3),
           end of type_item.
    types: begin of type_data,
            data(800),
           end of type_data.
    data : lineitems type table of type_item with header line,
           t_output type table of type_data with header line,
           fieldlist type table of RSTRUCINFO with header line.
    lineitems-f1 = 'a1'.
    lineitems-f2 = 'a2'.
    lineitems-f3 = 'a3'.
    lineitems-f4 = 'a4'.
    append lineitems.
    lineitems-f1 = 'b1'.
    lineitems-f2 = 'b2'.
    lineitems-f3 = 'b3'.
    lineitems-f4 = 'b4'.
    append lineitems.
    lineitems-f1 = 'c1'.
    lineitems-f2 = 'c2'.
    lineitems-f3 = 'c3'.
    lineitems-f4 = 'c4'.
    append lineitems.
    lineitems-f1 = 'd1'.
    lineitems-f2 = 'd2'.
    lineitems-f3 = 'd3'.
    lineitems-f4 = 'd4'.
    append lineitems.
    field-symbols : <fs> type any.
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        PROGRAM    = sy-repid
        FIELDNAME  = 'lineitems'
      TABLES
        COMPONENTS = fieldlist.
    data : fieldname like fieldlist-compname,data_line type type_data,dref
    type ref to data.
    format color 3.
    loop at lineitems REFERENCE INTO dref. .
    loop at fieldlist.
        fieldname =  fieldlist-compname .
        assign dref->(fieldname) to <fs>.
      concatenate data_line <fs> into data_line .
    endloop.
    append data_line to t_output.
    clear data_line.
    endloop.
    loop at t_output.
      write:/ t_output.
    endloop.
    Code *************
    If u still have any issues please revert back.
    Hope it'll help u.
    Regards,
    Ankur

  • How do I read the metadata of an object in abap?

    I need to find a way to read the metadata of an object (say an internal table) in abap.  An example of what I am looking to do is that I want to get a list of all the column names of an internal table.  Any help would be greatly appreciated!
    Dustin

    Sure, use this function.
    TYPES: BEGIN OF type_item,
           f1 TYPE char30,
           f2 TYPE char30,
           f3 TYPE char30,
           f4 TYPE char30,
           END OF type_item.
    DATA:  lineitems TYPE TABLE OF type_item WITH HEADER LINE,
           fieldlist TYPE TABLE OF rstrucinfo WITH HEADER LINE.
    DATA:  syrepid TYPE sy-repid.
    syrepid = sy-repid.
    * gets all of the components of a structure
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        program    = syrepid
        fieldname  = 'lineitems'
      TABLES
        components = fieldlist.
    LOOP AT fieldlist.
      WRITE:/ fieldlist-compname .
    ENDLOOP.
    Regards,
    Rich Heilman

  • Upload Flat File in Z-table

    Hello everyone,
    We have a Z custom table which contains data about Customer Class. I was wondering if it is possible to load a flat file into the Z Table. Kindly advice how to load a flat file in z-table.
    Thanks,
    Sanju

    PLS WATCH THE CODE and kindly tell me the error
    REPORT  z_test.
    TABLES: mara.
    FIELD-SYMBOLS : <fs> .
    DATA : fldname(50) TYPE c.
    DATA : col TYPE i.
    DATA : cmp LIKE TABLE OF rstrucinfo WITH HEADER LINE.
    DATA: progname LIKE sy-repid,
    dynnum LIKE sy-dynnr.
    DATA itab TYPE TABLE OF alsmex_tabline WITH HEADER LINE.
    DATA: BEGIN OF ZUPLOAD1_T OCCURS 0 ,
             matnr like mara-matnr,
             ersda like mara-ersda,
             ernam like mara-ernam,
             laeda like mara-laeda,
          END OF ZUPLOAD1_T.
    *DATA: ZUPLOAD1_T LIKE mara OCCURS 0 WITH HEADER LINE.
    DATA: wa_data LIKE TABLE OF  ZUPLOAD1_T WITH HEADER LINE.
    selection-screen
    SELECTION-SCREEN: BEGIN OF BLOCK blk WITH FRAME TITLE text-001.
    SELECTION-SCREEN : SKIP 1.
    PARAMETERS : p_file LIKE rlgrap-filename.
    SELECTION-SCREEN : SKIP 1.
    SELECTION-SCREEN : END OF BLOCK blk.
    AT SELECTION-SCREEN ON VALUE-REQUEST FOR p_file.
    F4 Value for File
      CALL FUNCTION 'KD_GET_FILENAME_ON_F4'
       EXPORTING
                          PROGRAM_NAME        = SYST-REPID
                          DYNPRO_NUMBER       = SYST-DYNNR
                          FIELD_NAME          = ' '
         static              = 'X'
                          MASK                = ' '
        CHANGING
          file_name           = p_file
       EXCEPTIONS
         mask_too_long       = 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.
    START-OF-SELECTION.
    CALL FUNCTION 'ALSM_EXCEL_TO_INTERNAL_TABLE'
      EXPORTING
        filename                      = P_FILE
        i_begin_col                   = 1
        i_begin_row                   = 1
        i_end_col                     = 5
        i_end_row                     = 12507
      tables
        intern                        = ITAB
    EXCEPTIONS
       INCONSISTENT_PARAMETERS       = 1
       UPLOAD_OLE                    = 2
       OTHERS                        = 3.
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        program          = SY-REPID
        fieldname        = 'ZMARA'
      tables
        components       = CMP.
      LOOP AT itab.
        AT NEW row.
          IF sy-tabix = 1.
            APPEND ZUPLOAD1_T.
          ENDIF.
        ENDAT.
        col = itab-col.
        READ TABLE cmp INDEX col.
        CONCATENATE 'ZUPLOAD1_T-' cmp-compname INTO fldname.
        ASSIGN (fldname) TO <fs>.
        <fs> = itab-COL.
        APPEND ZUPLOAD1_T.
      ENDLOOP.
    DELETE ZUPLOAD1_T where matnr eq space.
      LOOP AT ZUPLOAD1_T INTO wa_data.
    insert mara from  wa_data .
        WRITE: / ZUPLOAD1_T-matnr, 20 ZUPLOAD1_T-ersda , 45 ZUPLOAD1_T-ernam, 55 ZUPLOAD1_T-laeda.
    *HERE IAM JUST CHECKING I NEED TO UPDATE A ZTABLE
      ENDLOOP.
    insert ZMARA FROM table itab ACCEPTING DUPLICATE KEYS.
    Edited by: shivu kishu on Feb 7, 2011 10:29 AM

  • How to determine itab type at run time

    I need to write a subroutine that organizes data in internal tables for presentation by a smartform. There are a few similarly structured internal tables all with the same field name ("recipe_type") by which the data is sorted. My problem is that how I can determine the type of the itab inside my subroutine at run time? Is it ever possible in ABAP?
    The subroutine code is attached below. Thanks for any help.
    FORM beautify_itab    TABLES itab_in TYPE table
                                     USING v_type TYPE any
                                     CHANGING itab_out TYPE table.
    Data declaration
      DATA: v_data_row LIKE LINE OF itab_in,                " THIS WON'T COMPILE!
                 v_blank_row LIKE LINE OF itab_in.              " blank row
    Organize the display of the table data
      LOOP AT itab_in INTO v_data_row.
        IF v_type <> itab_in-recipe_type.                     " 'recipe_type' is the sort key for the incoming itabs
          v_type = itab_in-recipe_type.
          IF sy-tabix > 1.
            APPEND v_blank_row TO itab_out.
          ENDIF.
          APPEND v_data_row TO itab_out.
        ELSE.
          CLEAR v_data_row-recipe_type.
          APPEND v_data_row TO itab_out.
        ENDIF.
      ENDLOOP.
    ENDFORM.                    "beautify_itab

    The following code does what I want, but only if the input itab structure is declared first in the program. It won't work if the itab is declared as itab_in TYPE TABLE OF sflight. This is because the function 'GET_COMPONENTS_LIST'  only can load the structure of a field declared explicitly in the program.  Does anybody know of any method to load the structure of an itab based off a dtab? 
    Thanks you guys for answers. Points have been rewarded.
    *& Report  Z_GET_ITAB_TYPE_AT_RUN_TIME
    REPORT  z_get_itab_type_at_run_time.
    DATA: BEGIN OF itab_in OCCURS 0,
             seatsocc_b LIKE sflight-seatsocc,
             fldate LIKE sflight-fldate,
          END OF itab_in,
          itab_out TYPE TABLE OF string,
          wa_itab_out TYPE string.
    SELECT seatsocc_b fldate
    INTO TABLE itab_in
    FROM sflight
    WHERE carrid = 'AA' AND
          connid = '0017'
    ORDER BY seatsocc_b.
    PERFORM beautify_itab
                TABLES
                   itab_in
                USING
                   sy-repid
                   'itab_in'
                   'SEATSOCC_B'
                CHANGING
                   itab_out.
    LOOP AT itab_out INTO wa_itab_out.
      WRITE: / wa_itab_out.
    ENDLOOP.
    *&      Form  beautify_itab
          text
         -->ITAB_IN    text
         -->V_KET_FIELD   text
         -->ITAB_OUT   text
    FORM beautify_itab TABLES itab_in TYPE table
                       USING  v_prog_name LIKE sy-repid
                              v_itab_in_name TYPE any
                              v_key_field_name TYPE rstrucinfo-compname
                       CHANGING  itab_out TYPE table.
      DATA: itab_fields TYPE TABLE OF rstrucinfo,
            v_field_name LIKE rstrucinfo-compname,
            v_old_key TYPE string,
            v_field_value TYPE string,
            v_data_line TYPE string,
            v_tabix LIKE sy-tabix,
            c_blank_row TYPE string VALUE ''.
      FIELD-SYMBOLS: <fs_field>,
                     <fs_data_line>,
                     <fs_field_list> TYPE  rstrucinfo.
    gets all of the components of a structure
      CALL FUNCTION 'GET_COMPONENT_LIST'
        EXPORTING
          program    = v_prog_name
          fieldname  = v_itab_in_name
        TABLES
          components = itab_fields.
      LOOP AT itab_in ASSIGNING <fs_data_line>.
        v_tabix = sy-tabix.
        LOOP AT itab_fields ASSIGNING <fs_field_list>.
          v_field_name =  <fs_field_list>-compname.
          ASSIGN COMPONENT v_field_name OF STRUCTURE
                        <fs_data_line> TO <fs_field>.
          v_field_value = <fs_field>.
          IF v_key_field_name = v_field_name.
            IF v_old_key <> v_field_value.
              v_old_key = v_field_value.
              IF v_tabix > 1.
                APPEND c_blank_row TO itab_out.
              ENDIF.
            ELSE.
              CLEAR v_field_value.
            ENDIF.
          ENDIF.
          CONCATENATE v_data_line v_field_value INTO v_data_line
                      SEPARATED BY space.
        ENDLOOP.
        APPEND v_data_line TO itab_out.
        CLEAR v_data_line.
      ENDLOOP.
    ENDFORM.                    "beautify_itab

  • Alternative for 'WITH HEADER LINE' ?

    Hello All,
    In BSP's I gues we can't use table with header lines and occurs 0.
    SO whts the alternative for this ?
    I want to use the FM 'GET_COMPONENT_LIST' .
    To this FM I need to pass the table which is declared with  occurs 0 or with header line .
    Eg:
    DATA: lt_cols TYPE STANDARD TABLE OF it_cols with header line.
    DATA: v_count TYPE i.
    CALL FUNCTION 'GET_COMPONENT_LIST'
      EXPORTING
        program    = sy-repid
        fieldname  = 'LT_COLS'
      TABLES
        components = itab[].
    DESCRIBE TABLE itab LINES v_count.
    WRITE v_count.
    " I've used the following code :
          DATA: ls_final_t    TYPE STANDARD TABLE OF mara initial size 10  ,
                lt_rstrucinfo TYPE TABLE OF rstrucinfo .
          CALL FUNCTION 'GET_COMPONENT_LIST'
            EXPORTING
              program    = 'CL_O243NHIEBSRAZZG8RPTVGL3YAH9CP'
              fieldname  = 'LS_FINAL_T'
            TABLES
              components = lt_rstrucinfo[].
    But it's not working .
    I guess the problem is wid passage of parameter for program.
    Bcoz i tried the same in the ABAP Program and it's working !
    SO can any one tell me what to pass for the program ?
    I tried with sy-repid , hardcoded my BSP application name , but none of them worked !!!
    Can anyone help me out ?
    Regards,
    Deepu.K

    Hi Depp,
    The problem with your code example is that you should not have used the [] addition to the table name.
    Try this...
          CALL FUNCTION 'GET_COMPONENT_LIST'
            EXPORTING
              program    = 'CL_O243NHIEBSRAZZG8RPTVGL3YAH9CP'
              fieldname  = 'LS_FINAL_T'
            TABLES
              components = lt_rstrucinfo. "Note change here!
    It is a good idea to get used to working with tables without header lines. I like to use data references where possible.
    For example...
      DATA: i_tab TYPE TABLE OF sflight,
            w_ref TYPE REF TO sflight.
    * Append line to table
      APPEND INITIAL LINE TO i_tab REFERENCE INTO w_ref.
      w_ref->carrid = 'AA'.
      w_ref->connid = '123'.
    * Loop through table
      LOOP AT i_tab REFERENCE INTO w_ref.
        WRITE: / `ConnID is `, w_ref->connid.
      ENDLOOP.
    * Read line
      READ TABLE i_tab REFERENCE INTO w_ref WITH KEY connid = '123'.
    Cheers
    Graham Robbo

  • To get number and name of groups() existing in AD

    Dear Fouramites,
    I got the program from this forum to retrive the number of users in a group given the name of the group in search filter.
    String searchFilter = "(&(objectClass=group)(CN=pluto*))";
    My requirement is to get the names of all the the groups(aliases) created by admin. Can any one plz help me out in getting this info.
    Thanks & Regards
    Kaavyanjali jena

    use this FM GET_COMPONENT_LIST.
    can get list of fields also from variable which is not defined in DDIC. But has to be global.
    Michal

Maybe you are looking for