Passing table record to a function in a query

I have a procedure which calls a function in a query which has 2 input parameters as shown below -
select a.id, a.name, a.sal, check_xyz_func(a.id, a.sal) from employees a
The function check_xyz_func retiurns varchar2.
Now the requirement is that few more columns from the same table are needed as input to this function. So instead of giving all the column names,. can i pass the entire row as input to this function. Something like => check_xyz_func (a.*).
I tried creating a type --> TYPE rec IS TABLE OF employees%ROWTYPE and passing rec to this function, but this isn't working.

>
And what should i pass as parameter when calling the function
>
I showed you what to pass. You should pass a variable that is declared as
employee_rec employees%ROWTYPESo you would populate 'employee_rec' and pass it to the function.
See the pipelined function code below that declares a variable of %ROWTYPE and does a fetch into it.
    l_rec  emp%rowtype;
      fetch emp_cv into l_rec;You would then pass 'l_rec' to your function.
-- type to match emp record
create or replace type emp_scalar_type as object
  (EMPNO NUMBER(4) ,
   ENAME VARCHAR2(10),
   JOB VARCHAR2(9),
   MGR NUMBER(4),
   HIREDATE DATE,
   SAL NUMBER(7, 2),
   COMM NUMBER(7, 2),
   DEPTNO NUMBER(2)
-- table of emp records
create or replace type emp_table_type as table of emp_scalar_type
-- pipelined function
create or replace function get_emp( p_deptno in number )
  return emp_table_type
  PIPELINED
  as
   TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
    emp_cv EmpCurTyp;
    l_rec  emp%rowtype;
  begin
    open emp_cv for select * from emp where deptno = p_deptno;
    loop
      fetch emp_cv into l_rec;
      exit when (emp_cv%notfound);
      pipe row( emp_scalar_type( l_rec.empno, LOWER(l_rec.ename),
          l_rec.job, l_rec.mgr, l_rec.hiredate, l_rec.sal, l_rec.comm, l_rec.deptno ) );
    end loop;
    return;
  end;
select * from table(get_emp(20))

Similar Messages

  • How to pass table type variable into function from SQL*PLUS ?

    How to pass a table type variable from sql*plus prompt into a function ?
    Thanx in advance.

    Krishna,
    Do you mean like this?SQL> DECLARE
      2      TYPE t_tbl IS TABLE OF VARCHAR2(20);
      3      l_sample_tbl           t_tbl;
      4
      5      FUNCTION print_contents ( p_tbl IN t_tbl )
      6      RETURN VARCHAR2
      7      IS
      8          l_string            VARCHAR2(1000);
      9      BEGIN
    10          FOR i IN 1..p_tbl.COUNT LOOP
    11              IF (i = 1) THEN
    12                  l_string := p_tbl(i);
    13              ELSE
    14                  l_string := l_string || ', ' || p_tbl(i);
    15              END IF;
    16          END LOOP;
    17          RETURN (l_string);
    18      END print_contents;
    19
    20  BEGIN
    21      l_sample_tbl := t_tbl();
    22      l_sample_tbl.EXTEND;
    23      l_sample_tbl(1) := 'one';
    24      l_sample_tbl.EXTEND;
    25      l_sample_tbl(2) := 'two';
    26      l_sample_tbl.EXTEND;
    27      l_sample_tbl(3) := 'three';
    28      l_sample_tbl.EXTEND;
    29      l_sample_tbl(4) := 'four';
    30      l_sample_tbl.EXTEND;
    31      l_sample_tbl(5) := 'five';
    32      DBMS_OUTPUT.PUT_LINE(print_contents(l_sample_tbl));
    33  END;
    34  /
    one, two, three, four, five
    PL/SQL procedure successfully completed.
    SQL> HTH,
    T.

  • PipeLine Function Taking time to return Table record

    Hi,
    I want to use a function in join clause. so i go for pipelined function(using for loop to get record & 1 more loop to fetch in table type variable). i achieved what i required. but problem is it takes much time to fetch data. is there any other approach which returns table records without pipelined function.
    please suggest me a better approach as soon as possible.

    Hi,
    Thanks all for the quick response.
    I am using oracle 10g
    this is the table details & the entire function.
    Create object & table type to use in the function
    CREATE OR REPLACE TYPE SYSADM.STR_TYPE AS OBJECT(COLUMNVALUE VARCHAR2(8),FromNo Int,ToNo Int)
    CREATE OR REPLACE TYPE SYSADM.STR_ARRAY AS TABLE OF STR_TYPE
    table involved
    View : VesselType
    column : Code varchar2(5)
    Table : T065_SHIP
    column : SKIPS_KODE varchar2(4)
    CODE_SHIPTYPE varchar2(5)
    Table : SelsKap
    column : SELSKAPSKODE varchar2(4)
    Table : t041_shiptypeusers
    column : Code_ShipType varchar2(5)
    USERID varchar2(8)
    View : PositionBook
    column : VesselCode varchar2(8)
    VoyageNo integer
    Company varchar2(4)
    Table : T62_BRUKER_SELSKAP
    column : SELSKAPSKODE varchar2(4)
    BRUKER varchar2(8)
    Pipelined function
    CREATE OR REPLACE FUNCTION SYSADM.TF_ShiporShipTypeByUser
    In_UserName IN VARCHAR2,
    In_Type IN VARCHAR2,
    In_VesselCode IN VARCHAR2,
    In_CompanyHistory IN NUMBER DEFAULT 0
    RETURN str_array PIPELINED AS
    l_ShipTypeUser NUMBER(10,0);
    l_CompanyUser NUMBER(10,0);
    l_UseCompanyHistory NUMBER(1,0);
    l_Snicsacct NUMBER(1,0);
    BEGIN
    BEGIN
    SELECT shiptype_user,
    company_user
    INTO l_ShipTypeUser,
    l_CompanyUser
    FROM User_Segregation;
    EXCEPTION
    WHEN OTHERS THEN
    l_ShipTypeUser := NULL;
    l_CompanyUser := NULL;
    END;
    BEGIN
    SELECT 1 INTO l_Snicsacct
    FROM DUAL
    WHERE NOT EXISTS ( SELECT 1 FROM sn_user_cfg WHERE UserID='SNICS' and CfgID='ACCTSYS');
    EXCEPTION
    WHEN OTHERS THEN
    NULL;
    END;
    IF In_CompanyHistory = 1
    THEN
    BEGIN
    SELECT CfgData
    INTO l_UseCompanyHistory
    FROM SN_User_Cfg
    WHERE CfgID = 'USE COMPANY HISTORY'
    AND UserID = 'SNICS';
    EXCEPTION
    WHEN OTHERS THEN
    l_UseCompanyHistory := 0;
    END;
    END IF;
    IF In_UserName = 'SYSADM' OR (l_CompanyUser = 0 AND l_ShipTypeUser = 0)
    OR (l_CompanyUser = 1 and l_Snicsacct =1 ) or (In_CompanyHistory = 0 and l_CompanyUser = 1 and In_Type ='ShipType')
    OR (l_ShipTypeUser = 1 and In_Type = 'Company')
    THEN
    BEGIN
    IF In_Type = 'ShipType'
    THEN
    BEGIN
    FOR cur IN (SELECT Code ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM VesselType )
    LOOP
    PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
    END LOOP;
    RETURN;
    END;
    ELSIF In_Type = 'Ship'
    THEN
    BEGIN
    FOR cur IN (SELECT SKIPS_KODE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP
    WHERE SKIPS_KODE = NVL(In_VesselCode,SKIPS_KODE ))
    LOOP
    PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
    END LOOP;
    RETURN;
    END;
    ELSIF In_Type = 'Company'
    THEN
    BEGIN
    FOR cur IN (SELECT SELSKAPSKODE ShipCode
    , NULL VoyageFrom
    , NULL VoyageTo
    FROM SelsKap)
    LOOP
    PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
    END LOOP;
    RETURN;
    END;
    END IF;
    END;
    ELSE
    IF In_Type = 'Ship'
    THEN
    BEGIN
    IF l_ShipTypeUser =1
    THEN
    BEGIN
    FOR cur IN (SELECT S.SKIPS_KODE ShipCode
    , 1 FromVoyage
    , 999999999 ToVoyage
    FROM T065_SHIP S
    JOIN t041_shiptypeusers U
    ON S.CODE_SHIPTYPE = U.Code_ShipType
    AND USERID = In_UserName
    WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
    GROUP BY S.SKIPS_KODE)
    LOOP
    PIPE ROW(str_type(cur.ShipCode,cur.FromVoyage,cur.ToVoyage));
    END LOOP;
    RETURN;
    END;
    ELSIF l_CompanyUser = 1
    THEN
    BEGIN
    IF l_UseCompanyHistory = 1 AND In_CompanyHistory = 1
    THEN
    FOR cur IN (SELECT a.VesselCode ShipCode
    , a.VoyageNo VoyageFrom
    , a.VoyageNo VoyageTo
    FROM PositionBook a
    JOIN T62_BRUKER_SELSKAP b
    ON a.Company = b.SELSKAPSKODE
    AND b.BRUKER = In_UserName
    WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
    UNION
    SELECT a.VesselCode ShipCode
    , a.VoyageNo VoyageFrom
    , a.VoyageNo VoyageTo
    FROM PositionBook a
    LEFT JOIN T62_BRUKER_SELSKAP b
    ON a.company = b.SELSKAPSKODE
    WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
    AND b.SELSKAPSKODE IS NULL
    GROUP BY a.VesselCode,
    a.VoyageNo,
    a.VoyageNo)
    LOOP
    PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
    END LOOP;
    RETURN;
    ELSE
    FOR cur IN (SELECT a.SKIPS_KODE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP a
    JOIN T62_BRUKER_SELSKAP b
    ON a.Company = b.SELSKAPSKODE
    AND b.BRUKER = In_UserName
    WHERE a.SKIPS_KODE = NVL(In_VesselCode, a.SKIPS_KODE)
    AND NVL(l_UseCompanyHistory,0) = 0
    UNION
    SELECT a.SKIPS_KODE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP a
    LEFT JOIN T62_BRUKER_SELSKAP b
    ON a.company = b.SELSKAPSKODE
    WHERE a.SKIPS_KODE = NVL(In_VesselCode, a.SKIPS_KODE)
    AND b.SELSKAPSKODE IS NULL
    GROUP BY a.SKIPS_KODE)
    LOOP
    PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
    END LOOP;
    RETURN;
    END IF;
    END;
    END IF;
    END;
    ELSIF In_Type = 'ShipType'
    THEN
    IF l_ShipTypeUser = 1
    THEN
    BEGIN
    FOR cur IN (SELECT S.CODE_SHIPTYPE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP S
    JOIN t041_shiptypeusers U
    ON S.CODE_SHIPTYPE = U.Code_ShipType
    AND USERID = In_UserName
    WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
    GROUP BY S.CODE_SHIPTYPE)
    LOOP
    PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
    END LOOP;
    RETURN;
    END;
    ELSIF l_CompanyUser = 1
    THEN
    IF l_UseCompanyHistory = 1 AND In_CompanyHistory = 1
    THEN
    BEGIN
    FOR cur IN (SELECT a.VesselType ShipCode
    , a.VoyageNo VoyageFrom
    , a.VoyageNo VoyageTo
    FROM PositionBook a
    JOIN T62_BRUKER_SELSKAP b
    ON a.COMPANY = b.SELSKAPSKODE
    AND b.BRUKER = In_UserName
    WHERE a.VesselCode = NVL(In_VesselCode,a.VesselCode)
    UNION
    SELECT a.VesselType ShipCode
    , a.VoyageNo VoyageFrom
    , a.VoyageNo VoyageTo
    FROM PositionBook a
    LEFT JOIN T62_BRUKER_SELSKAP b
    ON a.company = b.SELSKAPSKODE
    WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
    AND b.SELSKAPSKODE IS NULL
    GROUP BY a.VesselType,
    a.VoyageNo,
    a.VoyageNo)
    LOOP
    PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
    END LOOP;
    RETURN;
    END;
    ELSE
    BEGIN
    FOR cur IN (SELECT S.CODE_SHIPTYPE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP S
    JOIN T62_BRUKER_SELSKAP b
    ON S.company = b.SELSKAPSKODE
    AND B.BRUKER = In_UserName
    WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
    AND NVL(l_UseCompanyHistory,0) = 0
    UNION
    SELECT S.CODE_SHIPTYPE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP S
    LEFT JOIN T62_BRUKER_SELSKAP b
    ON S.company = b.SELSKAPSKODE
    WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
    AND b.SELSKAPSKODE IS NULL)
    LOOP
    PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
    END LOOP;
    RETURN;
    END;
    END IF;
    END IF;
    ELSIF In_Type = 'Company'
    THEN
    BEGIN
    FOR cur IN (SELECT a.SELSKAPSKODE ShipCode
    , NULL VoyageFrom
    , NULL VoyageTo
    FROM Selskap a
    JOIN T62_BRUKER_SELSKAP b
    ON a.SELSKAPSKODE = b.SELSKAPSKODE
    WHERE b.BRUKER = In_UserName
    Union All
    Select a.SELSKAPSKODE ShipCode
    , NULL VoyageFrom
    , NULL VoyageTo
    From Selskap a
    LEFT JOIN T62_BRUKER_SELSKAP b
    ON a.SELSKAPSKODE = b.SELSKAPSKODE
    Where b.SELSKAPSKODE IS NULL
    GROUP BY a.SELSKAPSKODE)
    LOOP
    PIPE ROW(str_type(cur.ShipCode,cur.VoyageFrom,cur.VoyageTo));
    END LOOP;
    RETURN;
    END;
    END IF;
    END IF;
    END;
    select statement which i call the function it takes minimum 6 seconds to execute. It gives 8339 records
    WITH deftbl AS ( SELECT /*+ CACHE(deftbl) */
    /*+ result_cache */
    a.VesselCode,
    a.VoyageNo,
    CASE a.BallastLeg When 0
    THEN MIN(a.ArrivalDate)
    ELSE NVL(( SELECT MAX(DepartureDate)
    FROM PositionBook b
    WHERE b.VesselCode = a.VesselCode
    AND b.VoyageNo = (Select MAX(VoyageNo) From PositionBook c Where c.VesselCode = a.VesselCode and c.VoyageNo<a.VoyageNo)
    ),MIN(a.ArrivalDate))
    END AS StartOfVoyage,
    MAX(DepartureDate) EndOfVoyage
    FROM PositionBook a
    JOIN TABLE(*TF_ShiporShipTypeByUser*('BKA', 'Ship', NULL, 1)) D        /*Calling the function*/
    ON D.ColumnValue = a.VesselCode
    AND a.VoyageNo BETWEEN D.FromVoyageNo AND D.ToVoyageNo
    GROUP BY VesselCode,VoyageNo,a.BallastLeg )
    SELECT /*+ result_cache */
    ROW_NUMBER() OVER(PARTITION BY a.VesselCode ORDER BY a.VoyageNo DESC) as "Row"
    ,a.VesselCode
    ,v.Name AS VesselName
    ,a.VoyageNo
    ,c.StartOfVoyage AS FromPort
    ,c.EndOfVoyage AS ToPort
    /*,a.FROMPORT
    ,a.TOPORT*/
    , CASE
    WHEN ( SELECT PortName
    FROM PositionBook b
    WHERE b.VesselCode = a.VesselCode
    AND b.VoyageNo = a.VoyageNo
    AND SYSDATE BETWEEN ArrivalDate AND DepartureDate ) IS NOT NULL
    THEN ( SELECT FIRST_VALUE(PortName) OVER(PARTITION BY b.vesselcode,b.VoyageNo ORDER BY b.vesselcode,b.VoyageNo,b.ArrivalDate,b.secondarytime)
    FROM PositionBook b
    WHERE b.VesselCode = a.VesselCode
    AND b.VoyageNo = a.VoyageNo
    AND SYSDATE BETWEEN ArrivalDate AND DepartureDate
    AND ROWNUM=1
    WHEN SYSDATE BETWEEN c.StartOfVoyage AND c.EndOfVoyage
    THEN ( SELECT 'Steam From '||FIRST_VALUE(UPPER(PortName)) OVER(PARTITION BY b.vesselcode,b.VoyageNo ORDER BY b.vesselcode,b.VoyageNo,b.ArrivalDate desc,b.secondarytime desc)
    FROM POSITIONBOOK b
    WHERE b.VesselCode = a.VesselCode AND b.VoyageNo = a.VoyageNo
    AND b.ArrivalDate<SYSDATE
    AND ROWNUM=1
    WHEN (c.StartOfVoyage-SYSDATE)>0
    THEN 'Voyage Not Started'
    WHEN (c.EndOfVoyage-SYSDATE)<0
    THEN 'Voyage Completed'
    ELSE Null
    END "Location"
    ,( SELECT MIN(b.PortName) KEEP(DENSE_RANK FIRST ORDER BY b.ArrivalDate,b.secondarytime) OVER(PARTITION BY b.VesselCode,b.VoyageNo)
    FROM POSITIONBOOK b
    WHERE b.VesselCode = a.VesselCode AND b.VoyageNo = a.VoyageNo
    AND b.ArrivalDate>SYSDATE
    AND ROWNUM=1
    ) AS NextPort
    , ( SELECT MIN(b.ArrivalDate) KEEP(DENSE_RANK FIRST ORDER BY b.ArrivalDate,b.secondarytime) OVER(PARTITION BY b.VesselCode,b.VoyageNo)
    FROM POSITIONBOOK b
    where b.VesselCode = a.VesselCode AND b.VoyageNo = a.VoyageNo
    AND b.ArrivalDate>SYSDATE
    AND ROWNUM=1
    ) AS NextETA
    ,a.STATUS VoyageStatus
    ,a.Trade
    ,UFN_MyVoyConcatinate_Values('FIXNOTE', a.VesselCode, a.VoyageNo) FixNote
    ,UFN_MyVoyConcatinate_Values('CHARTERER', a.VesselCode, a.VoyageNo) Charterer
    ,CASE WHEN st.CurrentStatus=0
    THEN 1
    WHEN st.CurrentStatus=1
    THEN 0
    ELSE st.CurrentStatus
    END AS CurrentStatus
    FROM Positionbook a
    JOIN deftbl c
    ON a.VesselCode = c.VesselCode
    AND a.VoyageNo = c.VoyageNo
    JOIN Vessel v
    ON v.Code = c.VesselCode
    LEFT JOIN GTT_VOYAGESTATUS st
    ON st.VesselCode = c.Vesselcode
    AND st.VoyageNo = c.VoyageNo
    GROUP BY a.VesselCode
    , v.Name
    , a.VoyageNo
    , c.StartOfVoyage
    , c.EndOfVoyage
    /*, a.FROMPORT
    , a.TOPORT*/
    , a.Status
    , a.Trade
    , st.CurrentStatus;
    Note:
    i changed the function without pipelined also. but it doesnt show much difference
    non pipelined function
    CREATE OR REPLACE FUNCTION TF_ShiporShipTypeByUser_nonp
    In_UserName IN VARCHAR2,
    In_Type IN VARCHAR2,
    In_VesselCode IN VARCHAR2,
    In_CompanyHistory IN NUMBER DEFAULT 0
    RETURN str_array AS
    l_ShipTypeUser NUMBER(10,0);
    l_CompanyUser NUMBER(10,0);
    l_UseCompanyHistory NUMBER(1,0);
    l_Snicsacct NUMBER(1,0);
    l_str_array str_array:=str_array();
    BEGIN
    BEGIN
    SELECT shiptype_user,
    company_user
    INTO l_ShipTypeUser,
    l_CompanyUser
    FROM User_Segregation;
    EXCEPTION
    WHEN OTHERS THEN
    l_ShipTypeUser := NULL;
    l_CompanyUser := NULL;
    END;
    BEGIN
    SELECT 1 INTO l_Snicsacct
    FROM DUAL
    WHERE NOT EXISTS ( SELECT 1 FROM sn_user_cfg WHERE UserID='SNICS' and CfgID='ACCTSYS');
    EXCEPTION
    WHEN OTHERS THEN
    NULL;
    END;
    IF In_CompanyHistory = 1
    THEN
    BEGIN
    SELECT CfgData
    INTO l_UseCompanyHistory
    FROM SN_User_Cfg
    WHERE CfgID = 'USE COMPANY HISTORY'
    AND UserID = 'SNICS';
    EXCEPTION
    WHEN OTHERS THEN
    l_UseCompanyHistory := 0;
    END;
    END IF;
    IF In_UserName = 'SYSADM' OR (l_CompanyUser = 0 AND l_ShipTypeUser = 0)
    OR (l_CompanyUser = 1 and l_Snicsacct =1 ) or (In_CompanyHistory = 0 and l_CompanyUser = 1 and In_Type ='ShipType')
    OR (l_ShipTypeUser = 1 and In_Type = 'Company')
    THEN
    BEGIN
    IF In_Type = 'ShipType'
    THEN
    BEGIN
    SELECT STR_TYPE(Code,1,999999999)
    BULK COLLECT INTO l_str_array
    FROM VesselType;
    RETURN l_str_array;
    END;
    ELSIF In_Type = 'Ship'
    THEN
    BEGIN
    SELECT STR_TYPE(SKIPS_KODE,1,999999999)
    BULK COLLECT INTO l_str_array
    FROM T065_SHIP
    WHERE SKIPS_KODE = NVL(In_VesselCode,SKIPS_KODE);
    RETURN l_str_array;
    END;
    ELSIF In_Type = 'Company'
    THEN
    BEGIN
    SELECT STR_TYPE(SELSKAPSKODE,NULL,NULL)
    BULK COLLECT INTO l_str_array
    FROM SelsKap;
    RETURN l_str_array;
    END;
    END IF;
    END;
    ELSE
    IF In_Type = 'Ship'
    THEN
    BEGIN
    IF l_ShipTypeUser =1
    THEN
    BEGIN
    SELECT STR_TYPE(S.SKIPS_KODE,1,999999999)
    BULK COLLECT INTO l_str_array
    FROM T065_SHIP S
    JOIN t041_shiptypeusers U
    ON S.CODE_SHIPTYPE = U.Code_ShipType
    AND USERID = In_UserName
    WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
    GROUP BY S.SKIPS_KODE;
    RETURN l_str_array;
    END;
    ELSIF l_CompanyUser = 1
    THEN
    BEGIN
    IF l_UseCompanyHistory = 1 AND In_CompanyHistory = 1
    THEN
    SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
    BULK COLLECT INTO l_str_array
    FROM ( SELECT a.VesselCode ShipCode
    , a.VoyageNo VoyageFrom
    , a.VoyageNo VoyageTo
    FROM PositionBook a
    JOIN T62_BRUKER_SELSKAP b
    ON a.Company = b.SELSKAPSKODE
    AND b.BRUKER = In_UserName
    WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
    UNION
    SELECT a.VesselCode ShipCode
    , a.VoyageNo VoyageFrom
    , a.VoyageNo VoyageTo
    FROM PositionBook a
    LEFT JOIN T62_BRUKER_SELSKAP b
    ON a.company = b.SELSKAPSKODE
    WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
    AND b.SELSKAPSKODE IS NULL
    GROUP BY a.VesselCode,
    a.VoyageNo,
    a.VoyageNo);
    RETURN l_str_array;
    ELSE
    SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
    BULK COLLECT INTO l_str_array
    FROM (SELECT a.SKIPS_KODE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP a
    JOIN T62_BRUKER_SELSKAP b
    ON a.Company = b.SELSKAPSKODE
    AND b.BRUKER = In_UserName
    WHERE a.SKIPS_KODE = NVL(In_VesselCode, a.SKIPS_KODE)
    AND NVL(l_UseCompanyHistory,0) = 0
    UNION
    SELECT a.SKIPS_KODE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP a
    LEFT JOIN T62_BRUKER_SELSKAP b
    ON a.company = b.SELSKAPSKODE
    WHERE a.SKIPS_KODE = NVL(In_VesselCode, a.SKIPS_KODE)
    AND b.SELSKAPSKODE IS NULL
    GROUP BY a.SKIPS_KODE);
    RETURN l_str_array;
    END IF;
    END;
    END IF;
    END;
    ELSIF In_Type = 'ShipType'
    THEN
    IF l_ShipTypeUser = 1
    THEN
    BEGIN
    SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
    BULK COLLECT INTO l_str_array
    FROM (SELECT S.CODE_SHIPTYPE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP S
    JOIN t041_shiptypeusers U
    ON S.CODE_SHIPTYPE = U.Code_ShipType
    AND USERID = In_UserName
    WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
    GROUP BY S.CODE_SHIPTYPE);
    RETURN l_str_array;
    END;
    ELSIF l_CompanyUser = 1
    THEN
    IF l_UseCompanyHistory = 1 AND In_CompanyHistory = 1
    THEN
    BEGIN
    SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
    BULK COLLECT INTO l_str_array
    FROM ( SELECT a.VesselType ShipCode
    , a.VoyageNo VoyageFrom
    , a.VoyageNo VoyageTo
    FROM PositionBook a
    JOIN T62_BRUKER_SELSKAP b
    ON a.COMPANY = b.SELSKAPSKODE
    AND b.BRUKER = In_UserName
    WHERE a.VesselCode = NVL(In_VesselCode,a.VesselCode)
    UNION
    SELECT a.VesselType ShipCode
    , a.VoyageNo VoyageFrom
    , a.VoyageNo VoyageTo
    FROM PositionBook a
    LEFT JOIN T62_BRUKER_SELSKAP b
    ON a.company = b.SELSKAPSKODE
    WHERE a.VesselCode = NVL(In_VesselCode, a.VesselCode)
    AND b.SELSKAPSKODE IS NULL
    GROUP BY a.VesselType,
    a.VoyageNo,
    a.VoyageNo);
    RETURN l_str_array;
    END;
    ELSE
    BEGIN
    SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
    BULK COLLECT INTO l_str_array
    FROM ( SELECT S.CODE_SHIPTYPE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP S
    JOIN T62_BRUKER_SELSKAP b
    ON S.company = b.SELSKAPSKODE
    AND B.BRUKER = In_UserName
    WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
    AND NVL(l_UseCompanyHistory,0) = 0
    UNION
    SELECT S.CODE_SHIPTYPE ShipCode
    , 1 VoyageFrom
    , 999999999 VoyageTo
    FROM T065_SHIP S
    LEFT JOIN T62_BRUKER_SELSKAP b
    ON S.company = b.SELSKAPSKODE
    WHERE S.SKIPS_KODE = NVL(In_VesselCode, S.SKIPS_KODE)
    AND b.SELSKAPSKODE IS NULL);
    RETURN l_str_array;
    END;
    END IF;
    END IF;
    ELSIF In_Type = 'Company'
    THEN
    BEGIN
    SELECT STR_TYPE(ShipCode,VoyageFrom,VoyageTo)
    BULK COLLECT INTO l_str_array
    FROM ( SELECT a.SELSKAPSKODE ShipCode
    , NULL VoyageFrom
    , NULL VoyageTo
    FROM Selskap a
    JOIN T62_BRUKER_SELSKAP b
    ON a.SELSKAPSKODE = b.SELSKAPSKODE
    WHERE b.BRUKER = In_UserName
    Union All
    Select a.SELSKAPSKODE ShipCode
    , NULL VoyageFrom
    , NULL VoyageTo
    From Selskap a
    LEFT JOIN T62_BRUKER_SELSKAP b
    ON a.SELSKAPSKODE = b.SELSKAPSKODE
    Where b.SELSKAPSKODE IS NULL
    GROUP BY a.SELSKAPSKODE);
    RETURN l_str_array;
    END;
    END IF;
    END IF;
    END;please kindly provide me your valuable suggestions
    Edited by: ganex27lin on Mar 16, 2011 1:54 AM

  • Pass table name as a parameter to function

    Is there a way to pass table name as a parameter to functions? Then update the table in the function.
    Thanks a lot.
    Jiaxin

    Hi, Harm,
    Thank you very much for your suggestion and example. But to get my program work, i need to realise code like follows:
    CREATE OR REPLACE FUNCTION delstu_func(stuno char) RETURN NUMBER AS
    BEGIN
    EXECUTE IMMEDIATE 'DELETE FROM student s' ||
    'WHERE' || 's.student_number' || '=' || stuno;
    LOOP
    DBMS_OUTPUT.PUT_LINE('record deleted');
    END LOOP;
    END;
    SELECT delstu_func('s11') FROM STUDENT;
    The intention is to check if such a function can perform operations such as update, delete and insert on occurence of certain values. When executing the above statement, the system returns an error message:
    ERROR at line 1:
    ORA-00933: SQL command not properly ended
    ORA-06512: at "SCMJD1.DELSTU_FUNC", line 3
    Could you tell me where is wrong?
    Jiaxin

  • Error in Java Program when passing table to RFC function . JCO is used

    Hai All,
    I developed a JAVA application to update data into SAP using JCO via RFC. When i pass table to the function module i am getting the below error
    com.sap.mw.jco.JCO$Exception: (104) RFC_ERROR_SYSTEM_FAILURE: Conversion from type T to D not supported.
    Please let me know how to solve this.
    Below is my code
    IRepository m_Repository;
    IFunctionTemplate ftemplate;
    JCO.Table PwdReq;
    JCO.Function function;
    m_Repository = JCO.createRepository("MYRepository", client);
                ftemplate = m_Repository.getFunctionTemplate("Z_GESEFM_UPD_PWD_RESET_REQUEST");
    // Create a function from the template
    function = new JCO.Function(ftemplate);
    // Feeding in input parameters
    PwdReq = function.getTableParameterList().getTable("RESULT2");
    String userid = "PATCHTEST14 ", reqDate = "",reqNo = "01",reqStatus = "03", boxID = "09",ind2 = "X",
                        lcode = "abcd",rem = "One record testing";
    PwdReq.appendRow();
                    PwdReq.setValue(userid, "USERID");
                    PwdReq.setValue(reqNo,"REQ_NO");
                    PwdReq.setValue(reqStatus,"REQ_STATUS");
                    PwdReq.setValue(boxID,"BOX_ID");
                    PwdReq.setValue(ind2,"IND2");
                    PwdReq.setValue(lcode,"LCODE");
                    PwdReq.setValue(rem,"OTHER_REMARKS");
                // execute the function with the input parameters
                client.execute(function);
    Thanks & Regards,
    H.K.Hayath Basha.

    hi,
    I am not very good in Java.
    but try this code to giving input parameter.
    function.getImportParameterList().setValue(userid, "USERID");
    if you are not using Try and Catch blok then use Try and Catch blok,
    Regards
    Manoj

  • Function module for move internal table records into MSexcel file

    Hi all,
    Tell me the function module which is used to
    move internal table records in to MSexcel file.
    Give the sample program...

    Please search the forum for FM  "GUI_DOWNLOAD" You will get tons of threads with sample code.
    Also take a look into SAP_CONVERT_TO_XLS_FORMAT
    Thanks

  • Passing selection table as parameter to function modules

    i tried to pass a selection table as a parameter to a function module but there is a problem stating the eror the table length is different.
    *& Report  ZSFSELECT_OPTIONS_PGM
    REPORT  zsfselect_options_pgm.
    TABLES zselect_options.
    SELECT-OPTIONS sop FOR zselect_options-id.
    DATA  : fname(15) TYPE c.
    *CALL FUNCTION 'SSF_FUNCTION_MODULE_NAME'
    EXPORTING
       formname                 = fname
      VARIANT                  = ' '
      DIRECT_CALL              = ' '
    IMPORTING
      FM_NAME                  =
    EXCEPTIONS
      NO_FORM                  = 1
      NO_FUNCTION_MODULE       = 2
      OTHERS                   = 3
    *IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    *ENDIF.
    DATA lth(2) TYPE c.
    DATA ty TYPE i.
    DATA o TYPE i.
    DATA l TYPE i.
    DATA k TYPE c.
    DESCRIBE FIELD sop-sign TYPE lth LENGTH ty IN CHARACTER MODE.
    CALL FUNCTION fname
    EXPORTING
      ARCHIVE_INDEX              =
      ARCHIVE_INDEX_TAB          =
      ARCHIVE_PARAMETERS         =
      CONTROL_PARAMETERS         =
      MAIL_APPL_OBJ              =
      MAIL_RECIPIENT             =
      MAIL_SENDER                =
      OUTPUT_OPTIONS             =
      USER_SETTINGS              = 'X'
    IMPORTING
      DOCUMENT_OUTPUT_INFO       =
      JOB_OUTPUT_INFO            =
      JOB_OUTPUT_OPTIONS         =
      TABLES
        sf_sop                     =sop
    EXCEPTIONS
      FORMATTING_ERROR           = 1
      INTERNAL_ERROR             = 2
      SEND_ERROR                 = 3
      USER_CANCELED              = 4
      OTHERS                     = 5
    IF sy-subrc <> 0.
    MESSAGE ID SY-MSGID TYPE SY-MSGTY NUMBER SY-MSGNO
            WITH SY-MSGV1 SY-MSGV2 SY-MSGV3 SY-MSGV4.
    ENDIF.
    in the smart form i have tried to pass the sp as the table.
    i have created a program line node
    :SELECT * FROM zselect_options INTO TABLE it_tab WHERE id IN sf_sop.

    Hi,
    If i understand ur problem correctly u r trying to pass a select-option to Tables for a smartform function module. It gives an error & it correct.
    If u understand the structure of a select option, it will have 4 fields in it & the structure will be
    SIGN                   CHAR1
    OPTION               CHAR2
    LOW                   Type Zfield
    HIGH                   Type Zfield
    But ur receiving Table paramter of the smnartform FM will be having only 1 field - Type Zfield
    So this mismatch gives u an error.
    Solution:
    Case1:
    Write code outsied th FM in ur program to get all the values & build an internal table & pass that to the FM.
    Case2:
    Define the Structure of table in the smartforms as tols earlier & then try passsig the Select option.
    Thanks & Regards,
    Bhargava

  • Passing parameter for the bean function that deletes record from DB

    I need to delete some record from the DB without updating the reset of the user screen.
    I use commandButton with immediate attribute as true, because validation should be skipped.
    So, I can't rely on backing bean values being updated, but need to pass a param to the function that does the delete (deleteTemplate) function below.
    The value of this param is selected value in another comboBox called "template".
    Code below is not parsing. Could you advise how to do it?
    <a4j:commandButton id="deleteTemplate" value="Delete"
                             action="#{qtBeanParam.deleteTemplate(param['piPerformanceReturnsForm:template'])}" immediate="true" reRender="template,templateList,templateOwner,templateOwnerList"
                             styleClass="blue-button">
                        </a4j:commandButton>Error Parsing: #{qtBeanParam.deleteTemplate(param['piPerformanceReturnsForm:template'])}

    Thank you for your reply.
    Could I pass the value that is entered in some other field as a "parameter" though?
    <f:param name="anyName" value="parameter" />
    For example the value from the following comboBox?
    <rich:comboBox id="template" width="250" value="#{qtBeanParam.templateName}" enableManualInput="true"
                                  converter="#{templateConverter}" valueChangeListener="#{qtBeanParam.changeTemplate}" >
                                  <a4j:support event="onselect" reRender="template,templateList" ajaxSingle="true" />
                                  <a4j:support event="onchange" reRender="template,templateList" ajaxSingle="true" />
                             <f:selectItems id="templateList" value="#{qtBeanParam.templateList}" />
                        </rich:comboBox>

  • How can I convert table object into table record format?

    I need to write a store procedure to convert table object into table record. The stored procedure will have a table object IN and then pass the data into another stored procedure with a table record IN. Data passed in may contain more than one record in the table object. Is there any example I can take a look? Thanks.

    I'm afraid it's a bit labourious but here's an example.
    I think it's a good idea to work with SQL objects rather than PL/SQL nested tables.
    SQL> CREATE OR REPLACE TYPE emp_t AS OBJECT
      2      (eno NUMBER(4)
      3      , ename  VARCHAR2(10)
      4      , job VARCHAR2(9)
      5      , mgr  NUMBER(4)
      6      , hiredate  DATE
      7      , sal  NUMBER(7,2)
      8      , comm  NUMBER(7,2)
      9      , deptno  NUMBER(2));
    10  /
    Type created.
    SQL> CREATE OR REPLACE TYPE staff_nt AS TABLE OF emp_t
      2  /
    Type created.
    SQL> Now we've got some Types let's use them. I've only implemented this as one public procedure but you can see the principles in action.
    SQL> CREATE OR REPLACE PACKAGE emp_utils AS
      2      TYPE EmpCurTyp IS REF CURSOR RETURN emp%ROWTYPE;
      3      PROCEDURE pop_emp (p_emps in staff_nt);
      4  END  emp_utils;
      5  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY emp_utils AS
      2      FUNCTION emp_obj_to_rows (p_emps IN staff_nt) RETURN EmpCurTyp IS
      3          rc EmpCurTyp;
      4      BEGIN
      5          OPEN rc FOR SELECT * FROM TABLE( CAST ( p_emps AS staff_nt ));
      6          RETURN rc;
      7      END  emp_obj_to_rows;
      8      PROCEDURE pop_emp (p_emps in staff_nt) is
      9          e_rec emp%ROWTYPE;
    10          l_emps EmpCurTyp;
    11      BEGIN
    12          l_emps := emp_obj_to_rows(p_emps);
    13          FETCH l_emps INTO e_rec;
    14          LOOP
    15              EXIT WHEN l_emps%NOTFOUND;
    16              INSERT INTO emp VALUES e_rec;
    17              FETCH l_emps INTO e_rec;
    18          END LOOP;
    19          CLOSE l_emps;
    20      END pop_emp;   
    21  END;
    22  /
    Package body created.
    SQL>Looks good. Let's see it in action...
    SQL> DECLARE
      2      newbies staff_nt :=  staff_nt();
      3  BEGIN
      4      newbies.extend(2);
      5      newbies(1) := emp_t(7777, 'APC', 'CODER', 7902, sysdate, 1700, null, 40);
      6      newbies(2) := emp_t(7778, 'J RANDOM', 'HACKER', 7902, sysdate, 1800, null, 40);
      7      emp_utils.pop_emp(newbies);
      8  END;
      9  /
    PL/SQL procedure successfully completed.
    SQL> SELECT * FROM emp WHERE deptno = 40
      2  /
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM
        DEPTNO
          7777 APC        CODER           7902 17-NOV-05       1700
            40
          7778 J RANDOM   HACKER          7902 17-NOV-05       1800
            40
    SQL>     Cheers, APC

  • How to send Internal table records to Idoc Inbound posting FM to create Ido

    Hello Experts,
    I have all the data necessary to create shipments in one internal table inside my ABAP program.
    I can use BAPI_SHIPMENT_CREATE to create shipments. But associated with this BAPi there is one ALE message type SHIPMENT_CREATEFROMDATA. Now my requirement is to use this message type to cretae my shipments via idocs for one scenario for some of the records in the internal table.
    For this message type, I got the inbound function module IDOC_INPUT_SHIPMENT_CREATEFROM from TBDBE table.
    Can anybody please let me know how to send the data from the internal table to this inbound function  module?
    Becasue it has mandatory parameters INPUT_METHOD, MASS_PROCESSING. What values should be passed to these parameters if the data has to be sent to this function module?
    Regards.

    Hi Ravikanth,
    Thankyou very much for your quick reply.
    So If I split my internal table data and populate IDOC_DATA and IDOC_CONTROL and pass to the inbound function module directly in my ABAP program, will that be going to create idocs and post shipments?
    I mean is it enough to call the Inbound posting function module directly in my ABAP program or any other FMs to be called to take care of ALE settings and shipment creation?
    Please confirm.
    REgards.

  • Passing table data to pl sql procedure oaf

    Hi All,
    I have a requirement where i have to pass table data to plsql procedure.
    In the first page i select the REQUISITION and click on RETURN button and it will take me to the next page.
    and in the Next page i will click on APPLY button.
    When i click on APPLY, it will call the procedure and will give input to the procedure whatever has been selected when i have selected requisition.
    Please help. Please tell me the approach how to get this task done. A sample code will work.
    Hope the requirement is clear.
    Thanks in Advance.

    Hi Chinmay,
    Refer below code for Your Requirement.
    //Code For Quering Data
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    Connection conn = pageContext.getApplicationModule(webBean).getOADBTransaction().getJdbcConnection();
    String Query = "SELECT organization_id FROM hr_operating_units WHERE organization_id = fnd_global.org_id";
    PreparedStatement stmt = conn.prepareStatement(Query);
    resultset=stmt.executeQuery();
    while (resultset.next())
    orgId = (String)resultset.getString("ORGANIZATION_ID").toString();
    conn.commit();
    catch(Exception e)
    e.printStackTrace();
    //Code for Pass Resulted column to Procedure Input for delete Particular Record
    Execute parameterized PL SQL procedure from OAF page
    Let us try to call PL/SQL package from OAF page. We will try to remove selected line from Database.
    Package Spec
    CREATE OR REPLACE PACKAGE APPS.genpack_pkg
    AS
    PROCEDURE roll_delete_proc (orgId IN VARCHAR2);
    END genpack_pkg;
    Package Body
    CREATE OR REPLACE PACKAGE BODY APPS.genpack_pkg
    AS
    PROCEDURE roll_delete_proc (orgId IN VARCHAR2)
    AS
    BEGIN
    DELETE FROM pklist_roll_details_temp
    WHERE roll_line_id = orgId;
    COMMIT;
    END roll_delete_proc;
    END genpack_pkg;
    //in Controller PFR
    import java.sql.CallableStatement;
    if (pageContext.getParameter("ActionsButton") != null)
    String val = pageContext.getParameter("ActionsChoice");
    if ("DELLN".equals(val))
    CallableStatement cstmt = null;
    for (OAViewRowImpl row = (OAViewRowImpl)tempvo.first(); row != null; row = (OAViewRowImpl)tempvo.next()) {
    if ((row.getAttribute("Selectflag") == null) ||
    (!row.getAttribute("Selectflag").toString().equals("Y"))) continue;
    try {
    int rollid = Integer.parseInt((String)row.getAttribute("orgId"));
    Connection conn = am.getOADBTransaction().getJdbcConnection();
    if (rollid == 1)
    temphm.put(row.getAttribute("orgId").toString(), row.getAttribute("PoNumber").orgId());
    tempvo.removeCurrentRow();
    else
    try
    StringBuilder sb = new StringBuilder();
    sb.append(rollid);
    String strI = sb.toString();
    System.out.println("Inside else in delete");
    cstmt = conn.prepareCall("{call GENPACK_PKG.tpc_roll_delete_proc(?)}");
    cstmt.setString(1, strI);
    System.out.println("Oracle Callable Statment Execution Init for Delete");
    cstmt.execute();
    catch (SQLException e) {
    throw new OAException(e.toString(), (byte)0);
    }tempvo.removeCurrentRow();
    catch (OAException e) {
    throw new OAException("No row selected", (byte)3);
    Thanks,
    Dilip

  • Help passing table name as parameter to a procedure

    Hello,
    i'm trying to write a procedure that takes a table name as input and uses a cursor to select a column,count(1) from the passed table to the cursor. The procedure i've come up with is as follows,
    CREATE OR REPLACE
    PROCEDURE excur(
        p_tbl user_tables.table_name%type )
    AS
      type rc is ref cursor;
      c rc;
      res BOOLEAN;
    BEGIN
      open c for 'SELECT columnA,COUNT(1) FROM'|| p_tbl||';';
      close c;
    END excur;When i try to execute it, an error pops up informing that a table cannot be used in this context. As in i cannot pass a table name as an argument to a procedure. Kindly guide as to how to solve this situation.

    vishm8 wrote:
    Hello,
    i'm trying to write a procedure that takes a table name as input and uses a cursor to select a column,count(1) from the passed table to the cursor. The procedure i've come up with is as follows,
    CREATE OR REPLACE
    PROCEDURE excur(
    p_tbl user_tables.table_name%type )
    AS
    type rc is ref cursor;
    c rc;
    res BOOLEAN;
    BEGIN
    open c for 'SELECT columnA,COUNT(1) FROM'|| p_tbl||';';
    close c;
    END excur;When i try to execute it, an error pops up informing that a table cannot be used in this context. As in i cannot pass a table name as an argument to a procedure. Kindly guide as to how to solve this situation.Generally speaking, Dynamic code is a bad idea for a staggering number of reasons.
    That aside, what do you want to return? You're selecting a column and applying an aggregate function (count) but you're not grouping, that doesn't usually work out too well.
    TUBBY_TUBBZ?select owner, count(*) from all_objects;
    select owner, count(*) from all_objects
    ERROR at line 1:
    ORA-00937: not a single-group group functionWhy do you perceive the need to be able to take in ANY table name, can't you design an application where table names are known at compile time and not run time?

  • Passing TABLE NAME as parameter is possible or not?

    I want develop a small/simple report like this
    TABLE NAME :
    WHERE :
    ORDER BY :
    QUERY ROWS
    In the above model i want to pass all the three (TABLE NAME,WHERE and ORDER BY) as a parameter.
    My doubt, is that possible to pass TABLE NAME as a parameter? If so!
    When i enter any TABLE NAME it has to fetch me out the records of that table (Based on WHERE condition and ORDER BY).
    Is that possible to do?
    Need some help!
    Edited by: Muthukumar Seshadri on Aug 10, 2012 6:19 PM

    Yes, it is possible with lexical parameters. Look in the help for examples:
    SELECT Clause
    SELECT &P_ENAME NAME, &P_EMPNO ENO, &P_JOB ROLE  FROM EMP
    P_ENAME, P_EMPNO, and P_JOB can be used to change the columns selected at runtime.  For example, you could enter DEPTNO as the value for P_EMPNO on the Runtime Parameter Form. 
    Note that in this case, you should use aliases for your columns.  Otherwise, if you change the columns selected at runtime, the column names in the SELECT list will not match the Report Builder columns and the report will not run.
    FROM Clause
    SELECT ORDID, TOTAL FROM &ATABLE
    ATABLE can be used to change the table from which columns are selected at runtime.  For example, you could enter ORD for ATABLE at runtime. 
    If you dynamically change the table name in this way, you may also want to use lexical references for the SELECT clause (look at the previous example) in case the column names differ between tables.
    WHERE Clause
    SELECT ORDID, TOTAL FROM ORD WHERE &CUST
    ORDER BY Clause
    SELECT ORDID, SHIPDATE, ORDERDATE, TOTAL  FROM ORD ORDER BY &SORT You have to be really careful with this approach. Dynamic SQL may cause serious performance problems.
    Edited by: InoL on Aug 10, 2012 10:06 AM

  • How to declare Dynamic table in Tables Parameters of a Function Module...

    Hi Gurus,
    I would like to Know how to declare a Dynamic table in Tables parameters of a Function Module.
    so that it should be able to hold any table data ....
    I have tried all possible ways of trying to assign fields-symbol like declarations which doesnt allow here ...
    plz Dont reply with the basics of creating dynamic internal tables, coz my case is not an Internal table it is FM table parameter declaration.....

    Hi,
    If you are requirement is to create a function module with tables parameter having a generic line type i.e. no specific line type
    just declare it with a name under Parameter name with out specifying the type.
    A reference function module with such parameter, i would quote is the standard GUI_UPLOAD/ GUI_DOWNLOAD where the parameters specified under TABLES are generic.
    If you want to process the values passed to these parameters in the source code of function module, field symbols would be a preferable option.
    Regards,
    Sharath Panuganti

  • Doubt in  export, import and table para when creating Function Module

    Dear fellow ABAPers,
    I have a doubt in defining export, import and table parameter while creating a function module.
    I am calling a function module inside a user exit. Now in the user exit the SAP fills an internal table called i_lfa1 with all the data user has eneterd.
    Now I want to pass this whole internal table to function module and the perform some checks on the values of internal table.
    After that function module fills an error structure with values depending on some check.
    1)
    How do I pass this internal table to function module ? 
    When I am creating function module in se37 where do I define this iternal table type ? Is it in Import or Table parameter during function module creation?
    2)
    Where do I define error structure type (which is returned by function module to main program)? Is it in Export or table parameter during function module creation?
    Please clear my doubt..
    Relevant points will be awarded.
    Regards,
    Tushar.

    Hi Tushar,
    1. How do I pass this internal table to function module ?
       I assume u are creating your own Y/Z FM.
       Pass it thru TABLES parameter.
    2. When I am creating function module in se37 where do I define this iternal table type
       Define this in TABLES interface.
       What Type ?
       THE SAME TYPE WHICH HAS BEEN DEFINED
        WHILE PASSING IN THE USER-EXIT FUNCTION MODULE.
       IF U SEE THE FM OF THE USER-EXIT,
       U WILL COME TO KNOW.
    3.
    Where do I define error structure type (which is returned by function module to main program)? Is it in Export or table parameter during function module creation?
    Define it in TABLES interace. (not in export, import)
      (Since what u are going to return is an internal table)
      U can take for eg. BDCMSGCOLL.
      OR u can create your own Y/Z structure
    for the same purpose.
      (or u can use the structure type T100)
    I hope it helps.
    Regards,
    Amit M.

Maybe you are looking for

  • IPhone is duplicating voice memos

    I have thousands of very important voice notes on my phone. I'm a comedian and I use the voice memos to record joke ideas as well as record my performances.  Lately ITunes has been duplicating them with every sync. It would literally take me days to

  • How can I share a file with another mac computer?

    I would like to send a file to my girlfriends computer. A macbook pro. I have a macbook. Can you tell me how to do this? Is it with file sharing, or blue tooth or something else. I is a logic .aif file. Thanks

  • Need help In ALV report

    Hi All, I am working on ALV report.I need one logic. When Ever I executed report, The output should looks 'Selected Total data' like Yellow color. How can i do that. The report out should show sthe ' All the data is selected'. Just like Ctrl+A. regar

  • Is there a dual video sources workflow anywhere for Podcast Producer 2?

    I looked at the standard "dual source" workflow, but the QTZ compositions appear to use output from a plugin rather than direct "video input" patches. I'd love to be able to plug in both a Canopus ADVC-55 firewire codec (to capture PTZ camera image)

  • AI CS5.1 error - says it needs to be activated

    I have CS5.1 apps on my mac, but my subscription has reverted to the Cloud. I have been able to access the CS5.1 apps before but now I get a message "Unable to activate Creative Suite CS5 Premium Design Edition. Product Activation is required to use