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: 

Get access to specific fields of a field symbol

Former Member
0 Kudos

Hello,

i have following problem.

I've a dataset in string format f.e. lv_data(250) type c

I know the fieldcatalog of the dataset.

i've created a field symbol with the known structure ( see dynamic internal table)

I want to get access to the specific fields of the dataset.

best regards,

tomsd

11 REPLIES 11

RichHeilman
Developer Advocate
Developer Advocate
0 Kudos

Use the following statement. Now you can access the field thru <FS>.

ASSIGN Component 'THE_FIELD' of structure <fs_wa> to <fs>.

Regards,

Rich Heilman

0 Kudos

Hi Rich,

i've following coding:

      • Tabellen

DATA: LT_DATALAYOUT TYPE TABLE OF ZBAPI6118DALO.

DATA: LT_RESULTDATA TYPE TABLE OF ZBAPI6116DA.

DATA: LT_FIELDCATALOG_BW TYPE LVC_T_FCAT.

      • Structure

DATA: LS_FIELDCATALOG_BW TYPE LVC_S_FCAT.

DATA: LS_DATALAYOUT TYPE ZBAPI6118DALO.

DATA: LS_RESULTDATA TYPE ZBAPI6116DA.

DATA: LS_ZBW_STATISTIKOH TYPE ZBW_STATISTIKOH.

DATA: RETURN_READ TYPE BAPIRET2.

      • Data References

DATA: RESULTDATA_LINE TYPE REF TO DATA.

DATA: RESULTDATA TYPE REF TO DATA.

      • Field Symbols

FIELD-SYMBOLS: <FS_RESULTDATA_TABLE> TYPE ANY TABLE,

<FS_RESULTDATA_LINE> TYPE ANY,

<FS_DATA>.

  • LT_DATALAYAOUT contains the structure of the data

CALL FUNCTION 'RSB_API_OHS_DEST_READ_DATA'

DESTINATION 'BW1CLNT010'

EXPORTING

OHDEST = OHDEST

REQUESTID = REQUESTID

TABLES

DATALAYOUT = LT_DATALAYOUT

RESULTDATA = LT_RESULTDATA.

  • Create Fieldcatalog

LOOP AT LT_DATALAYOUT INTO LS_DATALAYOUT.

LS_FIELDCATALOG_BW-ROW_POS = '0'.

LS_FIELDCATALOG_BW-COL_POS = SY-TABIX.

LS_FIELDCATALOG_BW-TABNAME = '1'.

LS_FIELDCATALOG_BW-INTTYPE = LS_DATALAYOUT-TYPE.

LS_FIELDCATALOG_BW-INTLEN = LS_DATALAYOUT-LENGTH.

LS_FIELDCATALOG_BW-FIELDNAME = LS_DATALAYOUT-FIELDNM.

LS_FIELDCATALOG_BW-DATATYPE = LS_DATALAYOUT-DATATYPE.

LS_FIELDCATALOG_BW-DECIMALS = LS_DATALAYOUT-DECIMALS.

APPEND LS_FIELDCATALOG_BW TO LT_FIELDCATALOG_BW.

ENDLOOP.

  • Create dynamoc table

CALL METHOD CL_ALV_TABLE_CREATE=>CREATE_DYNAMIC_TABLE

EXPORTING

IT_FIELDCATALOG = LT_FIELDCATALOG_BW

IMPORTING

EP_TABLE = RESULTDATA

EXCEPTIONS

GENERATE_SUBPOOL_DIR_FULL = 1

OTHERS = 2.

      • So RESULTDATA now points to our dynamic internal table.

ASSIGN RESULTDATA->* TO <FS_RESULTDATA_TABLE>.

      • Next step is to create a work area for our dynamic internal table.

CREATE DATA RESULTDATA_LINE LIKE LINE OF <FS_RESULTDATA_TABLE>.

      • A field-symbol to access that work area

ASSIGN RESULTDATA_LINE->* TO <FS_RESULTDATA_LINE>.

  • Read the specific datasets

LOOP AT LT_RESULTDATA INTO LS_RESULTDATA.

ASSIGN LS_RESULTDATA-DATA TO <FS_RESULTDATA_LINE>.

ASSIGN COMPONENT 'BASE_UOM'

OF STRUCTURE <FS_RESULTDATA_LINE> TO <FS_DATA>.

And here i get sy-subrc 4.

Whats the problem?`

Best regards,

Strehle Thomas

0 Kudos

Thomas,

Please check one more time if there is field by name 'BASE_UOM' in <FS_RESULTDATA_LINE> at runtime. You can put a break point at the ASSIGN statement and look at the strucutre.

You are getting SY-SUBRC = 4 as the assign statement is not successful and this happening as the field name does not exist in the structure of the field symbol.

regards,

Ravi

0 Kudos

Hi Ravikumar Allampallam,

      • A field-symbol to access that work area

ASSIGN RESULTDATA_LINE->* TO <FS_RESULTDATA_LINE>.

After this statement the work_area <FS_RESULTDATA_LINE>

has field 'BASE_UOM'.

LOOP AT LT_RESULTDATA INTO LS_RESULTDATA.

ASSIGN LS_RESULTDATA-DATA TO <FS_RESULTDATA_LINE>.

After the assign the <FS_RESULTDATA_LINE> there is no more sturcture an therefor no field 'BASE_UOM'.

There are only the data in the the field symbol <FS_RESULTDATA_LINE>.

Best regards,

TomSd

0 Kudos

Thomas,

As I understand that this is a work area of the table and so the columns should be there. Just double click on the field symbols you see a row of data there right. You should see the column names there.

Now, if you don't see BASE_UOM as a column, then you cannot use that assign statement like that. The assign statement takes the value of the column you specify and assigns it to the feild symbols.

Regards,

Ravi

0 Kudos

Hi Ravikumar Allampallam,

      • A field-symbol to access that work area

ASSIGN RESULTDATA_LINE->* TO <FS_RESULTDATA_LINE>.

After this statement the work_area <FS_RESULTDATA_LINE>

has the structure of the fieldcatalog.

but when i do that assign:

ASSIGN LS_RESULTDATA-DATA TO <FS_RESULTDATA_LINE>.

the structure of the work_area <FS_RESULTDATA_LINE> is lost. i think i need to do a casting assign but its not possible because the work_area <FS_RESULTDATA_LINE> is defined as type any.

Best regards,

TomSd

0 Kudos

Thomas,

Can you try this?

LOOP AT LT_RESULTDATA ASSIGNING <FS_RESULTDATA_LINE>.

ASSIGN COMPONENT 'BASE_UOM'

OF STRUCTURE <FS_RESULTDATA_LINE> TO <FS_DATA>.

I guess double assignment is creating a problem.

Regards,

Ravi

Note : Please mark the helpful answers.

0 Kudos

Hi,

LT_RESULTDATA and <FS_RESULTDATA_LINE> hasn't the same type. There is no double assignment because i write at the loop over LT_RESULTDATA into an wa ls_resultdata.

The field ls_resultdata-data has to be assigned into

<FS_RESULTDATA_LINE>.

Best Regards,

TomSd

0 Kudos

Thomas,

ASSIGN LS_RESULTDATA-DATA TO <FS_RESULTDATA_LINE>

Looking at it closely, you are already assigning a specific column of LS_RESULTDATA to the field synbol. So, the field symbols will point only a column of the work area. Why would DATA column again other columns like BASE_UOM?

Regards,

Ravi

dusan_davidovic
Explorer
0 Kudos

Hi Thomas,

when you execute this statement:

"ASSIGN RESULTDATA_LINE->* TO <FS_RESULTDATA_LINE>"

field symbols is assigned and has same structure as RESULTDATA_LINE.

After that, with this

"ASSIGN LS_RESULTDATA-DATA TO <FS_RESULTDATA_LINE>".

you are changing structure of field-symbols to be the same as LS_RESULTDATA-DATA not RESULTDATA_LINE as you require, therefore there is no component called "BASE_UOM".

I would suggest simple assignment in this case, there is no need for another ASSIGN

<FS_RESULTDATA_LINE> = LS_RESULTDATA-DATA.

and then you can use

ASSIGN COMPONENT 'BASE_UOM' of STRUCTURE <FS_RESULTDATA_LINE> to <xxxx>.

Hope this helps.

DD

0 Kudos

Hi Dusan Davidovic,

the problem is that we have a unicode system,

and so the statement

<FS_RESULTDATA_LINE> = LS_RESULTDATA-DATA.

runs into an short dump UC_OBJECTS_NOT_CONVERTIBLE).

Best regards,

Strehle Thomas