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: 

top include memory in function module

Former Member
0 Kudos

Hi friends,

Iam declaring a internal table ITAB in top include of function group.

now iam appending values into that itab from a function module of that function group say ZFUNCTION1.

and now iam calling that ZFUNCTION1 in a program sapmv45a in a user exit.

now iam again calling that same functin module ZFUNCTION1 in the same program at the other place ie: in other user exit.

Now will the values which i have appended into ITAB which i have declared in top include WILL contain values when the function module is being called for 2nd time.

Regards,

Priyanka

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi,

as a simple example you may look at FM

MESSAGES_INITIALIZE

MESSAGE_STORE

and MESSAGES_SHOW

where messages are appended to global internal table and displayed at the and. Code example (with macro - sorry - if you want to debug while appending set break inside FM MESSAGE_STORE):

REPORT ZTEST_MSG_STORE MESSAGE-ID ad.

DATA: ZEILE(3) TYPE N, COUNTER TYPE I, CHAR_ZEILE(3).
DEFINE MSG_ADD.
ADD 1 TO COUNTER.
IF COUNTER <= 999.
  MOVE COUNTER TO ZEILE.
  WRITE ZEILE TO CHAR_ZEILE.
ENDIF.
  OVERLAY CHAR_ZEILE WITH '000'.
CALL FUNCTION 'MESSAGE_STORE'
     EXPORTING
          ARBGB                   = SY-MSGID
*         EXCEPTION_IF_NOT_ACTIVE = 'X'
          MSGTY                   = SY-MSGTY
          MSGV1                   = SY-MSGV1
         MSGV2                   = SY-MSGV2
         MSGV3                   = SY-MSGV3
         MSGV4                   = SY-MSGV4
          TXTNR                   = SY-MSGNO
         ZEILE                   = ZEILE
*    IMPORTING
*         ACT_SEVERITY            =
*         MAX_SEVERITY            =
*    EXCEPTIONS
*         MESSAGE_TYPE_NOT_VALID  = 1
*         NOT_ACTIVE              = 2
*         OTHERS                  = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
END-OF-DEFINITION.

CALL FUNCTION 'MESSAGES_INITIALIZE'
*    EXPORTING
*         collect_and_send = 'X'
*         RESET            = 'X'
*         LINE_FROM        = ' '
*         LINE_TO          = ' '
*         I_IDENTIFICATION =
*         CHECK_ON_COMMIT  = 'X'
*    IMPORTING
*         E_IDENTIFICATION =
          .

MESSAGE S010 WITH 'msgv11' 'msgv12' 'msgv13' 'msgv14'.
MSG_ADD.
MESSAGE S010 WITH 'msgv21' 'msgv22' 'msgv23' 'msgv24'.
MSG_ADD.
MESSAGE S010 WITH 'msgv31' 'msgv32' 'msgv33' 'msgv34'.
MSG_ADD.
MESSAGE S010 WITH 'msgv41' 'msgv42' 'msgv43' 'msgv44'.
MSG_ADD.
DO 200 TIMES.
MESSAGE S010 WITH SY-INDEX.
MSG_ADD.
ENDDO.

CALL FUNCTION 'MESSAGES_SHOW'
*    EXPORTING
*         CORRECTIONS_OPTION    = ' '
*         CORRECTIONS_FUNC_TEXT = ' '
*         LINE_FROM             = ' '
*         LINE_TO               = ' '
*         OBJECT                = ' '
*         SEND_IF_ONE           = ' '
*         BATCH_LIST_TYPE       = 'J'
*         SHOW_LINNO            = 'X'
*         SHOW_LINNO_TEXT       = ' '
*         SHOW_LINNO_TEXT_LEN   = '3'
*    IMPORTING
*         CORRECTIONS_WANTED    =
*    EXCEPTIONS
*         INCONSISTENT_RANGE    = 1
*         NO_MESSAGES           = 2
*         OTHERS                = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

7 REPLIES 7

Former Member
0 Kudos

Hi Priyanka,

All the data declarations in the TOP include of the function group are global and are accessible across function modules in that function group.

At runtime, the global data modified by one FM would be visible to the other FM in the same function group.

Regards,

Chitrali

MarcinPciak
Active Contributor
0 Kudos

Function Group within which you declare your top include (global data) is similar to report program. When you run your program these global data are seen within entire program until it is ended. Identically when you call FM from this FG, all global data of that FG are placed into memory and removed when the program ends (in this case FM). Therefore the answer is no. You use top include only to declare data which will be seen among all the FMs defined within that FG.

If you want to pass some data to be seen within another program or FM, use SAP memory or ABAP memory (in case programs' calls are nested)

Hope it helps you

Marcin

0 Kudos

actually

my function module contains 2 parts of code.

iam checking for for indicator 1 & 2.

if indicator = '1'

this part of function module code will append the values to itab.

if indicator = '2'

in this part of the function module iam looping the itab.

now i will call the function module in 2 differnrt exits in sapmv45a (va01)

in ist exit indicator 1 part will be succesful and append the values.

now in the 2nd exit the indicator 2 will be succesfull.

here since iam calling the same function module within the same program can i able to loop the itab now.

will it contain the values in it.

Regards,

Priyanka.

i

0 Kudos

As long as FM is called couple times but within same program execution, your data will be there. So this will work!

Former Member
0 Kudos

Hello Priyanka,

It will not happen. For accessing the same you need to store the values which you get in the internal table into a custom table or in ABAP memory using IMPORT TO MEMORY-ID --> to save and EXPORT TO MEMORY-ID --> To read data, and this will only work if the programs runs in the same session.

Hope it helps.

Thanks,

Jayant

Former Member
0 Kudos

Hi,

as a simple example you may look at FM

MESSAGES_INITIALIZE

MESSAGE_STORE

and MESSAGES_SHOW

where messages are appended to global internal table and displayed at the and. Code example (with macro - sorry - if you want to debug while appending set break inside FM MESSAGE_STORE):

REPORT ZTEST_MSG_STORE MESSAGE-ID ad.

DATA: ZEILE(3) TYPE N, COUNTER TYPE I, CHAR_ZEILE(3).
DEFINE MSG_ADD.
ADD 1 TO COUNTER.
IF COUNTER <= 999.
  MOVE COUNTER TO ZEILE.
  WRITE ZEILE TO CHAR_ZEILE.
ENDIF.
  OVERLAY CHAR_ZEILE WITH '000'.
CALL FUNCTION 'MESSAGE_STORE'
     EXPORTING
          ARBGB                   = SY-MSGID
*         EXCEPTION_IF_NOT_ACTIVE = 'X'
          MSGTY                   = SY-MSGTY
          MSGV1                   = SY-MSGV1
         MSGV2                   = SY-MSGV2
         MSGV3                   = SY-MSGV3
         MSGV4                   = SY-MSGV4
          TXTNR                   = SY-MSGNO
         ZEILE                   = ZEILE
*    IMPORTING
*         ACT_SEVERITY            =
*         MAX_SEVERITY            =
*    EXCEPTIONS
*         MESSAGE_TYPE_NOT_VALID  = 1
*         NOT_ACTIVE              = 2
*         OTHERS                  = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
END-OF-DEFINITION.

CALL FUNCTION 'MESSAGES_INITIALIZE'
*    EXPORTING
*         collect_and_send = 'X'
*         RESET            = 'X'
*         LINE_FROM        = ' '
*         LINE_TO          = ' '
*         I_IDENTIFICATION =
*         CHECK_ON_COMMIT  = 'X'
*    IMPORTING
*         E_IDENTIFICATION =
          .

MESSAGE S010 WITH 'msgv11' 'msgv12' 'msgv13' 'msgv14'.
MSG_ADD.
MESSAGE S010 WITH 'msgv21' 'msgv22' 'msgv23' 'msgv24'.
MSG_ADD.
MESSAGE S010 WITH 'msgv31' 'msgv32' 'msgv33' 'msgv34'.
MSG_ADD.
MESSAGE S010 WITH 'msgv41' 'msgv42' 'msgv43' 'msgv44'.
MSG_ADD.
DO 200 TIMES.
MESSAGE S010 WITH SY-INDEX.
MSG_ADD.
ENDDO.

CALL FUNCTION 'MESSAGES_SHOW'
*    EXPORTING
*         CORRECTIONS_OPTION    = ' '
*         CORRECTIONS_FUNC_TEXT = ' '
*         LINE_FROM             = ' '
*         LINE_TO               = ' '
*         OBJECT                = ' '
*         SEND_IF_ONE           = ' '
*         BATCH_LIST_TYPE       = 'J'
*         SHOW_LINNO            = 'X'
*         SHOW_LINNO_TEXT       = ' '
*         SHOW_LINNO_TEXT_LEN   = '3'
*    IMPORTING
*         CORRECTIONS_WANTED    =
*    EXCEPTIONS
*         INCONSISTENT_RANGE    = 1
*         NO_MESSAGES           = 2
*         OTHERS                = 3
          .
IF SY-SUBRC <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
*         WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.

Former Member
0 Kudos

Hi Priyanka,

Yes if you have declared itab in the TOP include, you will be able to loop at it when the FM is called the second time, if in the first call to FM had populated itab with some data!

Thanks,

Chitrali