Application Development 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: 

calling form-routines

Former Member
0 Kudos

Hello ABAP gutus,

i am using 10 form-routines to get some data, in all subroutines code is same, but i am passing different internal tables to all form-routines with USING, CHANGING parameters.

for example

perform get_header1 using itab changing jtab.

perform get_header2 using itab1 changing jtab1.

FORM get_header1 USING P_ITAB

CHANGING P_JTAB.

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = r_alvtab

CHANGING

t_table = itab[].

CALL METHOD r_alvtab->get_columns

RECEIVING

value = r_col.

CALL METHOD r_col->get

RECEIVING

value = r_cols.

loop at r_cols into wa_col.

ref_col = wa_col-r_column.

CALL METHOD ref_col->get_medium_text

RECEIVING

value = lv_text.

jtab-header = lv_text.

APPEND jtab.

endloop.

endform.

FORM get_header2 USING P_ITAB

CHANGING P_JTAB.

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = r_alvtab

CHANGING

t_table = itab1[].

CALL METHOD r_alvtab->get_columns

RECEIVING

value = r_col.

CALL METHOD r_col->get

RECEIVING

value = r_cols.

loop at r_cols into wa_col.

ref_col = wa_col-r_column.

CALL METHOD ref_col->get_medium_text

RECEIVING

value = lv_text.

jtab1-header = lv_text.

APPEND jtab1.

endloop.

endform.

as above i used 10 form-routines.but i passed different internal tables.after these subrotines i am using those internal table in function modules.

now my client wants me to maintain one form-routine instead of 10 form-routines.

Is it possible that? please tell me . its urgent

Regards

Mahesh

8 REPLIES 8

chaouki_akir
Contributor
0 Kudos

Hello,

do those internal tables have the same structure ?

Former Member
0 Kudos

Hi,

Yes you can do that using FIELD SYMBOLS.

Take a look at this:

PERFORM appl_upload USING p_header 'gt_header[]' 'gs_header'.
PERFORM appl_upload USING p_item   'gt_item[]' 'gs_item'.
PERFORM appl_upload USING p_period 'gt_period[]' 'gs_period'.

Here if you see, i need to upload a file from Appln Server into 3 different tables with diff structures. However i use the same PERFORM. The trick here is pass the tables names in single quotes ' ' i.e nothing but as a constant.

In your FORM:

FORM appl_upload  USING    FILE LIKE rlgrap-filename
                           TABNAME TYPE string
                           WAREA TYPE string.

  FIELD-SYMBOLS: <TAB>   TYPE TABLE.
  FIELD-SYMBOLS: <WA>.

  ASSIGN (TABNAME) TO <TAB>.
  ASSIGN (WAREA) TO <WA>.

  OPEN DATASET FILE FOR INPUT IN TEXT MODE ENCODING DEFAULT.
  IF sy-subrc NE 0.
  ELSE.
    DO.
      READ DATASET FILE INTO <WA>.
      IF sy-subrc NE 0.
        EXIT.
      ELSE.
        APPEND <WA> TO <TAB>.
      ENDIF.
    ENDDO.
    CLOSE DATASET FILE.
  ENDIF.

ENDFORM.                    " appl_upload

So here u assign the names you passed to the FIELD SYMBOLS and you can do your logic.

Let me know if you have any issues.

Sri

0 Kudos

hello sri ,

thank for your quick reply, can you modify my code as you said? i sent sample code na. please modify it once so that i can understand it.

Regards

Mahesh

former_member223537
Active Contributor
0 Kudos
perform get_header1 using itab changing jtab.
perform get_header2 using itab1 changing jtab1.

FORM get_header1 USING P_ITAB
CHANGING P_JTAB.

CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = r_alvtab
CHANGING
t_table = p_itab[].

CALL METHOD r_alvtab->get_columns
RECEIVING
value = r_col.

CALL METHOD r_col->get
RECEIVING
value = r_cols.

loop at r_cols into wa_col.
ref_col = wa_col-r_column.
CALL METHOD ref_col->get_medium_text
RECEIVING
value = lv_text.
jtab-header = lv_text.
APPEND p_jtab.
endloop.
endform.

FORM get_header2 USING P_ITAB
CHANGING P_JTAB.

CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = r_alvtab
CHANGING
t_table = p_itab1[].

CALL METHOD r_alvtab->get_columns
RECEIVING
value = r_col.

CALL METHOD r_col->get
RECEIVING
value = r_cols.

loop at r_cols into wa_col.
ref_col = wa_col-r_column.
CALL METHOD ref_col->get_medium_text
RECEIVING
value = lv_text.
jtab1-header = lv_text.
APPEND p_jtab1.
endloop.
endform.

Former Member
0 Kudos

Hi,

try this common subroutine..


FORM get_header1 USING P_ITAB
CHANGING P_JTAB.

* " Inserted here..
FIELD-SYMBOLS : <FS>.

CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = r_alvtab
CHANGING
t_table = p_itab[].     " Changed here..

CALL METHOD r_alvtab->get_columns
RECEIVING
value = r_col.

CALL METHOD r_col->get
RECEIVING
value = r_cols.

loop at r_cols into wa_col.
ref_col = wa_col-r_column.
CALL METHOD ref_col->get_medium_text
RECEIVING
value = lv_text.
* " Inserted here..
ASSIGN COMPONENT 'HEADER' OF STRUCTURE jtab INTO <FS>.

CHECK sy-subrc = 0.

<FS> = lv_text.
* " Inserted End...

APPEND jtab.
endloop.
endform.

Thanks

Naren

0 Kudos

Hello Naredran,

i tried your way, but its not working. please check that once

Regards

Mahesh

Former Member
0 Kudos

Hi,

Does it give any syntax error..Please let me know

Thanks

Naren

0 Kudos

Hello Naredran.

see the below code

perform get_header1 using it changing it1.

perform get_header1 using itab changing it2.

&----


*& Form get_header1

&----


  • text

----


  • -->P_IT text

  • <--P_IT1 text

----


FORM get_header1 USING P_IT

CHANGING P_IT1.

FIELD-SYMBOLS : <FS>.

CALL METHOD cl_salv_table=>factory

IMPORTING

r_salv_table = r_alvtab

CHANGING

t_table = p_it.

CALL METHOD r_alvtab->get_columns

receiving

value = r_col

.

CALL METHOD r_col->get

receiving

value = r_cols

.

loop at r_cols into wa_col.

ref_col = wa_col-r_column.

CALL METHOD ref_col->get_medium_text

receiving

value = lv_text.

assign IT1 to <FS>.

<FS> = lv_text.

append it1.

endloop.

ENDFORM. " get_header1

bellow error is coming while use the code which you said.

A USING reference parameter should not be used. Instead, define the

parameter as a USING-VALUE(...) or CHANGING parameter.

please let me know waht is wrong .