SAP R/3 форум ABAP консультантов
Russian ABAP Developer's Club

Home - FAQ - Search - Memberlist - Usergroups - Profile - Log in to check your private messages - Register - Log in - English
Blogs - Weblogs News

Reading other program’s data using field symbols in ABAP



 
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dynamic Programming | Динамическое программирование
View previous topic :: View next topic  
Author Message
admin
Администратор
Администратор



Joined: 01 Sep 2007
Posts: 1640

PostPosted: Sat Sep 22, 2007 3:50 pm    Post subject: Reading other program’s data using field symbols in ABAP Reply with quote

One of the first questions we ask when we are going to implement a new logic in an SAP user exit is: what kind of data is available as input and what can I modify as output? Though limited, most of the time the parameters of user exit functions let us do what we want. But sometimes we get stuck because some field is not provided. The field can be either some global field of the calling program or a global field in a function group that is used by calling program. (You should remember that in latter case, the data is still sitting in the memory until we exit the main program or transaction, and can be used by any subsequent calls).

There is a simple trick that allows you read and modify the global data of any module loaded by a running program. It is using the ABAP’s dynamic assignment feature of field-symbols. The best way is to show it with an example.

The user exit ZXCO1U06 is running when we save a production order in the transaction CO02. In this user exit you can do some additional checks, modify data, probably issue some messages and so on. Unfortunately, only header data of the order is provided as its parameter. Reading the database is not an option because any updated data (new operations, new status flags) is not yet written to the database. If you want to read, say, order operations or their status, you either call the same functions that are called by CO02 (as the same global data is used), or access the data directly. If we want to check the status of the order and ist operations, we could read the global data (internal tables) of the function group BSVA, that is used to manage the status in CO02. The table that contains the status flags is called JEST_BUF and we can get the table content in out user exit in the following way:

Code:
* See declarations in LBSVATOP
* This type should match the one used in SAP program!
types: begin of t_jest.
            include structure jest_upd.
types:
            mod,
            inact_old like jest-inact,
          end of t_jest.

data:
  lf_text(40)   type c,
  lt_jest       type standard table of t_jest.

field-symbols:
  <ls_jest_buf>      type any table.

lf_text = '(SAPLBSVA)JEST_BUF[]'.
assign (lf_text) to <ls_jest_buf>.
check sy-subrc = 0.
lt_jest[] = <ls_jest_buf>.  "now everything is in lt_jest !

If we want to do some changes of the global data, we could do a "reversed" assignment to the field-symbol:
<ls_jest_buf> = lt_jest[].

Finding the needed program and variable names is not a straightforward task, but can be done with debugger. The best motivation is that there is rarely some alternative solution (that is less ugly than using dynamic ABAP assignments).

Important note: Using user exits is a kind of advanced task because you can easily screw up the SAP program’s internal data. But this trick gives you even more chances of doing that, so everything should be done with a special care.

http: //abaplog.wordpress.com/2007/03/01/reading-other-programs-data-using-field-symbols-in-abap/
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Russian ABAP Developer's Club Forum Index -> Dynamic Programming | Динамическое программирование All times are GMT + 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


All product names are trademarks of their respective companies. SAPNET.RU websites are in no way affiliated with SAP AG.
SAP, SAP R/3, R/3 software, mySAP, ABAP, BAPI, xApps, SAP NetWeaver and any other are registered trademarks of SAP AG.
Every effort is made to ensure content integrity. Use information on this site at your own risk.