Define Field Symbols Dynamically
Hi,
Is it possible to define field symbols dynamically based on some naming convention? If yes, please let me know how to do that.
Thanks & Best Regards,
Kumar.
I have this code in a loop that does this
CONCATENATE 'TYPE' zlmltyp-ztext_key '_' zlmstyp-scrnseq
INTO wk_fldname.
CONCATENATE wk_fldname '-DATE' INTO fldname.
ASSIGN (fldname) TO <text_fld>.
<text_fld> = wa_zlmstat-erdat.
CONCATENATE wk_fldname '-CURR_STATUS' INTO fldname.
ASSIGN (fldname) TO <text_fld>.
IF wa_zlmstat-ltype = zlmlead-ltype
AND wa_zlmstat-status = zlmlead-status.
<text_fld> = 'X'.
ELSE.
CLEAR <text_fld>.
ENDIF.
the fields are defined like this
DATA:
BEGIN OF scrn_stat_rec,
ltype TYPE zlmltype,
status TYPE zlmstatus,
descrip TYPE zstypex,
date LIKE sy-datum,
curr_status TYPE c,
specstatdate TYPE z_scrn_date,
auth TYPE zlmauth,
END OF scrn_stat_rec,
type100_01 LIKE scrn_stat_rec,
type100_02 LIKE scrn_stat_rec,
type100_03 LIKE scrn_stat_rec,
type100_04 LIKE scrn_stat_rec,
type100_05 LIKE scrn_stat_rec,
type100_06 LIKE scrn_stat_rec,
type100_07 LIKE scrn_stat_rec,
type100_08 LIKE scrn_stat_rec,
type100_09 LIKE scrn_stat_rec,
type100_10 LIKE scrn_stat_rec,
type200_01 LIKE scrn_stat_rec,
*** all the way to
type600_09 LIKE scrn_stat_rec,
type600_10 LIKE scrn_stat_rec,
type700_01 LIKE scrn_stat_rec,
type700_02 LIKE scrn_stat_rec,
type700_03 LIKE scrn_stat_rec,
type700_04 LIKE scrn_stat_rec,
type700_05 LIKE scrn_stat_rec,
type700_06 LIKE scrn_stat_rec,
type700_07 LIKE scrn_stat_rec,
type700_08 LIKE scrn_stat_rec,
type700_09 LIKE scrn_stat_rec,
type700_10 LIKE scrn_stat_rec.
Similar Messages
-
Very Urgent: how to define field symbols in class using se24 Points assured
hi all
I am new to abap oo programming. I am using se24 to build a class
where some methods have code which involves working with field sybmols but i am not able to figure out way for how to define field symbols in the attributes section.
I tried defining like : fld_sym type ref to dbtab-fld
but in the method implementation if i try to use it like assign fld to <fld_sym> there it says fld_sym is not defined as a field symbol.
So can anyone please guide me how to define field symbols in se24.
Also what should be the general steps while creating a class using se24.
Points assured
thanksHi
Global classes are like Global fun modules in which the Methods and code is already written and is mainly used for Reusability purpose.
Goto SE24 tcode and see the std global classes like
CL_ABAP_CHAR_UTILITIES
see the links
chk out the links below:
General Tutorial for OOPS
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907
Have a look at these links for OO ABAP.
http://www.sapgenie.com/abap/OO/
http://help.sap.com/saphelp_nw04/helpdata/en/c3/225b5654f411d194a60000e8353423/content.htm
http://www.esnips.com/doc/375fff1b-5a62-444d-8ec1-55508c308b17/prefinalppt.ppt
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/5c65b0dd-eddf-4512-8e32-ecd26735f0f2/prefinalppt.ppt
http://www.allsaplinks.com/
http://www.sapgenie.com/abap/controls/index.htm
http://www.esnips.com/doc/2c76dc57-e74a-4539-a20e-29383317e804/OO-abap.pdf
http://www.esnips.com/doc/0ef39d4b-586a-4637-abbb-e4f69d2d9307/SAP-CONTROLS-WORKSHOP.pdf
http://help.sap.com/saphelp_erp2005/helpdata/en/ce/b518b6513611d194a50000e8353423/frameset.htm
SDN Series:
https://www.sdn.sap.com/irj/sdn/developerareas/abap?rid=/webcontent/uuid/35eaef9c-0b01-0010-dd8b-e3b0f9ed7ccb [original link is broken]
http://help.sap.com/printdocu/core/Print46c/en/data/pdf/BCABA/BCABA.pdf
Basic concepts of OOPS
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/b6cae890-0201-0010-ef8b-f970a9c41d47
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/1591ec90-0201-0010-3ba8-cdcd500b17cf
https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/abap/abap%20code%20samples/alv%20grid/abap%20code%20sample%20to%20display%20data%20in%20alv%20grid%20using%20object%20oriented%20programming.doc
http://www.henrikfrank.dk/abapuk.html
http://www.erpgenie.com/abap/OO/
Reward oints if useful,
Aleem. -
Building Field Symbols Dynamically
Hi All,
Has anyone tried to build field symbols dynamically? something like this...
DATA: field_symbol(13) TYPE c,
v_lines TYPE sy-tabix,
v_count(2) TYPE n.
FIELD-SYMBOLS: <f2> TYPE ANY.
DESCRIBE TABLE itab LINES v_lines.
DO v_lines TIMES.
v_count = v_count + 1.
CONCATENATE '<fs_new_sf' v_count '>' INTO field_symbol.
ASSIGN (field_symbol) TO <f2>.
CONCATENATE '<fs_new_sf' v_count '>' INTO field_symbol.
ASSIGN (field_symbol) TO <f2>.
ASSIGN COMPONENT v_sf01 OF STRUCTURE s_MARA TO <f2>.
ENDDO.
V_SF01 could be anything from MATNR to any field in table MARA.
Although the above code is correct syntactically, and though there is no program termination either.
the statement
ASSIGN (field_symbol) TO <f2>.
fails to assign the field symbol.
Thanks,
S-rayHi Sudheer,
There is a program termination because does not exist a field symbol called <fs_new_sf1> or <fs_new_sf2>... <fs_new_sfn> when you assign (field_symbol) TO <f2>.
You should look for Dymamic Type specification, something like this:
DATA: dref TYPE REF TO DATA.
FIELD-SYMBOLS: <dobject> TYPE any.
PERFORM declareData USING dref 'SFLIGHT'.
ASSIGN dref->* to <dobject>.
FORM declareData USING dref TYPE REF TO DATA
tname TYPE string.
Create a data object of type 'tname'
CREATE DATA dref TYPE (tname).
ENDFORM.
regards,
Alejandro. -
How to change the text of a user defined field in dynamic selections?
Logical Database PSJ is used by t code CJI3 - we added a couple of user fields into the dynamic selections of CJI3.
Now - how to change the text of this user filed (USR01 of structure PRSP_R in logical database PSJ)?
Found an OSS note - 86980 - that tells that this is not possible.
But when we read the documentation on the user field (CJI3 - dynamic selections - double click on user field - F1), it shows the following text:
User-defined field in which you can enter general information with a length of up to 20 characters.
Dependencies
The names (key words) for user-defined fields depend on the field key.
Now the question is where to change the field key..
Thanks,
VenMadhu - you did not get the question I think.
Anyways - I found an OSS note 1266643 - this code change should take care of the issue - it will then reflect the details maintained in custoizng at transaction code OPS1..
Thanks, -
Query in Optimal Coding - Assigning INT TAB to FIELD SYMBOLS dynamically.
TABLES: tkesk.
DATA: itkesk type table of tkesk.
DATA: BEGIN of itab_RP occurs 11,
tabname type string,
END of itab_RP.
DATA : wa_rp like line of itab_Rp,
wa_onemore like line of itkesk.
FIELD-SYMBOLS: <fs> LIKE itkesk.
ITAB_RP-tabname = 'ITKESK'.
APPEND ITAB_RP.
LOOP at ITAB_RP into wa_rp.
<i><b>*How to assign the table itkesk to the field symbol
*which is available in wa_rp dynamically instead of assigning it directly)</b></i>
*ASSIGN wa_rp-tabname to <fs>.
ASSIGN itkesk to <fs>.
LOOP at <fs> into wa_onemore.
WRITE : 'hi'.
endloop.
ENDLOOP.Is this even possible ?
Thanks
Mark -
Dynamic Field Symbols with Structures
Hello,
I am stuck on a piece of code and looking for some help. I am trying to figure out how to assign values in a structure of a dynamically defined field symbol to the structure inside another dynamically defined field symbol. Here is my code and some comments. Basically I am uploading data via a flatfile and placing it into a dynamically defined field symbol.
DATA:
lr_area TYPE REF TO cl_sem_planarea_attributes,
lr_t_data TYPE REF TO data,
lr_s_data TYPE REF TO data,
lr_s_chas TYPE REF TO data,
lr_s_kyfs TYPE REF TO data.
FIELD-SYMBOLS:
<lt_data> TYPE STANDARD TABLE,
<ls_data> TYPE ANY,
<ls_chas> TYPE ANY,
<ls_kyfs> TYPE ANY.
DATA: ls_chasel TYPE upc_ys_chasel,
ls_charng TYPE upc_ys_charng.
FIELD-SYMBOLS:
<f> TYPE ANY,
<chas> TYPE TABLE,
<kyfs> TYPE ANY.
CALL METHOD cl_sem_planarea_attributes=>get_instance
EXPORTING i_area = i_area
RECEIVING er_instance = lr_area.
CHECK sy-subrc = 0.
CREATE DATA lr_s_data TYPE (lr_area->typename_s_data).
ASSIGN lr_s_data->* TO <ls_data>.
CREATE DATA lr_t_data TYPE (lr_area->typename_t_data).
ASSIGN lr_t_data->* TO <lt_data>.
CREATE DATA lr_s_chas TYPE (lr_area->typename_s_chas).
ASSIGN lr_s_chas->* TO <ls_chas>.
CREATE DATA lr_s_kyfs TYPE (lr_area->typename_s_kyfs).
ASSIGN lr_s_kyfs->* TO <ls_kyfs>.
LOOP AT gt_file INTO ls_file.
CLEAR <ls_data>.
MOVE-CORRESPONDING ls_file TO <ls_kyfs>. " Map key figures
MOVE-CORRESPONDING ls_file TO <ls_chas>. " Map chars
* MOVE-CORRESPONDING ls_file TO <ls_data>. " Map data
* ASSIGN COMPONENT 'ls_chas' OF STRUCTURE <ls_Data> TO <chas> .
* IF sy-subrc = 0.
** <chas> = <ls_chas>.
*MOVE-CORRESPONDING <ls_chas> to <chas>.
* ENDIF.
<chas> = <ls_chas>.
LOOP AT <chas> INTO ls_chasel.
READ TABLE ls_chasel-t_charng INTO ls_charng INDEX 1.
IF sy-subrc = 0 AND ls_charng-option = 'EQ'.
ASSIGN COMPONENT ls_chasel-chanm OF STRUCTURE <ls_chas> TO <ls_data>.
IF sy-subrc = 0.
<ls_data> = ls_charng-low.
ENDIF.
ENDIF.
ENDLOOP.
COLLECT <ls_data> INTO <lt_data>.
ENDLOOP.
Ls_chasel has 2 components:
Chanm (a char 30 which contains the component’s name)
T_CHARNG (a table with values for chanm)
Ls_data has 2 components:
S_chas (a structure with a list of components and values – same list as would have)
S_kyfs (a structure with a list of components and values – same list as would have)
Lt_data is a table of ls_data
I need to get the data in ls_chas into the ls_chas structure of ls_data and the ls_kyfs data into the ls_kyfs structure of ls_chas and append ls_chas to lt_data. Anything that is commented out is something I tried that didn't work. RIght now I get a dump at the 'loop at <chas> into ls_chasel' that the field symbol is not assigned.
Thanks for your help!It looks like the the original poster didn't completely understand all he was doing. (This is why I always recommend getting an ABAP programmer in for what is, essentially, advanced ABAP programming, rather than someone "kind of familiar" with ABAP trying it - we're often available at very reasonable rates ).
It seems he's using ito_chasel to set the fixed values (which is in fact quite smart!). What isn't required, so far as I can tell without implementing, are any of the statements involving <ls_kyfs> or <ls_chas>.
The following should be sufficient (with the necessary declarations etc. - but really: omit <ls_kyfs> and <ls_chas> - I'm sure they're not needed and they confuse things).
" Go through the data from the flat file
LOOP AT gt_file INTO ls_file.
CLEAR <ls_data>.
" Transfer the characteristics
MOVE-CORRESPONDING ls_file TO <s_chas>.
" Transfer the key figure
MOVE-CORRESPONDING ls_file TO <s_kyfs>.
" Go through the fixed characteristic selections from the package
LOOP AT ito_chasel INTO ls_chasel.
" We only care about the first value (if there is one).
READ TABLE ls_chasel-s_charng INTO ls_charng INDEX 1.
" Check there is a first value and that it is fixed
CHECK sy-subrc IS INITIAL AND ls_charng EQ 'EQ'.
" Get access to that characteristic
FIELD-SYMBOLS <fixed_value> TYPE ANY.
ASSIGN COMPONENT ls_chasel-chanm OF STRUCTURE <s_chas> TO <fixed_value>.
" Make sure that it exists in the data structure
CHECK sy-subrc IS INITIAL.
" Set the value
<fixed_value> = ls_charng-low.
ENDLOOP.
COLLECT <ls_data> INTO <lt_data>.
ENDLOOP. -
Hello :i would like to ask one favor , how can i define a field symbol, that can recieve a dynamic variable
segment of code:
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fldcat
IMPORTING
ep_table = it_dynamic.
ASSIGN it_dynamic->* TO <dyn_table>.
CREATE DATA wa_dynamic LIKE line of <dyn_table>.
ASSIGN wa_dynamic->* TO <dyn_wa>. " this one 'wa_dynamic' i need to sent to <dyn_wa>
thanks a lotHI
GOOD
Generic Type Specification
The following types allow you more freedom when using actual parameters. The data object only needs to have the selection of attributes specified.
Typing
Check for data object
No type specification
TYPE ANY
All types of data object are accepted. The field symbol adopts all of the attributes of the data object.
TYPE C, N, P, or X
Only data objects with type C, N, P, or X are accepted. The field symbol adopts the field length and DECIMALS specification (type P) of the data object.
TYPE TABLE
The system checks whether the data object is a standard internal table. This is a shortened form of TYPE STANDARD TABLE (see below).
TYPE ANY TABLE
The system checks whether the data object is an internal table. The field symbol inherits all of the attributes (line type, table type, key) from the data object.
TYPE INDEX TABLE
The system checks whether the data object is an index table (standard or sorted table). The field symbol inherits all of the attributes (line type, table type, key) from the data object.
TYPE STANDARD TABLE
The system checks whether the data object is a standard internal table. The field symbol inherits all of the remaining attributes (line type, key) from the data object.
TYPE SORTED TABLE
The system checks whether the actual parameter is a sorted internal table. The field symbol inherits all of the remaining attributes (line type, key) from the data object.
TYPE HASHED TABLE
The system checks whether the actual parameter is a hashed internal table. The field symbol inherits all of the remaining attributes (line type, key) from the data object.
If you specify a type generically, remember that the attributes inherited by the field symbol from the program are not statically recognizable in the program. You can, at most, address them dynamically.
TYPES: BEGIN OF line,
col1 TYPE c,
col2 TYPE c,
END OF line.
DATA: wa TYPE line,
itab TYPE HASHED TABLE OF line WITH UNIQUE KEY col1,
key(4) TYPE c VALUE 'COL1'.
FIELD-SYMBOLS <fs> TYPE ANY TABLE.
ASSIGN itab TO <fs>.
READ TABLE <fs> WITH TABLE KEY (key) = 'X' INTO wa.
The internal table ITAB is assigned to the generic field symbol <FS>, after which it is possible to address the table key of the field symbol dynamically. However, the static address
READ TABLE <fs> WITH TABLE KEY col1 = 'X' INTO wa.
is not possible syntactically, since the field symbol does not adopt the key of table ITAB until runtime. In the program, the type specification ANY TABLE only indicates that <FS> is a table. If the type had been ANY (or no type had been specified at all), even the specific internal table statement READ TABLE <FS> would not have been possible.
If you adopt a structured type generically (a structure, or a table with structured line type), the individual components cannot be addressed in the program either statically or dynamically. In this case, you would have to work with further field symbols and the method of assigning structures component by component.
Specifying the Type Fully
When you use the following types, the technical attributes of the field symbols are fully specified. The technical attributes of the data objects must correspond to those of the field symbol.
Typing
Technical attributes of the field symbol
TYPE D, F, I, or T
The field symbol has the technical attributes of the predefined elementary type
TYPE <type>
The field symbol has the type <type>. This is a data type defined within the program using the TYPES statement, or a type from the ABAP Dictionary
TYPE REF TO <cif>|DATA
The field symbol is a reference variable for the class or interface <cif>, or for a data object.
TYPE LINE OF <itab>
The field symbol has the same type as a line of the internal table <itab> defined using a TYPES statement or defined in the ABAP Dictionary
LIKE <f>
The field symbol has the same type as an internal data object <f> or structure, or a database table from the ABAP Dictionary
When you use a field symbol that is fully typed, you can address its attributes statically in the program, since they are recognized in the source code. If you fully specify the type of a field symbol as a reference or structured data object, you can address it as you would the data object itself, once you have assigned an object to it. So, for example, you could address the components of a structure, loop through an internal table, or create an object with reference to a field symbol.
REPORT demo_field_symbols_type .
DATA: BEGIN OF line,
col1(1) TYPE c,
col2(1) TYPE c VALUE 'X',
END OF line.
FIELD-SYMBOLS <fs> LIKE line.
ASSIGN line TO <fs>.
MOVE <fs>-col2 TO <fs>-col1.
The field symbol <FS> is fully typed as a structure, and you can address its components in the program.
Attaching a structure to a field symbol
The STRUCTURE addition forces a structured view of the data objects that you assign to a field symbol.
FIELD-SYMBOLS <FS> STRUCTURE <s> DEFAULT <f>.
The structure <s> is either a structured local data object in the program, or a flat structure from the ABAP Dictionary. <f> is a data object that must be assigned to the field symbol as a starting field. However, this assignment can be changed later using the ASSIGN statement.
When you assign a data object to the field symbol, the system only checks that it is at least as long as the structure. You can address the individual components of the field symbol. It has the same technical attributes as the structure <s>.
If <s> contains components with type I or F, you should remember the possible effects of alignment. When you assign a data object to a field symbol with a structure, the data object must have the same alignment, otherwise a runtime error may result. In such cases, you are advised to assign such data objects only to structured field symbols, which retain the same structure as the field symbol at least over the length of the structure.
The STRUCTURE is obsolete; you should no longer use it. Field symbols defined using the STRUCTURE addition are a mixture of typed field symbols and a utility for casting to either local or ABAP Dictionary data types. If you want to define the type of a field symbol, include the TYPE addition in a FIELD-SYMBOLS statement. If you want to use casting, include the CASTING addition in an ASSIGN statement.
Example using the obsolete STRUCTURE addition:
DATA: wa(10) VALUE '0123456789'.
DATA: BEGIN OF line1,
col1(3),
col2(2),
col3(5),
END OF line1.
DATA: BEGIN OF line2,
col1(2),
col2 LIKE sy-datum,
END OF line2.
FIELD-SYMBOLS: <f1> STRUCTURE line1 DEFAULT wa,
<f2> STRUCTURE line2 DEFAULT wa.
WRITE: / <f1>-col1, <f1>-col2, <f1>-col3,
/ <f2>-col1, <f2>-col2.
Example using the correct syntax (TYPE and CASTING):
DATA: wa(10) VALUE '0123456789'.
DATA: BEGIN OF line1,
col1(3),
col2(2),
col3(5),
END OF line1.
DATA: BEGIN OF line2,
COL1(2),
COL2 LIKE sy-datum,
END OF line2.
FIELD-SYMBOLS: <f1> LIKE line1.
ASSIGN wa TO <f1> CASTING.
FIELD-SYMBOLS: <f2> LIKE line2.
ASSIGN wa TO <f2> CASTING.
WRITE: / <f1>-col1, <F1>-col2, <F1>-col3,
/ <f2>-col1, <F2>-col2.
In both cases, the list appears as follows:
012 34 56789
01 2345/67/89
This example declares two field symbols to which different structures are attached. The string WA is then assigned to each of them. The output shows that the field symbols assign the strings component by component according to the type of the components.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/content.htm
THANKS
MRUTYUN -
Read Data from the dynamic Field Symbol with key ?
Dear All,
I've 2 dynamic internal tables in the form of field symbols.
Now,I want to loop the item field symbol, read the header field symbol content and then move the corresponding into a final field symbol.
How to read the field symbol with key ?
When I'm trying to give the key clause in the paranthesis it's giving a syntax error.
Any clues ?
FYI .....
* Get the Dynamic Field and Value for the Date/Year and convert it into Year value
LOOP AT <fs_t_son> ASSIGNING <wa_son>.
ASSIGN COMPONENT gwa_znrows_def-fieldname OF STRUCTURE <wa_son> TO <fs_year>.
IF sy-subrc = 0.
CLEAR gv_string.
MOVE <fs_year> TO gv_string.
CLEAR gv_year.
gv_year = gv_string.
<fs_year> = gv_year.
ELSE.
* When the Date/year Field is not in the Table then -->
* Get the Dynamic Field and Value
ASSIGN COMPONENT gwa_znrows_def-kfldname OF STRUCTURE <wa_rson> TO <fs_value>.
* Populate field for Dynamic Where condition
CLEAR gv_value.
CONCATENATE '''' <fs_value> '''' INTO gv_value.
CONCATENATE gwa_znrows_def-kfldname '=' gv_value INTO gt_where SEPARATED BY space.
APPEND gt_where.
CLEAR gt_where.
READ TABLE <fs_t_rson> ASSIGNING <wa_rson> ( gt_where ). "Key clause
ENDIF. " if sy-subrc = 0. "Assign
ENDLOOP.
Thanks & regards,
Deepu.KTYPES: BEGIN OF line,
col1 TYPE c,
col2 TYPE c,
END OF line.
DATA: wa TYPE line,
itab TYPE HASHED TABLE OF line WITH UNIQUE KEY col1,
key(4) TYPE c VALUE 'COL1'.
FIELD-SYMBOLS <fs> TYPE ANY TABLE.
ASSIGN itab TO <fs>.
READ TABLE <fs> WITH TABLE KEY (key) = 'X' INTO wa.
The internal table itab is assigned to the generic field symbol <fs>, after which it is possible to address the table key of the field symbol dynamically. However, the static address
READ TABLE <fs> WITH TABLE KEY col1 = 'X' INTO wa.
is not possible syntactically, since the field symbol does not adopt the key of table itab until runtime. In the program, the type specification ANY TABLE only indicates that <fs> is a table. If the type had been ANY (or no type had been specified at all), even the specific internal table statement READ TABLE <fs> would not have been possible from a syntax point of view. -
Field symbols as Table name and in where condition in a select statement
Hello All,
I have a scenario where I need to get user input on table name and old field value and new field value. Then based on user input, I need to select the record from the database. The column name for all the tables in question is different in the database, however there data type is the same and have same values.
I am not able to use a field symbol for comparing the old field value to fetch the relevant record in my where clause.
I cannnot loop through the entire table as it has 10 millilon records, please advice on how to add the where clause as field symbol as the table name is also dynamically assigned.
Here is my code:
DATA: TAB LIKE SY-TNAME,
TAB_COMP1 LIKE X031L-FIELDNAME,
TAB_COMP2 LIKE X031L-FIELDNAME,
NO_OF_FLD TYPE N.
DATA: BEGIN OF BUFFER,
ALIGNMENT TYPE F,
C(8000) TYPE C,
END OF BUFFER.
FIELD-SYMBOLS: <WA> TYPE ANY,
<COMP1> TYPE ANY,
<COMP2> TYPE ANY.
GET TABLE NAME GIVEN BY USER IN LOCAL VARIABLE
TAB = TAB_NAME.
CREATE FIELD NAME BASED ON THE TABLE NAME ENTERED.
CASE TAB_NAME.
WHEN 'OIUH_RV_GL'.
KEY FIELD
TAB_COMP1 = 'GL_GL_SYS_NO'.
NO_OF_FLD = 1.
WHEN 'OIUH_RV_OPSL'.
KEY FIELD
TAB_COMP1 = 'OPSL_GL_SYS_NO'.
NO_OF_FLD = 1.
WHEN 'OIUH_RV_OTAX'.
NOT THE ONLY KEY FIELD
TAB_COMP1 = 'OTAX_GL_SYS_NO'.
TAB_COMP2 = 'OTAX_TAX_POS_NO'.
NO_OF_FLD = 2.
WHEN 'OIUH_RV_GTAX'.
NOT THE ONLY KEY FIELD
TAB_COMP1 = 'GTAX_GL_SYS_NO'.
TAB_COMP2 = 'GTAX_TAX_POS_NO'.
NO_OF_FLD = 2.
WHEN OTHERS.
EXIT.
ENDCASE.
SET FIELD SYMBOL WITH APPROPRIATE TYPE TO BUFFER AREA.
ASSIGN BUFFER TO <WA> CASTING TYPE (TAB).
How to add where clause and remove the if condition in the select -- endselect
SELECT * FROM (TAB) INTO <WA>.
ASSIGN COMPONENT TAB_COMP1 OF STRUCTURE <WA> TO <COMP1>.
IF NO_OF_FLD = 2.
ASSIGN COMPONENT TAB_COMP2 OF STRUCTURE <WA> TO <COMP2>.
ENDIF.
IF <COMP1> = OLD_SYS_NO.
code for updating table would come here
WRITE: 'MATCH FOUND'.
EXIT.
ENDIF.
ENDSELECT.
Please advice. Thanks much.
Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:33 PM
Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:34 PM
Edited by: Shipra Jhunjhunwala on Jul 22, 2009 1:35 PM1. Create single column table for holding field name depending on the table entered.
2. Take input from user: for e.g. table_name
3. Using case load single column table with required fields
for e.g.
CASE TAB_NAME.
WHEN 'OIUH_RV_GL'.
Append 'GL_GL_SYS_NO' to KEY_FIELD --> KEY_FIELD is the single line internal table as mentioned in step 1.
WHEN 'OIUH_RV_OPSL'.
Append 'OPSL_GL_SYS_NO'.
WHEN 'OIUH_RV_OTAX'.
Append 'OTAX_GL_SYS_NO' to KEY_FIELD.
APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
WHEN 'OIUH_RV_GTAX'.
Append 'GTAX_GL_SYS_NO' to KEY_FIELD.
APPEND 'OTAX_TAX_POS_NO' to KEY_FIELD.
WHEN OTHERS.
EXIT.
ENDCASE.
Now depending on the table name you have required column ready
4. Create dynamic internal table using following sudo code
Fill the fieldcatlog using the single column field table and DD03L table, See what all columns from DD03L you want to fill in field catlog table
loop at internal table with all the fields.
move it to field catalog.
append field catalog.
endloop.
5. Pass this field catalog table to static method create_dynamic_table method
DATA table TYPE REF TO DATA. --> data object for holding handle to dynamic internal table.
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = fieldcatalog_tab
importing
ep_table = table.
6. Now assign table reference to field symbol of type table.
ASSIGN table->* to <field-tab>.
7. Also create work area <field-wa> using refrence of table.
create data object wa LIKE LINE OF <field-tab>.
ASSIGN wa->* to <field-wa>.
8. Also define field symbol for field name.
for e.g. <field_name>
4. Dynamic internal table is ready
5. Now execute the select statement as follows:
SELECT (KEY_FIELD)
INTO <ITAB> --> created dynamically above
FROM (TABLE_NAME)
WHERE (WHERE). --> WHERE is single line internal table having line type of CHAR72. So for every old value there will be one line
Where condition is same as like we give in static way only difference in this case it will stored in internal table line wise.
In this case you need to append all your where condition line by line in to WHERE.
5. To fill this dynamic internal table using ASSIGN COMPONENT <Comp_number> OF STRUCTURE <field-wa> TO <field-name>
So in this case if first field of structure STRUCT1 is user_id then sudo-code will be
loop at internal table containing list of fields into field_wa --> single column field table
ASSIGN COMPONENT field_wa OF STRUCTURE <field-wa> TO <field>. "Here field_wa is wa area for single column internal table holding all the fieldnames.
Now <field-name> points to user_id field. Move some value into it as nornally we do with variables.
Move <your_new_value> to <field-name>. --> Assign new value
or
<field-name> = <your_new_value>.
Endloop.
6. After completing all the fields one row will be ready in <field_wa>.
APPEND <field_wa> to <field_tab>.
Hope this helps you.
Thanks,
Augustin. -
Hi all,
how can we move internal tables data to field symbol table.
i am new to field symbol, can any one guide me in detail.. i have searched in forums but i am unable understand..
i have defined fields symbols like this.
FIELD-SYMBOLS: <F_TAB> TYPE STANDARD TABLE,
<F_LINE> TYPE ANY,
<F_FIELD> TYPE ANY.
and i have data in ITAB1, ITAB2 & ITAB3.
this tables data i need to move to final internal table i.e. <F_TAB>, whose structure is created dynamically..
in this way i have created the dynamical internal table structure
LOOP AT IT_WDAYS INTO WA_WDAYS.
PERFORM MONTH_TEXT USING WA_WDAYS-PERIODAT CHANGING V_FNAME.
* Element Description
LO_ELEMENT ?= CL_ABAP_ELEMDESCR=>DESCRIBE_BY_NAME( 'CHAR5' ).
MOVE V_FNAME TO LA_COMP-NAME.
* Field type
LA_COMP-TYPE = CL_ABAP_ELEMDESCR=>GET_P(
P_LENGTH = LO_ELEMENT->LENGTH
P_DECIMALS = LO_ELEMENT->DECIMALS ).
* Filling the component table
APPEND LA_COMP TO LT_TOT_COMP.
CLEAR: LA_COMP.
ENDLOOP.
* 3. Create a New Type
LO_NEW_TYPE = CL_ABAP_STRUCTDESCR=>CREATE( LT_TOT_COMP ).
* 4. New Table type
LO_NEW_TAB = CL_ABAP_TABLEDESCR=>CREATE(
P_LINE_TYPE = LO_NEW_TYPE
P_TABLE_KIND = CL_ABAP_TABLEDESCR=>TABLEKIND_STD
P_UNIQUE = ABAP_FALSE ).
* 5. data to handle the new table type
CREATE DATA LO_DATA TYPE HANDLE LO_NEW_TAB.
* 6. New internal table in the fieldsymbols
ASSIGN LO_DATA->* TO <F_TAB>.
i dont want to create thru fieldcatalog method...
just i want know how to pass 2 internal tables data into one final field symbol table..
thanks
Edited by: Matt on Mar 23, 2009 10:52 AM - added tagsHi,
Check this code:
*& Report Z_RTTS_TABLE
REPORT z_rtts_table.
TYPE-POOLS: abap.
DATA: gs_comp TYPE abap_componentdescr,
gt_comp TYPE abap_component_tab.
"example table
DATA: BEGIN OF it OCCURS 3, "<- your ITAB1
pernr TYPE persno,
kostl TYPE kostl,
endda TYPE endda,
END OF it.
"data references
DATA: r_type_struct TYPE REF TO cl_abap_structdescr,
r_type_table TYPE REF TO cl_abap_tabledescr,
r_data_tab TYPE REF TO data,
r_data_str TYPE REF TO data.
* 1. ------------- filling example table IT -> i.e your ITAB1
it-pernr = '12345678'.
it-kostl = '0112345678'.
it-endda = sy-datum.
APPEND it.
it-pernr = '45678909'.
it-kostl = '3452345678'.
it-endda = sy-datum - 1.
APPEND it.
* 2. ------------ components structure type
gs_comp-name = 'PERNR'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'PERSNO' ).
APPEND gs_comp TO gt_comp.
gs_comp-name = 'KOSTL'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'KOSTL' ).
APPEND gs_comp TO gt_comp.
gs_comp-name = 'BEGDA'.
gs_comp-type ?= cl_abap_elemdescr=>describe_by_name( 'BEGDA' ).
APPEND gs_comp TO gt_comp.
* 3. ------------- create structure type
TRY.
r_type_struct = cl_abap_structdescr=>create(
p_components = gt_comp ).
CATCH cx_sy_struct_creation .
ENDTRY.
* 4. ------------- create table type
TRY.
r_type_table = cl_abap_tabledescr=>create( r_type_struct ).
CATCH cx_sy_table_creation .
ENDTRY.
" 5. -------------- create table based on RTTS types
CREATE DATA: r_data_tab TYPE HANDLE r_type_table,
r_data_str TYPE HANDLE r_type_struct.
FIELD-SYMBOLS: <fs_table> TYPE INDEX TABLE, "-> here table must by type INDEX TABLE in order to append to it
<fs_wa> TYPE ANY.
ASSIGN: r_data_tab->* TO <fs_table>,
r_data_str->* TO <fs_wa>. "work area for dynamic table (based on your dynamic structure)
" 6. ---------------- move internal table data (IT) to dynamic table
LOOP AT it.
MOVE-CORRESPONDING it TO <fs_wa>.
APPEND <fs_wa> TO <fs_table>.
ENDLOOP.
Do the same with ITAB2 and ITAB3.
Regards
Marcin -
Hi all,
Can anyone explains what is Fiels symbol and significance of that with examples?
Thanks
ShivaHI Shiva
Field symbols are placeholders or symbolic names for other fields. They do not physically reserve space for a field, but point to its contents. A field symbol cam point to any data object. The data object to which a field symbol points is assigned to it after it has been declared in the program.
Whenever you address a field symbol in a program, you are addressing the field that is assigned to the field symbol. After successful assignment, there is no difference in ABAP whether you reference the field symbol or the field itself. You must assign a field to each field symbol before you can address the latter in programs.
Field symbols are similar to dereferenced pointers in C (that is, pointers to which the content operator * is applied). However, the only real equivalent of pointers in ABAP, that is, variables that contain a memory address (reference) and that can be used without the contents operator, are reference variables in ABAP Objects. (For more information, see Data References).
All operations programmed with field symbols are applied to the field assigned to it. For example, a MOVE statement between two field symbols moves the contents of the field assigned to the first field symbol to the field assigned to the second field symbol. The field symbols themselves point to the same fields after the MOVE statement as they did before.
You can create field symbols either without or with type specifications. If you do not specify a type, the field symbol inherits all of the technical attributes of the field assigned to it. If you do specify a type, the system checks the compatibility of the field symbol and the field you are assigning to it during the ASSIGN statement.
Field symbols provide greater flexibility when you address data objects:
If you want to process sections of fields, you can specify the offset and length of the field dynamically.
You can assign one field symbol to another, which allows you to address parts of fields.
Assignments to field symbols may extend beyond field boundaries. This allows you to address regular sequences of fields in memory efficiently.
You can also force a field symbol to take different technical attributes from those of the field assigned to it.
The flexibility of field symbols provides elegant solutions to certain problems. On the other hand, it does mean that errors can easily occur. Since fields are not assigned to field symbols until runtime, the effectiveness of syntax and security checks is very limited for operations involving field symbols. This can lead to runtime errors or incorrect data assignments.
While runtime errors indicate an obvious problem, incorrect data assignments are dangerous because they can be very difficult to detect. For this reason, you should only use field symbols if you cannot achieve the same result using other ABAP statements.
For example, you may want to process part of a string where the offset and length depend on the contents of the field. You could use field symbols in this case. However, since the MOVE statement also supports variable offset and length specifications, you should use it instead. The MOVE statement (with your own auxiliary variables if required) is much safer than using field symbols, since it cannot address memory beyond the boundary of a field. However, field symbols may improve
To declare a field symbol, use the statement
FIELD-SYMBOLS <FS> [<type>|STRUCTURE <s> DEFAULT <wa>].
For field symbols, the angle brackets are part of the syntax. They identify field symbols in the program code.
If you do not specify any additions, the field symbol <FS> can have data objects of any type assigned to it. When you assign a data object, the field symbol inherits its technical attributes. The data type of the assigned data object becomes the actual data type of the field symbol.
Note: it is possible to assign reference variables and structured data objects to untyped field symbols. However, the static field symbol is only a pointer to the field in memory, and does not have the complex type attributes of a reference or structured field until runtime. You can only use the field symbol to address the whole field (for example, in a MOVE statement). Specific statements such as CREATE OBJECT <FS> or LOOP AT <FS> are not possible.
Typing Field Symbols
The <type> addition allows you to specify the type of a field symbol. When you assign a data object to a field symbol, the system checks whether the type of the data object you are trying to assign is compatible with that of the field symbol. If the types are not compatible or convertible, the system reacts with a syntax or runtime error. If however, you want to assign the type of the field symbol to the data object by means of casting, you must do so explicitly using the ASSIGN statement. The system then treats the assigned data object as if it had the same type as the field symbol.
You specify the type of a field symbol using the same semantics as for formal parameters in procedures. For <type> you can enter either TYPE <t> or LIKE <f>. You can specify the type either generically or in full. If you specify a generic type, the type of the field symbol is either partially specified or not specified at all. Any attributes that are not specified are inherited from the corresponding data object in the ASSIGN statement. If you specify the type fully, all of the technical attributes of the field symbol are determined when you define it. You can then only assign data objects to it that have exactly the same data type.
You should always specify a type for each field symbol. If you cannot avoid defining a generic field symbol, make this clear by using an appropriate generic type declaration.
Generic Type Specification
The following types allow you more freedom when using actual parameters. The data object only needs to have the selection of attributes specified.
Typing
Check for data object
No type specification
TYPE ANY
All types of data object are accepted. The field symbol adopts all of the attributes of the data object.
TYPE C, N, P, or X
Only data objects with type C, N, P, or X are accepted. The field symbol adopts the field length and DECIMALS specification (type P) of the data object.
TYPE TABLE
The system checks whether the data object is a standard internal table. This is a shortened form of TYPE STANDARD TABLE (see below).
TYPE ANY TABLE
The system checks whether the data object is an internal table. The field symbol inherits all of the attributes (line type, table type, key) from the data object.
TYPE INDEX TABLE
The system checks whether the data object is an index table (standard or sorted table). The field symbol inherits all of the attributes (line type, table type, key) from the data object.
TYPE STANDARD TABLE
The system checks whether the data object is a standard internal table. The field symbol inherits all of the remaining attributes (line type, key) from the data object.
TYPE SORTED TABLE
The system checks whether the actual parameter is a sorted internal table. The field symbol inherits all of the remaining attributes (line type, key) from the data object.
TYPE HASHED TABLE
The system checks whether the actual parameter is a hashed internal table. The field symbol inherits all of the remaining attributes (line type, key) from the data object.
If you specify a type generically, remember that the attributes inherited by the field symbol from the program are not statically recognizable in the program. You can, at most, address them dynamically.
TYPES: BEGIN OF line,
col1 TYPE c,
col2 TYPE c,
END OF line.
DATA: wa TYPE line,
itab TYPE HASHED TABLE OF line WITH UNIQUE KEY col1,
key(4) TYPE c VALUE 'COL1'.
FIELD-SYMBOLS <fs> TYPE ANY TABLE.
ASSIGN itab TO <fs>.
READ TABLE <fs> WITH TABLE KEY (key) = 'X' INTO wa.
The internal table ITAB is assigned to the generic field symbol <FS>, after which it is possible to address the table key of the field symbol dynamically. However, the static address
READ TABLE <fs> WITH TABLE KEY col1 = 'X' INTO wa.
is not possible syntactically, since the field symbol does not adopt the key of table ITAB until runtime. In the program, the type specification ANY TABLE only indicates that <FS> is a table. If the type had been ANY (or no type had been specified at all), even the specific internal table statement READ TABLE <FS> would not have been possible.
If you adopt a structured type generically (a structure, or a table with structured line type), the individual components cannot be addressed in the program either statically or dynamically. In this case, you would have to work with further field symbols and the method of assigning structures component by component.
Specifying the Type Fully
When you use the following types, the technical attributes of the field symbols are fully specified. The technical attributes of the data objects must correspond to those of the field symbol.
Typing
Technical attributes of the field symbol
TYPE D, F, I, or T
The field symbol has the technical attributes of the predefined elementary type
TYPE <type>
The field symbol has the type <type>. This is a data type defined within the program using the TYPES statement, or a type from the ABAP Dictionary
TYPE REF TO <cif>|DATA
The field symbol is a reference variable for the class or interface <cif>, or for a data object.
TYPE LINE OF <itab>
The field symbol has the same type as a line of the internal table <itab> defined using a TYPES statement or defined in the ABAP Dictionary
LIKE <f>
The field symbol has the same type as an internal data object <f> or structure, or a database table from the ABAP Dictionary
When you use a field symbol that is fully typed, you can address its attributes statically in the program, since they are recognized in the source code. If you fully specify the type of a field symbol as a reference or structured data object, you can address it as you would the data object itself, once you have assigned an object to it. So, for example, you could address the components of a structure, loop through an internal table, or create an object with reference to a field symbol.
REPORT demo_field_symbols_type .
DATA: BEGIN OF line,
col1(1) TYPE c,
col2(1) TYPE c VALUE 'X',
END OF line.
FIELD-SYMBOLS <fs> LIKE line.
ASSIGN line TO <fs>.
MOVE <fs>-col2 TO <fs>-col1.
The field symbol <FS> is fully typed as a structure, and you can address its components in the program.
Attaching a structure to a field symbol
The STRUCTURE addition forces a structured view of the data objects that you assign to a field symbol.
FIELD-SYMBOLS <FS> STRUCTURE <s> DEFAULT <f>.
The structure <s> is either a structured local data object in the program, or a flat structure from the ABAP Dictionary. <f> is a data object that must be assigned to the field symbol as a starting field. However, this assignment can be changed later using the ASSIGN statement.
When you assign a data object to the field symbol, the system only checks that it is at least as long as the structure. You can address the individual components of the field symbol. It has the same technical attributes as the structure <s>.
If <s> contains components with type I or F, you should remember the possible effects of alignment. When you assign a data object to a field symbol with a structure, the data object must have the same alignment, otherwise a runtime error may result. In such cases, you are advised to assign such data objects only to structured field symbols, which retain the same structure as the field symbol at least over the length of the structure.
The STRUCTURE is obsolete; you should no longer use it. Field symbols defined using the STRUCTURE addition are a mixture of typed field symbols and a utility for casting to either local or ABAP Dictionary data types. If you want to define the type of a field symbol, include the TYPE addition in a FIELD-SYMBOLS statement. If you want to use casting, include the CASTING addition in an ASSIGN statement.
Example using the obsolete STRUCTURE addition:
DATA: wa(10) VALUE '0123456789'.
DATA: BEGIN OF line1,
col1(3),
col2(2),
col3(5),
END OF line1.
DATA: BEGIN OF line2,
col1(2),
col2 LIKE sy-datum,
END OF line2.
FIELD-SYMBOLS: <f1> STRUCTURE line1 DEFAULT wa,
<f2> STRUCTURE line2 DEFAULT wa.
WRITE: / <f1>-col1, <f1>-col2, <f1>-col3,
/ <f2>-col1, <f2>-col2.
Example using the correct syntax (TYPE and CASTING):
DATA: wa(10) VALUE '0123456789'.
DATA: BEGIN OF line1,
col1(3),
col2(2),
col3(5),
END OF line1.
DATA: BEGIN OF line2,
COL1(2),
COL2 LIKE sy-datum,
END OF line2.
FIELD-SYMBOLS: <f1> LIKE line1.
ASSIGN wa TO <f1> CASTING.
FIELD-SYMBOLS: <f2> LIKE line2.
ASSIGN wa TO <f2> CASTING.
WRITE: / <f1>-col1, <F1>-col2, <F1>-col3,
/ <f2>-col1, <F2>-col2.
In both cases, the list appears as follows:
012 34 56789
01 2345/67/89
This example declares two field symbols to which different structures are attached. The string WA is then assigned to each of them. The output shows that the field symbols assign the strings component by component according to the type of the components.
Assigning Components of Structures to a Field Symbol
For a structured data object <s>, you can use the statement
ASSIGN COMPONENT <comp> OF STRUCTURE <s> TO <FS>.
to assign one of its components <comp> to the field symbol <FS>. You can specify the component <comp> either as a literal or a variable. If <comp> is of type C or a structure that has no internal tables as components, it specifies the name of the component. If <comp> has any other elementary data type, it is converted to type I and specifies the number of the component. If the assignment is successful, SY-SUBRC is set to 0. Otherwise, it is set to 4.
This statement is particularly important for addressing components of structured data objects dynamically. If you assign a data object to a field symbol either generically or using casting, or pass it generically (or using casting) to the parameter interface of a procedure, you cannot address its components either statically or dynamically. Instead, you must use the above statement. This allows indirect access either using the component name or its index number.
DATA: BEGIN OF LINE,
COL1 TYPE I VALUE '11',
COL2 TYPE I VALUE '22',
COL3 TYPE I VALUE '33',
END OF LINE.
DATA COMP(5) VALUE 'COL3'.
FIELD-SYMBOLS: <F1>, <F2>, <F3>.
ASSIGN LINE TO <F1>.
ASSIGN COMP TO <F2>.
DO 3 TIMES.
ASSIGN COMPONENT SY-INDEX OF STRUCTURE <F1> TO <F3>.
WRITE <F3>.
ENDDO.
ASSIGN COMPONENT <F2> OF STRUCTURE <F1> TO <F3>.
WRITE / <F3>.
The output is:
11 22 33
33
The field symbol <F1> points to the structure LINE, <F2> points to the field COMP. In the DO loop, the components of LINE are specified by their numbers and assigned one by one to <F3>. After the loop, the component COL3 of LINE is specified by its name and assigned to <F3>. Note that ASSIGN COMPONENT is the only possible method of addressing the components of <F1>. Expressions such as <F1>-COL1 are syntactically incorrect.
Regards,
Laxmi. -
Internal table to field symbol
hi all,
type-pools : abap.
field-symbols: <dyn_table> type standard table,
<dyn_wa>,
<dyn_field>.
data: dy_table type ref to data,
dy_line type ref to data,
xfc type lvc_s_fcat,
ifc type lvc_t_fcat.
*data : dyn_itab2 type ANY table.
selection-screen begin of block b1 with frame.
parameters: p_table(30) type c.
selection-screen end of block b1.
start-of-selection.
BREAK-POINT.
perform get_structure.
perform create_dynamic_itab.
perform get_data.
PERFORM OUTPUT.
*perform write_out.
form get_structure.
data : idetails type abap_compdescr_tab,
xdetails type abap_compdescr.
data : ref_table_des type ref to cl_abap_structdescr.
Get the structure of the table.
ref_table_des ?=
cl_abap_typedescr=>describe_by_name( p_table ).
idetails = ref_table_des->components.
*idetails] = ref_table_des->components[.
loop at idetails into xdetails.
clear xfc.
xfc-fieldname = xdetails-name .
xfc-datatype = xdetails-type_kind.
xfc-inttype = xdetails-type_kind.
xfc-intlen = xdetails-length.
xfc-decimals = xdetails-decimals.
append xfc to ifc.
endloop.
endform.
form create_dynamic_itab.
Create dynamic internal table and assign to FS
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = ifc
importing
ep_table = dy_table.
here i want to assighn the structure of dy_table to internal atble.
assign dy_table->* to <dyn_table>.
Create dynamic work area and assign to FS
create data dy_line like line of <dyn_table>.
assign dy_line->* to <dyn_wa>.
endform.
form get_data.
Select Data from table.
select * into table <dyN_table> UP TO 10 ROWS
from (p_table).
endform.
Write out data from table.
FORM OUTPUT.
loop at <dyn_table> into <dyn_wa>.
do.
assign component sy-index
of structure <dyn_wa> to <dyn_field>.
if sy-subrc = 0.
exit.
endif.
if sy-index = 1.
write:/ <dyn_field>.
else.
write: <dyn_field>.
endif.
enddo.
endloop.
ENDFORM.
how can i achieve this one.
regards
sivaHi,
Check this Code ...
LOOP AT <dyn_table> INTO <dyn_wa>.
DO.
ASSIGN COMPONENT sy-index
OF STRUCTURE <dyn_wa> TO <fs_field> .
IF sy-subrc NE 0.
EXIT.
ENDIF.
IF sy-index = 1.
WRITE:/ <fs_field>.
ELSE.
WRITE: <fs_field>.
ENDIF.
ENDDO.
ENDLOOP.
For reference check below code
DATA: it_fieldcat TYPE lvc_t_fcat . " Field catalog
DATA: wa_fieldcat LIKE LINE OF it_fieldcat. " Field catalog
DATA: it_dyn_table TYPE REF TO data, " Dynamic table
it_wa_dyn_table TYPE REF TO data. " Dynamic table
* Field sysmbols Begin with <fs> *
FIELD-SYMBOLS: <fs_dyn_table> TYPE STANDARD TABLE, " Dynamic tbale
<fs_dyn_table_temp> TYPE ANY , " Dynamic tbale
<fs_field> TYPE ANY , " Temp field for data assignment
<fs_field_temp> TYPE ANY . " Temp field for data assignment
* Macro *
* Macro Defination
* Building field catalog using macro defination
DEFINE m_fieldcat.
wa_fieldcat-fieldname = &1.
wa_fieldcat-scrtext_l = &2.
wa_fieldcat-coltext = &2.
wa_fieldcat-no_zero = &3.
wa_fieldcat-hotspot = &4.
wa_fieldcat-outputlen = &5.
wa_fieldcat-emphasize = &6.
* Appending workarea to internal table
append wa_fieldcat to it_fieldcat.
clear wa_fieldcat.
END-OF-DEFINITION.
*& Form f005_prepare_field_catalog
* text
form f005_prepare_field_catalog .
REFRESH: it_fieldcat.
* Build the field catalog
m_fieldcat text-007 text-008 c_blank c_blank c_30 c_blank.
m_fieldcat text-009 text-010 c_blank c_blank c_30 c_blank.
SORT it_final_temp BY equnr point.
SORT it_final BY equnr point psort idate.
w_date1 = so_date-low.
* Loop to generate grid column at run time
* Loop - Till the lower date not equal to higer date
WHILE so_date-high GE w_date1.
* Changing date into actual date format using edit mask
WRITE w_date1 TO w_var4 USING EDIT MASK '__-__-____'.
m_fieldcat w_var4 w_var4 c_flag c_blank c_12 c_blank.
w_date1 = w_date1 + c_count.
CLEAR w_var4.
ENDWHILE.
*& Form f007_create_dynamic_table
* text: Create dynamic table
form f007_create_dynamic_table .
* Call method to create dynamic internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = it_fieldcat
IMPORTING
ep_table = it_dyn_table
EXCEPTIONS
generate_subpool_dir_full = 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.
SORT it_final_temp BY equnr point.
SORT it_final BY equnr point psort idate.
ASSIGN it_dyn_table->* TO <fs_dyn_table>.
CREATE DATA it_wa_dyn_table LIKE LINE OF <fs_dyn_table>.
ASSIGN it_wa_dyn_table->* TO <fs_dyn_table_temp>.
IF it_final_temp IS NOT INITIAL.
LOOP AT it_final_temp INTO wa_final_temp.
* Assign equipment number and it's field data to field symbols (Dynamic table)
* Assign field name to field symbol
ASSIGN text-007 TO <fs_field_temp>.
* Assign component name and it's value to dynamic table
ASSIGN COMPONENT <fs_field_temp> OF STRUCTURE <fs_dyn_table_temp> TO <fs_field>.
* Assign equipment number value to field symbol
<fs_field> = wa_final_temp-equnr.
* Assign Short Description and it's field data to field symbols (Dynamic table)
* Assign field name to field symbol
ASSIGN text-009 TO <fs_field_temp>.
* Assign component name and it's value to dynamic table
ASSIGN COMPONENT <fs_field_temp> OF STRUCTURE <fs_dyn_table_temp> TO <fs_field>.
* Assign short description value to field symbol
<fs_field> = wa_final_temp-psort.
* Loop to assign value of run time generated column.
IF it_final IS NOT INITIAL.
LOOP AT it_final INTO wa_final WHERE equnr = wa_final_temp-equnr
AND point = wa_final_temp-point.
w_date1 = wa_final-idate.
WRITE w_date1 TO w_var4 USING EDIT MASK '__-__-____'.
ASSIGN w_var4 TO <fs_field_temp>.
ASSIGN COMPONENT <fs_field_temp> OF STRUCTURE <fs_dyn_table_temp> TO <fs_field>.
<fs_field> = wa_final-cdiff.
CLEAR: wa_final, w_var4, w_date1.
ENDLOOP.
ENDIF.
CLEAR: wa_final_temp.
* Assign field symbol temporary table to final dynamic table
APPEND <fs_dyn_table_temp> TO <fs_dyn_table>.
CLEAR: <fs_dyn_table_temp>.
ENDLOOP.
ENDIF.
endform. " f007_create_dynamic_table -
Field-symbols : internal table
Dear experts,
I am trying to put contents of internal table from a standard transaction in this way but i am not getting.
Further i get last record successfully if i try to follow the code of this link
http://www.sapdevelopment.co.uk/enhance/enhance_fsymbol.htm
The code that i use is :
types: begin of t_type,
tabix type i,
color type c,
selfl type c,
vbeln like lips-vbeln,
posnr like lips-posnr,
kschl like nast-kschl,
nacha like nast-nacha,
parvw like nast-parvw,
pname like kna1-name1,
pcity like lfa1-ort01,
vstel type c,
lfdat like mkpf-budat,
wadat like mkpf-budat,
end of t_type.
data : pgm(40) value '(SAPLKKBL)T_OUTTAB[]'.
field-symbols: <fs> type standard table.
data: i_get type t_type occurs 0 with header line.
assign (pgm) to <fs>.
append lines of <fs> to i_get[].
But not getting,the datatype i have created is only by looking at fields in memory map.Its not exactly of T_OUTPUT[] as it can't be referredHi aditya,
Please try defining field symbol as of generic type ( TYPE ANY).
or try this way.
data :
pgm(40)
t_pgm like standard table of pgm.
field-symbols: <fs> type ANY
data: i_get type t_type occurs 0 with header line.
t_pgm = (SAPLKKBL)T_OUTTAB[].
Loop at t_pgm into pgm.
assign pgm to <fs>.
append <fs> to i_get[].
ENDLOOP.
Hope this would help you.
Good luck
Narin -
Sample program for field symbol
hi,
I am fresher. I want sample program(code) for field symbol.http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm
TYPES: BEGIN OF line,
col1 TYPE c,
col2 TYPE c,
END OF line.
DATA: wa TYPE line,
itab TYPE HASHED TABLE OF line WITH UNIQUE KEY col1,
key(4) TYPE c VALUE 'COL1'.
FIELD-SYMBOLS <fs> TYPE ANY TABLE.
ASSIGN itab TO <fs>.
READ TABLE <fs> WITH TABLE KEY (key) = 'X' INTO wa.
The internal table ITAB is assigned to the generic field symbol <FS>, after which it is possible to address the table key of the field symbol dynamically. However, the static address
READ TABLE <fs> WITH TABLE KEY col1 = 'X' INTO wa.
is not possible syntactically, since the field symbol does not adopt the key of table ITAB until runtime. In the program, the type specification ANY TABLE only indicates that <FS> is a table. If the type had been ANY (or no type had been specified at all), even the specific internal table statement READ TABLE <FS> would not have been possible.
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/content.htm
http://help.sap.com/saphelp_nw2004s/helpdata/en/fc/eb387a358411d1829f0000e829fbfe/content.htm -
How to copy the structure of a Field Symbol?
Hi,
I have a requirement where in a dynamic Internal table is supposed to be created. I have created that dynamic table using the class method cl_alv_table_create=>create_dynamic_table. Here I have a structure in the field symbol. My requirement is how do I create a internal table with the structure that is there in the field symbol?...
and i'm unable to refer to the field that is dynamically created in the field symbol.
Like,
<gfs_tab>-pernr = itab-pernr.
in the above stmt the field pernr is created in the field symbol dynamically.
Thanks,
Deepak.Hi Matt,
my objective is to create an internal table with structure that i have obtained in <gfs_tab> .
other than the pernr, there are many fields dynamically generated.
say if I have generated the following structure in <gfs_tab> :
pernr ename1 day1 day2 day3
then I want to create an internal table with the above structure so that my internal table will have fields:
1) pernr
2) ename1
3) day1
4) day2
5) day3
for each execution of the report there will be different structure generated in <gfs_tab> depending upon the inputs that I give.
Thanks,
Deepak.
Maybe you are looking for
-
How to remove credit card from Apple iCloud account
I cannot seem to remove my credit card info and it's not one of in good use anymore. But every time I try to install an app it redirects me to login page for payment info page with a "billing" problem due to old credit card on there.
-
Ipod shuffle not recognised by my desk top
I have a new ipod shuffle that does not show up in devices when I plug it into my desk top. What should I do. Have all the latest software and the device is working and being recognised by another computer.
-
Hi experts, In this simple report,why iam not able to get the end-of-page?I have few details in the end-of-page,and i want to get it in <b>Every page.</b>Where iam doing wrong? REPORT Z_ISSUE_SLIP_WH MESSAGE-ID ZM LINE-SIZE 80
-
I using 'div' tags with 'css' & javascript to make either the divs visible or hidden.(parents) everything works cool with this though i now need nested divs (conditionally shown or hidden)(children) within each of the (parent) divs.... whenever i mak
-
Variables in query, greater than
Please tell me if the following is possible. I have a query with a variable that asks for a date to be entered, e.g. 02.2006 and spits out the results. However I have been asked to set this variable in such a way that it should display the results of