Monday 28 May 2012

FIELD SYMBOLS

*******FIELD SYMBOLS PROGRAM-1******

data : begin of line,
          col1 value 'a',
          col2 value 'b',
          col3 value 'c',
       end of line.

field-symbols : <fs> like line. " Declaring a field symbol
assign line to <fs> .
if <fs> is assigned .
  write :/ <fs>-col1,
            <fs>-col2,
            <fs>-col3.
  endif.

*******FIELD SYMBOL PROGRAM-2************

data : val(10) value '1234567890'.
data : begin of line1,
        col1(2),
        col2(2),
        col3(3),
        col4(3),
       end of line1.

data : begin of line2,
       col1(2),
       col2 type sy-datum,
      end of line2.

field-symbols : <fs1> structure line1 default val.
field-symbols : <fs2> structure line2 default val.

if <fs1> is assigned.
  write :/ <fs1>-col1,
             <fs1>-col2,
            <fs1>-col3,
            <fs1>-col4.
  endif.
  uline.
  if <fs2> is assigned.
  write :/ <fs2>-col1,
           <fs2>-col2.
  endif.

**********FIELD SYMBOL PROGRAM-3***********

data : text(15) value 'PRODUCTS',
       num type i value 10,
       begin of line1,
         col1 type i value '20',
         col2 type i value '40',
       end of line1,
       line2 like line1.

field-symbols : <fs1> type any,
                <fs2> type i.

assign text to <fs1>.
assign num to <fs2>.
write :/ <fs1>, <fs2>.

describe field <fs1> length <fs2> in character mode.
write :/ <fs1>, 'has length=', num , <fs2>.

uline.
assign line1 to <fs1>.
assign line2-col1 to <fs2>.
move <fs1> to line2.
write :/ <fs2>.

**********FIELD SYMBOLS PROGRAM-4***************

data : begin of line,
       text1(10) value '0123456789',
       text2(10) value 'abcdefghij',
       end of line.

field-symbols <fs> type any.
write :/ line-text1+5.
write :/ line-text2+5.
assign line-text1+5(*) to <fs>.
if <fs> is assigned.
  write :/ <fs>.
  endif.

**********FIELD SYMBOLS PROGRAM-5***************

data : begin of line,
       col1 type i value '11',
       col2 type i value '22',
       col3 type i value '33',
       end of line.
field-symbols : <fs1> type any,
                <fs2> type any,
                <fs3> type any.
data : comp type char4 value 'COL3'.
assign line to <fs1>.
ASSIGN COMP TO <FS2>.

DO 3 TIMES.
  ASSIGN COMPONENT SY-INDEX OF STRUCTURE <FS1> TO <FS3>.
  WRITE :/ <FS3>.
  ENDDO.

  ASSIGN COMPONENT <FS2> OF STRUCTURE <FS1> TO <FS3>.
  WRITE :/ <FS3>.

**********FIELD SYMBOLS PROGRAM-6***************

types : begin of line,
       year(4) type n,
       month(2) type n,
       day(2) type n,
  end of line.

  field-symbols <fs> type line.

  assign sy-datum to <fs> casting.
  write :/ <fs>-year,
           <fs>-month,
           <fs>-day.

**********FIELD SYMBOLS PROGRAM-7***************

types : begin of line,
       year(4) type n,
       month(2) type n,
       day(2) type n,
  end of line.

  field-symbols <fs1> type any.
  field-symbols <fs2> type n.

  assign sy-datum to <fs1> casting type line.

  do 3 times.

    assign component sy-index of structure <fs1> to <fs2>.
    write :/ <fs2>.
    enddo.

**********FIELD SYMBOLS PROGRAM-8***************

data : text(8) type c value '20120129'.
data : hex type c value 'X'.
field-symbols : <fs> type any.

assign text to <fs>.
write :/ <fs>.
assign text to <fs> casting type d.
write :/ <fs>.

assign text to <fs> casting type x.
write :/ <fs>.

assign text to <fs> casting type (hex).
write :/ <fs>.

**********FIELD SYMBOLS PROGRAM-9***************

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.

**********FIELD SYMBOLS PROGRAM-10***************

types : begin of line,
        col1 type i,
        col2 type i,
        end of line.

 data : dref1 type ref to data,
        dref2 type ref to data.

field-symbols : <fs1> type line,
                <fs2> type i.
create data dref1 type line.
assign dref1->* to <fs1>.
<fs1>-col1 = 11.
<fs1>-col2 = 22.
dref2 = dref1.
assign dref2->* to <fs2> casting.
write :/ <fs2>.
get reference of <fs1>-col2 into dref2.
assign dref2->* to <fs2>.
write :/ <fs2>. 

**********FIELD SYMBOLS PROGRAM-11***************

data : p_num1 type p decimals 2 value '100',
       p_num2 type p decimals 2,
       p_num3 type p decimals 2.

field-symbols : <fs1> type any,
                <fs2> type any.

assign p_num1 to <fs1> casting type p decimals 1.
write :/ 'p_num1=', p_num1,
                    <fs1>.

p_num2 = <fs1>.
write :/ 'p_num2=' , p_num2.
assign p_num2 to <fs2> casting type p decimals 4.
write  <fs2>.

p_num3 = <fs1> + <fs2>.
write :/ 'p_num3=', p_num3.

**FIELD SYMBOLS & DATA REFERENCE PROGRAM-12********
types : begin of ty_tab,
        col1,
        col2,
        col3,
    end of ty_tab.

data : dref1 type ref to data.
field-symbols : <fs1> type ty_tab.
create data dref1 type ty_tab.
assign dref1->* to <fs1>.
<fs1>-col1 = 'z'.
<fs1>-col2 = 'y'.
<fs1>-col3 = 'x'.
write :/ <fs1>-col1,
         <fs1>-col2,
          <fs1>-col3.

***FIELD SYMBOLS & DATA REFERENCE PROGRAM-13******

types : begin of ty_tab,
        c1 type  char2,
        c2 type char2,
        c3 type char2,
       end of ty_tab.

 data : dref1 type ref to data.
 data : dref2 type ref to data.
 field-symbols : <fs1> type standard table.
 field-symbols : <fs2> type ty_tab.
 create data dref1 type standard table of ty_tab.
 assign dref1->* to <fs1>.
 create data dref2 type ty_tab.
 assign dref2->* to <fs2>.

 <fs2>-c1 = 'aa'.
 <fs2>-c2 = 'ab'.
 <fs2>-c3 = 'ac'.
 append <fs2> to <fs1>.

  <fs2>-c1 = 'xx'.
 <fs2>-c2 = 'xy'.
 <fs2>-c3 = 'xz'.
 append <fs2> to <fs1>.

   <fs2>-c1 = 'pp'.
 <fs2>-c2 = 'pq'.
 <fs2>-c3 = 'pr'.
 insert <fs2> into <fs1> index 3.

 loop at <fs1> assigning <fs2>.
   write :/ <fs2>-c1,
            <fs2>-c2,
            <fs2>-c3.

   endloop.

**FIELD SYMBOLS & DATA REFERENCE PROGRAM-14*********

types : begin of ty_tab,
        col1,
        col2,
        col3,
    end of ty_tab.

data : dref1 type ref to data.
data : dref2 type ref to data.
field-symbols : <fs1> type ty_tab.
field-symbols : <fs2> type c.
create data dref1 type ty_tab.
assign dref1->* to <fs1>.
<fs1>-col1 = 'z'.
<fs1>-col2 = 'y'.
<fs1>-col3 = 'x'.
write :/ <fs1>-col1,
         <fs1>-col2,
          <fs1>-col3.
uline.

create data dref2 type c.
get reference of <fs1>-col1 into dref2.
assign dref2->* to <fs2>.
write :/ <fs2>.
get reference of <fs1>-col2 into dref2.
assign dref2->* to <fs2>.
write :/ <fs2>.

get reference of <fs1>-col3 into dref2.
assign dref2->* to <fs2>.
write :/ <fs2>. 

***FIELD SYMBOLS & DATA REFERENCE PROGRAM-15*******

TYPES : BEGIN OF TY_TAB,
        F1 TYPE I,
        F2 TYPE I,
        F3 TYPE I,
        END OF TY_TAB.

DATA : DREF1 TYPE REF TO DATA.
DATA : DREF2 TYPE REF TO DATA.

FIELD-SYMBOLS : <FS1> TYPE TY_TAB.
FIELD-SYMBOLS : <FS2> TYPE I.

CREATE DATA DREF1 TYPE TY_TAB.

ASSIGN DREF1->* TO <FS1>.

<FS1>-F1 = '11'.
<FS1>-F2 = '12'.
<FS1>-F3 = '13'.

DREF2 = DREF1.

ASSIGN DREF2->* TO <FS2> CASTING.
WRITE : / <FS2>.



GET REFERENCE OF <FS1>-F2 INTO DREF2.
ASSIGN DREF2->* TO <FS2>.
WRITE / <FS2>.

    -------------------------------------------------------------

2 comments:

Manish Shankar said...

Good explanation, Keep it up..

SoftMan said...

You should say: Good example, because there is no explanation at all!

Comments system

Disqus Shortname