Do you ever know we can do wonders with field symbols in ABAP programs??? Yes. This is true. Let us see this with below practical example.
Access the internal tables or work areas that are not defined in interface of user exit/customer exit/dynamic program!!!
There are many instances where customer exits/user exits/dynamic program calls are used for coding custom business logic specially in sales and distribution area.
Customer exits are called from standard SAP programs using statement CALL-CUSTOMER FUNCTION '.....'. Parameters are defined in the FM interface. When, customer exit is implemented, only parameters defined in the interface are accessible for read/modify.
User exits are called as subroutines with statement PERFORM from standard programs.
Dynamic program calls usually happens from standard programs. Dynamic program name can be picked up from customization.
E.g. Sales order, Delivery, Billing output type processing routines.
For implementing business logic, if you need some data which is not available in FM interface/user exit/in dynamic program, how to go about? Do we really need to compromise on the requirement? No. Definitely not. Field symbol is the savior here. Let us see how to use them to access the data not available in the interface/user exit main program/dynamic program.
Place the break point in the required exit and do the business transaction. Once control stop at break point, go to calls button. You can see a list of program chain here from where different calls has happened. See the sample screen below which is an example of custom program assigned to process an output type. This program is called dynamically from standard program.
How to define field symbol?
FIELD-SYMBOLS <lfs_xlips> TYPE ANY.
This statement defines the field symbol with undefined structure.
From where to get data?
We can access any internal table or work area which is defined in the programs available in the call stack.
How to access data?
Use below statement to access data of a internal table/work area of the program available in call stack.
ASSIGN ('(SAPMV50A)XLIPS[]') TO <lfs_xlips>.
This statement assigns the structure and data of internal table XLIPS (Data is taken from the point when the control passed from program SAPMV50A to program SAPLV61B. You can see the sequence from call stack). Any internal table/work area defined in any of the programs in the call stack can be accessed with this technique.
Before executing the assign statement, if you see the contents of field symbol <lfs_xlips>, this variable comes as not recognized as shown below.
After executing above statement, field symbol is assigned with the structure and data of internal table XLIPS from program SAPMV50A.
But in the same dynamic program, if you directly try to access internal table XLIPS, this comes as unrecognized.
This technique also helps to get data of particular table at different point in time from different programs as well.
Note: This technique has to be used with extreme caution and care as any modification in data to field symbol directly reflects in the source data object (Function same as Modify statement).
E.g: If you change the data of field symbol <lfs_xlips>, this directly modifies the data in source internal table XLIPS as well along with field symbol data without MODIFY statement.
Your valuable feedback and comments are always welcome
Regards,
Vinod Vemuru