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: 

Issue with Inline Declaration Assignment

former_member207873
Participant
0 Kudos

Hi Experts,

Please find my below code.


DATA : PA_FY TYPE GJAHR.    " SUCCEEDING FINANCIAL YEAR.
DATA(PA_FY1) = PA_FY + 1.

**/-- FINANCIAL YEAR STARTING DATE

CONCATENATE PA_FY '04' '01' INTO DATA(FIN_STRT_DATE).

**/-- FINACIAL YEAR ENDING DATE

CONCATENATE PA_FY1 '03' '31' INTO DATA(FIN_END_DATE).

This code is returning error message .

"PA_FY1" must be character-type data object (data type C,N,D,T or string)

But if i declare 'PA_FY1' as

DATA(PA_FY1) TYPE GJAHR.

Then it wont throw any error message.

B.R.

1 ACCEPTED SOLUTION

Sandra_Rossi
Active Contributor

DATA(PA_FY1)= PA_FY +1.

The compiler determines the types as explained here: Calculation type

Based on the documentation: PA_FY being of type N, and 1 being an Integer, then the calculation type will be Packed (type P).

Consequently, PA_FY1 is also defined as type P.

If you comment the erroneous code, and if you debug, you'll be able to see the real type of PA_FY1.

6 REPLIES 6

nomssi
Active Contributor
0 Kudos

Your statement

DATA(PA_FY1)= PA_FY +1.

is not valid because the type of the defined variable PA_FY1 cannot be determined from the left hand side of the term: PA_FY is character-like, 1 is a number. So which type should the compiler use? That is how the error message should be understood, I guess.

And you probably mean

DATA PA_FY1 TYPE GJAHR

as

DATA(PA_FY1)TYPE GJAHR.

is not valid ABAP.

JNN

Sandra_Rossi
Active Contributor

DATA(PA_FY1)= PA_FY +1.

The compiler determines the types as explained here: Calculation type

Based on the documentation: PA_FY being of type N, and 1 being an Integer, then the calculation type will be Packed (type P).

Consequently, PA_FY1 is also defined as type P.

If you comment the erroneous code, and if you debug, you'll be able to see the real type of PA_FY1.

Sandra_Rossi
Active Contributor
0 Kudos

DATA(PA_FY1) = PA_FY + 1.

is a valid statement as of ABAP 7.40

The syntax error is probably for this line, because PA_FY1 is of type P :

CONCATENATE PA_FY1 '03' '31' INTO DATA(FIN_END_DATE).

horst_keller
Product and Topic Expert
Product and Topic Expert

Besides all the other correct answers here, think about using the CONV operator in order to enforce the correct type at operand positions. Then, you cannot use CONCATENATE but &&:

... = ... && CONV string( ... ) && ...

Horst

raghug
Active Contributor

Taking both Horst Keller's response and Sandra Rossi's into account, you could combine them and use the statement

DATA(PA_FY1) = CONV gjahr( PA_FY + 1 ).

This will force the data type gjahr onto PA_FY1.

horst_keller
Product and Topic Expert
Product and Topic Expert

or

DATA(FIN_STRT_DATE) = CONV string( PA_FY1 ) && '04' && '01'.

FIN_STRT_DATE will have type string.