Application Development and Automation Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

Routine from FORM -ENDFORM to METHOD

Former Member
0 Likes
2,615

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

1 ACCEPTED SOLUTION
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,299

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

1 REPLY 1
Read only

uwe_schieferstein
Active Contributor
0 Likes
1,300

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