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
Praveen
Hi 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
Similar Messages
-
Date conversion for internal table
Hi experts,
I have an issue with Date conversion.
i have declared my internal table with type same as that of standard table from which im fetching data.
The date is coming in YYYYMMDD format and i have to change it to MM/DD/YYYY format.
I tried using a function Module and used Mask as well . It is working but wen im putting the value back into my internal table it is truncating my conver sion .
For eg : 20110530 after conversion and wen im putting it back to internal table value is : 05/30/20
bacuse of length issue "11" disappeared.
I tried changing the type declaration of my internal table to : date(10) type c.
But wen im executing the code, the place were im putting the values from my standard table to internal, it is giving run time error.
can anyonenhelp me with this?Hi,
Why not have the date in MMDDYYYY format truncating the '/' part. Doing this would reduce the size to 8. Which can later be added in any field level rotine.
Regards
Raj Rai
Edited by: Raj Rai on Jun 1, 2011 5:48 AM -
Adding Specific columns of dynamic internal table row into another column
Hi Gurus,
I need to add few columns of a dynamic internal table row into another column:
Article description hy01 hy02 total
101 panza 10 12 22
102 masht 12 12 24
dynamic internal table is created and columns hy01 hy02.... can increase
How to add the the values in hy01 hy 02... into total.
Regards,
DepHi,
If you really want to have a dynamic table, then you will have to find a way to generate a whole new table, and then copy the data from the old table to the new one. There is no way to modify a type during runtime in ABAP.
Here an example how to generate a dynamic table based on another internal table, hope this will help you.
TYPE-POOLS: slis.
PARAMETERS: p_nb_hy TYPE i DEFAULT 2. "Number of new HY columns to be added
* Type ZST_T:
* matnr TYPE matnr
* maktx TYPE maktx
* hy01 TYPE i
* total TYPE i
TYPES: ty_t TYPE STANDARD TABLE OF zst_s.
PERFORM main.
*& Form main
* text
FORM main.
DATA: lt_fieldcat TYPE slis_t_fieldcat_alv,
lt_t TYPE ty_t,
lr_new_t TYPE REF TO data.
FIELD-SYMBOLS: <lt_new_t> TYPE STANDARD TABLE.
"Add some lines to LT_T just to have something to display on screen
DO 10 TIMES.
APPEND INITIAL LINE TO lt_t.
ENDDO.
CALL FUNCTION 'REUSE_ALV_FIELDCATALOG_MERGE'
EXPORTING
i_structure_name = 'ZST_S'
CHANGING
ct_fieldcat = lt_fieldcat.
"Copy LT_T to LR_NEW_T
PERFORM extend_and_copy_table USING lt_t p_nb_hy CHANGING lr_new_t lt_fieldcat.
CLEAR lt_t. "Not needed anymore...
ASSIGN lr_new_t->* TO <lt_new_t>.
CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
EXPORTING
it_fieldcat = lt_fieldcat
TABLES
t_outtab = <lt_new_t>.
ENDFORM. "main
*& Form extend_and_copy_table
FORM extend_and_copy_table USING ut_t TYPE STANDARD TABLE
uv_nb_hy TYPE i
CHANGING cr_t TYPE REF TO data
ct_fieldcat TYPE slis_t_fieldcat_alv
RAISING cx_sy_struct_creation cx_sy_table_creation.
DATA: lo_tabledescr TYPE REF TO cl_abap_tabledescr,
lo_structdescr TYPE REF TO cl_abap_structdescr,
lo_new_structdescr TYPE REF TO cl_abap_structdescr,
lo_new_tabledescr TYPE REF TO cl_abap_tabledescr,
lt_components TYPE cl_abap_structdescr=>component_table,
ls_component TYPE cl_abap_structdescr=>component,
lv_field_cnt TYPE numc2,
ls_fieldcat TYPE slis_fieldcat_alv,
lr_fieldcat TYPE REF TO slis_fieldcat_alv.
FIELD-SYMBOLS: <ls_old_s> TYPE ANY,
<lt_new_t> TYPE STANDARD TABLE,
<ls_new_s> TYPE ANY.
"Get the list of all components from UT_T line structure
lo_tabledescr ?= cl_abap_tabledescr=>describe_by_data( ut_t ).
lo_structdescr ?= lo_tabledescr->get_table_line_type( ).
lt_components = lo_structdescr->get_components( ).
"The new columns will be from type of column HY01
ls_component-type = lo_structdescr->get_component_type( 'HY01' ).
"The new columns will have the same fieldcat info as column HY01
READ TABLE ct_fieldcat INTO ls_fieldcat WITH KEY fieldname = 'HY01'.
"HY<lv_field_cnt> = new field name
lv_field_cnt = uv_nb_hy + 1.
"For each new column...
DO uv_nb_hy TIMES.
"Generate the new column field name
CONCATENATE 'HY' lv_field_cnt INTO ls_component-name.
ls_fieldcat-fieldname = ls_component-name.
"Add the new field to the components of the new structure
INSERT ls_component INTO lt_components INDEX 4.
"Add the new field's fieldcat info to the fieldcat
INSERT ls_fieldcat INTO ct_fieldcat INDEX 4.
lv_field_cnt = lv_field_cnt - 1.
ENDDO.
"Adjust the COL_POS from fieldcat
LOOP AT ct_fieldcat REFERENCE INTO lr_fieldcat.
lr_fieldcat->col_pos = sy-tabix.
ENDLOOP.
"Create the new table
lo_new_structdescr = cl_abap_structdescr=>create( p_components = lt_components ).
lo_new_tabledescr = cl_abap_tabledescr=>create( p_line_type = lo_new_structdescr ).
CREATE DATA cr_t TYPE HANDLE lo_new_tabledescr.
ASSIGN cr_t->* TO <lt_new_t>.
"Copy all data from old to new table
LOOP AT ut_t ASSIGNING <ls_old_s>.
APPEND INITIAL LINE TO <lt_new_t> ASSIGNING <ls_new_s>.
MOVE-CORRESPONDING <ls_old_s> TO <ls_new_s>.
ENDLOOP.
ENDFORM. "main -
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 -
Filling dynamic internal table with data from other internal table
Hi Friends,
My problem is that i have already built a dynamic internal table
(class int_table->create) but now i want to fill it with data from other internal table.
The dynamic table column name and the field value of the data filled internal table are same, but how to access that column name, since i cant hard code it anyway.
Like if my werks field value is '8001'. I want to place it under the column 8001 of dynamic table, Can anybody help me in this regard?
Awarding points is not a problem for even giving a slight hint.
Best RegardsHi
See this
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.
Reward if useful
Anji -
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. -
How to send multiple row data into an internal table??
I have a view with table control.i want to select multiple row and send all the row data into an internal table.i am able to select multiple row but all the selected row data is not going to the internal table.....only a particular row data which is lead selected is going.
Do anyone can help me regarding this issue?
Thanks in advance,
Subhasis.Hey,
Some code example:
declaring an internal table and work area to get all the elements from the node.
data : lt_Elements type WDR_CONTEXT_ELEMENT_SET,
ls_Element type WDR_CONTEXT_ELEMENT_SET,
considering flights is my node.
lt_data type sflight.
Node_Flights is the ref of the node to which ur table is binded.
Use Code Inspector to read the node.
lt_Element = Node_Flights->GET_ELEMENTS
loop at lt_elements into ls_Element.
l_bollean = ls_elements->is_selected ( returns abap true/false ).
if l_bollean IS INITIAL.
append ls_Element to lt_data.
endif.
Hope this would help.
Cheers,
Ashish -
How to copy data from one internal table to another
i am using some function module to get some data for my function module
and the retrieved data is not getting populated in mu fumctional module
i am sucessful in getting the data to an internal table in my function module but dont know how to pass it to my table parameter
thanks in advanceHi Naval,
Declare an internal table of type table parameter structure and pass it the table parameters of the Function module.
Check the code for this function module.
DATA IT_MARA LIKE MARA OCCURS 0 WITH HEADER LINE.
SELECT * FROM MARA UP TO 10 ROWS INTO TABLE IT_MARA.
CALL FUNCTION 'GUI_DOWNLOAD'
EXPORTING
FILENAME = 'C:\TEST.TXT'. FILETYPE = 'ASC'
WRITE_FIELD_SEPARATOR = 'X'
<b> TABLES
DATA_TAB = IT_MARA</b>
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.
Thanks,
Vinay -
Query statement for internal table
is it possible to use a select statement to select data from an internal table? if yes, can anyone show me the codes to it? thx
Hi Daphne,
You use SELECT statement to read data from database table but not from Internal table.
For reading data from Internal table, you have to use READ statement.
Syntax:
READ TABLE itab { table_key
| free_key
| index } result.
Effect of using read statement:
This statement reads a row from internal table itab. You have to specify the row by either naming values table_key for the table key, a free condition free_key or an index index. The latter choice is possible only for index tables. The output result result determines when and where the row contents are read.
If the row to be read is not uniquely specified, the first suitable row is read. In the case of index tables, this row has the lowest table index of all matching rows.
Reward if usefull
thanks
swaroop -
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. -
SELECT-OPTIONS sel FOR Internal Table
Hello,
I would like to use select-options. Normally you can specify a selection tab (sel) and a row of an table being registered in the ABAP dictionary.
I would like to use an internal table instead.
First I read data into the internal table. Next I would refer on one column of that internal using the select-options:
SELECT * FROM database-tab INTO itab
WHERE key1 = 'a'.
SELECT-OPTIONS: sel FOR itab.
It does not work, although the internal table is filled!!!
Can I use internal tables with select-options?
thx, holgerHallo Holger,
i think i get it now - thanks Amit !
here's an example:
AT SELECTION-SCREEN ON VALUE-REQUEST FOR matnr-low.
SELECT matnr maktg FROM m_mat1t
INTO CORRESPONDING FIELDS OF TABLE f4_itab
WHERE mtart = 'DIEN'.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield = 'MATNR'
dynpprog = sy-repid
dynpnr = sy-dynnr
dynprofield = 'MATNR'
window_title = 'select material no.'
value_org = 'S'
TABLES
value_tab = f4_itab[].
Andreas -
Passing data to different internal tables with different columns from a comma delimited file
Hi,
I have a program wherein we upload a comma delimited file and based on the region( we have drop down in the selection screen to pick the region). Based on the region, the data from the file is passed to internal table. For region A, we have 10 columns and for region B we have 9 columns.
There is a split statement (split at comma) used to break the data into different columns.
I need to add hard error messages if the no. of columns in the uploaded file are incorrect. For example, if the uploaded file is of type region A, then the uploaded file should be split into 10 columns. If the file contains lesser or more columns thenan error message should be added. Similar is the case with region B.
I do not want to remove the existing split statement(existing code). Is there a way I can exactly pass the data into the internal table accurately? I have gone through some posts where in they have made use of the method cl_alv_table_create=>create_dynamic_table by passing the field catalog. But I cannot use this as I have two different internal tables to be populated based on the region. Appreciate help on this.
Thanks,
PavanHi Abhishek,
I have no issues with the rows. I have a file with format like a1,b1,c1,d1,e1, the file should be uploaded and split at comma. So far its fine. After this, if the file is related to region A say Asia, then it should have 5 fields( as an example). So, all the 5 values a1,b1..e1 will be passed to 5 fields of itab1.
I also have region B( say Europe) whose file will have only 4 fields. So, file is of the form a2,b2,c2,d2. Again data is split at comma and passed to itab2.
If some one loads file related to Asia and the file has only 4 fields then the data would be incorrect. Similar is the case when someone tries to load Europe file with 5 fields related data. To avoid this, I want to validate the data uploaded. For this, I want to count the no. of fields (seperated by comma). If no. of fields is 5 then the file is related to Asia or if no. of fields is 4 then it is Europe file.
Well, the no. of commas is nothing but no. of fields - 1. If the file is of the form a1,b1..e1 then I can say like if no. of commas = 4 then it is File Asia.But I am not sure how to write a code for this.Please advise.
Thanks,
Pavan -
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 -
Data types in internal tables.
Examples for LINE & KEY.
Mithun,
Internal Tables as Data Types
Internal tables and structures are the two structured data types in ABAP. The data type of an internal table is fully specified by its line type, key, and table type.
Line type
The line type of an internal table can be any data type. The data type of an internal table is normally a structure. Each component of the structure is a column in the internal table. However, the line type may also be elementary or another internal table.
Key
The key identifies table rows. There are two kinds of key for internal tables - the standard key and a user-defined key. You can specify whether the key should be UNIQUE or NON-UNIQUE. Internal tables with a unique key cannot contain duplicate entries. The uniqueness depends on the table access method.
If a table has a structured line type, its default key consists of all of its non-numerical columns that are not references or themselves internal tables. If a table has an elementary line type, the default key is the entire line. The default key of an internal table whose line type is an internal table, the default key is empty.
The user-defined key can contain any columns of the internal table that are not references or themselves internal tables. Internal tables with a user-defined key are called key tables. When you define the key, the sequence of the key fields is significant. You should remember this, for example, if you intend to sort the table according to the key.
Pls. reward if useful -
How to join two internal table rows in alternative manner into one internal table?
How to join two internal table rows in alternative manner into one internal table?
two internal tables are suppose itab1 & itab2 & its data
Header 1
Header 2
Header 3
a
b
c
d
e
f
g
h
i
Header 1
Header 2
Header 3
1
2
3
4
5
6
7
8
9
INTO itab3 data
Header 1
Header 2
Header 3
a
b
c
1
2
3
d
e
f
4
5
6
g
h
i
7
8
9Hi Soubhik,
I have added two additional columns for each internal table.
Table_Count - It represents the Internal Table Number(ITAB1 -> 1, ITAB2 -> 2)
Row_Count - It represents the Row Count Number, increase the row count value 1 by one..
ITAB1:
Header 1
Header 2
Header 3
Table_Count
Row_Count
a
b
c
1
1
d
e
f
1
2
g
h
i
1
3
ITAB2:
Header 1
Header 2
Header 3
Table_Count
Row_Count
1
2
3
2
1
4
5
6
2
2
7
8
9
2
3
Create the Final Internal table as same as the ITAB1/ITAB2 structure.
"Data Declarations
DATA: IT_FINAL LIKE TABLE OF ITAB1. "Final Internal Table
FIELD-SYMBOLS: <FS_TAB1> TYPE TY_TAB1, "TAB1
<FS_TAB2> TYPE TY_TAB2. "TAB2
"Assign the values for the additional two column for ITAB1
LOOP AT ITAB1 ASSIGNING <FS_TAB1>.
<FS_TAB1>-TABLE_COUNT = 1. "Table value same for all row
<FS_TAB1>-ROW_COUNT = SY-TABIX. "Index value
ENDLOOP.
"Assign the values for the additional two column for ITAB2
LOOP AT ITAB2 ASSIGNING <FS_TAB2>.
<FS_TAB2>-TABLE_COUNT = 2. "Table value same for all row
<FS_TAB2>-ROW_COUNT = SY-TABIX. "Index value
ENDLOOP.
"Copy the First Internal Table 'ITAB1' to Final Table
IT_FINAL[] = ITAB1[].
"Copy the Second Internal Table 'ITAB2' to Final Table
APPEND IT
LOOP AT ITAB2 INTO WA_TAB2.
APPEND WA_TAB2 TO IT_FINAL.
ENDLOOP.
"Sort the Internal Table based on TABLE_COUNT & ROW_COUNT
SORT IT_FINAL BY ROW_COUNT TABLE_COUNT.
After sorting, check the output for IT_FINAL Table, you can find the required output as shown above.
Regards
Rajkumar Narasimman
Maybe you are looking for
-
Unable to Deploy a Webservice.
Hello All, I created a java bean and put the implemented code in some of the methods etc. ( By the way the code is generated using a WSDL using the SAP Netweaver libraries ) Now when I attempt to actually create the webservice out of the implemented
-
Hello, I am a user of the iPhone is not the place for bi çıkıcak turkey apple brand products and product support and equipment does not work as it used to fix and send back waiting for your help. Please support me in this regard quit
-
Error when Settling AuC to a Cost Center
HI All, Following err msg is occurring when i tried to settle an AuC to a cost center using the Tcode AIAB. 'Settlement of old asset data to a receiver type CTR is not allowed" In this asset there are line items belongs to current fiscal year as well
-
Terminal doesn't execute .profile
Hi all, I am trying to add a PATH input so that I don't have to keep using ./ for commands that aren't system-native. The problem is that bash doesn't seem to be executing any of the .profile commands. Thanks, Bradley
-
How can I make the player show the song's rating all the time?
I want to be able to see the rating of the song that is playing. I know I can open a menu that will show it, but I want to be always displayed in the player. How do I do this? also: I am trying to rate all the songs in my library. I have tried to