Workflow Template:
**********************************************************************************
METHOD get_details.
DATA :id TYPE thead-tdid,
language TYPE thead-tdspras,
name TYPE thead-tdname,
object TYPE thead-tdobject,
lines TYPE TABLE OF tline,
lin TYPE tline,
wa_reason TYPE soli,wa_output TYPE w3html.
TYPES : BEGIN OF ty_rea,
f1 TYPE char100,
f2 TYPE char100,
f3 TYPE char100,
END OF ty_rea.
DATA :lv_amt TYPE char20.
DATA : lv_unam TYPE sy-uname.
DATA: doc_chng TYPE sodocchgi1.
DATA: tab_lines TYPE sy-tabix,
body_start TYPE sy-tabix.
DATA: it_objtxt TYPE TABLE OF solisti1 .
DATA: wa_objtxt TYPE solisti1 .
DATA: it_objpack TYPE TABLE OF sopcklsti1 .
DATA: wa_objpack TYPE sopcklsti1 .
DATA: it_objbin TYPE TABLE OF solisti1 .
DATA: wa_objbin TYPE solisti1 .
DATA: it_reclist TYPE TABLE OF somlreci1 .
DATA: wa_reclist TYPE somlreci1 .
*DATA: it_shortcut_param type zst_shortcut_par OCCURS 0 WITH HEADER LINE.
DATA: content TYPE string.
DATA : text TYPE bcsy_text,
body_text TYPE so_text255.
DATA : parameter TYPE text255 .
DATA : gt_rea TYPE TABLE OF ty_rea,
gs_rea TYPE ty_rea,
lv_string TYPE char200,
lv_string1 TYPE char200,
lv_string2 TYPE char200,
lv_string3 TYPE char200.
"Getting Purchase requisition Details
SELECT SINGLE * FROM eban INTO @DATA(gs_eban) WHERE banfn = @pr_number.
********Commented by Navaneetha Krishnan on 10.2.17************************************************
*
* SELECT SUM( preis ),
* SUM( menge ) FROM eban INTO ( @gs_eban-preis , @gs_eban-menge ) WHERE banfn = @pr_number.
***************************************************************************************************
"Getting PR Release stages details
SELECT SINGLE * FROM t16fs INTO @DATA(gs_stat) WHERE frggr = @gs_eban-frggr
AND frgsx = @gs_eban-frgst.
"Getting users to sent msg and approve reject option to their inbox
SELECT * FROM zmm_pr_wf_users INTO TABLE @DATA(gt_users) WHERE ekorg = @gs_eban-ekorg.
"to fill description
SELECT SINGLE ekotx FROM t024e INTO zmm_s_pr_wf_desc-gv_company
WHERE ekorg = gs_eban-ekorg.
* CONCATENATE '<H> Pr Company </>' ZMM_S_PR_WF_DESC-GV_COMPANY INTO ZMM_S_PR_WF_DESC-GV_COMPANY SEPARATED BY ':'.
SELECT banfn, preis, menge FROM eban INTO TABLE @DATA(gt_eban) WHERE banfn = @pr_number AND
loekz NE 'X'.
********************** Coded By Navaneethakrishnan 10.2.17************************************
DATA: lv_amount TYPE PREIS,
lv_amnt TYPE preis.
CLEAR: lv_amount,lv_amnt.
LOOP AT gt_eban INTO DATA(gw_eban).
lv_amount = gw_eban-preis * gw_eban-menge.
lv_amnt = lv_amnt + lv_amount.
ENDLOOP.
********************End of Code ********************************************************************
zmm_s_pr_wf_desc-gv_curr = gs_eban-waers.
IF gs_eban-menge IS NOT INITIAL.
zmm_s_pr_wf_desc-gv_amt = lv_amnt."gs_eban-preis * gs_eban-menge. "/ 5.8.15
ELSE.
zmm_s_pr_wf_desc-gv_amt = space.
ENDIF.
zmm_s_pr_wf_desc-gv_reim = gs_eban-bednr.
*
*
* DO .
* data flag.
* IF flag = '1'.
* exit.
* ENDIF.
* ENDDO.
SELECT SINGLE eknam FROM t024 INTO zmm_s_pr_wf_desc-gv_team
WHERE ekgrp = gs_eban-ekgrp.
IF gs_eban-knttp = 'N'.
SELECT SINGLE post1 FROM proj INTO zmm_s_pr_wf_desc-gv_project
WHERE pspnr IN ( SELECT p~psphi FROM aufk AS a JOIN prps AS p
ON a~pspel = p~pspnr WHERE aufnr IN
( SELECT nplnr FROM ebkn WHERE banfn = gs_eban-banfn AND bnfpo = gs_eban-bnfpo ) ).
ELSEIF gs_eban-knttp = 'Q' OR gs_eban-knttp = 'P'.
SELECT SINGLE post1 FROM proj INTO zmm_s_pr_wf_desc-gv_project
WHERE pspnr IN ( SELECT psphi FROM prps WHERE pspnr IN
( SELECT ps_psp_pnr FROM ebkn WHERE banfn = gs_eban-banfn AND bnfpo = gs_eban-bnfpo ) ).
ENDIF.
IF gs_eban-knttp = 'K'.
SELECT SINGLE ltext FROM cskt INTO zmm_s_pr_wf_desc-gv_project
WHERE kostl IN ( SELECT kostl FROM ebkn
WHERE banfn = gs_eban-banfn AND bnfpo = gs_eban-bnfpo )
* and KOSTL in ( select KOSTL from EBKN
* WHERE BANFN = gs_eban-banfn and BNFPO = gs_eban-BNFPO )
AND spras = 'EN'.
ENDIF.
id = 'B01'.
object = 'EBANH'.
name = gs_eban-banfn.
language = 'EN'.
CALL FUNCTION 'READ_TEXT'
EXPORTING
* CLIENT = SY-MANDT
id = id
language = language
name = name
object = object
TABLES
lines = lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT lines INTO lin .
* IF sy-subrc = 0.
APPEND lin-tdline TO gt_just.
CONCATENATE zmm_s_pr_wf_desc-gv_just lin-tdline INTO zmm_s_pr_wf_desc-gv_just.
CLEAR lin.
* ENDIF..
ENDLOOP.
"For Displaying reason entered in approval of Pr using workflow
REFRESH lines[].
object = 'EBANH'.
id = 'B02'.
language = 'EN'.
name = pr_number.
CALL FUNCTION 'READ_TEXT'
EXPORTING
client = sy-mandt
id = id
language = language
name = name
object = object
TABLES
lines = lines
EXCEPTIONS
id = 1
language = 2
name = 3
not_found = 4
object = 5
reference_check = 6
wrong_access_to_archive = 7
OTHERS = 8.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
LOOP AT lines INTO DATA(gs_lin).
SPLIT gs_lin-tdline AT ':' INTO gs_rea-f1 lv_string.
SPLIT lv_string AT '/' INTO gs_rea-f2 lv_string1 lv_string2 lv_string3.
CONCATENATE lv_string1 lv_string2 lv_string3 INTO gs_rea-f3 SEPARATED BY '/'.
APPEND gs_rea TO gt_rea.
CLEAR : lv_string1, lv_string2 ,lv_string3,lv_string.
ENDLOOP.
LOOP AT lines INTO DATA(wa_lin).
wa_reason-line = wa_lin-tdline.
APPEND wa_reason TO reasons.
ENDLOOP.
IF sy-subrc = 0.
wa_output-line = '<HTML><BODY><TABLE BORDER="2" ><TR><TH>Action Taken</TH><TH>Action Done by</TH>'.
APPEND wa_output TO output_table.
CLEAR: wa_output.
wa_output-line = '<TH>Remarks</TH></TR>'.
APPEND wa_output TO output_table.
CLEAR: wa_output.
IF gt_rea[] IS NOT INITIAL.
LOOP AT gt_rea INTO gs_rea.
CONCATENATE '<TR><TD>' gs_rea-f1 '</TD><TD>' gs_rea-f3 '</TD><TD>' gs_rea-f2 '</TD></TR>' INTO wa_output-line.
APPEND wa_output TO output_table.
CLEAR: wa_output, gs_rea.
ENDLOOP.
ENDIF.
wa_output-line = '</TABLE></BODY></HTML>'.
APPEND wa_output TO output_table.
CLEAR: wa_output.
ENDIF.
"Till here description filled
IF gs_eban-banpr <> '08'.
condition = 2.
"this read used to find creator or manager who is responsible for PR
* READ TABLE gt_users INTO DATA(gs_users) WITH KEY frgco = ' '.
CONCATENATE 'US' gs_eban-ernam INTO users_msg.
CONCATENATE 'Approve or reject PR' pr_number INTO lv_msg_dec SEPARATED BY ' '.
"below code dynamically build message at each level of release which we gona convey for above user(responsible person)
IF gs_eban-frgzu IS INITIAL.
"below read used to get user who is responsible for next level of PR release
READ TABLE gt_users INTO DATA(gs_users) WITH KEY frgco = gs_stat-frgc1."'C1'.
CONCATENATE 'US' gs_users-uname INTO users_opt.
CONCATENATE 'PR' pr_number 'Created' INTO lv_msg SEPARATED BY ' '.
ELSEIF gs_eban-frgzu = 'X'.
IF gs_stat-frgc2 IS INITIAL.
CLEAR condition.
CONCATENATE 'PR' pr_number 'Released' INTO lv_msg SEPARATED BY ' ' .
ELSE.
DESCRIBE TABLE reasons LINES DATA(lv_cnt).
READ TABLE reasons INTO DATA(lv_reasons) INDEX lv_cnt..
IF sy-subrc = 0.
IF lv_reasons-line CS 'Reject'.
condition = 2.
ELSE.
CLEAR condition.
ENDIF.
ELSE.
CLEAR condition.
ENDIF.
"below read used to get user who is responsible for next level of PR release
READ TABLE gt_users INTO gs_users WITH KEY frgco = gs_stat-frgc2."'C2'.
CONCATENATE 'US' gs_users-uname INTO users_opt.
CONCATENATE 'PR' pr_number 'Released at 1st Level' INTO lv_msg SEPARATED BY ' ' .
ENDIF.
ELSEIF gs_eban-frgzu = 'XX'.
CLEAR condition.
CONCATENATE 'PR' pr_number 'Released' INTO lv_msg SEPARATED BY ' ' .
ENDIF.
ELSE.
condition = 1.
CONCATENATE 'US' gs_eban-ernam INTO users_msg.
CONCATENATE 'US' gs_eban-ernam INTO users_opt.
CONCATENATE 'PR' pr_number 'Rejected' INTO lv_msg_dec SEPARATED BY ' ' .
CONCATENATE 'PR' pr_number 'Rejected' INTO lv_msg SEPARATED BY ' ' .
ENDIF.
REFRESH : it_objpack[],it_objbin[], it_objtxt[],it_reclist[].
CLEAR : doc_chng.
"To send Vendor Mails
IF gs_eban-frgkz IS INITIAL OR gs_eban-frgkz = 'R'.
CLEAR frgkz.
SELECT * FROM zmm_pr_create INTO TABLE @DATA(users_table1) WHERE ekorg = @gs_eban-ekorg.
LOOP AT users_table1 INTO DATA(gs_user).
CONCATENATE parameter 'EBAN-BANFN='
"'MEREQ_TOPLINE-BANFN_EXT='
pr_number ';' INTO parameter.
.
* IF sy-subrc = 0.
*** Mail Subject
CONCATENATE 'Pr Created' pr_number 'Now you can process PO' INTO doc_chng-obj_descr SEPARATED BY space.
*** Mail Contents
"table formation
CONCATENATE '<BR><B> Company-</B>' zmm_s_pr_wf_desc-gv_company '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
lv_amt = zmm_s_pr_wf_desc-gv_amt.
CONCATENATE '<BR> <B>Currency/Amount-</B>' zmm_s_pr_wf_desc-gv_curr '/' lv_amt '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR><B> Team-</B>' zmm_s_pr_wf_desc-gv_team '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR><B> Project/Cost center-</B>' zmm_s_pr_wf_desc-gv_project '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR><B> Justification-</B>' '' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
LOOP AT gt_just INTO DATA(line1).
wa_objtxt-line = line1.
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
ENDLOOP.
wa_objtxt-line = '</BR>' .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR><B> Client Reimbursement-</B>' zmm_s_pr_wf_desc-gv_reim '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR>' space '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR>' space '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
IF gt_rea[] IS NOT INITIAL.
CONCATENATE '<BR><B>' 'Remarks' '</B></BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR>' space '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE body_text
'<TABLE BORDER = "1" >' INTO body_text.
wa_objtxt-line = body_text.
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CLEAR: body_text.
CONCATENATE body_text
'<TR><TD><B>Action Taken</B></TD><TD><B>Action Done by</B></TD><TD><B>Remarks</B></TD>'
'</TR>'
INTO body_text.
CONDENSE body_text.
wa_objtxt-line = body_text.
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CLEAR: body_text.
LOOP AT gt_rea INTO gs_rea.
CONCATENATE '<TR><TD>' gs_rea-f1 '</TD><TD>' gs_rea-f3 '</TD><TD>' gs_rea-f2 '</TD></TR>' INTO body_text.
CONDENSE body_text.
wa_objtxt-line = body_text.
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CLEAR: body_text.
ENDLOOP.
ENDIF.
wa_objtxt-line = '</TABLE>' .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CLEAR: body_text.
"end of table formation
*** Creation of the entry for the document
DESCRIBE TABLE it_objtxt LINES tab_lines.
CLEAR wa_objpack-transf_bin.
wa_objpack-head_start = 1.
wa_objpack-head_num = 0.
wa_objpack-body_start = 1.
wa_objpack-body_num = tab_lines.
wa_objpack-doc_type = 'HTM'.
APPEND wa_objpack TO it_objpack.
lv_unam = gs_user-users.
*** create the shortcut content for the required transaction
CALL FUNCTION 'SWN_CREATE_SHORTCUT'
EXPORTING
i_transaction = 'ME53'
i_parameter = parameter
i_sysid = sy-sysid
i_client = sy-mandt
i_user = lv_unam
i_language = sy-langu
i_windowsize = 'NORMAL WINDOW'
IMPORTING
shortcut_string = content
EXCEPTIONS
inconsistent_parameters = 1
OTHERS = 2.
*** Populate attachment content
CLEAR : tab_lines, wa_objbin.
CONCATENATE content wa_objbin-line INTO wa_objbin-line.
APPEND wa_objbin TO it_objbin.
DESCRIBE TABLE it_objbin LINES tab_lines.
*** Creation of the entry for the compressed attachment
wa_objpack-transf_bin = 'X'. "Will get content from content_bin
wa_objpack-head_start = 1.
wa_objpack-head_num = 1.
wa_objpack-body_start = 1.
wa_objpack-body_num = tab_lines.
wa_objpack-doc_type = 'SAP'.
wa_objpack-obj_name = 'SAPSHORTCUTMAIL'.
wa_objpack-obj_descr = pr_number.
wa_objpack-doc_size = tab_lines * 255.
APPEND wa_objpack TO it_objpack.
*** target recipent(s)
CLEAR it_reclist.
FREE it_reclist.
* CONCATENATE 'US' gs_user-users INTO gs_user1.
* CONDENSE gs_user1.
* users = gs_user1."'USTESTABAP'.
* gs_user1-ekorg = gs_user-ekorg.
wa_reclist-receiver = gs_user-users. "&----- Assign SAP User Id
wa_reclist-rec_type = 'B'. "&-- Send to SAP Inbox
wa_reclist-com_type = 'INT'.
wa_reclist-notif_del = 'X'.
wa_reclist-notif_ndel = 'X'.
APPEND wa_reclist TO it_reclist.
*** Sending the document to recipients with the shortcut attachment
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_objpack
contents_bin = it_objbin
contents_txt = it_objtxt
receivers = it_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
*endif.
REFRESH : it_objpack[],it_objbin[], it_objtxt[],it_reclist[].
CLEAR : doc_chng.
ENDLOOP.
ENDIF.
IF condition <> 1 OR condition <> 2.
IF gs_eban-frgkz IS NOT INITIAL.
REFRESH : it_objpack[],it_objbin[], it_objtxt[],it_reclist[].
CLEAR : doc_chng.
CONCATENATE parameter 'EBAN-BANFN='
"'MEREQ_TOPLINE-BANFN_EXT='
pr_number ';' INTO parameter.
.
*** Mail Subject
doc_chng-obj_descr = lv_msg.
*** Mail Contents
"table formation
CONCATENATE '<BR><B> Company-</B>' zmm_s_pr_wf_desc-gv_company '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
lv_amt = zmm_s_pr_wf_desc-gv_amt.
CONCATENATE '<BR> <B>Currency/Amount-</B>' zmm_s_pr_wf_desc-gv_curr '/' lv_amt '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR><B> Team-</B>' zmm_s_pr_wf_desc-gv_team '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR><B> Project/Cost center-</B>' zmm_s_pr_wf_desc-gv_project '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR><B> Justification-</B>' zmm_s_pr_wf_desc-gv_just INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
LOOP AT gt_just INTO DATA(line).
wa_objtxt-line = line.
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
ENDLOOP.
wa_objtxt-line = '</BR>' .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR><B> Client Reimbursement-</B>' zmm_s_pr_wf_desc-gv_reim '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR>' space '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR>' space '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
IF gt_rea[] IS NOT INITIAL.
CONCATENATE '<BR><B>' 'Remarks' '</B></BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE '<BR>' space '</BR>' INTO wa_objtxt-line .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CONCATENATE body_text
'<TABLE BORDER = "1" >' INTO body_text.
wa_objtxt-line = body_text.
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CLEAR: body_text.
CONCATENATE body_text
'<TR><TD><B>Action Taken</B></TD><TD><B>Action Done by</B></TD><TD><B>Remarks</B></TD>'
'</TR>'
INTO body_text.
CONDENSE body_text.
wa_objtxt-line = body_text.
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CLEAR: body_text.
LOOP AT gt_rea INTO gs_rea.
CONCATENATE '<TR><TD>' gs_rea-f1 '</TD><TD>' gs_rea-f3 '</TD><TD>' gs_rea-f2 '</TD></TR>' INTO body_text.
CONDENSE body_text.
wa_objtxt-line = body_text.
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CLEAR: body_text.
ENDLOOP.
ENDIF.
wa_objtxt-line = '</TABLE>' .
APPEND wa_objtxt TO it_objtxt." TO it_message.
CLEAR: wa_objtxt.
CLEAR: body_text.
"end of table formation
*** Creation of the entry for the document
DESCRIBE TABLE it_objtxt LINES tab_lines.
CLEAR wa_objpack-transf_bin.
wa_objpack-head_start = 1.
wa_objpack-head_num = 0.
wa_objpack-body_start = 1.
wa_objpack-body_num = tab_lines.
wa_objpack-doc_type = 'HTM'.
APPEND wa_objpack TO it_objpack.
DATA(LV_LENGTH) = STRLEN( users_msg ).
lv_unam = users_msg+2(LV_LENGTH).
*** create the shortcut content for the required transaction
CALL FUNCTION 'SWN_CREATE_SHORTCUT'
EXPORTING
i_transaction = 'ME53'
i_parameter = parameter
i_sysid = sy-sysid
i_client = sy-mandt
i_user = lv_unam
i_language = sy-langu
i_windowsize = 'NORMAL WINDOW'
IMPORTING
shortcut_string = content
EXCEPTIONS
inconsistent_parameters = 1
OTHERS = 2.
*** Populate attachment content
CLEAR : tab_lines, wa_objbin.
CONCATENATE content wa_objbin-line INTO wa_objbin-line.
APPEND wa_objbin TO it_objbin.
DESCRIBE TABLE it_objbin LINES tab_lines.
*** Creation of the entry for the compressed attachment
wa_objpack-transf_bin = 'X'. "Will get content from content_bin
wa_objpack-head_start = 1.
wa_objpack-head_num = 1.
wa_objpack-body_start = 1.
wa_objpack-body_num = tab_lines.
wa_objpack-doc_type = 'SAP'.
wa_objpack-obj_name = 'SAPSHORTCUTMAIL'.
wa_objpack-obj_descr = pr_number.
wa_objpack-doc_size = tab_lines * 255.
APPEND wa_objpack TO it_objpack.
*** target recipent(s)
CLEAR it_reclist.
FREE it_reclist.
* CONCATENATE 'US' gs_user-users INTO gs_user1.
* CONDENSE gs_user1.
* users = gs_user1."'USTESTABAP'.
* gs_user1-ekorg = gs_user-ekorg.
wa_reclist-receiver = lv_unam. "&----- Assign SAP User Id
wa_reclist-rec_type = 'B'. "&-- Send to SAP Inbox
wa_reclist-com_type = 'INT'.
wa_reclist-notif_del = 'X'.
wa_reclist-notif_ndel = 'X'.
APPEND wa_reclist TO it_reclist.
*** Sending the document to recipients with the shortcut attachment
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_objpack
contents_bin = it_objbin
contents_txt = it_objtxt
receivers = it_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
*endif.
REFRESH : it_objpack[],it_objbin[], it_objtxt[],it_reclist[].
CLEAR : doc_chng.
* ENDLOOP.
ENDIF.
ENDIF.
ENDMETHOD.
***********************************************************************************
method APPROVE_PR.
data : REL_STATUS_NEW type BAPIMMPARA-REL_STATUS,
REL_INDICATOR_NEW type BAPIMMPARA-REL_IND,
RETURN type TABLE OF BAPIRETURN,
gv_relcod TYPE FRGCO.
select SINGLE * FROM eban INTO @data(gs_eban) where banfn = @pr_number.
IF gs_eban is NOT INITIAL.
select * from t16fs INTO TABLE @data(gt_rel)
WHERE frggr = @gs_eban-frggr
and frgsx = @gs_eban-frgst.
ENDIF.
READ TABLE gt_rel INTO data(gs_rel) with key frggr = gs_eban-frggr
frgsx = gs_eban-frgst.
*
* DO .
* data flag.
* IF flag = 'x'.
* exit.
* ENDIF.
* ENDDO.
IF gs_eban-frgzu is INITIAL .
gv_relcod = gs_rel-FRGC1.
else.
gv_relcod = gs_rel-FRGC2.
ENDIF.
CALL FUNCTION 'BAPI_REQUISITION_RELEASE_GEN'
EXPORTING
number = pr_number
rel_code = gv_relcod
NO_COMMIT_WORK = ' '
IMPORTING
REL_STATUS_NEW = REL_STATUS_NEW
REL_INDICATOR_NEW = REL_INDICATOR_NEW
TABLES
RETURN = RETURN
.
"To insert approval text for Pr
CALL METHOD zmm_cl_pr_det_workflow=>reason_insert
EXPORTING
workitemid = workitemid
pr_number = pr_number
USERS_OPT = USERS_OPT
action = 'A'
.
endmethod.
*************************************************************************************
method REJECT_PR.
DATA: container type TABLE OF swr_cont ,
gt_eban type TABLE OF ueban ,
gt_ebkn type TABLE OF uebkn ,
it_eban type TABLE OF ueban ,
it_ebkn type TABLE OF uebkn ,
object_key TYPE swr_struct-object_key,
item_numc TYPE numc05,
BAPIRET TYPE BAPIRET2,
wa_con TYPE swr_cont,
MESSAGE_LINES type TABLE OF SWR_MESSAG,
MESSAGE_STRUCT type TABLE OF SWR_MSTRUC.
*DO .
*DATA flag.
*IF flag = 'x'.
*exit.
*ENDIF.
*ENDDO.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_eban
FROM eban
WHERE banfn = pr_number.
*AND bnfpo = item.
SELECT *
INTO CORRESPONDING FIELDS OF TABLE gt_ebkn
FROM ebkn
WHERE banfn = pr_number.
*AND bnfpo = item.
it_eban = gt_eban.
it_ebkn = gt_ebkn.
LOOP AT gt_eban INTO data(gs_eban).
gs_eban-kz = 'U'.
gs_eban-banpr = '08'.
MODIFY gt_eban FROM gs_eban TRANSPORTING kz banpr .
ENDLOOP.
CALL FUNCTION 'ME_UPDATE_REQUISITION'
TABLES
xeban = gt_eban
xebkn = gt_ebkn
yeban = it_eban
yebkn = it_ebkn.
CALL FUNCTION 'ME_UPDATE_REQUISITION_CHNGDOC'
TABLES
xeban = gt_eban
xebkn = gt_ebkn
yeban = it_eban
yebkn = it_ebkn.
CALL FUNCTION 'BAPI_TRANSACTION_COMMIT'
EXPORTING
WAIT = 'X'
IMPORTING
RETURN = BAPIRET
.
*wa_con-element = 'RELEASECODE'.
*wa_con-value = REL_CODE.
*append wa_con to container.
*item_numc = item.
*concatenate number item_numc into object_key.
CALL METHOD zmm_cl_pr_det_workflow=>reason_insert
EXPORTING
workitemid = workitemid
pr_number = pr_number
USERS_OPT = USERS_OPT
Action = 'R'
.
object_key = pr_number.
CALL FUNCTION 'SAP_WAPI_CREATE_EVENT'
EXPORTING
object_type = 'BUS2105'
object_key = object_key
event = 'REJECTION_START'
TABLES
input_container = container
message_lines = message_lines
message_struct = message_struct.
endmethod.
***********************************************************************************
method REASON_INSERT.
data : ATTACHMENTS type TABLE OF SWR_OBJECT,
MESSAGE_LINES type TABLE OF SWR_MESSAG,
MESSAGE_STRUCT type TABLE OF SWR_MSTRUC,
RETURN_CODE type SY-SUBRC,
OBJECT_ID type SOODK,
OBJCONT type TABLE OF SOLI,
lv_msgtyp TYPE char10,
lv_msgtyp1 TYPE char255,"used to split string to avoide numeric values
gv_len TYPE char255,
HEADER TYPE THEAD,
LINES type TABLE OF TLINE,
wa_line TYPE tline.
CALL FUNCTION 'SAP_WAPI_GET_ATTACHMENTS'
EXPORTING
workitem_id = workitemid
USER = SY-UNAME
LANGUAGE = SY-LANGU
COMMENT_SEMANTIC_ONLY = ' '
IMPORTING
RETURN_CODE = RETURN_CODE
TABLES
ATTACHMENTS = ATTACHMENTS
MESSAGE_LINES = MESSAGE_LINES
MESSAGE_STRUCT = MESSAGE_STRUCT
.
IF RETURN_CODE = 0.
READ TABLE ATTACHMENTS INTO data(wa_attach) INDEX 1.
IF Action = 'A'.
lv_msgtyp = 'Approved'.
ELSe.
lv_msgtyp = 'Reject'.
ENDIF.
REPLACE 'SOFM' WITH '' INto wa_attach-object_id.
CONDENSE wa_attach-object_id NO-GAPS.
object_id-objtp = wa_attach-object_id+17(3).
object_id-objyr = wa_attach-object_id+20(2).
object_id-objno = wa_attach-object_id+22(12).
ENDIF.
*
*do.
* data: flag(1).
* if flag = 1.
* exit.
* endif.
*enddo.
CALL FUNCTION 'SO_OBJECT_GET_CONTENT'
EXPORTING
object_id = object_id
tables
objcont = objcont
EXCEPTIONS
ARCHIVE_ERROR = 1
OBJECT_NOT_EXIST = 2
OTHERS = 3
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
* READ TABLE objcont INTO data(wa_objcont) INDEX 1.
* if sy-subrc = 0.
* gv_len = strlen( wa_objcont-line ).
* endif.
header-tdobject = 'EBANH'.
header-tdid = 'B02'.
header-tdspras = 'EN'.
header-tdname = pr_number.
CALL FUNCTION 'READ_TEXT'
EXPORTING
CLIENT = SY-MANDT
id = header-tdid
language = header-tdspras
NAME = header-tdname
OBJECT = header-tdobject
TABLES
lines = lines
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
NOT_FOUND = 4
OBJECT = 5
REFERENCE_CHECK = 6
WRONG_ACCESS_TO_ARCHIVE = 7
OTHERS = 8
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
data(users) = users_opt.
REPLACE 'US' WITH '' INTO users.
CONDENSE users.
select SINGLE NAME_LAST ,
NAME_text from adrp INTO @data(ADDRESS)
WHERE PERSNUMBER in ( select PERSNUMBER from usr21 where BNAME = @users ).
data(name) = ADDRESS-NAME_text.
IF name is INITIAL.
name = ADDRESS-NAME_LAST.
ENDIF.
***
*DO .
* data:fin.
* IF fin = '1'.
* exit.
* ENDIF.
*
*ENDDO.
if objcont is NOT INITIAL.
DESCRIBE TABLE objcont LINES DATA(cnt).
LOOP AT objcont INTO data(wa_objcont).
wa_line-tdformat = '*'.
if not wa_attach-def_attrib cs 'User Comments'.
* if sy-tabix = 1.
gv_len = strlen( wa_objcont-line ).
gv_len = gv_len - 3.
if sy-tabix = 1 and cnt = 1.
CONCATENATE lv_msgtyp wa_objcont-line+3(gv_len) INTO wa_line-tdline SEPARATED BY ':'.
CONCATENATE wa_line-tdline+0(100) name sy-datum sy-uzeit INTO wa_line-tdline SEPARATED BY '/'.
elseif sy-tabix = cnt.
* CONCATENATE lv_msgtyp wa_objcont-line+3(gv_len) INTO wa_line-tdline." SEPARATED BY ':'.
CONCATENATE wa_line-tdline wa_objcont-line+3(gv_len) INTO wa_line-tdline.
CONCATENATE wa_line-tdline+0(100) name sy-datum sy-uzeit INTO wa_line-tdline SEPARATED BY '/'.
elseif sy-tabix = 1.
CONCATENATE lv_msgtyp wa_objcont-line+3(gv_len) INTO wa_line-tdline SEPARATED BY ':'.
* CONCATENATE wa_line-tdline+0(100) name sy-datum sy-uzeit INTO wa_line-tdline SEPARATED BY '/'.
else.
CONCATENATE wa_line-tdline wa_objcont-line+3(gv_len) INTO wa_line-tdline." SEPARATED BY ':'.
endif.
* else.
* wa_line-tdline = wa_objcont-line.
* endif.
else.
* wa_line-tdline = wa_objcont-line.
CONCATENATE lv_msgtyp wa_objcont-line INTO wa_line-tdline SEPARATED BY ':'.
CONCATENATE wa_line-tdline name sy-datum sy-uzeit INTO wa_line-tdline SEPARATED BY '/'.
endif.
ENDLOOP.
append wa_line to lines.
CALL FUNCTION 'SAVE_TEXT'
EXPORTING
CLIENT = SY-MANDT
header = header
savemode_direct = 'X'
tables
lines = lines
EXCEPTIONS
ID = 1
LANGUAGE = 2
NAME = 3
OBJECT = 4
OTHERS = 5
.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
endif.
endmethod.
****************************************************************************************************
method VMT.
*DO .
*data fi.
*if fi = 1.
* exit.
* endif.
*ENDDO.
DATA: doc_chng type sodocchgi1.
DATA: tab_lines type sy-tabix,
body_start type sy-tabix.
DATA: it_objtxt type TABLE OF solisti1 .
DATA: wa_objtxt type solisti1 .
DATA: it_objpack type TABLE OF sopcklsti1 .
DATA: wa_objpack type sopcklsti1 .
DATA: it_objbin type TABLE OF solisti1 .
DATA: wa_objbin type solisti1 .
DATA: it_reclist type TABLE OF somlreci1 .
DATA: wa_reclist type somlreci1 .
*DATA: it_shortcut_param type zst_shortcut_par OCCURS 0 WITH HEADER LINE.
DATA: content TYPE string.
data : text TYPE bcsy_text,
body_text TYPE so_text255.
DESCRIBE TABLE it_objtxt LINES tab_lines.
CLEAR wa_objpack-transf_bin.
wa_objpack-head_start = 1.
wa_objpack-head_num = 0.
wa_objpack-body_start = 1.
wa_objpack-body_num = tab_lines.
wa_objpack-doc_type = 'HTM'.
APPEND wa_objpack to it_objpack.
DESCRIBE TABLE it_objbin LINES tab_lines.
*** Creation of the entry for the compressed attachment
wa_objpack-transf_bin = 'X'. "Will get content from content_bin
wa_objpack-head_start = 1.
wa_objpack-head_num = 1.
wa_objpack-body_start = 1.
wa_objpack-body_num = tab_lines.
wa_objpack-doc_type = 'SAP'.
wa_objpack-obj_name = 'SAPSHORTCUTMAIL'.
wa_objpack-obj_descr = pr_number.
wa_objpack-doc_size = tab_lines * 255.
APPEND wa_objpack to it_objpack.
data : parameter TYPE TEXT255 .
wa_reclist-receiver = 'TESTABAP'."gs_user-users'. "&----- Assign SAP User Id
wa_reclist-rec_type = 'B'. "&-- Send to SAP Inbox
wa_reclist-com_type = 'INT'.
wa_reclist-notif_del = 'X'.
wa_reclist-notif_ndel = 'X'.
APPEND wa_reclist to it_reclist.
CONCATENATE 'Pr Created' pr_number 'pls check' INTO doc_chng-obj_descr SEPARATED BY space.
*** Sending the document to recipients with the shortcut attachment
CALL FUNCTION 'SO_NEW_DOCUMENT_ATT_SEND_API1'
EXPORTING
document_data = doc_chng
put_in_outbox = 'X'
commit_work = 'X'
TABLES
packing_list = it_objpack
contents_bin = it_objbin
contents_txt = it_objtxt
receivers = it_reclist
EXCEPTIONS
too_many_receivers = 1
document_not_sent = 2
operation_no_authorization = 4
OTHERS = 99.
*endif.
refresh : it_objpack[],it_objbin[], it_objtxt[],it_reclist[].
CLEAR : doc_chng.
endmethod.
*****************************************************************************
No comments:
Post a Comment