‎2019 Sep 10 1:56 PM
CLASS lcl_ewb DEFINITION.
PUBLIC SECTION.
METHODS:
get_data,
get_sd_invoice.
"get_sd_invoice EXPORTING t_vbrk TYPE ANY TABLE - Not Working
ENDCLASS.
CLASS lcl_ewb IMPLEMENTATION
METHOD get_data.
check_active_jobs( ).
IF gr_fkart IS NOT INITIAL OR gr_vbeln IS NOT INITIAL.
get_sd_invoice( ).
"get_sd_invoice( IMPORTING t_vbrk = data( gt_vbrk ) )- Not Working
CHECK gt_vbrk IS NOT INITIAL
ENDIF.
ENDMETHOD.
METHOD get_sd_invoice.
SELECT vbeln,
fkart,
knumv,
fkdat,
belnr,
gjahr
FROM vbrk
INTO TABLE @DATA(lt_vbrk)
WHERE vbeln IN @gr_vbeln
AND fkart IN @gr_fkart
AND fkdat IN @s_bldat
AND bukrs IN @s_bukrs
AND kunag IN @s_kunnr.
IF sy-subrc = 0.
SORT lt_vbrk BY vbeln.
t_vbrk = lt_vbrk.
ENDIF.
ENDMETHOD.
ENDCLASS.
Hey Guys,
I'm facing a challenge in using the Inline declaration which I'm trying for the first time. I have attached the code snippet.
In a Local method I'm writing a fetch from VBRK into ITAB using the inline declaration. This ITAB will be local but I need this internal table to be used in other methods globally. If I use the IMPORTING parameter in method definition how should I declare the internal table? I tried ANY TABLE but it is not working. I dont want to create a table type in SE11 and use it here(which defeats the purpose of using Inline).
Kindly help me in find out in what I have done wrong and If you have any suggestions in writing this logic in a better way please mention that.
Regards,
NishanthVK
‎2019 Sep 10 2:54 PM
CLASS lcl_ewb DEFINITION.
PUBLIC SECTION.
METHODS:
get_sd_invoice EXPORTING eo_data TYPE REF TO data,
test.
ENDCLASS.
CLASS lcl_ewb IMPLEMENTATION.
METHOD get_sd_invoice.
DATA: lo_data TYPE REF TO data.
FIELD-SYMBOLS: <fs_table> TYPE ANY TABLE.
SELECT vbeln,
fkart,
knumv,
fkdat,
belnr,
gjahr
FROM vbrk
INTO TABLE @DATA(lt_vbrk)
UP TO 10 ROWS.
IF sy-subrc = 0.
SORT lt_vbrk BY vbeln.
CREATE DATA lo_data LIKE lt_vbrk.
IF lo_data IS BOUND.
ASSIGN lo_data->* TO <fs_table>.
IF <fs_table> IS ASSIGNED.
<fs_table> = lt_vbrk[].
ENDIF.
eo_data = lo_data.
ENDIF.
ENDIF.
ENDMETHOD.
METHOD test.
DATA: lo_data TYPE REF TO data.
FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE.
get_sd_invoice(
IMPORTING
eo_data = lo_data
).
IF lo_data IS BOUND.
ASSIGN lo_data->* TO <fs_tab>.
IF <fs_tab> IS ASSIGNED.
"--- Perform action
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
DATA: go_obj TYPE REF TO lcl_ewb.
START-OF-SELECTION.
CREATE OBJECT go_obj.
go_obj->test( ).
PS: made changes to code after your comment
‎2019 Sep 10 2:17 PM
I prefer to declare the type in the dictionary.
If you are using a local class, you could define the type in the public section.
(yes, your inline declaration is not usefull here)
In your code, define a returning variable / Structure / table.
A method need importing(most of the time) & 1 returning. If not, you could not have a clear responsability for this method. And this is bad bad bad, because it is not clean code
‎2019 Sep 12 4:51 AM
Hey Frederic,
Sorry I didn't give the feedback earlier.
I will use types structures for most used internal tables.
Thank you
Regards,
Nishanth VK
‎2019 Sep 10 2:54 PM
CLASS lcl_ewb DEFINITION.
PUBLIC SECTION.
METHODS:
get_sd_invoice EXPORTING eo_data TYPE REF TO data,
test.
ENDCLASS.
CLASS lcl_ewb IMPLEMENTATION.
METHOD get_sd_invoice.
DATA: lo_data TYPE REF TO data.
FIELD-SYMBOLS: <fs_table> TYPE ANY TABLE.
SELECT vbeln,
fkart,
knumv,
fkdat,
belnr,
gjahr
FROM vbrk
INTO TABLE @DATA(lt_vbrk)
UP TO 10 ROWS.
IF sy-subrc = 0.
SORT lt_vbrk BY vbeln.
CREATE DATA lo_data LIKE lt_vbrk.
IF lo_data IS BOUND.
ASSIGN lo_data->* TO <fs_table>.
IF <fs_table> IS ASSIGNED.
<fs_table> = lt_vbrk[].
ENDIF.
eo_data = lo_data.
ENDIF.
ENDIF.
ENDMETHOD.
METHOD test.
DATA: lo_data TYPE REF TO data.
FIELD-SYMBOLS: <fs_tab> TYPE ANY TABLE.
get_sd_invoice(
IMPORTING
eo_data = lo_data
).
IF lo_data IS BOUND.
ASSIGN lo_data->* TO <fs_tab>.
IF <fs_tab> IS ASSIGNED.
"--- Perform action
ENDIF.
ENDIF.
ENDMETHOD.
ENDCLASS.
DATA: go_obj TYPE REF TO lcl_ewb.
START-OF-SELECTION.
CREATE OBJECT go_obj.
go_obj->test( ).
PS: made changes to code after your comment
‎2019 Sep 11 6:41 AM
Hi Rameez,
Thank you for your answer. I followed your steps. In this case while executing the get_sd_invoice method it goes for dump because the field-symbol is not assigned. I'm trying with other options and will update on the progress.
Regards,
NishanthVK
‎2019 Sep 11 7:54 AM
Hello Nishant,
Try now. I have made changes to answer. it should work now.
Just to add this is adding complexity to code, why can't we create types in program.
Regards
Rameez
‎2019 Sep 11 10:14 AM
Dear Rameez,
Thank you for the quick reply and the solution. Creating the data reference and using field symbols is working fine. Ofcourse this will become complex when the select queries are more. I was just curious in how to do this with Inline declaration which can act as global internal table. From now on I will use global types or local types for the mostly required ITab and Inline for locally required ITab.
Regards,
NishanthVK
‎2019 Sep 10 4:01 PM
With Eclipse, there's the quickfix to convert the host variable locally, and it declares the type with all the fields.
If you don't have it, you're stuck (or, either you do it manually, or you do an ugly workaround).
NB: in the old backend editor, you also have the "pattern" button to select the "structured data object with fields", i.e. select the fields from one table, and it generates ABAP code "BEGIN OF ... END OF..." (but much less practical than Eclipse!)
‎2019 Sep 12 4:46 AM
Hey Sandra
Apologize for not giving the feedback. I didn't know what I was thinking at that time.I too use the 'structured data object with fields' option for creating long structures since it will create in the order. Now I have found a solution which is given in Rammez's answer.
Thankyou
Regards,
Nishanth VK
‎2019 Sep 11 12:07 PM
You didn't even provide a feedback to 2 of 3 people who answered, so I guess other people won't even try if they know you will ignore most of them 😉