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: 

Assign Internal table to field symbol

Former Member

Hi experts

The assignment for the internal table to the fields symbol gets failed. Please find my below code where I tried all posiblities of field symbol declaration even though the values are in the internal table XVBPA the ASSIGN ('(sapmv45a)xvbpa[]') TO <y1> statments fails and gives sy-subrc 4.

Please let me know any code need to change or provide the code for this

I declared the field symbol like below.

FIELD-SYMBOLS: <y1> TYPE any TABLE .

ASSIGN ('(sapmv45a)xvbpa[]') TO <y1>.

Thanks in advance.

Sai

5 REPLIES 5

Former Member
0 Kudos

Hello

Try like this:


data: FIELD_SYMBOL(40) TYPE C VALUE '(SAPMV45A)xvbpa[]'.
FIELD-SYMBOLS: <y1> TYPE any .

ASSIGN (FIELD_SYMBOL) to <y1>.

0 Kudos

Guys,

Though I agree that uppercase used for program name should solve the issue, I think there is one very important thing to be noticed - context of this statement usage.

BTW - I think we all should get the habit of addressing all dynamically determined field names in uppercase in any context. This also relates to data objects used within the program. This assures that we are never confused which form of addressing the components to use and also we are not doing a very basic and common error.

But as for the note I mentioned above.

The coding above would never work unless it is called either from main program (which is obvious and we don't need program name here) or from some other program's procedure (subroutine in most common case). If I write something like


"in program SAPMV45A
submit z_my_program and return.

"in z_my_program
in data: FIELD_SYMBOL(40) TYPE C VALUE '(SAPMV45A)xvbpa[]'.
FIELD-SYMBOLS: <y1> TYPE any .
 
ASSIGN (FIELD_SYMBOL) to <y1>.

the code would fail and I would not get the field symbol assigned. This is because whenever we submit a report there is separate new internal session opened (which either replaces the current one -> submit statement; or places this new on call stack -> submit and return ) and the only way to address previous internal session data would be by means of SAP/ABAP memory.

On the other hand when we use


"in program SAPMV45A
perform my_subroutine(z_my_program).

"in z_my_program
form my_subroutine.
  in data: FIELD_SYMBOL(40) TYPE C VALUE '(SAPMV45A)xvbpa[]'.
  FIELD-SYMBOLS: <y1> TYPE any .
 
   ASSIGN (FIELD_SYMBOL) to <y1>.
endform.

the field symbol would hold expected data. This is because (in contrary to submiting a program), the perform statement places called subroutine in the same internal session of the calling program. All is keep in so called main program group. The calling program is used to be called main program and subroutine is just external subroutine .

To confirm this all if you compare both programs in debugger -> call stack you shall see that in first case the calling program is "hidden" (as is no part of the current sesision) while the second one executes in same internal session (placing the external subroutine call on the call stack which makes the calling program data available for addressing them this way).

That's why we need to keep in mind the context of the code in subject to make this ever work out.

Regards

Marcin

0 Kudos

Thanks Marcin for this excellent piece of info.

Have a happy weekend !!!

Suhas

0 Kudos

Thank you Suhas you too.

Cheers

Marcin

Former Member
0 Kudos

I agree to what Dzed has given.

Regards,

Uma