Sap odata: Export a single Variable with abap - abap

I have got a function module that counts some variables in sap system and export it as single INT4. But when I try to use this in gateway service, it says me
"no output table mapped" How can i overcome it, I tried to put this variable in a table and export then but I couldnt.
DATA: EV_ENQ TYPE STANDARD TABLE OF seqg3.
CALL FUNCTION 'ENQUEUE_READ'
EXPORTING
guname = '*'
IMPORTING
number = EV_TABLESIZE
TABLES
enq = EV_ENQ.
Ev_Tablesize is the variable that I want to export. It holds the total lock count.

Your parameter should be mapped under your service implementation in SEGW. If it is not, then you should map them again and be sure that the parameter is being displayed.

Related

How to programmatically tell if system is R/3 or S/4

Is it possible to determine via code if the current system is R/3 or S/4?
I need it because I have a method that returns the software component of Human Resources related data, but this component should be different to R/3 and S/4 systems.
DATA(lv_software_component) = mo_configuration->get_software_component( ).
SELECT * FROM tadir INTO TABLE #DATA(lt_inftype_tables)
WHERE pgmid = 'R3TR'
AND object = 'TABL'
AND devclass IN ( SELECT devclass FROM tdevc
WHERE dlvunit = #lv_software_component
OR dlvunit = 'SAP_HRGXX'
OR dlvunit = 'SAP_HRRXX' )
On R/3, lv_software_component should be 'SAP_HRCMX', for example, while on S/4 it should be 'S4HCMCMX'. Currently, I have no idea on how to tell the difference between the releases, programmatically speaking.
The best I've come up with is hardcoding SY-SYSID, since I know which systems are S/4 and which aren't, but that shouldn't be ideal.
I appreciate any help, thanks!
You can use below class method for determining it. On the other hand is_s4h method only exists on S4 system. You need to check method exits before calling it.
cl_cos_utilities=>is_s4h( )
Working full example:
REPORT ZMKY_ISS4.
CLASS cl_oo_include_naming DEFINITION LOAD.
DATA oref TYPE REF TO if_oo_class_incl_naming.
DATA: lt_methods TYPE seop_methods_w_include,
lv_clskey TYPE seoclskey,
ls_cpdkey TYPE seocpdkey,
lv_iss4 TYPE abap_bool,
lt_params TYPE abap_parmbind_tab.
lv_clskey = 'CL_COS_UTILITIES'.
oref ?= cl_oo_include_naming=>get_instance_by_cifkey( lv_clskey ).
lt_methods = oref->get_all_method_includes( ).
ls_cpdkey-clsname = lv_clskey.
ls_cpdkey-cpdname = 'IS_S4H'.
READ TABLE lt_methods WITH KEY cpdkey = ls_cpdkey TRANSPORTING NO FIELDS.
IF sy-subrc EQ 0.
lt_params = VALUE #( ( name = 'RV_IS_S4H'
kind = cl_abap_objectdescr=>returning
value = REF #( lv_iss4 ) ) ).
CALL METHOD CL_COS_UTILITIES=>('IS_S4H')
PARAMETER-TABLE
lt_params.
ELSE.
lv_iss4 = abap_false.
ENDIF.
Using the method cl_cos_utilities=>is_s4h is a rather unclean solution, because that method does not exist on older releases.
A cleaner method is to use the function module SFW_IS_BFUNC_SWITCHED_ON. This function module checks if a business function in the switch framework is enabled.
To check for the S4HANA on premise business function:
CALL FUNCTION 'SFW_IS_BFUNC_SWITCHED_ON'
EXPORTING
bfunc_name = 'SIMPLIFY_ON_PREMISE'
IMPORTING
is_switched_on = is_s4.
To check for the S4HANA on cloud business function:
CALL FUNCTION 'SFW_IS_BFUNC_SWITCHED_ON'
EXPORTING
bfunc_name = 'SIMPLIFY_PUBLIC_CLOUD'
IMPORTING
is_switched_on = is_s4.
By the way: The method cl_cos_utilities=>is_s4h actually uses this function module internally.
You might also want to check if it might be more appropriate in your use-case to use that function module to actually detect which HR business functions are active instead of deriving that information indirectly from whether or not the system has S/4 activated.
There's the function module OCS_GET_INSTALLED_COMPS which returns all software components installed. Note that it's not released by SAP. It used to work in old systems and still works in S/4HANA.
You can use function module DELIVERY_CHCK_ACTIVE_COMPONENT to check which of the two components is active.
I am also pretty sure only S/4 systems will have the S4CORE component active if you really need to check if it's S/4 or R/3.

Notification: BTPLN vs TPLNR

I have this data type to hold the information to create a notification.
DATA: LS_NOTIFHEADER LIKE BAPI2080_NOTHDRI.
I want to create a notification with a functional location and an affected functional location. I know I can add the functional location with
LS_NOTIFHEADER-TPLNR = '1010-XXXXXXXXXXXXXX'.
Is there also a field to add the affected functional location (BTPLN)?
This is the code I use to create the notification.
CALL FUNCTION 'BAPI_ALM_NOTIF_CREATE'
EXPORTING
NOTIF_TYPE = 'M1'
NOTIFHEADER = LS_NOTIFHEADER
IMPORTING
NOTIFHEADER_EXPORT = LS_NOTIF
TABLES
RETURN = LT_RETURN.
There is no possibility to specify affected location in BAPI.
But user-exit EXIT_SAPLIQS0_017 (enhancement QQMA0025) may be helpful for you. It is called by BAPI and there you can modify BTPLN.

Inserting data into BAPIRET2_TAB structure

My method is using an export parameter of type BAPIRET2_TAB. I need to fill the values of this structure, but I cant access the structure directly. For example, parameter-message = 'text', etc.
How can I do this?
These are the parameters I need to pass:
lv_msg_line. type i
lv_syntax_text. //Error message
And this is syntax checker.
syntax-check for l_tab_code
program lv_progname
message l_error_message
line l_error_line
word l_error_word
id 'ERR' table l_tab_errors.
Like said above in the comments, BAPIRET2_TAB is not a structure, and therefore cannot have its components accessed directly via STRUCTURE-FIELD paradigm.
What you need is to declare an structure like this
DATA error_line TYPE LINE OF BAPIRET2_TAB.
Then, you can use it to fill the data in...
error_line-program = sy-repid.
error_line-id = sy-msgid.
... and so forth. Then, lastly, you append the error_line item to your BAPIRET2_TAB.
APPEND error_line TO bapi2tab.
CLEAR error_line.
Hope it helps.

Function module to export local table to excel

I am working on a program in Business Warehouse that allows you to map out all of your process chains by following the hierarchy of parent to sub-chains by using the rspcchain table. As of right now I have it printing the output to the screen, but would like to export this output to excel instead. I have been unable to find a function module that serves this purpose, so any help would be greatly appreciated
note - after learning about the SALV classes available I changed the code to display the table differently.
REPORT Z_PC_VARIANT_MAPPING.
*Declaring types and variables
TYPES: BEGIN OF t_chains,
chain_id LIKE rspcchain-chain_id,
variant LIKE rspcchain-variante,
END OF t_chains.
DATA: lt_rspcchain TYPE STANDARD TABLE OF t_chains,
lwa_rspcchain TYPE t_chains,
o_alv TYPE REF TO cl_salv_table,
lx_msg TYPE REF TO cx_salv_msg.
TABLES: rspcchain.
*selection screen setup
SELECT-OPTIONS chain_id FOR rspcchain-chain_id.
SELECT-OPTIONS type FOR rspcchain-type.
*filling local table
SELECT chain_id variante
FROM rspcchain INTO TABLE lt_rspcchain
WHERE chain_id IN chain_id AND
type IN type AND
objvers = 'A'.
*original code to test printing output on screen
*LOOP AT lt_rspcchain INTO lwa_rspcchain.
* skip.
* WRITE lwa_rspcchain-chain_id.
* WRITE lwa_rspcchain-variant.
*ENDLOOP.
IF sy-subrc NE 0. "sy-subrc = return code
WRITE 'Data not found'.
ENDIF.
*loading data from local table into alv object table
TRY.
cl_salv_table=>factory(
IMPORTING
r_salv_table = o_alv
CHANGING
t_table = lt_rspcchain ).
CATCH cx_salv_msg INTO lx_msg.
ENDTRY.
*calling display method to display table
o_alv->display( ).
You can use the SALV framework for this, it comes with a class to export whatever would be displayed to various formats, including .MHTML and .XML formats that are understood by Excel. The class CL_SALV_TABLE has a method TO_XML to support this; additionally, you might need the CL_SALV_BS_XML_UTILS to handle the transformations. See the report SALV_TEST_TABLE_DISPLAY_OR_XML for example coding.
You should look at the ABAP2XLSX project.
http://wiki.sdn.sap.com/wiki/display/ABAP/abap2xlsx
Not sure if all the necessary components exist in BW, but this is really the best solution for creating spreadsheets out of ABAP code that I have found.
You can try the following which will download a CSV file, which with the .xls extension opens flawlessly in Excel:
Convert lt_rspcchain to a csv internal table by calling SAP_CONVERT_TO_CSV_FORMAT
Figure out where the user wants to store the file by calling cl_gui_frontend_services=>file_save_dialog( )
Store the file by calling cl_gui_frontend_services=>gui_download( )
I assume you will be able to find how these work by experience or through Google.

.NET ODBC Oracle Params getting param name returned by db provider- possible?

I'm converting some RDO code to ODBC Provider code in .NET.
The problem is parameter names were not specified in the orignal code, but param values were retrieved by parameter name after the command was executed.
Is there anyway to have parameter names populated by the provider once the command is executed so calling code can access params by name.
Let me show you an example of the declaration of param and accessing of it.
With rdqryClntBasic
.Parameters.Add(.CreateParameter) : .Parameters(0).Direction = ParameterDirection.Input
.Parameters(0).DbType = DbType.String
.Parameters(0).Value = sClntProdCd
End With
.EffectiveDate = ToDate(rdqryClntBasic.Parameters("dtEffDt").Value)
You can now see how this "used to work in RDO/VB". For some reason it would accept this and know what the param names were after execution. I imagine it had to do another round trip to the db to get this info.
Is there anyway to mimic this behaviour in .NET for ODBC Provider (using Oracle)? Or am I stuck manually specifying the param names in the code (I understand this is the better option, but wondering what the alternative is to match the original code as closely as possible).
No, parameters in ODBC are positional not by name.