Hi,
I am trying to simulate the stock calculation in R/3 using HANA solution for having a real time stock calculation using HANA. For this I replicated related tables to a HANA standalone system. Later I started to prepare a procedure to derive the summation logic combining the different tables involved in stock calculation.
I am stuck on the step where I need to do iteration on a result set and do summation and subtraction of defined movement types and later make a table which should be passed as the result set.I dont see any possible option to do such kind of runtime temporary tables and modification capability in the available HANA SQL script capabilities. I tried cursor, CE_UNION_ALL , various select based table variables to achieve this requirement.
I am pasting the attempted code below. Here I am trying to add some data and minus some data. Later I need to send the IBESTAND table as my result set. I dont see an option to send this as a select statement only...please throw some light...Thanks
eg:
FOR cur_row as cursor1 DO
V_MENGE := 0;
V_WERKS := CUR_ROW.WERKS;
V_LGORT := CUR_ROW.LGORT;
V_MATNR := CUR_ROW.MATNR;
SELECT
"WERKS",
"LGORT",
"MATNR",
"SHKZG",
"MENGE"
INTO V_WERKS,
V_LGORT,
V_MATNR,
V_SHKZG,
V_MENGE
FROM :IWEG_MAT
WHERE "WERKS" = :V_WERKS
AND "LGORT" = :V_LGORT
AND "MATNR" = :V_MATNR
AND "SHKZG" = 'S';
V_ENDMENGE := 0;
V_ENDMENGE := CUR_ROW.LABST + CUR_ROW.INSME + CUR_ROW.SPEME + CUR_ROW.EINME + CUR_ROW.RETME - :V_MENGE;
V_MENGE := 0;
CNT := 1;
SELECT
"WERKS",
"LGORT",
"MATNR",
"SHKZG",
"MENGE"
INTO V_WERKS,
V_LGORT,
V_MATNR,
V_SHKZG,
V_MENGE
FROM :IWEG_MAT
WHERE "WERKS" = :V_WERKS
AND "LGORT" = :V_LGORT
AND "MATNR" = :V_MATNR
AND "SHKZG" = 'H' ;
V_ENDMENGE := V_ENDMENGE + V_MENGE ;
V_BWKEY := CNT ;
CNT := CNT + 1 ;
V_CHARG := CNT ;
CNT := CNT + 1 ;
INSERT
INTO IBESTAND VALUES ( :V_BWKEY,
CUR_ROW.WERKS,
CUR_ROW.MATNR,
:V_CHARG,
:V_ENDMENGE,
:V_ANFMENGE,
:V_MEINS,
:V_ENDWERT,
:V_ANFWERT,
:V_SOLL,
:V_HABEN,
:V_SOLLWERT,
:V_HABENWERT,
:V_WAERS) ;
END FOR;