2006 Dec 09 7:52 AM
hi friends,
can anyone give the idea of changing FORM-ENDFORM code
to METHOD-ENDMETHOD
if required i will give my code
thanks in advance
raj
2006 Dec 09 9:11 AM
Hello Raj
In general, you can transfer most of the coding possible in FORMs to methods. However, itabs with header lines must be replaced by table types, e.g.:
DATA:
ls_line TYPE <tablename>,
lt_itab TYPE STANDARD TABLE of <tablename>.Certain statements are not allowed in methods, e.g.
CALL SCREEN. If your original FORM called a screen then you have to move the CALL SCREEN statement to a function module and call this function module within your method.
If your original FORM contains USING and CHANGING parameters you have to define the corresponding IMPORTING and EXPORTING / CHANGING parameters in the method. Again, "itab" parameters must be defines as table types. If your FORM returned a single parameter then you can define a RETURNING parameter in your method.
Finally, like fields only exists in the context of a table (or structure) methods only exist in the context of a class. Thus, you have to define your class in the class builder (SE24) or, alternatively, define it as local class.
Here is a simple example:
FORM routine USING
ud_matnr TYPE matnr
CHANGING
cs_mara TYPE mara.
CLEAR: cs_mara.
SELECT SINGLE * FROM mara INTO cs_mara.
ENDFORM.METHOD read_single_material
IMPORTING
id_matnr TYPE matnr
RETURNING
rs_mara TYPE mara.
SELECT SINGLE * FROM mara INTO rs_mara.
ENDMETHOD.Regards
Uwe
hi friends,
can anyone give the idea of changing FORM-ENDFORM code
to METHOD-ENDMETHOD
if required i will give my code
thanks in advance
raj
2006 Dec 09 9:11 AM
Hello Raj
In general, you can transfer most of the coding possible in FORMs to methods. However, itabs with header lines must be replaced by table types, e.g.:
DATA:
ls_line TYPE <tablename>,
lt_itab TYPE STANDARD TABLE of <tablename>.Certain statements are not allowed in methods, e.g.
CALL SCREEN. If your original FORM called a screen then you have to move the CALL SCREEN statement to a function module and call this function module within your method.
If your original FORM contains USING and CHANGING parameters you have to define the corresponding IMPORTING and EXPORTING / CHANGING parameters in the method. Again, "itab" parameters must be defines as table types. If your FORM returned a single parameter then you can define a RETURNING parameter in your method.
Finally, like fields only exists in the context of a table (or structure) methods only exist in the context of a class. Thus, you have to define your class in the class builder (SE24) or, alternatively, define it as local class.
Here is a simple example:
FORM routine USING
ud_matnr TYPE matnr
CHANGING
cs_mara TYPE mara.
CLEAR: cs_mara.
SELECT SINGLE * FROM mara INTO cs_mara.
ENDFORM.METHOD read_single_material
IMPORTING
id_matnr TYPE matnr
RETURNING
rs_mara TYPE mara.
SELECT SINGLE * FROM mara INTO rs_mara.
ENDMETHOD.Regards
Uwe
| User | Count |
|---|---|
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |