2007 Dec 24 11:39 AM
what r field symbols and field groups?what is "component idx of
structure" cluse with field group?
what r field symbols and field groups?what is "component idx of
structure" cluse with field group?
2007 Dec 24 11:42 AM
HI Srinath,
A field symbol is the place holder for a field. it doesnot reserve any space for the field, but points to the field. similar to pointer concept of other languages.
the ASSIGN statement is used to associate a field to the field symbol. if the data of the field is changed the field symbol will point the changed data. also if we assign any value directly to the field symbol it'll be reflected to the field attached to it.
a field symbol can be attached to a field of same type, if the type is not declared it can be attached to any data type.
DATA CNT TYPE I.
FIELD-SYMBOLS: <F1>,
<F2> TYPE I,
<F3> LIKE COUNTER.
CNT = 10.
ASSIGN: COUNTER TO <F1>,
COUNTER TO <F2>,
COUNTER TO <F3>.
WRITE: CNT, <F1>, <F2>, <F3>.
<F1> = 20.
WRITE: CNT, <F1>, <F2>, <F3>.
for the 1st write stmt o/p will be 10 10 10 10
for the 2nd write stmt o/p will be 20 20 20 20
Reward if useful
Regards
ANUPAM
2007 Dec 24 11:56 AM
Hi srinath,
Field symbols :are placeholders for other fields.
Field symbols use the memory to directly access the data from the internal table.
We do not pass the data to the header and from where we read the data which takes more time.
As a result Field Symbol is similar to a Pointer in C-Language. We can directly get the data from the memory which is very convenient.
A field symbol can point to any data object.
Does not occupy memory for the data objects.
Field should be assigned to field symbol before it is addressed in the program.
Field group:
It combines the related fields together into meaningful unit.
It provides the pre-selection so that we do not have to search through all fields of data source.
End user only has access to those fields assigned to field group
syntax:
data : letter(10) .
field-symbols : <fs> type any.
assign letter to <fs> type 'X'.
write <fs>.
sample code for field symbols:
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
sample code for field groups:
&----
*& Report ZSPFLI *
*& *
&----
REPORT ZSPFLI LINE-SIZE 132 LINE-COUNT 65(3)
NO STANDARD PAGE HEADING.
TABLES:SPFLI,SCARR, SFLIGHT, SBOOK.
SELECT-OPTIONS: MYCARRID FOR SPFLI-CARRID.
FIELD-GROUPS: HEADER, SPFLI_FG, SFLIGHT_FG, SBOOK_FG.
INSERT:
SPFLI-CARRID
SPFLI-CONNID
SFLIGHT-FLDATE
SBOOK-BOOKID
INTO HEADER,
SPFLI-CARRID
SPFLI-CONNID
SPFLI-CITYFROM
SPFLI-AIRPFROM
SPFLI-CITYTO
SPFLI-AIRPTO
SPFLI-DEPTIME
SCARR-CARRNAME
INTO SPFLI_FG,
SFLIGHT-FLDATE
SFLIGHT-SEATSMAX
SFLIGHT-SEATSOCC
SFLIGHT-PRICE
INTO SFLIGHT_FG,
SBOOK-BOOKID
SBOOK-CUSTOMID
SBOOK-CUSTTYPE
SBOOK-SMOKER
INTO SBOOK_FG.
SELECT * FROM SPFLI WHERE CARRID IN MYCARRID.
SELECT SINGLE * FROM SCARR WHERE CARRID = SPFLI-CARRID.
EXTRACT SPFLI_FG.
SELECT * FROM SFLIGHT
WHERE CARRID = SPFLI-CARRID AND CONNID = SPFLI-CONNID.
EXTRACT SFLIGHT_FG.
SELECT * FROM SBOOK
WHERE CARRID = SFLIGHT-CARRID AND
CONNID = SFLIGHT-CONNID AND FLDATE = SFLIGHT-FLDATE.
EXTRACT SBOOK_FG.
CLEAR SBOOK.
ENDSELECT.
CLEAR SFLIGHT.
ENDSELECT.
CLEAR SPFLI.
ENDSELECT.
SORT.
LOOP.
AT SPFLI_FG.
FORMAT COLOR COL_HEADING.
WRITE: / SCARR-CARRNAME,
SPFLI-CONNID, SPFLI-CITYFROM,
SPFLI-AIRPFROM, SPFLI-CITYTO, SPFLI-AIRPTO, SPFLI-DEPTIME.
FORMAT COLOR OFF.
ENDAT.
AT SFLIGHT_FG.
WRITE: /15 SFLIGHT-FLDATE, SFLIGHT-PRICE, SFLIGHT-SEATSMAX,
SFLIGHT-SEATSOCC.
ENDAT.
AT SBOOK_FG.
WRITE: /30 SBOOK-BOOKID, SBOOK-CUSTOMID,
SBOOK-CUSTTYPE, SBOOK-SMOKER.
ENDAT.
ENDLOOP.
&----
*& END OF REPORT
&----
please reward if helpful,
thanks & regards,
Dinesh.
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |