cancel
Showing results for 
Search instead for 
Did you mean: 

Error Extracting data from a STRUCTURE in SELECT statement

Former Member
0 Kudos

Hi,

I have an SAP defined structure BIW_KNA1_S which has been enhanced with 2 fields (ZZS1 and ZZS2). I need to populate these 2 fields with data from the 2 SORT fields from ADRC table.

I tried the following code but i do not get any output. This piece of code is in a FORM statement from which i should return contents of table ITAB in the foll. code.

DATA ZS TYPE TABLE OF ADRC WITH HEADER LINE.

DATA ITAB LIKE TABLE OF BIW_KNA1_S WITH HEADER LINE.

FIELD-SYMBOLS: <FS> LIKE ITAB.

SELECT SORT1 SORT2 FROM ADRC INTO CORRESPONDING FIELDS OF TABLE

ZS WHERE ADDRNUMBER IS NOT NULL.

LOOP AT ITAB ASSIGNING <FS>.

IF ZS-ADDRNUMBER IS NOT INITIAL.

<FS>-ZZS1 = ZS-SORT1.

<FS>-ZZS2 = ZS-SORT2.

ENDIF.

ENDLOOP.

Since i did not get any output, I then added the foll. line of code before the LOOP statement.

SELECT * FROM BIW_KNA1_S INTO CORRESPONDING FIELDS OF TABLE ITAB

WHERE KUNNR IS NOT NULL.

When i execute this, i get the foll. error.

"BIW_KNA1_S is not defined in the ABAP dictionary as table, projection view or database view."

How to extract data from a structure BIW_KNA1_S using a SELECT statement.

Could someone help.

Thanks

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

maybe you want to do the following...

DATA: BEGIN OF tb_cust OCCURS 0.

INCLUDE STRUCTURE BIW_KNA1_S.

DATA: END OF tb_cust.

TABLES ADRC.

(...)

WHEN '0CUSTOMER_ATTR'.

tb_cust[] = i_t_data[].

loop at tb_cust.

if tb_cust-adrnr ne ' '.

select single * from ADRC

where ADDRNUMBER = tb_cust-adrnr and

DATE_FROM = (I don't how do you want to manage this!) and

NATION = (?)

tb_cust-zzs1 = adrc-sort1.

tb_cust-zzs2 = adrc-sort2.

endif.

modify tb_cust.

clear tb_cust.

endloop.

DELETE TABLE i_t_data.

i_t_data[] = tb_cust[].

CLEAR tb_cust. REFRESH tb_cust. FREE tb_cust.

Former Member
0 Kudos

Hi Sachin,

1. You didn't get any output because you read data into ZS table and made loop on ITAB (which was empty).

2. To eliminate an error you can add a declaration

TABLE: BIW_KNA1_S.

3. Your logic of reading data from one table and getting additional data from another one using different keys looks to me not proper. Are sure the logic is right?

Best regards,

Eugene

Former Member
0 Kudos

Roberto is right. It's not a table. It's a structure.

Former Member
0 Kudos

Hi Roberto and Eugene,

My requirement is:

As i said, i have an extract structure BIW_KNA1_S (extract structure for 0CUSTOMER_ATTR datasource). I enhanced this structure with 2 fields (ZZS1 and ZZS2). I want to populate these fields. My assumption is that 0CUSTOMER_ATTR gets its data also from ADRC and not just from KNA1.

I wanted to poopulate ZZS1 and ZZS2 from SORT1 and SORT2 fields from ADRC table. Since, ADRC and BIW_KNA1_S are different (one is a table and another is structure), i cannot copy the contents directly. Hence i thought of storing SORT1 and SORT2 fields from ADRC into an Internal table. Also, i created an ITAB (lookalike of BIW_KNA1_S structure). And i thought of populating ZZS1 and ZZS2 in this way.

Could you tell me how to make this work. As i mentioned, this piece of code is in a FORM and i have to return contents of ITAB to a PERFORM call.

Thanks a lot.

Former Member
0 Kudos

Sachin,

the concept about select is more or less correct in my previous post (maybe some ABAP purist would suggest to use a work area for ADRC table instead of declare it in tables statement...) even if I'm not referring to your FORM need...anyway it's easy to adjust it for your purpose...but the question is: how do you want to manage several (from a technical point of view) entries coming from ADRC table for your unique record coming from KNA1?

In other words you have to manage the situation in which a customer have several addresses (this table is time-dependent as you can see from the key!).

Do you need the last entry ?

Apart from these functional doubts, you can work in this way if you want to fill your custom fields!!!

Hope it helps!

Bye,

Roberto

Former Member
0 Kudos

Hi Roberto,

Ok. Let me explain my requirement more clearly. I don't want to write the code in include ZXRSAU02. In ZXRSAU02, i will have only PERFORM statement which will call the FORM statement depending on the name of the program.

Ex: PERFORM form_name ...tables i_t_data.

In this way, i don't need to make any changes in this file. I will only need to make the changes in the report where my Actual FORM code resides. In the ABAP report, i will have my FORM code which will return contents.

And this is the code which my FORM report will consist:

DATA ZS TYPE TABLE OF ADRC WITH HEADER LINE.

DATA ITAB LIKE BIW_KNA1_S OCCURS 10 WITH HEADER LINE.

FIELD-SYMBOLS: <FS> LIKE ITAB.

SELECT SORT1 SORT2 FROM ADRC INTO CORRESPONDING FIELDS OF TABLE ZS WHERE ADDRNUMBER IS NOT NULL.

LOOP AT ITAB ASSIGNING <FS>.

IF ZS-ADDRNUMBER IS NOT INITIAL.

<FS>-ZZS1 = ZS-SORT1.

<FS>-ZZS2 = ZS-SORT2.

ENDIF.

ENDLOOP.

But as you said, i will have some problems i suppose. Like if my ADRC has some 70 records and if there are 100 records in BIW_KNA1_S, then when i try to copy the fields from ADRC into ITAB (BIW_KNA1_S) i might have problems. I will get back to you once i clarify these things.

Thanks for your reply.

Former Member
0 Kudos

Hi dear,

BIW_KNA1_S is a structure (one row) and you have no possibility to do a select against it !!!

What's the logic you want to implement ?

You want to add these two fields, but where is the link between customer number and ADRC table ?

Remember also that ADDRNUMBER is key in ADRC table so it's always filled !

Hope it helps!

Bye,

Roberto