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: 

Passing Dynamic Internal Table values to another program

lijisusan_mathews
Active Contributor
0 Kudos

Hi,

I have a program ZSAPNEW.

In this I have created a Dynamic internal table <fs_emp>. The number of fields differ for each run. The values are passed into <fs_emp> in this program. Now I need to submit thsi program from a main program ZHEAD and then display the values got from ZHEAD. For this I need to access the values retrieved from ZSAPNEW in <fs_emp> in ZHEAD. I cant figure out how to do this. I tried IMPORT ing the reference of teh field symbol too/ But its not allowing references in IMPORT/EXPORT. And since the table is of type ANY( as structure varies) I cant assign it to an internal table and then pass. Can some one suggest a solution please.

Suzie

1 ACCEPTED SOLUTION

kesavadas_thekkillath
Active Contributor
0 Kudos

ignore

Edited by: Keshav.T on Oct 25, 2011 2:08 PM

18 REPLIES 18

Former Member
0 Kudos

Hi

You can user following techniq for this using (Pgm name)<fs_name>:

FIELD-SYMBOLS: <NEW_FIELD> TYPE ANY.

DATA: FIELD_SYMBOL_NAME(30) VALUE '(ZPROGRAM)<FS>'.

ASSIGN (FIELD_SYMBOL_NAME) TO <NEW_FIELD>.

<NEW_FIELD> = ......

0 Kudos

Hi Fayaz,

This is my Code..The Assign statement returns value 4.

 
FIELD-SYMBOLS: <NEW_FIELD> TYPE ANY table.

DATA: FIELD_SYMBOL_NAME(30) VALUE '(ZSDR010)<FS_EMP>'.

ASSIGN (FIELD_SYMBOL_NAME) TO <NEW_FIELD>.

Is there something wrong in what I have written?

Edited by: Suzie on Oct 25, 2011 2:07 PM

kesavadas_thekkillath
Active Contributor
0 Kudos

ignore

Edited by: Keshav.T on Oct 25, 2011 2:08 PM

0 Kudos

I tried this option already. Bu the problem is: While Importing <fs> will have no values in it. And if I try to read <fs> in the debugger after this statement, it still says that <fs> has not been assigned yet.

I have passed another table( the field catalog for the dynamic table ) using IMPORT/EXPORT in the same program. But there is no problem there and I get this internal table in my calling program via IMPORT. But for <fs>, it does not work. May be I have to assign it to something??

0 Kudos

Based on what you are creating <fs_emp> in program 1 ?

If you can export the field catalouge to progrm 2 then create a dyn table in program 2 first , then assing it to <fs_emp> and then import it.

example


FIELD-SYMBOLS:<fs> TYPE ANY.
DATA:wf_ref TYPE REF TO data.
PARAMETERS:pa TYPE tabname.

START-OF-SELECTION.
  CREATE DATA wf_ref TYPE (pa).
  ASSIGN wf_ref->* TO <fs>.
  EXPORT pa TO MEMORY ID 'ABC'.
  EXPORT <fs> TO MEMORY ID 'TAB'.
  SUBMIT zxyz.

REPORT zxyz .
FIELD-SYMBOLS:<fs> TYPE ANY.
DATA:wf_ref TYPE REF TO data.
DATA:pa TYPE tabname.

START-OF-SELECTION.
  IMPORT pa FROM MEMORY ID 'ABC'.
  CREATE DATA wf_ref TYPE (pa).
  ASSIGN wf_ref->* TO <fs>.
  IF <fs> IS ASSIGNED.
    IMPORT <fs> FROM MEMORY ID 'TAB'.
  ENDIF.

Kesav

0 Kudos

Thats exactly what I tried to do in my program. It worked for normal internal table , but for dynamic internal table... No way, it dosnt return any error, but dosnt assign either. Infact I created the same dynamic table again in my program and assigned it to the new <fs>. But it still does not import the values.!!!!

0 Kudos

Try Exporting with DATABASE INDX(ST) ID INDXKEY where INDXKEY is ur memory id. It happened once with me that i was nt getting any error but data was not getting transferred only when i added DATABASE INDX(ST) ID INDXKEY the transfer was successfully taking place.

0 Kudos

Please execute this & check. As im using a very lower version of sap , i have used cl_alv_table_create=>create_dynamic_table

to create dyn table.


TYPE-POOLS:slis.

PARAMETERS:pa TYPE tabname.

FIELD-SYMBOLS :   <tbl_output> TYPE STANDARD TABLE,
                  <wa_output>  TYPE ANY.
DATA: new_line  TYPE REF TO data,  " dereference <fs>
      new_table TYPE REF TO data.

DATA: ref_descr TYPE REF TO cl_abap_structdescr,
      wa_comp TYPE abap_compdescr.

DATA: it_fieldcat TYPE lvc_t_fcat,
      is_fieldcat LIKE LINE OF it_fieldcat.

DATA: ct_fieldcat TYPE  slis_t_fieldcat_alv,
      wa_fc LIKE LINE OF ct_fieldcat.

CREATE DATA new_line TYPE (pa).
ASSIGN new_line->* TO <wa_output>.

ref_descr ?= cl_abap_typedescr=>describe_by_data( <wa_output> ).

LOOP AT ref_descr->components INTO wa_comp.
  MOVE:wa_comp-name  TO is_fieldcat-fieldname,
       wa_comp-name  TO is_fieldcat-ref_field,
       pa TO is_fieldcat-ref_table.
  APPEND is_fieldcat TO it_fieldcat.
ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog           = it_fieldcat
  IMPORTING
    ep_table                  = new_table.

IF sy-subrc = 0.
  ASSIGN   new_table->* TO <tbl_output>.
ENDIF.

SELECT * FROM (pa) UP TO 10 ROWS
INTO CORRESPONDING FIELDS OF TABLE <tbl_output>.
IF sy-subrc = 0.
  EXPORT pa TO MEMORY ID 'ABC'.
  EXPORT <tbl_output> TO MEMORY ID 'TAB'.
ENDIF.
submit zxyz.

0 Kudos

REPORT zxyz .
TYPE-POOLS:slis.

FIELD-SYMBOLS :   <tbl_output> TYPE STANDARD TABLE,
                  <wa_output>  TYPE ANY.
DATA:pa TYPE tabname.
DATA: new_line  TYPE REF TO data,  " dereference <fs>
      new_table TYPE REF TO data.

DATA: ref_descr TYPE REF TO cl_abap_structdescr,
      wa_comp TYPE abap_compdescr.

DATA: it_fieldcat TYPE lvc_t_fcat,
      is_fieldcat LIKE LINE OF it_fieldcat.

DATA: ct_fieldcat TYPE  slis_t_fieldcat_alv,
      wa_fc LIKE LINE OF ct_fieldcat.

IMPORT pa FROM MEMORY ID 'ABC'.
CREATE DATA new_line TYPE (pa).
ASSIGN new_line->* TO <wa_output>.

ref_descr ?= cl_abap_typedescr=>describe_by_data( <wa_output> ).

LOOP AT ref_descr->components INTO wa_comp.
  MOVE:wa_comp-name  TO is_fieldcat-fieldname,
       wa_comp-name  TO is_fieldcat-ref_field,
       pa TO is_fieldcat-ref_table.
  APPEND is_fieldcat TO it_fieldcat.
ENDLOOP.

CALL METHOD cl_alv_table_create=>create_dynamic_table
  EXPORTING
    it_fieldcatalog           = it_fieldcat
  IMPORTING
    ep_table                  = new_table.

IF sy-subrc = 0.
  ASSIGN   new_table->* TO <tbl_output>.
ENDIF.


IMPORT <tbl_output> FROM MEMORY ID 'TAB'.
BREAK-POINT.

Another method is you can also create two function modules and pass the reference variables. You can also search for shared memory objects ( I m not aware of this much ).

0 Kudos

Hi Keshav,

CREATE DATA wf_ref TYPE (pa).

But in my program I do not know the table structure directly. i am creating a dynamic table <FS_EMP> and then trying to pass it. So how can I replace pa??

0 Kudos

PA is the table name given as input in selection screen. Its not directly written.

0 Kudos

Ya but i will not get the table name.. I mean My dynamic table created internally. It is not based on any structure in the DB. I create it based on teh combination of inputs like country, state , customer etc... For eg.. if IN, 11 and 1000005, then my int table will have 5 fields. if values are 'IN' 11 and 10000101 then I will have to create a table with 7 fields.. etc... So in this case, how can I assign a tablename??

0 Kudos

tablename was just an example used. Pass your own criteria to program 2 and create the dyn tab.

I better suggest to create two function modules and pass the reference within both.

Or you can do as Amit suggested.I didnot suggested it because accessing from meory is much better than accessing from database.

@Amit-It happened once with me that i was nt getting any error but data was not getting transferred

Its because EXport/Import will not work in background.

Kesav

0 Kudos

Below is the code I have used:. Please check and suggest the changes...

Part - 1 The Submitted Code - here is where the Dynamic Table is created.


*    Create the Dynamic Table
    CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = it_dynfield[]
      IMPORTING
        ep_table        = cl_employees.

    ASSIGN cl_employees->* TO <fs_emp>.
    CREATE DATA cl_employees LIKE LINE OF <fs_emp>.
    ASSIGN cl_employees->* TO <fs_line>.
    LOOP AT it_targets ASSIGNING <fs_tar> .

      READ TABLE <fs_rslt> ASSIGNING <fs_field> WITH KEY (lw_field) = <fs_tar>-kunnr.
      MOVE-CORRESPONDING <fs_field> TO <fs_line>.
      MOVE-CORRESPONDING <fs_tar> TO <fs_line>.
      INSERT <fs_line> INTO TABLE  <fs_emp>.
    ENDLOOP.

*    CREATE DATA lw_id TYPE <fs_emp>.
*  ASSIGN lw_id->* TO <fs>.
*  EXPORT <fs_emp> TO MEMORY ID 'ABC'.
*  EXPORT <fs> TO MEMORY ID 'TAB'.
    GET REFERENCE OF <fs_emp> INTO lw_id.
    EXPORT <fs_emp>  TO MEMORY ID 'TAB' .

    CALL FUNCTION 'C14Z_EXPORT_TO_MEMORY'
      EXPORTING
        i_id = 'FLD'
      TABLES
        tab  = it_dynfield[].

Part - 2 The program calling the Above program


     DATA :cl_employees TYPE REF TO data.
      DATA: lit_fc TYPE lvc_t_fcat.
      FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE.
      FIELD-SYMBOLS: <new_field> TYPE ANY.

      DATA: field_symbol_name(30) VALUE '(ZSDR010)<FS_EMP>'.

      ASSIGN (field_symbol_name) TO <new_field>.
      SUBMIT zsdr010 WITH so_lnd00 IN so_lnd00
                WITH so_zon00 IN so_zon00
                WITH so_reg00 IN so_reg00
                WITH so_cit00 IN so_cit00
                WITH so_des00 IN  so_des00
                WITH so_emp00 IN so_emp00
                WITH so_cou00 IN so_cou00
                WITH so_kun00 IN so_kun00
                WITH so_mat00 IN so_mat00 AND RETURN .


      CALL FUNCTION 'C14Z_IMPORT_FROM_MEMORY'
        EXPORTING
          i_id = 'FLD'
        TABLES
          tab  = lit_fc.
      CALL METHOD cl_alv_table_create=>create_dynamic_table
        EXPORTING
          it_fieldcatalog = lit_fc[]
        IMPORTING
          ep_table        = cl_employees.

      ASSIGN cl_employees->* TO <fs_tab>.
      IMPORT <fs_tab> FROM DATABASE indx(st) ID 'TAB'.

And Keshav,

I want to Resort to FM only if I have no other option with this method, as I would have to change it in many areas.

0 Kudos

Hi

You need to know how the strcture of your table is generated In both programm:

- Calling program:

DATA: LR_VALUE_DESCR  TYPE REF TO CL_ABAP_ELEMDESCR,
      COMPONENT       TYPE CL_ABAP_STRUCTDESCR=>COMPONENT,
      LT_COMPONENTS   TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE.

DATA: LT_STRUC        TYPE REF TO CL_ABAP_STRUCTDESCR,
      LT_TAB          TYPE REF TO CL_ABAP_TABLEDESCR.

DATA: L_INDEX TYPE C.

DATA: W_LINE          TYPE REF TO DATA,
      INT_TABLE       TYPE REF TO DATA.

FIELD-SYMBOLS: <WA>    TYPE ANY,
               <ITAB>  TYPE TABLE,
               <VALUE> TYPE ANY.

DO 4 TIMES.
  CLEAR COMPONENT.
  MOVE SY-INDEX TO L_INDEX.
  CONCATENATE 'FIELD' L_INDEX INTO COMPONENT-NAME.
  MOVE CL_ABAP_ELEMDESCR=>GET_C( P_LENGTH = 4 ) TO LR_VALUE_DESCR.
  COMPONENT-TYPE = LR_VALUE_DESCR.
  INSERT COMPONENT INTO TABLE LT_COMPONENTS.
ENDDO.

* Workarea
LT_STRUC = CL_ABAP_STRUCTDESCR=>CREATE( P_COMPONENTS = LT_COMPONENTS
                                                   P_STRICT     = 'X' ).
CREATE DATA W_LINE TYPE HANDLE LT_STRUC.
ASSIGN W_LINE->* TO <WA>.

* Table
LT_TAB = CL_ABAP_TABLEDESCR=>CREATE( P_LINE_TYPE = LT_STRUC ).

CREATE DATA INT_TABLE TYPE HANDLE LT_TAB.
ASSIGN INT_TABLE->* TO <ITAB>.

DO 3 TIMES.
  CLEAR <WA>.
  DO 4 TIMES.
    MOVE SY-INDEX TO L_INDEX.
    CONCATENATE 'FIELD' L_INDEX INTO COMPONENT-NAME.
    ASSIGN COMPONENT COMPONENT-NAME OF STRUCTURE <WA> TO <VALUE>.
    MOVE SY-INDEX TO <VALUE>.
  ENDDO.
  APPEND <WA> TO <ITAB>.
ENDDO.


DATA: WA_INDX TYPE INDX.

WA_INDX-USERA = SY-UNAME.
WA_INDX-PGMID = 'MAXMAX'.

EXPORT TAB = <ITAB>
  TO DATABASE INDX(XY)
  FROM WA_INDX
  CLIENT SY-MANDT
  ID 'TABLE'.

Called program:

DATA: LR_VALUE_DESCR  TYPE REF TO CL_ABAP_ELEMDESCR,
      COMPONENT       TYPE CL_ABAP_STRUCTDESCR=>COMPONENT,
      LT_COMPONENTS   TYPE CL_ABAP_STRUCTDESCR=>COMPONENT_TABLE.

DATA: LT_STRUC        TYPE REF TO CL_ABAP_STRUCTDESCR,
      LT_TAB          TYPE REF TO CL_ABAP_TABLEDESCR.

DATA: L_INDEX TYPE C.

DATA: W_LINE          TYPE REF TO DATA,
      INT_TABLE       TYPE REF TO DATA.

FIELD-SYMBOLS: <WA>    TYPE ANY,
               <ITAB>  TYPE TABLE,
               <VALUE> TYPE ANY.

DO 4 TIMES.
  CLEAR COMPONENT.
  MOVE SY-INDEX TO L_INDEX.
  CONCATENATE 'FIELD' L_INDEX INTO COMPONENT-NAME.
  MOVE CL_ABAP_ELEMDESCR=>GET_C( P_LENGTH = 4 ) TO LR_VALUE_DESCR.
  COMPONENT-TYPE = LR_VALUE_DESCR.
  INSERT COMPONENT INTO TABLE LT_COMPONENTS.
ENDDO.

* Workarea
LT_STRUC = CL_ABAP_STRUCTDESCR=>CREATE( P_COMPONENTS = LT_COMPONENTS
                                                   P_STRICT     = 'X' ).
CREATE DATA W_LINE TYPE HANDLE LT_STRUC.
ASSIGN W_LINE->* TO <WA>.

* Table
LT_TAB = CL_ABAP_TABLEDESCR=>CREATE( P_LINE_TYPE = LT_STRUC ).

CREATE DATA INT_TABLE TYPE HANDLE LT_TAB.
ASSIGN INT_TABLE->* TO <ITAB>.


DATA: WA_INDX TYPE INDX.

WA_INDX-USERA = SY-UNAME.
WA_INDX-PGMID = 'MAXMAX'.

IMPORT TAB = <ITAB>
  FROM DATABASE INDX(XY)
  TO WA_INDX
  CLIENT SY-MANDT
  ID 'TABLE'.

LOOP AT <ITAB> ASSIGNING <WA>.
  WRITE: / <WA>.
ENDLOOP.

The sample above use IMPORT/EXPORT from database: if the called program can't know the structure of the dynaic table, you need to transfer it by the same way you transfer the data

Max

0 Kudos

EXPORT <fs_emp> TO MEMORY ID 'TAB' .

IMPORT <fs_tab> FROM DATABASE indx(st) ID 'TAB'.

In your code you are exporting to memory and importing from database which is incorrect.

In part one add.


export it_dynfield[] to memory id 'FCG'.
export <fs_emp> to memory id 'TAB'.

In part two after submit add.


import it_dynfield from memory id 'FCG'.

 CALL METHOD cl_alv_table_create=>create_dynamic_table
      EXPORTING
        it_fieldcatalog = it_dynfield[]
      IMPORTING
        ep_table        = cl_employees.

if cl_employees is bound.
ASSIGN cl_employees->* TO <fs_emp>.
if sy-subrc = 0.
import <fs_emp> from memory id 'TAB'.
endif.
endif.

0 Kudos

No actually I was trying Amits way. I Have Imported and Exported both from memory itself. Not database. Amits solution of replacing with database index too dint work by the way.

It_dynfld if imported using a FM 'C14Z_IMPORT_TO_MEMORY'

and it is exported bacj as Lit_fc again using a FM.. It works for this. the values assigned are imported successfully in Prog 2,

I added the Cl_employees is bound section....

It gives sy-subrc = 0. in all steps.. But the value in <fs_emp> is blank.

0 Kudos

Thank you all...

I got it solved using

DATA: WA_INDX TYPE INDX.
 
WA_INDX-USERA = SY-UNAME.
WA_INDX-PGMID = 'MAXMAX'.
 
EXPORT TAB = <ITAB>
  TO DATABASE INDX(XY)
  FROM WA_INDX
  CLIENT SY-MANDT
  ID 'TABLE'.

I am still confused on how to achieve this using memory ID and field symbols.. But I can at least continue with my work.

Thanks a lot..

Suzie