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: 

INVALID_SRC_TYPE with Corresponding #

sh4il3sh
Participant
0 Kudos

why do I get above runtime error with below code?

DATA: gv_kunnr TYPE kunnr.
SELECT-OPTIONS: s_kunnr FOR gv_kunnr.                          "Passed 5 Customer Nos here

TYPES: BEGIN OF kunnr_type,
         kunnr TYPE kunnr,
       END OF kunnr_type.
DATA: kunnr_input TYPE STANDARD TABLE OF kunnr_type.

START-OF-SELECTION
kunnr_input = VALUE #( FOR l_kunnr IN s_kunnr ( kunnr = l_kunnr-low ) ). "Works well kunnr_input = CORRESPONDING #( s_kunnr MAPPING kunnr = low ). ">>>>>>>>>>RUNTIME ERROR
I believe something due to type mismatch but I need clarity.

Thanks.
1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

Any variable name corresponding to a SELECT-OPTIONS (S_KUNNR in your case) may express both a Ranges Table (internal table with components SIGN, OPTION, LOW, HIGH) AND a Header Line (a structure with type same as one line of the internal table).

  • In positions of ABAP statements where ONLY an internal table is accepted (like WHERE ... IN <name>), mentioning the name will be considered as an internal table.
  • At all other places, it will be considered as the header line.
  • If you want to force the ABAP compiler/program to consider the internal table, you must append 2 square brackets [] at the end of the name

e.g.

kunnr_input = CORRESPONDING #( s_kunnr[] MAPPING kunnr = low ).

The header lines are obsolete because it's prone to errors. SELECT-OPTIONS and TABLES parameters (when seen from inside the procedure) are the only non-obsolete cases where a header line is generated by the kernel.

Header Line:

  • Obsolete work area of an internal table whose type is the line type and has the same name as the internal table. When an internal table with a header line is used in an operand position, the header line is usually addressed. To force access to the table body, square brackets [] can be specified after the table name.

More information: Internal Tables with a Header Line

4 REPLIES 4

sh4il3sh
Participant
0 Kudos

Corresponding Hash one errors!

sunil_mani
Active Participant

Hi Shailesh,

Use the square bracket [] after S_KUNNR while doing corresponding, it will work. See the below code snippet.

DATA: gv_kunnr TYPE kunnr.
SELECT-OPTIONS: s_kunnr FOR gv_kunnr. "Passed 5 Customer Nos here

TYPES: BEGIN OF kunnr_type,
kunnr TYPE kunnr,
END OF kunnr_type.
DATA: kunnr_input TYPE STANDARD TABLE OF kunnr_type.

START-OF-SELECTION.
kunnr_input = VALUE #( FOR l_kunnr IN s_kunnr
( kunnr = l_kunnr-low )
). "Works well

kunnr_input = CORRESPONDING #( s_kunnr[] MAPPING kunnr = low ). ">>>>>>>>>>RUNTIME ERROR

Regards

Sunil Mani

Sandra_Rossi
Active Contributor

Any variable name corresponding to a SELECT-OPTIONS (S_KUNNR in your case) may express both a Ranges Table (internal table with components SIGN, OPTION, LOW, HIGH) AND a Header Line (a structure with type same as one line of the internal table).

  • In positions of ABAP statements where ONLY an internal table is accepted (like WHERE ... IN <name>), mentioning the name will be considered as an internal table.
  • At all other places, it will be considered as the header line.
  • If you want to force the ABAP compiler/program to consider the internal table, you must append 2 square brackets [] at the end of the name

e.g.

kunnr_input = CORRESPONDING #( s_kunnr[] MAPPING kunnr = low ).

The header lines are obsolete because it's prone to errors. SELECT-OPTIONS and TABLES parameters (when seen from inside the procedure) are the only non-obsolete cases where a header line is generated by the kernel.

Header Line:

  • Obsolete work area of an internal table whose type is the line type and has the same name as the internal table. When an internal table with a header line is used in an operand position, the header line is usually addressed. To force access to the table body, square brackets [] can be specified after the table name.

More information: Internal Tables with a Header Line

Very Nicely explained. Everything is clear now!