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

abap inline declaration doubts

Former Member
5,551

Hi,

I was just trying out a simple code using abap inline declaration. However, I am stuck at some particular lines of code . Below is the code snippet:

TYPES: BEGIN OF TY_FINAL,
 VBELN TYPE VBELN_VA, 
 VKORG TYPE VKORG, 
 KUNNR TYPE KUNNR, 
 POSNR TYPE POSNR_VA, 
 MATNR TYPE MATNR,
 END OF TY_FINAL.
DATA: L_REF TYPE REF TO DATA,
 VBELN1 TYPE VBELN_VA.
SELECT-OPTIONS: S1 FOR VBELN1.
 START-OF-SELECTION.
 CREATE DATA L_REF TYPE TY_FINAL. 
 SELECT VBELN, 
 VKORG, 
 KUNNR 
 FROM VBAK 
 INTO TABLE @data(IT_VBAK) 
 WHERE VBELN IN @S1.
 IF IT_VBAK IS NOT INITIAL. 
 SELECT VBELN,
 POSNR, 
 MATNR
 FROM VBAP 
 INTO TABLE @data(IT_VBAP) 
 FOR ALL ENTRIES IN @IT_VBAK 
 WHERE VBELN = @IT_VBAK-VBELN.
 ENDIF.
 ASSIGN IT_FINAL TO field-SYMBOL(<FS_FINAL>). 
 ASSIGN L_REF->* TO FIELD-SYMBOL(<FS_WA>) .
LOOP AT IT_VBAK ASSIGNING FIELD-SYMBOL(<FS_VBAK>). 
 <FS_WA>-VBELN = <FS_VBAK>-VBELN.
 <FS_WA>-Vkorg = <FS_VBAK>-Vkorg.
 <FS_WA>-kunnr = <FS_VBAK>-kunnr. 
 read table it_vbap assigning <fs_vbap> with key vbeln = <fs_vbak>-vbeln. 
 <FS_WA>-posnr = <FS_VBAp>-posnr. 
 <FS_WA>-matnr = <FS_VBap>-matnr.
 APPEND <FS_WA> TO <FS_FINAL>. 
 ENDLOOP.
 UNASSIGN <FS_WA> .

Here are my queries:

1) Is there a different way to declare the select options when working with inline declaration or do I have to use a variable using DATA statement like the conventional way (I had to declare a vbeln1 type vbeln_va) ?

2) How do I assign the internal table to a field symbol?

ASSIGN IT_FINAL TO field-SYMBOL(<FS_FINAL>).

3) How to create the reference variable (L_REF in this case) using inline declaration ?

Regards,

Matt

1 ACCEPTED SOLUTION
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
3,049

Read the documentation?

https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abeninline_declara...

"Is there a different way to declare the select options when working with inline declaration or do I have to use a variable using DATA statement like the conventional way"

No, the only thing you can do (but that doesn't change the SELECT-OPTIONS statement):

DATA(var) = VALUE scarr-carrid( ).
SELECT-OPTIONS selopt FOR var.

"How do I assign the internal table to a field symbol?"

Exactly as shown, but of course, the internal table must exist, the position behind ASSIGN is not a declaration position:

DATA itab TYPE TABLE OF string.
ASSIGN itab TO FIELD-SYMBOL(<fs>).

"How to create the reference variable (L_REF in this case) using inline declaration":

Trivial ...

DATA var TYPE i.
GET REFERENCE OF var INTO DATA(dref1).
DATA(dref2) = REF #( var ).
6 REPLIES 6
Read only

retired_member
Product and Topic Expert
Product and Topic Expert
3,050

Read the documentation?

https://help.sap.com/http.svc/rc/abapdocu_752_index_htm/7.52/en-US/index.htm?file=abeninline_declara...

"Is there a different way to declare the select options when working with inline declaration or do I have to use a variable using DATA statement like the conventional way"

No, the only thing you can do (but that doesn't change the SELECT-OPTIONS statement):

DATA(var) = VALUE scarr-carrid( ).
SELECT-OPTIONS selopt FOR var.

"How do I assign the internal table to a field symbol?"

Exactly as shown, but of course, the internal table must exist, the position behind ASSIGN is not a declaration position:

DATA itab TYPE TABLE OF string.
ASSIGN itab TO FIELD-SYMBOL(<fs>).

"How to create the reference variable (L_REF in this case) using inline declaration":

Trivial ...

DATA var TYPE i.
GET REFERENCE OF var INTO DATA(dref1).
DATA(dref2) = REF #( var ).
Read only

0 Likes
3,049

So even though I am using inline declaration in my program, in some cases I HAVE to use the DATA statement (like in the case of the internal table and the reference variable) ? I thought that the purpose of inline declaration was to eliminate the use the DATA statement completely for declaration purposes.

Read only

matt
Active Contributor
3,049

I thought that the purpose of inline declaration was to eliminate the use the DATA statement completely for declaration purposes.

Not really.I find inline declaration to improve readability, especially with helper variables.

Read only

0 Likes
3,049

"I thought that the purpose of inline declaration was to eliminate the use the DATA statement completely for declaration purposes."

Who said so? No you use it where appropriate. Of course, you can in fact get rid of DATA, but why?

TYPES itab TYPE STANDARD TABLE OF string WITH EMPTY KEY.
DATA(itab) = VALUE itab( ).

ASSIGN itab TO FIELD-SYMBOL(<fs>).

Read only

retired_member
Product and Topic Expert
Product and Topic Expert
3,049

Your explanation is wrong regarding TABLES. With TABLES you declare a structure and not a table.

Simply, don't use TABLES ...

Read only

matt
Active Contributor
0 Likes
3,049

Thanks for using a code block - do you think next time you might nicely format the code as well, with indents, to make it easier to read?