Syntax of declaring the field variables:
Data <field name>(<length>) Type <Data Type> ----->1st(way).
or
Data <field name> Type <Data Element>. --------> 2nd(way).
or
Data <field name> Type <Database table name>--<field name>.
3rd(way) [this is the most preferable way of declaring fields].
Eg:
Data BUKRS(4) Type C. 1st way.
Data BUKRS Type BUKRS. 2nd way(the data element name may change from fields).
Data BUKRS Type T001-BUKRS. 3rd way.
OBJECT:
To display the vendor numbers , names , and countries.
solution:
LFA1(Vendor master table)
1.LIFNR ----->Vendor Number.
2. NAME1 -----> Vendor Name.
3.ORT01 ------> City.
4. LAND1 ------> Country.
(before writing the program see the steps to create an internal table in previous post because i repeated it twice)
PROGRAM:
*Declaring work area with 3rd way of declaring field variables.
DATA : Begin of WA.
LIFNR Type LFA1-LIFNR ,
NAME1 Type LFA1-NAME1 ,
LAND1 Type LFA1-LAND1,
End of WA.
*declaring internal table.
DATA IT Like Table Of WA.
*fetching data from data base table.
SELECT LIFNR NAME1 LAND1 FROM LFA1 INTO TABLE IT.
*retreving data from internal table
Loop At IT Into WA
WRITE : / WA-LIFNR,
WA-NAME1,
WA-LAND1.
ENDLOOP.
>>Save , check , activate and test it you will get output .
NOTE:
The order of the fields in the work area as well as
the order of the the fields in SELECT Query must be SAME.


Comments
Post a Comment