Question on Dynamic Internal Table creation
Good day everyone.
I would like to ask if it is possible to just add several fields to an existing internal table to make it dynamic? if possible, does anyone have a sample program? thanks a lot!
Hi Christian,
Refer the following code. It may help you.
Reward points if it helps.
REPORT ZDSAP .
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 .
parameter: p_tablen type tabname.
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 TABLE.
REFRESH itab.
CALL FUNCTION 'NAMETAB_GET'
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.
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>.
SELECT * FROM (p_tablen) INTO CORRESPONDING FIELDS OF TABLE <F_FS>.
LOOP AT <F_FS> ASSIGNING <F_FS2>.
*your code goes here.
ENDLOOP.
Similar Messages
-
Dynamic Internal Table creation and population
Hi gurus !
my issue refers to the slide 10 provided in this slideshow : https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/b332e090-0201-0010-bdbd-b735e96fe0ae
My example is gonna sound dumb, but anyway: I want to dynamically select from a table into a dynamically created itab.
Letu2019s use only EKPO, and only field MENGE.
For this, I use Classes cl_abap_elemdescr, cl_sql_result_set and the Data Ref for table creation. But while fetching the resultset, program dumps when fields like MENGE, WRBTR are accessed. Obviously their type are not correctly taken into account by my program.
Here it comes:
DATA: element_ref TYPE REF TO cl_abap_elemdescr,
vl_fieldname TYPE string,
tl_components TYPE abap_component_tab,
sl_components LIKE LINE OF tl_components_alv,
linetype_lcl TYPE REF TO cl_abap_structdescr,
ty_table_type TYPE REF TO cl_abap_tabledescr,
g_resultset TYPE REF TO cl_sql_result_set
u2026
CONCATENATE sg_columns-table_name '-' sg_columns-column_name INTO vl_fieldname.
* sg_columns-table_name contains 'EKPO'
* sg_columns-column_name contains 'MENGE'
* getting the element as a component
element_ref ?= cl_abap_elemdescr=>describe_by_name( vl_fieldname ).
sl_components-name = sg_columns-column_name.
sl_components-type ?= element_ref.
APPEND sl_components TO tl_components.
* dynamic creation of internal table
linetype_lcl = cl_abap_structdescr=>create( tl_components ).
ty_table_type = cl_abap_tabledescr=>create(
p_line_type = linetype_lcl ).
u2026
* Then I will create my field symbol table and line. Code has been cut here.
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
u2026
* Then I will execute my query. Here itu2019s: Select MENGE From EKPO Where Rownum = 1.
g_resultset = g_stmt_ref->execute_query( stmt_str ).
* Then structure for the Resultset is set
CALL METHOD g_resultset->set_param_struct
EXPORTING
struct_ref = dy_line.
* Fetching the lines of the resultset => Dumpu2026
WHILE g_resultset->next( ) > 0.
ASSIGN dy_line->* TO <dyn_wa>.
APPEND <dyn_wa> TO <dyn_table>.
ENDWHILE.
Anyone has any clue to how prevent my Dump ??
The component for MENGE seems to be described as a P7 with 2 decimals. And the resultset wanna use a QUAN type... or something like that !Hello
I have expanded your sample coding for selecting three fields out of EKPO:
*& Report ZUS_SDN_SQL_RESULT_SET
*& Thread: Dynamic Internal Table creation and population
*& <a class="jive_macro jive_macro_thread" href="" __jive_macro_name="thread" modifiedtitle="true" __default_attr="1375510"></a>
*& NOTE: Coding for dynamic structure / itab creation taken from:
*& Creating Flat and Complex Internal Tables Dynamically using RTTI
*& https://wiki.sdn.sap.com/wiki/display/Snippets/Creating+Flat+and+
*& Complex+Internal+Tables+Dynamically+using+RTTI
REPORT zus_sdn_sql_result_set.
TYPE-POOLS: abap.
DATA:
go_sql_stmt TYPE REF TO cl_sql_statement,
go_resultset TYPE REF TO cl_sql_result_set,
gd_sql_clause TYPE string.
DATA:
gd_tabfield TYPE string,
go_table TYPE REF TO cl_salv_table,
go_sdescr_new TYPE REF TO cl_abap_structdescr,
go_tdescr TYPE REF TO cl_abap_tabledescr,
gdo_handle TYPE REF TO data,
gdo_record TYPE REF TO data,
gs_comp TYPE abap_componentdescr,
gt_components TYPE abap_component_tab.
FIELD-SYMBOLS:
<gs_record> TYPE ANY,
<gt_itab> TYPE STANDARD TABLE.
START-OF-SELECTION.
continued. -
DYNAMIC INTERNAL TABLE CREATION BASED ON THE CONTENT OF ANOTHER INTERNAL TA
Hi All
I need to create an internal table at runtime.
I have a selection screen parameter which is specific to country, Which can take values below
eg:- IT_AREA for Italy(IT)
FR_AREA for France(FR)
IE_AREA for Ireland(IE).....And similary for other countries
Based on the Above parameter, I need to create Internal Table as below
DATA: itab TYPE italy_data Occurs 0.
If I declare as above, Then itab has fields from italy_data. And this internal table i will be sending it to Function Module to get data into it.
My Requirement is to Create the Internal table itab during runtime for tables italy_data OR france_data OR ireland_data based on selection screen parameter. Tables on Country may have different number of fields in it.
Can anyone help me on this??Hi,
Here is a sample code to create a dynamic internal table.
REPORT ytrab03.
TABLES: mara, makt.
TYPE-POOLS: slis.
DATA: it_fcat TYPE slis_t_fieldcat_alv,
is_fcat LIKE LINE OF it_fcat,
ls_layout TYPE slis_layout_alv.
DATA: it_fieldcat TYPE lvc_t_fcat,
is_fieldcat LIKE LINE OF it_fieldcat.
DATA: new_table TYPE REF TO data,
new_line TYPE REF TO data,
ob_cont_alv TYPE REF TO cl_gui_custom_container,
ob_alv TYPE REF TO cl_gui_alv_grid,
vg_campos(255) TYPE c,
i_campos LIKE TABLE OF vg_campos,
vg_campo(30) TYPE c,
vg_tables(60) TYPE c.
DATA: e_params LIKE zutsvga_alv_01.
FIELD-SYMBOLS: <l_table> TYPE table,
<l_line> TYPE ANY,
<l_field> TYPE ANY.
PARAMETERS: p_max(2) TYPE n DEFAULT '20' OBLIGATORY.
is_fcat-fieldname = 'COL01'.
is_fcat-ref_fieldname = 'MATNR'.
is_fcat-ref_tabname = 'MARA'.
APPEND is_fcat TO it_fcat.
is_fcat-fieldname = 'COL02'.
is_fcat-ref_fieldname = 'MAKTX'.
is_fcat-ref_tabname = 'MAKT'.
APPEND is_fcat TO it_fcat.
LOOP AT it_fcat INTO is_fcat.
is_fieldcat-fieldname = is_fcat-fieldname.
is_fieldcat-ref_field = is_fcat-ref_fieldname.
is_fieldcat-ref_table = is_fcat-ref_tabname.
APPEND is_fieldcat TO it_fieldcat.
CONCATENATE is_fieldcat-ref_table is_fieldcat-ref_field
INTO vg_campos SEPARATED BY '~'.
APPEND vg_campos TO i_campos.
ENDLOOP.
*... Create the dynamic internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = new_table.
*... Create a new line
ASSIGN new_table->* TO <l_table>.
CREATE DATA new_line LIKE LINE OF <l_table>.
ASSIGN new_line->* TO <l_line>.
SELECT (i_campos) FROM mara INNER JOIN makt
ON mara~matnr = makt~matnr
UP TO p_max ROWS
INTO TABLE <l_table>.
LOOP AT <l_table> INTO <l_line>.
LOOP AT it_fcat INTO is_fcat.
ASSIGN COMPONENT is_fcat-fieldname
OF STRUCTURE <l_line> TO <l_field>.
IF sy-tabix = 1.
WRITE: /2 <l_field>.
ELSE.
WRITE: <l_field>.
ENDIF.
ENDLOOP.
ENDLOOP.
Regards,
Karuna. -
Dynamic Internal Table creation in SAP version 4.5B
Hi All,
Can anybody please let me know if it is possible to create dynamic internal table in SAP version 4.5 B.
If yes will be of great help if somebody can give the method of doing it or any sample code to follow.
Thanks in advance!!!Hi
Refer this wiki [http://wiki.sdn.sap.com/wiki/display/ABAP/DynamicInternaltable]
Regards
Raj -
Dynamic internal table and dynamic field catalog
hi
i need to decide the number of fields of the internal table at runtime
and then need to pass value to this internal table.
then i need to create the field catalog for this internal table (so here
field catalog is also dynamic) to display in alv.
how to achieve this dynamic internal table creation and dyanmic field catalog generationHi Ajay,
U can use the below code to create a dynamic internal table.
*adding the field names only once for the dynamic table .
MOVE 'PRCTR' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'RCNTR' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'RACCT' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'RYEAR' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'YTDBAL' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
MOVE 'OBAL' TO gw_component-name.
gw_component-type ?= cl_abap_elemdescr=>get_string( ).
INSERT gw_component INTO TABLE gt_components.
*get structure descriptor -> GR_STRUCTDESCR
gr_structdescr ?= cl_abap_structdescr=>create( gt_components ).
create work area of structure GR_STRUCTDESCR -> GR_WA
CREATE DATA gr_wa TYPE HANDLE gr_structdescr.
ASSIGN gr_wa->* TO <gw_wa>.
determine key components -> GT_KEYS
MOVE lv_value1 TO gw_key-name.
INSERT gw_key INTO TABLE gt_keys.
create descriptor for internal table -> GR_TABLEDESCR
gr_tabledescr ?= cl_abap_tabledescr=>create( p_line_type = gr_structdescr
p_table_kind = cl_abap_tabledescr=>tablekind_hashed
p_unique = abap_true
p_key = gt_keys
p_key_kind = cl_abap_tabledescr=>keydefkind_user ).
create internal table -> GR_ITAB
CREATE DATA gr_itab TYPE HANDLE gr_tabledescr.
ASSIGN gr_itab->* TO <gt_itab>.
CREATE DATA gr_itab LIKE STANDARD TABLE OF <gw_wa>.
ASSIGN gr_itab->* TO <gt_sttab>.
Now u r internal table named <gt_sttab> has been created with fields like RCNTR, PRCTR,RACCT, RYEAR etc whatever the field u need u can go ahead and create dynamically.
then by using the table <gt_sttab> u can create u r field catalog.
Regards,
Rose. -
Dynamic internal table with problem
Hi,
I have developed a program to update standard table. I am using dynamic internal table creation concept. But my dynamic internal table is having width only 1200 bytes. But many standard tables have more than that width. Do you have any input create dynamic internal table with more than 1200 bytes width..
Have a look at the error.
[http://3.bp.blogspot.com/_O5f8iAlgdNQ/SjYXTBpO92I/AAAAAAAAErI/Fs996_APHbE/s1600-h/error-792463.JPG|http://3.bp.blogspot.com/_O5f8iAlgdNQ/SjYXTBpO92I/AAAAAAAAErI/Fs996_APHbE/s1600-h/error-792463.JPG]
Expecting reply
Thanks
VenkatHi,
DATA: IT_TABSTRUC TYPE STANDARD TABLE OF DFIES INITIAL SIZE 0,
V_REF TYPE REF TO DATA,
V_I_AVL_CAT TYPE TABLE OF LVC_S_FCAT.
FIELD-SYMBOLS : <F_FS_DATA> TYPE STANDARD TABLE.
SELECTION-SCREEN:BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001
NO INTERVALS.
PARAMETERS: P_TABNAM TYPE X_TABNAME.
SELECTION-SCREEN:END OF BLOCK B1.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
TABNAME = p_tabnam
LANGU = SY-LANGU
TABLES
DFIES_TAB = IT_TABSTRUC
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3.
LOOP AT IT_TABSTRUC .
V_LS_AVL_CAT-FIELDNAME = IT_TABSTRUC -FIELDNAME.
V_LS_AVL_CAT-REF_TABLE = P_TABNAM.
V_LS_AVL_CAT-REF_FIELD = IT_TABSTRUC -FIELDNAME.
APPEND V_LS_AVL_CAT TO V_I_AVL_CAT.
ENDLOOP.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = V_I_AVL_CAT
IMPORTING
EP_TABLE = V_REF.
ASSIGN V_REF->* TO <F_FS_DATA>.
FREE V_REF.
SELECT * FROM (P_TABNAM) INTO CORRESPONDING
FIELDS OF TABLE <F_FS_DATA> .
Hope this resolves ur probs.... -
Creation of dynamic internal table is not synchronous
In my code following lines are used to create a dynamic table.
REFRESH : INCTABL .
CLEAR INCTABL .
INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.
INCTABL-LINE = 'zpltnamec like zvendplt-zpltnamec,'. APPEND INCTABL.
INCTABL-LINE = 'sourcing like zopsdwbom-sourcing,'. APPEND INCTABL.
INCTABL-LINE = 'zmatgrp like zrmrpmaterial-zmatgrp,'. APPEND INCTABL.
INCTABL-LINE = 'zcollection like zrmrpmaterial-zcollection,'.
APPEND INCTABL.
INCTABL-LINE = 'fiscintrodt like zrmrpmaterial-zfiscintrodt,'.
APPEND INCTABL.
INCTABL-LINE = 'bednr like ekpo-bednr,'. APPEND INCTABL.
INCTABL-LINE = 'revlv like ekpo-revlv,'. APPEND INCTABL.
INCTABL-LINE = 'ematn like ekpo-ematn,'. APPEND INCTABL.
INCTABL-LINE = 'menge like mara-eannr,'. APPEND INCTABL.
INCTABL-LINE = 'stprs like mara-eannr,'. APPEND INCTABL.
*inctabl-line = 'kbetr like cdred-f_new,'. append inctabl.
DATA : T_KBETR(72) .
DATA :CNT(2).
DO LIN TIMES .
CNT = SY-INDEX .
CONCATENATE 'kbetr' CNT ' like cdred-f_new,' INTO T_KBETR .
CONDENSE T_KBETR .
INCTABL-LINE = T_KBETR . APPEND INCTABL.
ENDDO .
INCTABL-LINE = 'end of dyntab. '. APPEND INCTABL.
INSERT REPORT 'zcrchangereport_3'(001) FROM INCTABL.
but during run time it is using the previously created dynamic internal table structure and then creating currently required internal table.
how to overcome this problem/
Thanks.Hello,
Instead of creating report, create subroutine pool. Like
INCTABL-LINE = 'report ztest.'. APPEND INCTABL.
INCTABL-LINE = 'form main'. APPEND INCTABL.
INCTABL-LINE = 'data: begin of dyntab occurs 10,'. APPEND INCTABL.
INCTABL-LINE = 'zpltnamec like zvendplt-zpltnamec.'. APPEND INCTABL.
INCTABL-LINE = 'data: end of dyntab.'. APPEND INCTABL.
CATCH SYSTEM-EXCEPTIONS GENERATE_SUBPOOL_DIR_FULL = 9.
GENERATE SUBROUTINE POOL inctabl NAME l_name
MESSAGE L_MESSAGE LINE L_LINE WORD L_WORD.
ENDCATCH.
IF L_MESSAGE IS INITIAL.
PERFORM (L_FORM) IN PROGRAM (L_NAME).
ELSE.
WRITE : L_MESSAGE, L_LINE.
ENDIF.
You can get the message in L_message variable, if any error occurs.
Regards,
Naimesh -
Reg: Creation of Dynamic Internal table
Hi All,
I got a requirement which should be handled by creating dynamic internal table.
*Scenario: *
1.First I will fetch data from one table into an internal table.
Let suppose I am fetching the fieldnames of the table MAKT from DD03l. Then I will having following records in my internal table.
MANDT
MATNR
SPRAS
MAKTX
MAKTG
2.Now I need to download these fields into an excel file with same field names as headings as shown below
| MANDT | MATNR | SPRAS | MAKTX | MAKTG |
3.Later User will enter data for all those fields in the downloaded excel file and again upload the file. Here I need to create dynamic internal table because the table name is dynamic. Based on the table name, field names will be varying..
Please provide me solution for the above..
Thanks,
RaveeHi
U can try something like this:
TYPES: TY_LINE TYPE STRING.
PARAMETERS: P_TABLE TYPE DDOBJNAME.
DATA: DYN_TAB TYPE REF TO DATA.
FIELD-SYMBOLS: <FS_TAB> TYPE TABLE,
<FS_WA> TYPE ANY,
<FS_FIELD> TYPE ANY.
DATA: DFIES_TAB TYPE TABLE OF DFIES WITH HEADER LINE.
DATA: W_LINE(10000) TYPE C.
DATA: V_OFFSET TYPE I.
DATA: LAST_FIELD.
START-OF-SELECTION.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
TABNAME = P_TABLE
TABLES
DFIES_TAB = DFIES_TAB
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
MESSAGE I208(00) WITH 'No table'.
STOP.
ENDIF.
* Create internal table
CREATE DATA DYN_TAB TYPE TABLE OF (P_TABLE).
ASSIGN DYN_TAB->* TO <FS_TAB>.
* Create Header
LOOP AT DFIES_TAB.
* Insert field name
MOVE DFIES_TAB-FIELDNAME TO W_LINE+V_OFFSET.
V_OFFSET = V_OFFSET + 30.
AT LAST.
LAST_FIELD = 'X'.
ENDAT.
CHECK LAST_FIELD IS INITIAL.
* Insert separator
MOVE ';' TO W_LINE+V_OFFSET.
V_OFFSET = V_OFFSET + 1.
ENDLOOP.
CONDENSE W_LINE NO-GAPS.
WRITE W_LINE.
* Get DATA
SELECT * FROM (P_TABLE) INTO TABLE <FS_TAB>.
LOOP AT <FS_TAB> ASSIGNING <FS_WA>.
CLEAR LAST_FIELD.
CLEAR V_OFFSET.
CLEAR W_LINE.
LOOP AT DFIES_TAB.
AT LAST.
LAST_FIELD = 'X'.
ENDAT.
ASSIGN COMPONENT DFIES_TAB-FIELDNAME
OF STRUCTURE <FS_WA> TO <FS_FIELD>.
* Insert value
MOVE <FS_FIELD> TO W_LINE+V_OFFSET(DFIES_TAB-INTLEN).
V_OFFSET = V_OFFSET + DFIES_TAB-INTLEN.
* Insert separator
MOVE ';' TO W_LINE+V_OFFSET.
V_OFFSET = V_OFFSET + 1.
ENDLOOP.
CONDENSE W_LINE NO-GAPS.
WRITE: / W_LINE.
ENDLOOP.
In your case u can append the workarea W_LINE to an internal table and then download it as CSV file.
Max -
How to create Dynamic internal table with columns also created dynamically.
Hi All,
Any info on how to create a dynamic internal table along with columns(fields) also to be created dynamically.
My requirement is ..On the selection screen I enter the number of fields to be in the internal table which gets created dynamically.
I had gone thru some posts on dynamic table creation,but could'nt find any on the dynamic field creation.
Any suggestions pls?
Thanks
NaraI don't understand ...
something like that ?
* Form P_MODIFY_HEADER. *
form p_modify_header.
data : is_fieldcatalog type lvc_s_fcat ,
v_count(2) type n ,
v_date type d ,
v_buff(30).
* Update the fieldcatalog.
loop at it_fieldcatalog into is_fieldcatalog.
check is_fieldcatalog-fieldname+0(3) eq 'ABS' or
is_fieldcatalog-fieldname+0(3) eq 'VAL' .
move : is_fieldcatalog-fieldname+3(2) to v_count ,
p_perb2+5(2) to v_date+4(2) ,
p_perb2+0(4) to v_date+0(4) ,
'01' to v_date+6(2) .
v_count = v_count - 1.
call function 'RE_ADD_MONTH_TO_DATE'
exporting
months = v_count
olddate = v_date
importing
newdate = v_date.
if is_fieldcatalog-fieldname+0(3) eq 'ABS'.
concatenate 'Quantité 0'
v_date+4(2)
v_date+0(4)
into v_buff.
else.
concatenate 'Montant 0'
v_date+4(2)
v_date+0(4)
into v_buff.
endif.
move : v_buff to is_fieldcatalog-scrtext_s ,
v_buff to is_fieldcatalog-scrtext_m ,
v_buff to is_fieldcatalog-scrtext_l ,
v_buff to is_fieldcatalog-reptext .
modify it_fieldcatalog from is_fieldcatalog.
endloop.
* Modify the fieldcatalog.
call method obj_grid->set_frontend_fieldcatalog
exporting it_fieldcatalog = it_fieldcatalog.
* Refresh the display of the grid.
call method obj_grid->refresh_table_display.
endform. " P_MODIFY_HEADER -
Need information on Dynamic internal table
Hi All,
I need some information on dynamic internal table.
I want what are the field names and the values in dynamic internal table.
Is there any function module, which tells us the field names and values of corresponding fields from a dynamic internal table ?
Thank you very much in advance.Hi,
Program to display/edit database tables dynamically.
REPORT zdyn_table_display.
PARAMETERS: p_table TYPE tabname OBLIGATORY,
p_rows TYPE I.
* Creation of dynamic internal table
DATA: lv_dref TYPE REF TO data.
FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE.
DATA: lv_table TYPE string.
START-OF-SELECTION.
* Dynamic internal table.
CREATE DATA lv_dref TYPE TABLE OF (p_table).
ASSIGN lv_dref->* TO <fs_table>.
IF sy-subrc EQ 0.
* EXIT.
ENDIF.
data i type i.
* Get the data
SELECT *
FROM (p_table)
UP TO p_rows ROWS
INTO TABLE <fs_table>.
CONCATENATE 'Table contents : ' p_table INTO lv_table.
* display the table control.
CALL FUNCTION 'STC1_FULLSCREEN_TABLE_CONTROL'
EXPORTING
header = lv_table
tabname = p_table
no_button = space
TABLES
table = <fs_table>
EXCEPTIONS
no_more_tables = 1
too_many_fields = 2
nametab_not_valid = 3
handle_not_valid = 4
OTHERS = 5.
IF sy-subrc EQ 0.
EXIT.
ENDIF.
Getting internal table definition
Try this...
DATA : l_descr_ref TYPE REF TO cl_abap_structdescr.
l_descr_ref ?= cl_abap_typedescr=>describe_by_data( itab ).
Now l_descr_ref->components holds the entire list of fields in itab.
Thanks & Regards,
ShreeMohan -
How to populate field catalogue fields in ALV using dynamic internal table
Hi All,
Please let me know how to populate field catalogue fields in ALV using dynamic internal table.
I have created <dyn_table> using code below.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = g_t_ifc
it_fieldcatalog = g_t_fieldcat
IMPORTING
ep_table = dy_table.
ASSIGN dy_table->* TO <dyn_table>.
Create dynamic work area and assign to FS
CREATE DATA dy_line LIKE LINE OF <dyn_table>.
ASSIGN dy_line->* TO <dyn_wa>.
Now this <dyn_table> has fields like idoc no.,creation date ,
segment field 1, segment field 2 etc..Now idoc no.,creation date are static fields from table EDIDC. And segment field 1, segment field 2 etc are dynamic fields from table EDSAPPL.
In my ALV report I am getting the final layout properly but I am unable to move values to corresponding fields in the final layout shown.Please let me know how to populate these fields from different tables.
I tried this way but its not working.
SORT g_t_edid4 BY docnum.
LOOP AT g_t_edidc INTO g_r_edidc.
READ TABLE g_t_edid4 into g_r_edid4
WITH KEY docnum = g_r_edidc-docnum
BINARY SEARCH.
IF sy-subrc = 0.
<dyn_wa> = g_r_edid4-sdata.
MOVE-CORRESPONDING g_r_edid4 to <dyn_wa>.
CLEAR g_r_edid4.
ENDIF.
MOVE-CORRESPONDING g_r_edidc to <dyn_wa>.
APPEND <dyn_wa> TO <dyn_table>.You have to assign each field to field symbol and then assign the value to that field symbol and asssign that field symbol to workarea field symbol.
LOOP AT g_t_edidc INTO g_r_edidc.
READ TABLE g_t_edid4 into g_r_edid4
WITH KEY docnum = g_r_edidc-docnum
BINARY SEARCH.
IF sy-subrc = 0.
ASSIGN COMPONENT 'SDATA' OF STRUCTURE <DYN_WA> TO <DYN_FLD>.
<DYN_FLD> = g_r_edid4-sdata.
" <dyn_wa> = g_r_edid4-sdata.
" Assign each fields like this.
" MOVE-CORRESPONDING g_r_edid4 to <dyn_wa>.
CLEAR g_r_edid4.
ENDIF.
" MOVE-CORRESPONDING g_r_edidc to <dyn_wa>.
APPEND <dyn_wa> TO <dyn_table>.
Regards,
Naimesh Patel -
How 2 create dynamic internal table and can we pass it to gui_download FM
HI all,
How can we create a dynamic internal table?
I have a requirement where i have to create an internal table with the no. of fields depending on the selection screen values, i think tat can be possible though dynamic creation only.
How to solve this issue..?Pointers will be very much useful..
Thanks
Sunny.hi
Follow the code it will help you out....
REPORT YUSMM_TEXT2 .
*TABLES
TABLES: MARA, " General Material Data
MAKT, " Material Descriptions
T002. " Language Keys
* GLOBAL TYPE-POOL
TYPE-POOLS : SLIS.
* GLOBAL TYPES
TYPES: BEGIN OF TP_LANG ,
SPRAS LIKE T002-SPRAS,
LAISO LIKE T002-LAISO,
SRNO(3) TYPE N,
END OF TP_LANG.
TYPES: BEGIN OF TP_MATNR,
MATNR LIKE MARA-MATNR,
BEGRU LIKE MARA-BEGRU,
END OF TP_MATNR.
* DECLARATION FOR GLOBAL INTERNAL TABLES (WITH INCLUDE STRUCTURE)
DATA:GT_MAKT TYPE STANDARD TABLE OF MAKT, "Materialkurztexte,
GT_THEAD TYPE STANDARD TABLE OF THEAD, "SAPscript: Text-Header,
GT_LINETAB TYPE STANDARD TABLE OF TLINE, "SAPscript: Text-Zeilen,
GT_T002 TYPE STANDARD TABLE OF T002. "Language key
DATA: BEGIN OF GV_TEXT_OUTPUT_LINE,
MATNR LIKE MARA-MATNR,
BEGRU LIKE MARA-BEGRU,
MAKTX LIKE MAKT-MAKTX,
LTXT40(1250) TYPE C,
SRNO(3) TYPE N,
SPRAS LIKE T002-SPRAS,
END OF GV_TEXT_OUTPUT_LINE.
DATA: GT_MATNR TYPE STANDARD TABLE OF TP_MATNR,
WA_GT_MATNR TYPE TP_MATNR.
DATA: GT_LANG TYPE STANDARD TABLE OF TP_LANG,
WA_GT_LANG TYPE TP_LANG.
DATA: GT_TEXT_OUTPUT_LINE LIKE STANDARD TABLE OF GV_TEXT_OUTPUT_LINE,
GT_FIELDCAT TYPE SLIS_T_FIELDCAT_ALV,
GV_FIELDCAT LIKE LINE OF GT_FIELDCAT,
CT_GT_FIELDCAT_IN LIKE GV_FIELDCAT,
GS_LAYOUT TYPE SLIS_LAYOUT_ALV,
GV_REPID TYPE SY-REPID.
DATA: BEGIN OF GV,
FORMER_ERROR LIKE SY-MARKY, " Fehlermeldung bereits
FILE_OPEN(1), " Flag open file
REC_LENGTH TYPE I, " record length
MATNR TYPE MARA-MATNR, " material
REPID TYPE SYST-REPID,
RETCO TYPE SY-SUBRC,
END OF GV.
DATA: GV_MAKT TYPE MAKT,
GV_T002 TYPE T002,
GV_LANGU TYPE THEAD-TDSPRAS.
* DECLARATION FOR FIELD-SYMBOLS
FIELD-SYMBOLS: <FS_DATA> TYPE REF TO DATA,
<FS_DATA1> TYPE REF TO DATA,
<FS_2> TYPE STANDARD TABLE,
<FS_22> TYPE STANDARD TABLE,
<FS_1>,
<FS_11>,
<F>,
<FA>,
<LWA_LINE_WA>,
<LWA_LINE_WA1>.
DATA: IT_FLDCAT TYPE LVC_T_FCAT.
DATA: T_FLDCAT1 TYPE SLIS_T_FIELDCAT_ALV.
DATA: L_LT TYPE SLIS_LAYOUT_ALV.
DATA: WA_IT_FLDCAT TYPE LVC_S_FCAT.
DATA: WA_IT_FLDCAT1 TYPE SLIS_FIELDCAT_ALV.
DATA: GP_TABLE TYPE REF TO DATA.
DATA: WA_NEWLINE TYPE REF TO DATA.
*DECLARATION FOR CONSTANTS
CONSTANTS:
BEGIN OF GC,
TDID_GRUN TYPE THEAD-TDID VALUE 'GRUN',
TDOBJECT_MAT TYPE THEAD-TDOBJECT VALUE 'MATERIAL',
ON(01) TYPE C VALUE 'X',
YES(01) TYPE C VALUE 'X',
TXT(25) TYPE C VALUE 'MATERIAL DETAILS',
MAT(25) TYPE C VALUE 'MATERIAL NUMBER',
AUT(25) TYPE C VALUE 'AUTHORIZATION GROUP',
FOUND TYPE SY-SUBRC VALUE '00', " Return-Code
RC_OK TYPE SY-SUBRC VALUE '00', " Return-Code
OFF TYPE SY-SUBRC VALUE '00', " return code
FALSE TYPE SY-SUBRC VALUE '00', " boolean
TRUE TYPE SY-SUBRC VALUE '01', " boolean
END OF GC.
* DECLARATION FOR VARIABLES
DATA: V(3) TYPE N,
STR TYPE STRING,
STR1 TYPE STRING,
V_VAR(3) TYPE N,
V_VAR1(3) TYPE N,
V_FIELDNAME(15) TYPE C,
V_CHAR(15) TYPE C,
V_LINES(3) TYPE N,
MAKTEXT LIKE MAKT-MAKTX,
LT_DATA TYPE REF TO DATA,
LT_DATA1 TYPE REF TO DATA,
LWA_LINE TYPE REF TO DATA,
LWA_LINE1 TYPE REF TO DATA.
*SELECTION-SCREEN AND PARAMETERS
SELECTION-SCREEN: BEGIN OF BLOCK A1 WITH FRAME TITLE TEXT-002.
SELECT-OPTIONS:
S_MATNR FOR MARA-MATNR, "MATERIAL NUMBER
S_MTART FOR MARA-MTART, "MATERIAL TEXT
S_LANG FOR MAKT-SPRAS. "LANGUAGE
PARAMETER: GP_SIZE TYPE I DEFAULT 200. "DATA LENGTH
SELECTION-SCREEN: END OF BLOCK A1.
* AT SELECTION SCREEN
AT SELECTION-SCREEN.
IF GP_SIZE < 0.
MESSAGE E002(00).
ENDIF.
IF GP_SIZE > 50000.
MESSAGE W130(26) WITH TEXT-004.
SET CURSOR FIELD 'gp_size'.
ENDIF.
* INITIALIZATION
INITIALIZATION.
GV-REPID = SY-REPID.
*START-OF-SELECTION
START-OF-SELECTION.
PERFORM GET_MARA_DATA
TABLES
GT_TEXT_OUTPUT_LINE
USING
S_MATNR[]
S_MTART[]
GP_SIZE
CHANGING
GV-RETCO
PERFORM GET_MAT_TEXT
TABLES
GT_MAKT
GT_TEXT_OUTPUT_LINE
GT_THEAD
GT_LINETAB
USING
GC
GV-RETCO
CHANGING
GV_TEXT_OUTPUT_LINE
GV_MAKT
PERFORM GET_LANG.
PERFORM DYNAMIC_TABLES.
PERFORM POPULATE_FINAL_TABLE.
PERFORM POPULATE_DYNAMIC_TABLE.
* END-OF-SELECTION
END-OF-SELECTION.
PERFORM DATA_OUTPUT.
*& Form get_mara_data
* Materialdaten lesen
* <->ct_gt_text_output_line Ausgabetabelle
* -->it_s_matnr Parameter Materialnummer
* -->it_s_mtart Parameter Materialart
* -->if_gp_size Parameter Anzahl Materialnummern
FORM GET_MARA_DATA TABLES CT_GT_TEXT_OUTPUT_LINE STRUCTURE
GV_TEXT_OUTPUT_LINE
USING IT_S_MATNR LIKE S_MATNR[]
IT_S_MTART LIKE S_MTART[]
IF_GP_SIZE
CHANGING IF_GV-RETCO. "#EC *
* MARA in die Übergabestruktur einlesen
SELECT MATNR BEGRU
FROM MARA UP TO IF_GP_SIZE ROWS
APPENDING CORRESPONDING FIELDS OF TABLE GT_MATNR
WHERE MATNR IN IT_S_MATNR
AND MTART IN IT_S_MTART.
IF_GV-RETCO = SY-SUBRC.
ENDFORM. " get_mara_data
*& Form get_mat_text
* Kurz- und Langtexte zum Material lesen
* <->ct_gt_makt Materialkurztexte
* <->ct_gt_text_output_line Ausgabetabelle
* <->ct_gt_thead Kopftabelle für ALV
* <->ct_gt_linetab Zeilentabelle für ALV
* -->if_gc Globale Konstanten
* <--cf_gv_text_output_line Struktur Ausgabetabelle
* <--cf_gv_makt Struktru Materialkurztexte
FORM GET_MAT_TEXT TABLES CT_GT_MAKT STRUCTURE MAKT
CT_GT_TEXT_OUTPUT_LINE STRUCTURE
GV_TEXT_OUTPUT_LINE
CT_GT_THEAD STRUCTURE THEAD
CT_GT_LINETAB STRUCTURE TLINE
USING
IF_GC LIKE GC
IF_GV-RETCO
CHANGING CF_GV_TEXT_OUTPUT_LINE LIKE
GV_TEXT_OUTPUT_LINE
CF_GV_MAKT LIKE GV_MAKT
DATA: STRG TYPE STRING,
STRG1(1255) TYPE C.
IF IF_GV-RETCO = IF_GC-FOUND.
* Materialkurztexte in alles Sprachen einlesen
SELECT * FROM MAKT APPENDING TABLE CT_GT_MAKT
FOR ALL ENTRIES IN GT_MATNR "ct_gt_text_output_line
WHERE MATNR = GT_MATNR-MATNR " ct_gt_text_output_line-matnr
* Kurztexte in die sprachabhängigen Felder bringen
LOOP AT GT_MATNR INTO WA_GT_MATNR.
LOOP AT CT_GT_MAKT INTO CF_GV_MAKT
WHERE MATNR = WA_GT_MATNR-MATNR.
CF_GV_TEXT_OUTPUT_LINE-MATNR = WA_GT_MATNR-MATNR.
CF_GV_TEXT_OUTPUT_LINE-BEGRU = WA_GT_MATNR-BEGRU.
CF_GV_TEXT_OUTPUT_LINE-MAKTX = CF_GV_MAKT-MAKTX.
CF_GV_TEXT_OUTPUT_LINE-SPRAS = CF_GV_MAKT-SPRAS.
* LANGTEXT
CLEAR CT_GT_THEAD[].
CT_GT_THEAD-TDOBJECT = IF_GC-TDOBJECT_MAT.
CT_GT_THEAD-TDNAME = WA_GT_MATNR-MATNR.
CT_GT_THEAD-TDID = IF_GC-TDID_GRUN.
CT_GT_THEAD-TDSPRAS = CF_GV_MAKT-SPRAS.
CALL FUNCTION 'TEXT_READ'
EXPORTING
I_HEADER = CT_GT_THEAD
I_READONLY = IF_GC-ON
IMPORTING
E_HEADER = CT_GT_THEAD
TABLES
T_LINES = CT_GT_LINETAB[]
EXCEPTIONS
NOTFOUND = 1.
IF SY-SUBRC = IF_GC-FOUND.
LOOP AT CT_GT_LINETAB.
STRG = CT_GT_LINETAB-TDLINE.
IF STRG1 <> ' '.
CONCATENATE STRG1 ';' STRG INTO STRG1.
ELSE.
STRG1 = STRG.
ENDIF.
ENDLOOP.
CF_GV_TEXT_OUTPUT_LINE-LTXT40 = STRG1.
APPEND CF_GV_TEXT_OUTPUT_LINE TO CT_GT_TEXT_OUTPUT_LINE.
CLEAR CF_GV_TEXT_OUTPUT_LINE.
STRG1 = ' '.
ELSE.
APPEND CF_GV_TEXT_OUTPUT_LINE TO CT_GT_TEXT_OUTPUT_LINE.
ENDIF.
ENDLOOP.
ENDLOOP.
ENDIF.
ENDFORM. " get_mat_text
*& Form data_output
* Daten mit ALV ausgeben
* <->ct_GT_FIELDCAT Feldkatalog für ALV
* <->ct_gt_text_output_line Ausgabetabelle
* -->P_GS_LAYOUT Layout für ALV
* -->if_gc Globale Konstanten
* <--cf_GV_REPID Zur Zeit aufgerufener Reportname
* <--cf_gv_fieldcat Struktur Feldkatalog
* <--cf_gv Globale Variablen
FORM DATA_OUTPUT.
PERFORM FIELDCATBUILD.
PERFORM LAYOUT.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_CALLBACK_PROGRAM = GV-REPID
I_CALLBACK_PF_STATUS_SET = 'EVENT_SET_STATUS_01'
I_CALLBACK_USER_COMMAND = 'EVENT_USER_COMMAND'
IS_LAYOUT = L_LT
IT_FIELDCAT = T_FLDCAT1[]
TABLES
T_OUTTAB = <FS_2>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2.
IF SY-SUBRC <> GC-FOUND.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " data_output
*& Form fieldcatbuild
* text
* --> p1 text
* <-- p2 text
FORM FIELDCATBUILD. " TABLES ct_gt_fieldcat_in STRUCTURE gv_fieldcat.
LOOP AT IT_FLDCAT INTO WA_IT_FLDCAT.
WA_IT_FLDCAT1-FIELDNAME = WA_IT_FLDCAT-FIELDNAME.
WA_IT_FLDCAT1-TABNAME = WA_IT_FLDCAT-TABNAME.
WA_IT_FLDCAT1-SELTEXT_L = WA_IT_FLDCAT-FIELDNAME.
APPEND WA_IT_FLDCAT1 TO T_FLDCAT1.
CLEAR : WA_IT_FLDCAT,WA_IT_FLDCAT1.
ENDLOOP.
ENDFORM. " fieldcatbuild
* Form event_set_status_01*
FORM EVENT_SET_STATUS_01 USING LT_EXCL TYPE SLIS_T_EXTAB.
SET PF-STATUS 'ABCD' .
ENDFORM. "EVENT_SET_STATUS_01
*& Form Name: event_user_command *
*& Form Desc: For Handling USER_COMMAND *
FORM EVENT_USER_COMMAND USING
IF_UCOMM TYPE SY-UCOMM
IS_SELFIELD TYPE SLIS_SELFIELD.
CASE IF_UCOMM.
WHEN 'DOWNLOAD'.
PERFORM POPULATE_DOWNLOAD_TABLE.
DATA: L_LENGHT TYPE I.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:data.xls'
FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
TRUNC_TRAILING_BLANKS = 'X'
DAT_MODE = 'X'
IMPORTING
FILELENGTH = L_LENGHT
TABLES
DATA_TAB = <FS_22>.
IF SY-SUBRC <> GC-FOUND.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF L_LENGHT NE GC-FOUND.
MESSAGE S398(00) WITH 'DATA downloaded to c:data.xls'.
ENDIF.
ENDCASE.
ENDFORM. "event_user_command
*& Form get_lang
* text
* --> p1 text
* <-- p2 text
FORM GET_LANG.
SELECT SPRAS
LAISO FROM T002 INTO CORRESPONDING FIELDS OF TABLE GT_LANG
WHERE SPRAS IN S_LANG.
DESCRIBE TABLE GT_LANG LINES V_LINES.
LOOP AT GT_LANG INTO WA_GT_LANG.
V = V + 1.
WA_GT_LANG-SRNO = V.
MODIFY GT_LANG FROM WA_GT_LANG TRANSPORTING SRNO.
ENDLOOP.
LOOP AT GT_LANG INTO WA_GT_LANG.
CONCATENATE 'MATEDESC-' WA_GT_LANG-LAISO INTO V_FIELDNAME.
CLEAR WA_IT_FLDCAT.
WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
WA_IT_FLDCAT-SELTEXT = V_FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-INTLEN = 40.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_GT_LANG.
ENDLOOP.
LOOP AT GT_LANG INTO WA_GT_LANG.
CONCATENATE 'BASDAT-' WA_GT_LANG-LAISO INTO V_FIELDNAME.
CLEAR WA_IT_FLDCAT.
WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-INTLEN = 255.
WA_IT_FLDCAT-SELTEXT = V_FIELDNAME.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
APPEND WA_IT_FLDCAT TO IT_FLDCAT .
CLEAR WA_GT_LANG.
ENDLOOP.
V_FIELDNAME = 'MATNR'.
CLEAR WA_IT_FLDCAT.
WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-SELTEXT = 'Matnr'.
WA_IT_FLDCAT-INTLEN = 18.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
INSERT WA_IT_FLDCAT INTO IT_FLDCAT INDEX 1.
V_FIELDNAME = 'BEGRU'.
CLEAR WA_IT_FLDCAT.
WA_IT_FLDCAT-FIELDNAME = V_FIELDNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-SELTEXT = 'BEGRU'.
WA_IT_FLDCAT-INTLEN = 4.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
INSERT WA_IT_FLDCAT INTO IT_FLDCAT INDEX 2.
ENDFORM. " get_lang
*& Form dynamic_tables
* text
* --> p1 text
* <-- p2 text
FORM DYNAMIC_TABLES.
ASSIGN LT_DATA TO <FS_DATA>.
* Creating the Dynamic Internal Table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FLDCAT " Fieldcatalogue
IMPORTING
EP_TABLE = <FS_DATA> " Dynamic Internal Table
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
* Assign Dyn Table To Field Sumbol
ASSIGN <FS_DATA>->* TO <FS_1>.
* Assigning the Internal Table TYPE ANY to Standard internal Table
ASSIGN <FS_1> TO <FS_2>.
* Creating a Workarea
CREATE DATA LWA_LINE LIKE LINE OF <FS_2> .
* Assigning the Content to the workares as a Pointer
ASSIGN LWA_LINE->* TO <LWA_LINE_WA>.
ENDFORM. " dynamic_tables
*& Form populate_final_table
* text
* --> p1 text
* <-- p2 text
FORM POPULATE_FINAL_TABLE.
LOOP AT GT_TEXT_OUTPUT_LINE INTO GV_TEXT_OUTPUT_LINE.
READ TABLE GT_LANG INTO WA_GT_LANG
WITH KEY SPRAS = GV_TEXT_OUTPUT_LINE-SPRAS.
IF SY-SUBRC EQ GC-FOUND.
GV_TEXT_OUTPUT_LINE-SRNO = WA_GT_LANG-SRNO.
ENDIF.
MODIFY GT_TEXT_OUTPUT_LINE FROM GV_TEXT_OUTPUT_LINE.
ENDLOOP.
ENDFORM. " populate_final_table
*& Form populate_dynamic_table
* text
* --> p1 text
* <-- p2 text
FORM POPULATE_DYNAMIC_TABLE.
DATA: INDX TYPE SY-TABIX.
LOOP AT GT_TEXT_OUTPUT_LINE INTO GV_TEXT_OUTPUT_LINE.
AT NEW MATNR.
INDX = SY-TABIX.
ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = GV_TEXT_OUTPUT_LINE-MATNR.
ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = GV_TEXT_OUTPUT_LINE-BEGRU.
ENDAT.
LOOP AT GT_LANG INTO WA_GT_LANG.
IF GV_TEXT_OUTPUT_LINE-SRNO = WA_GT_LANG-SRNO.
V_VAR = GV_TEXT_OUTPUT_LINE-SRNO + 2.
ASSIGN COMPONENT V_VAR OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = GV_TEXT_OUTPUT_LINE-MAKTX.
V_VAR = GV_TEXT_OUTPUT_LINE-SRNO + V_LINES + 2.
ASSIGN COMPONENT V_VAR OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = GV_TEXT_OUTPUT_LINE-LTXT40.
ENDIF.
ENDLOOP.
AT END OF MATNR.
APPEND <LWA_LINE_WA> TO <FS_2>.
CLEAR <LWA_LINE_WA>.
ENDAT.
ENDLOOP.
ENDFORM. " populate_dynamic_table
*& Form LAYOUT
* text
* --> p1 text
* <-- p2 text
FORM LAYOUT.
CLEAR L_LT.
L_LT-ZEBRA = GC-YES.
L_LT-COLWIDTH_OPTIMIZE = 'X'.
L_LT-WINDOW_TITLEBAR = GC-TXT.
ENDFORM. " LAYOUT
*& Form populate_download_table
* text
* --> p1 text
* <-- p2 text
FORM POPULATE_DOWNLOAD_TABLE.
ASSIGN LT_DATA1 TO <FS_DATA1>.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FLDCAT " Fieldcatalogue
IMPORTING
EP_TABLE = <FS_DATA1> " Dynamic Internal table
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
* Assign Dyn Table To Field Sumbol
ASSIGN <FS_DATA1>->* TO <FS_11>.
* Assigning the Internal Table TYPE ANY to Standard internal Table
ASSIGN <FS_11> TO <FS_22>.
* Creating a Workarea
CREATE DATA LWA_LINE1 LIKE LINE OF <FS_22> .
* Assigning the Content to the workares as a Pointer
ASSIGN LWA_LINE1->* TO <LWA_LINE_WA1>.
DATA: STRN1 TYPE STRING,
STRN2 TYPE STRING,
INDX TYPE SY-TABIX.
ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = GC-MAT.
ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = GC-AUT.
LOOP AT GT_LANG INTO WA_GT_LANG.
V_VAR1 = WA_GT_LANG-SRNO + 2.
CONCATENATE 'MATERIALDESCRIPTION-' WA_GT_LANG-LAISO INTO STRN1.
ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = STRN1.
V_VAR1 = WA_GT_LANG-SRNO + V_LINES + 2.
CONCATENATE 'BASICDATA-' WA_GT_LANG-LAISO INTO STRN2.
ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = STRN2.
ENDLOOP.
APPEND <LWA_LINE_WA1> TO <FS_22>.
CLEAR <LWA_LINE_WA1>.
APPEND <LWA_LINE_WA1> TO <FS_22>.
V_VAR1 = 0.
LOOP AT GT_TEXT_OUTPUT_LINE INTO GV_TEXT_OUTPUT_LINE.
AT NEW MATNR.
INDX = SY-TABIX.
ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = GV_TEXT_OUTPUT_LINE-MATNR.
ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = GV_TEXT_OUTPUT_LINE-BEGRU.
ENDAT.
LOOP AT GT_LANG INTO WA_GT_LANG.
IF GV_TEXT_OUTPUT_LINE-SRNO EQ WA_GT_LANG-SRNO.
V_VAR1 = GV_TEXT_OUTPUT_LINE-SRNO + 2.
ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = GV_TEXT_OUTPUT_LINE-MAKTX.
V_VAR1 = GV_TEXT_OUTPUT_LINE-SRNO + V_LINES + 2.
ASSIGN COMPONENT V_VAR1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
* STR = GV_TEXT_OUTPUT_LINE-LTXT40.
* SEARCH STR FOR ';'.
* DO.
* IF SY-SUBRC = 0.
* SPLIT STR AT ';' INTO STR1 STR.
* <FA> = STR1.
* APPEND <LWA_LINE_WA1> TO <FS_22>.
* SEARCH STR FOR ';'.
* CLEAR <LWA_LINE_WA1>.
* ELSE.
* EXIT.
* ENDIF.
* ENDDO.
* <FA> = STR.
* APPEND <LWA_LINE_WA1> TO <FS_22>.
<FA> = GV_TEXT_OUTPUT_LINE-LTXT40.
ENDIF.
ENDLOOP.
AT END OF MATNR.
APPEND <LWA_LINE_WA1> TO <FS_22>.
CLEAR <LWA_LINE_WA1>.
ENDAT.
ENDLOOP.
ENDFORM. " populate_download_table
thanks
Nitya -
Dynamic internal table in SAP 3.1I version
hi All,
i am new to this form and have the following question.
Currently i am working in SAP 3.1I version and i am required to create a dynamic internal table.
Basically the table name will be entered by the user on the selection screen and the dynamic internal table has to be of this type (entered by user on the selection screen).
Please let me know whether this is possible in 3.1I version and if its possible then how to achieve this.
Note: this requirement has to be done in 3.1I version hence OO concept (ie)
cl_alv_table_create=>create_dynamic_table doesn't work here.refer this demo code -
parameter p_table type tabname.
field-symbols <tab> type table.
field-symbols <tab1> type any.
types: begin of itab,
t_name type tabname,
t_ref type ref to data,
end of itab.
data itab1 type table of itab with non-unique key t_name.
perform fetch_data using p_table.
perform print_table using p_table.
*& Form fetch_data
text
-->P_P_TABLE text
FORM fetch_data USING P_TABLE1 type tabname.
data itab2 type itab.
itab2-t_name = p_table1.
create data itab2-t_ref type table of (itab2-t_name) .
assign itab2-t_ref->* to <tab>.
append itab2 to itab1.
select * from (p_table1) up to 25 rows into corresponding fields of table <tab>.
ENDFORM. " fetch_data
*& Form print_table
text
-->P_P_TABLE text
FORM print_table USING P_TABLE1 type tabname.
DATA t_ref1 TYPE REF TO data.
DATA itab2 TYPE itab.
FIELD-SYMBOLS <field> TYPE ANY.
READ TABLE itab1 INTO itab2 WITH KEY t_name = p_table1.
ASSIGN itab2-t_ref->* TO <tab>.
CREATE DATA t_ref1 LIKE LINE OF <tab>.
ASSIGN t_ref1->* TO <tab1>.
DO.
*READ TABLE <tab> ASSIGNING <tab1> INDEX 1.
READ TABLE <tab> ASSIGNING <tab1> INDEX SY-INDEX.
*WRITE:/ p_table1.
NEW-LINE.
IF sy-subrc <> 0.
EXIT.
ENDIF.
DO.
ASSIGN COMPONENT sy-index OF STRUCTURE <tab1> TO <field>.
IF sy-subrc <> 0.
EXIT.
ENDIF.
WRITE: <field>,' '.
ENDDO.
ENDDO.
ENDFORM. " print_table -
Create a dynamic internal table
Hi ,
Can any one send me some code for creating dynamic internal table
My req is like this
Input table:
OP QUAN DATE
1 2 10/10/2009
2 3 10/10/2009
3 2 11/10/2009
4 1 12/10/2009
Output table should look like this ( there are 3 different dates in above input and my output should have 3 additional columns and quan should fall under date)
OP 10/10/2009 11/10/2009 12/10/2009
1 2 0 0
2 3 0 0
3 0 2 0
4 0 0 1
Any quick respone will be greatlt appreciated
Moderator message - Please search before asking - post locked
Edited by: Rob Burbank on Dec 16, 2009 4:52 PMThe dynamic creation of internal tables has been discussed many times before in the forum. Please search the forum for them. If you have difficulties after that, post a new message with the code you have to create the table along with a description of your difficulty.
Rob -
Dynamic Internal Table with the same name
Hey Guys
I have a question.
I know that we can create dynamic internal table taking a struct dynamically.
But I have 2 ques on the same subject.
1. Can we create an internal table based on a type that we have locally declared eg
types: begin of ty_demo.
var1(1) type c,
var2 type p,
end of ty_demo.
2. If an internal table is already declared based on the above type say data: i_tab type standard table of ty_demo.
If i need to enhance the struct of this internal table. Can i do that by dynamically redefining it based on a different structure but keepin the same name i_tab.
In a nut shell I cannot change the name of my itab but I want to enhance the structure.
I Hope I am clear.
Help will be greatly apprcieated.
Thanks
Sameerhai.
we can create an internal table based on a type that we have locally declared, but you have to use data instead of types like.
data: begin of ty_demo.
var1(1) type c,
var2 type p,
end of ty_demo.
check the example notes for dynamic itab .
Dynamic internal table is internal table that we create on the fly with flexible column numbers.
For sample code, please look at this code tutorial. Hopefully it can help you
Check this link:
http://www.****************/Tutorials/ABAP/DynamicInternaltable/DynamicInternalTable.htm
Sample code:
DATA: l_cnt(2) TYPE n,
l_cnt1(3) TYPE n,
l_nam(12),
l_con(18) TYPE c,
l_con1(18) TYPE c,
lf_mat TYPE matnr.
SORT it_bom_expl BY bom_comp bom_mat level.
CLEAR: l_cnt1, <fs_dyn_wa>.
Looping the component internal table
LOOP AT it_bom_expl INTO gf_it_bom_expl.
CLEAR: l_cnt1.
AT NEW bom_comp.
CLEAR: l_cnt, <fs_dyn_wa>, lf_mat.
For every new bom component the material data is moved to
temp material table which will be used for assigning the levels
checking the count
it_mat_temp[] = it_mat[].
Component data is been assigned to the field symbol which is checked
against the field of dynamic internal table and the value of the
component number is been passed to the dynamic internal table field
value.
ASSIGN COMPONENT c_comp_list OF STRUCTURE <fs_dyn_wa> TO
<fs_check>.
<fs_check> = gf_it_bom_expl-bom_comp.
ENDAT.
AT NEW bom_mat.
CLEAR l_con.
ENDAT.
lf_mat = gf_it_bom_expl-bom_mat.
Looping the temp internal table and looping the dynamic internal table
*by reading line by line into workarea, the materialxxn is been assigned
to field symbol which will be checked and used.
LOOP AT it_mat_temp.
l_nam = c_mat.
l_cnt1 = l_cnt1 + 1.
CONCATENATE l_nam l_cnt1 INTO l_nam.
LOOP AT <fs_dyn_table2> ASSIGNING <fs_dyn_wa2>.
ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa2> TO <fs_xy>.
ENDLOOP.
IF <fs_xy> = lf_mat.
CLEAR lf_mat.
l_con1 = l_con.
ENDIF.
Checking whether the material exists for a component and if so it is
been assigned to the field symbol which is checked against the field
of dynamic internal table and the level of the component number
against material is been passed to the dynamic internal table field
value.
IF <fs_xy> = gf_it_bom_expl-bom_mat.
ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa> TO <fs_check>.
CLEAR l_con.
MOVE gf_it_bom_expl-level TO l_con.
CONCATENATE c_val_l l_con INTO l_con.
CONDENSE l_con NO-GAPS.
IF l_con1 NE space.
CONCATENATE l_con1 l_con INTO l_con SEPARATED BY c_comma.
CLEAR l_con1.
l_cnt = l_cnt - 1.
ENDIF.
<fs_check> = l_con.
l_cnt = l_cnt + 1.
ENDIF.
ENDLOOP.
AT END OF bom_comp.
At end of every new bom component the count is moved to the field
symbol which is checked against the field of dynamic internal table
and the count is been passed to the dynamic internal table field
value.
ASSIGN COMPONENT c_count OF STRUCTURE <fs_dyn_wa> TO <fs_check>.
<fs_check> = l_cnt.
INSERT <fs_dyn_wa> INTO TABLE <fs_dyn_table>.
ENDAT.
ENDLOOP.
regards.
sowjanya.b
Maybe you are looking for
-
How can I get an iPad donated to my severely handicapped classroom?
I have a class with Autistic children ages 4 to ten, that could benefit greatly from using an iPad. I bring my personal iPad in for them to use but it would be nice to have one donated to the class. Dztravis clear lake, ca.
-
New Ipod touch won't sync with window's vista/itunes 9.2 - help!!
I charged my brand new ipod touch via my computer, have it plugged it into my computer's USB port, and Itunes acknowledges the device in the left hand menu BUT it automatically says "itunes could not connect to the itunes store. The network connectio
-
Using a literal "." in sed regex
I recently picked up O'Reilly's _Classic Shell Scripting_. Two of the examples have me stuck. (1) Both the man pages on 10.4.5 and various references say that to get a literal period into the regex part of a s/regex/str/, use "\.". This command, howe
-
Regular expressions API in v1.3.1
hi, is there any package like java.util.regex of java version 1.4.1 in java version 1.3.1? is it possible to use regular expressions in 1.3.1 version? i need methods like matches() and replaceAll() in Matcher class of version 1.4.1 if not, is there a
-
What is Attr data source name for SOLD,BILL and SHIP TO PARTY
Hi all, I want master data source names for these SOLD,BILL and SHIP TO PARTY. Bill to party,Ship to party and Sold to party Master data source names. Plz give me Some help on this. i want solution very urgently. Thanks, Guna.