Help needed in debugging dynamic SQL.

When I pass the p_deptno =30 and run the below code the refcursor returns the rows.But when I pass the dpetno =null then it goes to the condition if p_job is not null and throws an error.Can any one please help me in debugging this code.
declare
p_deptno number:=null;
p_job varchar2(30):='SALESMAN';
v_sql varchar2(4000);
l_ename varchar2(30);
  TYPE my_cursor IS REF CURSOR;
  RC my_cursor;
begin
  v_sql := 'select ename
            from emp
           where 1=1';
  if p_deptno is not null then
    v_sql := v_sql||' AND deptno='||p_deptno;
  else
    if p_job is not null then
      v_sql := v_sql||' AND job='||p_job;
    end if;
  end if;
  OPEN RC FOR v_sql;
  LOOP
    FETCH RC INTO l_ename;
    EXIT WHEN RC%NOTFOUND;
    dbms_output.put_line(l_ename);
  END LOOP;
  CLOSE RC;
END;Thanks.
Edited by: user3565577 on Mar 6, 2010 8:44 PM

Hi
I've mocked up a simple test and it seems to use the indexes when I try with one or the other values being supplied, I've made an assumption on the indexes you have (i.e. single column indexes on job and deptno),
--indexes on emp table:
p2056@dbapw01> @indexes
Enter value for table_name: emp
Enter value for owner: p2056
INDEX_OWNER                    INDEX_NAME                INDEX_TYPE                  PAR COLUMN_NAME                    STATUS
P2056                          EMPI1                     NORMAL                      NO  DEPTNO                         VALID
P2056                          EMPI2                     NORMAL                      NO  JOB                            VALID
2 rows selected.
--when accessing with a job value
p2056@dbapw01> explain plan for select *
  2  from emp
  3  where (
  4   (null is null and job = 'SALESMAN')
  5   OR
  6   ('SALESMAN' is null and deptno = null)
  7   OR
  8   ('SALESMAN' is null and null is null)
  9         );
Explained.
p2056@dbapw01> @xplan
PLAN_TABLE_OUTPUT
Plan hash value: 1888885832
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT            |       |     2 |   154 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMP   |     2 |   154 |     1   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | EMPI2 |     2 |       |     1   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   2 - access("JOB"='SALESMAN')
--when accessing with a deptno value
p2056@dbapw01> explain plan for select *
  2  from emp
  3  where (
  4   (2 is null and job = null)
  5   OR
  6   (null is null and deptno = 2)
  7   OR
  8   (null is null and 2 is null)
  9         );
Explained.
p2056@dbapw01> @xplan
PLAN_TABLE_OUTPUT
Plan hash value: 1336173234
| Id  | Operation                   | Name  | Rows  | Bytes | Cost (%CPU)| Time     |
|   0 | SELECT STATEMENT            |       |     1 |    77 |     1   (0)| 00:00:01 |
|   1 |  TABLE ACCESS BY INDEX ROWID| EMP   |     1 |    77 |     1   (0)| 00:00:01 |
|*  2 |   INDEX RANGE SCAN          | EMPI1 |     1 |       |     1   (0)| 00:00:01 |
Predicate Information (identified by operation id):
   2 - access("DEPTNO"=2)

Similar Messages

  • Help to make this dynamic sql work

    Hi,
    I have many DDLs to execute and these DDLs change over time, so I try to load these DDLs into a table (y) and write a proc to loop through them. But I run into some problems and need your help.
    Here are the details:
    create table y ( x varchar2(4000));
    CREATE TABLE error_log (
    error_log_ID NUMBER(20),
    statement VARCHAR2(2000),
    error_msg VARCHAR2(400),
    Action VARCHAR2(16)
    CREATE SEQUENCE SEQ_error_log
    START WITH 1
    INCREMENT BY 1
    NOMINVALUE
    NOMAXVALUE
    NOCYCLE
    CACHE 20
    NOORDER
    CREATE OR REPLACE PROCEDURE CUST_UPDATE1 (
    schema_name IN VARCHAR2 ,
    table_tablespcae_name IN VARCHAR2,
    index_tablespcae_name IN VARCHAR2
    ) AS
    v_code NUMBER;
    v_errm VARCHAR2(400);
    sql_stmt1 VARCHAR2(3000) ;
    CURSOR c1 IS SELECT x FROM y;
    BEGIN
    FOR i IN c1 LOOP
    sql_stmt1 := i.x;
    DBMS_OUTPUT.PUT_LINE ( 'x = '|| sql_stmt1 );
    / **************************** worked if use this hard coded ********************************
    sql_stmt1 := 'CREATE TABLE '||schema_name||'.zz
    aa VARCHAR2(4) NOT NULL,
    bb VARCHAR2(100) NOT NULL,
    cc VARCHAR2(2) NOT NULL
    TABLESPACE '|| table_tablespcae_name;
    BEGIN
    EXECUTE IMMEDIATE sql_stmt1;
    EXCEPTION
    WHEN OTHERS THEN
    v_code := SQLCODE;
    v_errm := SUBSTR(SQLERRM, 1 , 400);
    INSERT INTO error_log VALUES ( SEQ_error_log.nextval, sql_stmt1, v_errm, DECODE(v_code, -1430, 'IGNORE', 'CHECK') );
    END;
    END LOOP;
    END;
    Test:
    exec cust_update1('SCOTT', 'USERS', 'c'); -- didn't use last parameter
    Senario 1. insert into y values (
    'CREATE TABLE schema_name.zz
    aa VARCHAR2(4) NOT NULL,
    bb VARCHAR2(100) NOT NULL,
    cc VARCHAR2(2) NOT NULL
    TABLESPACE table_tablespcae_name ' );
    ===> error_log show: ORA-01918: user 'SCHEMA_NAME' does not exist
    Senario 2. insert into y values (
    '''CREATE TABLE ''||schema_name||''.zz
    aa VARCHAR2(4) NOT NULL,
    bb VARCHAR2(100) NOT NULL,
    cc VARCHAR2(2) NOT NULL
    TABLESPACE ''|| table_tablespcae_name' );
    ==> error_log show: ORA-00900: invalid SQL statement
    3. I hard coded the exact dynamic from step 2 and assigned to sql_stmt1, ( as commeted out in my code) it WORKED.
    Thanks
    George

    hi,
    do the scenario1 but you have to substitute the schema_name and table_space name with your actual string before calling the dynamic sql.
    ei.
    sql_stmt1 := replace(sql_stmt1,'schema_name',schema_name);
    sql_stmt1 := replace(sql_stmt1,'table_tablespcae_name',table_tablespcae_name);
    BEGIN
    EXECUTE IMMEDIATE sql_stmt1;
    EXCEPTION
    WHEN OTHERS THEN
    v_code := SQLCODE;
    v_errm := SUBSTR(SQLERRM, 1 , 400);
    INSERT INTO error_log VALUES ( SEQ_error_log.nextval, sql_stmt1, v_errm, DECODE(v_code, -1430, 'IGNORE', 'CHECK') );
    END;
    Cheers,
    J

  • Help on Execute Immediate Dynamic Sql

    Hi all
    when i run the following Pl/SQL,nothing is happening
    I want to pass array to following procedure
    DECLARE
    SQL_STMT      VARCHAR2(1000);
    BEGIN
    SQL_STMT  := 'Select '|| '''populate_table_test(''' || '|| chr(39)||id_name||chr(39)||' ||''','''||'|| chr(39)||attribute1||chr(39)||' ||''','''||'|| chr(39)||attribute2||chr(39)||' ||''');'''||' from table_test1';
    dbms_output.put_line(sql_stmt);
    execute immediate sql_stmt;
    Exception when others then
    dbms_output.put_line(sqlerrm);
    end;
    SQL> ed
    Wrote file afiedt.buf
      1  Select 'populate_table_test('|| chr(39)||id_name||chr(39)||','||
      2  chr(39)||attribute1||chr(39)||','|| chr(39)||attribute2||chr(39)||');' from
      3* table_test
    SQL> /
    'POPULATE_TABLE_TEST('||CHR(39)||ID_NAME||CHR(39)||','||CHR(
    populate_table_test('AAA','AA','AA');
    populate_table_test('AAA','AA','AA');
    CREATE
      TABLE TABLE_TEST1
        "ID_NO"      NUMBER(10,0)     ,
        "ID_NAME"    VARCHAR2(10 BYTE),
        "ATTRIBUTE1" VARCHAR2(10 BYTE),
        "ATTRIBUTE2" VARCHAR2(10 BYTE)
    Insert into TABLE_TEST1 (ID_NO,ID_NAME,ATTRIBUTE1,ATTRIBUTE2) values (null,'AAA','AA','AA');
    Insert into TABLE_TEST1 (ID_NO,ID_NAME,ATTRIBUTE1,ATTRIBUTE2) values (null,'AAA','AA','AA');
    commit;
    CREATE TABLE TABLE_TEST
    (ID_NO NUMBER(10) ,
    id_NAME VARCHAR2(10) ,
    ATTRIBUTE1 VARCHAR2(10),
    ATTRIBUTE2 VARCHAR2(10)
    select * from "TABLE_TEST";
    CREATE OR REPLACE TYPE T_TYPE IS OBJECT (
    id_NAME VARCHAR2(10),
    ATTRIBUTE1 VARCHAR2(10),
    ATTRIBUTE2 VARCHAR2(10)
    Create or replace  type TB_T_TYPE as varray(200) of  T_TYPE ;
    CREATE OR REPLACE
    PROCEDURE POPULATE_TABLE_TEST (EXAMPLE IN TB_T_TYPE) AS
    begin
    FOR I IN 1..EXAMPLE.COUNT LOOP
    DBMS_OUTPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ID_NAME);
    DBMS_OUTPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ATTRIBUTE1);
    DBMS_OUtPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ATTRIBUTE2);
    insert into TABLE_TEST(id_name,attribute1,attribute2)
    values (treat(example(i) as T_TYPE).id_NAME,
    treat(example(i) as T_TYPE).ATTRIBUTE1,
    treat(example(i) as T_TYPE).ATTRIBUTE2
    end loop;
    end; Select 'populate_table_test('|| chr(39)||id_name||chr(39)||','||
    chr(39)||attribute1||chr(39)||','|| chr(39)||attribute2||chr(39)||');' from
    table_test
    Edited by: user1849 on Nov 30, 2011 12:40 PM
    Edited by: user1849 on Nov 30, 2011 1:18 PM

    user1849 wrote:
    Hi all
    when i run the following Pl/SQL,nothing is happeningRemember to issue the SQL*Plus command
    SET  SERVEROUTPUT  ONbefore running it; otherwise, you won't see the output from dbms_output.
    >
    I want to pass array to following procedureIs this a procedure or an anonymous PL/SQL block?
    If it's a procedure, post the entire procedure, starting with CREATE [OR REPLACE] PROCEDURE...
    Never write, let alone post, unformatted code. Indent the code to show the scope of BEGIN, LOOP, etc.
    DECLARE
    SQL_STMT      VARCHAR2(1000);
    BEGIN
    SQL_STMT  := 'Select '|| '''populate_table_test(''' || '|| chr(39)||id_name||chr(39)||' ||''','''||'|| chr(39)||attribute1||chr(39)||' ||''','''||'|| chr(39)||attribute2||chr(39)||' ||''');'''||' from table_test1';
    dbms_output.put_line(sql_stmt);
    execute immediate sql_stmt;
    Exception when others then
    dbms_output.put_line(sqlerrm);
    end;
    /Only use an EXCEPTION handler when you can improve on the default error handling. The default is to print an error message, so there's no point in you explicitly doing the same.
    Why do you need dynamic SQL? Post the output results you want to get from the sample data you posted.
    Given that you do need dynamic SQL, why can't you use bind variables, rather than including the values as literals?
    Given that you have to use literals, use Q-notation for strings that include single-quote characters.
    http://docs.oracle.com/cd/B28359_01/server.111/b28286/sql_elements003.htm#sthref337
    For example:
    ...     SQL_STMT  := Q{'Select  populate_table_test ('}'
              || id_name
              || Q'{','}'
              || attribute1
              || Q'{','}'
    SQL> ed
    Wrote file afiedt.buf
    1  Select 'populate_table_test('|| chr(39)||id_name||chr(39)||','||
    2  chr(39)||attribute1||chr(39)||','|| chr(39)||attribute2||chr(39)||');' from
    3* table_test
    SQL> /
    'POPULATE_TABLE_TEST('||CHR(39)||ID_NAME||CHR(39)||','||CHR(
    populate_table_test('AAA','AA','AA');
    populate_table_test('AAA','AA','AA');
    CREATE
    TABLE TABLE_TEST1
    "ID_NO"      NUMBER(10,0)     ,
    "ID_NAME"    VARCHAR2(10 BYTE),
    "ATTRIBUTE1" VARCHAR2(10 BYTE),
    "ATTRIBUTE2" VARCHAR2(10 BYTE)
    Insert into TABLE_TEST1 (ID_NO,ID_NAME,ATTRIBUTE1,ATTRIBUTE2) values (null,'AAA','AA','AA');
    Insert into TABLE_TEST1 (ID_NO,ID_NAME,ATTRIBUTE1,ATTRIBUTE2) values (null,'AAA','AA','AA');
    commit;
    Thanks for posting the CREATE TABLE and INSERT statements; that's very helpful.
    Is that the best sample data for testing? Wouldn't it be better to have at least one row that was not the same as all the others?
    CREATE TABLE TABLE_TEST
    (ID_NO NUMBER(10) ,
    id_NAME VARCHAR2(10) ,
    ATTRIBUTE1 VARCHAR2(10),
    ATTRIBUTE2 VARCHAR2(10)
    select * from "TABLE_TEST";
    CREATE OR REPLACE TYPE T_TYPE IS OBJECT (
    id_NAME VARCHAR2(10),
    ATTRIBUTE1 VARCHAR2(10),
    ATTRIBUTE2 VARCHAR2(10)
    Create or replace  type TB_T_TYPE as varray(200) of  T_TYPE ;
    CREATE OR REPLACE
    PROCEDURE POPULATE_TABLE_TEST (EXAMPLE IN TB_T_TYPE) AS
    begin
    FOR I IN 1..EXAMPLE.COUNT LOOP
    DBMS_OUTPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ID_NAME);
    DBMS_OUTPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ATTRIBUTE1);
    DBMS_OUtPUT.PUT_LINE(TREAT(EXAMPLE(I) AS T_TYPE).ATTRIBUTE2);
    insert into TABLE_TEST(id_name,attribute1,attribute2)
    values (l_t_seq(i),
    treat(example(i) as T_TYPE).id_NAME,
    treat(example(i) as T_TYPE).ATTRIBUTE1,
    treat(example(i) as T_TYPE).ATTRIBUTE2
    end loop;
    end; You're trying to INSERT 4 values into 3 columns. Did you mean to say "insert into TABLE_TEST( *id_no,* id_name,attribute1,attribute2)"?
    What is l_t_seq? Post complete test scripts that people can run to re-create the problem and test their ideas.

  • Help With SUBSTR in dynamic SQL statement

    Following is the dynamic SQL statement.
    EXECUTE IMMEDIATE 'UPDATE table_name pml
    SET pml.'|| con_fields.field ||' = SUBSTR(pml.'||con_fields.field||' ||'' ''||
    (SELECT pml1.'||con_fields.field||'
    FROM table_name pml1
    WHERE pml1.grp_id = '||los_concats.grp_id ||'
    AND pml1.row_id = '||los_concats.row_id||'
    AND pml1.loser_flg = ''Y''),1, '||con_fields.max_length||')
    WHERE pml.grp_id = '||los_concats.grp_id ||'
    AND pml.loser_flg IS NULL ';
    what it does is that it updates a particular field. This field is concatenated by a field of a similar record.
    My problem is with SUBSTR function. Since I am concatenating fields I do not want the field to be updated greater than max_length on that field, the reason why I use SUBSTR. the select query inside SUBSTR works alright with one of the AND condition in a WHERE clause not present. When I add that additional condition it gives me this error.
    ORA-00907: missing right parenthesis.
    Is there any way to get around this problem. Does SQL has other than SUBSTR function which can limit the character length.
    Appreciate it.

    The other alternative I thought about was to do this first
    EXECUTE IMMEDIATE 'SELECT pml.'||con_fields.field||'
    FROM table_name pml
    WHERE pml.grp_id = '||los_concats.grp_id||'
    AND pml.row_id = '||los_concats.row_id||'
    AND pml.loser_flg = ''Y''
    ' INTO v_concat_field;
    write into the variable v_concat_field and then use it into the previous script.
    But on this I get SQL Command not properly terminated, I don't get it Why?
    Donald I tried with your suggested script. It works fine with one of the conditions eliminated. I don't understand what the error trying to say?
    Thanks

  • Help needed in debugging callablestatement changing performance

    Looking for some help debugging a performance problem.
    We are in the process of converting an ASP web application running on IIS to a java web application running on OAS. We have java code using a CallableStatement that calls an Oracle PL/SQL Procedure that runs inserts and updates as needed and does not return anything.
    When the Java application calls the procedure using the same parameters and doing the exact same work the execution time is either 3 minutes or 30 minutes. We have narrowed down the location of the slowdown and when it takes 30 minutes to execute it appears to be hanging during a cursor execution. What would cause the execution times to vary so much?
    Here's another piece to the puzzle. When the procedure is called from IIS with the exact same parameters that were used from OAS the procedure ALWAYS runs in 3 minutes. Why would IIS performance be so consistent and OAS so inconsistent?
    Any debugging suggestions would be greatly appreciated.
    Thanks,
    Bob

    user4908334 wrote:
    We are in the process of converting an ASP web application running on IIS to a java web application running on OAS. We have java code using a CallableStatement that calls an Oracle PL/SQL Procedure that runs inserts and updates as needed and does not return anything.
    More information is needed on that.
    There is one proc or 50?
    The proc is being called one time or 50 times?
    You are not using Batching right?
    When the procedure is called from IIS with the exact same parameters that were used from OAS the procedure ALWAYS runs in 3 minutesYou are running the java server on exactly the same box as IIS?
    The java code is using exactly the same database as IIS? (Did you verify this?)

  • Help needed in debugging the BADI: BBP_CREATE_REQ_BACk

    Hi,
    I  need help in debugging a BADI which causing an error ' SE142 please enter quantity in line 3000111'.
    This happens only when number items in the cart are more than four and only for Service category items for which we have this BADI, if the items were less than or equal to 4, follow on document is created.
    Please let me know what could be the error.
    Thank you,
    Manyam
    METHOD if_ex_bbp_create_req_back~fill_req_interface.
    Method Parameters:
    *LOGICAL_SYSTEM     TYPE BBP_BACKEND_DEST-LOG_SYS OPTIONAL
    *REQ_ITEMS            TYPE BBP_REQ_ITEM_SPOOL
    *REQ_ITEM_ACCOUNT     TYPE BBP_REQ_ACCT_SPOOL
    *REQ_ITEM_TEXT     TYPE BBP_REQ_TEXT_SPOOL
    *REQ_LIMITS            TYPE BBP_REQ_LIMITS_SPOOL
    *REQ_CONTRACT_LIMITS     TYPE BBP_REQ_LIMITS_CONTR_SPOOL
    *REQ_SERVICES            TYPE BBP_REQ_SERV_SPOOL
    *REQ_SERV_ACCOUNT     TYPE BBP_REQ_SERV_ACC_SPOOL
    *REQ_SERV_TEXT     TYPE BBP_REQ_SERV_TEXT_SPOOL
    *REQ_ADDRDELIVERY     TYPE BBP_REQ_ADDRDELIVERY_SPOOL
    This is the logic to create a Service Requisition based on a service
    material group selected in the Shopping Cart.  This logic is based on
    SAP's standard function SPOOL_RQ_READ_BAPI_EXPORTS from which this
    BADI is called.
    INSERT FUNCTION SPOOL_RQ_READ_BAPI_EXPORTS TO REPROCESS DATA FOR
    SERVICE SPECIAL REQUESTS.  -- IOK 07/13/01
    *function spool_rq_read_bapi_exports.
    ""Lokale Schnittstelle:
    *"  IMPORTING
    *"     VALUE(REQNO) LIKE  REQHEAD-REQNO
    *"     VALUE(REQUIS_NUMBER) LIKE  BAPIEBANC-PREQ_NO
    *"  EXPORTING
    *"     VALUE(SKIP_ITEMS_WITH_ERROR) LIKE  BAPIMMPARA-SELECTION
    *"     VALUE(LOGICAL_SYSTEM) LIKE  BBP_BACKEND_DEST-LOG_SYS
    *"  TABLES
    *"      REQUISITION_ITEMS STRUCTURE  BAPIEBANC
    *"      REQUISITION_ACCOUNT_ASSIGNMENT STRUCTURE  BAPIEBKN
    *"      REQUISITION_ITEM_TEXT STRUCTURE  BAPIEBANTX
    *"      REQUISITION_LIMITS STRUCTURE  BAPIESUHC
    *"      REQUISITION_CONTRACT_LIMITS STRUCTURE  BAPIESUCC
    *"      REQUISITION_SERVICES STRUCTURE  BAPIESLLC
    *"      REQUISITION_SRV_ACCASS_VALUES STRUCTURE  BAPIESKLC
    *"      RETURN STRUCTURE  BAPIRETURN
    *"      REQUISITION_SERVICES_TEXT STRUCTURE  BAPIESLLTX
    *"      REQUISITION_ADDRDELIVERY STRUCTURE  BBPS_RQADDRDELIVERY_46
    *"      CONTROL_RECORD STRUCTURE  BBP_CONTROL_RECORD
    *"  EXCEPTIONS
    *"      INTERNAL_ERROR
    ---- Data Declaration -  from LBBP_BS_RQTOP -
    - Header                         -
      DATA: reqheader TYPE reqhead.
    - Header services                -
      DATA: reqheaders TYPE reqheads.
    - References -
      TYPES: reqreferences_type TYPE reqref.
      DATA:  reqreferences      TYPE STANDARD TABLE OF reqreferences_type
                                     INITIAL SIZE 10.
      DATA:  l_reqreferences    TYPE reqreferences_type,
             x_reqreferences    TYPE reqreferences_type.
    - Administrative lines requirement request -
      TYPES: reqlines_type TYPE reqline.
      DATA:  reqlines      TYPE STANDARD TABLE OF reqlines_type
                                INITIAL SIZE 10.
      DATA:  l_reqlines    TYPE reqlines_type.
    - MRO-Lines requirement request -
      TYPES: reqlinemas_type TYPE reqlinema_eci.
      DATA:  reqlinemas      TYPE STANDARD TABLE OF reqlinemas_type
                                  INITIAL SIZE 10.
      DATA:  l_reqlinemas    TYPE reqlinemas_type.
    - SRV-Lines requirement request -
      TYPES: reqlinesrs_type TYPE bbps_reqlinesr_eci.
      DATA:  reqlinesrs      TYPE STANDARD TABLE OF reqlinesrs_type
                                  INITIAL SIZE 10.
      DATA:  l_reqlinesrs    TYPE reqlinesrs_type.
    - Texts requirement request -
      TYPES: reqtexts_type TYPE reqtext.
      DATA:  reqtexts      TYPE STANDARD TABLE OF reqtexts_type
                                INITIAL SIZE 10.
      DATA:  l_reqtexts    TYPE reqtexts_type.
    *- Delivery address
      TYPES: reqaddress_type TYPE reqaddress.
      DATA:  reqaddress      TYPE STANDARD TABLE OF reqaddress_type
                                  INITIAL SIZE 10.
      DATA:  l_reqaddress    TYPE reqaddress_type.
    - Account assignment requirement request -
      TYPES: reqaccts_type TYPE reqacct_470.
      DATA:  reqaccts      TYPE STANDARD TABLE OF reqaccts_type
                                INITIAL SIZE 10.
      DATA:  l_reqaccts    TYPE reqaccts_type.
    - tablekey with the shortlife-line -
      DATA: BEGIN OF shortkey,
               client   TYPE ec_client, "REQLINE-CLIENT,
               reqno    TYPE ec_reqno,  "REQLINE-REQNO,
               reqsline TYPE reqsline,  "REQLINE-REQSLINE,
               reqlline TYPE reqlline,  "REQLINE-REQLLINE,
            END OF shortkey.
    - tablekey with the longlife-line -
      DATA: BEGIN OF longkey,
               client   TYPE ec_client, "REQLINE-CLIENT,
               reqno    TYPE ec_reqno,  "REQLINE-REQNO,
               reqlline TYPE reqlline,  "REQLINE-REQLLINE,
            END OF longkey.
      DATA: BEGIN OF bankey,
                preq_no    TYPE banfn, "BAPIEBAN-PREQ_NO,
                preq_item  TYPE bnfpo, "BAPIPOGN-PREQ_ITEM,
            END OF bankey.
    any other working fields
      DATA: h_preq_item     TYPE bnfpo,       "BAPIEBANC-PREQ_ITEM,
            h_srv_item      TYPE bnfpo,       "BAPIEBANC-PREQ_ITEM,
            h_logsys        TYPE log_system.  "reqref-logical_system.
      DATA: h_serial_no     TYPE dzebkn.      "BAPIEBKN-SERIAL_NO.
      DATA: h_packno_item   TYPE packno,      "BAPIESLL-PCKG_NO,
            h_packno_srv    TYPE packno,      "BAPIESLL-PCKG_NO,
            h_introw        TYPE srv_line_no, "BAPIESLL-LINE_NO,
            h_serial_no_srv TYPE dzekkn,      "BAPIESKN-SERIAL_NO,
            h_srv_outl_created,
            next TYPE i,
            h_index         LIKE sy-tabix,
            h_wempf         TYPE wempf.       "bapiekkn-gr_rcpt.
    ------ End of std data declaration -
      DATA:   l_req_items               TYPE bapiebanc,
              l_req_item_account        TYPE bapiebkn,
              l_req_item_text               TYPE bapiebantx,
              l_req_limits               TYPE bapiesuhc,
              l_req_contract_limits      TYPE bapiesucc,
              l_req_services               TYPE bapiesllc,
              l_req_serv_account        TYPE bapiesklc,
              l_req_serv_text               TYPE bapieslltx,
              l_req_addrdelivery        TYPE bbps_rqaddrdelivery_46.
      DATA:
           old_req_items           TYPE STANDARD TABLE OF bapiebanc,
           old_req_item_account    TYPE STANDARD TABLE OF bapiebkn,
           old_req_item_text       TYPE STANDARD TABLE OF bapiebantx,
           old_req_limits          TYPE STANDARD TABLE OF bapiesuhc,
           old_req_contract_limits TYPE STANDARD TABLE OF bapiesucc,
           old_req_services        TYPE STANDARD TABLE OF bapiesllc,
           old_req_serv_account    TYPE STANDARD TABLE OF bapiesklc,
           old_req_serv_text       TYPE STANDARD TABLE OF bapieslltx,
           old_req_addrdelivery    TYPE STANDARD TABLE OF
                                              bbps_rqaddrdelivery_46.
      DATA: l_mat_group TYPE comm_category-category_id.
      DATA: f_change_required TYPE c,
            f_limit_change    TYPE c,
            f_mat_sr_change   TYPE c,
            f_first_change    TYPE c VALUE 'X'.
    Data declaration for Shopping Cart number and PO number
      DATA: reqno          TYPE ec_reqno,
            requis_number  TYPE banfn.
      DATA: l_current_item TYPE bnfpo,
            line_item(5)   TYPE n.
    ---- Begin Processing ----
      DATA: l_requis_number TYPE banfn.   "jms 022802
    DEBUG TOOL ****** Goto SM50
    *data: i type i value 1.
    *while i <> 0.
    i = i + 1.
    *endwhile.
    END DEBUG TOOL *******
    Get Req Number and Shopping Cart Number
    read table req_items into l_req_items index 1.
    requis_number = l_req_items-preq_no.
    select single reqno
         into  (reqno)
         from  reqref
         where refnumber = requis_number.
    read detailed data from the requirement request
    call function 'BBP_REQREQ_GETDETAIL'
          EXPORTING
               reqno               = reqno
          IMPORTING
               req_header          = reqheader
               req_header_srv      = reqheaders
          TABLES
               req_reference       = reqreferences
               req_line            = reqlines
               req_line_mat        = reqlinemas
               req_line_srv        = reqlinesrs
               req_text            = reqtexts
               req_acct            = reqaccts
               req_address         = reqaddress
          EXCEPTIONS
               not_found           = 1
               foreign_lock        = 2
               no_enqueue_possible = 3
               others              = 4.
    if sy-subrc <> 0.
       raise internal_error.
       exit.
    endif.
    Begin JMS
    PO_NUM = PO_HEADER-PO_NUMBER.
    CMH Data declaration
      TYPES: et_header TYPE bbp_pds_sc_header_d.
      DATA:  t_et_header TYPE STANDARD TABLE OF et_header INITIAL SIZE 0,
             x_et_header TYPE et_header.
      TYPES: et_item TYPE bbp_pds_sc_item_d.
      DATA:  t_et_item TYPE STANDARD TABLE OF et_item INITIAL SIZE 0,
             x_et_item TYPE et_item.
      TYPES: sc_header TYPE bbp_pds_sc_header_d.
      DATA:  x_sc_header TYPE sc_header.
      TYPES: sc_is_pd TYPE xfeld.
      DATA:  l_sc_is_pd TYPE sc_is_pd.
      TYPES: sc_item TYPE bbp_pds_sc_item_d.
      DATA:  t_sc_item TYPE STANDARD TABLE OF sc_item INITIAL SIZE 0,
             x_sc_item TYPE sc_item.
      TYPES: sc_account TYPE bbp_pds_acc.
      DATA:  t_sc_account TYPE STANDARD TABLE OF sc_account INITIAL SIZE 0,
             x_sc_account TYPE sc_account.
      TYPES: sc_partner TYPE bbp_pds_partner.
      DATA:  t_sc_partner TYPE STANDARD TABLE OF sc_partner INITIAL SIZE 0,
             x_sc_partner TYPE sc_partner.
      TYPES: sc_confirm TYPE bbp_pds_con.
      DATA:  t_sc_confirm TYPE STANDARD TABLE OF sc_confirm INITIAL SIZE 0,
             x_sc_confirm TYPE sc_confirm.
      TYPES: sc_longtext TYPE bbp_pds_longtext.
      DATA:  t_sc_longtext TYPE
               STANDARD TABLE OF sc_longtext INITIAL SIZE 0,
             x_sc_longtext TYPE sc_longtext.
      TYPES: sc_limit TYPE bbp_pds_limit.
      DATA:  t_sc_limit TYPE STANDARD TABLE OF sc_limit INITIAL SIZE 0,
             x_sc_limit TYPE sc_limit.
      TYPES: sc_orgdata TYPE bbp_pds_org.
      DATA:  t_sc_orgdata TYPE
               STANDARD TABLE OF sc_orgdata INITIAL SIZE 0,
             x_sc_orgdata TYPE sc_orgdata.
      TYPES: sc_tax TYPE bbp_pds_tax.
      DATA:  t_sc_tax TYPE STANDARD TABLE OF sc_tax INITIAL SIZE 0,
             x_sc_tax TYPE sc_tax.
      TYPES: sc_pridoc TYPE bbp_pds_prc.
      DATA:  t_sc_pridoc TYPE STANDARD TABLE OF sc_pridoc INITIAL SIZE 0,
             x_sc_pridoc TYPE sc_pridoc.
      TYPES: sc_messages TYPE bbp_pds_messages.
      DATA:  t_sc_messages TYPE
               STANDARD TABLE OF sc_messages INITIAL SIZE 0,
             x_sc_messages TYPE sc_messages.
      TYPES: sc_actval TYPE bbp_pds_actval.
      DATA:  t_sc_actval TYPE STANDARD TABLE OF sc_actval INITIAL SIZE 0,
             x_sc_actval TYPE sc_actval.
      TYPES: sc_acc_actval TYPE bbp_pds_actval.
      DATA:  t_sc_acc_actval TYPE STANDARD TABLE OF sc_acc_actval
                                                          INITIAL SIZE 0,
             x_sc_acc_actval TYPE sc_acc_actval.
      TYPES: sc_header_rel TYPE bbp_pds_hrel.
      DATA:  t_sc_header_rel TYPE STANDARD TABLE OF sc_header_rel
                                                          INITIAL SIZE 0,
             x_sc_header_rel TYPE sc_header_rel.
      TYPES: sc_itmlim_rel TYPE bbp_pds_ilrel.
      DATA:  t_sc_itmlim_rel TYPE STANDARD TABLE OF sc_itmlim_rel
                                                          INITIAL SIZE 0,
             x_sc_itmlim_rel TYPE sc_itmlim_rel.
      TYPES: it_cuf_item_type TYPE bbps_cuf_item.
      DATA:  t_it_cuf_item TYPE STANDARD TABLE OF it_cuf_item_type
                                                          INITIAL SIZE 0,
             x_it_cuf_item TYPE it_cuf_item_type.
    - Contract limits                -
      TYPES: reqconlimits_type TYPE reqheads.
      DATA:  reqconlimits      TYPE STANDARD TABLE OF reqconlimits_type
                                INITIAL SIZE 10.
      DATA:  l_reqconlimits    TYPE reqconlimits_type.
      DATA:   lv_abort      TYPE xfeld,
              lv_is_pd      TYPE xfeld,
              lv_deliv_date LIKE sy-datum,
              lv_tabix      LIKE sy-tabix,
              lv_line       TYPE introw,
              lv_msarg      TYPE char200,
              lv_sc_guid    TYPE bbp_pdview_iap-header,
              lv_req_guid   TYPE bbp_pdview_iap-header.
      DATA: x_requis_number TYPE bapiebanc.
      IF NOT req_items[] IS INITIAL.
        CLEAR l_requis_number.
        READ TABLE req_items INTO x_requis_number INDEX 1.
        l_requis_number = x_requis_number-preq_no.
        requis_number = x_requis_number-preq_no.
      ENDIF.
    Get PO Guid from Backend Table.
      SELECT SINGLE guid
             INTO   lv_req_guid
             FROM   bbp_pdbei
             WHERE  be_object_id   =  l_requis_number
             AND    be_object_type = 'BUS2105'.
    Get Shopping Cart Guid from PO Guid
      SELECT SINGLE header
             INTO   lv_sc_guid
             FROM   bbp_pdview_iap
             WHERE  guid = lv_req_guid.
    Get detail from shopping cart
      CALL FUNCTION 'BBP_PD_SC_GETDETAIL'
        EXPORTING
          i_guid                  = lv_sc_guid
          i_with_itemdata         = 'X'
        IMPORTING
          e_header                = x_sc_header
          ev_is_pd                = l_sc_is_pd
        TABLES
          e_item                  = t_sc_item
          e_account               = t_sc_account
          e_partner               = t_sc_partner
          e_confirm               = t_sc_confirm
          e_longtext              = t_sc_longtext
          e_limit                 = t_sc_limit
          e_orgdata               = t_sc_orgdata
          e_tax                   = t_sc_tax
          e_pridoc                = t_sc_pridoc
          e_messages              = t_sc_messages
          e_actval                = t_sc_actval
          e_acc_actval            = t_sc_acc_actval
          e_header_rel            = t_sc_header_rel
          e_itmlim_rel            = t_sc_itmlim_rel.
      lv_is_pd = l_sc_is_pd.
    message handling
      IF NOT t_sc_messages[] IS INITIAL.
        CALL FUNCTION 'BBP_BS_ADD_MESSAGES'
          IMPORTING
            ev_abort    = lv_abort
          TABLES
            it_messages = t_sc_messages.
      ENDIF.
    if error occured set alert/ exception.
      IF NOT lv_abort IS INITIAL.
        CALL FUNCTION 'BBP_ALERT_SB_LOCAL'
          EXPORTING
            msgid              = 'BBP_PD'
            msgno              = 280
            msgarg1            = lv_msarg
          EXCEPTIONS
            invalid_parameters = 1
            OTHERS             = 2.
       RAISE internal_error.
      ENDIF.
    map shopping cart in new structure into old structure to be able
    to continue with the old coding
      REFRESH t_sc_messages.
      CALL FUNCTION 'BBP_SC_MAP_PD_TO_REQ'
        EXPORTING
          is_new_header    = x_sc_header
        IMPORTING
          es_reqhead       = reqheader
          es_req_heads     = reqheaders
         es_cuf_header    = is_cuf_header
        TABLES
          et_req_reference = reqreferences
          et_req_line      = reqlines
          et_req_line_mat  = reqlinemas
          et_req_line_srv  = reqlinesrs
          et_req_text      = reqtexts
          et_req_acct      = reqaccts
          et_req_address   = reqaddress
          et_req_conlimit  = reqconlimits
          it_new_items     = t_sc_item
          it_account       = t_sc_account
          it_partner       = t_sc_partner
          it_longtext      = t_sc_longtext
          it_limit         = t_sc_limit
          it_orgdata       = t_sc_orgdata
          it_tax           = t_sc_tax
          it_actval        = t_sc_actval
          it_itmlim_rel    = t_sc_itmlim_rel
          et_messages      = t_sc_messages.
         et_cuf_item      = it_cuf_item
         et_cuf_acc       = it_cuf_acc.
      IF NOT t_sc_messages[] IS INITIAL.
    message handling
        CALL FUNCTION 'BBP_BS_ADD_MESSAGES'
          IMPORTING
            ev_abort    = lv_abort
          TABLES
            it_messages = t_sc_messages.
      ENDIF.
    if error occured set alert/ exception.
      IF NOT lv_abort IS INITIAL.
        CALL FUNCTION 'BBP_ALERT_SB_LOCAL'
          EXPORTING
            msgid              = 'BBP_PU'
            msgno              = 326
            msgarg1            = lv_msarg
          EXCEPTIONS
            invalid_parameters = 1
            OTHERS             = 2.
       RAISE internal_error.
      ENDIF.
    End insert 03/26/2003
    ReqReferences doesn't list the PO item number.  We'll need that to
    associate the WBS to a Service Sub Item later.  Let's put it in.
      SORT reqreferences BY client refnumber reqlline.
      LOOP AT reqreferences INTO x_reqreferences.
        IF x_reqreferences-refline IS INITIAL.
          IF l_requis_number = x_reqreferences-refnumber. "jms 022802
            ADD 1 TO line_item.
          ELSE.
            l_requis_number = x_reqreferences-refnumber.  "jms 022802
            line_item = 1.
          ENDIF.
        Accumulate the line item
          x_reqreferences-refline = line_item.
          MODIFY reqreferences FROM x_reqreferences INDEX sy-tabix.
        ENDIF.
      ENDLOOP.
      SORT reqlines      BY client reqno reqlline.
      SORT reqreferences BY client reqno reqlline counter.
      SORT reqlinemas    BY client reqno reqsline reqlline.
      SORT reqlinesrs    BY client reqno reqsline reqlline.
      SORT reqaccts      BY client reqno reqlline serial_no. " note 359605
      CLEAR: h_preq_item.
      CLEAR: h_srv_item, h_srv_outl_created,
             h_packno_item, h_packno_srv, h_introw.
    First, the Shopping Cart number should be extracted from REQREF table
    based on the Req number.
    take all items with the specific reference number
      LOOP AT reqreferences
         INTO l_reqreferences                                  "iok 091701
        WHERE refnumber EQ requis_number.
       if logical_system is initial.
         logical_system = l_reqreferences-logical_system.
       endif.
        MOVE-CORRESPONDING l_reqreferences TO longkey.
      read table reqlines with key longkey binary search.
        READ TABLE reqlines INTO l_reqlines                    "iok 091701
            WITH KEY client = longkey-client
                      reqno = longkey-reqno
                   reqlline = longkey-reqlline
                   BINARY SEARCH.
        CHECK sy-subrc EQ 0.
        h_preq_item = l_reqlines-reqsline+5(5).
      clear h_preq_item.
      Change line_type based on Material Group
      add code here later.
        CLEAR: f_change_required,
               f_mat_sr_change,
               f_limit_change.
        SELECT SINGLE category_id
          INTO l_mat_group
          FROM comm_category
         WHERE category_guid = l_reqlines-category.
      Check if Services Special Request
        IF l_reqlines-catalogid IS INITIAL AND
           l_reqlines-product   IS INITIAL AND
           l_mat_group(1)        = 'S'     AND
           l_reqlines-line_type  = '1'.     "Service Special Request
        Set flags for future processing
          l_reqlines-line_type = '3'.
          f_change_required    = 'X'.
          f_limit_change       = 'X'.
      Check if Material Special Request
        ELSEIF l_reqlines-catalogid IS INITIAL AND
               l_reqlines-product   IS INITIAL AND
               l_mat_group(1)       <> 'S'     AND
               l_reqlines-line_type = '1'. "Material Special Request
        Set flags for future processing
          f_change_required = 'X'.
          f_mat_sr_change = 'X'.
        ENDIF.
        CHECK f_change_required = 'X'.
      For Material Special Requests only need to select and store UNSPSC
      code   -- iok 092401
        IF f_mat_sr_change = 'X'.
        Get UNSPSC code (first hit) based on Material Group and store
        in text id B05.   iok 092101
          READ TABLE req_items INTO l_req_items
              WITH KEY preq_item = h_preq_item
                       mat_grp   = l_mat_group.
          READ TABLE req_item_text INTO l_req_item_text
              WITH KEY preq_no   = requis_number
                       preq_item = l_req_items-preq_item
                       text_id = 'B05'.
          IF sy-subrc <> 0.
            CLEAR l_req_item_text.
          Find a UNSPSC Code from a Material Group .. even it's arbitrary
            SELECT unspsc_code UP TO 1 ROWS
                 FROM zxl8_category_id
                 INTO l_req_item_text-text_line
                WHERE category_id = l_mat_group.
            ENDSELECT.
          If nothing found then fill in a dummy UNSPSC.  The first
          letter of the Material will designate whether it's a Material
          or Service.
            IF sy-subrc NE 0.
            Move the Material Group value into a holding variable
              CONCATENATE l_mat_group(1) 'XXXXXXXX'
                     INTO l_req_item_text-text_line.
            ENDIF.
            l_req_item_text-preq_no   = requis_number.
            l_req_item_text-preq_item = l_req_items-preq_item.
            l_req_item_text-text_id   = 'B05'.
            INSERT l_req_item_text INTO TABLE req_item_text.
          ENDIF.
          CONTINUE.  "to next item.
        ENDIF.
        IF f_first_change = 'X' AND f_limit_change = 'X'.
        Save old P.Req. data and clear tables
          old_req_items[]           = req_items[].
          old_req_item_account[]    = req_item_account[].
          old_req_item_text[]       = req_item_text[].
          old_req_limits[]          = req_limits[].
          old_req_contract_limits[] = req_contract_limits[].
          old_req_services[]        = req_services[].
          old_req_serv_account[]    = req_serv_account[].
          old_req_serv_text[]       = req_serv_text[].
          old_req_addrdelivery[]    = req_addrdelivery[].
          REFRESH:  req_items,
                    req_item_account,
                  req_item_text,
                    req_limits,
                    req_contract_limits,
                    req_services,
                    req_serv_account,
                    req_serv_text.
                  req_addrdelivery.
          CLEAR f_first_change.
        ENDIF.
      Limit
        IF l_reqlines-line_type EQ '3'.
          and not reqheaders-limit is initial.
          DATA: l_reqreferences_temp   TYPE reqreferences_type.
        +JMS 2/26/2002
          CLEAR l_reqreferences_temp.
          READ TABLE reqreferences INTO l_reqreferences_temp
            WITH KEY client   = longkey-client
                     reqno    = longkey-reqno
                     reqlline = longkey-reqlline
                     BINARY SEARCH.
          IF sy-subrc = 0.
            h_preq_item = l_reqreferences_temp-refline.
          ENDIF.
          CLEAR l_req_items.
          READ TABLE old_req_items INTO l_req_items
              WITH KEY preq_item = h_preq_item.
          MOVE-CORRESPONDING l_req_items TO reqheaders.
          reqheaders-begdate   = l_req_items-deliv_date.
          reqheaders-limit     = l_req_items-c_amt_bapi.
          reqheaders-exp_value = l_req_items-c_amt_bapi.
          reqheaders-gr_ind    = 'X'.
          reqheaders-reqno     = l_req_items-preq_no.           "jms 022602
          CLEAR l_req_items.
    INSERT FORM **** CREATE_SERVICE_ITEM
          h_packno_item = h_packno_item + 1.
          h_packno_srv  = h_packno_srv  + 10000.
          h_introw      = h_introw + 1.
          CLEAR l_req_items.                                 " Note 364396
          MOVE-CORRESPONDING reqheaders TO l_req_items.
          l_req_items-preq_no = reqheaders-reqno.               "jms 022602
         l_REQ_ITEMS-PREQ_NO = REQUIS_NUMBER.                 "jms 022602
    l_REQ_ITEMS-PREQ_ITEM = H_PREQ_ITEM + 1.    "iok 091801
          l_req_items-preq_item = h_preq_item.                  "iok 091801
          l_current_item = h_preq_item.                         "iok 092101
          h_srv_item  = l_req_items-preq_item.
          h_preq_item = h_preq_item + 1.
          IF NOT reqheaders-limit IS INITIAL OR
             NOT reqheaders-exp_value IS INITIAL.
            IF reqheaders-gr_ind IS INITIAL.
              l_req_items-item_cat = '1'.
            ELSE.
              l_req_items-item_cat = '9'.
            ENDIF.
            l_req_items-deliv_date = reqheaders-begdate.
          ELSE.
            l_req_items-item_cat = '9'.
          ENDIF.
          IF l_req_items-del_datcat IS INITIAL.
            l_req_items-del_datcat = '1'.
          ENDIF.
          l_req_items-quantity = 1.
          l_req_items-pckg_no  = h_packno_item.
          IF l_req_items-preq_name EQ space.
            l_req_items-preq_name = sy-uname.
          ENDIF.
          APPEND l_req_items TO req_items.
    END OF FORM INSERTION ********
          l_req_limits-pckg_no    = h_packno_item.
          l_req_limits-limit      = reqheaders-limit.
          l_req_limits-exp_value  = reqheaders-exp_value.
          l_req_limits-no_limit   =  reqheaders-no_limit.
          l_req_limits-no_frlimit = 'X'.
          APPEND l_req_limits TO req_limits.
    *.... Account assignment
        clear requisition_srv_accass_values.
          CLEAR l_req_serv_account.
          l_req_serv_account-pckg_no = h_packno_item.
          MOVE-CORRESPONDING l_reqlines TO longkey.
        read table reqaccts with key longkey binary search. "iok 091801
          READ TABLE reqaccts INTO l_reqaccts                   "iok 091801
            WITH KEY client   = longkey-client
                     reqno    = longkey-reqno
                     reqlline = longkey-reqlline
                     BINARY SEARCH.
          IF sy-subrc = 0.
            LOOP AT reqaccts
                INTO l_reqaccts
                WHERE reqno    = l_reqreferences-reqno
                AND   reqlline = l_reqreferences-reqlline.
    INSERT FULL FORM *********** FILL_REQ_ACCT_SRV
              DATA: acctcomp1 TYPE bapiebkn,
                    acctcomp2 TYPE bapiebkn,
                    high_serial TYPE dzekkn.  "LIKE BAPIEKKN-SERIAL_NO.
              CLEAR l_req_serv_account-serial_no.
              CLEAR acctcomp1.
              MOVE-CORRESPONDING l_reqaccts TO acctcomp1.
              CLEAR: acctcomp1-preq_no,
                     acctcomp1-preq_item,
                     acctcomp1-serial_no,
                     acctcomp1-created_on,
                     acctcomp1-created_by,
                     acctcomp1-preq_qty,
                     acctcomp1-distr_perc,
                     acctcomp1-change_id,
                     acctcomp1-currency.
              LOOP AT req_item_account INTO l_req_item_account.
                CLEAR acctcomp2.
      MOVE-CORRESPONDING l_req_item_account TO ACCTCOMP2.  "is blank
                CLEAR: acctcomp2-preq_no,
                       acctcomp2-preq_item,
                       acctcomp2-serial_no,
                       acctcomp2-created_on,
                       acctcomp2-created_by,
                       acctcomp2-preq_qty,
                       acctcomp2-distr_perc,
                       acctcomp2-change_id,
                       acctcomp2-currency.
               IF acctcomp1 EQ acctcomp2  AND h_srv_outl_created IS INITIAL.
                l_req_serv_account-serial_no = l_req_item_account-serial_no.
                  EXIT.
                ENDIF.
                high_serial = l_req_item_account-serial_no.
              ENDLOOP.
              h_srv_outl_created = ' '.
              IF l_req_serv_account-serial_no IS INITIAL.
                MOVE-CORRESPONDING l_reqaccts TO l_req_item_account.
               l_REQ_item_ACCOUNT-PREQ_NO   = REQUIS_NUMBER.   "jms 022702
                l_req_item_account-preq_no = l_req_items-preq_no."jms 022702
                l_req_item_account-preq_item = h_srv_item.
    REQUISITION_ACCOUNT_ASSIGNMENT-WBS_ELEM_E = REQACCT-BBP_PROJECT.
                l_req_item_account-serial_no = high_serial + 1.
                l_req_serv_account-serial_no = l_req_item_account-serial_no.
                APPEND l_req_item_account TO req_item_account.
              ENDIF.
    END OF FORM INSERTION ***********
              h_serial_no = h_serial_no + 1.
              l_req_serv_account-serno_line = h_serial_no.
              l_req_serv_account-percentage = l_reqaccts-distr_perc.
              APPEND l_req_serv_account TO req_serv_account.
            ENDLOOP.
    INSERT FULL FORM **************** CONVERT_ACCOUNT_***_CAT
    data: account_tab LIKE bbp_pds_acc OCCURS 0 WITH HEADER LINE.
            DATA: account_tab TYPE STANDARD TABLE OF bbp_pds_acc.
            DATA: l_account_tab TYPE bbp_pds_acc.
            DATA: h_knttp TYPE knttp.
          move the accounting data to that item into the interface table
                LOOP AT reqaccts
               INTO l_reqaccts
              WHERE reqno    EQ l_reqreferences-reqno
                AND reqlline EQ l_reqreferences-reqlline.
              MOVE-CORRESPONDING l_reqaccts TO l_account_tab.
              APPEND l_account_tab TO account_tab.
            ENDLOOP.
          call the convert API
            CALL FUNCTION 'BBP_ACCCAT_MAP_EXP'
                 EXPORTING
                      i_logical_system = logical_system
                 IMPORTING
                      e_r3_acc_cat     = h_knttp
                 TABLES
                      i_pd_account     = account_tab.
            IF h_knttp IS INITIAL.
              h_knttp = 'X'.
            ENDIF.
          +JMS 2/14/2002 Issue #1590
            CLEAR   account_tab.
            REFRESH account_tab.
          account assignment category - set in the correct item
            LOOP AT req_items
               INTO l_req_items
              WHERE preq_item EQ l_req_item_account-preq_item.
              l_req_items-acctasscat = h_knttp.
              MODIFY req_items FROM l_req_items INDEX sy-tabix.
            ENDLOOP.
    END OF FORM INSERTION ************
          ELSE.
    INSERT FULL FORM ************* Form  CONVERT_ACCOUNT_***_CAT_U
            LOOP AT req_items
               INTO l_req_items
              WHERE preq_item EQ l_current_item.
              l_req_items-acctasscat = 'U'.
              MODIFY req_items FROM l_req_items INDEX sy-tabix.
            ENDLOOP.
    END OF FORM INSERTION ************
          ENDIF.
        Get UNSPSC code (first hit) based on Material Group and store
        in text id B05.   iok 092101
          READ TABLE req_items INTO l_req_items
              WITH KEY preq_item = l_current_item
                       mat_grp   = l_mat_group.
          READ TABLE req_item_text INTO l_req_item_text
              WITH KEY preq_no   = requis_number
                       preq_item = l_req_items-preq_item
                       text_id   = 'B05'.
          IF sy-subrc <> 0.
            CLEAR l_req_item_text.
          Get UNSPSC Code from Material Group .. even if arbitrary
            SELECT unspsc_code UP TO 1 ROWS
              FROM zxl8_category_id
              INTO l_req_item_text-text_line
             WHERE category_id = l_mat_group.
            ENDSELECT.
          If nothing found then fill in a dummy UNSPSC.  The first
          letter of the Material will designate whether it's a Material
          or Service.
            IF sy-subrc NE 0.
            Move the Material Group value into a holding variable
              CONCATENATE l_mat_group(1) 'XXXXXXX'
                     INTO l_req_item_text-text_line.
            ENDIF.
            l_req_item_text-preq_no   = requis_number.
            l_req_item_text-preq_item = l_req_items-preq_item.
            l_req_item_text-text_id   = 'B05'.
            INSERT l_req_item_text INTO TABLE req_item_text.
          ENDIF.
        Don't send Internal Note to Backend
         delete req_item_text where text_id = 'B02'.
    Service -- NOT NEEDED -- IOK 07/13/01
       elseif not reqlines-reqsline is initial
             and reqlines-line_type eq '2'.
         move-corresponding reqlines to shortkey.
         read table reqlinesrs with key shortkey binary search.
         if sy-subrc = 0.
           h_serv = reqlinesrs.
           append h_serv.
         endif.
    material item -- NOT NEEDED -- IOK 07/13/01
        ENDIF.
      ENDLOOP.
    Services -- NOT NEED -- IOK 07/13/01
      IF f_limit_change = 'X'.
      Check multiple account assignment
        LOOP AT req_items INTO l_req_items.
          h_index = sy-tabix.
          CLEAR next.
          LOOP AT req_item_account
             INTO l_req_item_account
            WHERE preq_item EQ l_req_items-preq_item.
            next = next + 1.
          ENDLOOP.
          IF next > 1.
            l_req_items-distrib    = '2'. "prozentuale Verteilung
            l_req_items-part_inv   = '1'.
            l_req_items-gr_non_val = 'X'.
           MODIFY req_items FROM l_req_items INDEX h_index.     "217191
         modify requisition_items.                                "217191
          ENDIF.
        ENDLOOP.
      ENDIF.
    Remap delivery address for backend processing
      LOOP AT req_addrdelivery INTO l_req_addrdelivery.
        MOVE:  l_req_addrdelivery-name_2   TO l_req_addrdelivery-name,
               l_req_addrdelivery-c_o_name TO l_req_addrdelivery-name_2.
        CLEAR: l_req_addrdelivery-c_o_name.
        MODIFY req_addrdelivery FROM l_req_addrdelivery INDEX sy-tabix.
      ENDLOOP.
    CHM 07/16/2003 Changed created by to always be actual creator even
                   for on behalf of situations
        LOOP AT req_items
           INTO l_req_items.
          l_req_items-created_by = x_sc_header-created_by.
          MODIFY req_items FROM l_req_items INDEX sy-tabix.
        ENDLOOP.
    CMH - end change
    MA 12/10/04 - Pass MP2 number from Manu Prod# to Req Item Text
    LOOP AT req_items INTO l_req_items.
        READ TABLE t_sc_item into x_sc_item
             WITH KEY number_int  = l_req_items-preq_item.
        l_req_item_text-preq_no   = requis_number.
        l_req_item_text-preq_item = l_req_items-preq_item.
        l_req_item_text-text_id   = 'B06'.
        l_req_item_text-text_line = x_sc_item-manu_prod.
        INSERT l_req_item_text INTO TABLE req_item_text.
    ENDLOOP.
    ENDMETHOD.

    Any help guys?
    Thanks
    Manyam

  • Help needed on writing a SQL query

    Here is my table that shows records of 3 ORDER_ID (10, 20 and 30). All I need to do is, pick the first record of each order_id and check the event_id, if the event_id is same for the next record, ignore it, else show it and ignore rest all records for that order_id. This way my query output will show only two records for each ORDER_ID. Query should produce records that are in BOLD in the sample data. (Database - 11g)
    Thanks for your help in advance
    ORDER_ID     EVENT_ID     EVNT_DATE     STATE_CODE
    *10     16937555     20100212     COMPLETE*
    10     16937555     20100212     ACTIVE
    *10     16308004     20100129     OCCURRED*
    10     16131904     20100125     ACTIVE
    10     16270684     20100128     OCCURRED
    10     14899116     20091213     ACTIVE
    10     16085672     20100123     COMPLETE
    10     16085673     20100123     OCCURRED
    10     14899119     20100123     COMPLETE
    10     14899120     20100123     COMPLETE
    *20     17134164     20100223     COMPLETE*
    20     17134164     20100223     ACTIVE
    20     17134164     20100223     STARTED
    *20     15479131     20100105     OCCURRED*
    20     15478409     20100105     OCCURRED
    20     15478408     20100105     ACTIVE
    20     15119404     20100105     COMPLETE
    20     14346123     20091129     ACTIVE
    20     15467821     20100104     OCCURRED
    20     14346125     20091216     COMPLETE
    20     14346126     20091215     COMPLETE
    20     14346126     20091214     COMPLETE
    *30     18814670     20100412     COMPLETE*
    30     18814670     20100412     ACTIVE
    *30     18029509     20100320     OCCURRED*
    30     16853720     20100211     ACTIVE
    30     17965764     20100319     OCCURRED
    30     16386708     20100211     COMPLETE
    30     16804451     20100211     OCCURRED
    30     15977897     20100121     ACTIVE
    Edited by: sarvan on Aug 12, 2011 7:16 AM

    try this [Not fully tested]
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for Linux: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    Elapsed: 00:00:00.00
    SQL> SELECT *
      2    FROM (SELECT order_id, event_id, evnt_date, state_code, next_evntid,
      3                 ROW_NUMBER () OVER (PARTITION BY event_id ORDER BY NULL)
      4                                                                       AS rownm
      5            FROM (WITH t AS
      6                       (SELECT 10 AS order_id, 16937555 AS event_id,
      7                               20100212 AS evnt_date, 'COMPLETE' AS state_code
      8                          FROM DUAL
      9                        UNION ALL
    10                        SELECT 10, 16937555, 20100212, 'ACTIVE'
    11                          FROM DUAL
    12                        UNION ALL
    13                        SELECT 10, 16308004, 20100129, 'OCCURRED'
    14                          FROM DUAL
    15                        UNION ALL
    16                        SELECT 10, 16131904, 20100125, 'ACTIVE'
    17                          FROM DUAL
    18                        UNION ALL
    19                        SELECT 10, 16270684, 20100128, 'OCCURRED'
    20                          FROM DUAL
    21                        UNION ALL
    22                        SELECT 20, 17134164, 20100223, 'COMPLETE'
    23                          FROM DUAL
    24                        UNION ALL
    25                        SELECT 20, 17134164, 20100223, 'ACTIVE'
    26                          FROM DUAL
    27                        UNION ALL
    28                        SELECT 20, 17134164, 20100223, 'STARTED'
    29                          FROM DUAL
    30                        UNION ALL
    31                        SELECT 20, 15479131, 20100105, 'OCCURRED'
    32                          FROM DUAL)  -- End of test data
    33                  SELECT order_id, event_id, evnt_date, state_code,
    34                         LEAD (event_id, 1, 0) OVER (PARTITION BY order_id ORDER BY NULL)
    35                                                                 AS next_evntid
    36                    FROM t)
    37           WHERE event_id = next_evntid)
    38   WHERE rownm <= 2
    39  /
      ORDER_ID   EVENT_ID  EVNT_DATE STATE_CO NEXT_EVNTID      ROWNM
            10   16937555   20100212 COMPLETE    16937555          1
            20   17134164   20100223 COMPLETE    17134164          1
            20   17134164   20100223 ACTIVE      17134164          2
    Elapsed: 00:00:00.00
    SQL> PS - You should seriously think about ordering the data before you do this kind off operations.
    Edited by: Sri on Aug 12, 2011 9:12 AM

  • Help needed in executing pl/sql programs

    hi all
    iam new to PL/SQL programming
    i have installed oracle 9i
    iam trying to practice some sample pl/sql programs
    i have opened oracle 9i and typed these commands
    sql>ed sum
    then a notepad opens where i type my pl/sql program and save it and then return back to oracle 9i and type this
    sql>@ sum
    then my pl/sql program gets executed.......but iam not getting any output
    its comig as procedure implemented succesfully
    is it compulsory to open notepad to execute pl/sql progams or we can direclty type the programs in oracle 9i
    please help in this matter ASAP
    Regards
    Suresh

    Yes, you can type the program directly at the SQL prompt, but editing will be a bit difficult.
    You should use some good editor that allows you to edit properly and then run like you did.
    You need to do:
    SQL> set serveroutput onbefore running your program to see dbms_output messages.

  • Help needed in designing dynamic images

    Hi,
    I just posted a thread before, but there is something wrong in that post.
    Any ways, I am new to Java and am trying to design a GUI which has images, which change dynamically. One of the examples is on this webpage
    http://images.google.com/imgres?imgurl=http://www.snapstream.com/images/blog/godzilla/overheating_max_cpu_tn.jpg&imgrefurl=http://blogs.snapstream.com/2006/01/18/godzilla-pvr/&h=516&w=683&sz=80&hl=en&start=3&tbnid=huDY6gDdtS_o-M:&tbnh=105&tbnw=139&prev=/images%3Fq%3DCPU%2Btemperature%26gbv%3D2%26svnum%3D10%26hl%3Den%26sa%3DG
    I need help desperately. I would appreciate, if you can help me. What do i need to use? Can it be done by using Swing? Are there any good examples of it on web? I am basically not clear, what do I need to use...
    waiting for your reply. thanks in advance.
    Ankit

    consider you have a JFrame called "frame"
    what you can do:
    JLabel lab = new JLabel("../firstPic.jpg");
    frame.getContentPane().add(lab);
    then, each time you will call "setIcon()" on the lab and refresh the frame it will display a new picture

  • Help needed in configuring Dynamic F4

    Hi All
    I am trying to configure Dynamic F4 help for Actvities appln.
    In Actvities Appln I have the Partners tab.In this Partner tab I have partner function and partner Id fields. When I make a search for partner Id  I need to launch  the search screen based on thepartner function selected.
    I guess we can use dynamic F4 help but how to achieve this I am not sure. If anyone has done simliar stuff please do give your inputs.
    Thanks
    Regards
    Senthil

    Hi Senthil,
    You can use Search Help Exit for your problem.
    <b>Search help exit</b> : A search help exit is a function module for making the input help process described by the search help more flexible than possible with the standard version.
    This function module must have the same interface as function module F4IF_SHLP_EXIT_EXAMPLE. The search help exit may also have further optional parameters (in particular any EXPORTING parameters).
    A search help exit is called at certain time points in the input help process.
    <b>Note:</b> The source text and long documentation of the above-specified function module (including the long documentation about the parameters) contain information about using search help exits.
    Function modules are provided in the function library for operations that are frequently executed in search help exits. The names of these function modules begin with the prefix F4UT_. These function modules can either be used directly as search help exits or used within other search help exits. You can find precise instructions for use in the long documentation for the corresponding function module.
    A search help exit is called repeatedly in connection with several
    Events during the F4 process. The relevant step of the process is passed on in the CALLCONTROL step. If the module is intended to perform only a few modifications before the step, CALLCONTROL-STEP should remain unchanged.
    However, if the step is performed completely by the module, the following step must be returned in CALLCONTROL-STEP.
    For more detailed information please refer to the documentation describing the concept of the search help exit.
    The module must react with an immediate EXIT to all steps that it does not know or does not want to handle.
    <b>Time Points</b> :
    During the input help process, a number of time points are defined that each define the beginning of an important operation of the input help process.
    If the input help process is defined with a search help having a search help exit, this search help exit is called at each of these time points. If required, the search help exit can also influence the process and even determine that the process should be continued at a different time point.
    The following time points are defined:
    <b>1. SELONE</b>
    Call before selecting an elementary search help. The possible elementary search helps are already in SHLP_TAB. This time point can be used in a search help exit of a collective search help to restrict the selection possibilities for the elementary search helps.
    Entries that are deleted from SHLP_TAB in this step are not offered in the elementary search help selection. If there is only one entry remaining in SHLP_TAB, the dialog box for selecting elementary search helps is skipped. You may not change the next time point.
    The time point is not accessed again if another elementary search help is to be selected during the dialog.
    <b>2. PRESEL1</b>
    After selecting an elementary search help. Table INTERFACE has not yet been copied to table SELOPT at this time point in the definition of the search help (type SHLP_DESCR_T). This means that you can still influence the attachment of the search help to the screen here. (Table INTERFACE contains the information about how the search help parameters are related to the screen fields).
    <b>3. PRESEL</b>
    Before sending the dialog box for restricting values.
    This time point is suitable for predefining the value restriction or for completely suppressing or copying the dialog.
    <b>4. SELECT</b>
    Before selecting the values. If you do not want the default selection, you should copy this time point with a search help exit. DISP should be set as the next time point.
    <b>5. DISP</b>
    Before displaying the hit list. This time point is suitable for restricting the values to be displayed, e.g. depending on authorizations.
    <b>6. RETURN</b> (usually as return value for the next time point)
    The RETURN time point should be returned as the next step if a single hit was selected in a search help exit.
    It can make sense to change the F4 flow at this time point if control of the process sequence of the Transaction should depend on the selected value (typical
    example: setting SET/GET parameters). However, you should note that the process will then depend on whether a value was entered manually or with an input help.
    <b>7. RETTOP</b>
    You only go to this time point if the input help is controlled by a collective search help. It directly follows the time point RETURN. The search help exit of the collective search help, however, is called at time point RETTOP.
    <b>8. EXIT</b> (only for return as next time point)
    The EXIT time point should be returned as the next step if the user had the opportunity to terminate the dialog within the search help exit.
    <b>9. CREATE</b>
    The CREATE time point is only accessed if the user selects the function "Create new values". This function is only available if field CUSTTAB of the control string CALLCONTROL was given a value not equal to SPACE earlier on.
    The name of the (customizing) table to be maintained is normally entered there. The next step returned after CREATE should be SELECT so that the newly entered value can be selected and then displayed.
    10. <b>APP1, APP2, APP3</b>
    If further pushbuttons are introduced in the hit list with function module F4UT_LIST_EXIT, these time points are introduced. They are accessed when the user presses the corresponding pushbutton.
    <b>Note:</b> If the F4 help is controlled by a collective search help, the search help exit of the collective search help is called at time points SELONE and RETTOP. (RETTOP only if the user selects a value.) At all other time points the search help exit of the selected elementary search help is called.
    If the F4 help is controlled by an elementary search help, time point RETTOP is not executed. The search help exit of the elementary search help is called at time point SELONE (at the moment). This search help exit should not do anything at this time point. Any preparatory work should be carried out at time point PRESEL1.
    <b>Steps for creating search help :</b>
    1. Run Transaction SE11
    2. Give search help name
    3. Click on Create
    4. Make selection for Elementary or Collective search
       Help
    <b>For Elementary Search Help</b>
    5. Elementary search Help screen.  
    6. Give short description.
    7. Dialog type specifies the data display in the hit
       list.
    8. Give selection method
    A] Search for database tables
    B] Search for Views
    9. Hot key specifies the letter or number displayed with every elementary search help. 
    10. Search help Exit: Specify the function module developed for the search of data for the elementary search help.
    11. Search help parameter
    A] Specify the input and output fields in the search help parameter column.
    B] IMP column is input parameter for the search help.
    C] EXP column is output parameter of the search help, to be displayed in the Hit list after selection.
    D] LPos specifies the order in which fields are displayed in the hit list.
    E] SPos specifies the order in which fields are displayed in the search help pop up screen.
    F] Specify Data element in the field.
    G] Specify the default value for any field required.
    <b>For Collective Search Help :</b>
    12. Search help exit: Specify the function module developed for the search of data for the elementary search help.
    13. Search help parameter: Specify the import and export parameters.          
    14. Search help: Specify the elementary search help and the short text.
    15. Parameter Assignment: Select the elementary search help and click on the parameter assignment. System proposes fields. User has to select the fields as per requirement, fields to be displayed in the output
    hit list. Parameter assignment has to be done compulsorily for every elementary search help designed for the collective search help.   
    <b>Please reward points if it helps.</b>
    Regards,
    Amit Mishra

  • Help needed with Express and SQL Dev

    Recently was asked to make a sql server application work with Oracle. I have never worked with Oracle products and no one in my small shop has either. I downloaded the Express 10g onto a virtual machine on my dev server and oracle SQL Developer locally. I have no idea how to connect to the Express db on the prod server using sql developer. I have tried Basic and TNS connection types and all the errors are very cryptic. Any help is appreciated. Do I need to install anything client side to connect to the server?
    I figured it out. I had to use the Basic connection type and I DL'd the J2EE .
    Edited by: jt_stand on Sep 25, 2008 10:51 AM

    Had to use the Basic connection type and get the right combination of options. I can now connect to my remote Express server with my local sql developer program.

  • Help needed writing simple PL/SQL statement

    Hi,
    I need to run the following delete statement in a PL/SQL procedure but for it to commit every 1000 rows or so. Can anyone help?
    DELETE
    FROM IDIS.YPROCRULES A
    WHERE 1 = 1
    AND NOT EXISTS (SELECT 'X' FROM IDIS.YPROCCTRL B WHERE A.SEQ_0 = B.SEQ_0)
    Thanks
    Mark

    The fastest most efficient way of doing the delete is to write it in one sql statement as you have done.
    Commiting every 1000 rows means you have to use row by row processing. A lot of us call this slow by slow processing.
    Every time you commit in a loop , you increase the risk of snapshot too old error, plus you actually slow down the processing, as well as give you issues with regards to what happens if your process fails after x iterations. (some of your data is commited, other data is not, how do you restart the process)
    The correct approach is to have appropriately sized rollback/undo segments.

  • Help needed in debugging null pointer exception

    I am debugging one seeded report in R12. It is erroring out with the following error.
    Calling XDO Data Engine...
    java.lang.NullPointerException
    at
    oracle.apps.xdo.oa.util.DataTemplate.getDataTemplate(DataTemplate.java:281)
    at oracle.apps.xdo.oa.util.DataTemplate.<init>(DataTemplate.java:133)
    at
    oracle.apps.xdo.oa.cp.JCP4XDODataEngine.runProgram(JCP4XDODataEngine.java:282)
    -> data definition exists but i didn't see anything against 'XML Schema', 'Data Template', 'Preview Data'. Buttons against them are also greyed out.
    ->I have tried searching XML Publisher Administrator ->Templates. But i didnot find anything.
    ->XDO_LOBS has record against this report.
    -> Data Template(.xml file) exists in the following location $XLA_TOP/patch/115/publisher/defs
    Can anybody help me in resolving this issue.
    Thanks in Advance,
    Srini

    Hi Srini
    This forum is for customers - please use the ML I sent you for questions.
    Regards
    Tim
    http://blogs.oracle.com/xmlpublisher

  • Help needed in building a  sql query

    Hello,
    I am using Oracle 10g db.
    I have 3 tables table1 and table2 and table3
    I am writing one sql query which is like
    select table1.a a1,(select distinct b from table2,table3 where table2.id=table3.id and table1.id=table2.id) b1
    from table1
    Now the b1 value may give more then 1 values so when i am trying to execute the query its giving me error.
    What i would like to have is if it gives returns more then 1 value then add that value as a new column means if b1 gives like abc and def as values.
    Then i want the sql to return like
    acolvalue abc def as a single row.
    Is this possible to do?
    Thanks

    Hello,
    The approach which i took is i wrote a function which gives me the b values , sseparated.
    Then i am building a outer query considering the max of b so i just found there are max 10 values which one row is showing.
    select b11,b12,b13,,,b10
    from (
    select table1.a a1,func(select distinct b from table2,table3 where table2.id=table3.id and table1.id=table2.id) b1
    from table1)
    but now i am facing problem like the value of b1 is a,b,c
    i want to use the substr and instr function to get
    a as b11
    b as b12
    c as b13
    can anyone pls help me out to write a query? i am getting b11 but other values are somehow not coming.
    for b11
    i used
    substr(b1,1,instr(b1,',',1,1)-1)
    Thanks

  • Help needed in defaulting Dynamic assignment blocks

    Hi All,
    We are trying to default assignment blocks based on the configuration saved against each object type.
    Procedure followed is as below
    Created 2 configurations, one for sold to party and the other one for ship to party in the BP_Head cpmponent for the Overview page. Two configurations of the overview page are saved against a role config key but with a variant of object type
    Created two logical link IDs one each for sold to party and ship to party
    Make these two logical link IDs available in the UI as direct link groups
    Upon clicking sold to party the configuration saved against that(Set of assignment blocks in the overview page) needs to be called (Remember we saved this configuration with a variant of object type)
    Similarly when clicking on the ship to party link corresponding configuration (Set of assignment blocks in the overview page) needs to be displayed
    Any inputs on this will be of great help.
    Regards,
    udaya

    you need to redefine the method DO_CONFIG_DETERMINATION of your controller
    there you get the role and any other needed values, and you define the OBJECT_TYPE and SUBTYPE that will be used as key fields for the configuration

Maybe you are looking for