2024 Feb 14 4:47 PM
Hello everyone, I am new to abap programming. I have a local table where I store data from a join select. Which is defined like this
TYPES: BEGIN OF adrc,
addrnumber TYPE c LENGTH 10,
name1 TYPE c LENGTH 60,
name2 TYPE c LENGTH 60,
city1 TYPE c LENGTH 40,
city2 TYPE c LENGTH 40,
post_code1 TYPE c LENGTH 10,
street TYPE c LENGTH 60,
house_num1 TYPE c LENGTH 10,
house_num2 TYPE c LENGTH 10,
adrnr TYPE adrnr,
END OF adrc.
Data: lt_adrc TYPE TABLE OF adrc, ...
How can I define now a return parameter for a method of the same local table like lt_adrc. Anything I find online like the following does not work.
Methods: prepare_data IMPORTING lv_read_sucess TYPE abap_bool returning value(lt_data) type table of adrc,...
OR
TYPES tt_adrc TYPE STANDARD TABLE OF adrc WITH DEFAULT KEY.
...
prepare_data IMPORTING lv_read_sucess TYPE abap_bool returning value(lt_data) type tt_adrc,...
Is there a solution or is this just not done anymore.
Thank you so much!
Stefanie
2024 Feb 14 8:12 PM
Hello,
You need to use EXPORTING or CHANGING.
Heres a link that might help.
https://help.sap.com/doc/abapdocu_750_index_htm/7.50/en-US/abapmethods.htm
2024 Feb 15 8:15 AM
This is not true. Returning parameter is OK (and often recommended) to use.
2024 Feb 15 12:15 AM
2024 Feb 15 8:15 AM - edited 2024 Feb 15 8:16 AM
As @Edrilan_Berisha said, your second approach should work, and maybe you are confused by defining a "local table" instead of just using the result parameter, no need to use an intermediate internal table.
Maybe another source of confusion (maybe the compiler is confused too), is that you named your type the same as the DDIC type "ADRC". Choose a program type name like TS_ADRC.
Example:
TYPES tt_adrc TYPE STANDARD TABLE OF ts_adrc WITH DEFAULT KEY.
METHODS prepare_data
IMPORTING
iv_read_sucess TYPE abap_bool
returning
value(rt_adrc) type tt_adrc.
METHOD prepare_data.
SELECT ...
FROM adrc
INTO TABLE rt_adrc.
ENDMETHOD.
METHOD main.
DATA(lt_adrc) = prepare_data( iv_read_success = abap_true ).
ENDMETHOD.
2024 Feb 15 8:21 AM
Where did you define that structure type "TYPES: BEGIN OF adrc..." ?
It should be defined in class. I hope it is not defined in method.
Another issue might be conflict/confusion with global data dictionary table ADRC which has same name like your type. Try to choose different name for your structure type.
After that it should work like in your example:
"Class definitions:
TYPES: BEGIN OF address_struc,
...
END OF address_struc.
TYPES tt_address TYPE STANDARD TABLE OF address_struc WITH DEFAULT KEY.
"Method:
prepare_data RETURNING value(lt_data) type tt_address...
2024 Feb 15 9:19 AM
Thank you all for your help. You are probably right that the compiler got confused, it is now working. I am now parallel looking how things should be defined.