12-12-2008 12:24 PM
Hi Everyone first thanx for answering my first question in this forum.
i try to explain the situation clearly
i use a parameter to get an input table name, it can be CAWN, can be MARA, can be MVKE,
then i need to check whether in this table whether there is a colume/field called MatNr or Werks...
if so ... Process A
if not ... Process B
how can i get the name of fields.(not the data content)
i think i should use fieldsymbol or something alike, anyone has a good example or idea?
thanx!!!
12-12-2008 12:31 PM
Hi Yunfan,
You can acheive this by using field symbols.
You need to declare two field symbols.
FIELD_SYMBOLS: <fs1> TYPE "Your internal table.
FIELD_SYMBOLS: <fs2> TYPE any
Then, You need to use the statement
ASSIGN COMPONENT 'FIELD NAME' OF STRUCTURE <FS1> TO <FS2>
- Check help for proper syntax
If this ASSIGNMENT is succcessful, this means the field that you are looking for is existing.
If the assignment is not successful, the field does not exist.
Hope this solves your query.
Best Regards,
Ram.
12-12-2008 12:31 PM
12-12-2008 12:31 PM
Hi Yunfan,
You can acheive this by using field symbols.
You need to declare two field symbols.
FIELD_SYMBOLS: <fs1> TYPE "Your internal table.
FIELD_SYMBOLS: <fs2> TYPE any
Then, You need to use the statement
ASSIGN COMPONENT 'FIELD NAME' OF STRUCTURE <FS1> TO <FS2>
- Check help for proper syntax
If this ASSIGNMENT is succcessful, this means the field that you are looking for is existing.
If the assignment is not successful, the field does not exist.
Hope this solves your query.
Best Regards,
Ram.
12-12-2008 1:13 PM
really interested in ur answer
FIELD_SYMBOLS: <fs1> TYPE "Your internal table.
but problem is i got my type from an input through parameter, it can be mvke, mara, cawn, or ...
how can i define <fs1> using a dynamic?.
12-12-2008 1:17 PM
here is my codes
PARAMETERS p_mat1 TYPE mara-matnr.
PARAMETERS p_mat2 type mara-matnr.
parameters p_tab(20) type c.
FIELD-SYMBOLS: <tab1> like p_tab,
<tab2> type any,
<wa> type any.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <tab1> TO <tab2>.
but the sy-subrc after this always 4 , even if i set p_tab = mvke
why???
12-12-2008 1:24 PM
Hi
U can use fm DDIF_FIELDINFO_GET in order to find out the name of the fields of a dictionary table.
If you're working on realese => 4.7:
PARAMETERS: P_TABLE(30).
DATA: MY_TABLE TYPE REF TO DATA,
WA_TABLE TYPE REF TO DATA.
FIELD-SYMBOLS: <MY_TABLE> TYPE TABLE,
<WA_TABLE> TYPE TABLE.
* Create an internal table (this command works from rel 47)
CREATA DATA MY_TABLE TYPE TABLE OF (P_TABLE).
ASSIGN MY_TABLE->* TO <MY_TABLE>.
* Create a work area
CREATA DATA WA_TABLE TYPE (P_TABLE).
ASSIGN WA_TABLE->* TO <WA_TABLE>.
Max
12-12-2008 1:33 PM
hi, thanx for replying
CREATA DATA MY_TABLE TYPE TABLE OF (P_TABLE).
ASSIGN MY_TABLE->* TO <MY_TABLE>.
Create a work area
CREATA DATA WA_TABLE TYPE (P_TABLE).
ASSIGN WA_TABLE->* TO <WA_TABLE>.
then how to prove if in this p_table has a field called matnr or not?
12-12-2008 2:53 PM
Hi
If yuo need to know if a table has field called MATNR, you don't need to use field-symbols:
PARAMETERS: P_TABLE TYPE DDOBJNAME.
START-OF-SELECTION.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
TABNAME = P_TABLE
FIELDNAME = 'MATNR'
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
WRITE: 'No field called MATNR'.
ELSE.
WRITE: 'Ok field called MATNR'.
ENDIF.
But if you wan to use field-symbols:
PARAMETERS: P_TABLE TYPE DDOBJNAME.
FIELD-SYMBOLS: <WA> TYPE ANY,
<MATNR> TYPE ANY.
DATA: WA TYPE REF TO DATA.
START-OF-SELECTION.
CREATE DATA WA TYPE (P_TABLE).
ASSIGN WA->* TO <WA>.
ASSIGN COMPONENT 'MATNR' OF STRUCTURE <WA> TO <MATNR>.
IF SY-SUBRC = 0.
WRITE: 'Ok field called MATNR'.
ELSE.
WRITE: 'No field called MATNR'.
ENDIF.
Max
12-12-2008 12:34 PM
Hi,
your report contain varying number of columns in the output ?
If yes then only you require dynamic table logic.
Else you can use Case statement or if statement according to the requirement.
If table = CAWN
Check for the fields in the table
if sy-subrc = 0.
Process A.
else.
Process B.
endif.
endif.
Thanks.
12-12-2008 12:59 PM
Hi,
please use the following:
data:i_table_fieldlist like ddfield occurs 0 with header line.
Getting all fields of the specified table in internal table
call function 'DD_NAMETAB_TO_DDFIELDS'
exporting
tabname = <<---- table name
tables
ddfields = i_table_fieldlist.
then do 2 read table i_table_fieldlist with key FIELDNAME = matnr/werks.
Thanks and Regards,
Dev
12-12-2008 1:37 PM
Hi,
FIELD-SYMBOLS:<l_fs_dyn> TYPE ANY.
ASSIGN COMPONENT ls_fcat1-fieldname
OF STRUCTURE <dyn_wa> TO <l_fs_dyn>.
Thanks & Regards,
Krishna...
12-12-2008 1:54 PM
Hi Yunfan,
Maybe a simpler way would be :
parameters p_tab TYPE dd03l-TABNAME .
select count(*)
from dd03l
where TABNAME = p_tab
and fieldname in ('MATNR', 'WERKS').
IF sy-subrc = 0.
write: 'field exists in table', p_tab.
ENDIF.
Thanks and regards,
Dev.