6 Replies Latest reply: Nov 29, 2012 4:05 AM by Bhabani Ranjan RSS

    KM: How to get length and substring?

    932033
      I write my own IKM and I need detect long string and cut them.
      I try to use
      <%=odiRef.getTable("L","TARG_NAME","A").length() %> --> returns value: 70 (!) , but real length is 25 (perhaps returned buffer size).
      Any ideas?
        • 1. Re: KM: How to get length and substring?
          932033
          70 - it's a length of code - <?=snpRef.getObjectName("L", "<table name>", "<schema>", "", "D") ?>
          It's stupid :(
          • 2. Re: KM: How to get length and substring?
            Bhabani Ranjan
            Create a new step in your IKM (must be 1st step). Then put below code with oracle technology.

            <%
            String tname= odiRef.getTable("L", "TARG_NAME", "A") ; /// for source table name use <%=snpRef.getFrom()%> and use these codes in LKM
            if (tname.length() >25) {
                 tname=tname.trim();
            tname=substring(tname,1,25);
            }
            %>

            Now where ever you want your target table name you can just use <%=tname%>

            example
            select * from <%=tname%>


            Thanks
            Bhabani
            http://dwteam.in
            • 3. Re: KM: How to get length and substring?
              932033
              I use my own IKM (ODI 11.1.1.1).
              Your code is not correct. It's repeatly my fail.

              <%
              String tname= odiRef.getTable("L", "TARG_NAME", "A") ; /// for source table name use <%=snpRef.getFrom()%>
              if (tname.length() >25) { <<< - HERE NOT REAL LENGTH OF TARGET NAME! HERE LENGTH OF <?=snpRef.GetObjectName...?>
              tname=tname.trim();
              tname=substring(tname,1,25);
              }
              %>
              • 4. Re: KM: How to get length and substring?
                Bhabani Ranjan
                use this and let me know

                <%
                String tname= odiRef.getTable("L", "TARG_NAME", "A") ;
                if (tname.length() >25)
                tname=tname.trim().substring(0);
                %>

                select * from <%= tname%>

                Thanks
                Bhabani
                http://dwteam.in
                • 5. Re: KM: How to get length and substring?
                  932033
                  This is not correct code
                  if (tname.length() > 25)
                  tname=tname.trim().substring(0);

                  Because,after
                  tname = snpRef.getTable("L","TARG_NAME","A");
                  ODI put into tname <?=snpRef.getObjectName("L", "<table name>", "<schema>", "", "D") ?>. This code will be evaluate on execution.
                  tname.length() is equal to "<?=snpRef.getObjectName("L", "<table name>", "<schema>", "", "D") ?>".length() and return 70.

                  I parse <?=snpRef.getObjectName("L", *"<table name>"*, "<schema>", "", "D") ?> and resolve my problem:

                  <%
                  var s=snpRef.getTable("L", "TARG_NAME", "A");
                  var pos1 = s.indexOf('"', 0);
                  var pos2 = s.indexOf('"', pos1 + 1);
                  var pos3 = s.indexOf('"', pos2 + 1); // 3-td quote pos
                  var pos4 = s.indexOf('"', pos3 + 1); // 4-th quote pos
                  var targ_name = s.substring(pos3 + 1, pos4);
                  ...
                  And now, targ_name.length() and targ_name.substring(x,y) return correct values.
                  %>

                  Edited by: Aikon on 29.11.2012 1:59
                  • 6. Re: KM: How to get length and substring?
                    Bhabani Ranjan
                    Glad you resolved it.

                    Thanks
                    Bhabani
                    http://dwteam.in