SAP & Oracle partner and support companies

Loading

Archives 2025

SAP

GPS like tool in SAP using Google Map API

In the previous article, we perceived how we can get the scope and longitude of any location utilizing Google Guide Programming interface. Adding to that learning, here, we would figure out how to get the distance between two locations. We would likewise perceive how we can infer turn by turn headings between two given addresses. To add more to the tomfoolery, we would likewise open a program from SAP and show the course between two focuses on the guide. Let’s delve into the GPS like tool in SAP using Google Map API.

Do you think, this is interesting? 

To put it plainly, this device would carry on like a GPS like tool in SAP using Google Map API, which would assist you with getting the Directions (Scopes/Longitudes), Course and Guide with complete heading.

Before we check, how it tends to be finished, let us first see, what we are referring to.

I.  First radio button: Coordinates & Distance

We get the Directions of two locations and furthermore the distance between them.

II.  Second Radio button: Turn by turn route

The device would give you the total separation of the course from the source to the objective location. It would likewise furnish you with different courses if accessible.

II.  Let’s check the third radio button which says ‘Display Map‘.

As mentioned, this GPS Device would show the guide alongside the courses in an Internet Browser. Look at this.

Google Map

Did you like it?

You can utilize the code piece gave toward the finish of this article and attempt it yourself. The code gave here would function for what it’s worth. The idea was at that point made sense of in our previous post ‘Get Scope and Longitude of any spot utilizing Google Guide Programming interface in SAP’.

For the three result choices, we want to call three APIs. As made sense of in the previous article, we link the strings with source and objective location, Scopes and Longitudes and so forth to finish the Programming interface URL and get the XML information. Perusing the XML information and pinpointing the required data is the stunt which we have previously learned.

a) GeoCode API String for Coordinates:

* Prepare the url of the GeoCode API
  CONCATENATE
    'http://maps.google.com/maps/api/geocode/xml?address='
    lv_address
    INTO lv_http_url .

b) Distance Matrix API String for retrieving the distance between Coordinates:

* Prepare the url for the DistanceMatrix API using From Address Coordinates and To Address Coordinates
  CONCATENATE
    'http://maps.googleapis.com/maps/api/distancematrix/xml?origins='
    <fs_dest>-place_f '|' <fs_dest>-lat_f ',' <fs_dest>-lng_f ','
    '&destinations=' <fs_dest>-place_t '|' <fs_dest>-lat_t ',' <fs_dest>-lng_t
    '&alternatives=' 'true'
    INTO lv_http_url .

c) Directions API String to trace the route on the Map:

* Prepare the url for Directions API for the From Address Coordinates and To Address Coordinates
  CONCATENATE
    'http://maps.googleapis.com/maps/api/directions/xml?origin='
    <fs_dest>-place_f '|' <fs_dest>-lat_f ',' <fs_dest>-lng_f
    '&destination=' <fs_dest>-place_t '|' <fs_dest>-lat_t ',' <fs_dest>-lng_t
    '&alternatives=' 'true'
    INTO lv_http_url .

where:
lv_address               = From/To address
<fs_dest>-place_f = From address
<fs_dest>-lat_f      = From address latitude
<fs_dest>-lng_f     = From address longitude
<fs_dest>-place_t = To address
<fs_dest>-lat_t      = To address latitude
<fs_dest>-lng_t      = To address longitude

Once you have the correct API URL, use this cl_http_client class and create_by_url method to get the detailed information.

* Get client from url
  CALL METHOD cl_http_client=>create_by_url
    EXPORTING
      url                = lv_http_url
    IMPORTING
      client             = p_http_client
    EXCEPTIONS
      argument_not_found = 1
      plugin_not_active  = 2
      internal_error     = 3
      OTHERS             = 4.

Kindly go through the nitty gritty code to check how it functions. There may be better ways of perusing these APIs and XML information however we simply needed to show the potential outcomes. You can investigate more and sort out the most ideal way for you.

In the event that you track down any trouble in figuring out the code or idea, kindly keep in touch with us or leave your inquiry in the remark segment. We would doubtlessly answer.

In the event that you have question whether this apparatus would work for Non-India address. Be have confidence, it works for any location. Really look at the result for the location in the USA.

To get such commonsense issues and objectives straightforwardly to your inbox, assuming no one minds, Purchase in. We respect your security and view shielding it in a serious manner.

Expecting that you partook in this post, assuming no one minds, hit the deal buttons.

Much obliged to you generous for your time!!

*-----------------------------------------------------------------------
* Title : Get Latitude and Longitude of a place from Google API
* Get distance between two addresses
* Show the turn by turn route of two addresses
* Show route in map in a browser
*-----------------------------------------------------------------------
* Change History :
* Author DATE REQUEST# DESCRIPTION
*--------------- ---------- ----------- -------------------------------
* Intial Development
*-----------------------------------------------------------------------
REPORT elearningsolutions_gps_google_api NO STANDARD PAGE HEADING
LINE-COUNT 132.
*&---------------------------------------------------------------------*
*& TYPE-POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS: truxs, slis.
*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK b1 WITH FRAME TITLE text-t01.
PARAMETERS : p_add_f TYPE c LENGTH 50,
p_add_t TYPE c LENGTH 50.
SELECTION-SCREEN END OF BLOCK b1.

SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-t02.
PARAMETERS:
p_alv RADIOBUTTON GROUP
p_route RADIOBUTTON GROUP
p_map RADIOBUTTON GROUP
SELECTION-SCREEN END OF BLOCK b2.

*&---------------------------------------------------------------------*
*& Types and Data
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_dest,
place_f TYPE c LENGTH 50, " From Place
place_t TYPE c LENGTH 50, " To Place
lat_f TYPE c LENGTH 20, " From Latitude
lng_f TYPE c LENGTH 20, " From Longitude
lat_t TYPE c LENGTH 20, " To Latitude
lng_t TYPE c LENGTH 20, " To Longitude
dis TYPE c LENGTH 30, " Distance
END OF ty_dest,

BEGIN OF ty_route,
route_n TYPE c LENGTH 255, " Start of New Route
summary TYPE c LENGTH 120, " Route Summary
step TYPE syst_tabix, " Turn step
ins TYPE c LENGTH 255, " Instruction
dis TYPE c LENGTH 20, " Distance
END OF ty_route.

TYPES: t_ty_route TYPE TABLE OF ty_route.

DATA:
gt_dest TYPE STANDARD TABLE OF ty_dest,
gt_route TYPE STANDARD TABLE OF ty_route.

FIELD-SYMBOLS:
<fs_dest> TYPE ty_dest.


*&---------------------------------------------------------------------*
*& Start of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION .

* Get longitude and latitude of From Address
PERFORM get_long_lat USING p_add_f.

* Get longitude and latitude of To Address
PERFORM get_long_lat USING p_add_t.

*&---------------------------------------------------------------------*
*& End of Selection
*&---------------------------------------------------------------------*
END-OF-SELECTION .

* Get distance between two address
PERFORM measure_distance.

* Get detailed turn by turn address
PERFORM turn_by_turn_route.

* Show the output
PERFORM show_output.


************************************************************************
*&---------------------------------------------------------------------*
*& Sub Routines
*&---------------------------------------------------------------------*
************************************************************************
FORM get_long_lat USING lv_address TYPE char50.

DATA:
lv_http_client TYPE REF TO if_http_client,
lv_content TYPE string.

* Creation of new IF_HTTP_Client object
PERFORM create_http_client USING lv_address
CHANGING lv_http_client .

* Request and Get
PERFORM http_client_request_get_method USING lv_http_client.

* Send the request
PERFORM http_client_send USING lv_http_client.

* Retrieve the result
PERFORM http_client_receive USING lv_http_client CHANGING lv_content.

* Get the actual coordinate using the content string
PERFORM get_coordinates USING lv_content lv_address.


ENDFORM. " get_long_lat
*&---------------------------------------------------------------------*
*& Form CREATE_HTTP_CLIENT
*&---------------------------------------------------------------------*
* Create HTTP Client
*----------------------------------------------------------------------*
FORM create_http_client USING lv_address TYPE char50
CHANGING p_http_client TYPE REF TO if_http_client.

DATA: lv_http_url TYPE string.

* Prepare the url of the GeoCode API
CONCATENATE
'http://maps.google.com/maps/api/geocode/xml?address='
lv_address
INTO lv_http_url .

* Get client from url
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_http_url
IMPORTING
client = p_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form HTTP_CLIENT_REQUEST_GET_METHOD
*&---------------------------------------------------------------------*
* Request and Get Method
*----------------------------------------------------------------------*
FORM http_client_request_get_method USING p_http_client TYPE REF TO if_http_client..
* Request and Get
p_http_client->request->set_header_field( name = '~request_method' value = 'GET' ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form HTTP_CLIENT_SEND
*&---------------------------------------------------------------------*
* Send request
*----------------------------------------------------------------------*
FORM http_client_send USING p_http_client TYPE REF TO if_http_client.
* Send the request
p_http_client->send( ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form HTTP_CLIENT_RECEIVE
*&---------------------------------------------------------------------*
* Get the string content
*----------------------------------------------------------------------*
FORM http_client_receive USING p_http_client TYPE REF TO if_http_client
CHANGING p_p_content TYPE string.
* Reterive the result
CALL METHOD p_http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.

* CALL METHOD p_http_client->response->get_cdata(
* RECEIVING
* data = p_p_content " Character data
* EXCEPTIONS
* OTHERS = 1 ).

p_p_content = p_http_client->response->get_cdata( ).

ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_COORDINATES
*&---------------------------------------------------------------------*
* Get Latitute Longitude Coordinate
*----------------------------------------------------------------------*
FORM get_coordinates USING p_p_content TYPE string
lv_address TYPE char50.

* Local data declaration
DATA: lv_url TYPE c LENGTH 255,
ls_dest TYPE ty_dest,
moff TYPE syst-tabix,
moff1 TYPE syst-tabix,
lv_len TYPE syst-tabix,
lv_lat TYPE c LENGTH 20,
lv_lng TYPE c LENGTH 20.

* Field symbol
FIELD-SYMBOLS:
<lfs_dest> TYPE ty_dest.
*&---------------------------------------------------------------------*
*& Processing string
*&---------------------------------------------------------------------*
DO .
* Find <location> text in the content string
FIND '<location>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff .

IF sy-subrc = 0 .
* <location> is a 10 character string, hence adding 10
moff = moff + 10 .

* Find closing tag </location> text in the content string
FIND '</location>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff1 .

* Find the length of string between tag <location> and </location>
lv_len = moff1 - moff .

* We have seen the API string contet, so we know <lat> </lat> <lng> </lng> are there between
* <location> and </location>
*--------------------------------------------------------------------*
* ---------------Find latitude
*--------------------------------------------------------------------*
* Find string <lat>
FIND '<lat>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff .
IF sy-subrc = 0 .
* <lat> is a 5 character string, hence adding 5
moff = moff + 5 .

* Find closing tag </lat> text in the content string
FIND '</lat>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff1 .

* Find the length of string between tag <lat> and </lat>
lv_len = moff1 - moff .

* Characters between <lat> </lat> will have the latitude coorniate
lv_lat = p_p_content+moff(lv_len) .

* From place address
ls_dest-place_f = lv_address .

* Keep latitude in structure
ls_dest-lat_f = lv_lat.

ENDIF.

*--------------------------------------------------------------------*
* ---------------Find longitude
*--------------------------------------------------------------------*
* Find string <lng>
FIND '<lng>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff .
IF sy-subrc = 0 .

* <lng> is a 5 character string, hence adding 5
moff = moff + 5 .

* Find closing tag </lng> text in the content string
FIND '</lng>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff1 .

* Find the length of string between tag <lng> and </lng>
lv_len = moff1 - moff .

* Characters between <lng> </lng> will have the latitude coorniate
lv_lng = p_p_content+moff(lv_len) .

* Keep longitude in structure
ls_dest-lng_f = lv_lng.

ENDIF.
ELSE.

EXIT.

ENDIF.

ENDDO .

IF gt_dest[] IS INITIAL.
* This part would trigger for From Latitude and Longitude
* Put in internal table to display later
APPEND ls_dest TO gt_dest.
CLEAR:ls_dest .

ELSE.

* This part would trigger for To Latitude and Longitude
READ TABLE gt_dest ASSIGNING <lfs_dest> INDEX 1.
IF sy-subrc EQ 0.
<lfs_dest>-place_t = lv_address.
<lfs_dest>-lat_t = ls_dest-lat_f.
<lfs_dest>-lng_t = ls_dest-lng_f.
ENDIF.

ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_LAT_LONGITUDE
*&---------------------------------------------------------------------*
* Display Latitude and Longitude
*----------------------------------------------------------------------*
FORM display_lat_longitude .

DATA:
lr_alv TYPE REF TO cl_salv_table,
lr_columns TYPE REF TO cl_salv_columns_table,
lr_column TYPE REF TO cl_salv_column,
lr_functions TYPE REF TO cl_salv_functions_list,
lr_display TYPE REF TO cl_salv_display_settings,
lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key,
lr_sorts TYPE REF TO cl_salv_sorts.

" Check to make sure the internal table has data.
IF lines( gt_dest ) > 0.

TRY.
* Create ALV instance
* Use CALL METHOD since this is a static method
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lr_alv
CHANGING
t_table = gt_dest.

* Get functions object and then set all the functions to be allowed
lr_functions = lr_alv->get_functions( ).
lr_functions->set_all( ).

lr_columns = lr_alv->get_columns( ).

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'PLACE_F'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'From Place Name'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'LAT_F'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'From Latitude'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'LNG_F'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'From Longitude'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'PLACE_T'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'To Place Name'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'LAT_T'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'To Latitude'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'LNG_T'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'To Longitude'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'DIS'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'Distance between From & To Address'.



lr_columns->set_optimize( ).

* Set sort column
lr_sorts = lr_alv->get_sorts( ).
lr_sorts->clear( ).

* This code is to get the layout, save the layout and display the layout
lr_layout = lr_alv->get_layout( ).
ls_key-report = sy-repid.
lr_layout->set_key( ls_key ).
lr_layout->set_default( ' ' ).
lr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).


lr_display = lr_alv->get_display_settings( ).
lr_display->set_striped_pattern( cl_salv_display_settings=>true ).

* Now display the report as an ALV grid
lr_alv->display( ).

CATCH cx_salv_msg.
WRITE: 'Error displaying grid CX_SALV_MSG!'(001).

CATCH cx_salv_not_found.
WRITE: 'Error displaying grid CX_SALV_NOT_FOUND!'(002).

CATCH cx_salv_data_error.
WRITE: 'Error displaying grid CX_SALV_DATA_ERROR!'(003).

CATCH cx_salv_existing.
WRITE: 'Error displaying grid CX_SALV_EXISTING!'(004).

ENDTRY.

ELSE.
MESSAGE 'No data to display' TYPE 'I'.
LEAVE LIST-PROCESSING.

ENDIF.


ENDFORM.
*&---------------------------------------------------------------------*
*& Form MEASURE_DISTANCE
*&---------------------------------------------------------------------*
* Get distance between the from and to address
*----------------------------------------------------------------------*
FORM measure_distance .

DATA:
lv_http_client TYPE REF TO if_http_client,
lv_content TYPE string.

LOOP AT gt_dest ASSIGNING <fs_dest>.

* Creation of new IF_HTTP_Client object
PERFORM create_http_client_dist CHANGING lv_http_client .

* Request and Get
PERFORM http_client_request_get_method USING lv_http_client.

* Send the request
PERFORM http_client_send USING lv_http_client.

* Retrieve the result
PERFORM http_client_receive USING lv_http_client CHANGING lv_content.

* Get the actual coordinate using the content string
PERFORM get_coordinates_dist USING lv_content.

ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_HTTP_CLIENT_DIST
*&---------------------------------------------------------------------*
* * Create HTTP Client
*----------------------------------------------------------------------*
FORM create_http_client_dist CHANGING p_http_client TYPE REF TO if_http_client.

DATA: lv_http_url TYPE string.

* Prepare the url for the DistanceMatrix API From Address Coordinates and To Address Coordinates
CONCATENATE
'http://maps.googleapis.com/maps/api/distancematrix/xml?origins='
<fs_dest>-place_f '|' <fs_dest>-lat_f ',' <fs_dest>-lng_f ','
'&destinations=' <fs_dest>-place_t '|' <fs_dest>-lat_t ',' <fs_dest>-lng_t
'&alternatives=' 'true'
INTO lv_http_url .

* Get client from url
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_http_url
IMPORTING
client = p_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_COORDINATES_DIST
*&---------------------------------------------------------------------*
* Get Latitute Longitude Coordinate
*----------------------------------------------------------------------*
FORM get_coordinates_dist USING p_p_content TYPE string.

* Local data declaration
DATA: lv_url TYPE c LENGTH 255,
ls_dest TYPE ty_dest,
moff TYPE syst-tabix,
moff1 TYPE syst-tabix,
lv_len TYPE syst-tabix,
lv_lat TYPE c LENGTH 20,
lv_lng TYPE c LENGTH 20.

* Field symbol
FIELD-SYMBOLS:
<lfs_dest> TYPE ty_dest.
*&---------------------------------------------------------------------*
*& Processing string
*&---------------------------------------------------------------------*
DO .
* Find <distance> text in the content string
FIND '<distance>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff .
IF sy-subrc = 0 .

* <distance> is a 10 character string, hence adding 10
moff = moff + 10 .

* Find closing tag </distance> text in the content string
FIND '</distance>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff1 .

** Find the length of string between tag <distance> and </distance>
* lv_len = moff1 - moff .

* We have seen the API string contet, so we know <text> </text> are there between
* <distance> and </distance>
FIND '<text>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff .
IF sy-subrc = 0 .
* <text> is a 6 character string, hence adding 6
moff = moff + 6 .

* Find closing tag </text> text in the content string
FIND '</text>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff1 .

* Find the length of string between tag <text> and </text>
lv_len = moff1 - moff .

* Characters between <text> </text> will have the distance
<fs_dest>-dis = p_p_content+moff(lv_len).

* Get one distance and exit
EXIT.

ENDIF.

ELSE.
EXIT.
ENDIF.
ENDDO .
ENDFORM.
*&---------------------------------------------------------------------*
*& Form SHOW_OUTPUT
*&---------------------------------------------------------------------*
* Show output
*----------------------------------------------------------------------*
FORM show_output .

IF p_alv IS NOT INITIAL.

* Show Latitute, Longitude and Distance
PERFORM display_lat_longitude.

ELSEIF p_route IS NOT INITIAL.

* Show the complete break down of driving route
PERFORM display_turn_by_turn_route.

ELSEIF p_map IS NOT INITIAL.

* Show direction in map
PERFORM show_map.

ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form TURN_BY_TURN_ROUTE
*&---------------------------------------------------------------------*
* Get turn by turn ROUTE
*----------------------------------------------------------------------*
FORM turn_by_turn_route .

DATA:
lv_http_client TYPE REF TO if_http_client,
lv_content TYPE string,
lv_xstring TYPE xstring,
li_xml_table TYPE TABLE OF smum_xmltb.

IF p_route IS NOT INITIAL.

LOOP AT gt_dest ASSIGNING <fs_dest>.

* Creation of new IF_HTTP_Client object
PERFORM create_http_client_direction CHANGING lv_http_client .

* Request and Get
PERFORM http_client_request_get_method USING lv_http_client.

* Send the request
PERFORM http_client_send USING lv_http_client.

* Retrieve the result
PERFORM http_client_receive USING lv_http_client CHANGING lv_content.

** Get the actual coordinate using the content string
* PERFORM get_coordinates_dist USING lv_content.

* Convert String to XString
PERFORM convert_string_to_xstring USING lv_content CHANGING lv_xstring.

* Parse XML document into a table structure
PERFORM parse_xml_to_table USING lv_xstring CHANGING li_xml_table.

* Clean XML file
PERFORM clean_xml_data USING li_xml_table.



ENDLOOP.

ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form CONVERT_STRING_TO_XSTRING
*&---------------------------------------------------------------------*
* Convert sting to xstring
*----------------------------------------------------------------------*
FORM convert_string_to_xstring USING p_p_content TYPE string
CHANGING p_p_xstring TYPE xstring.

CALL FUNCTION 'SCMS_STRING_TO_XSTRING'
EXPORTING
text = p_p_content
IMPORTING
buffer = p_p_xstring
EXCEPTIONS
failed = 1
OTHERS = 2.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form PARSE_XML_TO_TABLE
*&---------------------------------------------------------------------*
* Parse XML docment into a table structure
*----------------------------------------------------------------------*
FORM parse_xml_to_table USING p_p_xstring TYPE xstring
CHANGING p_li_xml_table TYPE hrpayfr_t_smum_xmltb.

DATA:
li_return TYPE TABLE OF bapiret2.

CALL FUNCTION 'SMUM_XML_PARSE'
EXPORTING
xml_input = p_p_xstring
TABLES
xml_table = p_li_xml_table
return = li_return.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form CREATE_HTTP_CLIENT_DIRECTION
*&---------------------------------------------------------------------*
* Get Direction API
*----------------------------------------------------------------------*
FORM create_http_client_direction CHANGING p_http_client TYPE REF TO if_http_client.

DATA: lv_http_url TYPE string.

* Prepare the url for Directions API for the From Address Coordinates and To Address Coordinates
CONCATENATE
'http://maps.googleapis.com/maps/api/directions/xml?origin='
<fs_dest>-place_f '|' <fs_dest>-lat_f ',' <fs_dest>-lng_f
'&destination=' <fs_dest>-place_t '|' <fs_dest>-lat_t ',' <fs_dest>-lng_t
'&alternatives=' 'true'
INTO lv_http_url .

CONDENSE lv_http_url.

* Get client from url
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_http_url
IMPORTING
client = p_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form CLEAN_XML_DATA
*&---------------------------------------------------------------------*
* Clean XML data to cleaner format
*----------------------------------------------------------------------*
FORM clean_xml_data USING p_li_xml_table TYPE hrpayfr_t_smum_xmltb.
DATA:
ls_xml TYPE smum_xmltb,
ls_path TYPE ty_route.

* Deleting time mentioned in the XML. If you want time, you need to
* keep this and manipulate later
DELETE p_li_xml_table WHERE cvalue CS 'min'.

* Remove sub total for partial route. If you want time, you need to
* keep this and manipulate later
DELETE p_li_xml_table WHERE
hier = '5' AND
type = 'V' AND
cname = 'text'.

* Reading the XML data
LOOP AT p_li_xml_table INTO ls_xml.

AT FIRST.
* First step is new route by default
ls_path-route_n = abap_true.
ENDAT.

* Remove the XML format tag codes
REPLACE ALL OCCURRENCES OF '<b>' IN ls_xml-cvalue WITH space.
REPLACE ALL OCCURRENCES OF '</b>' IN ls_xml-cvalue WITH space.

* Remove the XML format tag codes
REPLACE ALL OCCURRENCES OF '<div style="font-size:0.9em">' IN ls_xml-cvalue WITH '.'.
REPLACE ALL OCCURRENCES OF '</div>' IN ls_xml-cvalue WITH space.

* Check the name
CASE ls_xml-cname.

* Get the summary of the route
WHEN 'summary'.
ls_path-summary = ls_xml-cvalue.

* Driving instruction
WHEN 'html_instructions'.
ls_path-ins = ls_xml-cvalue.

* Text would have the distance and unit
WHEN 'text'.
ls_path-dis = ls_xml-cvalue.

* Copyrights means, start of new path
WHEN 'copyrights'.

ls_path-route_n = 'X'.
CLEAR ls_path-step.

WHEN OTHERS.
* do nothing

ENDCASE.

* If there is some data, populate the route table
IF ls_path-ins IS NOT INITIAL
AND ls_path-dis IS NOT INITIAL.

ls_path-step = ls_path-step + 1.

* This will have the route details
APPEND ls_path TO gt_route.

CLEAR: ls_path-ins, ls_path-dis, ls_path-route_n, ls_path-summary.

ENDIF.

CLEAR: ls_xml.

ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_TURN_BY_TURN_ROUTE
*&---------------------------------------------------------------------*
* Display Turn by Turn route
*----------------------------------------------------------------------*
FORM display_turn_by_turn_route .

DATA:
lr_alv TYPE REF TO cl_salv_table,
lr_columns TYPE REF TO cl_salv_columns_table,
lr_column TYPE REF TO cl_salv_column,
lr_functions TYPE REF TO cl_salv_functions_list,
lr_display TYPE REF TO cl_salv_display_settings,
lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key,
lr_sorts TYPE REF TO cl_salv_sorts.

" Check to make sure the internal table has data.
IF lines( gt_route ) > 0.

TRY.
* Create ALV instance
* Use CALL METHOD since this is a static method
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lr_alv
CHANGING
t_table = gt_route.

* Get functions object and then set all the functions to be allowed
lr_functions = lr_alv->get_functions( ).
lr_functions->set_all( ).

lr_columns = lr_alv->get_columns( ).

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'ROUTE_N'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'New Route Indicator'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'SUMMARY'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'Via'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'STEP'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'Important Turns'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'INS'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'Instructions'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'DIS'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'Distance'.

lr_columns->set_optimize( ).

* Set sort column
lr_sorts = lr_alv->get_sorts( ).
lr_sorts->clear( ).

* This code is to get the layout, save the layout and display the layout
lr_layout = lr_alv->get_layout( ).
ls_key-report = sy-repid.
lr_layout->set_key( ls_key ).
lr_layout->set_default( ' ' ).
lr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).


lr_display = lr_alv->get_display_settings( ).
lr_display->set_striped_pattern( cl_salv_display_settings=>true ).

* Now display the report as an ALV grid
lr_alv->display( ).

CATCH cx_salv_msg.
WRITE: 'Error displaying grid CX_SALV_MSG!'(001).

CATCH cx_salv_not_found.
WRITE: 'Error displaying grid CX_SALV_NOT_FOUND!'(002).

CATCH cx_salv_data_error.
WRITE: 'Error displaying grid CX_SALV_DATA_ERROR!'(003).

CATCH cx_salv_existing.
WRITE: 'Error displaying grid CX_SALV_EXISTING!'(004).

ENDTRY.

ELSE.
MESSAGE 'No route data to display' TYPE 'I'.
LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form SHOW_MAP
*&---------------------------------------------------------------------*
* Show direction on the map
*----------------------------------------------------------------------*
FORM show_map .

DATA:
lv_http_client TYPE REF TO if_http_client,
lv_content TYPE string.

LOOP AT gt_dest ASSIGNING <fs_dest>.

* Call Browser
PERFORM call_browser.

EXIT.
ENDLOOP.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form CALL_BROWSER
*&---------------------------------------------------------------------*
* Route map
*----------------------------------------------------------------------*
FORM call_browser.

DATA: lv_url TYPE c LENGTH 255.

* Prepare the url for Directions API for the From Address Coordinates and To Address Coordinates
CONCATENATE
'https://www.google.co.in/maps/dir/'
<fs_dest>-lat_f ',' <fs_dest>-lng_f '/'
<fs_dest>-lat_t ',' <fs_dest>-lng_t
INTO lv_url .

* Condense the text
CONDENSE lv_url.

* Open the route in browser
CALL FUNCTION 'CALL_BROWSER'
EXPORTING
url = lv_url
EXCEPTIONS
frontend_not_supported = 1
frontend_error = 2
prog_not_found = 3
no_batch = 4
unspecified_error = 5
OTHERS = 6.


ENDFORM.

YOU MAY BE INTERESTED IN

Consuming APIs in SAP Applications

SAP API Landscape

SAP API Development: Bridging the Digital Divide

Stream of data api

SAP

Get Latitude and Longitude of any place using Google Map API in SAP

Before diving into the Get Latitude and Longitude of any place using Google Map API in SAP. Understand SAP shocks us consistently. Indeed, even in the wake of working for over 10 years, another undertaking or client will have a few prerequisites which are exceptional and you want out of the case thinking and arrangement. The beneath post is a comparable necessity where a client needed to realize the Geo Directions of some random spot. There are numerous ways of getting the Scopes and Longitudes however Kuldeep Joshi (who contributed this post), found an extremely helpful way by utilizing Google Guide Programming interface. He thought Google Guide is free and promptly accessible, so why not use it in SAP effortlessly.

Check underneath, assuming the client enters any location, he ought to get the scope and longitude of that spot. Get Latitude and Longitude of any place using Google Map API in SAP.

Geo Coordinates in SAP

Isn’t it a cool requirement?

How might we accomplish this?

Straightforward, interface with Google Guide Administration (read Programming interface), examine through its substance string and track down your information. It needs some perusing the string, yet this is truly successful and simple arrangement.

You can also read for:- Is Google using Oracle?

Really take a look at this means (itemized code is accessible toward the finish of the article beneath)

http_client

Connect your feedback address with the Google Guides Programming interface web address to get the client information.

Generate Google Map API path

Demand the information. Really take a look at your cases (lower/upper) of the strategies (they may be case touchy).

Get Method

Send the request.

Request service

Get the reaction from Google Programming interface.

Receive the request

Presently, you have the string content. Simply glance through the string at the ideal locations and get the scope/longitude data.

Geo Code from Google Map API

<location> </location> are the opening and closing tag. We need to find the latitudes and longitudes in between these two tags.

Similarly <lat> </lat> and <lng> </lng> are the opening and closing tags for Latitude and Longitude respectively.

This is one illustration of the substance record got from Google Programming interface. Taking a gander at the information, it is extremely clear, where we can track down the directions.

Google API

Ideally, this post would assist you with tracking down the expected directions. In the following post would tell the best way to find the distance between two tends to involving Google Programming interface in SAP. Additionally, he would show, how to open the two tends to in research Guide and show the distance in the program. If it’s not too much trouble, remain tuned.

Furthermore, our code not just works for India address, it works for any location on the planet. We should actually look at a location in USA.

Coordinates in SAP ABAP

You can approve the directions in Google Guide physically.

Here is the code snippet used for this post.

*-----------------------------------------------------------------------
* Date : 07/05/2025
* Author : Varad (For www.elearningsolutions.co.in)
* Title : Get Latitude and Longitude of a place from Google API
*-----------------------------------------------------------------------
* Change History :
* Author DATE REQUEST# DESCRIPTION
*--------------- ---------- ----------- -------------------------------
* varad 07/05/2025 Intial Development
*-----------------------------------------------------------------------
REPORT elearningsolutions_google_api NO STANDARD PAGE HEADING
LINE-COUNT 132.
*-----------------------------------------------------------------------
* Title : Get Latitude and Longitude of a place from Google API
*-----------------------------------------------------------------------
* Change History :
* Author DATE REQUEST# DESCRIPTION
*--------------- ---------- ----------- ------------------------------- Intial Development
*-----------------------------------------------------------------------
*&---------------------------------------------------------------------*
*& TYPE-POOLS
*&---------------------------------------------------------------------*
TYPE-POOLS: truxs, slis.
*&---------------------------------------------------------------------*
*& Selection Screen
*&---------------------------------------------------------------------*
PARAMETERS : p_add_f TYPE c LENGTH 50.


*&---------------------------------------------------------------------*
*& Types and Data
*&---------------------------------------------------------------------*
TYPES: BEGIN OF ty_dest,
place_f TYPE c LENGTH 50,
lat_f TYPE c LENGTH 20,
lng_f TYPE c LENGTH 20,
END OF ty_dest.

DATA: gt_dest TYPE STANDARD TABLE OF ty_dest.


*&---------------------------------------------------------------------*
*& Start of Selection
*&---------------------------------------------------------------------*
START-OF-SELECTION .

* Get longitude and latitude
PERFORM get_long_lat.

*&---------------------------------------------------------------------*
*& End of Selection
*&---------------------------------------------------------------------*
END-OF-SELECTION .

* Show Latitute and Longitude
PERFORM display_lat_longitude.
*&---------------------------------------------------------------------*
*& Sub Routines
*&---------------------------------------------------------------------*
FORM get_long_lat .

DATA:
lv_http_client TYPE REF TO if_http_client,
lv_content TYPE string.

* Creation of new IF_HTTP_Client object
PERFORM create_http_client CHANGING lv_http_client.

* Request and Get
PERFORM http_client_request_get_method USING lv_http_client.

* Send the request
PERFORM http_client_send USING lv_http_client.

* Retrieve the result
PERFORM http_client_receive USING lv_http_client CHANGING lv_content.

* Get the actual coordinate using the content string
PERFORM get_coordinates USING lv_content.


ENDFORM. " get_long_lat
*&---------------------------------------------------------------------*
*& Form CREATE_HTTP_CLIENT
*&---------------------------------------------------------------------*
* Create HTTP Client
*----------------------------------------------------------------------*
FORM create_http_client CHANGING p_http_client TYPE REF TO if_http_client.

DATA: lv_http_url TYPE string.

* Prepare the url of the address
CONCATENATE
'http://maps.google.com/maps/api/geocode/xml?address='
p_add_f
INTO lv_http_url .

* Get client from url
CALL METHOD cl_http_client=>create_by_url
EXPORTING
url = lv_http_url
IMPORTING
client = p_http_client
EXCEPTIONS
argument_not_found = 1
plugin_not_active = 2
internal_error = 3
OTHERS = 4.

ENDFORM.
*&---------------------------------------------------------------------*
*& Form HTTP_CLIENT_REQUEST_GET_METHOD
*&---------------------------------------------------------------------*
* Request and Get Method
*----------------------------------------------------------------------*
FORM http_client_request_get_method USING p_http_client TYPE REF TO if_http_client..
* Request and Get
p_http_client->request->set_header_field( name = '~request_method' value = 'GET' ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form HTTP_CLIENT_SEND
*&---------------------------------------------------------------------*
* Send request
*----------------------------------------------------------------------*
FORM http_client_send USING p_http_client TYPE REF TO if_http_client.
* Send the request
p_http_client->send( ).
ENDFORM.
*&---------------------------------------------------------------------*
*& Form HTTP_CLIENT_RECEIVE
*&---------------------------------------------------------------------*
* Get the string content
*----------------------------------------------------------------------*
FORM http_client_receive USING p_http_client TYPE REF TO if_http_client
CHANGING p_p_content TYPE string.
* Reterive the result
CALL METHOD p_http_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
p_p_content = p_http_client->response->get_cdata( ).

ENDFORM.
*&---------------------------------------------------------------------*
*& Form GET_COORDINATES
*&---------------------------------------------------------------------*
* Get Latitute Longitude Coordinate
*----------------------------------------------------------------------*
FORM get_coordinates USING p_p_content TYPE string.

* Local data declaration
DATA: lv_url TYPE c LENGTH 255,
ls_dest TYPE ty_dest,
moff TYPE syst-tabix,
moff1 TYPE syst-tabix,
lv_len TYPE syst-tabix,
lv_lat TYPE c LENGTH 20,
lv_lng TYPE c LENGTH 20.

*&---------------------------------------------------------------------*
*& Processing string
*&---------------------------------------------------------------------*
DO .
* Find <location> text in the content string
FIND '<location>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff .

IF sy-subrc = 0 .
* <location> is a 10 character string, hence adding 10
moff = moff + 10 .

* Find closing tag </location> text in the content string
FIND '</location>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff1 .

* Find the length of string between tag <location> and </location>
lv_len = moff1 - moff .

* We have seen the API string contet, so we know <lat> </lat> <lng> </lng> are there between
* <location> and </location>
*--------------------------------------------------------------------*
* ---------------Find latitude
*--------------------------------------------------------------------*
* Find string <lat>
FIND '<lat>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff .
IF sy-subrc = 0 .
* <lat> is a 5 character string, hence adding 5
moff = moff + 5 .

* Find closing tag </lat> text in the content string
FIND '</lat>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff1 .

* Find the length of string between tag <lat> and </lat>
lv_len = moff1 - moff .

* Characters between <lat> </lat> will have the latitude coorniate
lv_lat = p_p_content+moff(lv_len) .

* From place address
ls_dest-place_f = p_add_f .

* Keep latitude in structure
ls_dest-lat_f = lv_lat.

ENDIF.

*--------------------------------------------------------------------*
* ---------------Find longitude
*--------------------------------------------------------------------*
* Find string <lng>
FIND '<lng>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff .
IF sy-subrc = 0 .

* <lng> is a 5 character string, hence adding 5
moff = moff + 5 .

* Find closing tag </lng> text in the content string
FIND '</lng>' IN SECTION OFFSET moff OF p_p_content IGNORING CASE MATCH OFFSET moff1 .

* Find the length of string between tag <lng> and </lng>
lv_len = moff1 - moff .

* Characters between <lng> </lng> will have the latitude coorniate
lv_lng = p_p_content+moff(lv_len) .

* Keep longitude in structure
ls_dest-lng_f = lv_lng.

ENDIF.
ELSE.

EXIT.

ENDIF.

ENDDO .

* Put in internal table to display later
APPEND ls_dest TO gt_dest.
CLEAR:ls_dest .

ENDFORM.
*&---------------------------------------------------------------------*
*& Form DISPLAY_LAT_LONGITUDE
*&---------------------------------------------------------------------*
* Display Latitude and Longitude
*----------------------------------------------------------------------*
FORM display_lat_longitude .

DATA:
lr_alv TYPE REF TO cl_salv_table,
lr_columns TYPE REF TO cl_salv_columns_table,
lr_column TYPE REF TO cl_salv_column,
lr_functions TYPE REF TO cl_salv_functions_list,
lr_display TYPE REF TO cl_salv_display_settings,
lr_layout TYPE REF TO cl_salv_layout,
ls_key TYPE salv_s_layout_key,
lr_sorts TYPE REF TO cl_salv_sorts.

" Check to make sure the internal table has data.
IF lines( gt_dest ) > 0.

TRY.
* Create ALV instance
* Use CALL METHOD since this is a static method
CALL METHOD cl_salv_table=>factory
IMPORTING
r_salv_table = lr_alv
CHANGING
t_table = gt_dest.

* Get functions object and then set all the functions to be allowed
lr_functions = lr_alv->get_functions( ).
lr_functions->set_all( ).

lr_columns = lr_alv->get_columns( ).

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'PLACE_F'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'Place Name'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'LAT_F'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'Latitude'.

CALL METHOD lr_columns->get_column
EXPORTING
columnname = 'LNG_F'
RECEIVING
value = lr_column.
CALL METHOD lr_column->set_short_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_medium_text
EXPORTING
value = ''.
CALL METHOD lr_column->set_long_text
EXPORTING
value = 'Longitude'.


lr_columns->set_optimize( ).

* Set sort column
lr_sorts = lr_alv->get_sorts( ).
lr_sorts->clear( ).

* This code is to get the layout, save the layout and display the layout
lr_layout = lr_alv->get_layout( ).
ls_key-report = sy-repid.
lr_layout->set_key( ls_key ).
lr_layout->set_default( ' ' ).
lr_layout->set_save_restriction( cl_salv_layout=>restrict_none ).


lr_display = lr_alv->get_display_settings( ).
lr_display->set_striped_pattern( cl_salv_display_settings=>true ).

* Now display the report as an ALV grid
lr_alv->display( ).

CATCH cx_salv_msg.
WRITE: 'Error displaying grid CX_SALV_MSG!'(001).

CATCH cx_salv_not_found.
WRITE: 'Error displaying grid CX_SALV_NOT_FOUND!'(002).

CATCH cx_salv_data_error.
WRITE: 'Error displaying grid CX_SALV_DATA_ERROR!'(003).

CATCH cx_salv_existing.
WRITE: 'Error displaying grid CX_SALV_EXISTING!'(004).

ENDTRY.

ELSE.
MESSAGE 'No data to display' TYPE 'I'.
LEAVE LIST-PROCESSING.

ENDIF.


ENDFORM.

If you have any desire to get such viable issues and goals directly to your inbox, kindly Buy in. We regard your security and treat safeguarding it in a serious way.

YOU MAY LIKE THIS

Building APIs with SAP Tools and Technologies

A Deep Dive into the SAP API Hub

API Documentation: A Comprehensive Guide to Seamless Integration

API Integration: Bridging the Digital Divide

SAP

How to Show the ALV Output and the Selection Screen on the Same Screen?

How to Show the ALV Output and the Selection Screen on the same Screen? Typically the ALV yield is shown in another screen. Not on a similar screen where you have the choice boundaries and select choices. In any case, at times client need to see what they input in the screen and what they get yield in the ALV in a similar screen. It simply assists them with performing better, report better and break down better. This prerequisite and situation isn’t new. We have answer for it from in those days in 2008.

On the off chance that the arrangement is as of now there, why again another article?

 The previous arrangement gave utilizes SALV class “CL_SALV_TABLE”. We will utilize “CL_GUI_ALV_GRID” class because of its upgraded highlights.

Expectations (How to Show the ALV Output and the Selection Screen on the same Screen)

  1. Choice Screen and ALV on A similar Screen.
  2. Add a Button on the ALV Toolbar.
  3. Handle Client Order.

For additional data on the use and working of the class CL_GUI_ALV_GRID, you can allude to the demo programs gave by SAP the name like “BCALV_GRID* “.

Sample programs provided by SAP on the usage of CL_GUI_ALV_GRID.

Output (How to Show the ALV Output and the Selection Screen on the same Screen)

Simple Selection Screen with one Select-Options S_CARRID of type SFLIGHT-CARRID

Below is the Final Output which the Client is Expecting.

Selection screen and ALV on same screen

Let’s Design

High Level Programming Paradigm:

All in all, pseudo code for this necessity.

  1. The docking holder should be made in the introduction occasion.
  2. ALV should be made on that docking holder.
  3. Trade the Chose Result Table Information to ABAP Memory (this part we could do without. Yet, till we track down an improved arrangement, we should utilize it).
  4. Import information from ABAP Memory and Produce the Result.

Global Data Declarations

CLASS lcl_report DEFINITION DEFERRED.
DATA: lo_report TYPE REF TO lcl_report. "Reference object of the local class
DATA: alv_container TYPE REF TO cl_gui_docking_container, "ALV Container
      alv_grid      TYPE REF TO cl_gui_alv_grid,          "ALV Grid
      layout        TYPE lvc_s_layo.                      "Layout Options               
DATA gv_carrid TYPE sflight-carrid. "Variable for Select-options declaration.

Selection Screen Declarations

SELECTION-SCREEN: BEGIN OF BLOCK block_1 WITH FRAME TITLE text-001.
SELECT-OPTIONS: s_carrid FOR gv_carrid.
SELECTION-SCREEN: END   OF BLOCK block_1.

Local Class Definition

CLASS lcl_report DEFINITION .

  PUBLIC SECTION.
    DATA: gt_data TYPE STANDARD TABLE OF sflight.
    METHODS :
      get_data,
      generate_output,
      toolbar      FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING e_object, "To add some buttons on the ALV toolbar
      user_command FOR EVENT user_command OF cl_gui_alv_grid
        IMPORTING e_ucomm.

ENDCLASS.

Local Class Implementation

  • Method: GET_DATA
CLASS lcl_report IMPLEMENTATION.
  "Method Get Data
  METHOD get_data.
*   data selection
    SELECT * FROM sflight
           INTO  TABLE me->gt_data
           WHERE carrid IN s_carrid.
    IF sy-dbcnt IS INITIAL.
      MESSAGE s398(00) WITH 'No data selected'.
    ENDIF.
*
*   Export to memory
    EXPORT data = me->gt_data TO MEMORY ID sy-cprog.
  ENDMETHOD.
  • Method: GENERATE_OUTPUT
"Method generate_output
  METHOD generate_output.
*   Local data
    DATA: variant TYPE  disvariant.
    DATA: repid   TYPE sy-repid.

*   Import output table from the memory and free afterwards
    IMPORT data = me->gt_data FROM MEMORY ID sy-cprog.
    FREE MEMORY ID sy-cprog.
*
*   Only if there is some data
    CHECK me->gt_data IS NOT INITIAL.

    repid = sy-repid.
    variant-report = sy-repid.
    variant-username = sy-uname.
    layout-zebra = 'X'.

    CHECK alv_container IS INITIAL.
    CREATE OBJECT alv_container
      EXPORTING
        repid     = repid
        dynnr     = sy-dynnr
        side      = alv_container->dock_at_bottom
        extension = 200.
    CREATE OBJECT alv_grid
      EXPORTING
        i_parent = alv_container.
*  ALV Specific. Data selection.
    SET HANDLER : lo_report->toolbar      FOR alv_grid.
    SET HANDLER : lo_report->user_command FOR alv_grid.
    CALL METHOD alv_grid->set_table_for_first_display
      EXPORTING
        is_layout        = layout
        is_variant       = variant
        i_save           = 'U'
        i_structure_name = 'SFLIGHT'
      CHANGING
        it_outtab        = me->gt_data.

  ENDMETHOD.
  • Method: TOOLBAR

In this technique, we will make one press button (similarly as an illustration of no usefulness), for instance, to save a record, on the off chance that we had made this ALV as editable.

"Method Tool-bar
  METHOD toolbar.
    DATA: lv_toolbar TYPE stb_button.

* Push Button "For Example SAVE
    CLEAR lv_toolbar.
    MOVE 'FC_SAVE' TO lv_toolbar-function. "Function Code
    lv_toolbar-icon = icon_system_save.    "Save Icon
    MOVE 'Save'(100) TO lv_toolbar-text.   "Push button Text
    MOVE 'Save'(100) TO lv_toolbar-quickinfo. "Push button Quick-Info
    MOVE space TO lv_toolbar-disabled. "Push button enabled
    APPEND lv_toolbar TO e_object->mt_toolbar.
  ENDMETHOD. 
  • Method: USER_COMMAND

This strategy will be utilized to deal with every one of the orders given by the client, for instance assuming client push on the Save button we made above, and so on. I have kept this segment as clear, you can add the rationale as required.

"Method User_command
  METHOD user_command.
    IF e_ucomm = ' '.

    ENDIF.
  ENDMETHOD.                    "USER_COMMAND

ENDCLASS.                    "lcl_report IMPLEMENTATION

In the event that you set the breakpoint at the above strategy and press the Save button on the ALV, the execution will stop. Kindly check the underneath screen capture:

User Command captured when clicked on “Save” button.

Finally, the Events of the program execution

INITIALIZATION.
* object for the report
  CREATE OBJECT lo_report.
* generate output
  lo_report->generate_output( ).

START-OF-SELECTION.
* Get data
  lo_report->get_data( ).

Conclusion

In this blog entry we took in the nuts and bolts of making an ALV on the determination screen with the utilization of CL_GUI_ALV_GRID class.

On the off chance that you simply duplicate the above code scraps and glue it to your SE38 supervisor and actuate it. Very much like one of our sluggish editors. You will find the result like underneath. Indeed!! It is a functioning code. What’s more, you don’t have to configure any screen components.

For what reason did we have to utilize ABAP Memory when all information is there in the program and we are showing them in a similar program?

At the point when the program control arrives at the introduction occasion, all memory is invigorated and worldwide information is made FREE. After all everything ought to be instated in the introduction occasion. That is the occupation of the introduction occasion. Thusly, we must have the ALV information someplace to pull it back when we are in Instatement occasion. Presently you know why we had to take help of the ABAP Memory. 

YOU MAY BE INTERESTED IN

Call instance method from workflow using class

Using ABAP Classes in Workflow

Best Practices for SAP Cloud Platform Development: A Comprehensive Guide

Leveraging SAP HANA for Advanced Analytics

SAP ABAP Training Institute in Pune, SAP ABAP Courses Online

SAP

Selective Handling of the Buttons in ALV Grid Toolbar

By and large, on the off chance that the necessity is to eliminate the entire ALV framework toolbar, it’s quite simple as it requires setting one field (no_toolbar) in format as ‘X’. Let’s dive into the Selective Handling of the Buttons in ALV Grid Toolbar.

ALV Toolbars

Setting the no_toolbar would give the result as beneath. Kindly check, there is NO Toolbar in the ALV Result.

No Toolbar in ALV Report

We can pass this design as bringing in boundary for strategy ‘set_table_for_first_display’.

Be that as it may, in the event of Article Arranged ALV, debilitating a few fastens and empowering some can get bit precarious.

The objective of this article is to give a comprehensive picture with regards to meeting this prerequisite and sort of make it a solitary complete perspective for all engineers who need some assistance on this point.

As displayed above, in design, there is a field to eliminate the entire toolbar and we have no simple method for handicapping only a couple of buttons from the toolbar list. Selective Handling of the Buttons in ALV Grid Toolbar.

However, every time it isn’t 1 or 0 100% of the time. Here and there, we really want a center way.

Handicapping of a portion of the buttons is a greater amount of the genuine prerequisite you will get in execution projects as ALV network toolbar is an exceptionally useful asset to use it for capabilities like arranging, sifting, trading information to yield and so on.

Yet, how to accomplish it?

OK!!! So the response to this is Occasion Controllers. That’s it!!! Presently on the off chance that you are a novice to Drain Improvement, the occasion overseer is finished in ALV report advancements. In this article, we will attempt to make sense of the ideas and subtleties of occasion overseers however much as could be expected so that regardless of whether you are a fresher, you ought to have the option to figure out it and effectively execute it.

On a significant level, this execution can be isolated into underneath steps:

Making of ALV Framework, Compartment (This item will be alluded from standard kinds given by SAP) and Occasion overseer protests (This article will allude to nearby class).

Meaning of Occasion Overseer class with the technique to deal with toolbar.

Execution of the strategy.

Setting of the occasion controller and its setting off components.

The primary arrangement is there in sync four so we will cover that at the last. Just to ensure you read the total article and figure out the general picture.

Presently prior to going any additionally we should initially get our ideas clear about occasions overseers.

Occasion overseers are strategies which get called once their separate occasions are set off.

This setting off should be possible by means of programming utilizing “raise_event” strategy for the network.

In the first place, we will make matrix variable concerning cl_gui_alv_grid. We would likewise require a compartment to consume this framework.

You can also read for: ABAP for SAP HANA. ALV Report On SAP HANA – Opportunities And Challenges

DATA :  gref_alvgrid TYPE REF TO cl_gui_alv_grid ,              
gref_ccontainer TYPE REF TO cl_gui_custom_container .

Once this is done we need to do the object creation.

*----Creating custom container instance
    CREATE OBJECT gref_ccontainer 
      EXPORTING
        container_name              = con_custom_control_name
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6.
    IF sy-subrc <> 0.
*--Exception handling
    ENDIF.
*   checking instance existence, creating instance, setting for first display and refreshing
*----Creating ALV Grid instance
    CREATE OBJECT gref_alvgrid
      EXPORTING
        i_parent          = gref_ccontainer
      EXCEPTIONS
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        OTHERS            = 5.
    IF sy-subrc <> 0
*--Exception handling
    ENDIF.

Now for event handling, we will create a local class lcl_event_handler in the program.

DATA gref_event_handler TYPE REF TO lcl_event_handler .

In the beneath neighborhood class we can make a technique that will deal with our toolbar handling. We acquainted two additional techniques purposefully with further explain our idea about occasion controllers.

Event Handler Class

Presently prior to going for execution, we will likewise perceive how we can set overseers for this strategy.

Set Event Handler
ucomm in sap

As referenced, to raise an occasion, we will set off occasions utilizing ‘raise_event’ strategy which will call handle_user_command from our neighborhood controller class. Further handling should be possible in this technique execution utilizing ‘ucomm’ boundary.

Aside from bringing the occasion up in our program with above strategy, a few unexpected occasions are remembered for standard SAP class CL_GUI_ALV_GRID.

Class CL_GUI_ALV_GRID will set off an occasion for toolbar inside through technique ‘SET_TABLE_FOR_FIRST_DISPLAY’ and we will deal with that brought occasion up in our nearby class strategy execution.

To show records in ALV we use strategy ‘SET_TABLE_FOR_FIRST_DISPLAY’ which calls technique ‘REFRESH_TABLE_DISPLAY’ which thusly calls strategy ‘SOFT_REFRESH_TABLE_DISPLAY’ that further calls strategy ‘SET_TOOLBAR’. This SET_TOOLBAR raises the occasion for toolbar taking care of.

We will deal with this occasion through our custom strategy.

Handle_toolbar strategy as e_object as bringing in boundary. Network toolbar data gets put away in table ‘e_object->mt_toolbar’. This data incorporates Capability, Symbol, Data, Kind of button, Cripple Banner and so on.

To handicap the button it is expected to alter this table ‘e_object->mt_toolbar’ with Cripple Banner with ‘X’. Comparatively to empower button which is crippled by Framework, this banner should be reset.

In beneath technique, we are handicapping not many buttons as well as empowering one button which was debilitating as a matter of course in the framework. Sections of this table will seem to be this.

disable toolbar buttons

Every one of the buttons with their data get put away in table ‘e_object->mt_toolbar’ as displayed underneath.

The end-product will look something like this.

In the event that you are a novice, underneath is the bit by bit process for you.

  1. Create a program in t-code SE38.

Go to t-code SE80 and create a Screen. (Selective Handling of the Buttons in ALV Grid Toolbar)

create a Screen

Give the screen number.

Give a description and hit the Layout.

Click on the Custom Control and drag it across to the layout. (Selective Handling of the Buttons in ALV Grid Toolbar)

how to create custom control in ALV

Give the Custom Control some name. We give it the name as CC_ALV. This name would be utilized in the program.

how to create custom control in ALV

In the program, we have given similar name to customs control.

This finishes the screen and customs control plan. Presently we want to compose our program to deal with it.

Use the below program (at the bottom of this article) and activate your code.

Let’s test it.

OOPs.. we get no output.

What did we miss?

Since your ALV Custom Holder showed nothing. Let us take a quick trip and see the PBO PAI screen.

Uncomment the PBO and PAI modules and retest.

OOPs, again no output.

What did we miss now?

On the off chance that you take a gander at the program intently, the MODULE Show has not yet been characterized in that frame of mind on the screen.

Go to the screen and add the Presentation module in PBO.

Presently test it one final time. At last, you can see the ALV yield.

If you have any desire to analyze, when Occasion Overseers, you would see the underneath distinction.

Trust this article was adequately clear to explain how to utilize custom regulators and compartments. You currently know how to utilize the occasion controllers. Likewise, it ought to have given you enough knowledge to deal with the device bar fastens unequivocally.

Complete Code Snippet.

*&---------------------------------------------------------------------*
*& Program to show ALV Grid Display with Some Toolbar buttons disabled *
*&---------------------------------------------------------------------*
REPORT ztest_alv_grid_test NO STANDARD PAGE HEADING
                  LINE-SIZE  132
                  LINE-COUNT 65.
*--------------------------------------------------------------------*
* Tables
*--------------------------------------------------------------------*
TABLES : mara.
*--------------------------------------------------------------------*
* Types
*--------------------------------------------------------------------*
TYPES : BEGIN OF tty_mara,
          matnr TYPE matnr,
          ernam TYPE ernam,
          mtart TYPE mtart,
          matkl TYPE matkl,
        END OF tty_mara.
*--------------------------------------------------------------------*
* Data
*--------------------------------------------------------------------*
DATA : g_tab_mara TYPE STANDARD TABLE OF tty_mara.
*--- Object for ALV grid
DATA gref_alvgrid TYPE REF TO cl_gui_alv_grid .
*--- Object for Custom container
DATA gref_ccontainer TYPE REF TO cl_gui_custom_container .
*--- Name of the custom control added on the screen
CONSTANTS con_custom_control_name TYPE scrfname VALUE 'CC_ALV'.
*--- Field catalog
DATA g_tab_fieldcat TYPE lvc_t_fcat .
*--- Field catalog structure
DATA g_wa_fieldcat TYPE lvc_s_fcat .
*----Layout
DATA g_str_layout TYPE lvc_s_layo.
*--- Event handler class
CLASS lcl_event_handler DEFINITION DEFERRED.
*--- Object for Event Handler
DATA gref_event_handler TYPE REF TO lcl_event_handler .
*--------------------------------------------------------------------*
* Local Class Definition for Event Handler
*--------------------------------------------------------------------*
CLASS lcl_event_handler DEFINITION .
  PUBLIC SECTION .
    CLASS-DATA alv_err TYPE subrc.
    METHODS
*     Event handler for toolbar in alvgrid.
      handle_toolbar
                    FOR EVENT toolbar OF cl_gui_alv_grid
        IMPORTING e_object.
ENDCLASS.
*--------------------------------------------------------------------*
* Local Class Implementation for Event Handler
*--------------------------------------------------------------------*
CLASS lcl_event_handler IMPLEMENTATION .
* Method for toolbar handling
  METHOD handle_toolbar.

    DATA : l_wa_toolbar TYPE stb_button.

*   Disabling some Buttons
    MOVE 'X' TO l_wa_toolbar-disabled.
*   This sets the data
    MODIFY e_object->mt_toolbar FROM l_wa_toolbar TRANSPORTING disabled
    WHERE function = '&DETAIL' OR function = '&MB_SUM' OR function = '&MB_VIEW'
    OR function = '&MB_SUBTOT' OR function = '&PRINT_BACK' OR function = '&COL0'
    OR function = '&GRAPH' OR function = '&INFO' OR function = '&REFRESH'
    OR function = '&LOCAL&CUT' OR function = '&LOCAL&COPY' OR function = '&LOCAL&PASTE'
    OR function = '&LOCAL&UNDO' OR function = '&LOCAL&APPEND' OR function = '&LOCAL&INSERT_ROW'
    OR function = '&LOCAL&DELETE_ROW' OR function = '&LOCAL&COPY_ROW' .

*   Enabling some Buttons
    MOVE ' ' TO l_wa_toolbar-disabled.
*   This sets the data
    MODIFY e_object->mt_toolbar FROM l_wa_toolbar TRANSPORTING disabled
    WHERE function = '&FIND_MORE'.

  ENDMETHOD.                    "handle_toolbar
ENDCLASS .

*--------------------------------------------------------------------*
* Selection Screen
*--------------------------------------------------------------------*
SELECTION-SCREEN BEGIN OF BLOCK bm WITH FRAME TITLE text-001.
SELECT-OPTIONS : s_matnr FOR mara-matnr.
SELECTION-SCREEN END OF BLOCK bm.

*--------------------------------------------------------------------*
* Start of Selection
*--------------------------------------------------------------------*
START-OF-SELECTION.
* Fetch data
  PERFORM get_testdatafordisplay.

*--------------------------------------------------------------------*
* End of Selection
*--------------------------------------------------------------------*
END-OF-SELECTION.
* Field Catalog
  PERFORM create_fieldcat CHANGING g_tab_fieldcat.
* Layout
  PERFORM create_layout CHANGING g_str_layout.
* Display Report
  PERFORM display_report.

*&---------------------------------------------------------------------*
*&      Form  GET_TESTDATAFORDISPLAY
*&---------------------------------------------------------------------*
FORM get_testdatafordisplay .
  SELECT matnr ernam mtart matkl
    FROM mara
  INTO CORRESPONDING FIELDS OF TABLE g_tab_mara
  WHERE matnr IN s_matnr  .
ENDFORM.                    " GET_TESTDATAFORDISPLAY
*&---------------------------------------------------------------------*
*&      Form  CREATE_FIELDCAT
*&---------------------------------------------------------------------*
FORM create_fieldcat CHANGING c_tab_fieldcat TYPE lvc_t_fcat.
  DATA : ls_fcat TYPE lvc_s_fcat.
  ls_fcat-col_pos = 0.
  ls_fcat-fieldname = 'MATNR'.
  ls_fcat-coltext = 'Material Number'.
  ls_fcat-seltext = 'Material Number'.
  ls_fcat-col_opt = 'X'.
  APPEND ls_fcat TO c_tab_fieldcat.
  ls_fcat-col_pos = 1.
  ls_fcat-fieldname = 'ERNAM'.
  ls_fcat-coltext = 'Created By'.
  ls_fcat-seltext = 'Created By'.
  ls_fcat-col_opt = 'X'.
  APPEND ls_fcat TO c_tab_fieldcat.
  ls_fcat-col_pos = 2.
  ls_fcat-fieldname = 'MTART'.
  ls_fcat-coltext = 'Material Type'.
  ls_fcat-seltext = 'Material Type'.
  ls_fcat-col_opt = 'X'.
  APPEND ls_fcat TO c_tab_fieldcat.
  ls_fcat-col_pos = 3.
  ls_fcat-fieldname = 'MATKL'.
  ls_fcat-coltext = 'Material Group'.
  ls_fcat-seltext = 'Material Group'.
  ls_fcat-col_opt = 'X'.
  APPEND ls_fcat TO c_tab_fieldcat.
ENDFORM.                    " CREATE_FIELDCAT
*&---------------------------------------------------------------------*
*&      Form  CREATE_LAYOUT
*&---------------------------------------------------------------------*
FORM create_layout CHANGING c_str_layout TYPE lvc_s_layo..
*  c_str_layout-no_toolbar = 'X'.
ENDFORM.                    " CREATE_LAYOUT

*&---------------------------------------------------------------------*
*&      Form  DISPLAY_REPORT
*&---------------------------------------------------------------------*
FORM display_report .
  CALL SCREEN 100.
ENDFORM.                    " DISPLAY_REPORT
*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100 INPUT
*&---------------------------------------------------------------------*
MODULE user_command_0100 INPUT.
  DATA: l_var_valid      TYPE c,
        l_selected_cells TYPE STANDARD TABLE OF lvc_s_cell.

  CALL METHOD gref_alvgrid->check_changed_data
    IMPORTING
      e_valid = l_var_valid.

  CALL METHOD gref_alvgrid->get_selected_cells
    IMPORTING
      et_cell = l_selected_cells.

  CASE sy-ucomm.
    WHEN 'EXIT' OR 'ENDE' or 'ECAN'.
      LEAVE PROGRAM.
    WHEN 'BACK' OR 'E'.
      LEAVE TO SCREEN 0.
    WHEN 'INS'.
      CALL METHOD gref_alvgrid->raise_event
        EXPORTING
          i_ucomm = 'INS'.
    WHEN 'DELETE'.

    WHEN OTHERS.
  ENDCASE.

ENDMODULE.                 " DISPLAY  OUTPUT
*&---------------------------------------------------------------------*
*&      Module  DISPLAY  OUTPUT
*&---------------------------------------------------------------------*
MODULE display OUTPUT.
  PERFORM display_test_alv.
ENDMODULE.                 " DISPLAY  OUTPUT
*&---------------------------------------------------------------------*
*&      Form  DISPLAY_TEST_ALV
*&---------------------------------------------------------------------*
FORM display_test_alv .
  IF gref_alvgrid IS INITIAL .
*----Creating custom container instance
    CREATE OBJECT gref_ccontainer
      EXPORTING
        container_name              = con_custom_control_name
      EXCEPTIONS
        cntl_error                  = 1
        cntl_system_error           = 2
        create_error                = 3
        lifetime_error              = 4
        lifetime_dynpro_dynpro_link = 5
        OTHERS                      = 6.
    IF sy-subrc <> 0.
*--Exception handling
    ENDIF.
*   checking instance existence, creating instance, setting for first display and refreshing
*----Creating ALV Grid instance
    CREATE OBJECT gref_alvgrid
      EXPORTING
        i_parent          = gref_ccontainer
      EXCEPTIONS
        error_cntl_create = 1
        error_cntl_init   = 2
        error_cntl_link   = 3
        error_dp_create   = 4
        OTHERS            = 5.
    IF sy-subrc <> 0.
*--Exception handling
    ENDIF.
*--Creating an instance for the event handler
    CREATE OBJECT gref_event_handler.
    SET HANDLER gref_event_handler->handle_toolbar FOR gref_alvgrid .

    CALL METHOD gref_alvgrid->set_table_for_first_display
      EXPORTING
        is_layout                     = g_str_layout
      CHANGING
        it_outtab                     = g_tab_mara
        it_fieldcatalog               = g_tab_fieldcat
      EXCEPTIONS
        invalid_parameter_combination = 1
        program_error                 = 2
        too_many_lines                = 3
        OTHERS                        = 4.
  ENDIF.
ENDFORM.                    " DISPLAY_TEST_ALV

YOU MAY LIKE THIS

What Companies Use SAP Software in India

AI and Machine Learning in SAP: A Practical Guide

Top SAP ABAP Reports Interview Questions: Be Prepared

Courses For Sap ABAP On HANA Training

SAP

ABAP for SAP HANA. ALV Report On SAP HANA – Opportunities And Challenges

ALV Report On SAP HANA

Let’s dive into the ALV Report On SAP HANA – Opportunities And Challenges. The HANA Tempest has been clearing everybody away. As of September 2017, SAP report guaranteed there were in excess of 1000 Clients currently live on S/4HANA. So tomorrow while possibly not today, all Professionals chipping away at SAP would need to swim through the HANA waters. Reducing the SAP Professionals to ABAPer, who program ALV Reports each and every other week. Have you thought about how fortunate or unfortunate it tends to be to plan an ALV in SAP with HANA as Suite as well as Data set? In this article, we would attempt to introduce stories from the two times, preceding HANA and in HANA.ALV Report On SAP HANA – Opportunities And Challenges!

ALV Reports are the Cockroaches of SAP world, which would survive every evolution.

Roots or Establishment or the Beginning point in ALV is same in HANA World as it was before in conventional data set, for example Choice SCREEN. Tragically, we will quite often make a few determinations when we see this. The screen needs to have checkboxes, radio buttons, choice screen blocks and so forth. This is miserable on the grounds that toward one side we see Fiori Platforms have dynamic and beautiful screens with applications upgrading Client Experience (UX) utilizing SAP UI5 and at the opposite end the customary ALV.

Rather cribbing about it, we want to recall that clients (actually) request ALV reports like standard T-Code yield for example ME2N (citing on the grounds that that was the prerequisite I got). Afterall everything isn’t about client experience. Complex business needs likewise get some weight.

Regardless, whether you are attempting to learn Fiori or SAPUI5, ALV reports can’t be supplanted. In this way, likewise begin investigating the new way you can make the ALVs.

How might we make our (ABAPers) lives merry and fascinating? Add HANA in with the general mish-mash and what you get is simpler to code (well not really) and all the more critically more prominent improvement in the exhibition.

The improvement in execution is exclusively credited to one thing that is the idea called “Code Push Down” or “Code to Information (Data set) Worldview”. Heard it anyplace? Try not to say No. We are at the twentieth part in our HANA ABAP Series.

What is Code Push Down? (ALV Report On SAP HANA – Opportunities And Challenges)

Here we have a tipping point. One can go for the strategy for utilizing Discs View alongside AMDP (if vital) or go with IDA. Utilizing IDA is much more straightforward than AMDP, yet possibly one can’t be a swap for the other. They play their own parts to play. In the following article, I will cover the distinctions and benefits of IDA against Albums.

Prior to looking down it would be smart to discover somewhat more about AMDP (ABAP Oversaw Data set System) and IDA (Coordinated Information Access).

So for ALV in HANA, we have the accompanying:

  1. Selection Screen
  2. Data is ready in CDS +/- AMDP

What next? Just connect them.

3. Applying selection screen criteria into CDS view entries.

The third step is a piece precarious. We again have various open doors here.

3.1 Either pass all the determination screen channels into AMDP ( NOT Compact discs View as a result of the way that Cds Perspectives are defined and can’t take more than one incentive for a solitary field and choice screen of the ALV report has select choices which are in range tables)

OR

3.2 Get every one of the passages from Compact discs View into your Application Layer and afterward continue with regular coding practice.

At this point, experienced ABAPers would agree that that first methodology (AMDP) would do every one of the positive qualities regarding execution.

Now we have narrowed down to:

  1. Choice Screen
  2. Information is prepared in Discs +/ – AMDP
  3. Applying choice screen measures into Discs view sections utilizing AMDP and bringing just required passages into AS layer and continuing with regular SALV manufacturing plant class utilizing Oh no.

You can also read for:- OOPs Report Using Splitter and ALV Tree Combination

Technical Points:

  1. Conversion of SELECT-OPTIONS into Dynamic “WHERE CLAUSE”: When the standard determination screen is constructed, the main obstacle is incorporate the select choices into AMDP. To accomplish that we have the accompanying code piece:
DATA(lv_where) = cl_shdb_seltab=>combine_seltabs(
it_named_seltabs = VALUE #(
( name = 'MATNR' dref = REF #( so_matnr[] ) )
( name = 'EBELN' dref = REF #( so_ebeln[] ) )
) ).

Trust you can grasp the above code. Else, the beneath elective for a similar activity can assist you with bettering.

cl_shdb_seltab=>combine_seltabs(
EXPORTING
it_named_seltabs = VALUE #(
( name = 'MATNR' dref = REF #( so_matnr[] ) )
( name = 'EBELN' dref = REF #( so_ebeln[] ) )
)
RECEIVING
rv_where = DATA(lv_where) ).

2. Using Dynamic where clause in AMDP: The following test is to utilize the where condition. There is an element in SAP AS 7.40 and higher of “APPLY Channel”. The lv_where statement worked above is passed to AMDP technique boundary ip_filters.

Conclusion: ALV Report On SAP HANA – Opportunities And Challenges

Making the most of HANA DB and HANA instruments like HANA Studio we enjoy following benefits ( opportunity ):

  1. Further developed Execution since there is Code Push Down and larger part of the Information bringing is finished at HANA DB alongside collections/total/midpoints.
  2. On the Fly powerful custom naming of the Result Fields in ALV [can be finished utilizing CDS].
  3. Dynamic SELECT questions in AMDP in light of the information given by Client and content put away in the DB [e.g. Assuming that in DB we have fields City and Country, we can utilize the CASE articulation to finish up assuming that input city given by the client is the capital or not].
  4. Dispose of FOR ALL Sections. [Use Internal Joins instead]. Did we simply get into another sticky situation?
  5. Can be extremely powerful for External Participate in situations where we really want to skirt the field esteems that are available in one table however NOT in other.

The opposite side of the story, challenges:

  • At the point when we go with Discs Perspectives to extricate information into AS layer, then, at that point, there might be still some presentation issues (despite the fact that Cds relics would in any case give great exhibitions, still some unacceptable utilization of Cds can blow up).

Kindly trust that the following article will get a brief look at the genuine code to exhibit all the abovementioned and IDA. Along these lines, if it’s not too much trouble, remain tuned and get yourself HANA-tized.

Now we want to hear from you.

Kindly leave your input, stories and speedy remarks beneath.

YOU MAY LIKE THIS

Auto Refresh ALV Using CL_GUI_TIMER

Courses For Sap ABAP On HANA Training

Oracle cloud for manufacturing

SAP ABAP Interview Questions Real time Expectations

SAP

Extensive Tips and Tricks for Interactive SAP ALV

Tips and Tricks for Interactive SAP ALV

In the wake of chipping away at various activities and utilizing intuitive ALV Uh oh ideas broadly, I considered drafting one record with some valuable data, which will assist each engineer with defeating the vast majority of the plan prerequisites in any intuitive ALV Report.

Do you be aware, you can Really take a look at the Consistency of an ALV with simply SHIFT + 2 RIGHT Snaps? Let’s dive into the Tips and Tricks for Interactive SAP ALV!

Allow us to begin our The present subject.

1. Create a Container in the screen, say ‘ALV_CONT’.

2. Create Reference Object for the Container:

CREATE OBJECT container_r
        EXPORTING
          container_name              = 'ALV_CONT'
        EXCEPTIONS
          cntl_error                  = 1
          cntl_system_error           = 2
          create_error                = 3
          lifetime_error              = 4
          lifetime_dynpro_dynpro_link = 5.

3. Create Reference Object for the ALV Grid as below:

CREATE OBJECT grid_r
          EXPORTING
            i_parent = container_r.

4. Define the ALV Layout as below:

gw_layout-cwidth_opt = abap_true.
gw_layout-zebra = abap_true.
gw_layout-sel_mode = ‘D’.

5. Populate the Field Catalog data for display as below:

lv_pos = lv_pos + 1.              “Position number
CLEAR wa_fieldcat.
wa_fieldcat-fieldname = 'BUKRS'.  "Company Code
wa_fieldcat-col_pos = lv_pos.
wa_fieldcat-ref_table = 'T001'.
APPEND wa_fieldcat TO gt_fieldcat.

5.1. For Field Editable:

wa_fieldcat-edit = abap_true.

Also read:- Introduction to ALV with an Editable Row

5.2. For field No Display in output:

wa_fieldcat-no_out = abap_true.   “Check for field display

5.3. For field display as a Checkbox:

wa_fieldcat-checkbox = abap_true.

5.4. For the field where customized F4-Help is required:

wa_fieldcat-f4availabl  = abap_true.

5.5. For the field where the Summation is required:

wa_fieldcat-do_sum = abap_true.

Moreover, the field in light of which summation will show up should be characterized as below(eg. ANLKL):

CLEAR li_sort.

lst_sort-fieldname = 'ANLKL'.

lst_sort-subtot = abap_true.

APPEND lst_sort TO li_sort

6. To Restrict Functions from ALV display:

lw_exclude = cl_gui_alv_grid=>mc_fc_check.
APPEND lw_exclude TO gt_exclude.
lw_exclude = cl_gui_alv_grid=>mc_fc_refresh.
APPEND lw_exclude TO gt_exclude.
lw_exclude = cl_gui_alv_grid=>mc_fc_loc_copy_row.
APPEND lw_exclude TO gt_exclude.
lw_exclude = cl_gui_alv_grid=>mc_fc_loc_delete_row.
APPEND lw_exclude TO gt_exclude.
lw_exclude = cl_gui_alv_grid=>mc_fc_loc_append_row.
APPEND lw_exclude TO gt_exclude.
lw_exclude = cl_gui_alv_grid=>mc_fc_loc_insert_row.
APPEND lw_exclude TO gt_exclude.

7. Populate the Data in table GT_DATA.

8. Call the method set_table_for_first_display for Display of data.

CALL METHOD grid_r->set_table_for_first_display
EXPORTING
i_structure_name     = 'ZFI_S_PIS'  “Structure
is_layout            = gw_layout
it_toolbar_excluding = gt_exclude
i_save               = gc_save_a   "A
i_default            = abap_true
CHANGING
it_outtab            = gt_data[]     “Table with ALV data

It_sort              = li_sort
it_fieldcatalog      = gt_fieldcat[].
CALL METHOD cl_gui_control=>set_focus
EXPORTING
control = grid_r.

Data declaration for Reference:

Data:

container_r TYPE REF TO cl_gui_custom_container,      "Container for ALV PIS data

grid_r TYPE REF TO cl_gui_alv_grid,                                "Grid for ALV PIS data

gt_exclude TYPE ui_functions,                                            "Exclude functions from ALV

gt_fieldcat TYPE lvc_t_fcat,                                                "Field catalog for ALV PIS data

ref_aplic TYPE REF TO lcl_application_alv,

gw_layout   TYPE lvc_s_layo.                                              "Layout for PIS

9. If the Data just needs to be Refreshed:

CALL METHOD grid_r->refresh_table_display
EXCEPTIONS
finished = 1
OTHERS   = 2.

10. To make fields Editable, call the below method while calling ALV for display:

CALL METHOD grid_r->register_edit_event
EXPORTING
i_event_id = cl_gui_alv_grid=>mc_evt_modified.  " enter.  "MC_EVT_MODIFIED

11. Now to Validate the Data Changed in the grid we need to do the following:

11.1. Define a class (lcl_application_alv) definition and implementation and define event (handle_data_changed) for event data_changed of class cl_gui_alv_grid in it.

CLASS lcl_application_alv DEFINITION.
PUBLIC SECTION.
METHODS:
handle_data_changed
FOR EVENT data_changed OF cl_gui_alv_grid
IMPORTING er_data_changed e_onf4_after.
ENDCLASS.                    "lcl_application_alv DEFINITION

11.2. In method handle_data_changed call methods get_cell_value and modify_cell to get and modify cell values like below –

LOOP AT er_data_changed->mt_good_cells INTO lw_good.

WHEN 'KUNNR'.
CALL METHOD er_data_changed->get_cell_value
EXPORTING
i_row_id    = lw_good-row_id
i_fieldname = lw_good-fieldname
IMPORTING
e_value     = gv_kunnr.
*     Get name1 for the kunnr
SELECT SINGLE name1 FROM kna1
INTO lw_pis-name1
WHERE kunnr = gv_kunnr .
IF sy-subrc = 0.
*              update name1 in table
CALL METHOD er_data_changed->modify_cell
EXPORTING
i_row_id    = lw_good-row_id
i_fieldname = 'NAME1'
i_value     = lv_name1.
ELSE.
MESSAGE i000 WITH 'Invalid Customer number in row'(027)
lw_good-row_id.
ENDIF.

12. Now before calling method set_table_for_first_display, write the below code:

CREATE OBJECT ref_aplic.
SET HANDLER ref_aplic->handle_data_changed FOR grid_r.

13. Assuming that the Field Inventory is expected to change when various activities are executed for the ALV lattice information show, call strategy set_frontend_fieldcatalog subsequent to populating the field index information to revive the field list settings.

CALL METHOD grid_r->set_frontend_fieldcatalog
EXPORTING
it_fieldcatalog = gt_fieldcat[].

14. In the event that Contingent F4 Help is expected to be populated in the ALV, express in view of one information in ALV, another field F4-Help information should be populated then do the accompanying:

14.1. Prior to calling strategy set_table_for_first_display, we need to Enlist the fields we need to have the tweaked F4-help like beneath:

lw_f4-fieldname  = 'ZFI_BRN_LOC'.    "IFSC code
lw_f4-register   = abap_true.
lw_f4-getbefore  = space.
lw_f4-chngeafter = abap_true.
INSERT lw_f4 INTO TABLE lt_f4.

CLEAR lw_f4.
lw_f4-fieldname  = 'STGRD'.  "Reason for Reversal
lw_f4-register   = abap_true.
lw_f4-getbefore  = space.
INSERT lw_f4 INTO  TABLE lt_f4.

CALL METHOD grid_r->register_f4_for_fields
EXPORTING
it_f4 = lt_f4.

14.2. In class lcl_application_alvdefine the method and then implement it.

METHODS:
handle_on_f4 FOR EVENT onf4 OF cl_gui_alv_grid
IMPORTING sender
e_fieldname
e_fieldvalue
es_row_no
er_event_data
et_bad_cells
e_display.

14.3. In class lcl_application_alv implementation, implement the method handle_on_f4.

*-------------------------------------------------------------
* Add the custom F4 values for IFSC code
*-------------------------------------------------------------
IF e_fieldname = 'ZFI_BRN_LOC'.
IF gv_flag_inst_type = abap_true.  "For chq only
*        IF gt_data[] IS INITIAL.
CLEAR lt_knbk.
CLEAR gt_data.
READ TABLE gt_pis INTO lw_pis INDEX es_row_no-row_id.
IF sy-subrc = 0.
SELECT bankl bkref FROM knbk
INTO TABLE lt_knbk WHERE kunnr = lw_pis-kunnr.  "gv_kunnr.
IF sy-subrc = 0.
LOOP AT lt_knbk INTO lw_knbk.
lw_data-zfi_brn_loc = lw_knbk-bankl.
lw_data-zfi_bnk_code = lw_knbk-bkref.
APPEND lw_data TO gt_data.
CLEAR lw_data.
ENDLOOP.
ENDIF.
ENDIF.
*        ENDIF.
*Call the function module to display the custom F4 values
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield        = 'ZFI_BRN_LOC'
window_title    = 'List of IFSC entries'(026)
value_org       = gc_val_org
TABLES
value_tab       = gt_data[]
return_tab      = lt_ret[]
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS          = 3.
*    (note: gt_ret[] contains the row id selected by the user from the list of f4 values)
IF sy-subrc = 0.
READ TABLE lt_ret INTO lw_sel INDEX 1.
ASSIGN er_event_data->m_data->* TO <itab>.
READ TABLE gt_pis INDEX es_row_no-row_id
INTO lw_pis.
lw_modi-row_id   = es_row_no-row_id.
lw_modi-fieldname = 'ZFI_BRN_LOC'.
lw_modi-value     = lw_sel-fieldval.
APPEND lw_modi TO <itab>.

READ TABLE gt_data INTO lw_data
WITH KEY zfi_brn_loc = lw_modi-value+0(11).
IF sy-subrc = 0.
lw_modi-row_id   = es_row_no-row_id.
lw_modi-fieldname = 'ZFI_BNK_CODE'.
lw_modi-value     = lw_data-zfi_bnk_code.
APPEND lw_modi TO <itab>.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
*-------------------------------------------------------------
* Add the custom F4 values for Reversal Reason
*-------------------------------------------------------------
IF e_fieldname = 'STGRD'.
CLEAR: lt_t041ct, lt_return.
IF gv_uname = gc_depo_userid.    "BTDEPO
SELECT stgrd txt40 FROM t041ct
INTO TABLE lt_t041ct
WHERE spras = sy-langu
AND stgrd = gc_stgrd_06.
IF sy-subrc = 0.
*    do nothing
ENDIF.
ELSE.
SELECT stgrd txt40 FROM t041ct
INTO TABLE lt_t041ct
WHERE spras = sy-langu
AND stgrd IN (gc_stgrd_06,
gc_stgrd_08,
gc_stgrd_09,
gc_stgrd_10).
IF sy-subrc = 0.
*    do nothing
ENDIF.
ENDIF.

IF sy-subrc = 0.
CALL FUNCTION 'F4IF_INT_TABLE_VALUE_REQUEST'
EXPORTING
retfield        = 'STGRD'
window_title    = 'List of Rev reason entries'(025)
value_org       = gc_val_org
TABLES
value_tab       = lt_t041ct
return_tab      = lt_return
EXCEPTIONS
parameter_error = 1
no_values_found = 2
OTHERS          = 3.
IF sy-subrc = 0.
READ TABLE lt_return INTO lw_sel INDEX 1.
ASSIGN er_event_data->m_data->* TO <itab>.
READ TABLE gt_pis INDEX es_row_no-row_id
INTO lw_pis.
lw_modi-row_id   = es_row_no-row_id.
lw_modi-fieldname = 'STGRD'.
lw_modi-value     = lw_sel-fieldval.
APPEND lw_modi TO <itab>.
ENDIF.
ENDIF.
ENDIF.
er_event_data->m_event_handled = abap_true. "(to inform grid that f4 was handled manually)

14.4. Now after Register_F4_for_Fields is called, add below code:

SET HANDLER ref_aplic->handle_on_f4 FOR grid_r.

15. When the Back button is pressed, clear and refresh as below:

CALL METHOD grid_r->refresh_table_display.
CALL METHOD grid_r->free.
CALL METHOD container_r->free.
CALL METHOD cl_gui_cfw=>flush.

16. To make an ALV invisible add below code:

CALL METHOD inv_grid_r->set_visible( EXPORTING visible = '0' ).

17. To make Row Selection through code: Pass the row ids into lt_lvc_s_roid-

lw_lvc_s_roid-row_id = sy-tabix.
APPEND lw_lvc_s_roid TO lt_lvc_s_roid.

CALL METHOD grid_r->set_selected_rows
EXPORTING
it_row_no = lt_lvc_s_roid.

18. To Reset Scroll Bar Position after selecting rows through code, add the below code:

CALL METHOD grid_r->get_scroll_info_via_id
IMPORTING
es_row_no   = lw_row_no
es_row_info = lw_row_info
es_col_info = lw_col_info.

CALL METHOD grid_r->set_selected_rows
EXPORTING
it_row_no = lt_lvc_s_roid.

CALL METHOD grid_r->set_scroll_info_via_id(
EXPORTING
is_row_no   = lw_row_no
is_row_info = lw_row_info
is_col_info = lw_col_info
).

19. Display Top-of-Page data:

19.1. To show To-of-page subtleties first the primary holder should be parted into equal parts – one will be alloted to the Network and the other for populating the top header subtleties as underneath:

* Create TOP-Document

CREATE OBJECT g_dyndoc_id

EXPORTING

style = 'ALV_GRID'.

* Create Splitter for custom_container

CREATE OBJECT g_splitter

EXPORTING

parent  = g_custom_container

rows    = 2

columns = 1.
CALL METHOD g_splitter->get_container

EXPORTING

row       = 1

column    = 1

RECEIVING

container = g_parent_top.
CALL METHOD g_splitter->get_container

EXPORTING

row       = 2

column    = 1

RECEIVING

container = g_parent_grid.
* Set height for g_parent_html

CALL METHOD g_splitter->set_row_height

EXPORTING

id     = 1

height = 20.

CREATE OBJECT g_grid

EXPORTING

i_parent          = g_parent_grid

EXCEPTIONS

error_cntl_create = 1

error_cntl_init   = 2

error_cntl_link   = 3

error_dp_create   = 4

OTHERS            = 5.

19.2. Now in the local class, define method handle_top_of_page as below:

METHODS:

*Define method to handle Toolbar

handle_top_of_page FOR EVENT top_of_page

OF cl_gui_alv_grid

IMPORTING e_dyndoc_id.

19.3. In the class implementation, define the method details:

METHOD handle_top_of_page.

PERFORM f_event_top_of_page USING g_dyndoc_id.

ENDMETHOD. "EVENT_HANDLER

19.4. Logic in the Subroutine:

FORM f_event_top_of_page USING   dg_dyndoc_id TYPE REF TO cl_dd_document.
DATA: lv_name    TYPE lvc_fname,  "Name

li_t093b   TYPE STANDARD TABLE OF ty_t093b

INITIAL SIZE 0,  "T093B temp table

lst_t093b  TYPE ty_t093b,  "T093b wa

lv_reptext TYPE reptext,  "report Text

lv_text    TYPE sdydo_text_element. "Final text
* Header1

lv_name = c_header1.

PERFORM f_read_text USING lv_name

CHANGING lv_reptext.

lv_text = lv_reptext.

CALL METHOD dg_dyndoc_id->add_text

EXPORTING

text         = lv_text

sap_style    = cl_dd_area=>heading

sap_fontsize = cl_dd_area=>large

sap_color    = cl_dd_area=>list_heading_int. 

* Add new-line

CALL METHOD dg_dyndoc_id->new_line.
* Header2

WRITE s_budat-low TO g_fdate.

WRITE s_budat-high TO g_tdate.

lv_name = c_header2.

PERFORM f_read_text USING lv_name

CHANGING lv_reptext.

REPLACE '&G_FDATE&' INTO lv_reptext WITH g_fdate.

REPLACE '&G_TDATE&' INTO lv_reptext WITH g_tdate.

lv_text = lv_reptext.

CALL METHOD dg_dyndoc_id->add_gap.

CALL METHOD g_dyndoc_id->add_text

EXPORTING

text         = lv_text

sap_emphasis = cl_dd_area=>heading.

* Add new-line

CALL METHOD dg_dyndoc_id->new_line.
* Header3

lv_name = c_header3.

PERFORM f_read_text USING lv_name

CHANGING lv_reptext.

lv_text = lv_reptext.

CALL METHOD dg_dyndoc_id->add_gap.

CALL METHOD g_dyndoc_id->add_text

EXPORTING

text         = lv_text

sap_emphasis = cl_dd_area=>heading.

* Add new-line

CALL METHOD dg_dyndoc_id->new_line.

* Header4

lv_name = c_header4.

PERFORM f_read_text USING lv_name

CHANGING lv_reptext.

lv_text = lv_reptext.

li_t093b[] = i_t093b[].

SORT li_t093b BY waers.

DELETE ADJACENT DUPLICATES FROM li_t093b COMPARING waers.

LOOP AT li_t093b INTO lst_t093b.

CONCATENATE lv_text lst_t093b-waers INTO lv_text

SEPARATED BY space.

ENDLOOP.

CALL METHOD dg_dyndoc_id->add_gap.

CALL METHOD g_dyndoc_id->add_text

EXPORTING

text         = lv_text

sap_emphasis = cl_dd_area=>heading.
* Display output

PERFORM f_display.

ENDFORM.                    " EVENT_TOP_OF_PAGE
*&---------------------------------------------------------------------*

*&      Subroutine F_DISPLAY

*&---------------------------------------------------------------------*

*       Display data

*----------------------------------------------------------------------*

FORM f_display.

* Creating html control

IF g_html_cntrl IS INITIAL.

CREATE OBJECT g_html_cntrl

EXPORTING

parent = g_parent_top.

ENDIF.

CALL METHOD g_dyndoc_id->merge_document.

g_dyndoc_id->html_control = g_html_cntrl.

* Display document

CALL METHOD g_dyndoc_id->display_document

EXPORTING

reuse_control      = abap_true

parent             = g_parent_top

EXCEPTIONS

html_display_error = 1.

IF sy-subrc NE 0.

*    Error in displaying top-of-page

MESSAGE i023.

LEAVE LIST-PROCESSING.

ENDIF.

ENDFORM.                    " display

19.5. Before method set_table_for_first_display is called write the below code:

SET HANDLER ref_aplic->handle_top_of_page FOR grid_r.

CALL METHOD g_dyndoc_id->initialize_document

EXPORTING

background_color = cl_dd_area=>col_textarea.

* Processing events

CALL METHOD g_grid->list_processing_events

EXPORTING

i_event_name = 'TOP_OF_PAGE'

i_dyndoc_id  = g_dyndoc_id.

Some data declaration help:

g_dyndoc_id        TYPE REF TO cl_dd_document,   "Object ref for document header

g_splitter         TYPE REF TO cl_gui_splitter_container, "Object ref for splitter

g_parent_grid      TYPE REF TO cl_gui_container,   "Object ref for grid container

g_parent_top       TYPE REF TO cl_gui_container,   "Object ref for top container

g_html_cntrl       TYPE REF TO cl_gui_html_viewer, "Object ref for html control

g_custom_container TYPE REF TO cl_gui_custom_container, "Object ref for custom container

i_fcat             TYPE lvc_t_fcat.         "Field catalog

YOU MAY LIKE THIS

ABAP Applications for the Cloud: Modernizing for the Future

Top SAP ABAP Reports Interview Questions: Be Prepared

What are the ERP modules

SAP ABAP on HANA

SAP

Introduction to ALV with an Editable Row

Introduction to ALV with an Editable Row

Practically we all are very mindful of ALVs with an editable section. Assuming got some information about an editable line, we could see bewildered faces. Albeit the idea has been talked about in various discussions often previously, no whole code was found to carry out that in a hurry. The accompanying conversation will make sense of all through making an ALV with an Editable Row. Additionally, find the whole working code toward the end which can be downloaded and yet again utilized.

Requirement of ALV with an Editable Row

We should expect the necessity is to show buy orders given as a contribution to the choice screen. Buy requests will be shown with all thing numbers and material numbers. In our result screen, we need Buy Request Number, Plant, Stockpiling, Organization Code, Archive Type, Thing No and Material. Moreover, we ought to have an area of interest empower field on Buy request number after tapping on which framework ought to explore to the ME21N screen. At the point when tapped on back from ‘ME21N’ exchange every one of the lines of that specific buy request ought to become editable.

You can also read for:- Why are developers so fond of ‘REUSE_ALV_GRID_DISPLAY’?

Program Construct

  1. Types and Structure Declarations
  2. Work Areas and Internal Tables
  3. Declare Local Class For Event Handling
  4. Class Implementation
  5. Selection Screen Design
  6. Start Of Selection
  7. Call Screen
  8. PBO
  9. Module DISPLAY_ALV
  10. PAI

1. Types and Structure Declarations

OOPS ALV Reports in ABAP

Note – Aside from the expected sorts, in our last kinds structure we utilized ‘fstyl’ of type lvc_t_styl to control the editable settings. This assumes the real part to make the last ALV yield table lines editable or show as it were.

OOPs Report

2. Workspaces and Interior Tables Note-LS_STYLEROW and LT_STYLEROW are utilized for holding the style data we will make later in this article.

3. Declare Local Class for Event Handling

Hot Spot in ALV

For area of interest occasion, we have made this class-technique.

4. Class Implementation

ALV Report to make Row Editable

This part will deal with the significant errands expected in our program. Above all else, we want to have the area of interest route usefulness. This has been accomplished with ‘Consider Exchange’ explanation in the wake of perusing the row_id and comparing PO number for that. Additionally note, for that specific PO number, we have gathered all the details into the GT_FINAL table which we will make editable.

Presently we ought to deal with the column altering rationale.

SAP ALV report

Make note of the utilization of this segment (cl_gui_alv_grid=>mc_style_enabled). This really makes a specific field of your ALV editable. For this necessity, I utilized every one of the fields. On the other hand, in the event that you have a necessity to create 2 fields of a specific column editable you can basically pass just those two field names and you will see those as editable.

You need to make fields editable as well as need to deal with making those handicapped on the off chance that the altering condition isn’t met.

Editable Field in ALV

Presently you ought to be great with the editable line usefulness. We should continue on toward the fundamental body of our program.

5. Selection Screen Design

*&-------------------------------------------------------------------*
*&     S E L E C T I O N    S C R E E N
*&-------------------------------------------------------------------*
selection-screen: begin of block B1 with frame title text-001.
select-options: s_ebeln for ekko-ebeln.
selection-screen: end of block B1.

6. Start Of Selection

*&-------------------------------------------------------------------*
*&     S T A R T   O F   S E L E C T I O N
*&-------------------------------------------------------------------*
start-of-selection.
perform fetch_data.
call screen 0100.

Make a subroutine for bringing the fundamental information for framework show. The stream rationale for the custom screen made will look like underneath.

custom screen in SAP

6.a. Refer the full code.

6.b. Refer the full code.

6.c. Module Display_ALV

This part contains rationale to recognize whether the program has been executed in closer view/foundation. Contingent upon that, it utilizes a specific class reference. Keep in mind, on the off chance that you have made an object of a custom compartment (for example assuming you have utilized CL_GUI_CUSTOM_CONTAINER), foundation execution of the report will come up short and occupation status will be dropped. Continuously use docking holder reference in such cases. We use CL_GUI_ALV_GRID_OFFLINE to distinguish whether the program is executed on frontal area/foundation.

Docking Container

6.d. Refer the full code.

We should perceive how accurately it was planned.

Selection Screen
SAP OOPs Report
List Screen

Click on any Buying Record no in list screen and explore back to the report. You ought to have the option to see all related lines of the buying report editable.

Attempted with other PO number and it worked consistently!

Why ALV Report is dumping in Background

Execute the program in foundation

Foundation Occupation Status ought to be “Done”

Further Reading

For comparative usefulness and better comprehension allude BCALV_EDIT_02 program.

Extra Perusing

The client will clearly need some altering activity with change-save usefulness. When the lines are in the editable mode, the client will change a few information and hit save button. This will ultimately set off the PAI part of the custom screen and to deal with the save we want to utilize ‘SPOS’ capability code. Changes can be saved to particular standard tables/custom tables(depending on the prerequisite). To simplify our article I presented no such save activity except for showed the changed information in another ALV design utilizing the manufacturing plant technique.

Code for the PAI section is attached below.

*&---------------------------------------------------------------------*
*&      Module  USER_COMMAND_0100  INPUT
*&---------------------------------------------------------------------*
*       Process After Input and Back,Exit and Cancel logic
*----------------------------------------------------------------------*

MODULE USER_COMMAND_0100 INPUT.

  if sy-ucomm = 'E'.

    leave to screen 0.

  elseif sy-ucomm = 'ENDE'.

    leave to screen 0.

  elseif sy-ucomm = 'ECAN'.

    leave to screen 0.

  elseif sy-ucomm = 'SPOS'.

* When save trigger this section
  ref_ag->check_changed_data(

  importing e_valid = c_valid ).

  if c_valid eq abap_true.

*Check the data change

    if lt_final_old[] NE lt_final[].

      LOOP AT lt_final into ls_final.

        read table lt_final_old into ls_final_old index sy-tabix.

         if ls_final_old ne ls_final.

           append ls_final to t_final.

         endif.

      ENDLOOP.

*Any table update should be handled here

*Create the ALV to show the final data updated

    TRY.

     CALL METHOD CL_SALV_TABLE=>FACTORY
        IMPORTING
          R_SALV_TABLE   = ref_salv
        CHANGING
          T_TABLE        = t_final.

    CATCH CX_SALV_MSG .
    ENDTRY.

*Display the final updated table
    ref_salv->display( ).

    leave to screen 0.

    endif.

  endif.

  endif.

ENDMODULE.                 " USER_COMMAND_0100  INPUT

The last result in the wake of consolidating this activity will look something like beneath.

The client will alter something in the ALV yield (I have changed the ‘Material’ as WL-test and DG-test).

After change hit the ‘SAVE’ button and see the changed tuples in last ALV.

So… What Is Your Take?

Presently we need to hear from you.

What is your take of this technique? Do you have a superior methodology?

YOU MAY BE INTERESTED IN

Introduction to SAP ABAP for HANA

Future of ABAP on Cloud

ABAP Evolution: From Monolithic Masterpieces to Agile Architects

Create and Consume Business Add-in(BAdI) in ABAP

SAP

OOPs Report Using Splitter and ALV Tree Combination

Let’s dive into OOPs Report Using Splitter and ALV Tree Combination. For one client necessity, we needed to construct a report with splitter compartments alongside tree structure. The mix of these two could sound troublesome however, these are very simple to deal with. Quickly, we constructed a model and it worked impeccably.

Albeit the plan of the underneath made sense of model can be improved in various folds, essential skeleton for programming ought to continue as before. As we were obliging our advancement we discovered a few very much examined subjects over the web which I have attempted to tweak and address through this article.

Objective: OOPs Report Using Splitter and ALV Tree Combination

The goal of this article is to clear up how for utilize SPLITTER Compartment and TREE MODEL (TREE_STRUCTURE) in Uh oh ABAP report age coordinating standard occasions.

Also, the second and more significant goal is to destroy our apprehension about utilizing Tree Models and Splitter Compartments, for the last time.

Scope

This article covers the arrangements of the accompanying normal issues experienced by designers

  • Full screen use of custom holder when it is splitted into additional sub-compartments.
  • Enlisting custom occasions with standard occasions of tree model
  • Width customization of splitter compartments.

Overview

The accompanying code has been composed to show a report which has 2 compartments in the rundown screen. The left board compartment has been intended to hold the tree model and the right compartment is to show the subtleties of the left board record upon an occasion of double tapping. In this model a tree structure has been made with deals orders which have deal as a first record. These business orders can be chosen by giving specific determination screen models. After tapping on the leaf hub framework will show subtleties of the deals request in the right holder as an ALV design (if it’s not too much trouble, allude fig. 1).

Tree ALV

fig. – 1

Program Construct

Step – I: Declare all required structures and tables
Step –II: Declare reference of various classes
Step – III: Definition of event class
Step – IV: Implementation of Event Class
Step – V:  Selection Screen
Step – VI: Subroutine to fetch basic data for tree model
Step – VII: Screen Design
Step – VIII: Module for object creation of various classes. (In PBO of output screen)
Step – IX: Module for event registration. (In PBO of output Screen)
Step – X: Module for output processing. (In PBO of output Screen)

You can also read for:- A Deep Dive into the SAP API Hub

Step-I: Declare all required structures and tables

Tables: vbak,vbap,vbfa.

*&---------------------------------------------------------------------*
*&            Structures and Table Declarations
*&---------------------------------------------------------------------*
Data: ls_vbak type vbak,
lt_vbak type table of vbak,
ls_vbap type vbap,
lt_vbap type table of vbap.

Types: begin of ty_vbfa,
vbelv type vbfa-vbelv, "Preceding SD Document
posnv type vbfa-posnv, "Preceding SD Document Item Number
vbeln type vbfa-vbeln, "Subsequent SD Document
posnn type vbfa-posnn, "Subsequent SD Document Item Number
vbtyp_n type vbfa-vbtyp_n, "Subsequent Document Category
vbtyp_v type vbfa-vbtyp_v, "Preceding Document Category
end of ty_vbfa.

Data: ls_vbfa type ty_vbfa,
lt_vbfa type table of ty_vbfa.

Data: ls_vbfa_copy type ty_vbfa,
lt_vbfa_copy type table of ty_vbfa.

Types: begin of ty_vbak,
vbeln type vbak-vbeln,  "Contract Number
audat type vbak-audat,  "Document Date
ernam type vbak-ernam,  "Name of Person who Created the Object
auart type vbak-auart,  "Sales Document Type
end of ty_vbak.

Data: ls_vbak_cont type ty_vbak,
lt_vbak_cont type table of ty_vbak.

Step –II: Declare reference of various classes

*&---------------------------------------------------------------------*
*&            Type Reference of Various Classes
*&---------------------------------------------------------------------*
Data: ref_split type ref to cl_gui_splitter_container,
ref_cust  type ref to cl_gui_custom_container,
ref_alv1  type ref to cl_gui_alv_grid,
ref_alv2  type ref to cl_gui_alv_grid,
ref_cont1 type ref to cl_gui_container,
ref_cont2 type ref to cl_gui_container.
Data: ref_tree  type ref to cl_simple_tree_model.

Step – III: Definition of event class

*&---------------------------------------------------------------------*
*&                       Event Class
*&---------------------------------------------------------------------*
class lcl_event_handler definition.
public section.
methods: node_dc for event node_double_click of cl_simple_tree_model
importing node_key sender.
endclass.

Step – IV: Implementation of Event Class

class lcl_event_handler implementation.
method: node_dc.

Data: lt_children type tm_nodekey,
v_so        type vbeln,
v_item      type posnr.

Data: ls_layout type lvc_s_layo.
* 'sender' is an implicit event parameter that is provided by
* ABAP Objects runtime system. It contains a reference to the
* object that fired the event. You may directly use it to
* call methods of this instance.

CALL METHOD SENDER->NODE_GET_LAST_CHILD
EXPORTING
NODE_KEY       = node_key
IMPORTING
CHILD_NODE_KEY = lt_children.

* ‘Level_count’ in expand_node method determines in which level of the tree
* we want the double_click method to be triggered.

if lt_children is not initial.
CALL METHOD SENDER->EXPAND_NODE
EXPORTING
NODE_KEY            = node_key
LEVEL_COUNT         = 2.
endif.

split node_key at space into v_so v_item.

refresh: lt_vbap.

select * from vbap
into table lt_vbap
where vbeln = v_so.

if sy-subrc = 0.

ls_layout-grid_title = text-002.
ls_layout-zebra      = 'X'.
ls_layout-smalltitle = ''.
ls_layout-cwidth_opt = 'X'.

CALL METHOD REF_ALV2->SET_TABLE_FOR_FIRST_DISPLAY
EXPORTING
I_STRUCTURE_NAME              = 'VBAP'
IS_LAYOUT                     = ls_layout
CHANGING
IT_OUTTAB                     = lt_vbap.

CALL METHOD REF_ALV2->REFRESH_TABLE_DISPLAY.

endif.

endmethod.
endclass.

Step – V:  Selection Screen

*&---------------------------------------------------------------------*
*&                   Selection Screen
*&---------------------------------------------------------------------*
selection-screen: begin of block b1 with frame title text-001.
select-options: s_vbeln for vbak-vbeln, "Document Number
s_audat for vbak-audat, "Document Date
s_ernam for vbak-ernam. "Name who Created the Object
selection-screen: end of block b1.

Step – VI: Subroutine to fetch basic data for tree model

*&---------------------------------------------------------------------*
*&                   Start Of Selection
*&---------------------------------------------------------------------*
start-of-selection.
perform Get_Data.

*&---------------------------------------------------------------------*
*&      Form  GET_DATA
*&---------------------------------------------------------------------*
*       Get All the display relevant Data for Tree Structure
*----------------------------------------------------------------------*
FORM GET_DATA .

select vbeln audat ernam auart
from vbak
into table lt_vbak_cont
where vbeln in s_vbeln and
audat in s_audat and
ernam in s_ernam.

if sy-subrc <> 0.
message E001(ZMSG) with 'No Record Found' display like 'I'.
elseif sy-subrc = 0.

select vbelv posnv vbeln posnn vbtyp_n vbtyp_v
from vbfa
into table lt_vbfa
for all entries in lt_vbak_cont
where vbelv = lt_vbak_cont-vbeln and
vbtyp_n = 'C' and
vbtyp_v = 'G'.

if lt_vbfa is initial.
message E002(ZMSG) with 'No Subsequent Record Found' display like 'I'.
else.
select * from vbak
into table lt_vbak
for all entries in lt_vbfa
where vbeln = lt_vbfa-vbeln.

select * from vbap
into table lt_vbap
for all entries in lt_vbak
where vbeln = lt_vbak-vbeln.

endif.
endif.
ENDFORM.

Step – VII: Screen Design

call screen 0100.
Splitter Container

*The holder ought to be drawn as extensive as could be expected. Likewise, the Lines/segments in the qualities tab of the screen painter are to be loaded up with the worth 240 to get the full-screen splitter compartment.

OOPs ALV Report

Step – VIII: Module for object creation of various classes. (In PBO of output screen)

Create one module in the flow logic of the screen.

*&---------------------------------------------------------------------*
*&      Module  OBJECT_CREATION  OUTPUT
*&---------------------------------------------------------------------*
*       Object Creation for Classes
*----------------------------------------------------------------------*
MODULE OBJECT_CREATION OUTPUT.

CREATE OBJECT REF_CUST
EXPORTING
CONTAINER_NAME    = 'SPLIT_CONT'.

CREATE OBJECT REF_SPLIT
EXPORTING
PARENT            = ref_cust
ROWS              = 1
COLUMNS           = 2.

CALL METHOD REF_SPLIT->GET_CONTAINER
EXPORTING
ROW       = 1
COLUMN    = 1
RECEIVING
CONTAINER = ref_cont1.

* The width of the splitter container can be adjusted with the SET_COLUMN_WIDTH method. Pass the width as required.

CALL METHOD REF_SPLIT->SET_COLUMN_WIDTH
EXPORTING
ID                = 1
WIDTH             = 22.

CALL METHOD REF_SPLIT->GET_CONTAINER
EXPORTING
ROW       = 1
COLUMN    = 2
RECEIVING
CONTAINER = ref_cont2.

CREATE OBJECT REF_TREE
EXPORTING
NODE_SELECTION_MODE   = cl_simple_tree_model=>node_sel_mode_single.

CALL METHOD REF_TREE->CREATE_TREE_CONTROL
EXPORTING
PARENT                = ref_cont1.

CREATE OBJECT REF_ALV2
EXPORTING
I_PARENT  = ref_cont2.

ENDMODULE.                 " OBJECT_CREATION  OUTPUT

Step – IX: Module for event registration. (In PBO of output Screen)

ALV Tree
*&---------------------------------------------------------------------*
*&      Module  EVENT_REGISTRATION  OUTPUT
*&---------------------------------------------------------------------*
*       Double Click Event Registration

*§4a. Frontend registration(i):  get already registered tree events.
*................................................................
* The following four tree events registers ALV Tree in the constructor
* method itself.
*    - cl_gui_column_tree=>eventid_expand_no_children
* (needed to load data to frontend when a user expands a node)
*    - cl_gui_column_tree=>eventid_header_context_men_req
* (needed for header context menu)
*    - cl_gui_column_tree=>eventid_header_click
* (allows selection of columns (only when item selection activated))
*   - cl_gui_column_tree=>eventid_item_keypress
* (needed for F1-Help (only when item selection activated))
*
* Nevertheless you have to provide their IDs again if you register
* additional events with SET_REGISTERED_EVENTS (see below).
* To do so, call first method  GET_REGISTERED_EVENTS (this way,
* all already registered events remain registered, even your own):

* (If you do not these events will be deregistered!!!).
* You do not have to register events of the toolbar again.
*----------------------------------------------------------------------*
MODULE EVENT_REGISTRATION OUTPUT.
Data: lt_events type cntl_simple_events,
ls_event type cntl_simple_event.

Data: event_handler type ref to lcl_event_handler.

CALL METHOD REF_TREE->GET_REGISTERED_EVENTS
IMPORTING
EVENTS = lt_events.

ls_event-eventid = cl_simple_tree_model=>eventid_node_double_click.
append ls_event to lt_events.

CALL METHOD REF_TREE->SET_REGISTERED_EVENTS
EXPORTING
EVENTS                    = lt_events.

create object event_handler.
set handler event_handler->node_dc for ref_tree.

ENDMODULE.                 " EVENT_REGISTRATION  OUTPUT

Step – X: Module for output processing. (In PBO of output Screen)

OOPs ALV for Hierarchy Tree
*&---------------------------------------------------------------------*
*&      Module  PROCESSING_OUTPUT  OUTPUT
*&---------------------------------------------------------------------*
*       Processing Output of the Table
*----------------------------------------------------------------------*
MODULE PROCESSING_OUTPUT OUTPUT.

Data: ls_node type treemsnodt.

CALL METHOD REF_TREE->ADD_NODE
EXPORTING
NODE_KEY                = 'ROOT'
ISFOLDER                = 'X'
TEXT                    = 'Orders'
EXPANDER                = 'X'.

loop at lt_vbak into ls_vbak.

ls_node-node_key = ls_vbak-vbeln.

concatenate 'Sales Order#' ':' ls_vbak-vbeln
into ls_node-text
separated by space.

CALL METHOD REF_TREE->ADD_NODE
EXPORTING
NODE_KEY                = ls_node-node_key
RELATIVE_NODE_KEY       = 'ROOT'
RELATIONSHIP            = cl_simple_tree_model=>relat_last_child
ISFOLDER                = 'X'
TEXT                    = ls_node-text
EXPANDER                = 'X'.

endloop.

loop at lt_vbap into ls_vbap.

concatenate ls_vbap-vbeln ls_vbap-posnr
into ls_node-node_key
separated by space.

ls_node-relatkey = ls_vbap-vbeln.

concatenate ls_vbap-posnr ls_vbap-matnr
into ls_node-text
separated by space.

CALL METHOD REF_TREE->ADD_NODE
EXPORTING
NODE_KEY                = ls_node-node_key
RELATIVE_NODE_KEY       = ls_node-relatkey
RELATIONSHIP            = cl_simple_tree_model=>relat_last_child
ISFOLDER                = ''
TEXT                    = ls_node-text
EXPANDER                = ''.

endloop.
ENDMODULE.                 " PROCESSING_OUTPUT  OUTPUT

Duplicate or allude the inserted code however change the plan. I would prefer to propose foster the whole report with the assistance of nearby class or possibly apply some modularization ideas. I utilized different PBO modules which are a major ‘no’ for any continuous articles.

Tree designs should likewise be possible in numerous alternate ways. A lot of reports is accessible over the web. I picked the least difficult approach to doing that(ironically the class name is “cl_simple_tree_model”). Splitter holders are all around investigated yet barely utilized except if we have such unambiguous prerequisites. Nonetheless, this report is only “Old wine in another container”. Trust this annihilates our restraint of utilizing Splitter Compartments and Tree Models on a similar call and meet the second level headed of this instructional exercise.

At the point when you are done with your new development, the eventual outcome of your steady exertion should look something like underneath.

OOPs ABAP Tutorial
Selection Screen
Output List Screen
Expanded List
On Double-Click Event

We put a great deal of exertion in conceptualizing, testing and composing every single article. In the event that you could pass this connect to no less than 5 partners/companions who you think would profit from our post, it would be an extraordinary blessing to our group. We believe our articles should reach to whatever number crowds as could be allowed so everybody would benefit and our group would stay spurred and our work doesn’t lose all sense of direction in this colossal expanse of the web.

YOU MAY LIKE THIS

Cracking the Code: Your Earning Potential as a SAP ABAP Developer with 5 Years of Experience

A Comprehensive Guide to SAP ABAP Training Online

SAP LUW in ABAP Cloud

SAP ABAP Interview Questions Real time Expectations

SAP

Future of APIs in SAP: Gazing into the Crystal Ball

The world of SAP APIs is constantly evolving, driven by innovation and the ever-growing need for seamless data exchange in a hybrid IT landscape. In this, the final part of our blog series, we delve into the exciting Future of APIs in SAP, exploring emerging trends, the role of APIs in the cloud, and the importance of developing your API skillset.

You can also read for: how sap api works ?

As we look towards the future, several key trends are poised to shape the landscape of SAP API development and integration:

  • API Gateways: These intelligent gateways will act as central hubs for managing API traffic, enforcing security policies, and providing valuable analytics on API usage. Think of them as sophisticated airport terminals for your APIs, ensuring smooth and secure data flow.
  • Serverless Computing: The rise of serverless architectures will allow developers to focus on building API functionalities without worrying about server infrastructure management. This frees up valuable resources and empowers faster development cycles.
  • AI and Machine Learning (AI/ML): The integration of AI/ML with APIs will unlock a new level of automation and intelligence. Imagine APIs that can learn user behavior and preferences, personalizing data delivery and optimizing API performance.
  • Microservices Architecture: The popularity of microservices architectures, where applications are built as small, independent services, will further increase the demand for APIs as the communication channels between these services.

Embracing the Cloud: The Role of APIs in S/4HANA Cloud

The future of SAP is undoubtedly cloud-based, with S/4HANA Cloud leading the charge. APIs play a vital role in this cloud-centric world by enabling seamless integration between S/4HANA Cloud and other applications, both within and outside the SAP ecosystem. This fosters a more agile and extensible enterprise application landscape.

  • Pre-built APIs: S/4HANA Cloud offers a rich library of pre-built APIs that cater to various functionalities, streamlining the integration process for developers.
  • API Management as a Service (APIaaS): Cloud-based API management platforms will simplify API development, deployment, and governance within S/4HANA Cloud environments.
  • Event-Driven Architecture: APIs will play a crucial role in event-driven architectures, where applications react to real-time events, enabling a more dynamic and responsive business environment.

Future-Proofing Your Career: The Importance of API Skills

As the reliance on APIs in SAP continues to grow, developing your API skillset becomes increasingly important for future-proofing your career in the SAP world. Here are some ways to stay ahead of the curve:

  • Learn about API Design Principles: Understanding best practices for designing secure, well-documented, and user-friendly APIs is crucial.
  • Master API Development Tools: Familiarize yourself with SAP’s API development tools, such as the SAP Cloud Platform API Management service and the SAP API Business Hub.
  • Explore Integration Technologies: Gain knowledge of integration technologies like OData and SOAP, which form the backbone of SAP API communication.
  • Stay Updated with the Latest Trends: Continuously learn about emerging trends in the API landscape, such as serverless computing and AI/ML integration with APIs.

Resources for Staying Ahead of the Curve

Here are some valuable resources to help you stay updated on the latest advancements and best practices in SAP APIs:

  • SAP API Hub: This central repository provides access to a wealth of information on SAP APIs, including documentation, tutorials, and best practices. 
  • SAP Community: Engage with other SAP developers and experts in the SAP Community to discuss API-related topics and learn from their experiences. 
  • SAP Learning Hub: Explore online courses and learning resources offered by SAP to enhance your API development skills.

The future of SAP APIs is brimming with exciting possibilities. By embracing emerging trends, understanding the role of APIs in the cloud, and actively developing your API skillset, you can ensure you’re well-positioned to thrive in the ever-evolving world of SAP technology. So, dive into the world of SAP APIs, and unlock a future filled with innovation, agility, and seamless data integration!

you may be interested in this blog here:-

SAP API Hub

What is SAP?

What Does an SAP Developer Do?

SAP

SAP API Landscape

Mastering the Maze: Managing Your SAP API Landscape (Part 5)

Congratulations! You’ve conquered the foundational knowledge of SAP APIs, explored their various types and use cases, and even delved into the practicalities of consuming and developing them. But the journey doesn’t end there. Just like a bustling city, your SAP API landscape requires careful management to ensure its smooth operation and continued value.

In this final part of our SAP API series, we’ll equip you with the knowledge to effectively manage your API landscape. We’ll explore strategies for monitoring usage, establishing governance practices, prioritizing security, and utilizing valuable tools for streamlined API management.

Keeping a Pulse on Your APIs: Usage Monitoring and Performance Analysis

Just like any critical business function, your SAP APIs deserve close monitoring. Here’s how to ensure they’re performing optimally:

  • Track API Usage: Implement tools that track the frequency of API calls, user access patterns, and overall API utilization. This data helps identify popular APIs, potential bottlenecks, and areas for optimization.
  • Monitor API Performance: Measure response times, identify slow-performing APIs, and pinpoint potential performance issues. This proactive approach ensures your APIs remain responsive and deliver a seamless user experience.
  • Analyze API Errors: Track and analyze errors encountered during API calls. This can reveal integration issues, data inconsistencies, or faulty logic within the APIs themselves.

By implementing these monitoring practices, you can gain valuable insights into your API landscape’s health, identify areas for improvement, and proactively address potential issues before they disrupt business operations.

Governing Your APIs: Establishing Lifecycle Management Practices

Effective governance is paramount for a well-managed SAP API landscape. Here are some key practices to establish:

  • API Versioning: As APIs evolve, implement a versioning strategy to maintain compatibility with existing integrations while introducing new functionalities.
  • Deprecation Management: Clearly define a process for deprecating outdated APIs. This ensures developers are aware of upcoming changes and can plan their integrations accordingly.
  • Standardization and Documentation: Establish clear standards for API design, development, and documentation. This promotes consistency, simplifies maintenance, and ensures everyone is on the same page.
  • Access Controls and Security: Implement robust access control mechanisms to restrict access to specific APIs based on user roles and permissions.

By establishing these governance practices, you can ensure the order, control, and predictability needed for a healthy and sustainable SAP API landscape.

Security First: Prioritizing API Security Throughout the Lifecycle

The security of your SAP APIs is non-negotiable. Here’s how to prioritize security throughout the entire API lifecycle:

  • Threat Modeling: Identify potential security threats and vulnerabilities associated with your APIs. This proactive approach helps you mitigate risks before they can be exploited.
  • Authentication and Authorization: Implement robust authentication mechanisms to verify user identities and authorization controls to restrict access to authorized users only.
  • Data Encryption: Encrypt sensitive data transmitted through APIs to safeguard it from unauthorized access or interception.
  • API Gateway Security: Utilize an API Gateway that enforces security policies, monitors API traffic for suspicious activity, and provides additional layers of protection.

By adhering to these security best practices, you can build a strong defense against cyberattacks and ensure the confidentiality, integrity, and availability of your valuable SAP data.

Tools and Technologies: Your SAP API Management Arsenal

Fortunately, you don’t have to navigate the complexities of API management alone. Here are some valuable tools and platforms to consider:

  • SAP Cloud Application Programming Model (CAPM): A robust platform for building and managing APIs in the SAP Cloud environment.
  • SAP API Management (SAP APIM): A comprehensive solution for designing, securing, publishing, and monitoring APIs across both on-premise and cloud environments.
  • Third-Party API Management Tools: Several third-party API management tools integrate seamlessly with SAP, offering additional functionalities and features.

By leveraging these tools and platforms, you can streamline API development, governance, and monitoring processes, allowing you to focus on the strategic utilization of your SAP APIs to drive business value.

Conclusion: A Landscape Under Control

Managing your SAP API landscape effectively requires a multi-pronged approach. By implementing the strategies and practices outlined in this blog, you can ensure your APIs are monitored, governed, and secured effectively. Additionally, utilizing the available tools and platforms empowers you to streamline API management tasks and maximize the potential of your SAP API ecosystem.

Remember, a well-managed SAP API landscape fosters innovation, streamlines integrations, and unlocks a world of possibilities for your business. So, take control, implement these valuable practices, and watch your SAP APIs become the driving force behind agility, efficiency, and a competitive edge in the ever-evolving digital landscape.

you may be interested in this blog here:-

Customer 360 in Salesforce: A Holistic Approach

Spark Joyful Learning Engaging English Worksheet For UKG Class

Introduction SAP FLORI

× How can I help you?