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: 

dynamic Structure Creation !!

Former Member
0 Kudos
114

hi all ,

I have two function Module with different structute with the same Table name parameter

Like in FM1 :

Tables : I_Tab Like Structure1

And Second FM2 Program2 :

Tables : I_Tab Like Structure2

And this two FM will call my Function module which i need to built with the same processing for both.

So, Can i create a dynamic structure based on the caller FM.

That is if FM1 Calls then I create I_Tab with Stru1

and if FM2 Calls then I create I_Tab with Stru2

Hope i m clear to present my problem

Praff

5 REPLIES 5

Former Member
0 Kudos
89

Hi

You can try to use this solution:

DATA: GT_FIELDCAT TYPE LVC_T_FCAT.

DATA: MY_TABLE TYPE REF TO DATA,

MY_WORKAREA TYPE REF TO DATA.

FIELD-SYMBOLS: <TABLE> TYPE TABLE,

<WA> TYPE ANY.

DATA: STRACTURE_NAME LIKE DD02L-TABNAME.

  • Create internal table

IF FM = FM1

STRACTURE_NAME = .....

ELSE.

STRACTURE_NAME = .....

ENDIF.

CALL FUNCTION 'LVC_FIELDCATALOG_MERGE'

EXPORTING

I_STRUCTURE_NAME = STRUCTURE_NAME

  • I_CLIENT_NEVER_DISPLAY = 'X'

  • I_BYPASSING_BUFFER =

CHANGING

CT_FIELDCAT = GT_FIELDCAT

EXCEPTIONS

INCONSISTENT_INTERFACE = 1

PROGRAM_ERROR = 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.

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

  • I_STYLE_TABLE =

IT_FIELDCATALOG = GT_FIELDCAT

IMPORTING

EP_TABLE = MY_TABLE

  • E_STYLE_FNAME =

EXCEPTIONS

GENERATE_SUBPOOL_DIR_FULL = 1

OTHERS = 2

.

IF SY-SUBRC <> 0.

MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO

WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.

ENDIF.

ASSIGN MY_TABLE->* TO <TABLE>.

  • Create work area

CREATE DATA MY_WORKAREA LIKE LINE OF <TABLE>.

ASSIGN MY_WORKAREA->* TO <WA>.

or this:

DATA: ITAB1 LIKE STANDARD TABLE OF <STRUCTURE1>,

ITAB2 LIKE STANDARD TABLE OF <STRUCTURE2>.

FIELD-SYMBOLS: <TABLE> TYPE TABLE.

IF FM = FM1

ASSIGN ITAB1 TO <TABLE>.

ELSE.

ASSIGN ITAB2 TO <TABLE>.

ENDIF.

Max

Message was edited by: max bianchi

Message was edited by: max bianchi

0 Kudos
89

hi thanks

But caller function module is passing the values to my function module .

so how to do that >

that is how to use that data from caller fm

Praff

0 Kudos
89

Hi

Your fm should have a parameter table without reference, so it'll have the structure of the table transfered from caller.

Can you give me your code where you manage this calling?

Max

0 Kudos
89

thanks yaar it has been solved

Praff

Former Member
0 Kudos
89

very useful thread.

it work fine for me.

thanks