0% found this document useful (0 votes)
2 views18 pages

ABAP Batch Processing Demo Code

The document contains ABAP code for handling batch operations related to sales orders, including methods for creating, updating, retrieving, and deleting entities in the header and item sets. It also includes examples of HTTP requests for single and multiple POST, PUT, and DELETE operations, as well as handling changesets in defer mode. The code demonstrates the use of data conversion functions and error handling within the methods.

Uploaded by

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

ABAP Batch Processing Demo Code

The document contains ABAP code for handling batch operations related to sales orders, including methods for creating, updating, retrieving, and deleting entities in the header and item sets. It also includes examples of HTTP requests for single and multiple POST, PUT, and DELETE operations, as well as handling changesets in defer mode. The code demonstrates the use of data conversion functions and error handling within the methods.

Uploaded by

mayuresh kumar
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

$Batch Demo Code

$Batch Demo Code


method HEADERSET_GET_ENTITY.

data : lv_vbeln type vbeln.

lv_vbeln = it_key_tab[ 1 ]-value.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
input = lv_vbeln
IMPORTING
OUTPUT = lv_vbeln.

select SINGLE * from zso_header into er_entity WHERE vbeln = lv_vbeln.

endmethod.

method HEADERSET_GET_ENTITYSET.

select * from zso_header into TABLE et_entityset.

endmethod.

method HEADERSET_CREATE_ENTITY.

data : wa_entity like er_entity.

Try.
call METHOD io_data_provider->read_entry_data
IMPORTING
es_data = wa_entity.

insert zso_header from wa_entity.

CATCH cx_root.
ENDTRY.

endmethod.

method HEADERSET_UPDATE_ENTITY.

data : wa_entity like er_entity.

Try.
call METHOD io_data_provider->read_entry_data
IMPORTING
es_data = wa_entity.

modify zso_header from wa_entity.

CATCH cx_root.
ENDTRY.

endmethod.
$Batch Demo Code
method HEADERSET_DELETE_ENTITY.

data : lv_vbeln type vbeln.

lv_vbeln = it_key_tab[ 1 ]-value.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
input = lv_vbeln
IMPORTING
OUTPUT = lv_vbeln.

delete from zso_header WHERE vbeln = lv_vbeln.

endmethod.

method ITEMSET_GET_ENTITY.

data : lv_vbeln type vbeln,


lv_posnr type vbap-posnr.

lv_vbeln = it_key_tab[ 1 ]-value.


lv_posnr = it_key_tab[ 2 ]-value.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
input = lv_vbeln
IMPORTING
OUTPUT = lv_vbeln.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
input = lv_posnr
IMPORTING
OUTPUT = lv_posnr.

select SINGLE * from zso_item into er_entity WHERE vbeln = lv_vbeln


and posnr = lv_posnr.

endmethod.

method ITEMSET_GET_ENTITYSET.
select * from zso_item into TABLE et_entityset.
endmethod.

method ITEMSET_CREATE_ENTITY.

data : wa_entity like er_entity.

Try.
call METHOD io_data_provider->read_entry_data
IMPORTING
es_data = wa_entity.
CATCH cx_root.
ENDTRY.

insert zso_item from wa_entity.

endmethod.
$Batch Demo Code
method ITEMSET_UPDATE_ENTITY.

data : wa_entity like er_entity.

Try.
call METHOD io_data_provider->read_entry_data
IMPORTING
es_data = wa_entity.

modify zso_item from wa_entity.

CATCH cx_root.
ENDTRY.

endmethod.

method ITEMSET_DELETE_ENTITY.

data : lv_vbeln type vbeln,


lv_posnr type vbap-posnr.

lv_vbeln = it_key_tab[ 1 ]-value.


lv_posnr = it_key_tab[ 2 ]-value.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
input = lv_vbeln
IMPORTING
OUTPUT = lv_vbeln.

CALL FUNCTION 'CONVERSION_EXIT_ALPHA_INPUT'


EXPORTING
input = lv_posnr
IMPORTING
OUTPUT = lv_posnr.

delete from zso_item WHERE vbeln = lv_vbeln


and posnr = lv_posnr.

endmethod.

method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_BEGIN.
CV_DEFER_MODE = abap_true.
endmethod.

method /IWBEP/IF_MGW_APPL_SRV_RUNTIME~CHANGESET_PROCESS.
BREAK-POINT.

data : ls_changeset_request type /IWBEP/IF_MGW_APPL_types=>ty_s_changeset_request,


ls_changeset_response like LINE OF ct_changeset_response,
lo_create_context type REF TO /iwbep/if_mgw_req_entity_c,
lv_entity_type type string,

ls_header type zcl_zkso_mpc=>ts_header,


ls_item type zcl_zkso_mpc=>ts_item,

lt_item type STANDARD TABLE OF ZSO_ITEM,

ep_msg_type type char1,


$Batch Demo Code
ep_msg type char100.

if it_changeset_request[] is NOT INITIAL.

loop at it_changeset_request into ls_changeset_request.

lo_create_context ?= ls_changeset_request-request_context.
lv_entity_type = lo_create_context->get_entity_type_name( ).

case ls_changeset_request-operation_type.
WHEN 'CE'.

case lv_entity_type.

when 'header'.

ls_changeset_request-entry_provider-
>read_entry_data( IMPORTING es_data = ls_header ).

ls_changeset_response-operation_no = ls_changeset_request-operation_no.

copy_data_to_ref(
EXPORTING
is_data = ls_header
CHANGING
cr_data = ls_changeset_response-entity_data
).

append ls_changeset_response to ct_changeset_response.


clear : ls_changeset_response.

when 'item'.

ls_changeset_request-entry_provider-
>read_entry_data( IMPORTING es_data = ls_item ).
append ls_item to lt_item.

ls_changeset_response-operation_no = ls_changeset_request-operation_no.

copy_data_to_ref(
EXPORTING
is_data = ls_item
CHANGING
cr_data = ls_changeset_response-entity_data
).

append ls_changeset_response to ct_changeset_response.


clear : ls_changeset_response.

endcase.

when 'OTHERS'.

ENDCASE.

clear : ls_changeset_request.
endloop.
$Batch Demo Code

endif.

if ls_header is NOT INITIAL and lt_item[] is NOT INITIAL.

CALL FUNCTION 'ZCUSTOM_SO_CREATE'


EXPORTING
IP_HEADER = ls_header
IMPORTING
EP_MSG_TYPE = ep_msg_type
EP_MSG = ep_msg
TABLES
IT_ITEM = lt_item
.

if ep_msg_type = 'S'.

else.
clear : ct_changeset_response[].

LOOP at it_changeset_request into ls_changeset_request.

RAISE EXCEPTION TYPE /IWBEP/CX_MGW_BUSI_EXCEPTION.

ls_changeset_response-operation_no = ls_changeset_request-operation_no.
APPEND ls_changeset_response to ct_changeset_response.

ENDLOOP.

endif.

endif.

endmethod.
$Batch Demo Code

Get Call
--salesorders
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/json

GET headerSet(Vbeln='1000000001')?$format=json HTTP/1.1

--salesorders
Content-Type: application/http
Content-Transfer-Encoding: binary
Accept: application/json

GET itemSet(Vbeln='1000000001',Posnr='10') HTTP/1.1

--salesorders
Content-Type: application/http
Content-Transfer-Encoding: binary

GET itemSet(Vbeln='1000000001',Posnr='20') HTTP/1.1

--salesorders--
$Batch Demo Code

Single POST
--batch_2023081101
Content-Type:multipart/mixed; boundary=changeset_1

--changeset_1
Content-Type:application/http
Content-Transfer-Encoding:binary

POST headerSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "2000000012",
"Erdat" : "/Date(1691712000000)/",
"Auart" : "OR",
"Kunnr" : "17100001",
"Vkorg" : "1200"
}

--changeset_1--

--batch_2023081101--
$Batch Demo Code

Multiple Post Call

--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_01

--changeset_01
Content-Type:application/http
Content-Transfer-Encoding:binary

POST headerSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "2000000016",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100050",
"Vkorg" : "2500"
}

--changeset_01--

--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_02

--changeset_02
Content-Type:application/http
Content-Transfer-Encoding:binary

POST headerSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "2000000017",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100050",
"Vkorg" : "2500"
}

--changeset_02--

--batch_23081402--
$Batch Demo Code

Multiple PUT Call

--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_01

--changeset_01
Content-Type:application/http
Content-Transfer-Encoding:binary

PUT headerSet('2000000016') HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "2000000016",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100060",
"Vkorg" : "5000"
}

--changeset_01--

--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_02

--changeset_02
Content-Type:application/http
Content-Transfer-Encoding:binary

PUT headerSet('2000000017') HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "2000000017",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100049",
"Vkorg" : "2000"
}

--changeset_02--

--batch_23081402--
$Batch Demo Code

Mixed Methods
--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_01

--changeset_01
Content-Type:application/http
Content-Transfer-Encoding:binary

POST headerSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "2000000021",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100060",
"Vkorg" : "3000"
}

--changeset_01--

--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_02

--changeset_02
Content-Type:application/http
Content-Transfer-Encoding:binary

POST headerSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "2000000022",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100010",
"Vkorg" : "1500"
}

--changeset_02--

--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_03
$Batch Demo Code

--changeset_03
Content-Type:application/http
Content-Transfer-Encoding:binary

PUT headerSet('2000000016') HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "2000000016",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100060",
"Vkorg" : "6000"
}

--changeset_03--

--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_04

--changeset_04
Content-Type:application/http
Content-Transfer-Encoding:binary

PUT headerSet('2000000017') HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "2000000017",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100010",
"Vkorg" : "7000"
}

--changeset_04--

--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_05

--changeset_05
Content-Type:application/http
Content-Transfer-Encoding:binary
$Batch Demo Code

DELETE headerSet('2000000013') HTTP/1.1

--changeset_05--

--batch_23081402
Content-Type:application/http
Content-Transfer-Encoding:binary

GET headerSet('1000000001') HTTP/1.1

--batch_23081402--
$Batch Demo Code

Same change set - Defer Mode


--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_01

--changeset_01
Content-Type:application/http
Content-Transfer-Encoding:binary

POST headerSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "4000000001",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100102",
"Vkorg" : "1000"
}

--changeset_01
Content-Type:application/http
Content-Transfer-Encoding:binary

POST itemSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "4000000001",
"Posnr" : "000010",
"Matnr" : "302",
"Arktx" : "Glass 50",
"Kwmeng" : "100.0",
"Vrkme" : "EA"
}

--changeset_01
Content-Type:application/http
Content-Transfer-Encoding:binary

POST itemSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "4000000001",
"Posnr" : "000020",
"Matnr" : "302",
$Batch Demo Code
"Arktx" : "Glass 50",
"Kwmeng" : "100.0",
"Vrkme" : "EA"
}

--changeset_01--

--batch_23081402--
$Batch Demo Code

Same change set - Defer Mode


--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_01

--changeset_01
Content-Type:application/http
Content-Transfer-Encoding:binary

POST headerSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "6000000001",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100102",
"Vkorg" : "1000"
}

--changeset_01
Content-Type:application/http
Content-Transfer-Encoding:binary

POST itemSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "6000000001",
"Posnr" : "000010",
"Matnr" : "302",
"Arktx" : "Glass 50",
"Kwmeng" : "100.0",
"Vrkme" : "EA"
}

--changeset_01
Content-Type:application/http
Content-Transfer-Encoding:binary

POST itemSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "6000000001",
"Posnr" : "000020",
"Matnr" : "302",
$Batch Demo Code
"Arktx" : "Glass 50",
"Kwmeng" : "100.0",
"Vrkme" : "EA"
}

--changeset_01--

--batch_23081402
Content-Type:multipart/mixed; boundary=changeset_02

--changeset_02
Content-Type:application/http
Content-Transfer-Encoding:binary

POST headerSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "7000000001",
"Erdat" : "\/Date(1691712000000)\/",
"Auart" : "OR",
"Kunnr" : "17100102",
"Vkorg" : "1000"
}

--changeset_02
Content-Type:application/http
Content-Transfer-Encoding:binary

POST itemSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
Accept: application/json

{
"Vbeln" : "7000000001",
"Posnr" : "000010",
"Matnr" : "302",
"Arktx" : "Glass 50",
"Kwmeng" : "100.0",
"Vrkme" : "EA"
}

--changeset_02
Content-Type:application/http
Content-Transfer-Encoding:binary

POST itemSet HTTP/1.1


sap-context-accept: header
Content-Type: application/json
$Batch Demo Code
Accept: application/json

{
"Vbeln" : "7000000001",
"Posnr" : "000020",
"Matnr" : "302",
"Arktx" : "Glass 50",
"Kwmeng" : "100.0",
"Vrkme" : "EA"
}

--changeset_02--

--batch_23081402--

You might also like