‎2006 Apr 26 11:36 AM - last edited on ‎2024 Feb 04 6:05 AM by postmig_api_4
Hello,
I've got same fields eg. kunnr, erdat and internal table with column names 1001,1002,1003 etc. I would like to make internal table from above values like following:
kunnr,erdat,1001,1002,1003,...
Some of fileds will be from SELECT statement others must be calculated and filled in program. Have anybody idea how to make it? Please send source code if possible.
Regards,
Marcin
‎2006 Apr 26 11:41 AM
YOu can use this syntax:
CREATE DATA <REF> TYPE <TYPE TABLE> TABLE OF <TYPE LINE>
[WITH [UNIQUE|NON-UNIQUE] keydef] [INITIAL SIZE n].
Regards,
Ravi
‎2006 Apr 26 11:41 AM
Marcin,
I am not sure what is dynamic here.
LOOP AT ITAB ASSIGNING <FS>.
Process and calculate
<FS>-1001 = value.
ENDLOOP.
If these fields are dynamic, take a look at weblog
/people/ravikumar.allampallam/blog/2005/05/31/expand-the-list-of-columns-in-a-report-dynamically
This should update the table..
Regards,
Ravi
Note : Please mark the helpful answers
Message was edited by: Ravikumar Allampallam
‎2006 Apr 26 12:44 PM
Ravi,
could you extend your answer by any example. Dynamic means that my dynamic internal table structure ITAB should be build from other internal table values CTAB as columns. CTAB may have field called MATNR and values 1001,1002,1003,... so my ITAB structure should be:
FIELD1, FIELD2,...,1001,1002,1003,....
It can be simple in theory but in practise I need fill first few fields from SELECT and other fields in a lopp.
Regards,
Marcin
‎2006 Apr 26 12:54 PM
Marcin,
I hope you are aware of creating the field catalog manually. So, create a field catalog of type LVC_T_FCAT by appending each field FIELD1, FIELD2, 1001, 1002 .... by giving the other details like DATA TYPE etc.
Once you have the field catalog, use the method CREATE_DYNAMIC_TABLE as shown in the blog and the output will be a internal table with the fields you have appended to the field catalog.
After that appending data to that field will be tricky. Look at ASSIGN COMPONENT xxx OF STRUCTURE .... USING which you will be to update data. If you can clearly tell me the strcuture of the table where the data is and explain in more detail, I can try giving you a psuedo code.
Regards,
Ravi
Note :Please mark all the helpful answers
‎2006 Apr 26 12:56 PM
Hi Marcin,
Please check the below code. In this I am getting
fields from some table and taking then as columns
for other table.
REPORT ZSIRI_TABLES1 .
* Selection screen
PARAMETER P_TAB LIKE DD03L-TABNAME.
DATA : BEGIN OF I_FIELDS OCCURS 0,
NAME LIKE DD03L-FIELDNAME,
POS LIKE DD03L-POSITION,
LEN LIKE DD03L-INTLEN,
DATATYPE LIKE DD03L-DATATYPE,
END OF I_FIELDS.
FIELD-SYMBOLS : <F_FS> TYPE TABLE,
<F_FS1> TYPE TABLE,
<F_FS2> TYPE ANY,
<F_FS3> TYPE TABLE,
<F_FS4> TYPE ANY.
DATA: D_REF TYPE REF TO DATA ,
D_REF2 TYPE REF TO DATA ,
D_REF3 TYPE REF TO DATA,
I_ALV_CAT TYPE TABLE OF LVC_S_FCAT ,
LS_ALV_CAT LIKE LINE OF I_ALV_CAT .
* get the fields of the table
SELECT DISTINCT FIELDNAME POSITION INTLEN
FROM DD03L
INTO TABLE I_FIELDS
WHERE TABNAME = P_TAB.
SORT I_FIELDS BY POS.
LOOP AT I_FIELDS.
LS_ALV_CAT-FIELDNAME = I_FIELDS-NAME.
LS_ALV_CAT-INTTYPE = I_FIELDS-DATATYPE.
LS_ALV_CAT-OUTPUTLEN = I_FIELDS-LEN.
LS_ALV_CAT-SELTEXT = I_FIELDS-NAME.
APPEND LS_ALV_CAT TO I_ALV_CAT.
ENDLOOP.
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>.
* get data from the table and insert into simultaneous rows.
SELECT * FROM (P_TAB) INTO TABLE <F_FS>.
* perform get_fields.
* endselect.
IF SY-SUBRC = 0.
ENDIF.
*
Hope this will help you.Pls let me know if you need more info.
Thanks&Regards,
Siri.
‎2006 Apr 26 11:42 AM
‎2006 Apr 26 12:16 PM
Hi,
Please go through the link below. It will surely help you.
<a href="http://www.sapfans.com/forums/viewtopic.php?p=107594">http://www.sapfans.com/forums/viewtopic.php?p=107594</a>
Please makr helpful answers.
Regards,
Amit Mishra
‎2006 Apr 26 12:42 PM
Hi marcin,
1. I've got same fields eg. kunnr, erdat and internal table with column names 1001,1002,1003 etc
For this purpose,
in my program,
there is an INDEPENDENT FORM
whose inputs are FIELD LIST
and from those, it consructs dynamic table.
2. Here is the program.
the dynamic table name will be
<DYNTABLE>.
3. U can use this program (FORM in this program)
to generate any kind of internal table
by specifying some inputs (ie. field list)
4.
REPORT abc.
*----
COMPULSORY
FIELD-SYMBOLS: <dyntable> TYPE ANY TABLE.
FIELD-SYMBOLS: <dynline> TYPE ANY.
DATA: lt TYPE lvc_t_fcat.
DATA: ls TYPE lvc_s_fcat.
FIELD-SYMBOLS: <fld> TYPE ANY.
DATA : fldname(50) TYPE c.
*----
PARAMETERS : infty(4) TYPE c OBLIGATORY.
DATA : iname LIKE dd02l-tabname.
START-OF-SELECTION.
*----
GET INFO
CONCATENATE 'P' infty INTO iname.
DATA : ddfields LIKE ddfield OCCURS 0 WITH HEADER LINE.
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = iname
TABLES
ddfields = ddfields.
.
*----
CONSTRUCT FIELD LIST
LOOP AT ddfields.
ls-fieldname = ddfields-fieldname.
APPEND ls TO lt.
ENDLOOP.
*----
PERFORM
PERFORM mydyntable USING lt.
BREAK-POINT.
*----
INDEPENDENT FORM
*----
FORM mydyntable USING lt TYPE lvc_t_fcat .
*----
Create Dyn Table From FC
FIELD-SYMBOLS: <fs_data> TYPE REF TO data.
FIELD-SYMBOLS: <fs_1>.
FIELD-SYMBOLS: <fs_2> TYPE ANY TABLE.
DATA: lt_data TYPE REF TO data.
ASSIGN lt_data TO <fs_data>.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt
IMPORTING
ep_table = <fs_data>
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
IF sy-subrc <> 0.
ENDIF.
*----
Assign Dyn Table To Field Sumbol
ASSIGN <fs_data>->* TO <fs_1>.
ASSIGN <fs_1> TO <fs_2>.
ASSIGN <fs_1> TO <dyntable>.
ENDFORM. "MYDYNTABLE
regards,
amit m.