Pass different Internal Tables to a Subroutine in ABAP

0
403

There are situations where an ABAPer needs to write the same code over and over again, just for the reason that the parameters (in this case, Internal Table) to be passed to this Subroutine are different in structure.

The code passes different Internal Tables to the same Subroutine, performing the common set of function on the tables.

REPORT zpwtest1 .
 
TYPES : t_mara TYPE TABLE OF mara ,
                t_kna1 TYPE TABLE OF kna1 .
 
DATA : i_mara TYPE t_mara ,
               i_kna1 TYPE t_kna1 ,
 
       ls_mara TYPE mara ,
       ls_kna1 TYPE kna1 .
 
ls_mara-matnr = ‘A1’ . APPEND ls_mara TO i_mara .
ls_mara-matnr = ‘A2’ . APPEND ls_mara TO i_mara .
ls_mara-matnr = ‘A3’ . APPEND ls_mara TO i_mara .
 
ls_kna1-kunnr = ‘K1’ . APPEND ls_kna1 TO i_kna1 .
ls_kna1-kunnr = ‘K2’ . APPEND ls_kna1 TO i_kna1 .
ls_kna1-kunnr = ‘K3’ . APPEND ls_kna1 TO i_kna1 .
 
PERFORM retrieve_history CHANGING  i_mara .
PERFORM retrieve_history CHANGING  i_kna1 .
 
*&———————————————————————*
*&      Form  retrieve_history
*&———————————————————————*
*       text
*———————————————————————-*
FORM retrieve_history CHANGING i_tab TYPE ANY TABLE .
 
  FIELD-SYMBOLS : <fs_work> TYPE ANY ,
                  <fs_item> TYPE ANY .
 
  WRITE : / ‘New table’ .
  LOOP AT i_tab ASSIGNING <fs_work>.
 
    ASSIGN COMPONENT 2 OF STRUCTURE <fs_work> TO <fs_item> .
    WRITE : / <fs_item> .
 
  ENDLOOP.
 
ENDFORM .                    “retrieve_history

Program Output

 

 

*source = Pawan Kesari

LEAVE A REPLY

Please enter your comment!
Please enter your name here