Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
Ramjee_korada
Active Contributor
Prerequisites:

  • Knowledge on ABAP Restful Application Programming

  • Knowledge on Entity Manipulation Language (EML)

  • [Optional] Hands on exercises in OpenSAP course https://open.sap.com/courses/cp13.


This blog gives you an idea to develop a custom action with a dialog for additional input fields that are needed based on scenario.

  • Use case:

    • There is a purchase contract that needs to be extended to next year by buyer.



  • Business logic:

    • Only extend those validities which are running on existing valid to

      • [i.e. continue business with same supplier].



    • Don’t touch items which are older than existing valid to.

      • [i.e. no need to continue business with this supplier]






In my example: 

Old valid to: Jun 30, 2021

New valid to: Dec 31, 2021

Item #10 runs on Jun 30,2021 hence it is expected to extend till Dec 31, 2021

Item #20 ends on Mar 31, 2021 hence it is not expected to touch.


Click the button Extend and to see results on Object page and item page



 

Implementation steps:

  1. Create a data model with Header (Parent), Item (Child), Conditions (Grand Child) having fields “Valid from”, “Valid to “.

  2. Create an abstract CDS entity with required input fields.


@EndUserText.label: 'Abstract entity to extend the validity'
@Metadata.allowExtensions: true
define abstract entity ZRK_A_Doc_Extend
// with parameters parameter_name : parameter_type
{
extend_till : /dmo/end_date;
comments : abap.string( 300 );

}

3.Enrich the entity with UI annotations such as labels.
@Metadata.layer: #CORE
annotate entity ZRK_A_Doc_Extend
with
{
@EndUserText.label: 'New validity to:'
extend_till;
@EndUserText.label: 'Enter your comments:'
comments;

}

4. In Behavior Definition, define action “extendDoc” with parameter using the abstract entity                created in step#2.
  action extendDoc parameter ZRK_A_Doc_Extend result [1] $self;


       5. Implement the core ABAP logic for extend in Behavior Pool Class
METHOD extendDoc.

DATA : lt_update_doc TYPE TABLE FOR UPDATE zrk_i_doc_head.
DATA(lt_keys) = keys.
DATA(lv_today) = cl_abap_context_info=>get_system_date( ).

LOOP AT lt_keys ASSIGNING FIELD-SYMBOL(<fs_key>).

IF <fs_key>-%param-extend_till < lv_today.

APPEND VALUE #( %tky = <fs_key>-%tky ) TO failed-head.

APPEND VALUE #( %tky = <fs_key>-%tky
%msg = new_message( id = 'ZRK_CM_DOC'
number = '001' " Document cannot be extended into the past
severity = if_abap_behv_message=>severity-error )
%element-ValidTo = if_abap_behv=>mk-on ) TO reported-head.

DELETE lt_keys.


ELSE.
DATA(lv_new_valid_to) = <fs_key>-%param-extend_till.
ENDIF.

ENDLOOP.

" Once the validations are passed, proceed with extending document.
CHECK lt_keys IS NOT INITIAL.

READ ENTITIES OF zrk_i_doc_head IN LOCAL MODE
ENTITY Head
FIELDS ( ValidFrom ValidTo )
WITH CORRESPONDING #( keys )
RESULT DATA(lt_doc_head).


CHECK lt_doc_head IS NOT INITIAL.

LOOP AT lt_doc_head ASSIGNING FIELD-SYMBOL(<fs_head>).

" Capture old valid to
DATA(lv_old_valid_to) = <fs_head>-ValidTo.

" Read items from entity
READ ENTITIES OF zrk_i_doc_head IN LOCAL MODE
ENTITY Head BY \_Items
FIELDS ( ValidFrom ValidTo )
WITH VALUE #( ( %tky = <fs_head>-%tky ) )
RESULT DATA(lt_items).

" Loop through items that are running on old valid to
LOOP AT lt_items ASSIGNING FIELD-SYMBOL(<fs_item>)
WHERE ValidFrom LE lv_old_valid_to
AND ValidTo GE lv_old_valid_to.

" Modify item with new valid to
<fs_item>-ValidTo = lv_new_valid_to.

" Read conditions from entity
READ ENTITIES OF zrk_i_doc_head IN LOCAL MODE
ENTITY Items BY \_Conds
FIELDS ( ValidFrom ValidTo )
WITH VALUE #( ( %tky = <fs_item>-%tky ) )
RESULT DATA(lt_conds).

LOOP AT lt_conds ASSIGNING FIELD-SYMBOL(<fs_conds>)
WHERE ValidFrom LE lv_old_valid_to
AND ValidTo GE lv_old_valid_to..

<fs_conds>-ValidTo = lv_new_valid_to.

ENDLOOP.

" Modify conditions entity
MODIFY ENTITIES OF zrk_i_doc_head IN LOCAL MODE
ENTITY Conds
UPDATE FIELDS ( ValidTo )
WITH CORRESPONDING #( lt_conds ).


ENDLOOP.

" Modify Items entity
MODIFY ENTITIES OF zrk_i_doc_head IN LOCAL MODE
ENTITY Items
UPDATE FIELDS ( ValidTo )
WITH CORRESPONDING #( lt_items ).


ENDLOOP.

" Modify header entity
MODIFY ENTITIES OF zrk_i_doc_head IN LOCAL MODE
ENTITY Head
UPDATE
FIELDS ( ValidTo )
WITH VALUE #( FOR <fs_doc> IN lt_doc_head
( %tky = <fs_doc>-%tky
validTo = COND #( WHEN lv_new_valid_to IS NOT INITIAL
THEN lv_new_valid_to
ELSE <fs_doc>-ValidTo ) ) )
REPORTED DATA(lt_update_reported).

reported = CORRESPONDING #( DEEP lt_update_reported ).

" Return result to UI
READ ENTITIES OF zrk_i_doc_head IN LOCAL MODE
ENTITY Head
ALL FIELDS
WITH CORRESPONDING #( keys )
RESULT lt_doc_head.

result = VALUE #( FOR <fs_doc_head> IN lt_doc_head ( %tky = <fs_doc_head>-%tky
%param = <fs_doc_head> ) ).

ENDMETHOD.

6. Position the Action button on List Report and Object Page using annotations.
  @UI: {

lineItem: [
{ type: #FOR_ACTION, dataAction: 'ExtendDoc' , label: 'Extend' , position: 90 } ] ,

identification : [
{ type: #FOR_ACTION, dataAction: 'ExtendDoc' , label: 'Extend' , position: 90 } ]
}

7. Generate the service Binding using OData V4 . [ If you use OData V2, then you have to enrich metadata in fiori app from webide or business studio ]


Service binding for document app with OData V4


Everything is set and its ready for user action:) Hope it helps in learning advanced ABAP RAP.

 
110 Comments
yusufoner
Participant
0 Kudos
Hello Ramjee

Thanks for explanation.

I created a custom screen. but Labels dont appear and i want to change last field to multiple line, how can i do this.

 

Best Regards

 

Yusuf Öner

 

@EndUserText.label: 'XXX'
@Metadata.allowExtensions: true
define abstract entity ZA_MMPUR_PENALTY_ABST with parameters Penalty : boole_d
{

@EndUserText.label: 'Strafe'
Penalty : boole_d;

@EndUserText.label: 'Rechnung'
Rechnung : boole_d;

@EndUserText.label: 'Kommentar'
PenaltyText : abap.char( 500 );

}

 

 

@Metadata.layer: #CORE
annotate entity ZA_MMPUR_PENALTY_ABST with
{

@EndUserText.label: 'Strafe'
Penalty;

@EndUserText.label: 'Rechnung'
Rechnung;

@EndUserText.label: 'Kommentar'
PenaltyText;

}

Odata Version V4 looks like

 

 

 

mainak-aich
Participant
0 Kudos
Hi timmuller , ramjee.korada ,

Can you please suggest how to pass the list report record value to the popup screen? How are you achieving it currently as you are showing in your screenshot?

Thanks,

Mainak
mainak-aich
Participant
0 Kudos
Hi ramjee.korada ,

Can you please share if there any blog or URL which describes how to "Define a function in Behavior definition and consume it from fragment in Fiori extension project." in this case?

Thanks,

Mainak
Ramjee_korada
Active Contributor
0 Kudos
Hi Mainak,

I answered it in another question.

Please see https://answers.sap.com/answers/13945315/view.html

 

Best wishes,

Ramjee Korada
rdulek
Explorer
0 Kudos
Hi Ramjee, Christine,

I have the same problem with 'readonly'. Do you have any solution suggestions?

 

 

Regards,
renatofraga47
Discoverer
0 Kudos

Hi Guys,

I have the same problem. Someone could fix it for oData V2 ?

I've tried all kind annotations, with or without an annotate entity extension.

Unfortunately I only got the technical name of field at pop up screen, not the Label that i set by annotation at Abstract Entity.

Can anybody help me?

kendrickc
Explorer
0 Kudos
Hello Ramazan,

I went into the BAS project and made a fully custom action in Javascript instead of trying to use the Fiori annotations.
0 Kudos
Hi koradaramjee789 ,

Its a very informative blog. Thanks for that.

I have two questions:

  • Is it possible to show multiple rows in the dialog that's opening?

  • Is it possible to add a 'Delete' button in the dialog or any other button for that matter?


 

Thanks,

Pratishtha
Ramjee_korada
Active Contributor
0 Kudos
Hi Pratishta,

Thanks for the feedback.

I don't think this is feasible with the current feature from RAP.

Best wishes,

Ramjee Korada
jdesousa
Explorer
0 Kudos
Dear koradaramjee789

Congrats for this very helpful blog!

I would like to know if it is possible to do a similar action but using a multi input instead of an input field.

I'm struggling to find a way to pass a array of values into action.

Best regards.

José Sousa
Labels in this area