0% found this document useful (0 votes)
29 views

PR Data Send

Uploaded by

bablu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views

PR Data Send

Uploaded by

bablu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

METHOD mjpro_data_send.

DATA : lw_message TYPE string.


DATA : i_s_log TYPE bal_s_log,
i_s_msg TYPE bal_s_msg,
wa_data TYPE zpr_item_data_send,
lt_data TYPE zmjpro_prdata,
lt_po_data TYPE zpo_srvdt_posender.
DATA:lv_rel_flag TYPE c,
lv_del_flag TYPE c,
lv_rel_flag1 TYPE c,
lv_del_flag1 TYPE c,
lv_po_derel TYPE c.
DATA:lt_source TYPE zt_mjpro_unrelease_pr_response,
lt_data_UNREL_PR TYPE zt_unrelease_pr_list,
lv_bnfpo TYPE c LENGTH 5,
lv_data TYPE string.

TYPES:BEGIN OF ty_po_derele,
client_key TYPE sy-uname,
Legacy_Po_Number TYPE ekko-ebeln,
status TYPE c LENGTH 1,
END OF ty_po_derele.

DATA:it_po_derel TYPE TABLE OF ty_po_derele,


wa_po_derel TYPE ty_po_derele,
it_zmjprounrelease TYPE STANDARD TABLE OF zmjprounrelease,
is_response TYPE zmjprodt_unrelease_pr_response,
is_zmjprounrelease TYPE zmjprounrelease,
lv_banfn TYPE banfn.
*CLEAR : url, token.
* DATA: url TYPE string.
* url = 'https://btp-is-a5ztyfq4.it-cpi021-rt.cfapps.in30.hana.ondemand.com/
http/PRimport'.
* DATA(token) = 'sb-fba1fa64-a5bf-4694-b090-7daa1ae82de9!b6570|it-rt-btp-is-
a5ztyfq4!b148'.

***CALL METHOD cl_http_client=>create_by_destination


*** EXPORTING
*** destination = 'BTP-API' " Logical destination
(specified in function call)
*** IMPORTING
*** client = DATA(o_client1) " HTTP Client
Abstraction
*** EXCEPTIONS
*** argument_not_found = 1 " Connection parameter
(destination) not available
*** destination_not_found = 2 " Destination was not found
*** destination_no_authority = 3 " No Authorization to Use HTTP
Destination
*** plugin_not_active = 4 " HTTP/HTTPS communication not
available
*** internal_error = 5 " Internal error (e.g. name
too long)
*** oa2c_set_token_error = 6 " General error when setting
the OAuth token
*** oa2c_missing_authorization = 7
*** oa2c_invalid_config = 8
*** oa2c_invalid_parameters = 9
*** oa2c_invalid_scope = 10
*** oa2c_invalid_grant = 11
*** oa2c_secstore_adm = 12 " Error accessing secure store
administration
*** others = 13
*** .
***IF SY-SUBRC <> 0.
**** MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
**** WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
***ENDIF.

CALL METHOD cl_http_client=>create_by_url


EXPORTING
url = im_url "url " URL
* proxy_host = " Logical destination
(specified in function call)
* proxy_service = " Port Number
* ssl_id = " SSL Identity
* sap_username = " ABAP System, User Logon
Name
* sap_client = " R/3 system (client number
from logon)
* proxy_user = " Proxy user
* proxy_passwd = " Proxy password
* do_not_use_client_cert = abap_false " SSL identity not used for
logon
* use_scc = abap_false " Connection needed for SAP
Cloud Connector
* scc_location_id = " Location ID for SAP Cloud
Connector
* oauth_profile = " OAuth 2.0 client profile
* oauth_config = " OAuth 2.0 client
configuration
* ssl_hostname =
* ssl_cipher_suites =
* ssl_sni_disabled = abap_false
IMPORTING
client = DATA(o_client) " HTTP Client
Abstraction
EXCEPTIONS
argument_not_found = 1 " Communication parameter
(host or service) not available
plugin_not_active = 2 " HTTP/HTTPS communication
not available
internal_error = 3 " Internal error (e.g. name
too long)
pse_not_found = 4 " PSE not found
pse_not_distrib = 5 " PSE not distributed
pse_errors = 6 " General PSE error
oa2c_set_token_error = 7 " General error when setting
OAuth token
oa2c_missing_authorization = 8
oa2c_invalid_config = 9
oa2c_invalid_parameters = 10
oa2c_invalid_scope = 11
oa2c_invalid_grant = 12
OTHERS = 13.
IF sy-subrc <> 0.

o_client->close( ).

* MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO


* WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
ENDIF.
IF o_client IS BOUND.
"Set authprization
*** SELECT SINGLE * FROM zhcit_url_id INTO wa_url_id WHERE url_name EQ
'IRN' AND gltgv LE sy-datum AND gltgb GE sy-datum.
IF sy-subrc = 0.
DATA: id TYPE string.
DATA: passcode TYPE string.
id = im_token. "token.
passcode = im_passcode. "'fa5ad910-fa70-40f3-8d63-
ab218dccda76$cOJkGNwyO5cqnnTzdnsB1ovWi2VAHBAo2sRGhyLtiB4='.
CALL METHOD o_client->authenticate
EXPORTING
username = id
password = passcode.
ELSE.
MESSAGE : 'Please maintain HCI authorization' TYPE 'E'.
ENDIF.
* "HEADER FIELDS
* o_client->request->set_header_field(
* EXPORTING
* name = 'token'
* value = token ).
o_client->request->set_header_field(
EXPORTING
name = 'customerid'
value = '1234' ).
o_client->request->set_header_field(
EXPORTING
name = 'Content-Type'
value = 'application/json' ). "lv_custid
* it_body = lt_kna1.
CALL METHOD /ui2/cl_json=>serialize
EXPORTING
* data = it_body
data = it_data
compress = abap_false
pretty_name = /ui2/cl_json=>pretty_mode-camel_case
* PRETTY_NAME = 'C'
RECEIVING
r_json = DATA(gs_json).

*concatenate '[' gs_json ']' INTO gs_json.


"Begin of addition by Simona on 27-06-2024
CALL METHOD me->replace_char
EXPORTING
spchar_string = '<(>'
ofset = 0
CHANGING
string = gs_json.

CALL METHOD me->replace_char


EXPORTING
spchar_string = '<)>'
ofset = 0
CHANGING
string = gs_json.
"End of addition by Simona on 27-06-2024
IF sy-subrc IS INITIAL.

* it_po_derel = it_data.
* wa_po_derel = it_po_derel[ 1 ].
* CONCATENATE wa_po_derel-client_key
CLEAR:lv_rel_flag,lv_del_flag.
IMPORT lv_rel_flag TO lv_rel_flag FROM MEMORY ID 'RELE'. " PR Release
IMPORT lv_del_flag TO lv_del_flag FROM MEMORY ID 'DERELE'." PR De-
Release
IMPORT lv_rel_flag1 TO lv_rel_flag1 FROM MEMORY ID 'REL'. " PO Release
IMPORT lv_po_derel TO lv_po_derel FROM MEMORY ID 'PODERE'. " PO De-
Release
IF lv_rel_flag = 'X'.
CONCATENATE '[' gs_json ']' INTO gs_json.
ENDIF.
IF lv_del_flag = 'X'.
REPLACE SUBSTRING '[{"prNumberList":' IN gs_json WITH '{ "prNumberList":
['.
DATA(lv_strlen) = strlen( gs_json ).
lv_strlen = lv_strlen - 2.
CONCATENATE gs_json+0(lv_strlen) ']}' INTO gs_json.
ENDIF.
IF lv_rel_flag1 = 'X'.
IF gs_json CS '"poAmendmentFlag": "N",'.
REPLACE SUBSTRING '"bidderAcceptanceFlag": "Y",' IN gs_json WITH ''.
ENDIF.
REPLACE SUBSTRING '"erpPoTermsAndConditionDat": "null",' IN gs_json WITH
'"erpPOTermsAndConditionDataList": null,'.
REPLACE SUBSTRING '"erpPoTermsAndConditionDa1": "null",' IN gs_json WITH
'"erpPOTermsAndConditionDataList2": null,'.
REPLACE SUBSTRING '"erpPoRequiredAttachmentDat": "null"' IN gs_json WITH
'"erpPORequiredAttachmentDataList": null'.
* REPLACE SUBSTRING '{"fileUrl": "","fileName": "","additionalInfo1":
"","documentId": ""}' IN gs_json WITH ''.
REPLACE SUBSTRING 'erpPoHeaderData' IN gs_json WITH 'erpPOHeaderData'.
REPLACE SUBSTRING 'erpPoVendorData' IN gs_json WITH 'erpPOVendorData'.
REPLACE SUBSTRING 'erpPoItemDataList' IN gs_json WITH
'erpPOItemDataList'.
REPLACE SUBSTRING 'erpPoAttachmentDataList' IN gs_json WITH
'erpPOAttachmentDataList'.
REPLACE SUBSTRING 'erpPoTermsConditionList' IN gs_json WITH
'erpPOTermsAndConditionDataList'.
* REPLACE SUBSTRING '"erpPOVendorData": [{' IN gs_json WITH
'"erpPOVendorData": {'.
* REPLACE SUBSTRING '}],"erpPOItemDataList":' IN gs_json WITH
'},"erpPOItemDataList"'.
CONCATENATE '[' gs_json ']' INTO gs_json.
ENDIF.

ENDIF.
* PERFORM format_json.
DATA: lo_http_req TYPE REF TO if_http_request.
* create object lo_http_req.
lo_http_req = o_client->request.
lo_http_req->append_cdata(
EXPORTING
data = gs_json ).

** "Set Timeout
CALL METHOD o_client->send
* EXPORTING
* timeout = CO_TIMEOUT_DEFAULT
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
http_invalid_timeout = 4
OTHERS = 5.
* "Read Response
CALL METHOD o_client->receive
EXCEPTIONS
http_communication_failure = 1
http_invalid_state = 2
http_processing_failed = 3
OTHERS = 4.
IF sy-subrc = 0.
o_client->response->get_status(
IMPORTING
code = DATA(lv_http_status) " HTTP Status Code
reason = DATA(lv_status_text) " HTTP status description
).
ENDIF.
DATA(lr_email) = NEW zcl_mj_integration_dpc( ).
IF lv_http_status = 200. " Sending Status Code
DATA: ls_batch_save_ui TYPE bpc_loc_s_batch_save_ui.
DATA(lv_result) = o_client->response->get_cdata( ). " Getting Receiving
Status Code and Message.
IF lv_result IS NOT INITIAL.
* IF im_url = 'https://btp-is-a5ztyfq4.it-cpi021-
rt.cfapps.in30.hana.ondemand.com/http/PRimport'.
IF lv_rel_flag = 'X'.
IF it_data IS NOT INITIAL.
lt_data = it_data.
ENDIF.

IF lv_result CS '"Return_Code":"200"'.
lw_message = lv_result.
REPLACE '"Return_Code":"200",' IN lw_message WITH ' '.
REPLACE '"Return_Message":' IN lw_message WITH ' '.

i_s_log-extnumber = lt_data-pr_number."WA_DATA-pr_Original_No.
i_s_log-object = 'ZPCBLSRM'. "Object name
i_s_log-subobject = 'ZPRLOG'. "Object name
i_s_msg-msgty = 'S'. "Message type
i_s_msg-msgid = 'ZPCBLSRM'. "Message id
i_s_msg-msgno = '000'. "Message number
CALL METHOD me->slg_log_create
EXPORTING
i_s_log = i_s_log
i_s_msg = i_s_msg
message = lw_message.
ELSE.
lw_message = lv_result.
REPLACE '"Return_Code":"500",' IN lw_message WITH ' '.
REPLACE '"Return_Message":' IN lw_message WITH ' '.

i_s_log-extnumber = lt_data-pr_number."WA_DATA-pr_Original_No.
i_s_log-object = 'ZPCBLSRM'. "Object name
i_s_log-subobject = 'ZPRLOG'. "Object name
i_s_msg-msgty = 'E'. "Message type
i_s_msg-msgid = 'ZPCBLSRM'. "Message id
i_s_msg-msgno = '000'. "Message number
CALL METHOD me->slg_log_create
EXPORTING
i_s_log = i_s_log
i_s_msg = i_s_msg
message = lw_message.
** If any Error Occured during PR details sent to mjPRO Email Notification to be
sent.

lr_email->send_email(
EXPORTING
i_s_log = i_s_log
i_s_msg = i_s_msg
message = lw_message
email_for = 'PR_SENT'
).

ENDIF.
* ELSEIF im_url = 'https://btp-is-a5ztyfq4.it-cpi021-
rt.cfapps.in30.hana.ondemand.com/http/PRunreleasePR'. "Derelease PR response
ELSEIF lv_del_flag = 'X'.
IF lv_result CP '[]'.
lt_data_UNREL_PR = it_data.
i_s_log-extnumber = lt_data_UNREL_PR[ 1 ]-pr_number_list.
CONCATENATE 'Derelease PR No-' i_s_log-extnumber ' RFQ Not created'
INTO lw_message SEPARATED BY ' '.
* i_s_log-extnumber = lt_data-pr_number.
i_s_log-object = 'ZPCBLSRM'. "Object name
i_s_log-subobject = 'ZPRLOG'. "Object name
i_s_msg-msgty = 'I'. "Message type
i_s_msg-msgid = 'ZPCBLSRM'. "Message id
i_s_msg-msgno = '000'. "Message number
CALL METHOD me->slg_log_create
EXPORTING
i_s_log = i_s_log
i_s_msg = i_s_msg
message = lw_message.
ELSE.

CALL METHOD /ui2/cl_json=>deserialize


EXPORTING
json = lv_result " JSON string
* jsonx = " JSON XString
pretty_name = /ui2/cl_json=>pretty_mode-extended "
Pretty Print property names
* assoc_arrays = " Deserialize associative
array as tables with unique keys
* assoc_arrays_opt = " Optimize rendering of name
value maps
* name_mappings = " ABAP<->JSON Name Mapping
Table
* conversion_exits = " Use DDIC conversion exits
on deserialize of values
* hex_as_base64 = " Serialize hex values as
base64
CHANGING
data = lt_source. " Data to serialize
IF sy-subrc = 0 .
EXPORT lt_source FROM lt_source TO MEMORY ID 'DERELEASE'.
lv_banfn = lt_source[ 1 ]-document_no.
LOOP AT lt_source INTO is_response.
MOVE-CORRESPONDING is_response TO is_zmjprounrelease.
is_zmjprounrelease-banfn = is_response-document_no.
is_zmjprounrelease-bnfpo = is_response-serial_no.
APPEND is_zmjprounrelease TO it_zmjprounrelease.
ENDLOOP.
select SINGLE pstyp FROM eban INTO @data(LV_PSTYP) WHERE banfn =
@lv_banfn AND pstyp = '9'.
IF sy-subrc is INITIAL.
DELETE it_zmjprounrelease WHERE parent_material_code NE '0'.
ENDIF.

EXPORT it_zmjprounrelease FROM it_zmjprounrelease TO MEMORY ID


'MJ_UPR'.
CALL FUNCTION 'ZMJPRO_UPDATE_ZMJPROUNRELEASE' DESTINATION 'NONE'
EXPORTING
banfn = lv_banfn
CHANGING
t_zmjprounrelease = it_zmjprounrelease.

ENDIF.
* lw_message = lv_result.
IF lt_source IS NOT INITIAL .
SORT lt_source BY document_no serial_no ASCENDING.
LOOP AT lt_source INTO DATA(LS_source).
lv_bnfpo = ls_source-serial_no.
SHIFT lv_bnfpo LEFT DELETING LEADING '0'.
* IF lw_message is INITIAL.
* CONCATENATE lv_bnfpo ',' INTO lw_message.
* else.
CONCATENATE lw_message lv_bnfpo INTO lw_message SEPARATED BY ','.
* ENDIF.
ENDLOOP.
ENDIF.
REPLACE FIRST OCCURRENCE OF ',' IN lw_message WITH '' .
i_s_log-extnumber = lt_source[ 1 ]-document_no."WA_DATA-
pr_Original_No.
CONCATENATE 'PR.No-' i_s_log-extnumber 'Items' lw_message 'RFQ
created' INTO lw_message SEPARATED BY ' ' .
i_s_log-object = 'ZPCBLSRM'. "Object name
i_s_log-subobject = 'ZPRLOG'. "Object name
i_s_msg-msgty = 'S'. "Message type
i_s_msg-msgid = 'ZPCBLSRM'. "Message id
i_s_msg-msgno = '000'. "Message number
CALL METHOD me->slg_log_create
EXPORTING
i_s_log = i_s_log
i_s_msg = i_s_msg
message = lw_message.
ENDIF.

ELSEIF lv_rel_flag1 = 'X'.


IF it_data IS NOT INITIAL.
lt_po_data = it_data.
ENDIF.
IF lv_result CS '"Return_Code":"200"'.

lw_message = lv_result.
REPLACE '"Return_Code":"200",' IN lw_message WITH ' '.
REPLACE '"Return_Message":' IN lw_message WITH ' '.

i_s_log-extnumber = lt_po_data-po_number."WA_DATA-pr_Original_No.
i_s_log-object = 'ZPCBLSRM'. "Object name
i_s_log-subobject = 'ZPOLOG'. "Object name
i_s_msg-msgty = 'I'. "Message type
i_s_msg-msgid = 'ZPCBLSRM'. "Message id
i_s_msg-msgno = '000'. "Message number
CALL METHOD me->slg_log_create
EXPORTING
i_s_log = i_s_log
i_s_msg = i_s_msg
message = lw_message.

ELSE.
lw_message = lv_result.
REPLACE '"Return_Code":"500",' IN lw_message WITH ' '.
REPLACE '"Return_Message":' IN lw_message WITH ' '.
i_s_log-extnumber = lt_po_data-po_number."WA_DATA-pr_Original_No.
i_s_log-object = 'ZPCBLSRM'. "Object name
i_s_log-subobject = 'ZPOLOG'. "Object name
i_s_msg-msgty = 'E'. "Message type
i_s_msg-msgid = 'ZPCBLSRM'. "Message id
i_s_msg-msgno = '000'. "Message number
CALL METHOD me->slg_log_create
EXPORTING
i_s_log = i_s_log
i_s_msg = i_s_msg
message = lw_message.
ENDIF.
ELSEIF lv_po_derel = 'X'.
IF lv_result CS '"Return_Code":"200"'.
IF it_data IS NOT INITIAL.
it_po_derel = it_data.
ENDIF.
lw_message = lv_result.
REPLACE '"Return_Code":"200",' IN lw_message WITH ' '.
REPLACE '"Return_Message":' IN lw_message WITH ' '.
READ TABLE it_po_derel INTO wa_po_derel INDEX 1.
i_s_log-extnumber = WA_po_derel-Legacy_Po_Number."WA_DATA-
pr_Original_No.
i_s_log-object = 'ZPCBLSRM'. "Object name
i_s_log-subobject = 'ZPOLOG'. "Object name
i_s_msg-msgty = 'I'. "Message type
i_s_msg-msgid = 'ZPCBLSRM'. "Message id
i_s_msg-msgno = '000'. "Message number
CALL METHOD me->slg_log_create
EXPORTING
i_s_log = i_s_log
i_s_msg = i_s_msg
message = lw_message.
ELSE.
lw_message = lv_result.
REPLACE '"Return_Code":"500",' IN lw_message WITH ' '.
REPLACE '"Return_Message":' IN lw_message WITH ' '.
READ TABLE it_po_derel INTO wa_po_derel INDEX 1.
i_s_log-extnumber = WA_po_derel-Legacy_Po_Number.
i_s_log-object = 'ZPCBLSRM'. "Object name
i_s_log-subobject = 'ZPOLOG'. "Object name
i_s_msg-msgty = 'E'. "Message type
i_s_msg-msgid = 'ZPCBLSRM'. "Message id
i_s_msg-msgno = '000'. "Message number
CALL METHOD me->slg_log_create
EXPORTING
i_s_log = i_s_log
i_s_msg = i_s_msg
message = lw_message.
ENDIF.

ENDIF.
ENDIF.

* CALL METHOD /ui2/cl_json=>deserialize


* EXPORTING
* json = lv_result
** pretty_name = PRETTY_MODE-NONE
** jsonx =
** pretty_name = PRETTY_MODE-NONE
** assoc_arrays = C_BOOL-FALSE
** assoc_arrays_opt = C_BOOL-FALSE
** name_mappings =
** conversion_exits = C_BOOL-FALSE
* CHANGING
* data = ls_batch_save_ui.
*** READ TABLE it_response INTO wa_response INDEX 1 .
* IF sy-subrc = 0.
* IF lv_del_flag = 'X'.
* /ui2/cl_json=>deserialize(
* EXPORTING
* json = Lv_RESULT " JSON string
* pretty_name = /ui2/cl_json=>pretty_mode-extended
*
* CHANGING
* data = lt_source ).
* ENDIF.
*
* IF sy-subrc = 0 .
* EXPORT lt_source FROM lt_source TO MEMORY ID 'DERELEASE'.
* ENDIF.
* ELSE.
*
* ENDIF.
** MODIFY zlog_einv_qrcode FROM wa_log_einv.
else.
* DATA: ls_batch_save_ui TYPE bpc_loc_s_batch_save_ui.
DATA(lv_result1) = o_client->response->get_cdata( ). " Getting Receiving
Status Code and Message.
IF lv_result1 IS NOT INITIAL.
lw_message = lv_result1.
REPLACE '"Return_Message":' IN lw_message WITH ' '.

i_s_log-object = 'ZPCBLSRM'. "Object name


IF lv_del_flag = 'X' or lv_rel_flag = 'X'.
IF it_data IS NOT INITIAL.
lt_data = it_data.
ENDIF.
i_s_log-extnumber = lt_data-pr_number."WA_DATA-pr_Original_No.
i_s_log-subobject = 'ZPRLOG'. "Object name
elseIF lv_del_flag1 = 'X' or lv_rel_flag1 = 'X'..
i_s_log-extnumber = lt_po_data-po_number."WA_DATA-pr_Original_No.
i_s_log-subobject = 'ZPOLOG'. "Object name
ENDIF.

i_s_msg-msgty = 'E'. "Message type


i_s_msg-msgid = 'ZPCBLSRM'. "Message id
i_s_msg-msgno = '000'. "Message number
CALL METHOD me->slg_log_create
EXPORTING
i_s_log = i_s_log
i_s_msg = i_s_msg
message = lw_message.
endif.

ENDIF.
"Close HTTP Connection
o_client->close( ).

ENDIF.
FREE MEMORY ID: 'RELE' , 'DERELE', 'REL','PODERE'.
* CLEAR :
wa_body,wa_itemlist,wa_precdocdtls ,wa_log_einv,lv_msg,it_response,it_body,it_addld
ocdtls,it_contrdtls,it_precdocdtls,it_itemlist,it_attribdtls,wa_url,gw_final.
ENDMETHOD.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy