SAP HR OM BAdI does not detecting IN_UPDATE changes - abap

We have implemented BADI ZHR_INT_BAD_OM_INFTY and Method IN_UPDATE. Now when some users save their OM work the IN_UPDATE method is not triggered.
The problem with debugging this is that when you go into abap debugger "stuff" in the background gets committed.
Our goal is to have a list of recent OM changes for delta detection.
Example of the code we have implemented:
DATA:
lw_old_image LIKE LINE OF old_image,
lw_new_image LIKE LINE OF new_image,
ls_object TYPE hrobject.
"-- Check if there is anything interesing in the old image
LOOP AT old_image INTO lw_old_image
WHERE infty IN me->get_range_infotypes( )
AND begda LE sy-datum
AND endda GE sy-datum.
MOVE-CORRESPONDING lw_old_image TO ls_object.
"-- If an object has been detected, trigger the refresh
TRY.
zhr_cl_int_person_masterdata=>trigger_om_object_changed( zhr_cl_om_object=>get( im_plvar = ls_object-plvar
im_otype = ls_object-otype
im_objid = ls_object-objid ) ).
CATCH zcx_hr_om. " " Base class for OM objects
ENDTRY.
ENDLOOP.
"-- If nothing found, check if there is anything interesting in the new image
IF ls_object IS INITIAL.
LOOP AT new_image INTO lw_new_image
WHERE infty IN me->get_range_infotypes( )
AND begda LE sy-datum
AND endda GE sy-datum.
MOVE-CORRESPONDING lw_new_image TO ls_object.
"-- If an object has been detected, trigger the refresh
TRY.
zhr_cl_int_person_masterdata=>trigger_om_object_changed( zhr_cl_om_object=>get( im_plvar = ls_object-plvar
im_otype = ls_object-otype
im_objid = ls_object-objid ) ).
CATCH zcx_hr_om. " " Base class for OM objects
ENDTRY.
ENDLOOP.
ENDIF.

Related

How to create a txt-file on the application server filled with an internal table?

I'm learning ABAP at the moment and got the task to build a function that creates a .txt file or a .csv file from an internal table and save it on the application server.
I know you can use, for example, GUI_DOWNLOAD for that, but the task is to build my own function to do that.
So I got an internal table filled and I want that to be saved as .txt file on the AS. I'm coding in Eclipse, BTW.
Anybody has an idea how to do that, using a function?
EDIT:
Here's what I tried already:
I created a function in the function builder. On the import parameters I put a parameter with the name "lv_mytab" with type table.
The source code of my function looks like this:
*"-------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(LV_MYTAB) TYPE TABLE
*"-------------------------------------------------------------------
DATA(myfile) = '/usr/sap/S42/data/textfile.txt'.
OPEN DATASET myfile FOR OUTPUT IN TEXT MODE ENCODING DEFAULT WITH SMART LINEFEED.
LOOP AT lv_mytab into lt_table.
TRANSFER lt_table to myfile.
CLOSE DATASET myfile.
In my program I tried calling the function like this:
CALL FUNCTION 'EXPORT_TXT_CSV_MR'
EXPORTING
lv_mytab = lt_summe.
lt_summe is the internal table I want to be exported as txt or csv.
Something like this:
OPEN DATASET lv_p_app FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT gt_error INTO gs_final.
TRANSFER gs_final TO lv_p_app.
ENDLOOP.
CLOSE DATASET lv_p_app.
ENDIF.
More samples here https://answers.sap.com/questions/3704234/download-internal-table-onto-the-application-serve.html
Okay with the help of a fellow student I got it working.
Heres the solution I found:
Code source of the function:
FUNCTION EXPORT_TXT_CSV_MR.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" REFERENCE(S_FILENAME) TYPE STRING
*" CHANGING
*" REFERENCE(GT_MYTAB) TYPE STANDARD TABLE
*" REFERENCE(GD_VERARBEITUNG) TYPE INT4
*"----------------------------------------------------------------------
DATA:
ld_filename TYPE string,
ld_datei type standard table of sbook,
ld_Zeile like line of ld_datei,
gd_useraction TYPE i,
lt_Ausgabe TYPE STANDARD TABLE OF sbook.
CONCATENATE '/usr/sap/S42/data/' s_filename into ld_filename.
IF gd_Verarbeitung = 1.
ld_datei = gt_mytab.
OPEN DATASET ld_filename FOR OUTPUT IN TEXT MODE ENCODING DEFAULT.
LOOP AT ld_datei into ld_Zeile.
Data(ld_string) = | Partnernummer: { ld_Zeile-customid } Betrag: { ld_Zeile-forcuram } Waehrung: { ld_Zeile-forcurkey } Name: { ld_Zeile-passname }|.
Transfer ld_string to ld_filename.
ENDLOOP.
Close dataset ld_filename.
ElseIF gd_Verarbeitung = 2.
ld_datei = gt_mytab.
*ld_filename = '/usr/sap/S42/data/CSVFile_MR.csv'.
Open Dataset ld_filename for output in text mode encoding default with SMART LINEFEED.
LOOP AT ld_datei into ld_Zeile.
ld_string = | Partnernummer: { ld_Zeile-customid } Betrag: { ld_Zeile-forcuram } Waehrung: { ld_Zeile-forcurkey } Name: { ld_Zeile-passname }|.
Transfer ld_string to ld_filename.
ENDLOOP.
Close dataset ld_filename.
ENDIF.
ENDFUNCTION.
And in my program I call it like this:
if p_txt = 'X'.
ld_txtcsv = 1.
CALL FUNCTION 'EXPORT_TXT_CSV_MR'
EXPORTING
s_filename = 'TXTFile_MR.txt'
CHANGING
gt_mytab = lt_summe
gd_verarbeitung = ld_txtcsv.
clear ld_txtcsv.
endif.
if p_csv = 'X'.
ld_txtcsv = 2.
CALL FUNCTION 'EXPORT_TXT_CSV_MR'
EXPORTING
s_filename = 'CSVFile_MR.csv'
CHANGING
gt_mytab = lt_summe
gd_verarbeitung = ld_txtcsv.
clear ld_txtcsv.
ENDIF.
Thanks for all of your help! I got it now! :)

Download an Excel document built with class CL_XLSX_DOCUMENT

My program below creates an Excel document built with the class CL_XLSX_DOCUMENT, which contains two sheets.
How can I download the Excel document on my laptop ?
lo_worksheetpart ?= lo_workbookpart->get_worksheetparts( )->get_part( lv_line_no_loop ).
lo_worksheetpart_1 ?= lo_workbookpart->add_worksheetpart( ).
lv_sheetxml = lo_worksheetpart->get_data( ).
lv_sheetxml_2 = lo_worksheetpart_1->get_data( ).
lo_sharedstringspart = lo_workbookpart->get_sharedstringspart( ).
lv_sharedxml = lo_sharedstringspart->get_data( ).
"Parse and replace
if lt_nameval is not initial.
lv_resultxml = update_shared_string_1(
EXPORTING
iv_xml = lv_sharedxml
iv_node = co_shared_string
it_nameval = lt_nameval ).
"write new excel
lo_sharedstringspart->feed_data( lv_resultxml ).
lv_resultxml = update_sheet_data_1(
EXPORTING
iv_xml = lv_sheetxml
iv_node = co_sheet_data
it_days = lt_days
it_nameval = lt_nameval ).
"write new excel
lo_worksheetpart->feed_data( lv_resultxml ).
endif.
I use the following:
DATA:
lv_fsize TYPE i,
lt_data TYPE tsfixml,
lv_resultxml TYPE xstring.
CALL FUNCTION 'SCMS_XSTRING_TO_BINARY'
EXPORTING
buffer = lv_resultxml
IMPORTING
output_length = lv_fsize
TABLES
binary_tab = lt_data.
CALL METHOD cl_gui_frontend_services=>gui_download
EXPORTING
bin_filesize = lv_fsize
filetype = 'BIN'
filename = 'C:\Temp\filename.xlsx
CHANGING
data_tab = lt_data

Add new emails Customer at XD02 from CALL METHOD cmd_ei_api=>maintain_bapi

I need to add a new email address on customers in XD02 from an xls.
That's all ok, but, when I CALL METHOD cmd_ei_api=>maintain_bapi
this really change the email but delete all the emails on XD02, and it's not what I want, I want to add a new email put this one default, but I want to keep the old ones.
My code :
FORM data_to_bapi.
DATA: gs_correct TYPE cmds_ei_main,
gt_customers TYPE cmds_ei_main,
gs_address TYPE bapiad1vl,
gs_addressx TYPE bapiad1vlx,
gs_company_code_st TYPE cmds_ei_company,
gs_company_code TYPE cmds_ei_cmd_company,
gt_smtp TYPE cvis_ei_smtp_t,
gs_smtp LIKE LINE OF gt_smtp,
gs_comm TYPE cvis_ei_cvi_communication,
gs_customers TYPE cmds_ei_extern,
gs_defective TYPE cmds_ei_main,
gs_msg_correct TYPE cvis_message,
gs_msg_error TYPE cvis_message,
iv_test_run TYPE c.
LOOP AT lt_data INTO wa_data.
"Controlo
gs_customers-header-object_instance-kunnr = wa_data-kunnr. "kunnr
gs_customers-header-object_task = 'U'. "Update this kunnr
gs_smtp-contact-task = 'I'. " Insert New Email
gs_smtp-contact-data-e_mail = wa_data-email. " New email
gs_smtp-contact-datax-e_mail = 'X'.
APPEND gs_smtp TO gt_smtp.
gs_comm-smtp-smtp = gt_smtp[].
gs_customers-central_data-address-communication = gs_comm.
gs_customers-central_data-address-task = 'I'. " Insert new communication
APPEND gs_customers TO gt_customers-customers.
**********************************************************************
* CALL BAPI *
**********************************************************************
CHECK gt_customers-customers IS NOT INITIAL.
gv_collect_messages = abap_true.
cmd_ei_api=>initialize( ).
iv_test_run = ' '.
CALL METHOD cmd_ei_api=>maintain_bapi
EXPORTING
iv_test_run = iv_test_run
iv_collect_messages = gv_collect_messages
is_master_data = gt_customer
" Master Data
IMPORTING
es_master_data_correct = gs_correct
es_message_correct = gs_msg_correct
es_master_data_defective = gs_defective
es_message_defective = gs_msg_error.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
wait = 'X'.
CLEAR wa_data.
ENDLOOP.
ENDFORM. "data_to_bapi
Thanks !

Set text field in screen visible again after user command

in my PBO Module I have something like this:
LOOP AT SCREEN.
IF screen-name EQ 'LBL_TEST'.
screen-invisible = '1'.
MODIFY SCREEN.
ENDIF.
ENDLOOP.
I want to set 'LBL_TEST' visible again after some User-Command in the PAI-Module. How can I do it?
Best regards,
Timur
You have to do it in PBO. You can set a global parameter when your operation completed and then check it. Like:
DATA: gv_checker.
PROCESS AFTER INPUT.
case ok_code.
when 'some_opp'.
gv_checker = 'X'.
endcase.
PROCESS BEFORE OUTPUT.
LOOP AT SCREEN.
IF screen-name EQ 'LBL_TEST'.
screen-invisible = '1'.
MODIFY SCREEN.
ENDIF.
if IF screen-name EQ 'LBL_TEST' and gv_checker = 'X'.
screen-invisible = '0'.
MODIFY SCREEN.
endif.
ENDLOOP.
Can't you check the value of sy-ucomm in the PBO? (I haven't checked myself, and don't know by heart, this is why I am asking.) If not, you can declare a global variable:
DATA: gv_ucomm TYPE sy-ucomm.
Move the value of sy-ucomm into this global variable in the PAI:
gv_ucomm = sy-ucomm.
And check the value of it in the PBO:
IF gv_ucomm EQ '...'.
... "turn on field
ELSE.
... "turn off field
ENDIF.

Sap Code Inspector how to use cl_ci_objectset class

I tried to use the cl_ci_objectset class to reference a set of objects to run a inspection afterwards:
data: lr_ci_objectset type ref to cl_ci_objectset.
CALL METHOD cl_ci_objectset=>get_ref
EXPORTING
P_OBJSNAM = 'ZTEST'
RECEIVING
p_ref = lr_ci_objectset
EXCEPTIONS
... exception list ...
IF sy-subrc <> 0.
MESSAGE i005(zsci).
* Fehler beim Ermitteln der Objektmenge
RAISE cancel.
ENDIF.
* Prüfen, ob es überhaupt Objekte in der SCI Objektmenge gibt
IF lr_ci_objectset->iobjlst-objects[] IS INITIAL.
write 'Object Menge leer'.
* in diesem Fall kann auch nichts geprüft werden
RETURN.
ENDIF.
write 'Object Menge nicht leer'.
the set 'ZTEST' is exsisting in the system as a public object set.
after more testing i found the solution.
IF lr_ci_objectset->iobjlst-objects[] IS INITIAL.
is the wrong array for a objset and is therefore used.
IF lr_ci_objectset->OBJECTSINF IS INITIAL.
is functional.
You can't check whether "an object set is empty" that easily. Object sets can be either discrete sets of objects (just like the contents of a transport) or a set of selection criteria. The latter might or might not yield a list of objects when the selection is executed - so the resulting object list may be empty, even if the object set is not.