ASSIGN Component ... (field symbol stuff)
Hi,
I want to validate certain fields (KNA1, BUKRS, KOART, FNAME) which are
entered by the user in the transaction XK01. They are being captured in a structure, lets say X_LFA1.
To validate this fields I am being asked to use field symbols using component assign.
Can someone tell me how do I do this ?
Tushar,
Its still not clear to me what exactly you are trying to do.
Is it like you just want to see if those fields exist in the table or not? If yes, you can do like this.
parameter : p_field -- field entered by the user
data : wa_ztable like ztable.
field-symbols : <fs_any> type any.
Assign component p_field of structure wa_ztable to <fs_any>.
if sy-subrc = 0.
Success.
endif.
Regards,
Ravi
Similar Messages
-
Dynamic assign in field symbols
dynamic assign in field symbols
Hi,
DYNAMIC ASSIGN:
If you do not know the name of the field that you want to assign to the field symbol when you write a program, you can use a dynamic ASSIGN statement:
ASSIGN (<f>) TO <FS>.
This statement assigns the field whose name is contained in the field <f> to the field symbol <FS>. You cannot use offset and length in a dynamic ASSIGN.
At runtime, the system searches for the corresponding data object in the following order:
If the ASSIGN statement is in a procedure, the system searches first in its local data.
If it cannot find the object in the local data (or if the ASSIGN statement is not in a procedure), it then looks in the local data of the program.
If the field does not exist in the global data of the program, the system looks in the table work areas declared with the TABLES statement in the main program of the current program group. A program group consists of a main program and all of the programs that are loaded into the same internal session as a result of other program calls.
If the search is successful and a field can be assigned to the field symbol, SY-SUBRC is set to 0. Otherwise, it is set to 4, and the field symbol remains unchanged. For security reasons, you should always check the value of SY-SUBRC after a dynamic ASSIGN to prevent the field symbol pointing to the wrong area.
Searching for the field in this way slows down the program. You should therefore only use the dynamic ASSIGN statement when absolutely necessary. If you know when you create the program that you want to assign a table work area to the field symbol, you can also use the following variant of the dynamic ASSIGN statement:
ASSIGN TABLE FIELD (<f>) TO <FS>.
The system then only searches within the table work areas in the main program of the current program group for the data object that is to be assigned to the field symbol. This addition is forbidden in ABAP Objects, since the latter does not support table work areas.
Suppose we have three programs. The main program:
REPORT demo_field_symbols_dynami_as_1.
TABLES sbook.
sbook-fldate = sy-datum.
PERFORM form1 IN PROGRAM demo_form1.
The other two programs are:
REPORT demo_form1.
FORM form1.
PERFORM form2 IN PROGRAM demo_form2.
ENDFORM.
and
REPORT demo_form2.
FORM form2.
DATA name(20) TYPE c VALUE 'SBOOK-FLDATE'.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN (name) TO <fs>.
IF sy-subrc EQ 0.
WRITE / <fs>.
ENDIF.
ENDFORM.
The output looks something like this:
02.06.1998
The program group in the internal session now consists of the programs DEMO, MYFORMS1 and MYFORMS2. The field symbol <FS> is defined in MYFORMS2. After the dynamic ASSIGN statement, it points to the component FLDATE of the table work area SBOOK declared in the main program DEMO.
REPORT demo_field_symbols_dynami_as_2 .
TABLES sbook.
DATA: name1(20) TYPE c VALUE 'SBOOK-FLDATE',
name2(20) TYPE c VALUE 'NAME1'.
FIELD-SYMBOLS <fs> TYPE ANY.
ASSIGN TABLE FIELD (name1) TO <fs>.
WRITE: / 'SY-SUBRC:', sy-subrc.
ASSIGN TABLE FIELD (name2) TO <fs>.
WRITE: / 'SY-SUBRC:', sy-subrc.
The output is:
SY-SUBRC: 0
SY-SUBRC: 4
In the first ASSIGN statement, the system finds the component FLDATE of the table work area SBOOK and SY-SUBRC is set to 0. In the second ASSIGN statement, the system does not find the field NAME1 because it is declared by the DATA statement and not by the TABLES statement. In this case, SY-SUBRC is set to 4.
Reference: http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb38d5358411d1829f0000e829fbfe/content.htm
reward points if helpful.
Regards,
Ramya -
Screen value not assign in field symbol
Hi gurus,
I create a field symbol for module pool programming for assigning screen value. I create a tab in main screen and three subscreen for tab. in first screen values perfectly asign in field symbol but second subscreen FS1,FS2,FS3 values not assign.
Atthe time of save three subscreen values stored in internal table, then insert into ztable.
PERFORM SAVE_DATA USING '15' 'GTAB-IO_CODE' 'GTAB-IO_PER' 'GATB-IO_VAL'.
PERFORM SAVE_DATA USING '26' 'GTAB-IO_SCODE' 'GTAB-IO_SPER' 'GTAB-IO_SVAL'.
FORM SAVE_DATA USING X TYPE I
FS1 TYPE STRING
FS2 TYPE STRING
FS3 TYPE STRING.
*FORM SAVE_DATA USING X TYPE I FS1 TYPE STRING.
CLEAR SNO.
CLEAR C.
ITAB-MANDT = SY-MANDT.
ITAB-BUKRS = '1000'.
ITAB-DOCNO = '0001000005'.
ITAB-BUDAT = SY-DATUM.
DO X TIMES.
IF X EQ '15'.
FS1 = 'GTAB-IO_CODE'.
FS2 = 'GTAB-IO_PER'.
FS3 = 'GTAB-IO_VAL'.
ELSEIF X EQ '26'.
FS1 = 'GTAB-IO_SCODE'.
FS2 = 'GTAB-IO_SPER'.
FS3 = 'GTAB-IO_SVAL'.
ENDIF.
C = C + 1.
SNO = SNO + 10.
ITAB-SLNO = SNO.
ZCOMRP_ORTRN-SLNO = SNO.
CONCATENATE FS1 C INTO FS1.
ASSIGN (FS1) TO <FS>.
ZCOMRP_ORTRN-PRCOD = <FS>.
ITAB-PRCOD = <FS>.
CONCATENATE FS2 C INTO FS2.
ASSIGN (FS2) TO <FS>.
ZCOMRP_ORTRN-KBETR = <FS>.
ITAB-KBETR = <FS>.
CONCATENATE FS3 C INTO FS3.
ASSIGN (FS3) TO <FS>.
ZCOMRP_ORTRN-DMBTR = <FS>.
ITAB-DMBTR = <FS>.
INSERT ZCOMRP_ORTRN.
APPEND ITAB.
INSERT ZCOMRP_ORTRN FROM ITAB.
CLEAR FS1.
CLEAR FS2.
CLEAR FS3.
CLEAR C.
ENDDO.
PERFORM CLEAR.
ENDFORM. " SAVE_DATAsolved
-
Dump GETWA_NOT_ASSIGNED assigning a Field Symbol
i have
DATA: W_PROG3(30) VALUE '(SAPLV56U)I_XVTTK[]'.
ASSIGN (W_PROG3) TO is executed i got a dump.
Only in this case i got a dump.
I hope somebody could help me with thisHello,
I have the same Problem with another Table. To evaluate the Problem I wrote a little testprogram with the following code:
*& Report ZL_FROELICHM_TEST1 *
report ZL_FROELICHM_TEST1 .
data: VBSK_I like VBSK.
data: T_KOMDLGN like KOMDLGN occurs 10 with header line,
T_VBFS type table of VBFS,
T_VBLS type table of VBLS.
call function 'GN_DELIVERY_CREATE'
exporting
VBSK_I = VBSK_I
tables
XKOMDLGN = T_KOMDLGN[]
XVBFS = T_VBFS
XVBLS = T_VBLS.
perform ASSIGN.
*& Form assign
text
--> p1 text
<-- p2 text
form ASSIGN .
data: NAME_TAB1(30) type C value '(SAPLV50S)XKOMDLGN'.
KOMDLGN type table of KOMDLGN with header line.
field-symbols: .
if SY-SUBRC = 0.
KOMDLGN = <KOMDLGN>.
endif.
assign: (NAME_TAB1) to <KOMDLGN>.
if SY-SUBRC = 0.
KOMDLGN[] = <KOMDLGN>.
endif.
check not KOMDLGN[] is initial.
endform. " assign
If you call Funktion 'GN_DELIVERY_CREATE' then the ASSIGN dumps. If you don't call it, then the ASSIGN gives you a returncode 4. The funktion works within the GN_DELIVERY_CREATE, however, the relevant coding is in the Program SAPMV50A in the performroutine USEREXIT_REFRESH_DOCUMENT. I get the dump when the exit is called by WS_DELIVERY_UPDATE, or RV_DELIVERY_CREATE. These functions don't know the Table XKOMDLGN.
So, if you find a solution to your problem, please let me know. I think I have the same problem.
Greetings,
Maria Frölich. -
Hi,
in user exit EXIT_SAPLVEDA_001.
data: wa_xvbap like line of xvbap.
FIELD-SYMBOLS: <fs_xvbap> like wa_xvbap.
ASSIGN '(SAPLVEDA)XVBAP' TO <fs_xvbap>.
getting error of type incompatible..
any ideas?
Thanks
GiriHi,
you are trying to assign a string '(SAPLVEDA)XVBAP' to a field symbol with type XVBAP. You are just missing brackets.
ASSIGN ('(SAPLVEDA)XVBAP') TO <fs_xvbap>.
Cheers -
Field name retrieval from field symbols after assigning to field in a struc
We have an internal table of about 100 columns. First 7 of them have key values and other fields are data fields. Out of remaining 93 fields, any 2 to 3 fields have data stored in it in each record. Using field symbols in a loop (93 fixed iterations), we are identifying which fields has a data in it. Once we identify the field, how do we retrieve the name of the field / column of the table. We are performing further processing based on name of the field.
Any ideas how to get the name of the column assigned to field symbols?
sample raw code piece is as below:
clear n.
Do 93 times.
n = n + 1.
assign component n of structure itab to <fs>.
if not <fs> is initial.
Get name of the field in cfname.
perform process_record using cfname.
endif.
enddo.
Thanks.
Regards.Hi,
Try this..use the function module GET_COMPONENT_LIST to get the fields of the internal table and store it in an internal table ITAB_COMP..
Then use READ TABLE ITAB_COMP INDEX sy-index..
You can get the field name from the work area..
Thanks,
Naren -
Problem with slis_t_specialcol_alv Field Symbol Assignment
I have created a dynamic internal table (runtime determined number of columns) to contain data to be displayed in an ALV. Ive also made ensured that the last column of the dynamic itab is of type <b>'slis_t_specialcol_alv'</b> and named <b>CINFO</b> to contain color information for that particular row. In the code below the dynamic itab is pointed to by field symbol <dyn_table> while the work area for it would be <dyn_wa>.
Somewhere down the line I attempt to assign the CINFO component of the current row of the itab to a field symbol called <fs_cinfo> typed as slist_t_specialcol_alv (Same as CINFO).
I used the code:
ASSIGN COMPONENT 'CINFO' OF STRUCTURE <dyn_wa> TO <fs_cinfo>.
This gives me the runtime error:
<i>Type conflict in the ASSIGN statement in the program "ZHRR001_TEMMATRIX".
You attempted to assign a field to a typed field symbol,
but the field does not have the required type. </i>
I am unsure why this happens as both the component CINFO and FS <fs_cinfo> are of type slist_t_specialcol_alv.
For some odd reason though during debugging, I took a look at the <dyn_wa> structure and the component type of CINFO was displayed as C???
Here is the relevant portion of code (creation of dynamic itab and attempting to assign <fs_cinfo>)
FIELD-SYMBOLS: <dyn_table> TYPE STANDARD TABLE,
<dyn_wa>.
FIELD-SYMBOLS: <fs_cinfo> TYPE slist_t_specialcol_alv.
DATA: lw_cinfo TYPE slis_specialcol_alv.
DATA: li_fldcat TYPE lvc_t_fcat,
lw_fldcat TYPE lvc_s_fcat.
*Create internal table fields (they will be called Field1, Field2, etc)
*Last column will be named 'CINFO' to contain row color information
DO l_alvcolumncount TIMES.
index = sy-index.
IF index <> l_alvcolumncount.
CLEAR lw_fldcat.
CONCATENATE 'Field' index INTO lw_fldcat-fieldname .
CONDENSE lw_fldcat-fieldname NO-GAPS.
lw_fldcat-datatype = 'STRING'.
* lw_fldcat-intlen = 5.
APPEND lw_fldcat TO li_fldcat .
ELSE.
CLEAR lw_fldcat.
lw_fldcat-fieldname = 'CINFO'.
CONDENSE lw_fldcat-fieldname NO-GAPS.
lw_fldcat-datatype = 'slis_t_specialcol_alv'.
APPEND lw_fldcat TO li_fldcat.
ENDIF.
ENDDO.
* Create dynamic internal table and assign to FS
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = li_fldcat
IMPORTING
ep_table = new_table.
ASSIGN new_table->* TO <dyn_table>.
*Create dynamic work area and assign to FS
CREATE DATA new_line LIKE LINE OF <dyn_table>.
ASSIGN new_line->* TO <dyn_wa>.
ASSIGN COMPONENT 'CINFO' OF STRUCTURE <dyn_wa> TO <fs_cinfo>.
* Color this cell
lw_cinfo-fieldname = fieldname.
lw_cinfo-color-col = 6.
APPEND lw_cinfo TO <fs_cinfo>.
Message was edited by: Sow Yong WongHello Sow
There is a big problem in the program: you are mixing types used for FM-based ALV (SLIS_...) and ABAP-OO based ALV (LVC_...).
For ABAP-OO based row colouring you have to define your itab like this:
TYPES: ty_s_outtab.
INCLUDE TYPE kna1. " just an example
TYPES: rowcolor(4) TYPE c.
TYPES: END OF ty_s_outtab.
TYPES: ty_t_outtab TYPE STANDARD TABLE of ty_s_outtab
WITH DEFAULT KEY.
In the layout (LVC_S_LAYO) you have to set <b>ls_layout-info_fname = 'ROWCOLOR'</b>.
ROWCOLOR has to be filled according to <b>Cxyz</b> whereas
- x = color
- y = inverse on/off
- z = intensified on/off
For documentation please refer to <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/e8a1d690-0201-0010-b7ad-d9719a415907">An Easy Reference to ALV Grid Control</a>
Regards
Uwe -
Assigning field symbol to a form parameter
Hello there.
I got this huge string that concatenates several columns from a structure and I have to distribute these data into fields of a generic work area in a FORM.
The thing is that I can't find the right way to pass this work area and when I try to assign my field symbol a dump occurs.
Could anyone give me a tip?
<b>Here is what I'm doing:</b>
Form Nameform <how to pass?> p_workarea
loop at it_tab
CONCATENATE 'p_table-' it_tab-fieldname INTO campo.
ASSIGN (campo) TO <fs>.
endloop.
When I debug it, the program sees p_workarea, but when I try to see a specific field like p_workarea-kunnr, it's like it doesn't exists.Thanks Matt,
But how do I append the values within this internal table ??
When I am using the following code:
ls_wa-fld3 = 'A'.
ls_wa-t_in-fld1 = 'B'.
ls_wa-t_in-fld2 = 'C'.
ls_wa-t_in-fld1 = 'D'.
ls_wa-t_in-fld2 = 'E'.
append ls_wa to lt_tab.
Its giving an error that:
The data object "LS_WA" does not have a component called "T_IN-FLD1".
I wanted the values to be appended in the following way in lt_tab:
fld3 fld1 fld2
A B C
D E
Please help. -
Assigning field value to Field symbol
Dear Experts,
I have one program which works fine in non unicode system.. The program contains Assign statement with offset and length..
This program dumps in Unicode system due to this instruction.. The field which i want to assign to field symbol is type P field..
Is there any ways to avoid the dump?
Thank you in Advance..Hi,
isn't it an ABAP question in an EP forum?
Romano -
Checking whether field-symbol from another program is assigned?
Hi all
I'm attempting to access a FS from another program.
As the FS can be assigned, or unassigned within that program, how do I checked for that in my calling program?
e.g. calling program;
FIELD-SYMBOLS: <fs> TYPE STANDARD TABLE.
DATA: lv_var(40) type c.
lv_var = '(ZTGT_PROG)<read_fs>'.
ASSIGN (lv_var) TO <fs>. " statement might dump...Hi
Go through this doc and use accordingly
Field Symbols
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.
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 performance in some cases.
check the below links u will get the answers for your questions
http://help.sap.com/saphelp_nw04/helpdata/en/fc/eb3860358411d1829f0000e829fbfe/content.htm
http://www.sts.tu-harburg.de/teaching/sap_r3/ABAP4/field_sy.htm
http://searchsap.techtarget.com/tip/1,289483,sid21_gci920484,00.html
Syntax Diagram
FIELD-SYMBOLS
Basic form
FIELD-SYMBOLS <fs>.
Extras:
1. ... TYPE type
2. ... TYPE REF TO cif
3. ... TYPE REF TO DATA
4. ... TYPE LINE OF type
5. ... LIKE s
6. ... LIKE LINE OF s
7. ... TYPE tabkind
8. ... STRUCTURE s DEFAULT wa
The syntax check performed in an ABAP Objects context is stricter than in other ABAP areas. See Cannot Use Untyped Field Symbols ad Cannot Use Field Symbols as Components of Classes.
Effect
This statement declares a symbolic field called <fs>. At runtime, you can assign a concrete field to the field symbol using ASSIGN. All operations performed with the field symbol then directly affect the field assigned to it.
You can only use one of the additions.
Example
Output aircraft type from the table SFLIGHT using a field symbol:
FIELD-SYMBOLS <PT> TYPE ANY.
DATA SFLIGHT_WA TYPE SFLIGHT.
ASSIGN SFLIGHT_WA-PLANETYPE TO <PT>.
WRITE <PT>.
Addition 1
... TYPE type
Addition 2
... TYPE REF TO cif
Addition 3
... TYPE REF TO DATA
Addition 4
... TYPE LINE OF type
Addition 5
... LIKE s
Addition 6
... LIKE LINE OF s
Addition 7
... TYPE tabkind
Effect
You can define the type of the field symbol using additions 2 to 7 (just as you can for FORM parameters (compare Defining the Type of Subroutine Parameters). When you use the ASSIGN statement, the system carries out the same type checks as for USING parameters of FORMs.
This addition is not allowed in an ABAP Objects context. See Cannot Use Obsolete Casting for FIELD SYMBOLS.
In some cases, the syntax rules that apply to Unicode programs are different than those for non-Unicode programs. See Defining Types Using STRUCTURE.
Effect
Assigns any (internal) field string or structure to the field symbol from the ABAP Dictionary (s). All fields of the structure can be addressed by name: <fs>-fieldname. The structured field symbol points initially to the work area wa specified after DEFAULT.
The work area wa must be at least as long as the structure s. If s contains fields of the type I or F, wa should have the structure s or at least begin in that way, since otherwise alignment problems may occur.
Example
Address components of the flight bookings table SBOOK using a field symbol:
DATA SBOOK_WA LIKE SBOOK.
FIELD-SYMBOLS <SB> STRUCTURE SBOOK
DEFAULT SBOOK_WA.
WRITE: <SB>-BOOKID, <SB>-FLDATE.
Related
ASSIGN, DATA
Additional help
Declaring Field Symbols
Reward points if useful
Regards
Anji -
Right way to declare field symbols
i am new to field symbols, pls help
i want to know which is the right way of declaration ?
types: begin of typ_tab,
vbeln type vbap-vbeln,
posnr type vbap-posnr,
matnr type vbap-matnr,
end of typ_tab.
data: itab type standard table of typ_tab,
wa type typ_tab.
field-symbols: <f_t> type standard table,
<f_w> type any, or <f_w> like line of typ_tab, ??
<f_s> type any.
select vbeln posnr ....... into itab......
assign itab to <f_t>.
assign wa to <f_w>.
loop at <f_t> assigning <f_w>.
assign component 'vbeln' of structure <f_w> to <f_s>.
write : / <f_s>.
endloop.
OR
loop at itab assigning <f_w>.
write: / <f_w>-vbeln.
endloop.
r these 2 statements correctt ? if so then which one to use, pls show with an example. wats the diff btwn above 2 types of looping statements ? how to use read statement on this ?Hello Saurajit,
Both the way are correct. And it depends on the requirement, which one to use.
<f_w> TYPE ty_tab - is TYPED field symbol - if you know TYPE before runtime you can use this. It will just work like a static work area.
<f_w> TYPE any - is not TYPED and structure of this field symbol is defined during runtime using ASSIGN statement. And fields of the structure is read by ASSIGN COMPONENT <<field name>> statement. -
Field-Symbols: How to retrieve data into an internal table from FS
Hello All,
I am working on field symbols.I have declared the field symbols as shown.
FIELD-SYMBOLS: <gt_pos_data> TYPE table,
<wa_pos_data> like <gt_pos_data>.
Data: Begin of itab occurs 0,
field1(5) type c,
field2(10)_type c,
end of itab.
The FS <gt_pos_data> has 100 fields but I need to move only two fields from this FS to my internal table itab.I am doing the following.
loop at <gt_pos_data> assigning <wa_pos_data>.
itab-field1 = <wa_pos_data>-field1.
itab-field2 = <wa_pos_data>-field2.
append itab.
clear itab.
endloop.
But it is giving me an error saying "<wa_pos_data> is a table without header line and therefore has no componet FIELD1".How to achieve this requirement?
Thanks in advance
Sandeep<wa_pos_data> should be defined LIKE LINE OF <gt_pos_data>, but it will still have no structure, so you need to assign a field symbol to the component as well.
FIELD-SYMBOLS: <gt_pos_data> TYPE table,
<wa_pos_data> like LINE OF <gt_pos_data>,
<field> type any.
Data: Begin of itab occurs 0,
field1(5) type c,
field2(10)_type c,
end of itab.
loop at <gt_pos_data> assigning <wa_pos_data>.
assign componet 'FIELD1' of structure <wa_pos_data> to <field>.
if sy-subrc = 0.
itab-field1 = <field>.
endif.
assign componet 'FIELD2' of structure <wa_pos_data> to <field>.
if sy-subrc = 0.
itab-field2 = <field>.
endif.
append itab.
clear itab.
endloop.
Regards,
Rich Heilman -
Mapping individual field symbols to a structure
Hi,
I have a requirement where I need to map some individual field symbols to some specific fields in a structure:.
Here is what mt code looks like :
data: <f1>, <f2> , <f3>,
<f4> type ZCUSTTAB.
data: upd type ZCUSTTAB.
data : fieldname1(30),
fieldname2(20),
fieldname3(20),
fname1(20),
fname2(20),
fname3(20).
fname1 = 'TOUR_ID'.
fname2 = 'VISIT_ID'.
fname3 = 'CUSTNR'.
concatenate 'ZCUSTTAB-' fname1 into fieldname1.
concatenate 'ZCUSTTAB-' fname2 into fieldname2.
concatenate 'ZCUSTTAB-' fname3 into fieldname3.
assign fieldname1 to <f1>.
assign fieldname2 to <f2>.
assign fieldname3 to <f3>.
<f1> = '12345'.
<f2> = '1'.
<f2> = '123'.
So, at this point I have my field symbols pointing towards individual fields , i.e.
<f1> holds value for ZCUSTTAB-TOUR_ID.
<f2> holds value for ZCUSTTAB-VISIT_ID.
<f3> holds value for ZCUSTTAB-CUSTNR.
Now, I want to move these individual values to a structure which is of type ZCUSTTAB, using which I can update the table ZCUSTTAB at DB.
Any ideas on how to achieve this ?
Thanks-Hi
U need to declar that table and that's all:
TABLES ZCUSTTAB.
data: <f1>, <f2> , <f3>,
<f4> type ZCUSTTAB.
data: upd type ZCUSTTAB.
data : fieldname1(30),
fieldname2(20),
fieldname3(20),
fname1(20),
fname2(20),
fname3(20).
fname1 = 'TOUR_ID'.
fname2 = 'VISIT_ID'.
fname3 = 'CUSTNR'.
concatenate 'ZCUSTTAB-' fname1 into fieldname1.
concatenate 'ZCUSTTAB-' fname2 into fieldname2.
concatenate 'ZCUSTTAB-' fname3 into fieldname3.
assign fieldname1 to <f1>.
assign fieldname2 to <f2>.
assign fieldname3 to <f3>.
<f1> = '12345'.
<f2> = '1'.
<f2> = '123'.
UPDATE ZCUSTTAB.
After assigning the field-symbols the structure ZCUSTTAB will be filled automatically.
U can also write:
TABLES ZCUSTTAB.
data: <f1>, <f2> , <f3>,
<f4> type ZCUSTTAB.
data: upd type ZCUSTTAB.
data : fieldname1(30),
fieldname2(20),
fieldname3(20),
fname1(20),
fname2(20),
fname3(20).
fname1 = 'TOUR_ID'.
fname2 = 'VISIT_ID'.
fname3 = 'CUSTNR'.
assign component fname1 of structure ZCUSTTAB to <f1>.
assign component fname2 of structure ZCUSTTAB to <f2>.
assign component fname3 of structure ZCUSTTAB to <f3>.
<f1> = '12345'.
<f2> = '1'.
<f2> = '123'.
UPDATE ZCUSTTAB.
Max -
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 fill Dynamic work area or field symbol?
HI All,
I have created dynamic work area(field symbol) by using following code. Now I want to fill the work area with values which are there in other internal table.
* Create dynamic internal table/structure
call method cl_alv_table_create=>create_dynamic_table
exporting
it_fieldcatalog = it_fieldcat
importing
ep_table = dyn_table.
assign dyn_table->* to <fs_table>.
* Create dynamic work area and assign to Field Symbol
create data dyn_line like line of <fs_table>.
assign dyn_line->* to <fs_wa>.
My <FS_WA> contains:
ROW1
ROW2
ROW3
ROW4 as fields in it without having any data.
I have other internal table.. where I have FIELDS and Data like following:
FIELD1 FIELD2 FIELD3
ID1 ROW1 A1
ID1 ROW2 A2
ID1 ROW3 A3
ID1 ROW4 A4
ID2 ROW1 B1
ID2 ROW2 B2
ID2 ROW3 B3
ID3 ROW1 C4
Important thing that I have to share with you is... Source table of my Internal table and Source structure to create my dynamic table are same.
This dynamic table has fields... with "FIELD2" values.
Thanks,
Naveen.ICreate a dynamic internal table
CALL METHOD cl_alv_table_create=>create_dynamic_table
EXPORTING
it_fieldcatalog = lt_fcat
IMPORTING
ep_table = lt_dy_table.
Create dynamic work area and assign to FS
ASSIGN lt_dy_table->* TO <fs_dyn_table>.
CREATE DATA lt_dy_line LIKE LINE OF <fs_dyn_table>.
ASSIGN lt_dy_line->* TO <fs_dyn_wa>.
Define WA
CREATE DATA dref TYPE (iv_struc_name).
ASSIGN dref->* TO <fs_final>.
Populate dynamic table from the file
OPEN DATASET iv_path FOR INPUT IN TEXT MODE ENCODING DEFAULT.
IF sy-subrc = 0.
DO.
READ DATASET iv_path INTO ls_str.
IF sy-subrc <> 0.
ev_failed = abap_true.
EXIT.
ENDIF.
SPLIT ls_str AT ';' INTO TABLE lt_dyn_tab. " columns
LOOP AT lt_dyn_tab INTO ls_dyn_tab.
READ TABLE lt_struc_fld INTO ls_struc_fld INDEX sy-tabix.
IF sy-subrc EQ 0.
MOVE ls_struc_fld-fieldname TO ls_fieldname.
ASSIGN COMPONENT ls_fieldname OF STRUCTURE <fs_dyn_wa> TO <fs_val>.
IF sy-subrc = 0.
<fs_val> = ls_dyn_tab.
ENDIF.
ASSIGN COMPONENT ls_fieldname OF STRUCTURE <fs_final> TO <fs_val>.
IF sy-subrc = 0.
<fs_val> = ls_dyn_tab.
ENDIF.
ENDIF.
ENDLOOP.
APPEND <fs_dyn_wa> TO <fs_dyn_table>.
APPEND <fs_final> TO et_table.
UNASSIGN: <fs_val>.
ENDDO.
ENDIF.
CLOSE DATASET iv_path.
Maybe you are looking for
-
Using a Deployable Proxy in a Web Dynpro Application
Hi, We have a Web Dynrpo application whose model is built from a set of Java business objects (POJOs.) These Java business objects currently make calls to a back-end R/3 system using JCo. We would like to provide the ability to allow the calls to b
-
Can not deploy after upgrading application from workshop 8.1 to 9.2
Hi, We have an application developed on workshop 8.1 worked fine. when we upgrade the application to 9.2, the application can not be deployed on weblogic server. The error is weblogic.application.ModuleException: [HTTP:101064][WebAppModule(SynDesk:Sy
-
Since downloading iOS 7 I have much slower WiFi connection and video playback is impaired. iPad 3
-
Hi all, I`ve had no luck creating a query report, neither using Table Join, nor Logical Database. Has somebody had any similar experience? Thanks -S
-
Open/save attachments from a website forum link is not working
Every time I click on a .doc or .docx or PDF it tells me I have chosen to open index.php and wants to open it in Dreamweaver. Other forum members using Firefox are having the same problem. Internet Explorer does open/save the document correctly so it