Application Development and Automation 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: 
Read only

Define work area with referencing to dynamic structure name

Former Member
0 Likes
1,758

Hi,

I need help on defining a work area with referencing to a dynamic structure name. Could you please help?

Thanks,

Chuong

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
1,569

simplest way to create a work area for your dynamic table


data: l_wa_ref type ref to data.

"Create a data
 create data l_wa_ref like line of <f_data>.

7 REPLIES 7
Read only

naimesh_patel
Active Contributor
0 Likes
1,569

You need to use the field-symbols to get an access of the dynamica structure. Insdie the loop, you need to access each field individually using the Field symbols.

Like:


  FIELD-SYMBOLS: <LT_TEXT>     TYPE ANY TABLE,
                 <LA_TAB>      TYPE ANY,
                 <LF_ITEXT>    TYPE ANY.

  LOOP AT <LT_TEXT> ASSIGNING <LA_TAB>.
    ASSIGN COMPONENT: 'FIELD1'    OF STRUCTURE <LA_TAB>  TO <LF_ITEXT>.

  ENDLOOP.

Regards,

Naimesh Patel

Read only

Former Member
0 Likes
1,569

This is how you can do this.

<line> will be your work area.

DATA: l_struct    TYPE REF TO data.

FIELD-SYMBOLS: <table>  TYPE STANDARD TABLE, " Dynamic Table
                            <line>   TYPE ANY.

CREATE DATA l_struct LIKE LINE OF <table>.
ASSIGN l_struct->* TO <line>.

A

Read only

messier31
Active Contributor
0 Likes
1,569

One simple approach can be using class cl_alv_table_create.

data: i_table type ref to data.

field-symbols : <list> type table .

call method cl_alv_table_create=>create_dynamic_table

exporting

it_fieldcatalog = lt_alv_cat

importing

ep_table = i_table .

assign i_table->* to <list> .

Enjoy SAP.

Pankaj Singh

Read only

Former Member
0 Likes
1,570

simplest way to create a work area for your dynamic table


data: l_wa_ref type ref to data.

"Create a data
 create data l_wa_ref like line of <f_data>.

Read only

0 Likes
1,569

I have a string of 2000 chars that will be populated with different formats and I need to dynamicly define a work area (wa) so I can map the data from the string to my work area. I am having a difficulty in defining such work area.

For example,

String can have data of VBAK or VBAP and I need a work area defined accordingly for my mapping like

wa = string.

Please help,

Thanks!

Read only

0 Likes
1,569

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.

Regards

Edited by: Alejandro Bindi on Sep 23, 2008 6:23 PM

Read only

0 Likes
1,569

Hi Alejandro Bindi,

My problem was resolved. Thank you for helping me!

Chuong