2008 Dec 09 11:56 AM
Hi,
i create an internal table like this:
FIELD-SYMBOLS: <GT_ITAB> TYPE TABLE,
<GS_ITAB>,
<FS>.
*
DATA: GT_DATA TYPE REF TO DATA.
DATA: GS_DATA TYPE REF TO DATA.
*
DATA: TABNAME LIKE DD03L-TABNAME.
DATA: FIELDNAME LIKE DD03L-FIELDNAME.
DATA: TBFDNAM TYPE TBFDNAM VALUE 'LFA1-NAME1'.
*
SPLIT TBFDNAM AT '-' INTO TABNAME FIELDNAME.
*
CREATE DATA GT_DATA TYPE TABLE OF (TABNAME).
ASSIGN GT_DATA->* TO <GT_ITAB>.
CREATE DATA GS_DATA LIKE LINE OF <GT_ITAB>.
ASSIGN GS_DATA->* TO <GS_ITAB>.
SELECT * FROM (TABNAME) INTO CORRESPONDING FIELDS OF TABLE <GT_ITAB>.
*
BREAK-POINT.
*
it works OK.
Now i want to create an internal table not like LFA1 but with LFA1-NAME1 Field TBFDNAM.
It's not only LFA1-NAME1 it shell be the value of TBFDNAM.
When i change
CREATE DATA GT_DATA TYPE TABLE OF (TABNAME).
to
CREATE DATA GT_DATA TYPE TABLE OF ( TBFDNAM).
i get an shortdump.
Any idea?
Regards, Dieter
Hi,
i create an internal table like this:
FIELD-SYMBOLS: <GT_ITAB> TYPE TABLE,
<GS_ITAB>,
<FS>.
*
DATA: GT_DATA TYPE REF TO DATA.
DATA: GS_DATA TYPE REF TO DATA.
*
DATA: TABNAME LIKE DD03L-TABNAME.
DATA: FIELDNAME LIKE DD03L-FIELDNAME.
DATA: TBFDNAM TYPE TBFDNAM VALUE 'LFA1-NAME1'.
*
SPLIT TBFDNAM AT '-' INTO TABNAME FIELDNAME.
*
CREATE DATA GT_DATA TYPE TABLE OF (TABNAME).
ASSIGN GT_DATA->* TO <GT_ITAB>.
CREATE DATA GS_DATA LIKE LINE OF <GT_ITAB>.
ASSIGN GS_DATA->* TO <GS_ITAB>.
SELECT * FROM (TABNAME) INTO CORRESPONDING FIELDS OF TABLE <GT_ITAB>.
*
BREAK-POINT.
*
it works OK.
Now i want to create an internal table not like LFA1 but with LFA1-NAME1 Field TBFDNAM.
It's not only LFA1-NAME1 it shell be the value of TBFDNAM.
When i change
CREATE DATA GT_DATA TYPE TABLE OF (TABNAME).
to
CREATE DATA GT_DATA TYPE TABLE OF ( TBFDNAM).
i get an shortdump.
Any idea?
Regards, Dieter
2008 Dec 09 12:24 PM
Hi Dieter,
If i understood your requirement, your trying to build the dynamic itab for the specified fields of the table instead of whole table.
for this, u take the values of the TBFDNAM into itab,, just like this
DATA: BEGIN OF ITAB,
WORD(30),
END OF ITAB.
SPLIT TBFDNAM AT '-' INTO TABNAME ITAB.
thanks
Mahesh
2008 Dec 09 12:42 PM
Hi Dieter,
This code for sure will give dump,
Because TBFDNAM (i.e. actually refering to say field NAME1) has got no existence without LFA1.
Your requirement is to create an internal table with the DATA ELEMENT of TBFDNAM which is NAME1_GP.
So try getting the details about the field and then use the code to create internal table:
Somewhat like this:
FM TO get the name of the data element say 'NAME1_GP' (Sorry I dont remember the FM name. But I am sure there is one)
and then use:
CREATE DATA GT_DATA TYPE TABLE OF ('NAME1_GP').
ASSIGN GT_DATA->* TO <GT_ITAB>.
CREATE DATA GS_DATA LIKE LINE OF <GT_ITAB>.
ASSIGN GS_DATA->* TO <GS_ITAB>.
Hope this works.
Cheers,
Prakash Pandey
2008 Dec 09 2:21 PM
Hi Dieter,
Your approach is ok, but it will create dynamic table without a structure of NAME1. Only the line type will be suitable (but field name will not exists -> hence the error in the select statement).
In this case you need to create a dynamic table which structure consists of one field named NAME1.
This code is the appropriate one:
" your definitions
DATA: tabname LIKE dd03l-tabname.
DATA: fieldname LIKE dd03l-fieldname.
DATA: tbfdnam TYPE tbfdnam VALUE 'LFA1-NAME1'.
FIELD-SYMBOLS <gt_itab> TYPE table.
"new ones
DATA: it_fcat TYPE lvc_t_fcat WITH HEADER LINE.
DATA: gt_itab TYPE REF TO data.
" get table and fieldname
SPLIT tbfdnam AT '-' INTO tabname fieldname.
" create dynamic table with structure NAME1 (only one field)
it_fcat-fieldname = fieldname.
it_fcat-tabname = tabname.
APPEND it_fcat.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fcat[]
IMPORTING
ep_table = gt_itab
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
CHECK sy-subrc = 0.
" dereference table
ASSIGN gt_itab->* TO <gt_itab>.
" insert data only to NAME1 field
SELECT * FROM (tabname) INTO CORRESPONDING FIELDS OF TABLE <gt_itab>.
I checked, this works fine:)
Regards
Marcin