Determining internal table structure dynamically
Hi,
I have a number of internal tables in my program which I declare using types. As an example:
TYPES: begin of ty_hierarchy,
control_id(6) type c,
node_id(10) type c,
node_name type bezei40,
material type matnr,
node_level type prodh_stuf,
node_parent(10) type c,
end of ty_hierarchy.
DATA: it_hierarchy type ty_hierarchy occurs 0.
Further down my program I need to determine the structure of internal table IT_HIERARCHY dynamically. Because I have a number of internal tables, I need to determine which internal table is being processed. Therefore it's important that I know the structure of the table that I'm currently processing.
I am aware of CL_ABAP* classes and functions like GET_COMPONENT_LIST. However because I have declared my tables using the TYPE statement the method/function cannot read my table structure correctly. If I changed my declaration to be as below, the method/function work! However I don't want to do this as I use field symbols to reference my internal tables and need to use the TYPE statement.
DATA: begin of ty_hierarchy,
control_id(6) type c,
node_id(10) type c,
node_name type bezei40,
material type matnr,
node_level type prodh_stuf,
node_parent(10) type c,
end of ty_hierarchy.
DATA: begin of it_hierarchy occurs 0.
include structure ty_hierarchy
DATA: end of it_hierarchy.
Does anyone know on how I can determine my internal table structure dynamically but still keeping my internal table declarations using TYPE statement?
Any help would be greatly appreciated with reward points .....
Thanks
Liam
Hello Liam
Both the ABAP-OO as well as the FM-based approach described by Eswar work well with your way of defining the itabs. I described three different ways how to get the structure of your itab dynamically:
- directly using the itab
- using a field symbol
- using a data reference
REPORT zus_sdn_dynamic_itabs.
TYPE-POOLS: abap.
TYPES: BEGIN OF ty_hierarchy,
control_id(6) TYPE c,
node_id(10) TYPE c,
node_name TYPE bezei40,
material TYPE matnr,
node_level TYPE prodh_stuf,
node_parent(10) TYPE c,
END OF ty_hierarchy.
DATA:
gs_hierarchy TYPE ty_hierarchy,
it_hierarchy TYPE ty_hierarchy OCCURS 0.
DATA:
gt_comp TYPE abap_compdescr_tab,
gs_comp_a LIKE LINE OF gt_comp,
gd_type TYPE abap_typekind,
gs_comp TYPE rstrucinfo,
it_comp TYPE TABLE OF rstrucinfo.
DATA:
go_struct TYPE REF TO cl_abap_structdescr,
go_table TYPE REF TO cl_abap_tabledescr,
gdo_data TYPE REF TO data.
FIELD-SYMBOLS:
<gt_itab> TYPE table.
START-OF-SELECTION.
GET REFERENCE OF it_hierarchy INTO gdo_data.
ASSIGN gdo_data->* TO <gt_itab>.
* (1) Describe directly by using the itab
* go_table ?= cl_abap_structdescr=>describe_by_data( it_hierarchy ).
* (2) Describe indirectly by using field symbol
* go_table ?= cl_abap_structdescr=>describe_by_data( <gt_itab> ).
* (3) Describe by data reference to itab
go_table ?= cl_abap_structdescr=>describe_by_data_ref( gdo_data ).
go_struct ?= go_table->get_table_line_type( ).
WRITE: / 'ABAP-OO Version:'.
gt_comp = go_struct->components.
LOOP AT gt_comp INTO gs_comp_a.
WRITE: / gs_comp_a-name,
gs_comp_a-length,
gs_comp_a-type_kind,
gs_comp_a-decimals.
ENDLOOP.
SKIP 2.
CALL FUNCTION 'GET_COMPONENT_LIST'
EXPORTING
program = sy-repid
fieldname = 'GS_HIERARCHY'
TABLES
components = it_comp.
WRITE: / 'Function Module Version:'.
LOOP AT it_comp INTO gs_comp.
WRITE: / gs_comp-compname,
gs_comp-level,
gs_comp-leng,
gs_comp-type,
gs_comp-olen,
gs_comp-decs.
ENDLOOP.
END-OF-SELECTION.
Regards
Uwe
Similar Messages
-
Change internal table structure dynamically
Dear Experts , I have a requirement to add an attribute to already declared internal table which is declared in standard SAP code, is it possible to change internal table structure dynamically.
my internal table is of type merel_t_grid2 which is standard table type in SAP , now I want to add an attribute of type LVC_T_STYL in my internal table so that I can modify the cell property of ALV grid.
I cant append LVC_T_STYL in standard structure because enhancement category of merel_t_grid2 is of type char and not deep
my internal table contains data to be displayed in ALV.
please helpDear Experts , I have a requirement to add an attribute to already declared internal table which is declared in standard SAP code, is it possible to change internal table structure dynamically.
my internal table is of type merel_t_grid2 which is standard table type in SAP , now I want to add an attribute of type LVC_T_STYL in my internal table so that I can modify the cell property of ALV grid.
I cant append LVC_T_STYL in standard structure because enhancement category of merel_t_grid2 is of type char and not deep
my internal table contains data to be displayed in ALV.
please help -
Need to make the internal table structure dynamic
Hi ,
I need to upload data from an excel file, the columns in the excel keep on varying
E.g the number of columns in one excel file can be 10, in the second excel file it can be 15.
So in order to upload the data into an internal table the structre of internal table needs to be dynamic and change according to the number of fields in the input file .
Is it possible by using field symbols or is there any other method to do the same
Thanks.
Nishant
Edited by: nishant patel on Sep 17, 2009 10:48 AMHi Nishant,
According to ur requirement, dynamic internal table can be created like below. But database table name has to passed dynacimally.
DATA: ftab TYPE STANDARD TABLE OF ddfield,
ftab_wa TYPE ddfield,
fcat_itab TYPE lvc_t_fcat,
fcat_wa TYPE lvc_s_fcat,
poi_itab TYPE REF TO data.
FIELD-SYMBOLS: <itab> TYPE STANDARD TABLE.
CALL FUNCTION 'DD_NAMETAB_TO_DDFIELDS'
EXPORTING
tabname = p_table " Pass database table name dynamically
TABLES
ddfields = ftab.
LOOP AT ftab INTO ftab_wa.
fcat_wa-fieldname = ftab_wa-fieldname.
fcat_wa-ref_field = ftab_wa-fieldname.
fcat_wa-ref_table = p_table.
APPEND fcat_wa TO fcat_itab.
ENDLOOP.
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = fcat_itab
IMPORTING
ep_table = poi_itab
EXCEPTIONS
generate_subpool_dir_full = 1
OTHERS = 2.
ASSIGN poi_itab->* TO <itab>. " <itab> is dynamic internal table
Might help u.
Thanks.
Edited by: Sap Fan on Sep 17, 2009 1:19 PM -
Dynamic internal table structure
pl. give the solution to create dynamically internal table structure with respective of different table.
Hi and welcome to the SDN,
this topic is more related to abap, but anyway:
data: l_tabname(30) type c value 'MARA',
ref_data type ref to data.
field-symbols: <fs_tab> type table.
create data ref_data type standard table of (l_tabname).
assign ref_data->* to <fs_tab>.
Now <fs_tab> is a internal table with structure of table mara.
Hope this helps!
regards
Siggi -
How to convert internal table with dynamic fields to XML
Dear all,
I met a problem like the following:
The aim is to transform the following parameter to XML
IT_FIELD stores the dynamic filed name of the internal table,with these fields, the dynamic internal can be created by cl_abap_tabledescr=>create(it_field)
IT_VALUE stores the value of the internal table dynamically created with dynamic fields.
For example
IT_FIELD =>
line1: FIELD1
line2: FIELD2
line3: FIELD3,
three lines in this internal table.
dynamically created internal table structure FIELD1 FIELD2 FIELD3
And IT_VALUE=>
1 2 3 (First line)
11 22 33
two lines of data.
Do you have any idea about how to transform the IT_VALUE to XML here? And also the transformed XML to the IT_VALUE.( we may need remember IT_FIELD here for later XML to IT_VALUE.)
Hope I describe the problem clearly.
Any inputs will be appreciated.
Edited by: Max Tang on Jan 12, 2009 3:46 PM
Edited by: Max Tang on Jan 12, 2009 4:14 PMHi,
you need to implement a bit of coding for that.
With the 'do varying' statement abap provides a loop over those fields. Within this loop you can build up a new internal table with one entry for each period and amount.
kind regards
Siggi
PS: I am not very familiar with CO, but I guess there will be a standard extractor for that. -
Internal table with Dynamic and Non dynamic fileds
Hi Experts,
How to get the internal table with Dynamic and Non-Dynamic Fields.
Could u please help me.
Thanks,
VarunHi,
Execute the below sample code or analyze it there is appropriate description provided.
*& Report ZTEST_PRM_DYN_ALV
REPORT ZTEST_PRM_DYN_ALV.
type-pools: slis.
field-symbols: <dyn_table> type standard table,
<dyn_wa>.
data: alv_fldcat type slis_t_fieldcat_alv,
it_fldcat type lvc_t_fcat.
selection-screen begin of block b1 with frame title text-001.
parameters: p_flds(5) type c.
selection-screen end of block b1.
start-of-selection.
*build the dynamic internal table
perform build_dyn_itab.
*write 5 records to the alv grid
do 5 times.
perform build_report.
enddo.
*call the alv grid.
perform call_alv.
*Build_dyn_itab
form build_dyn_itab.
data: new_table type ref to data,
new_line type ref to data,
wa_it_fldcat type lvc_s_fcat.
*Create fields .
clear wa_it_fldcat.
wa_it_fldcat-fieldname = 'name1'.
wa_it_fldcat-datatype = 'mara-matnr'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
*clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 5.
append wa_it_fldcat to it_fldcat .
do p_flds times.
clear wa_it_fldcat.
wa_it_fldcat-fieldname = sy-index.
wa_it_fldcat-datatype = 'CHAR'.
wa_it_fldcat-intlen = 6.
append wa_it_fldcat to it_fldcat .
enddo.
*Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fldcat
importing
ep_table = new_table.
assign new_table->* to <dyn_table>.
*Create dynamic work area and assign to FS
create data new_line like line of <dyn_table>.
assign new_line->* to <dyn_wa>.
endform.
*Form build_report
form build_report.
data: fieldname(20) type c.
data: fieldvalue(5) type c.
data: index(3) type c.
field-symbols: <fs1>.
do p_flds times.
index = sy-index.
*Set up fieldvalue
concatenate 'FLD' index into
fieldvalue.
condense fieldvalue no-gaps.
assign component index of structure <dyn_wa> to <fs1>.
<fs1> = fieldvalue.
enddo.
*Append to the dynamic internal table
append <dyn_wa> to <dyn_table>.
endform.
*CALL_ALV
form call_alv.
data: wa_cat like line of alv_fldcat.
*clear wa_cat.
wa_cat-fieldname = 'matnr'.
wa_cat-seltext_s = sy-index.
wa_cat-outputlen = '10'.
append wa_cat to alv_fldcat.
do p_flds times.
clear wa_cat.
wa_cat-fieldname = sy-index.
wa_cat-seltext_s = sy-index.
wa_cat-outputlen = '6'.
append wa_cat to alv_fldcat.
enddo.
*Call ABAP List Viewer (ALV)
call function 'REUSE_ALV_GRID_DISPLAY'
exporting
it_fieldcat = alv_fldcat
tables
t_outtab = <dyn_table>.
endform.
Hope this will help, reward if found usefull.
Cheers,
Ram. -
Populating values to internal table created dynamically
Hi,
I am creating an internal table(it1) dynamically and assigned it to a field symbol. now i want to upload values
which are present in a field of another internal table being populated from a Funct Module.Could you tell me
how to assign those values across the fields of field symbol?
loop at itab_char.
LS_ALV_CAT-FIELDNAME = itab_char-charact.
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>.
(Above my int tab is generated and now stored in <f_FS>)
loop at itab into w_lifnr.
CALL FUNCTION 'CLAF_CLASSIFICATION_OF_OBJECTS'
EXPORTING
CLASS = p_cname
CLASSTYPE = w_ctype
OBJECT = w_lifnr
TABLES
T_CLASS = t_class
T_OBJECTDATA = t_objectdata
w-lifnr is vendor number. and here we are populating t_objectdata with that vendor related datas. now i want to pass t_objectdata-ausp1 values for each vendor across the fields in <F_FS>.
FIELD-SYMBOLS : <F_FS> TYPE TABLE.
Please refer me the solution to this problem.
ThanksCheck below code and try to add in ur code....
IF NOT it_bom_expl[] IS INITIAL.
The material number data varies from run to run. For this purpose
the data is been used to build dynamic internal table which stores the
material number data along the x-axis
PERFORM build_matnr_table.
The material numbers data which is stored in the temp internal table
is been assigned to the dynamic internal table created along the
x-axis for the materials
PERFORM assign_matnr_val_fields.
The component data which is stored in the internal table needs to be
moved to the dynamic internal table
PERFORM move_bom_data_to_matnr_table.
*& Form build_matnr_table
Using the material number data the dynamic internal tables are been
built which holds the material number data along x-axis. Here the
first 3 columns are always constant which are Components-List,
Description, Count. From 4th column it depends on number of materials
FORM build_matnr_table .
DATA: l_val(3) TYPE n,
lf_mat(18) TYPE c.
Moving the Components-List details to the internal table 1st column
which will be used for creation of dynamic internal table
CLEAR gf_xfc.
gf_xfc-fieldname = text-t03.
gf_xfc-datatype = c_val_c.
gf_xfc-inttype = c_val_c.
gf_xfc-intlen = 18.
gf_xfc-decimals = 0.
APPEND gf_xfc TO gf_ifc.
APPEND gf_xfc TO gf_ipc.
CLEAR gf_xfc.
Moving the Description details to the internal table 2nd column
which will be used for creation of dynamic internal table
gf_xfc-fieldname = text-t04.
gf_xfc-datatype = c_val_c.
gf_xfc-inttype = c_val_c.
gf_xfc-intlen = 40.
gf_xfc-decimals = 0.
APPEND gf_xfc TO gf_ipc.
CLEAR gf_xfc.
Moving the Count details to the internal table 3rd column which will
be used for creation of dynamic internal table
gf_xfc-fieldname = text-t05.
gf_xfc-datatype = c_val_c.
gf_xfc-inttype = c_val_c.
gf_xfc-intlen = 5.
gf_xfc-decimals = 0.
APPEND gf_xfc TO gf_ifc.
APPEND gf_xfc TO gf_ipc.
Moving the Material numbers are moved to the internal table from 4th
column onwards till all the material numbers are moved to the columns
which will be used for creation of dynamic internal table. Here
columns will be reffered to as Material001 ..... Materialxxn
LOOP AT it_mat.
CLEAR gf_xfc.
l_val = l_val + 1.
CONCATENATE text-t06 l_val INTO lf_mat.
gf_xfc-fieldname = lf_mat.
gf_xfc-datatype = c_val_c.
gf_xfc-inttype = c_val_c.
gf_xfc-intlen = 18.
gf_xfc-decimals = 0.
APPEND gf_xfc TO gf_ifc.
APPEND gf_xfc TO gf_ipc.
ENDLOOP.
Using the above data dynamic internal table is been created
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gf_ifc
IMPORTING
ep_table = gf_table.
The dynamic internal table which is created is been assigned to
field-symbol which holds the data of the columns of X-axis
ASSIGN gf_table->* TO <fs_dyn_table>.
Dynamic work area is been created usng the reference to the
field-symbol which has the data and the line item is been assign to
field-symbol to hold line item data for reading purposes line by line
CREATE DATA gf_line LIKE LINE OF <fs_dyn_table>.
ASSIGN gf_line->* TO <fs_dyn_wa>.
Using the above data dynamic internal table is been created
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gf_ipc
IMPORTING
ep_table = gf_table1.
The dynamic internal table which is created is been assigned to
field-symbol which holds the data of the columns of X-axis
ASSIGN gf_table1->* TO <fs_dyn_table1>.
Dynamic work area is been created usng the reference to the
field-symbol which has the data and the line item is been assign to
field-symbol to hold line item data for reading purposes line by line
CREATE DATA gf_line1 LIKE LINE OF <fs_dyn_table1>.
ASSIGN gf_line1->* TO <fs_dyn_wa1>.
Using the above data dynamic internal table is been created
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = gf_ifc
IMPORTING
ep_table = gf_table2.
The dynamic internal table which is created is been assigned to
field-symbol which holds the data of the columns of X-axis
ASSIGN gf_table2->* TO <fs_dyn_table2>.
Dynamic work area is been created usng the reference to the
field-symbol which has the data and the line item is been assign to
field-symbol to hold line item data for reading purposes line by line
CREATE DATA gf_line2 LIKE LINE OF <fs_dyn_table2>.
ASSIGN gf_line2->* TO <fs_dyn_wa2>.
ENDFORM. " build_matnr_table
*& Form assign_matnr_val_fields
The material numbers data stored in the temp internal table needs to
be assigned to the dynamic internal table along x-axis as the first
record. The temp internal table is been looped and using the field
symbol concept the data is moved to the dynamic internal table
FORM assign_matnr_val_fields .
DATA: l_cnt(3) TYPE n,
l_nam(12),
g_total(3) TYPE n.
DESCRIBE TABLE it_mat LINES g_total.
CLEAR l_cnt.
Looping the temp internal table and concatenating material as
material001 and the same is been checked against the dynamic
internal table and the material number value is moved to the
internal table. Finally, the data is been appened as first record.
LOOP AT it_mat.
l_nam = c_mat.
l_cnt = l_cnt + 1.
CONCATENATE l_nam l_cnt INTO l_nam.
Material which is in form Materialxxn is been assigned to the field
symbol which is checked against the field of dynamic internal table
and the value of the Material Number is been passed to the dynamic
internal table field value.
After all materials are been assigned the record is been appended
to the dynamic internal table.
ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa> TO <fs_field>.
<fs_field> = it_mat-matnr.
IF l_cnt = g_total.
INSERT <fs_dyn_wa> INTO TABLE <fs_dyn_table>.
ENDIF.
ENDLOOP.
Looping the temp internal table and concatenating material as
material001 and the same is been checked against the dynamic
internal table and the material number value is moved to the
internal table. Finally, the data is been appened as first record.
This is been used for downloading of data to excel sheet as it
contains additional field which is Description field.
CLEAR l_cnt.
LOOP AT it_mat.
l_nam = c_mat.
l_cnt = l_cnt + 1.
CONCATENATE l_nam l_cnt INTO l_nam.
Material which is in form Materialxxn is been assigned to the field
symbol which is checked against the field of dynamic internal table
and the value of the Material Number is been passed to the dynamic
internal table field value.
After all materials are been assigned the record is been appended
to the dynamic internal table.
ASSIGN COMPONENT l_nam OF STRUCTURE <fs_dyn_wa1> TO <fs_field>.
<fs_field> = it_mat-matnr.
IF l_cnt = g_total.
INSERT <fs_dyn_wa1> INTO TABLE <fs_dyn_table1>.
ENDIF.
ENDLOOP.
The contents of one internal table is passed on to other internal
table for use while moving the component data for count purposes.
<fs_dyn_table2>[] = <fs_dyn_table>[].
ENDFORM. " assign_matnr_val_fields
*& Form move_bom_data_to_matnr_table
The component data is been appended to the dynamic internal table
The component is checked against a material and if exists the corresp-
onding level is been appended to the record
The total count is derived as the in how many materials the component
exists
FORM move_bom_data_to_matnr_table .
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.
Looping the component internal table. This is used for the additional
Description field which is shown in the excel sheet
LOOP AT it_bom_expl INTO gf_it_bom_expl.
CLEAR: l_cnt1.
AT NEW bom_comp.
CLEAR: l_cnt, <fs_dyn_wa1>, 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_wa1> 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_wa1> 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.
The description 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_description OF STRUCTURE <fs_dyn_wa1> TO
<fs_check>.
<fs_check> = gf_it_bom_expl-ojtxp.
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.
AT END OF bom_comp.
ASSIGN COMPONENT c_count OF STRUCTURE <fs_dyn_wa1> TO <fs_check>.
<fs_check> = l_cnt.
INSERT <fs_dyn_wa1> INTO TABLE <fs_dyn_table1>.
ENDAT.
ENDLOOP.
ENDFORM. " move_bom_data_to_matnr_table -
Create dynamic internal table with dynamic structure
I have an internal table itab1 that have 12 amount fields from period1 thru period12. I need to create a dynamic table with dynamic structure for the period column if the total amount of each column is > 0. Any idea on how to do that?
For example if my itab1 has 20 rows and the sum of period1 = 35, sum of period2 = 0, sum of period3 = 5, sum of period4 =0, sum of period5 = 2 then I need to create a dynamic structure for the field column that have the total > 0, i.e structure struct1 have field period1, period3 and period5 only. Then I will need to load the data to itab2 from itab1. Can someone help.
Thanks. I am on 4.7 and will upgrade to ERP 6.0 soon.go throgh this....
REPORT yusmm_text1 NO STANDARD PAGE HEADING
LINE-SIZE 199.
T A B L E S
TABLES: MARA,
MAKT,
THEAD.
GLOBAL TYPE-POOLS
TYPE-POOLS : SLIS.
GLOBAL TYPES
TYPES : BEGIN OF TP_FINAL,
MATNR TYPE MARA-MATNR,
BEGRU TYPE MARA-BEGRU,
MTART TYPE MARA-MTART,
MAKTX TYPE MAKT-MAKTX,
SPRAS TYPE MAKT-SPRAS,
LTXT(2000) TYPE C ,
SRNO TYPE N ,
END OF TP_FINAL.
TYPES : BEGIN OF TP_T002,
SPRAS TYPE T002-SPRAS,
LAISO TYPE T002-LAISO,
SRNO TYPE N ,
END OF TP_T002.
TYPES : BEGIN OF TP_MARA_MAKT,
MATNR TYPE MARA-MATNR,
BEGRU TYPE MARA-BEGRU,
MTART TYPE MARA-MTART,
SPRAS TYPE MAKT-SPRAS,
MAKTX TYPE MAKT-MAKTX,
END OF TP_MARA_MAKT.
Types: BEGIN OF tp_matnr,
matnr TYPE mara-matnr,
END OF tp_matnr.
GLOBAL ELEMENTARY VARIABLES
DATA : gv_date TYPE sy-datum.
DATA : gv_repid TYPE sy-repid.
DATA : g_var1(10) TYPE C.
DATA : gv_index TYPE sy-tabix.
DATA: gv_strg TYPE string,
gv_strg1(2000) TYPE C.
DATA : gv_lang TYPE sy-langu.
DATA : g_v(3) TYPE N .
DATA : gv_lines(3) TYPE N .
DATA : gv_var(3) TYPE N .
DATA : gv_var1(3) TYPE N.
DATA: gv_str TYPE STRING.
DATA: gv_str1 TYPE STRING.
DATA : gv_li TYPE I,
gv_lit TYPE I,
gv_lin TYPE I.
DATA: g_var11(3) TYPE N,
gv_li1(3) TYPE N,
g_var2(3) TYPE N.
DATA : gv_i1 TYPE I.
DATA : gv_i TYPE I.
DATA: gl_lenght TYPE I.
GLOBAL STRUCTURES
DATA: T_NEWTABLE TYPE REF TO DATA,
T_NEWLINE TYPE REF TO DATA,
T_FLDCAT1 TYPE SLIS_T_FIELDCAT_ALV,
T_FLDCAT TYPE LVC_T_FCAT,
WA_IT_FLDCAT TYPE LVC_S_FCAT,
WA_IT_FLDCAT1 TYPE SLIS_FIELDCAT_ALV,
WA_COLNO(2) TYPE N,
WA_FLNAME(5) TYPE C,
L_LT TYPE SLIS_LAYOUT_ALV.
GLOBAL INTERNAL TABLES (WITH INCLUDE STRUCTURE)
DATA : IG_MARA_MAKT TYPE STANDARD TABLE OF TP_MARA_MAKT,
WG_MARA_MAKT TYPE TP_MARA_MAKT.
DATA : IG_T002 TYPE STANDARD TABLE OF TP_T002,
WG_T002 TYPE TP_T002.
DATA : IG_FINAL TYPE STANDARD TABLE OF TP_FINAL,
WG_FINAL TYPE TP_FINAL.
data : IG_MATNR TYPE STANDARD TABLE OF TP_MATNR WITH HEADER LINE,
WG_MATNR TYPE TP_MATNR.
DATA:BEGIN OF IG_THEAD OCCURS 0.
INCLUDE STRUCTURE THEAD .
DATA: END OF IG_THEAD.
DATA:BEGIN OF IG_TLINE OCCURS 0.
INCLUDE STRUCTURE TLINE .
DATA:END OF IG_TLINE.
FIELD-SYMBOLS
FIELD-SYMBOLS: <T_DYNTABLE> TYPE STANDARD TABLE,"Dynamic internal
"tablename
<FS_DYNTABLE>, "Field symbol to create work area
<FS_FLDVAL> TYPE ANY. " Field symbol to assign values
COMPULSORY
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>.
------- Create Dyn Table From FC
DATA: LT_DATA TYPE REF TO DATA,
LT_DATA1 TYPE REF TO DATA,
LWA_LINE TYPE REF TO DATA,
LWA_LINE1 TYPE REF TO DATA,
LI_FIELD_CAT TYPE LVC_T_FCAT,
LWA_FIELD_CAT TYPE LVC_S_FCAT.
PARAMETERS & SELECT-OPTIONS
SELECTION-SCREEN : BEGIN OF BLOCK B1 WITH FRAME TITLE TEXT-001.
SELECT-OPTIONS : S_SPRAS FOR MAKT-SPRAS NO INTERVALS DEFAULT 'EN'
OBLIGATORY ,
S_MATNR FOR MARA-MATNR,
S_MTART FOR MARA-MTART.
PARAMETERS: GP_SIZE TYPE I DEFAULT '200'.
SELECTION-SCREEN : END OF BLOCK B1.
INITIALIZATION
INITIALIZATION.
gv_repid = sy-repid.
gv_date = sy-datum.
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.
START-OF-SELECTION
START-OF-SELECTION.
PERFORM FIELDCAT.
PERFORM LAYOUT.
PERFORM DATA_FETCH.
PERFORM READ_DATA_TO_FINAL.
SORT ig_final BY matnr spras.
gv_lin = gv_li.
gv_li = gv_li - 2.
LOOP AT ig_final INTO wg_final.
ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = 'Material Number'.
ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = 'Authorization Group'.
g_VAR11 = wg_final-srno + 2.
gv_li1 = gv_li1 + 2.
MOVE : g_var11 TO gv_i1.
ASSIGN COMPONENT g_var11 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = 'MatDesc'.
g_var2 = g_var11 + gv_lines.
ASSIGN COMPONENT g_var2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = 'BasicData'.
APPEND <LWA_LINE_WA1> TO <FS_22>.
EXIT.
ENDLOOP.
LOOP AT ig_final INTO wg_final.
AT NEW matnr.
gv_index = sy-tabix.
ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = wg_final-matnr.
ENDAT.
AT NEW MATNR.
GV_INDEX = SY-TABIX.
ASSIGN COMPONENT 1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = wg_final-matnr.
ENDAT.
ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = wg_final-begru.
ASSIGN COMPONENT 2 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = wg_final-begru.
gv_var = wg_final-srno + 2.
gv_li = gv_li + 2.
MOVE : gv_var TO gv_i.
ASSIGN COMPONENT gv_var OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = wg_final-maktx.
ASSIGN COMPONENT gv_var OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = wg_final-maktx.
gv_var1 = gv_var + gv_lines .
ASSIGN COMPONENT gv_var1 OF STRUCTURE <LWA_LINE_WA> TO <F>.
<F> = wg_final-ltxt.
ASSIGN COMPONENT gv_var1 OF STRUCTURE <LWA_LINE_WA1> TO <FA>.
<FA> = wg_final-ltxt.
AT END OF matnr.
APPEND <LWA_LINE_WA> TO <FS_2>.
CLEAR <LWA_LINE_WA>.
ENDAT.
AT END OF matnr.
APPEND <LWA_LINE_WA1> TO <FS_22>.
CLEAR <LWA_LINE_WA1>.
ENDAT.
ENDLOOP.
PERFORM display..
*& Form data_fetch
text
--> p1 text
<-- p2 text
FORM DATA_FETCH .
SELECT matnr
from mara up to gp_size rows
appending corresponding fields of table ig_matnr
where matnr in s_matnr
and mtart in s_mtart.
loop at ig_matnr.
SELECT MARA~MATNR
MARA~BEGRU
MARA~MTART
MAKT~SPRAS
MAKT~MAKTX FROM MARA INNER JOIN MAKT
ON MARAMATNR = MAKTMATNR
appending corresponding fields of TABLE ig_mara_makt UP TO GP_SIZE
ROWS
WHERE makt~spras IN s_spras
AND mara~matnr IN s_matnr
AND mara~mtart IN s_mtart
AND mara~matnr EQ ig_matnr-matnr.
endloop.
IF sy-subrc = 0.
SORT ig_mara_makt.
ENDIF.
ENDFORM. " data_fetch
*& Form read_data_to_final
text
--> p1 text
<-- p2 text
FORM READ_DATA_TO_FINAL .
LOOP AT ig_mara_makt INTO wg_mara_makt .
wg_final-MATNR = wg_mara_makt-MATNR.
wg_final-BEGRU = wg_mara_makt-BEGRU.
wg_final-MTART = wg_mara_makt-MTART.
wg_final-SPRAS = wg_mara_makt-SPRAS.
wg_final-MAKTX = wg_mara_makt-MAKTX.
READ TABLE ig_t002 INTO wg_t002 WITH KEY spras = wg_final-spras.
IF sy-subrc = 0.
wg_final-srno = wg_t002-srno.
ENDIF.
CLEAR ig_thead[].
ig_thead-TDOBJECT = 'MATERIAL'.
ig_thead-TDNAME = wg_final-matnr.
ig_thead-TDID = 'GRUN'.
ig_thead-TDSPRAS = wg_final-spras.
CALL FUNCTION 'TEXT_READ'
EXPORTING
I_HEADER = IG_THEAD
I_READONLY = 'X'
IMPORTING
E_HEADER = IG_THEAD
TABLES
T_LINES = IG_TLINE[]
EXCEPTIONS
NOTFOUND = 1.
IF sy-subrc EQ 0.
LOOP AT ig_tline.
gv_strg = ig_tline-tdline.
IF gv_strg1 <> ' '.
CONCATENATE gv_strg1 ';' gv_strg INTO gv_strg1.
ELSE.
gv_strg1 = gv_strg.
ENDIF.
ENDLOOP.
wg_final-ltxt = gv_strg1.
APPEND wg_final TO ig_final.
CLEAR wg_final.
gv_strg1 = ' '.
ELSE.
APPEND wg_final TO ig_final.
ENDIF.
ENDLOOP.
ENDFORM. " read_data_to_final
" read_data_to_final
*& Form layout
text
--> p1 text
<-- p2 text
FORM LAYOUT .
CLEAR L_LT.
L_LT-ZEBRA = 'X'.
L_LT-COLWIDTH_OPTIMIZE = 'X'.
L_LT-WINDOW_TITLEBAR = 'MATERIAL DETAILS'.
ENDFORM. " layout
*& Form fieldcat
text
--> p1 text
<-- p2 text
FORM FIELDCAT .
SELECT SPRAS
LAISO FROM t002 INTO CORRESPONDING FIELDS OF TABLE ig_t002
WHERE spras IN s_spras.
DESCRIBE TABLE ig_t002 LINES gv_lines.
LOOP AT ig_t002 INTO wg_t002.
g_v = g_v + 1.
Wg_t002-srno = g_v.
MODIFY ig_t002 FROM wg_t002 TRANSPORTING SRNO.
ENDLOOP.
LOOP AT ig_t002 INTO wg_t002.
CLEAR WA_IT_FLDCAT.
MOVE SY-INDEX TO WA_COLNO.
CONCATENATE 'MD-' wg_t002-LAISO
WA_COLNO
INTO WA_FLNAME.
WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-SELTEXT = WA_FLNAME.
WA_IT_FLDCAT-INTLEN = 250.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
APPEND WA_IT_FLDCAT TO T_FLDCAT.
CLEAR wg_t002.
ENDLOOP.
LOOP AT ig_t002 INTO wg_t002.
CLEAR WA_IT_FLDCAT.
MOVE SY-INDEX TO WA_COLNO.
CONCATENATE 'BD-' wg_t002-LAISO
WA_COLNO
INTO WA_FLNAME.
WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-SELTEXT = WA_FLNAME.
WA_IT_FLDCAT-INTLEN = 250.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
APPEND WA_IT_FLDCAT TO T_FLDCAT.
CLEAR wg_t002.
ENDLOOP.
MOVE 'MATNR' TO WA_FLNAME.
WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-SELTEXT = 'Material No'.
WA_IT_FLDCAT-INTLEN = 18.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
INSERT WA_IT_FLDCAT INTO T_FLDCAT INDEX 1.
MOVE 'BEGRU' TO WA_FLNAME.
WA_IT_FLDCAT-FIELDNAME = WA_FLNAME.
WA_IT_FLDCAT-DATATYPE = 'CHAR'.
WA_IT_FLDCAT-SELTEXT = 'Authorization Group'.
WA_IT_FLDCAT-INTLEN = 4.
WA_IT_FLDCAT-TABNAME = '<FS_2>'.
INSERT WA_IT_FLDCAT INTO T_FLDCAT INDEX 2.
DESCRIBE TABLE T_FLDCAT LINES gv_li.
ASSIGN LT_DATA TO <FS_DATA>.
Creating the Dynamic Internal Table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = T_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>.
LOOP AT T_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-SELTEXT.
WA_IT_FLDCAT1-REF_TABNAME = 'MARC'.
APPEND WA_IT_FLDCAT1 TO T_FLDCAT1.
CLEAR : WA_IT_FLDCAT,WA_IT_FLDCAT1.
ENDLOOP.
ASSIGN LT_DATA1 TO <FS_DATA1>.
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = T_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>.
ENDFORM. " fieldcat
*& Form show
text
--> p1 text
<-- p2 text
FORM Display .
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
I_INTERFACE_CHECK = ' '
I_BYPASSING_BUFFER = ' '
I_BUFFER_ACTIVE = ' '
I_CALLBACK_PROGRAM = GV_REPID
I_CALLBACK_PF_STATUS_SET = 'PF_STATUS_SET'
I_CALLBACK_USER_COMMAND = 'USER_COMMAND'
I_CALLBACK_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_TOP_OF_PAGE = ' '
I_CALLBACK_HTML_END_OF_LIST = ' '
I_STRUCTURE_NAME =
I_BACKGROUND_ID = ' '
I_GRID_TITLE =
I_GRID_SETTINGS =
IS_LAYOUT = L_LT
IT_FIELDCAT = T_FLDCAT1[]
IT_EXCLUDING =
IT_SPECIAL_GROUPS =
IT_SORT =
IT_FILTER =
IS_SEL_HIDE =
I_DEFAULT = 'X'
I_SAVE = ' '
IS_VARIANT =
IT_EVENTS =
IT_EVENT_EXIT =
IS_PRINT =
IS_REPREP_ID =
I_SCREEN_START_COLUMN = 0
I_SCREEN_START_LINE = 0
I_SCREEN_END_COLUMN = 0
I_SCREEN_END_LINE = 0
I_HTML_HEIGHT_TOP = 0
I_HTML_HEIGHT_END = 0
IT_ALV_GRAPHICS =
IT_HYPERLINK =
IT_ADD_FIELDCAT =
IT_EXCEPT_QINFO =
IR_SALV_FULLSCREEN_ADAPTER =
IMPORTING
E_EXIT_CAUSED_BY_CALLER =
ES_EXIT_CAUSED_BY_USER =
TABLES
T_OUTTAB = <FS_2>
EXCEPTIONS
PROGRAM_ERROR = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
ENDFORM. " display
FORM PF_STATUS_SET USING RS_EXTAB TYPE SLIS_T_EXTAB.
SET PF-STATUS 'DISPLAY' .
ENDFORM. "PF_STATUS_SET
*& Form Name: user_command *
*& Form Desc: For Handling USER_COMMAND *
FORM USER_COMMAND USING IF_UCOMM TYPE SY-UCOMM
IS_SELFIELD TYPE SLIS_SELFIELD.
CASE IF_UCOMM.
WHEN 'DOWNLOAD'.
CALL FUNCTION 'POPUP_TO_CONFIRM'
EXPORTING
TITLEBAR = ' '
DIAGNOSE_OBJECT = ' '
TEXT_QUESTION = 'Data download to excel'
TEXT_BUTTON_1 = 'Ja'(001)
ICON_BUTTON_1 = ' '
TEXT_BUTTON_2 = 'Nein'(002)
ICON_BUTTON_2 = ' '
DEFAULT_BUTTON = '1'
DISPLAY_CANCEL_BUTTON = 'X'
USERDEFINED_F1_HELP = ' '
START_COLUMN = 25
START_ROW = 6
POPUP_TYPE =
IMPORTING
ANSWER =
TABLES
PARAMETER =
EXCEPTIONS
TEXT_NOT_FOUND = 1
OTHERS = 2
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
BIN_FILESIZE =
FILENAME = 'C:\Material-Text.xls'
FILETYPE = 'ASC'
APPEND = ' '
WRITE_FIELD_SEPARATOR = 'X'
HEADER = '00'
TRUNC_TRAILING_BLANKS = 'X'
WRITE_LF = 'X'
COL_SELECT = ' '
COL_SELECT_MASK = ' '
DAT_MODE = 'X'
IMPORTING
FILELENGTH = GL_LENGHT
TABLES
DATA_TAB = <FS_22>
EXCEPTIONS
FILE_WRITE_ERROR = 1
NO_BATCH = 2
GUI_REFUSE_FILETRANSFER = 3
INVALID_TYPE = 4
NO_AUTHORITY = 5
UNKNOWN_ERROR = 6
HEADER_NOT_ALLOWED = 7
SEPARATOR_NOT_ALLOWED = 8
FILESIZE_NOT_ALLOWED = 9
HEADER_TOO_LONG = 10
DP_ERROR_CREATE = 11
DP_ERROR_SEND = 12
DP_ERROR_WRITE = 13
UNKNOWN_DP_ERROR = 14
ACCESS_DENIED = 15
DP_OUT_OF_MEMORY = 16
DISK_FULL = 17
DP_TIMEOUT = 18
FILE_NOT_FOUND = 19
DATAPROVIDER_EXCEPTION = 20
CONTROL_FLUSH_ERROR = 21
OTHERS = 22
IF SY-SUBRC <> 0.
MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF GL_LENGHT NE 0.
MESSAGE S398(00) WITH 'DATA downloaded to EXCEL'.
ENDIF.
ENDCASE.
ENDFORM. "user_command
Thanks -
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. -
Populate Final internal table from Dynamic internal table
Hello,
I have ti display data in ALV grid whose structure is fixed. I am dynamically selecting data iin an internal table.
Now from this dynamic internal table, i need to populate my final internal table whose structurte is fixed.
Please help.
Rgds,
HimanshuHello Himanshu,
When you say dynamic internal table there are two things one is the actual structure and other one is field table that holds information for all the fields used to create dynamic internal table.
No if you want to move data from dynamic table to fixed internal table then you can try as follows:
1.
field-symbols <field_name> TYPE C.
field-symbols <field_value> TYPE C.
Now you either use
LOOP AT fields_itab.
ASSIGN fields_itab-fieldname to <field_name>.
ASSIGN COMPONENT <field_name> OF STRUCTURE <structure_name> TO <field_value>
Now you move value from <field_value> to required field in fixed internal table.
i.e.
itab-fieldname = <field_value>.
Other way to do this:
If you fields order is constant then you can also use index in assign component statement.
do <no_of_fields> times.
ASSIGN COMPONENT sy-index OF STRUCTURE <structure_name> TO <field_value>.
rest is same as first method.
Hope this help!
I have given sudo code and you need to work on it little.
Thanks,
Augustin. -
Data allocation for internal table rows Dynamically
Hi Friends
I have requirement like below:
I have one internal table with 400 amounts columns, I will get the value from another program
that indicates to which column I have to add the values. I dont want to write the case statement
because I need to write 400 WHEN statements.
Is there any alternative way dynamically I can choose the internal table column and assign the value which
I am getting from external program.
Please help on this as soon as possible.
Points will be rewarded
Thanks
PraveenHi Praveen,
you may use the ASSIGN COMPONENT ... OF STRUCTURE ... statement.
It allows to assign the field by name or by sequence.
Assume you columns have names like amount_001 to amount_999 and are fields of structure ls_amounts. The do as decribed here roughly:
data:
lv_fieldseq type NUMC_3,
lv_fieldname type fieldname,
lv_amount type (???).
fieldsymbols:
<amount> type any.
* fetch amount and field sequence from external data into lv_amount and lv_fieldseq
concatenate 'AMOUNT_' lv_fieldseq into lv_fieldname.
* <amount> is something like a pointer
assign component (lv_fieldname) of structure ls_amounts to <amount>.
add lv_amount to <amount>.
if you are sure you have the correct position of the amount field in the structure stored in variable lv_position, you may use
assign component lv_position of structure ls_amounts to <amount>.
I prefer the ASSIGN (fieldname) for reasons of more transparency and less danger in case of structural changes.
Regards,
Clemens
Regards,
Clemens -
Dynamic internal table and dynamic read statements.
Hi,
My Scenario :
I have two dynamic internal tables.
I am looping at one internal table and trying to read another table.
In the read statement how do I mention the key dyamically.
Example code below :
LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
read second dynamic internal table.
enloop.
The key which I want use for reading say it is keyed in the selection criteria....
Also based on the value I read I want to modify the first internal table field value.
Remember I dont want to explicity mention the key
How do I do that?
Thanks
Krishna.Hi
U need to use the field-symbol, but u can't use a WHERE option, but u need to use the CHECK statament into the second loop:
LOOP AT <dyn_table> ASSIGNING <dyn_wa>.
LOOP AT <DYN_TABLE2> ASSIGNING <DYN_WA2>.
ASSIGN COMPONENT <COMPONENT> OF STRUCTURE <DYN_WA2> TO <FS>.
CHECK <FS> IN (=) .......
ASSIGN COMPONENT <COMPONENT> OF STRUCTURE <DYN_WA> TO <FS2>.
<FS2> = .......
EXIT.
ENDLOOP.
ENDLOOP.
Max -
Moving data from internal table to Dynamic internal table
Hello All,
I am facing a problem i moving the data from a internal table data to Dyn. internal table.
My code is as follows
*******Declartion**************************************
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
IS_FIELDCAT LIKE LINE OF IT_FIELDCAT.
DATA: IT_OUTTAB TYPE STANDARD TABLE OF ZVTEST.
DATA: WA_OUTTAB TYPE ZVTEST.
DATA: LV_LINE LIKE SY-TABIX,
COUNT TYPE I.
FIELD-SYMBOLS: <NEW_TABLE> TYPE REF TO DATA.
FIELD-SYMBOLS: <L_TABLE> TYPE ANY TABLE,
<L_LINE> TYPE ANY.
FIELD-SYMBOLS: <L_FIELD> TYPE ANY.
FIELD-SYMBOLS: <FS_DATA> TYPE REF TO DATA,
<FS_1> TYPE ANY TABLE,
<FS_2>,
<FS_3>.
DATA: NEW_LINE TYPE REF TO DATA.
DATA: LT_DATA TYPE REF TO DATA.
ASSIGN LT_DATA TO <FS_DATA>.
Create a new Table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCAT
IMPORTING
EP_TABLE = <FS_DATA>
EXCEPTIONS
GENERATE_SUBPOOL_DIR_FULL = 1
OTHERS = 2.
IF SY-SUBRC = 0.
ASSIGN <FS_DATA>->* TO <FS_1>.
CREATE DATA NEW_LINE LIKE LINE OF <FS_1>.
A field-symbol to access that work area
ASSIGN NEW_LINE->* TO <FS_2>.
LOOP AT IT_OUTTAB INTO WA_OUTTAB.
MOVE-CORRESPONDING WA_OUTTAB TO <FS_1>.
ENDLoop.
But when I am using MOVE-CORRESPONDING WA_OUTTAB TO <FS_1>.
I am getting the error like
"<FS_1>" is not a structure or internal table with header line.
Please check the code and tell where I am making the mistake.
Regards,
VasanthHello Rich ,
My is code is as below..
Declaration:
DATA: IT_FIELDCAT TYPE LVC_T_FCAT,
IS_FIELDCAT LIKE LINE OF IT_FIELDCAT.
DATA: BEGIN OF IT_OUTTAB OCCURS 0,
PSPID LIKE PROJ-PSPID, "Projektdefinition
POSID LIKE PRPS-POSID, "PSP-Element
POST1 LIKE PRPS-POST1, "Kurzbeschreibung
STTXT_INT LIKE CNJ_STAT-STTXT_INT, "Systemstatus
STTXT_EXT LIKE CNJ_STAT-STTXT_EXT, "Anwenderstatus
END OF IT_OUTTAB.
DATA: WA_OUTTAB LIKE IT_OUTTAB.
DATA: LV_LINES LIKE SY-TABIX,
COUNT TYPE I.
FIELD-SYMBOLS: type any.
DATA: NEW_LINE TYPE REF TO DATA.
DATA: LT_DATA TYPE REF TO DATA.
G_R_DISP_VARIANT-REPORT = SY-REPID.
G_R_DISP_VARIANT-VARIANT = PA_VAR.
CALL FUNCTION 'REUSE_ALV_VARIANT_SELECT'
EXPORTING
I_DIALOG = 'N'
I_USER_SPECIFIC = 'A'
I_DEFAULT = 'X'
IT_DEFAULT_FIELDCAT = G_T_FIELDCAT
I_LAYOUT = G_R_LAYOUT
IMPORTING
ET_FIELDCAT = G_T_FIELDCAT
et_sort = l_tab_sort
et_filter = l_tab_filter
ES_LAYOUT = G_R_LAYOUT
CHANGING
CS_VARIANT = G_R_DISP_VARIANT
EXCEPTIONS
ERROR_MESSAGE = 4
OTHERS = 4.
LOOP AT G_T_FIELDCAT INTO G_R_FIELDCAT WHERE NO_OUT IS INITIAL
AND TECH IS INITIAL.
MOVE-CORRESPONDING G_R_FIELDCAT TO IS_FIELDCAT.
IS_FIELDCAT-FIELDNAME = G_R_FIELDCAT-FIELDNAME.
IS_FIELDCAT-INTTYPE = G_R_FIELDCAT-INTTYPE.
IS_FIELDCAT-OUTPUTLEN = G_R_FIELDCAT-OUTPUTLEN.
IS_FIELDCAT-REF_FIELD = G_R_FIELDCAT-FIELDNAME.
IS_FIELDCAT-REF_TABLE = G_R_FIELDCAT-REF_TABNAME.
APPEND IS_FIELDCAT TO IT_FIELDCAT.
ENDLOOP.
DATA: WA_LISTE LIKE P_T_LISTE.
CLEAR:IT_OUTTAB.
REFRESH: IT_OUTTAB.
LOOP AT P_T_LISTE INTO WA_LISTE.
WA_OUTTAB-PSPID = WA_LISTE-PSPID .
WA_OUTTAB-POSID = WA_LISTE-POSID.
WA_OUTTAB-POST1 = WA_LISTE-POST1.
WA_OUTTAB-STTXT_INT = WA_LISTE-STTXT_INT.
WA_OUTTAB-STTXT_EXT = WA_LISTE-STTXT_EXT.
APPEND WA_OUTTAB TO IT_OUTTAB.
ENDLOOP.
**dynamic table creation for data
ASSIGN LT_DATA TO .
Create a new Table
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCAT
IMPORTING
EP_TABLE = .
A field-symbol to access that work area
ASSIGN NEW_LINE->* TO = WA_OUTTAB-PSPID.
ASSIGN COMPONENT 'POSID' OF STRUCTURE WA_OUTTAB TO <FS_3>.
ASSIGN COMPONENT 'POSID' OF STRUCTURE = WA_OUTTAB-POSID.
ASSIGN COMPONENT 'POST1' OF STRUCTURE WA_OUTTAB TO <FS_3>.
ASSIGN COMPONENT 'POST1' OF STRUCTURE .
<FS_5> = <FS_3>.
= WA_OUTTAB-POST1.
ASSIGN COMPONENT 'STTXT_INT' OF STRUCTURE WA_OUTTAB TO <FS_3>.
ASSIGN COMPONENT 'STTXT_INT' OF STRUCTURE TO P_FILE.
ENDLOOP.
ELSE.
MESSAGE E041(S9) WITH P_FILE.
ENDIF.
CLOSE DATASET P_FILE.
Here my problem is ´´, I am not able to use move corresponding statement.
So I am not getting the exact values to the fields of the dynamic table...
Please check it and give me a solution,
Regards,
Vasanth -
Dynamic Internal Table with Dynamic Fields
Hi all,
My scenario is fairly simple----
--> End user clicks a button on screen and he gets the list of HR tables.
--> Then selects a table and list of all the fields for that table gets displayed.
--> He/she selects the fields they want data to be retrieved for.
So, the requirement is, the dynamic internal table should get created with the fields selected.
The select statement should only retrieve fields which were selected by the end user
and from the table selected by the end user.
I believe the fields selected by end user can be passed by a variable of type string.
something like this---
select (fields)
from (p_table) " Table selected by end user
into dynamic internal table. " should contain columns selected by end user"
Appreciate your inputs and guidance.
Warm regards,
Hari KiranTYPE-POOLS :ABAP.
Parameters P_TAB TYPE DDOBJNAME.
DATA : GO_LINE_TYPE TYPE REF TO CL_ABAP_STRUCTDESCR,
GO_TABLE_DESC TYPE REF TO CL_ABAP_TABLEDESCR,
GS_COMPONENTS TYPE ABAP_COMPONENTDESCR,
GT_COMPONENTS TYPE ABAP_COMPONENT_TAB,
GR_TAB TYPE REF TO DATA,
GT_FIELDS TYPE TABLE OF DFIES WITH HEADER LINE.
FIELD-SYMBOLS: <GT_TABLE> TYPE TABLE,
<GS_TABLE> TYPE ANY,
<GV_VALUE> TYPE ANY.
CALL FUNCTION 'DDIF_FIELDINFO_GET'
EXPORTING
TABNAME = P_TAB
* FIELDNAME = ' '
* LANGU = SY-LANGU
* LFIELDNAME = ' '
* ALL_TYPES = ' '
* GROUP_NAMES = ' '
* UCLEN =
* IMPORTING
* X030L_WA =
* DDOBJTYPE =
* DFIES_WA =
* LINES_DESCR =
TABLES
DFIES_TAB = GT_FIELDS
* FIXED_VALUES =
EXCEPTIONS
NOT_FOUND = 1
INTERNAL_ERROR = 2
OTHERS = 3.
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
LOOP AT GT_FIELDS.
CLEAR GS_COMPONENTS.
GS_COMPONENTS-NAME = GT_FIELDS-FIELDNAME.
GS_COMPONENTS-TYPE ?= CL_ABAP_STRUCTDESCR=>DESCRIBE_BY_NAME( GT_FIELDS-ROLLNAME ).
APPEND GS_COMPONENTS TO GT_COMPONENTS.
ENDLOOP.
GO_LINE_TYPE = CL_ABAP_STRUCTDESCR=>CREATE( GT_COMPONENTS ).
GO_TABLE_DESC = CL_ABAP_TABLEDESCR=>CREATE( GO_LINE_TYPE ).
CREATE DATA: GR_TAB TYPE HANDLE GO_TABLE_DESC.
ASSIGN: GR_TAB->* TO <GT_TABLE>.
SELECT * FROM (P_TAB) APPENDING CORRESPONDING FIELDS OF TABLE <GT_TABLE>.
LOOP AT <GT_TABLE> ASSIGNING <GS_TABLE>.
NEW-LINE.
DO.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <GS_TABLE> TO <GV_VALUE>.
IF SY-SUBRC NE '0'.
EXIT.
ENDIF.
WRITE : <GV_VALUE>.
ENDDO.
ENDLOOP. -
Populating data into internal table created dynamically
Hi all,
I have created an internal table dynamically using the method
CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE
EXPORTING
IT_FIELDCATALOG = IT_FIELDCAT2[]
IMPORTING
EP_TABLE = L_TABLE.
ASSIGN L_TABLE->* TO <IT_TABLE>.
CREATE DATA wa_table LIKE LINE OF <it_table>.
ASSIGN wa_table->* TO <wa_table1>.
when I tried to append data into the internal table <it_table>
as below
ex : <wa_table1>-prueflos = wa_item-prueflos.
it is giving the error as 'The data object <wa_table1> has no structure therefore no component called prueflos'.
can anybody tell me how to append data into a dynamically created internal table.
Thanks,
SudheerHi Sudheer,
You need to use the ASSIGN COMPONENT command for this purpose. Check this code:
FIELD-SYMBOLS: <t_dyntable> TYPE STANDARD TABLE, u201C Dynamic internal table name
<fs_dyntable>, u201C Field symbol to create work area
<fs_fldval> type any. u201C Field symbol to assign values
* Assume your internal table has fields COL1, COL2, COL3 etc
DO p_cols TIMES.
index = sy-index.
MOVE sy-index TO wa_colno.
CONCATENATE 'COL'
wa_colno
INTO wa_flname.
* Set up fieldvalue
CONCATENATE 'VALUE' index INTO
fieldvalue.
CONDENSE fieldvalue NO-GAPS.
ASSIGN COMPONENT wa_flname
OF STRUCTURE <fs_dyntable> TO <fs_fldval>.
<fs_fldval> = fieldvalue.
ENDDO.
Hope this solves your problem!
Cheers,
Shailesh.
Maybe you are looking for
-
Fbl5n report showing pritn output for a new customer on a new page
Hello All, In fbl5n when i execute for all the customers and give print command its printing every new customer on a new page but i want to print the data continously. Pls let me knw how to avoid this? Sunny
-
Hi! I have a nokia 5530 xpressmusic and I have a problem.I can't acces Ovi.I can see just the image with ovi nokia and this is all.I think I have some viruses.what do you think? thank you! Solved! Go to Solution.
-
Hi, While performing cross domain SSO using SAML2.0 between the Oracel Identity Federation(IdP) and Novell Access Manager(SP). The connection between the both is in open mode and havent enabled SSO between the two. In the Idp end and the SP end, meta
-
Engineering Software on MacBook Air, help?
Hey there! I want to buy a new laptop easy to travel with (because I'll be taking it to college everyday) and people keep telling me I should a MacBook Air because it's light and it does everything. Unfortunately, I'm concerned about: 1. I need to in
-
how to search in ipad ios 7