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

problem to make a common perform

Former Member
0 Likes
631

hi all ,

i have code as given below :

data : ist_temp2  TYPE TABLE OF ZT_temp ,
          ist_temp2  type table of zt_temp .

APPEND wa_ist_temp TO ist_temp.
APPEND wa_ist_so_details TO ist_so_details.

PERFORM get_so_char_pri.
FORM get_so_char_pri .
    IF NOT ist_temp[] IS INITIAL.
    wa_ist_chars-atnam = gd_atinn.
    APPEND wa_ist_chars TO ist_chars.

      LOOP AT ist_temp ASSIGNING <gs_ist_temp>.
        ld_tabix = sy-tabix.
        READ TABLE ist_var_chars ASSIGNING <gs_ist_var_chars>
                                 WITH KEY    vbeln = <gs_ist_temp>-vbeln
                                             posnr = <gs_ist_temp>-posnr
                                 BINARY SEARCH.
        IF sy-subrc EQ 0.
          <gs_ist_temp>-atwrt = <gs_ist_var_chars>-atwrt.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.
endform .
APPEND wa_ist_temp2 TO ist_temp2.

PERFORM get_so_char_alt.

FORM get_so_char_alt .
 
    
    IF NOT ist_var_chars[] IS INITIAL.
      SORT ist_var_chars BY vbeln posnr.

*     Loop at table to modify the characteristic value
      LOOP AT ist_temp2 ASSIGNING <gs_ist_temp2>.
        READ TABLE ist_var_chars ASSIGNING <gs_ist_var_chars>
                                  WITH KEY vbeln = <gs_ist_temp2>-vbeln
                                           posnr = <gs_ist_temp2>-posnr.
        IF sy-subrc EQ 0.
          <gs_ist_temp2>-atwrt = <gs_ist_var_chars>-atwrt.
        ENDIF.
      ENDLOOP.
    ENDIF.
  ENDIF.
ENDFORM.

I want to make this both performs common how can i do it ?

Plz help ... i cant use passing internal table as everything is global .

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
604

Hi

Basicly you can pass one parameter in perform for each handling...

lets say parameter can be 1 and 2. When it's 1 you use logic of first perform and when 2 you use logic of second one - it is only to make them one perform.

But to make it less lines you can do much more.

For exampe you can pass name of itab in loop as second parameter and you don't need to write same loop twice but only to enter (itab_name) and use same loop for both logics...

Best Regards

Yossi Rozenberg

6 REPLIES 6
Read only

Former Member
0 Likes
605

Hi

Basicly you can pass one parameter in perform for each handling...

lets say parameter can be 1 and 2. When it's 1 you use logic of first perform and when 2 you use logic of second one - it is only to make them one perform.

But to make it less lines you can do much more.

For exampe you can pass name of itab in loop as second parameter and you don't need to write same loop twice but only to enter (itab_name) and use same loop for both logics...

Best Regards

Yossi Rozenberg

Read only

0 Likes
604

Hi plz explain me suing my example .....

Read only

Former Member
0 Likes
604

Hi Ujwal,

Below is my understanding of your requirement, you have

Perform f1.

form f1.

code f1...

endform.

Perform f2.

form f2.

code f2...

endform.

You want merge F1 and F2 into F3, As the code in the two subroutines use global variables you cannot have a single sub routine, and differentiate the sub-routine calls F1 and F2. If my understanding is correct you can proceed as below.

1) Declare a local variable l_routine_flag

2) Subroutine - PERFORM F3 using l_routine_flag.

FORM F3 using l_routine_flag.

case l_routine_flag.

when 'F1'.

code for F1.

when 'F2'.

code for F2.

when others.

endcase.

endform.

And in your main program you can call the sub routines as shown below,

l_routine_flag = 'F1'.

perform F3 using l_routine_flag.

l_routine_flag = 'F2'.

perform F3 using l_routine_flag.

Regards,

Chen

Read only

0 Likes
604

hi as code of both forms are similar can we make a single form and can be used by both internal tables ?

Read only

0 Likes
604

Yes, if the code in both the forms are exactly the same, and the variables in concern are of the same type, you can have just one subroutine with no repeated code. For ex, let's say, you have two ITABs of same type "XYZ" declared globally. ITAB1 and ITAB2.

In that case your single sub routine can be as shown below.

FORM F3 USING itab STRUCTURE "XYZ" l_flag_routine.

CASE: l_flag_routine.

when 'F1'.

itab[] = itab1[].

when 'F2'.

itab[] = itab2[].

when Others.

end case.

code using itab....

ENFORM.

and in your main program call the sub routines as below,

l_flag_routine = 'F1'.

perform f3 using itab1[] l_flag_routine.

l_flag_routine = 'F2'.

perform f3 using itab2[] l_flag_routine.

Regards,

Chen

Read only

Former Member
0 Likes
604

thanks all for your posts .