Slow process of ABAP code
Dear gurus
My this codes take to much time to execute.
How to resolve it ?.
*& Form call_bapi
* text
* -->P_GOODSMVT_HEADER text
* -->P_GOODSMVT_ITEM text
FORM call_bapi USING p_goodsmvt_header LIKE goodsmvt_header
p_goodsmvt_item LIKE goodsmvt_item.
DATA: materialdocument TYPE bapi2017_gm_head_ret-mat_doc,
matdocumentyear TYPE bapi2017_gm_head_ret-doc_year,
wa_return LIKE LINE OF return,
goodsmvt_code LIKE bapi2017_gm_code.
goodsmvt_code-gm_code = '04'.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = p_goodsmvt_header
goodsmvt_code = goodsmvt_code
testrun = 'X'
IMPORTING
materialdocument = materialdocument
matdocumentyear = matdocumentyear
TABLES
goodsmvt_item = p_goodsmvt_item
* GOODSMVT_SERIALNUMBER = GOODSMVT_SERIALNUMBER
return = return
* GOODSMVT_SERV_PART_DATA = GOODSMVT_SERV_PART_DATA
* EXTENSIONIN = EXTENSIONIN
READ TABLE return WITH KEY type = 'E' INTO wa_return.
IF sy-subrc IS INITIAL.
MESSAGE ID wa_return-id TYPE wa_return-type NUMBER wa_return-number
WITH wa_return-message_v1 wa_return-message_v2 wa_return-message_v3 wa_return-message_v4.
ELSE.
CALL FUNCTION 'BAPI_GOODSMVT_CREATE'
EXPORTING
goodsmvt_header = p_goodsmvt_header
goodsmvt_code = goodsmvt_code
IMPORTING
* GOODSMVT_HEADRET = GOODSMVT_HEADRET
materialdocument = materialdocument
matdocumentyear = matdocumentyear
TABLES
goodsmvt_item = p_goodsmvt_item
return = return
* COMMIT WORK.
call function 'BAPI_TRANSACTION_COMMIT'
exporting
wait = 'X'.
SORT itab_final ASCENDING BY vbeln posnr.
DATA wa_itab LIKE wa_itab_final.
LOOP AT itab_final INTO wa_itab_final.
UPDATE zpacking_list SET posted = 'X' WHERE vbeln = wa_itab_final-vbeln AND posnr = wa_itab_final-posnr
AND mblnr IN ( SELECT mblnr FROM mseg WHERE werks = wa_itab_final-plant AND charg = wa_itab_final-charg ).
ENDLOOP.
MESSAGE i001 WITH materialdocument matdocumentyear.
LEAVE PROGRAM.
ENDIF.
ENDFORM. " call_bapi
>
jayakrishna.k wrote:
> Hi,
>
> Point 1:
> Please check the code. You are reading RETURN table with TYPE = 'E' and if sy-subrc is not initial (i.e; BAPI fails) again you are calling the BAPI with the same data.
>
> Point 2:
> In the loop you are updating the DB table which will impact the performance. Avoid update in loop.
>
> Regards,
> Jaya krishna K
Regarding 1.: If it's not initial, then he didn't find a E message and thus it was ok.
Regarding 2: update inside a loop is not per definition wrong. It's the inner select on MSEG that's causing a sequential read
Similar Messages
-
Compilation process of ABAP code.?
Hai every one.
Can any one tell me how a ackground process of ABAP code..How it is executed and How it is stored in database ( In which form )..!This is probably the strangest thread I've seen for a while. First of all, why do you care? Just abstract knowledge?
ABAP is not a compiled language. Therefore there is no compilation process. ABAP is interpreted. If you want to know what that means, then go read a dictionary or wikipedia or something similar.
When you save an ABAP program it is stored in the database. You do not put it into the database or retrieve it from the database directly, using any form of SQL. Indeed, from ABAP, you can't. You use the editor and the save function. Programs are only "stored" in memory when you RUN them. You can have many versions of a program as well as the active/inactive versions. For information about that, search the help on version management and change and transport system (CTS)
Different programs are differentiated in the database by the name of the program. How else would it be done? -
To add a process name in ABAP code
hi experts,
I have a requirement where my code is sending only "unsuccessfull" message on a process failure.
Now i need to add a name also in the mail. I m using a ABAP code to send the mail.
Can u suGgest a way to do so?
thanks.Hi,
You can use the ABAP program an dgive multiple name..see the article.
http://www.sdn.sap.com/irj/scn/index?rid=/library/uuid/4096bf2d-bcea-2b10-4ab4-e0683830d9b2&overridelayout=true
REPORT ztest_fm_mail.
DATA : is_doc_chng TYPE sodocchgi1,
it_objtxt TYPE STANDARD TABLE OF solisti1,
is_objtxt TYPE solisti1,
it_objpack TYPE STANDARD TABLE OF sopcklsti1,
is_objpack TYPE sopcklsti1,
it_objbin TYPE STANDARD TABLE OF solisti1,
is_objbin TYPE solisti1,
it_reclist TYPE STANDARD TABLE OF somlreci1,
is_reclist TYPE somlreci1,
w_lines_tx TYPE i.
** Create Message Body
** Title and Description
*is_doc_chng-obj_name = 'MAIL'.
is_doc_chng-obj_descr = 'Auto genareted Mail from BW'.
** main text
is_objtxt-line = 'This is an automatically generated mail. Please do not reply to it.'(028).
APPEND is_objtxt TO it_objtxt.
is_objtxt-line = space.
APPEND is_objtxt TO it_objtxt.
* write packing list (main)
DESCRIBE TABLE it_objtxt LINES w_lines_tx.
READ TABLE it_objtxt INTO is_objtxt INDEX w_lines_tx.
is_doc_chng-doc_size = ( w_lines_tx - 1 ) * 255 + STRLEN( is_objtxt ).
CLEAR is_objpack-transf_bin.
is_objpack-head_start = 1.
is_objpack-head_num = 0.
is_objpack-body_start = 1.
is_objpack-body_num = w_lines_tx.
is_objpack-doc_type = 'RAW'.
APPEND is_objpack TO it_objpack.
is_reclist-receiver = 'SURENDRA.REDDY at ABC.IN'. " here you need to add mail ids.
is_reclist-rec_type = 'U'.
APPEND is_reclist TO it_reclist.
CLEAR is_reclist.
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = is_doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_objpack
contents_txt = it_objtxt
receivers = it_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
OTHERS = 8.
IF sy-subrc <> 0.
MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
ENDIF.
Thanks
Reddy -
Triggering Process chains through abap code
Hi Experts,
Can you please let me know if it is possible to trigger a BW Process chain using an abap code.
If yes , kindly let me know the sample code.
Help done would be appreciated.
Regards,
UdayHi Thanks for your reply.
When I am trying to execute process chain with variant as a APD ( In this APD data is getting loaded form one Query to Transactional ODS.) This process chain being executing through one ABAP program using the following code
CALL FUNCTION 'RSPC_API_CHAIN_SCHEDULE'
EXPORTING
I_CHAIN = 'XYZ'. ( Dummy Process chain name)
While executing this program I am getting following message :
You can specify the name of the application server here
on which all jobs in the chain are scheduled
If you do not specify a name, the jobs from batch
management are divided between the available servers
How to avoid this message.
Can we write any code in the above program to assign any fixed server name so that it will not ask for any server name.
Your help is much appreciated. -
How to run ABAP code as a daemon process?
Background:
I need a daemon process to check status and react on it. This daemon may run for a long time.
Current:
to implement this, use an update module, to call a normal module with an endless loop (the loop may end dependent on some condition). While the message Update Terminate was got.
Question:
1. is the current way feasible? if it's OK, what might be the cause of the above problem?
2. if the current way is not OK. what's the way to run ABAP code as a daemon process?
Thanks and kind regards,
Said
p.s.
Also please refer to the link below for more information:
can update module call normal module?You could use InDesign Server, that can be run as a service. Have a look at its documentation for more details.
-Manan -
Use ABAP code in "Decision Between Multiple Alernativesu201D in process chain
Hi, does anybody know if it is possible to include ABAP code in formula definition when using u201CDecision Between Multiple Alernativesu201D in process chain.
I wanted to read a specific parameter from one table in order to choose the next step in the process chain.
If it is not possible, do you any workaround?
Best regards,
João ArvanasHey. You could create your own custom formula which you would code. Then that formula is reuseable in the formula builder. That should get you where you need to be.
Here is a document on how to implement the custom formulas:
http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f095592f-42f7-2a10-6ab1-c836a559b48f?quicklink=index&overridelayout=true
Hope this helps.
Thanks -
ABAP code to trigger Process Chain (Weekdays)
Dear experts,
I have a process chain which is triggered after an event in BW which is executed after a job in R3 is finished. This job in R3 is executed all days after another event.
I would like this process chain to be executed only from Monday to Friday. What ABAP code should I write in the function module which triggers the BW event in order to execute it only the days I really need to?
Thanks in advance for your help!
Best regards,
CeciliaHello Surendra,
Thakns as well for your help, but my problem is that I don't know any ABAP. With help of SDN posts I've been able to create the program in R3 which calls a FM in BW. My issue now is that I need the exact code which triggers my function module only from Moday to Friday......
The FM I have created in BW which triggers the event is the following (here I suppose I will need a code which says something like, if today is Monday to Friday trigger the event, if not, do not do anything):
FUNCTION Z_BW_EVENT_RAISE_PEDIDOS.
""Interfase local
*" IMPORTING
*" VALUE(EVENTID) LIKE TBTCO-EVENTID
*" EXPORTING
*" VALUE(RESULT) TYPE CHAR2
*" EXCEPTIONS
*" BAD_EVENTID
*" EVENTID_DOES_NOT_EXIST
*" EVENTID_MISSING
*" RAISE_FAILED
*" OTHERS
*data: eventid LIKE TBTCO-EVENTID.
*data: RESULT type CHAR2.
call function 'BP_EVENT_RAISE'
EXPORTING
eventid = eventid
EXCEPTIONS
bad_eventid = 1
eventid_does_not_exist = 2
eventid_missing = 3
raise_failed = 4
others = 5.
if sy-subrc eq 0.
result = 'OK'.
endif.
ENDFUNCTION.
*& Title: Raise Event for BW *
Best regards,
Cecilia -
Trigger Process chain using ABAP code
Hi All,
As per my knowledge there are 2 ways to trigger a process chain using ABAP code :
1) Using FM RSPC_API_CHAIN_START and passing process chain name as the parameter
2)Using FM 'BP_EVENT_RAISE' and passing process event as the parameter, which you can create using SM62 transaction.
I would like to know which one is better to use, in terms of advantage and disadvantage.
Thanks,
PraveenaHi praveena,
check these links ..u .may get some help
Process Chain
Process Chain
How to run a Process Chain
Process chain-parallel process
Regards
BILL -
How to restrict user to process own company code data in z program
Hi All,
I have this issue. in asset management I would like to restrict user to process its own company data.
for example A who works in company 0123 only can process comp code 0123 data whereas X who is manager can process all company code data.
In the abap program, how can i achive this? by authority object? if yes what asset management authority object to use?
i have company code in selection screen. so may i know what method i can achive so that A can only execute co 0123 whereas X can do for all company code.
thanksHi,
One way would be:
For all persons for whom you would like to 'control' the access to a specific company, SU01-->Parameters--->Give some parameter ID say XXX, & in PArameter Value key in the compnay code whose data it can process.
Please note that this is only one time process which has to be carried out for all the users. Then in your z-program in SELECTIO-SCREEN OUTPUT use GET PARAMETER ID 'XXX" Field w_value. If GET PARAMETER ID returns su-subrc = 0 then move w_value to your company code on the selection screen. Then Use LOOP AT SCREEN & make SCREEN-INPUT = '0' for company code so that company code will be displayed but protected thus not allowing the user to change the company code.
I hope this helps,
Regards
Raju Chitale -
Execute ABAP code in Start Routine only once
I have ABAP code in a start routine that I only want to execute once. Is there a way to tell this is first execution of the start routine?
Also can I find out these value in the start routine ABAP:
1. How many data packets there are?
2. What data packet I am processing?
Regards,
Mike...Hi,
I've just setup a little test:
TRules, Start Routine Global Decl:
DATA: GVI TYPE I, GVN(5) TYPE N.
Start Routine:
IF GVI IS INITIAL.
GVI = 1.
ELSE.
ADD 1 TO GVI.
ENDIF.
MOVE GVI TO GVN.
This is basically counting the times the start routine is executed and populating the var GVN; I am posting GVN in a char ZTESTGV in the target cube. I am posting as well the datapakID in my cube.
I have loaded two requests (each 4 packets)
the first one first to PSA and then from the PSA to the target: this is Serially using one single process. Here's the result in the cube:
Request________________________________DATAPAKID_____ZTESTGV
REQU_8B5ASGQNYYNIV1OJN68HFH1SR____________1____________1
REQU_8B5ASGQNYYNIV1OJN68HFH1SR____________2____________2
REQU_8B5ASGQNYYNIV1OJN68HFH1SR____________3____________3
REQU_8B5ASGQNYYNIV1OJN68HFH1SR____________4____________4
In this case the global variable is persistent accross packets.
the second request is loaded in paralell: this is, multiple processes are executed at the time. Here's the result in the cube:
Request________________________________DATAPAKID_____ZTESTGV
REQU_14QVH21BSVH44FAJW94BD7N2H____________1____________1
REQU_14QVH21BSVH44FAJW94BD7N2H____________2____________1
REQU_14QVH21BSVH44FAJW94BD7N2H____________3____________1
REQU_14QVH21BSVH44FAJW94BD7N2H____________4____________1
In this case the global variable is always1 !!
This is logic since several a process cannot access the internal memory used by another one...
Conclusion; the global variable will work only if the load is serial...
hope this helps...
Olivier. -
ABAP CODE TO POPULATE LOGICAL SOURCE SYSTEM
Hi Friends please help me with the below
1. Requirement : to Populate The system Date , Source System
in BI for Each load request.
1 Solution: I thought of writing the Start Routine for this but it is giving me error
syntax Error: END METHOD MISSING?????
2. Also I have requirement to populate 0sourcsys source system id, can any body help how to populate that.
Thanks
Poonam Roy
ABAP Code.
I have the End Method. what more to do.
METHOD start_routine.
*=== Segments ===
FIELD-SYMBOLS:
<SOURCE_FIELDS> TYPE tys_SC_1.
DATA:
MONITOR_REC TYPE rstmonitor.
$$ begin of routine - insert your code only below this line -
... "insert your code here
FORM STARTROUTINE
USING G_S_MINFO TYPE RSSM_S_MINFO
CHANGING DATAPAK type TRANSTRU
ABORT LIKE SY-SUBRC.
DATA: ZLOAD_DAT LIKE SY-DATUM
ZZSOURSYS TYPE RSLOGSYS
IF G_S_MINFO-DATAPAKID=1
SOURCE_FIELDS-ZLOAD_DAT = SY-DATE.
SOURCE_FIELDS-ZZSOURSYS = G_S_MINFO-LOGSYS.
ENDIF.
ABORT = 0.
ENDFORM.
ENDMETHOD.
ENDCLASS.
*-- fill table "MONITOR" with values of structure "MONITOR_REC"
*- to make monitor entries
... "to cancel the update process
raise exception type CX_RSROUT_ABORT.
$$ end of routine - insert your code only before this line -
ENDMETHOD.You have to write the code (<b>in BI/BW</b>) in the transfer rule (<b>between Datasource transfer structure and infosource/info object</b>)
There the FORM begin with
[code]USING RECORD_NO LIKE SY-TABIX
TRAN_STRUCTURE TYPE TRANSFER_STRUCTURE
G_S_MINFO TYPE RSSM_S_MINFO
CHANGING RESULT TYPE /BI0/OIPERSON
G_T_ERRORLOG TYPE rssm_t_errorlog_int
RETURNCODE LIKE SY-SUBRC
ABORT LIKE SY-SUBRC. set ABORT <> 0 to cancel datapackag[/code]
GS_MIN_INFO structure RSSM_S_MINFO contains information on the request being processed.
<i>G_S_MINFO. This passes technical information about the data load request,
such as requesting user, request date and time, update mode, the handling of
duplicate records, error handling flags, parallel processing flags, and what data
targets to update.</i>
If tou want to use start-routine for optimization reasons and fill an empty field in transfer structure, the structure G_S_MINFO is available too.
[code]USING G_S_MINFO TYPE RSSM_S_MINFO
CHANGING DATAPAK type TAB_TRANSTRU
G_T_ERRORLOG TYPE rssm_t_errorlog_int
ABORT LIKE SY-SUBRC. set ABORT <> 0 to cancel datapackage[/code]
And stay in FORM between limits :
[code]$$ begin of routine
$$ end of routine[/code]
Update RESULT in first case, and field(s) of DATAPAK in second case.
[code]RESULT = G_S_MINFO-LOGSYS.[/code] or
[code]LOOP AT DATAPAK INTO l_s_datapak_line.
l_s_datapak_line-zzsourcsys = G_S_MINFO-LOGSYS.
MODIFY DATAPAK FROM l_s_datapak_line.
ENDLOOP.[/code]
Regards -
Convert ABAP code in start routine/update rule to transform. start routine
Dear BW ABAPers,
I have created a custom purchasing info cube (YCP_PURC1) based on 0CP_PURC1 standard cube. I would like to convert this new data flow to BI7 (from 3.x), and convert the standard update rule to transformation. I would need to rewrite the below start routine from the standard update rule to a start routine ABAP code in the newly created transformation / start routine. My ABAP knowledge is limited. Will you please help?
*this is the start routine from the update rule. As a side note, the data source is 2LIS_02_SCL.
LOOP AT SOURCE_PACKAGE.
IF ( SOURCE_PACKAGE-cppvlc EQ 0
AND SOURCE_PACKAGE-cppvoc EQ 0
AND SOURCE_PACKAGE-cpquaou EQ 0 ).
DELETE SOURCE_PACKAGE.
CONTINUE.
ENDIF.
no_scl is initial ( e.g. for good receipts, billing)
value has to be set depending on storno
IF SOURCE_PACKAGE-no_scl IS INITIAL.
IF SOURCE_PACKAGE-storno = 'X'.
SOURCE_PACKAGE-no_scl = -1.
ELSE.
SOURCE_PACKAGE-no_scl = 1.
ENDIF.
MODIFY SOURCE_PACKAGE.
ENDIF.
ENDLOOP.
if abort is not equal zero, the update process will be canceled
ABORT = 0.
Many thanks and look forward to your kind feedback.
Kind regards,
CsabaDear All, Durgesh,
thanks to you all for your valuable input. Mainly the ABAP part was more interesting for me.
Durgesh, thanks for your input, it was useful. I just had to change the info objects to data source fields and add the lines before the loop:
DATA: I_PACKAGE TYPE TYT_SC_1.
FIELD-SYMBOLS <i_package> TYPE tys_sc_1.
I_PACKAGE[] = SOURCE_PACKAGE[].
LOOP AT SOURCE_PACKAGE assigning <i_package>.
IF ( <i_package>-BWGEO EQ 0
AND <i_package>-BWGEOO EQ 0
AND <i_package>-BWMNG EQ 0 ).
DELETE SOURCE_PACKAGE index sy-tabix.
CONTINUE.
ENDIF.
no_scl is initial ( e.g. for good receipts, billing)
value has to be set depending on storno
IF <i_package>-NOSCL IS INITIAL.
IF <i_package>-ROCANCEL = 'X'.
<i_package>-NOSCL = -1.
ELSE.
<i_package>-NOSCL = 1.
ENDIF.
ENDIF.
ENDLOOP.
Points have been assigned accordingly.
Thanks,
Csaba -
Trouble with SAPconnect / sending email in ABAP-code
Hi,
with the code below I try to send an email from ABAP outside
to an mail-account in the internet.
I'll get no error/exceptions but the mail will be not send
to the internet-mail-account.
In Transaktion SCOT I checked the SAPconnect-Node "INT"-"SMTP".
There is a mailserver with the right IP und the right Port. So I don't understand
what could be the problem!?
Can anybody help me and say me why the code below doesn't works?
Best wishes!
* For API
data: maildata type sodocchgi1.
data: mailtxt type table of solisti1 with header line.
data: mailrec type table of somlrec90 with header line.
start-of-selection.
clear: maildata, mailtxt, mailrec.
refresh: mailtxt, mailrec.
maildata-obj_name = 'TEST'.
maildata-obj_descr = 'Test'.
maildata-obj_langu = sy-langu.
mailtxt-line = 'This is a test'.
append mailtxt.
mailrec-receiver = '[email protected]'.
mailrec-rec_type = 'U'.
append mailrec.
call function 'SO_NEW_DOCUMENT_SEND_API1'
exporting
document_data = maildata
document_type = 'RAW'
put_in_outbox = 'X'
tables
object_header = mailtxt
object_content = mailtxt
receivers = mailrec
exceptions
too_many_receivers = 1
document_not_sent = 2
document_type_not_exist = 3
operation_no_authorization = 4
parameter_error = 5
x_error = 6
enqueue_error = 7
others = 8.
if sy-subrc <> 0.
* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
endif.
* Start the send process using the following statement
submit rsconn01 with mode = 'int' and return.
Message was edited by:
sebastian eckesSAP is a robust system, which gives many facilities in the form of Function Modules (FMs) for connecting to external systems or for use within the system. With a clever use of these FMs we can achieve a lot of things through ABAP code.
This article focuses on ways to send E-mails and SAP Mails using ABAP code.
Firstly SAP Mail
A SAP mail is a mail internal to the SAP system. It is a very good forum to exchange information with other users. Using a SAP mail in ABAP code facilitates exchange of automatic messages at various stages of the business process. It is easy to use and saves many hassles involved in using workflows for exchanging messages.
The ABAP code to send a sap mail is built around the FM SO_OBJECT_SEND which has the following pattern.
call function 'SO_OBJECT_SEND'
exporting
EXTERN_ADDRESS = ' '
FOLDER_ID = ' '
FORWARDER = ' '
OBJECT_FL_CHANGE = ' '
OBJECT_HD_CHANGE = ' '
OBJECT_ID = ' '
OBJECT_TYPE = ' '
OUTBOX_FLAG = ' '
OWNER = ' '
STORE_FLAG = ' '
DELETE_FLAG = ' '
SENDER = ' '
CHECK_ALREADY_SENT = ' '
importing
object_id_new =
sent_to_all =
tables
OBJCONT =
OBJHEAD =
OBJPARA =
OBJPARB =
receivers =
PACKING_LIST =
ATT_CONT =
ATT_HEAD =
NOTE_TEXT =
exceptions
active_user_not_exist = 1
communication_failure = 2
component_not_available = 3
folder_not_exist = 4
folder_no_authorization = 5
forwarder_not_exist = 6
note_not_exist = 7
object_not_exist = 8
object_not_sent = 9
object_no_authorization = 10
object_type_not_exist = 11
operation_no_authorization = 12
owner_not_exist = 13
parameter_error = 14
substitute_not_active = 15
substitute_not_defined = 16
system_failure = 17
too_much_receivers = 18
user_not_exist = 19
x_error = 20
others = 21.
In the next article we will understand the main parameters and table interfaces of the FM.
Import Parameters Name and Description Field name Field function
Object_hd_change (structure) Contains the process to be done when SAP mail is marked for execution.When the Execute Icon in the SAP mail is clicked the corresponding object is executed vmtyp D for dialog module F for function moduleR for reportT for transactionU for transaction with export
Acnam Name of the object which is to be executed, like name of transaction/report
Skips X to execute first screen in background
Objsns Indicates sensitivity of the object. P for private objectF for functional objectO for confidential objectC for company confidential objectSensitivity level is restricted to O for documents in shared folders
Objla Language of the document E for Englishsy-langu for system language
Objnam Name of the document
Objdes Short description (Title) of the document
Objsrt Name of the sort field. This is used to group documents based on certain criteria
Object_type Type of document to be sent with mail RAW for raw text (default) DOC for word file XLS for excel fileAll classes can be used except for folders (FOL) and distribution lists (DLI)
Outbox_flag X to indicate that mail should also be stored in outbox of the user after sending (default )
Owner Sap login of the user responsible for transmission
Table Parameters Name and Description Field Name Field function
Objcont Table to hold the body of the mail Line Text lines up to 255 characters
Objhead Table to hold number of lines in the body of the mail, i.e size of the table in lines Line Text lines up to 255 characters
Objpara Table to hold the set/get parameters to be transferred to the processing element Name Name of the parameter. Only first three characters are used
Option Not used
Low Value of the parameter in name
High Not used
Objparb Table to hold information for mails to which a certain processing type is assigned. For a report or transaction with transfer of values to global memory, the table has to contain the parameters with relevant values. The memory id is taken from the first row. For a FM or dialog module, data in table will be transferred as table parameter msgdial Name For report or transaction with transfer of values to global memory, the field for first row should hold the name of the memory id used for export and the other rows should hold the parameter names. For FM or dialog module this field should hold the values as per the usage of the module
Value For report or transaction with transfer of values to global memory, the field for first row should remain empty and the other rows should hold values of the parameters. For FM or dialog module this field should hold the values as per the usage of the module
Receivers Table to hold recipient details Recnam SAP login of the recipient. Append all the recipients to this table
Sndcp X for sending mail as a copy
Sndex X for sending as express document. This will prompt a logged on recipient saying that he or she has received an express mail
Recesc B for SAP user E for external email addressU for unix address
Export Parameters Name and Description Field name Field function
Object_id_new Contains object id of document created during send process
Sent_to_all X indicates that document was sent to all recipients. Flag is not activated if sending fails in one or more cases
Main Exceptions Name and Description Description
Too_much_receivers Number of recipients is greater than number for which sender is authorised to send
Object_not_sent Document was not delivered to any of the recipients
Object_not_exist Document class specified does not exist or cannot be sent
Object_no_authorisation Document could not be sent as one of the required authorisations does not exist
Parameter_error Invalid combination of parameter values transferred to FM
X_error Internal error occurred
Once all the parameters and table interfaces are properly filled, call the function module to send the SAP mail to the recipient inbox.
Care should be taken to report the status of execution of the function module to the user using one of the exceptions defined (refer function module pattern above)
Though SAP mail is a very robust method of interacting with users within SAP system, it is always good to receive email in Microsoft inbox. This also works like an additional notification to users in case they do not check SAP mail regularly. The next article covers sending E-mails using ABAP.
Sending Email to a non-SAP system:
Though SAP mail is a very robust method of interacting with users within SAP system, it is always good to receive email in Microsoft inbox. This also works like an additional notification to users in case they do not check SAP mail regularly.
Sending an email to the Microsoft Inbox is a way of interacting with a non SAP system through ABAP code and hence is very interesting. A fair knowledge of UNIX shell scripting is assumed here.
The ABAP code to send an email to Microsoft inbox revolves around following UNIX script
Echo "From:" "<"$1">" > <unix file path name>
Echo "To:" "<"$2">" >> <unix file path name>
Echo "Subject:" "<"$3">" >> <unix file path name>
Cat $4 >> <unix file path name>
Uuencode $5 $6 >> <unix file path name>
Cat <unix file path name> | /usr/sbin/sendmail f $fraddr $toaddr
(Note : the commands in the above script can be case sensitive. Check the actual case on the unix installation in question)
Let us understand the various parts of the above script.
$1 = Sender email address
$2 = Recipient email address
$3 = Subject of the email
$4 = Path of unix server file having email body
Form email body as an internal table in ABAP program, download it to a unix server file
$5 = Path of unix server file to be sent as email attachment
$6 = Name to be given to the attachment (like test1.doc, test1.xls). The corresponding Microsoft icon
will be shown in the email for the type of file attached ( Word document, excel document etc)
The script builds a temporary file and pipes the file to the sendmail command to achieve the mission.
This script can be invoked from SAP to send the mail to the intended recipient. Store this small script on the unix server. (Assume script name is sndmail )
To do this we should define a link in the SAP system between a customized command and this unix script.
The FM to define a customized command in SAP system has the following pattern.
call function 'SXPG_CALL_SYSTEM'
exporting
commandname =
PARAMETERS = ' '
importing
status =
tables
exec_protocol =
exceptions
no_permission = 1
command_not_found = 2
parameters_too_long = 3
security_risk = 4
wrong_check_call_interface = 5
program_start_error = 6
program_termination_error = 7
x_error = 8
parameter_expected = 9
too_many_parameters = 10
illegal_command = 11
others = 12.
In the next article we will understand the main parameters and table interfaces of the FM.
Import Parameters Name and Description Field name Field function
Commandname Name of unix shell script or command to be executed by SAP Name of unix shell script to be invoked
Parameters The parameters to be sent to unix shell script ($1, $2 etc). Send parameters as a concatenated string separated by space and length not exceeding 128 characters For eg in UNIX environment the above shell script would be executed as Sndmail [email protected] [email protected] Trial /home/test.doc testmail.We will be simulating this command using the FM from SAP system
Table Parameters Name and Description Field Name Field function
Exec_protocol (structure) Table to get messages from unix server after shell script is executed Length Length of the message from external program i.e unix
Message Log message from external program i.e unix
Export Parameters Name and Description Field name Field function
Status Contains the status of execution of external program Scheduling status of external program i.e unix
Once the above FM is invoked with the necessary parameters the unix program sendmail will send a mail to the inbox of the recipient in Microsoft.
The restriction on the parameter string length of 128 characters can be removed to make way for very long email addresses and subjects. Build the parameters into an internal table and download it as a file on the unix server. Instead of passing each parameter individually, pass the unix server path of this file as the parameter to the unix shell script (sndmail mentioned above). Modify the shell script to read every line of this parameter file as variables to be used in the shell script.
In the next article we will see an example of the ABAP code you can use to send SAP Mails.
REPORT ZTSAPMAIL.
DATA: X_OBJECT_TYPE LIKE SOOD-OBJTP.
DATA: BEGIN OF X_OBJECT_HD_CHANGE.
INCLUDE STRUCTURE SOOD1.
DATA: END OF X_OBJECT_HD_CHANGE.
DATA: BEGIN OF X_OBJCONT OCCURS 10.
INCLUDE STRUCTURE SOLI.
DATA: END OF X_OBJCONT.
DATA: BEGIN OF X_OBJHEAD OCCURS 0.
INCLUDE STRUCTURE SOLI.
DATA: END OF X_OBJHEAD.
DATA: BEGIN OF RAW_HEAD.
INCLUDE STRUCTURE SORH.
DATA: END OF RAW_HEAD.
DATA: BEGIN OF X_RECEIVERS OCCURS 0.
INCLUDE STRUCTURE SOOS1.
DATA: END OF X_RECEIVERS.
PARAMETERS: RECEIVER LIKE X_RECEIVERS-RECNAM. " Name
*BUILD MESSAGE HEADER
MOVE 'Sort field goes here' TO X_OBJECT_HD_CHANGE-OBJSRT. " Sort field
MOVE 'Name of the object goes here' TO X_OBJECT_HD_CHANGE-OBJNAM. " Name
MOVE 'Document title goes here' TO X_OBJECT_HD_CHANGE-OBJDES. " Title
MOVE 'F' TO X_OBJECT_HD_CHANGE-OBJSNS. " Functional OBJECT
MOVE 'E' TO X_OBJECT_HD_CHANGE-OBJLA. " Language
Object type of the new document
MOVE 'RAW' TO X_OBJECT_TYPE.
CLEAR X_OBJCONT.
MOVE 'Contents of mail' TO X_OBJCONT-LINE.
APPEND X_OBJCONT.
CLEAR X_OBJCONT-LINE. APPEND X_OBJCONT.
MOVE 'More contents' TO X_OBJCONT-LINE.
APPEND X_OBJCONT.
MOVE 'Still more contents'
to x_objcont-line.
APPEND X_OBJCONT.
MOVE ' ' TO X_OBJCONT-LINE.
APPEND X_OBJCONT.
Specific header (Dependent on the object type, here RAW)
REFRESH X_OBJHEAD.
DESCRIBE TABLE X_OBJCONT LINES RAW_HEAD-RAWSIZ.
MOVE RAW_HEAD TO X_OBJHEAD.
APPEND X_OBJHEAD.
*RECEIVERS table
CLEAR X_RECEIVERS.
REFRESH X_RECEIVERS.
MOVE RECEIVER TO X_RECEIVERS-RECNAM. " Name
MOVE 'B' TO X_RECEIVERS-RECESC. " Receiver type
MOVE 'X' TO X_RECEIVERS-SNDCP. " Send as a copy
MOVE 'X' TO X_RECEIVERS-SNDEX. " EXPRESS DOCUMENT
APPEND X_RECEIVERS.
CALL FUNCTION 'SO_OBJECT_SEND'
EXPORTING
folder_id = 'OUTBOX'
forwarder = x_forwarder
object_fl_change = x_object_fl_change
OBJECT_HD_CHANGE = X_OBJECT_HD_CHANGE
object_id = x_object_id
OBJECT_TYPE = X_OBJECT_TYPE
OUTBOX_FLAG = 'X'
OWNER = SY-UNAME
store_flag = x_store_flag
importing
object_id_new = x_object_id_new
sent_to_all = x_sent_to_all "May need to use
TABLES
OBJCONT = X_OBJCONT
OBJHEAD = X_OBJHEAD
objpara = x_objpara
objparb = x_objparb
RECEIVERS = X_RECEIVERS.
REPORT ZTUNIXMAIL.
DATA : TO_ADDRESS LIKE SY_LISEL,
FROM_ADDRESS LIKE SY-LISEL,
SUBJECT LIKE SY-LISEL,
ATTACHMENT_NAME LIKE SY_LISEL,
DATA_FILE_PATH LIKE SXPGCOLIST-PARAMETERS,
BODY_FILE_PATH LIKE SXPGCOLIST-PARAMETERS.
DATA : BEGIN OF INT_EMAIL_ATTACH OCCURS 0,
TXTLINE CHAR(255),
END OF INT_EMAIL_ATTACH.
DATA : BEGIN OF INT_EMAIL_BODY OCCURS 0,
TXTLINE CHAR(255),
END OF INT_EMAIL_BODY.
CLEAR : INT_EXEC_PROTOCOL,INT_EMAIL_ATTACH,INT_EMAIL_BODY.
REFRESH : INT_EXEC_PROTOCOL,INT_EMAIL_ATTACH,INT_EMAIL_BODY.
INT_EMAIL_ATTACH-TXTLINE = 'Put all attachment text in this table'.
APPEND INT_EMAIL_ATTACH. CLEAR INT_EMAIL_ATTACH.
INT_EMAIL_BODY-TXTLINE = 'Put all attachment text in this table'.
APPEND INT_EMAIL_BODY. CLEAR INT_EMAIL_BODY.
CONCATENATE TO_ADDRESS
FROM_ADDRESS
SUBJECT
BODY_FILE_PATH
DATA_FILE_PATH
ATTACHMENT_NAME
INTO V_PARAMETERS.
IF NOT INT_EMAIL_ATTACH[] IS INITIAL.
OPEN DATASET DATA_FILE_PATH FOR OUTPUT IN TEXT MODE.
LOOP AT INT_EMAIL_ATTACH.
TRANSFER INT_EMAIL_ATTACH-TXTLINE TO DATA_FILE_PATH.
ENDLOOP.
CLOSE DATASET DATA_FILE_PATH.
ENDIF.
IF NOT INT_EMAIL_BODY[] IS INITIAL.
OPEN DATASET BODY_FILE_PATH FOR OUTPUT IN TEXT MODE.
LOOP AT INT_EMAIL_BODY.
TRANSFER INT_EMAIL_BODY-TXTLINE TO BODY_FILE_PATH.
ENDLOOP.
CLOSE DATASET BODY_FILE_PATH.
ENDIF.
CALL FUNCTION 'SXPG_CALL_SYSTEM'
EXPORTING
COMMANDNAME = 'Z_EMAIL' - Command calling unix script
PARAMETERS = V_PARAMETERS
importing
status = ''
TABLES
EXEC_PROTOCOL = INT_EXEC_PROTOCOL
EXCEPTIONS
NO_PERMISSION = 1
COMMAND_NOT_FOUND = 2
PARAMETERS_TOO_LONG = 3
SECURITY_RISK = 4
WRONG_CHECK_CALL_INTERFACE = 5
PROGRAM_START_ERROR = 6
PROGRAM_TERMINATION_ERROR = 7
X_ERROR = 8
PARAMETER_EXPECTED = 9
TOO_MANY_PARAMETERS = 10
ILLEGAL_COMMAND = 11
OTHERS = 12.
regards,
srinivas
<b>*Reward points for useful answers*</b> -
ABAP code to set Infopackage Monitor to "RED" status?
Hello,
I have an Infopackage that is using ABAP code to determine the selection values dynamically for an Infoobject during the load (Type: 6 ABAP routine). We have built in customer error checking on the selection values based on our requirements.
In the event of an error I need to do the following:
-Set the 'Total' and 'Technical' color status to "RED" in monitor.
-Define custom error message in "Status" tab of monitor for load.
Does anyone know how to accomplish this? Links to an example or previous thread will be appreciated.
Thank you,
Brian
Message was edited by:
BrianThe status of a particular request is stored in the table RSREQDONE. You can have an abap code to modify the entries of the field TSTATUS (technical status of the request) in this table for the given request number.
Example:
Value of @5B@ for this field denotes that this request is successful (GREEN)
FYI, I am not sure how recommendable this process is coz I never implemented before. -
ABAP Code To Authenticate Users
Hi,
How can I code a ABAP program/function which will authenticate a user based only on their user id? Do not want to use their password.
I want the entire authentication process to happen in the ABAP code.
Any ideas?
Thanks,
AudreyHi,
To check the authorization of the user of an ABAP program, use the AUTHORITY-CHECK statement:
AUTHORITY-CHECK OBJECT '<object>'
ID '<name1>' FIELD <f1>
ID '<name2>' FIELD <f2>
ID '<name10>' FIELD <f10>.
<object> is the name of the object that you want to check. You must list the names (<name1>, <name2> ...) of all authorization fields that occur in <object>. You can enter the values <f 1 >, <f 2 >.... for which the authorization is to be checked either as variables or as literals. The AUTHORITY-CHECK statement checks the users profile for the listed object, to see whether the user has authorization for all values of <f>. Then, and only then, is SY-SUBRC set to 0. You can avoid checking a field by replacing FIELD <f> with DUMMY. You can only evaluate the result of the authorization check by checking the contents of SY-SUBRC. For a list of the possible return values and further information, see the keyword documentation for the AUTHORITY-CHECK statement. For further general information about the SAP authorization concept, refer to Users and Authorizations.
There is an authorization object called F_SPFLI. It contains the fields ACTVT, NAME, and CITY.
SELECT * FROM SPFLI.
AUTHORITY-CHECK OBJECT 'F_SPFLI'
ID 'ACTVT' FIELD '02'
ID 'NAME' FIELD SPFLI-CARRID
ID 'CITY' DUMMY.
IF SY-SUBRC NE 0. EXIT. ENDIF.
ENDSELECT.
If the user has the following authorizations for F_SPFLI:
ACTVT 01-03, NAME AA-LH, CITY none,
and the value of SPFLI-CARRID is not between "AA" and "LH", the authorization check terminates the SELECT loop.
Hope it helps u.
Thanks&Regards,
Ruthra.R
Maybe you are looking for
-
I'm having trouble updating my pages - time out
Ok so I have uploaded my website before in the past, so my website is out there (http://www.lochalarchade.com), I added a few widgets and some adsense ads in several parts of the page, it couldn't upload, went on something about "please make sure you
-
Greeting Gurus, I am working with the Purchasing cube and I have come accross a routing that PERFORMs LOC_CURR_CONVERT. I need to convert this to a ABAP OO Method. I find it difficult to find any information on this. Does anybody have any suggesti
-
Multiple Monitor support using RDP in Windows 10
Does anyone know if you can use multiple monitors when connecting through RDP in Windows 10? In Windows 7, you need to be using Windows 7 Ultimate in order for RDP to support more than one monitor. For example, my home setup has (2) 22" monitors and
-
Lost my Trend Micro when updated to Mavericks
Just downloaded Maverick, but it says my version of Trend Micro that came with my laptop isn't compatible. It came with my purchase. Shouldn't I get a free upgrade to the new Trend Micro Titanium?
-
Why am I having trouble uploading photos from iPhoto on mac after update
Why am I having trouble uploading photos from iPhoto on mac after update