‎2008 Jun 30 10:19 AM
I understood that, in order to manipulate fields from an internal table or record passed as a parameter to a given form, you have to include STRUCTURE [table / struct name]. I wonder how would it be possible to have a program that decides, dynamically, amongst several possible table parameters - if we indeed have to have the STRUCTURE hard-coded, would such a thing be possible ?
Example:
FORM TEST TABLES P_ITAB STRUCTURE BSEG
USING P_REC STRUCTURE WS_REC.In the above excerpt of code, it is known beforehand that the table is of the BSEG type. Imagining a scenario where I would only have this information at run time, would it be possible to determine the structure of the table ?
Thanks
Avraham
‎2008 Jun 30 10:50 AM
if you don't have to know field names, you can use this simple solution:
FORM TEST TABLES P_ITAB
USING P_REC STRUCTURE WS_REC.
FIELD-SYMBOLS: <itab> TYPE ANY.
LOOP AT p_itab ASSIGNING <itab>.
MOVE-CORRESPONDING <itab> TO p_rec.
ENDLOOP.
ENDFORM.
you can still assign a field of <itab> but you have to do it for each field with ASSIGN COMPONENT
if you have a lot of named fields to use then you can map the input parameter into a local table with the structure you need
‎2008 Jun 30 10:50 AM
if you don't have to know field names, you can use this simple solution:
FORM TEST TABLES P_ITAB
USING P_REC STRUCTURE WS_REC.
FIELD-SYMBOLS: <itab> TYPE ANY.
LOOP AT p_itab ASSIGNING <itab>.
MOVE-CORRESPONDING <itab> TO p_rec.
ENDLOOP.
ENDFORM.
you can still assign a field of <itab> but you have to do it for each field with ASSIGN COMPONENT
if you have a lot of named fields to use then you can map the input parameter into a local table with the structure you need