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

Method redefinition with differen Returning (Exporting) Parameters

JaySchwendemann
Active Contributor
0 Likes
725

Hi all,

please cut me some slack, if this is really basic and I'm missing out on something.

I have a requirement to generate a security code (actually a voucher ID like on a gift card).

For gift card type A the ID should look like this: XXXX-XXXX-XXXX-XXXX-XXXX

For gift card type B the ID should look like this: XXXXX-XXXXX-XXXXX-XXXXX

Now I want to tackle this with ABAP OO. I was thinking of an (abstract?) super class "ZCL_SEC_CODE" with two subclasses "ZCL_SEC_CODE_A" and "ZCL_SEC_CODE_B". There should be a method "get_voucher_id" which should return Voucher Type A when called from "ZCL_SEC_CODE_A" and Voucher Type B when called from "ZCL_SEC_CODE_B".

I know (not saying to be an expert) about facade, factory and the like, but am still having problems with this:

ABAP OO doesn't allow me to create the methods with a different signature for "ZCL_SEC_CODE_A" and "ZCL_SEC_CODE_B". But I actually want (from a client perspective) the methods to be returning say a Char24 for Type A and a Char23 for Type B. Of course I could just use a Char24 for both and write the shorter Type B into that, but that's not my point.

Thanks and cheers

Jens

1 ACCEPTED SOLUTION
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
604

ABAP OO doesn't allow me to create the methods with a different signature for "ZCL_SEC_CODE_A" and "ZCL_SEC_CODE_B".

Is it actually allowed in the other programming languages? (pardon my ignorance)

My 2 cents:

  1. Can you not use type STRING for the RETURNING param? As a matter of fact you can also use a data reference (TYPE REF TO data), if you may!
  2. You can use an EXPORTING param instead with the generic type csequence. Please note RETURNING params cannot be generic! (refer: Typing - ABAP Keyword Documentation)
1 REPLY 1
Read only

SuhaSaha
Product and Topic Expert
Product and Topic Expert
0 Likes
605

ABAP OO doesn't allow me to create the methods with a different signature for "ZCL_SEC_CODE_A" and "ZCL_SEC_CODE_B".

Is it actually allowed in the other programming languages? (pardon my ignorance)

My 2 cents:

  1. Can you not use type STRING for the RETURNING param? As a matter of fact you can also use a data reference (TYPE REF TO data), if you may!
  2. You can use an EXPORTING param instead with the generic type csequence. Please note RETURNING params cannot be generic! (refer: Typing - ABAP Keyword Documentation)