Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Checking table field name

Former Member
0 Likes
1,345

I want to get "dynamic" some data from table. What i mean saying 'dynamic'.

I have an ABAP dictonary table TRDIR. I want to allow user to choose some data by typing the name of table column. Than I use want to read only data form this column.

I use field symbols (representing column name) to do this:

local_data_line_from_TRDIR-<FS>.

I'm interesting about FM whichcan check that local_data_line_from have column which name is in <FS>.

8 REPLIES 8
Read only

anversha_s
Active Contributor
0 Likes
1,249

hi tomaz,

first fetch all the data from the data base table

to an INTERNAL_TABLE.

then allow user to select a column.

then U get the field-name of that column

using FM - > GET_COMPONENT_LIST'

*********how to use it *************

DATA : components LIKE rstrucinfo OCCURS 0 WITH HEADER LINE.

----


Get component list*************

CALL FUNCTION 'GET_COMPONENT_LIST'

EXPORTING

program = sy-repid

fieldname = 'ITAB'

TABLES

components = components.

rgds

anver

if helped mark points

Read only

Laxmana_Appana_
Active Contributor
0 Likes
1,249

Hi,

Check this link for my sample code , once data comes into ALV , you can download it to excel and you can delete the columns which are not required.

Regards

Appana

Read only

0 Likes
1,249

I found in linked topic (by L Appana) partial solution which tell that I should to check if table field exist in table DD03L. (thx for that)

Off course my question is an generalization of some problem. Really I have an ready internal table (doesn't matter how it was created) with data (column: table_name and table_field_name). Inside this tables I have information from which table and from which field I should read information. But those names aren't freely selectable (they are limited to some tables and some fields). Because all those field are related in some way with itself I can early select some data to an internal table (let call it it_with_selected_data) with structur which have all fields relevant to allowed fieldname inside itself.

So my task is really to check value of table_name and table_field_name and read relevant information from it_with_selected_data.

Thx guys for help

Message was edited by: Tomasz Suchanek

Read only

0 Likes
1,249

I just wish to clarify whether the below states your requirement !!

U have an internal table say itab with table name and fieldname...while another isel with selected data for the corresponding fields...Now you wish to loop through itab and get the corresponding data from isel ??

In that case what is the structure of isel...is it storing the field data as column or in rows ?

Read only

0 Likes
1,249

I found solution myself, it look like below (the most important think was I was looking for was a DD03l table, thx again L Appana for link) :

This is the way how I find which table name was choosen and which field name (as I said is restricted, limited, in this case to TRDIR and TADIR)


FORM explode_parameters
  USING     pse_parameters TYPE ts_parameters
  CHANGING  pv_table_name  TYPE c
            pv_table_field TYPE c
            pv_status      TYPE c.

  DATA:     lv_table_name  TYPE c,
            lv_table_field TYPE c.

  CLEAR pv_table_name.
  CLEAR pv_table_field.

* default: nothing found
  pv_status = space.

  SPLIT  pse_parameters-value AT '-'
    INTO pv_table_name pv_table_field.

  IF sy-subrc EQ 0.
*   work on local data
    lv_table_name   =  pv_table_name.
    lv_table_field  =  pv_table_field.
    "uppercase
    TRANSLATE lv_table_name TO UPPER CASE.
    TRANSLATE lv_table_field TO UPPER CASE.
    CASE lv_table_name.
      WHEN 'TRDIR'.
        IF NOT lv_table_field IS INITIAL.
          pv_status = '1'.
          "restore parameters as upper case
          pv_table_name  = lv_table_name.
          pv_table_field = lv_table_field.
        ENDIF.
      WHEN 'TADIR'.
        IF NOT lv_table_field IS INITIAL.
          pv_status = '2'.
          "restore parameters as upper case
          pv_table_name  = lv_table_name.
          pv_table_field = lv_table_field.
        ENDIF.
      WHEN OTHERS.
        pv_status = 'S'.
    ENDCASE.
  ENDIF.

ENDFORM.


*&---------------------------------------------------------------------*
*&      Form  check_table_params_exists
*&---------------------------------------------------------------------*
*       2006.09.11 by Tsy
*       PV_OCCURRENCE is:
*         '1'   when TRDIR need to be read
*         '2'   when TADIR need to be read
*         '3'   when both table need to be read
*         SPACE when no table found
*
*       Function finish searching when both table need to be read
*       than later checking is not neccessary
*       or when it finish looping
*----------------------------------------------------------------------*
*      -->VALUE(PTE_PARAMETERS)  text
*      -->PV_OCCURRENCE          text
*----------------------------------------------------------------------*
form check_table_params_exists
    using    value(pte_parameters)  type  tt_parameters
    changing pv_occurrence          type  c.

  data:  ls_parameters  type ts_parameters,
         lv_table_name(40)    type c,
         lv_table_field(40)   type c,
         ls_table_def         type dd03l.

* default: no relevant table name found
  pv_occurrence = space.

  loop at pte_parameters into ls_parameters.

    clear ls_table_def.

*   extract table name and table field
    split ls_parameters-value at '-'
          into lv_table_name lv_table_field.

    if sy-subrc = 0.
*     to uppercase
      translate lv_table_name to upper case.
      translate lv_table_field to upper case.
*     is tablename TRDIR or TADIR?
      if  ( lv_table_name eq 'TRDIR' )       "if table name is correct
      and ( not lv_table_field is initial ). "and fieldname is choosen
        "found
        select single tabname fieldname
          into corresponding fields of ls_table_def
          from dd03l
          where tabname   = lv_table_name
            and fieldname = lv_table_field.
        "if this field exist
        if not ls_table_def is initial.
          if pv_occurrence eq '2'.
            pv_occurrence = '3'.
            exit.
          else.
            pv_occurrence = '1'.
          endif.
        endif.
      elseif  ( lv_table_name eq 'TADIR' )    "if table name is correct
      and ( not lv_table_field is initial ).  "and fieldname is choosen
        select single tabname fieldname
            into corresponding fields of ls_table_def
            from dd03l
            where tabname   = lv_table_name
              and fieldname = lv_table_field.
        if not ls_table_def is initial.
          if pv_occurrence eq '1'.
            pv_occurrence = '3'.
            exit.
          else.
            pv_occurrence = '2'.
          endif.
        endif.
      endif.
    endif.
    clear ls_parameters.
  endloop.
endform.                    "check_table_params_exists

This is how I assing correct values


FORM fill_param_val_from_table_line
    USING     pv_table_name   TYPE c
              pv_field_name   TYPE c
              pv_occurrence   TYPE c
              pse_prog_data   TYPE /imgdt/head_prog
    CHANGING  pv_param_value  TYPE c.

  FIELD-SYMBOLS <tn> TYPE /imgdt/head_prog.
  FIELD-SYMBOLS <fv> TYPE c.

  ASSIGN pse_prog_data TO <tn>.

  CASE pv_occurrence.
    WHEN '1'. "TRDIR
      ASSIGN COMPONENT pv_field_name OF STRUCTURE <tn> TO <fv>.
      pv_param_value = <fv>.
    WHEN '2'. "TADIR
      ASSIGN COMPONENT pv_field_name OF STRUCTURE <tn> TO <fv>.
      pv_param_value = <fv>.
    WHEN OTHERS. "when 'S' ad in other cases don't change anything
  ENDCASE.

ENDFORM. "fill_param_val_from_table_line

Message was edited by: Tomasz Suchanek

Message was edited by: Tomasz Suchanek

Message was edited by: Tomasz Suchanek

Read only

Former Member
0 Likes
1,249

Hi Tomasz,

do you use ALV. if yes, delete all fields which

are not marked from the fieldcat or set it to no_out.

Regards, Dieter

Read only

Former Member
0 Likes
1,249

Hi,

check Fm nametab_get.

Regards

Amole

Read only

Lakshmant1
Active Contributor
0 Likes
1,249

Hi Tom,

Check FM RFC_READ_TABLE.Pass the table name and the field names which you require to fetch data in FIELDS parameter or you can use the same logic used in the FM.

Hope this helps.

Thanks

Lakshman