Rest Based Api
Rest Based Api
Rest Based Api
com
Development Design:
We must fetch Header Information Line Items Information along Condition values.
Elements to develop.
1
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
Structures:
1. ZSD_ITEM_COND
2
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
2. ZSD_ITEMS
3
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
3. ZSD_SALEORDERS
4
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
Table Types:
1. ZTT_SD_ITEM_COND
2. ZTT_SD_ITEMS
5
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
6
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
The new window will appear to add code, For now just save and activate.
7
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
8
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
LO_ROUTER->ATTACH(
EXPORTING
IV_TEMPLATE = '/SO' " Unified Name for Resources
IV_HANDLER_CLASS = 'ZCL_SD_RP' " Object Type Name
).
ro_root_handler = lo_router.
Note: Just save it and activate the Method and Class Also.
9
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
10
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
11
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
12
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
13
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
Note: Must change the Structures name if created with your own names. If they are same then
remain the code as it is.
"select conditions
SELECT * FROM KONV INTO TABLE @DATA(GT_KONV) WHERE KNUMV = @GS_VBAK
-KNUMV.
GS_SO-VKORG = GS_VBAK-VKORG.
GS_SO-VTWEG = GS_VBAK-VTWEG.
GS_SO-SPART = GS_VBAK-SPART.
GS_SO-BSTNK = GS_VBAK-BSTNK.
14
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
GS_SO-BSTDK = GS_VBAK-BSTDK.
* ITEMS
LOOP AT GT_VBAP INTO DATA(GS_VBAP).
CLEAR : GS_ITEM.
MOVE-CORRESPONDING GS_VBAP TO GS_ITEM.
CLEAR : GS_ITEM_CONDITION.
GS_ITEM_CONDITION-VBELN = GS_VBAP-VBELN.
GS_ITEM_CONDITION-POSNR = GS_VBAP-POSNR.
GS_ITEM_CONDITION-KPOSN = GS_KONV-KPOSN.
GS_ITEM_CONDITION-STUNR = GS_KONV-STUNR.
GS_ITEM_CONDITION-KSCHL = GS_KONV-KSCHL.
GS_ITEM_CONDITION-KWERT = GS_KONV-KWERT.
GS_ITEM-ITEM_CONDITIONS[] = GT_ITEM_CONDITION[].
APPEND GS_ITEM TO GT_ITEM.
GS_SO-ITEMS[] = GT_ITEM[].
/UI2/CL_JSON=>SERIALIZE( EXPORTING
DATA = GS_SO " Data to serialize
RECEIVING
R_JSON = LV_RES " JSON string
).
MO_RESPONSE->SET_HEADER_FIELD(
EXPORTING
IV_NAME = 'Content-Type' " Header Name
IV_VALUE = 'application/json' " Header Value
).
ENDIF.
ELSE.
ENDIF.
15
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
Service Creation:
Your Service will be like this.
http:// Server link : Host /Service name /Resource Directory ?Landscape
Client &Parameter
Example:
http://:8000/zsd_rest/SO?sap-client=100&VBELN=20000014
16
Muhammad Uzair (SAP Technical Consultant ABAP, BTP, CPI & SAC) [email protected]
17