SAP HANA Samples
Example SAP HANA - Shipment Document
The following query example is based on the default Shipment_Document custom details screen.
For SAP HANA it is necessary to make use of stored procedures when working with variable data. The information below contains a sample for both the creation of the stored procedure and for calling this procedure from the Custom Details function.
CREATE PROCEDURE WHP_SP_Details_Shipment_Document
(
in UserID INT,
in Lang NVARCHAR(4),
in Documents NVARCHAR(255),
in ShipToCode NVARCHAR(100),
in TrnspCode INT,
in PaymentTerms INT
)
LANGUAGE SQLSCRIPT
AS
BEGIN
/* USE ONLY FOR TESTING RESULT IN HANA STUDIO */
/*
DECLARE UserID INT := 1;
DECLARE Lang NVARCHAR(4) := 'NL';
DECLARE Documents NVARCHAR(255) := '17-1,13-1';
DECLARE ShipToCode NVARCHAR(100) := 'Afleveradres';
DECLARE TrnspCode INT := 4;
DECLARE PaymentTerms INT := 6;
*/
/* STARTING SCRIPT */
/* PREPARATIONS FOR TEMPORARY DATA */
DECLARE CardCode NVARCHAR(30);
DECLARE CardName NVARCHAR(150);
DECLARE Address NVARCHAR(100);
DECLARE ShippingType NVARCHAR(50);
DECLARE PayTerms NVARCHAR(20);
DECLARE DocNum INT;
DECLARE ShipDate DATE;
DECLARE Remarks NVARCHAR(255);
DECLARE WhileCounter INT;
DECLARE CurBaseType NVARCHAR(10);
DECLARE CurDocEntry INT;
DECLARE ResultVar NVARCHAR(1500) := '';
CREATE LOCAL TEMPORARY TABLE #TempDocTABLE ( "BaseType" NVARCHAR(10), "DocEntry" INT );
/* CONVERT INPUT VAR @PickEntrys INTO USEABLE DATA (INTO TEMPORARY TABLE) */
INSERT INTO #TempDocTABLE
SELECT CAST(SUBSTRING_REGEXPR('[^-]+' IN "OUTPUT_SPLIT" FROM 1 OCCURRENCE 1) AS NVARCHAR(10)) AS "BaseType",
CAST(SUBSTRING_REGEXPR('[^-]+' IN "OUTPUT_SPLIT" FROM 1 OCCURRENCE 2) AS INT) AS "DocEntry"
FROM STRING_SPLIT(:Documents, ',');
--SELECT * FROM #TempDocTABLE;
/* SET STARTING LINE FOR RESULTTEXT VARIABLE */
ResultVar := CASE :Lang WHEN 'NL' THEN 'VOORBEELD QUERY: ' ELSE 'SAMPLE QUERY: ' END || char(13) || char(13);
SELECT COUNT(*) INTO WhileCounter FROM #TempDocTABLE;
WHILE :WhileCounter > 0 DO
SELECT TOP 1 "BaseType" , "DocEntry" INTO CurBaseType, CurDocEntry FROM #TempDocTABLE ORDER BY "BaseType" DESC, "DocEntry" ASC ;
/* READ DATA FROM FIRST RECORD IN TEMPORARY TABLE, EXTEND WITH WHP AND SAP DATA AND PUT DATA INTO VARIABLES */
SELECT R."CardCode", R."CardName", R."ShipToCode", R."TrnspName", R."PymntGroup", R."DocNum", R."DocDueDate", R."Comments"
INTO CardCode, CardName, Address, ShippingType, PayTerms, DocNum, ShipDate, Remarks
FROM
(
SELECT D."CardCode" , D."CardName" , D."ShipToCode" , IFNULL(S."TrnspName", '') AS "TrnspName" , IFNULL(C."PymntGroup", '') AS "PymntGroup" , D."DocNum" , D."DocDueDate"
, IFNULL(D."Comments" , '') AS "Comments"
FROM #TempDocTABLE T
INNER JOIN ORDR D ON D."DocEntry" = T."DocEntry" AND D."ObjType" = T."BaseType"
LEFT JOIN OSHP S ON S."TrnspCode" = D."TrnspCode"
LEFT JOIN OCTG C ON C."GroupNum" = D."GroupNum"
WHERE T."BaseType" = :CurBaseType AND T."DocEntry" = :CurDocEntry
UNION
SELECT D."CardCode" , D."CardName" , D."ShipToCode" , IFNULL(S."TrnspName", '') AS "TrnspName" , IFNULL(C."PymntGroup", '') AS "PymntGroup" , D."DocNum" , D."DocDueDate"
, IFNULL(D."Comments" , '') AS "Comments"
FROM #TempDocTABLE T
INNER JOIN OINV D ON D."DocEntry" = T."DocEntry" AND D."ObjType" = T."BaseType"
LEFT JOIN OSHP S ON S."TrnspCode" = D."TrnspCode"
LEFT JOIN OCTG C ON C."GroupNum" = D."GroupNum"
WHERE T."BaseType" = :CurBaseType AND T."DocEntry" = :CurDocEntry
)R;
/* ADD EACH VARIABLE IN READEABLE FORMAT INTO RESULT-VARIABLE */
ResultVar := :ResultVar
|| CASE :Lang WHEN 'NL' THEN 'Document: ' ELSE 'Document: ' END || char(13)
|| CASE :CurBaseType WHEN '17' THEN CASE :Lang WHEN 'NL' THEN 'Verkooporder' ELSE 'Sales Order' END
WHEN '13' THEN CASE :Lang WHEN 'NL' THEN 'Reservefactuur' ELSE 'Reserve Invoice' END
END
|| char(13) || CAST(:DocNum AS NVARCHAR(20)) || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Klant: ' ELSE 'Customer: ' END || char(13) || :CardCode || char(13) || :CardName || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Adres: ' ELSE 'Address: ' END || char(13) || :Address || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Verzenddatum: ' ELSE 'Shipping Date: ' END || char(13) || TO_VARCHAR(:ShipDate , 'DD-MM-YYYY') || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Verzendwijze: ' ELSE 'Shipping Type: ' END || char(13) || :ShippingType || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Betalingsconditie: ' ELSE 'Payment Terms: ' END || char(13) || :PayTerms || char(13) || char(13) ;
IF IFNULL(:Remarks, '') <> ''
THEN
/* ONLY FILL COMMENTS WHEN NOT EMPTY */
ResultVar := :ResultVar || CASE :Lang WHEN 'NL' THEN 'Opmerkingen: ' ELSE 'Remarks: ' END || char(13) || :Remarks || char(13) ;
END IF;
DELETE FROM #TempDocTABLE WHERE "BaseType" = :CurBaseType AND "DocEntry" = :CurDocEntry;
SELECT COUNT(*) INTO WhileCounter FROM #TempDocTABLE;
IF :WhileCounter > 0
THEN
/* ONLY ADD CLOSING LINE WHEN NOT LAST RECORD */
ResultVar := :ResultVar || char(13) || '____________________________' || char(13) || char(13);
END IF;
END WHILE;
/* DROP TEMPORARY TABLES */
DROP TABLE #TempDocTABLE;
/* READ END RESULT */
SELECT ResultVAR AS Details FROM DUMMY;
END
'Afleveradres'
Sample query to call the stored procedure:
CALL SBODEMONL_TEST1.WHP_SP_Details_Shipment_Document (@UserID1, '@Language', '@Documents', '@ShipToCode', @TrnspCode, @PaymentTerms);
When calling objects from SAP HANA, make sure to specify the schema name (SBODEMONL_TEST1 in the sample above).
The example above returns the following data in WarehousePro Client:
SAP HANA Orderpicking Line
This example uses a stored procedure and a function to parse the input parameter of different documents.
For SAP HANA it is necessary to make use of stored procedures when working with variable data. The information below contains a sample for both the creation of the stored procedure and for calling this procedure from the Custom Details function.
CREATE PROCEDURE "WHP_CUSTOM_DETAILS_ORDER_PICKING_LINE" (IN Trigger NVARCHAR(1), IN AbsEntry INT, IN PickEntrys NVARCHAR(2000))
LANGUAGE SQLSCRIPT AS
BEGIN
DECLARE Result NVARCHAR(6000) := '';
DECLARE CommentID INT := 1;
DECLARE MaxCommentID INT := 0;
DECLARE ItemCode NVARCHAR(150) := '';
DECLARE ItemName NVARCHAR(150) := '';
DECLARE Remarks NVARCHAR(400) := '';
CREATE LOCAL TEMPORARY TABLE #PickEntryTable ("PickEntry" INT);
CREATE LOCAL TEMPORARY TABLE #Data ("ItemCode" NVARCHAR(100), "ItemName" NVARCHAR(100), "Comment" NVARCHAR(4000));
CREATE LOCAL TEMPORARY TABLE #CommentData ("ID" INT, "Comment" NVARCHAR(4000));
INSERT INTO #PickEntryTable
SELECT CAST("OUTPUT_SPLIT" AS INT) FROM "STRING_SPLIT"(:PickEntrys, ',');
IF :Trigger = 'Y' THEN
--Trigger
SELECT CASE WHEN A."ItemCode" = 'A00001' THEN 'Y' ELSE 'N' END AS Result FROM
(
SELECT DISTINCT L."ItemCode"
FROM "APD_OPKL_1" T
INNER JOIN (
SELECT 17 AS "BaseType", R."DocEntry", R."LineNum", R."ItemCode" FROM "RDR1" R
UNION
SELECT 13 AS "BaseType", I."DocEntry", I."LineNum", I."ItemCode" FROM "INV1" I
) L ON T."BaseObject" = L."BaseType" AND T."OrderEntry" = L."DocEntry" AND T."OrderLine" = L."LineNum"
WHERE T."AbsEntry" = :AbsEntry AND T."PickEntry" IN (SELECT * FROM #PickEntryTable)
) A;
ELSE
--Script
INSERT INTO #Data
SELECT L."ItemCode", L."Dscription", L."Comment"
FROM "APD_OPKL_1" T
INNER JOIN (
SELECT 17 AS "BaseType", R."DocEntry", R."LineNum", R."ItemCode", R."Dscription", IFNULL(R."FreeTxt",'') AS "Comment" FROM "RDR1" R
UNION
SELECT 13 AS "BaseType", I."DocEntry", I."LineNum", I."ItemCode", I."Dscription", IFNULL(I."FreeTxt",'') AS "Comment" FROM "INV1" I
) L ON T."BaseObject" = L."BaseType" AND T."OrderEntry" = L."DocEntry" AND T."OrderLine" = L."LineNum"
WHERE T."AbsEntry" = :AbsEntry AND T."PickEntry" IN (SELECT * FROM #PickEntryTable);
INSERT INTO #CommentData
SELECT ROW_NUMBER() OVER (ORDER BY T."Comment"), T."Comment" FROM #Data T WHERE T."Comment" != '';
SELECT MAX(D."ID") INTO MaxCommentID FROM #CommentData D;
SELECT TOP 1 T."ItemCode" INTO ItemCode FROM #Data T;
SELECT TOP 1 T."ItemName" INTO ItemName FROM #Data T;
Result := 'Item = ' || :ItemCode || CHAR(10);
Result := :Result || 'Description = ' || :ItemName || CHAR(10) || CHAR(10);
Result := :Result || 'Comments' || CHAR(10) || CHAR(10);
WHILE :CommentID <= :MaxCommentID
DO
SELECT T."Comment" INTO Remarks FROM #CommentData T WHERE T."ID" = :CommentID;
Result := :Result || :Remarks || CHAR(10);
CommentID := :CommentID + 1;
END WHILE;
SELECT :Result AS Result FROM DUMMY;
END IF;
DROP TABLE #CommentData;
DROP TABLE #Data;
DROP TABLE #PickEntryTable;
END;
Sample query to call the stored procedure:
CALL "SCHEMA"."WHP_CUSTOM_DETAILS_ORDER_PICKING_LINE" ('N', @AbsEntry , '@PickEntrys');
When calling objects from SAP HANA, make sure to specify the schema name (SBODEMONL_TEST1 in the sample above).
Example SAP HANA - Stock Transfer Document
The following query example is based on the default Stock_Transfer_Document custom details screen.
For SAP HANA it is necessary to make use of stored procedures when working with variable data. The information below contains a sample for both the creation of the stored procedure and for calling this procedure from the Custom Details function.
CREATE PROCEDURE WHP_SP_Details_Stock_Transfer_Document
(
in AbsEntry INT,
in Lang NVARCHAR(4),
in UserID INT
)
LANGUAGE SQLSCRIPT
AS
BEGIN
/* USE ONLY FOR TESTING RESULT IN HANA STUDIO */
--UserID := 1 ;
--Lang := 'NL' ;
--AbsEntry := 25694 ;
/* STARTING SCRIPT */
/* PREPARATIONS FOR TEMPORARY DATA */
DECLARE PickDate DATE;
DECLARE FromWHSCode NVARCHAR(25);
DECLARE ToWHSCode NVARCHAR(25);
DECLARE FromWHSName NVARCHAR(150);
DECLARE ToWHSName NVARCHAR(150);
DECLARE Remarks NVARCHAR(255);
DECLARE ResultVAR NVARCHAR(1500);
/* RETREIVE TEMPORARY DATA */
SELECT "PickDate", "Remarks" INTO PickDate, Remarks FROM APD_OPKL WHERE "AbsEntry" = :AbsEntry;
SELECT D."Filler", D."ToWhsCode" INTO FromWHSCode, ToWhsCode FROM OWTQ D WHERE D."DocEntry" = (SELECT "OrderEntry" FROM APD_OPKL_1 WHERE "AbsEntry" = :AbsEntry AND "BaseObject" = '1250000001');
SELECT W."WhsName" INTO FromWHSName FROM OWHS W WHERE W."WhsCode" = :FromWHSCode;
SELECT W."WhsName" INTO ToWHSName FROM OWHS W WHERE W."WhsCode" = :ToWHSCode;
/* ADD EACH VALUE INTO READABLE FORMAT INTO RESULT-VARIABLE */
ResultVAR := CASE :Lang WHEN 'NL' THEN 'VOORBEELD QUERY: ' ELSE 'SAMPLE QUERY: ' END || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Document: ' ELSE 'Document: ' END || char(13) || CAST(:AbsEntry AS NVARCHAR(10)) || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Pickdatum: ' ELSE 'Pick Date: ' END || char(13) || TO_VARCHAR(:PickDate , 'DD-MM-YYYY') || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Vanaf magazijn: ' ELSE 'From Warehouse: ' END || char(13) || :FromWHSName || ' (' || :FromWHSCode || ')' || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Naar magazijn: ' ELSE 'To Warehouse: ' END || char(13) || :ToWHSName || ' (' || :ToWHSCode || ')' || char(13) || char(13);
/* ONLY ADD REMARKS WHEN AVAILABLE */
IF IFNULL(:Remarks, '') <> ''
THEN
ResultVAR := :ResultVAR || CASE :Lang WHEN 'NL' THEN 'Opmerkingen: ' ELSE 'Remarks: ' END || char(13) || IFNULL(:Remarks, '') || char(13) || char(13);
END IF;
/* READ END RESULT */
SELECT ResultVAR AS Details FROM DUMMY;
END
Sample query to call the stored procedure:
CALL SBODEMONL_TEST1.WHP_SP_Details_Stock_Transfer_Document (@AbsEntry,'@Language',@UserID);
When calling objects from SAP HANA, make sure to specify the schema name (SBODEMONL_TEST1 in the sample above).
The example above returns the following data in WarehousePro Client:
Example SAP HANA - Stock Transfer Line Get
The following query example is based on the default Stock_Transfer_Line Get custom details screen.
For SAP HANA it is necessary to make use of stored procedures when working with variable data. The information below contains a sample for both the creation of the stored procedure and for calling this procedure from the Custom Details function.
CREATE PROCEDURE WHP_SP_Details_Stock_Transfer_Line_Get
(
in UserID INT,
in Lang NVARCHAR(4),
in AbsEntry INT,
in PickEntrys NVARCHAR(255)
)
LANGUAGE SQLSCRIPT
AS
BEGIN
/* USE ONLY FOR TESTING RESULT IN HANA STUDIO */
/*
DECLARE UserID INT := 1 ;
DECLARE Lang NVARCHAR(4) := 'NL' ;
DECLARE AbsEntry INT := 13 ;
DECLARE PickEntrys NVARCHAR(100) := '0,1';
*/
/* STARTING SCRIPT */
/* PREPARATIONS FOR TEMPORARY DATA */
DECLARE ItemCode NVARCHAR(50);
DECLARE ItemName NVARCHAR(150);
DECLARE Quantity DECIMAL(19,6);
DECLARE UoM NVARCHAR(50);
DECLARE ResultVAR NVARCHAR(1500);
CREATE LOCAL TEMPORARY COLUMN TABLE #TEMPENTRYS ( "PickEntry" INT );
/* CONVERT INPUT VAR @PickEntrys INTO USEABLE DATA (INTO TEMPORARY TABLE) */
INSERT INTO #TEMPENTRYS
SELECT CAST("OUTPUT_SPLIT" AS INT) FROM STRING_SPLIT(:PickEntrys, ',');
/* RETREIVE TEMPORARY DATA */
SELECT I."ItemCode" , I."ItemName" , SUM(PL."PrevReleas") , IFNULL(I."InvntryUom", '') INTO ItemCode, ItemName , Quantity, UoM
FROM APD_OPKL_1 PL
INNER JOIN APD_OPKL P ON P."AbsEntry" = PL."AbsEntry"
INNER JOIN WTQ1 TQ ON TQ."DocEntry" = PL."OrderEntry" AND TQ."LineNum" = PL."OrderLine"
INNER JOIN OITM I ON I."ItemCode" = TQ."ItemCode"
WHERE PL."AbsEntry" = :AbsEntry AND PL."PickEntry" IN (SELECT "PickEntry" FROM #TEMPENTRYS)
GROUP BY I."ItemCode", I."ItemName", I."InvntryUom";
/* ADD EACH VALUE INTO READABLE FORMAT INTO RESULT-VARIABLE */
ResultVAR := CASE :Lang WHEN 'NL' THEN 'VOORBEELD QUERY: ' ELSE 'SAMPLE QUERY: ' END || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Document: ' ELSE 'Document: ' END || char(13) || CAST(:AbsEntry AS NVARCHAR(10)) || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Artikel: ' ELSE 'Item: ' END || char(13) || :ItemCode || char(13) || :ItemName || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Aantal: ' ELSE 'Quantity: ' END || char(13) || CAST(CAST(:Quantity AS Float) AS NVARCHAR(10)) || ' ' || :UoM || char(13) || char(13);
/* DROP TEMPORARY TABLES */
DROP TABLE #TEMPENTRYS;
/* READ END RESULT */
SELECT ResultVAR AS Details FROM DUMMY;
END
The sample above uses a String_Split function. Make sure to create this function in the required schema before using this sample.
Sample query to call the stored procedure:
CALL SBODEMONL_TEST1.WHP_SP_Details_Stock_Transfer_Line_Get (@UserID,'@Language',@AbsEntry, @PickEntrys);
When calling objects from SAP HANA, make sure to specify the schema name (SBODEMONL_TEST1 in the sample above).
The example above returns the following data in WarehousePro Client:
Example SAP HANA - Stock Transfer Line Put
The following query example is based on the default Stock_Transfer_Line Put custom details screen.
For SAP HANA it is necessary to make use of stored procedures when working with variable data. The information below contains a sample for both the creation of the stored procedure and for calling this procedure from the Custom Details function.
CREATE PROCEDURE WHP_SP_Details_Stock_Transfer_Line_Put
(
in UserID INT,
in Lang NVARCHAR(4),
in AbsEntry INT,
in PickEntrys NVARCHAR(255)
)
LANGUAGE SQLSCRIPT
AS
BEGIN
/* USE ONLY FOR TESTING RESULT IN HANA STUDIO */
/*
DECLARE UserID INT := 1 ;
DECLARE Lang NVARCHAR(4) := 'NL' ;
DECLARE AbsEntry INT := 13 ;
DECLARE PickEntrys NVARCHAR(100) := '0,1';
*/
/* STARTING SCRIPT */
/* PREPARATIONS FOR TEMPORARY DATA */
DECLARE ItemCode NVARCHAR(50);
DECLARE ItemName NVARCHAR(150);
DECLARE Quantity DECIMAL(19,6);
DECLARE UoM NVARCHAR(50);
DECLARE ResultVAR NVARCHAR(1500);
CREATE LOCAL TEMPORARY COLUMN TABLE #TEMPENTRYS ( "PickEntry" INT );
/* CONVERT INPUT VAR @PickEntrys INTO USEABLE DATA (INTO TEMPORARY TABLE) */
INSERT INTO #TEMPENTRYS
SELECT CAST("OUTPUT_SPLIT" AS INT) FROM STRING_SPLIT(:PickEntrys, ',');
/* RETREIVE TEMPORARY DATA */
SELECT I."ItemCode" , I."ItemName" , SUM(PL."PrevReleas") , IFNULL(I."InvntryUom", '') INTO ItemCode, ItemName , Quantity, UoM
FROM APD_OPKL_1 PL
INNER JOIN APD_OPKL P ON P."AbsEntry" = PL."AbsEntry"
INNER JOIN WTQ1 TQ ON TQ."DocEntry" = PL."OrderEntry" AND TQ."LineNum" = PL."OrderLine"
INNER JOIN OITM I ON I."ItemCode" = TQ."ItemCode"
WHERE PL."AbsEntry" = :AbsEntry AND PL."PickEntry" IN (SELECT "PickEntry" FROM #TEMPENTRYS)
GROUP BY I."ItemCode", I."ItemName", I."InvntryUom";
/* ADD EACH VALUE INTO READABLE FORMAT INTO RESULT-VARIABLE */
ResultVAR := CASE :Lang WHEN 'NL' THEN 'VOORBEELD QUERY: ' ELSE 'SAMPLE QUERY: ' END || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Document: ' ELSE 'Document: ' END || char(13) || CAST(:AbsEntry AS NVARCHAR(10)) || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Artikel: ' ELSE 'Item: ' END || char(13) || :ItemCode || char(13) || :ItemName || char(13) || char(13)
|| CASE :Lang WHEN 'NL' THEN 'Aantal: ' ELSE 'Quantity: ' END || char(13) || CAST(CAST(:Quantity AS Float) AS NVARCHAR(10)) || ' ' || :UoM || char(13) || char(13);
/* DROP TEMPORARY TABLES */
DROP TABLE #TEMPENTRYS;
/* READ END RESULT */
SELECT ResultVAR AS Details FROM DUMMY;
END
The sample above uses a String_Split function. Make sure to create this function in the required schema before using this sample.
Sample query to call the stored procedure:
CALL SBODEMONL_TEST1.WHP_SP_Details_Stock_Transfer_Line_Put (@UserID,'@Language',@AbsEntry, @PickEntrys);
When calling objects from SAP HANA, make sure to specify the schema name (SBODEMONL_TEST1 in the sample above).
The example above returns the following data in WarehousePro Client: