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: 

ASSIGN do not setting SY-SUBRC

antony_paul2
Active Participant
2,064

I have a simple ASSIGN statement as shown below..issue I am facing is SY-SUBRC is not set..it retains its previous value eventhough field symbol is successfully assigned. Any thoughts? Is it because am assigning a deep/nested structure?

FIELD-SYMBOLS: <lf_deep_str> TYPE t_deep_structure.

ASSIGN deep_strucutre TO <lf_deep_str>.

IF sy-subrc = 0.

..........

ENDIF
1 ACCEPTED SOLUTION

DominikTylczyn
SAP Champion
SAP Champion
1,119

Hello antony.paul2

Look at ASSIGN keyword documentation on SAP Help. It explains:

The return value is set only for the dynamic variants and the table expression variant of mem_area. Your case is a static variant of mem_area.

Therefore sy-subrc is not set.

Honestly I find this logic convoluted and I wouldn't rely on that. I'd rather put UNASSIGN before ASSIGN and then check if assignment is successful with IS ASSIGNED expression:

FIELD-SYMBOLS: <lf_deep_str> TYPE t_deep_structure.

UNASSIGN <lf_deep_str>.
ASSIGN deep_strucutre TO <lf_deep_str>.

IF <lf_deep_str> IS ASSIGNED.
..........
ENDIF.<br>

That seems safer and more readable to me.

Best regards

Dominik Tylczynski

2 REPLIES 2

DominikTylczyn
SAP Champion
SAP Champion
1,120

Hello antony.paul2

Look at ASSIGN keyword documentation on SAP Help. It explains:

The return value is set only for the dynamic variants and the table expression variant of mem_area. Your case is a static variant of mem_area.

Therefore sy-subrc is not set.

Honestly I find this logic convoluted and I wouldn't rely on that. I'd rather put UNASSIGN before ASSIGN and then check if assignment is successful with IS ASSIGNED expression:

FIELD-SYMBOLS: <lf_deep_str> TYPE t_deep_structure.

UNASSIGN <lf_deep_str>.
ASSIGN deep_strucutre TO <lf_deep_str>.

IF <lf_deep_str> IS ASSIGNED.
..........
ENDIF.<br>

That seems safer and more readable to me.

Best regards

Dominik Tylczynski

antony_paul2
Active Participant
1,119

Thank you Dominik