Define work area with referencing to dynamic structure name
I need help on defining a work area with referencing to a dynamic structure name. Could you please help?
Alejandro Bindi replied
Check this coding:
PARAMETERS: p_type TYPE typename OBLIGATORY DEFAULT 'VBAK'. DATA: gr_dataref TYPE REF TO data. FIELD-SYMBOLS: <gfs> TYPE ANY. CREATE DATA gr_dataref TYPE (p_type). ASSIGN gr_dataref->* TO <gfs>.
<gfs> will take the structure from the name parameter, in this case table VBAK by default.
So if you have VBAK data in your string, doing the assignment <gfs> = string would split the data over the different fields.
What this code is lacking is exception handling, which depends on the SAP version you're at.
If your WAS is >= 6.20, you can use exception classes, so you should catch exception CX_SY_CREATE_DATA_ERROR:
TRY. CREATE DATA gr_dataref TYPE (p_type). CATCH CX_SY_CREATE_DATA_ERROR. " Exception handling in here ENDTRY.
On older releases you should use CATCH SYSTEM-EXCEPTIONS ... ENDCATCH instead.
Edited by: Alejandro Bindi on Sep 23, 2008 6:23 PM