FM DB_GET_TABLE_FIELDS

Use the FM DB_GET_TABLE_FIELDS for this purpose.
Pass the table name in TABNAME parameter and it will return a table (thru the TABLES parameter) which u can capture in an internal table with structure DBFIELD.
Someone provide me this fm, but i dont know hw to delcare the internal table for the DBFIELD?
Code to declare the internal table pls.

Use the FM DB_GET_TABLE_FIELDS for this purpose.
Pass the table name in TABNAME parameter and it will return a table (thru the TABLES parameter) which u can capture in an internal table with structure DBFIELD.
Check the code below:
REPORT ZYKTEST3 .
DATA: d_ref TYPE REF TO data,
d_ref2 TYPE REF TO data,
i_alv_cat TYPE TABLE OF lvc_s_fcat,
ls_alv_cat LIKE LINE OF i_alv_cat.
TYPES: tabname LIKE dcobjdef-name ,
fieldname LIKE dcobjdef-name,
desc LIKE dntab-fieldtext.
PARAMETER: p_tablen TYPE tabname. -
> Input table field
DATA: BEGIN OF itab OCCURS 0.
INCLUDE STRUCTURE dntab.
DATA: END OF itab.
FIELD-SYMBOLS : <f_fs> TYPE table,
<f_fs1> TYPE table,
<f_fs2> TYPE ANY,
<f_fs3> TYPE ANY,
<f_fs4> type any,
<f_field> TYPE ANY.
REFRESH itab.
CALL FUNCTION 'NAMETAB_GET' -
> Fetches the fields
EXPORTING
langu = sy-langu
tabname = p_tablen
TABLES
nametab = itab
EXCEPTIONS
no_texts_found = 1.
LOOP AT itab .
ls_alv_cat-fieldname = itab-fieldname.
ls_alv_cat-ref_table = p_tablen.
ls_alv_cat-ref_field = itab-fieldname.
ls_alv_cat-seltext = itab-fieldtext.
ls_alv_cat-reptext = itab-fieldtext.
APPEND ls_alv_cat TO i_alv_cat.
ENDLOOP.
internal table build
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = i_alv_cat
IMPORTING
ep_table = d_ref.
ASSIGN d_ref->* TO <f_fs>. -
> Dynamic table creation with fields of the table
DATA: l_field TYPE fieldname,
l_field1 type fieldname.
SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <f_fs>.
Fetching of the data from the table
LOOP AT <f_fs> ASSIGNING <f_fs2>.
Here u can check the validations and process
ASSIGN COMPONENT 2 OF STRUCTURE <f_fs2> TO <f_fs3>.
ASSIGN COMPONENT 3 OF STRUCTURE <f_fs2> TO <f_fs4>.
IF sy-subrc = 0.
MOVE <f_fs3> TO l_field.
MOVE <f_fs4> TO l_field1.
WRITE:/1 l_field(20),
22 l_field1(10).
ENDIF.
ENDLOOP.

Similar Messages

  • How to download structure fields using  (Not querying DD03L)

    Hi Gurus,
    The function module 'DB_GET_TABLE_FIELDS' is used to download table fields but if I want to download structure fields, how do I do it ?
    I don't want to query DD03L because it then gives fields in alphabetical order but the actual structure does not have those fields in alphabetical order.
    Regards,
    Rajesh.

    Hi,
    You can still use DD03L..Then sort the internal table POSITION.
    Example
    DATA: ITAB LIKE DD03L OCCURS 0 WITH HEADER LINE.
    SELECT * FROM DD03L INTO TABLE ITAB
                 WHERE TABNAME = 'RV45A'.
    IF SY-SUBRC = 0.
      SORT ITAB BY POSITION.
    ENDIF.
    Now the itab will be in the order that you see in SE11..
    Thanks,
    Naren

  • Function mod

    hi all
    can anyone jst explain me for wht purpose the following function modules were used
    SPI_AGENT_IDOC_CREATE
    KD_GET_FILENAME_ON_F4
    MASTER_IDOC_DISTRIBUTE
    DB_GET_TABLE_FIELDS
    NUMBER_GET_NEXT
    EDI_DOCUMENT_OPEN_FOR_READ
    EDI_DOCUMENT_READ_LAST_STATUS
    CARD_CHARACTERISTIC_READ
    CONVERSION_EXIT_ATINN_INPUT

    It thinks it's easier to read the documentation....
    <b>KD_GET_FILENAME_ON_F4</b> --> Get the source of a file in the presentation server.
    <b>MASTER_IDOC_DISTRIBUTE</b> --> Create an IDOC by code.
    <b>DB_GET_TABLE_FIELDS</b> --> Get the fields of a table.
    <b>EDI_DOCUMENT_OPEN_FOR_READ</b> --> Opens an EDI (IDoc) document for reading....Just for reading.
    <b>EDI_DOCUMENT_READ_LAST_STATUS</b> --> Reads the status of an EDI (IDoc) document.....21 for Ok, 30 for error....
    <b>NUMBER_GET_NEXT</b> --> It think this is use by SNRO transacction....
    Greetings,
    Blag.

  • Case-endcase use with Radio button ...

    Hi,
    I am writing a small ABAP report.
    It has following selections:
    Parameter1
    Parameter2
    Radio1
    Radio2
    Radio3
    Now after I finish complete selection.
    Function module DB_GET_TABLE_FIELDS uses parameter 1.
    I have done till this part.
    Now, after this parameter2 should get concatenated with
    'ABC' if radio1 or
    'XYZ' if radio2 or
    'LMN' if radio3.
    How can I do this using case-endcase ?
    Regards,
    Rajesh.

    Hello Rajesh
    I have seen quite a few times the following coding within the SAP standard:
      CASE 'X'.
        WHEN radio1.
        WHEN radio2.
        WHEN radio3.
        WHEN others.
        ENDCASE.
    Needless to say that this is ugly programming.
    Regards
      Uwe

  • To get list of fields

    Hi
    I want to print the list of fields of a SAP table,
    The name of table is given by user on runtime??
    Thanks
    Lokesh

    Hi
    Also see this one..hope this helps u..
    DB_GET_TABLE_FIELDS
    Reward points
    Shakir

  • Download the file

    How to download the report output to the specified file
    Edited by: Anil Reddy on Dec 19, 2007 9:35 AM

    Hi Anil,
    There are different ways to do this. There is the ALV option that comes with the ability to download into spreadsheet format, and you can also use OLE to run Excel & create a spreadsheet. Since it is a report you asked about, ALV is the more logical way to go.
    OR
    standard SAP functionality: (from the menu) System --> List --> Save -->Local File choose excel format.
    or you can use the function module - GUI_DOWNLOAD for downloading the file to the presentations server.
    Here i am copying a sample code for downloading a file using
    GUI_DOWNLOAD.
    This code download the data from table kna1 to a text file along the
    header data.
    TABLES:  KNA1.
    PARAMETERS:  STATE LIKE KNA1-REGIO .
    TYPES:       BEGIN OF OUTREC,
                 KUNNR LIKE KNA1-KUNNR,
                 REGIO  LIKE KNA1-REGIO,
                 TELF1  LIKE KNA1-TELF1,
              END OF OUTREC.
    TYPES:
    BEGIN OF ty_output,
    name TYPE dbfieldnam,
    END OF ty_output.
    DATA:
    lt_dbfield TYPE STANDARD TABLE OF dbfield WITH HEADER LINE,
    lt_output TYPE STANDARD TABLE OF ty_output WITH HEADER LINE.
    CALL FUNCTION 'DB_GET_TABLE_FIELDS'
    EXPORTING
    field_info = 'A'
    tabname = 'KNA1'
    IMPORTING
    SUBRC =
    TABLES
    dbfields = lt_dbfield.
    LOOP AT lt_dbfield.
    lt_output-name = lt_dbfield-name.
    APPEND lt_output.
    ENDLOOP.
    DATA:     OUT_ITAB TYPE STANDARD TABLE OF OUTREC
                 INITIAL SIZE 10 WITH HEADER LINE,
           IN_ITAB TYPE STANDARD TABLE OF OUTREC
                 INITIAL SIZE 10 WITH HEADER LINE.
    SELECT * FROM KNA1 WHERE REGIO = STATE.
         MOVE-CORRESPONDING KNA1 TO OUT_ITAB.
         APPEND OUT_ITAB.
    ENDSELECT.
    CALL FUNCTION 'GUI_DOWNLOAD'
      EXPORTING
      BIN_FILESIZE                    =
        FILENAME                        =  'C:\XYZ.TXT'
       FILETYPE                        = 'ASC'
       APPEND                          = 'X'
       WRITE_FIELD_SEPARATOR           = 'X'
       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'
      WK1_N_FORMAT                    = ' '
      WK1_N_SIZE                      = ' '
      WK1_T_FORMAT                    = ' '
      WK1_T_SIZE                      = ' '
    IMPORTING
      FILELENGTH                      =
      TABLES
        DATA_TAB                        =  OUT_ITAB
       FIELDNAMES                    =   lt_output
       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.
    Reward points if useful.
    Regards
    Manoj Kumar

Maybe you are looking for

  • SCCM 2012 R2 Task Sequence to Restart Computers

    This is a simple question but I cannot seem to get it right. I am working on Monthly Maintenance plan for my servers and I cannot seem to get it right, any help would greatly appreciate it. I have Server collections for all OS's (2003, 2008...2012 R2

  • Weblogic starting issue

    Hi all to all the oracle users! Oracle is divine technology Edited by: mrKar on Sep 21, 2012 10:31 AM

  • Implicit conversion working then not working (ORA-017222)

    I have a table like following: One of the SQL of my application does the following: SELECT C1 FROM MyTable WHERE C1 =

  • Undefined variable or class name

    I am trying to call a java class to another class but gets the error: "Undefined variable or class name" Both my java files are in the same directory and I am able to compile only one of the program. Wondering what am I missing? The source code is: S

  • Internet connection tempermental and slow

    Hi, For about two week now my iMac has been dropping connection quite regularly, or running incredibly slow for a few minutes at a time. It's a problem that exclusively affects my Mac (my mobile and tablet work flawlessly at all times on the same net