TIPTOP之分割split函数方法getIndexOfsubString等临时表创建;

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了TIPTOP之分割split函数方法getIndexOfsubString等临时表创建;相关的知识,希望对你有一定的参考价值。

范例(cnmq001):

原:每次查询都把数据全部查询到临时表后再筛选;

现:查询到临时表的时候,增加可行的筛选条件,再二次筛选临时表的数据,进行优化;

 

1)临时表创建:

PRIVATE FUNCTION cnmq001_cr_tmp()
 
  DROP TABLE cnmq001_tmp 
  CREATE TEMP TABLE cnmq001_tmp(
   nmbc002 LIKE nmbc_t.nmbc002, 
   nmbc002_desc LIKE type_t.chr500, 
   nmbc005 LIKE nmbc_t.nmbc005, 
   nmbcdocno LIKE nmbc_t.nmbcdocno, 
   nmbcseq LIKE nmbc_t.nmbcseq, 
   nmbc006 LIKE nmbc_t.nmbc006, 
   nmbc007 LIKE nmbc_t.nmbc007, 
   nmbc007_desc LIKE nmajl_t.nmajl003,
   nmbcud001 LIKE nmbc_t.nmbcud001, 
   nmbc003 LIKE nmbc_t.nmbc003, 
   nmbc003_desc LIKE type_t.chr80, 
   inamt    LIKE type_t.num20_6, 
   nmbc100  LIKE nmbc_t.nmbc100,
   nmbc101  LIKE nmbc_t.nmbc101,
   outamt   LIKE type_t.num20_6,
   nmbccrtid LIKE nmbc_t.nmbccrtid,
   nmbccrtid_desc LIKE type_t.chr30,
   nmbccrtdt LIKE nmbc_t.nmbccrtdt
  )
  BEGIN WORK #170406-00001#1 放到事务里
   CALL cnmq001_ins_tmp()
  COMMIT WORK 
END FUNCTION

 

2)TIPTOP没有直接的split分割函数,所以走点弯路:

PRIVATE FUNCTION split_itemcount(p_arg1,p_arg2)
    DEFINE p_arg1   STRING
    DEFINE p_arg2   STRING
    DEFINE l_cnt    INT
    DEFINE tok      BASE.StringTokenizer

    #LET tok = base.StringTokenizer.create(p_arg1,p_arg2)  
    LET tok = base.StringTokenizer.createExt(p_arg1,p_arg2,"",TRUE)  
    LET l_cnt = tok.countTokens()  
    RETURN l_cnt

END FUNCTION

 

PRIVATE FUNCTION split(p_arg1,p_arg2,p_arg3)
    DEFINE p_arg1   STRING
    DEFINE p_arg2   STRING
    DEFINE p_arg3   INT
    DEFINE l_cnt    INT
    DEFINE l_idx    INT
    DEFINE l_retstr STRING
    DEFINE l_str    STRING
    DEFINE tok      BASE.StringTokenizer
    
    INITIALIZE l_retstr TO NULL
    #LET tok = base.StringTokenizer.create(p_arg1,p_arg2)  
    LET tok = base.StringTokenizer.createExt(p_arg1,p_arg2,"",TRUE)  
    LET l_cnt = tok.countTokens()  
    IF (p_arg3 <= 0) OR (l_cnt <= 0 ) OR (p_arg3 > l_cnt) THEN  
        LET l_retstr = NULL  
    ELSE  
        LET l_idx = 1  
        WHILE tok.hasMoreTokens()  
            LET l_str = tok.nextToken()   
            IF l_idx = p_arg3 THEN  
                LET l_retstr = l_str  
                EXIT WHILE  
            END IF  
            LET l_idx = l_idx + 1  
        END WHILE  
    END IF  
    RETURN l_retstr  

END FUNCTION

 

3)本人愚笨,试了几种方法,最后只能通过系统组合出来的条件,进行分割,再重组成自己所需的条件,用在临时表的查询上:

PRIVATE FUNCTION cnmq001_ins_tmp()
DEFINE l_sql STRING
DEFINE l_nmch006      LIKE nmch_t.nmch006
DEFINE l_nmcq006      LIKE nmcq_t.nmcq006
DEFINE l_nmck042      LIKE nmck_t.nmck042
DEFINE l_apde010      LIKE apde_t.apde010
DEFINE l_nmbb025      LIKE nmbb_t.nmbb025
DEFINE lr_tmp RECORD 
      nmbc002 LIKE nmbc_t.nmbc002, 
   nmbc002_desc LIKE type_t.chr500, 
   nmbc005 LIKE nmbc_t.nmbc005, 
   nmbcdocno LIKE nmbc_t.nmbcdocno, 
   nmbcseq LIKE nmbc_t.nmbcseq, 
   nmbc006 LIKE nmbc_t.nmbc006, 
   nmbc007 LIKE nmbc_t.nmbc007, 
   nmbc007_desc LIKE nmajl_t.nmajl003,
   nmbcud001 LIKE nmbc_t.nmbcud001, 
   nmbc003 LIKE nmbc_t.nmbc003, 
   nmbc003_desc LIKE type_t.chr80, 
   inamt    LIKE type_t.num20_6, 
   nmbc100  LIKE nmbc_t.nmbc100,
   nmbc101  LIKE nmbc_t.nmbc101,
   outamt   LIKE type_t.num20_6,
   nmbccrtid LIKE nmbc_t.nmbccrtid,
   nmbccrtid_desc LIKE type_t.chr30,
   nmbccrtdt LIKE nmbc_t.nmbccrtdt
   END RECORD
   
   #TEST 170531 by ljr
   DEFINE l_wc STRING
   DEFINE l_wc2 STRING
   DEFINE l_wc3 STRING
   DEFINE l_i INT
   INITIALIZE l_wc3 TO NULL
   CALL cl_replace_str(g_wc,"and","|") RETURNING l_wc
   FOR l_i=1 TO split_itemcount(l_wc,"|")
        LET l_wc2 = split(l_wc,"|",l_i)
        IF l_wc2.getIndexOf("nmbc002",1)>0 AND l_wc2.getIndexOf("nmbc002_",1)<=0 THEN
            LET l_wc3 = l_wc3,l_wc2," and "
        ELSE
            IF l_wc2.getIndexOf("nmbcdocno",1)>0 THEN
                LET l_wc3 = l_wc3,l_wc2," and "
            ELSE
                IF l_wc2.getIndexOf("nmbcseq",1)>0 THEN
                    LET l_wc3 = l_wc3,l_wc2," and "
                ELSE
                    IF l_wc2.getIndexOf("nmbc006",1)>0 THEN
                        LET l_wc3 = l_wc3,l_wc2," and "
                    ELSE
                        IF l_wc2.getIndexOf("nmbccrtid",1)>0 AND l_wc2.getIndexOf("nmbccrtid_",1)<=0  THEN
                            LET l_wc3 = l_wc3,l_wc2," and "
                        END IF
                    END IF
                END IF
            END IF
        END IF
   END FOR
    IF NOT cl_null(l_wc3) THEN
        LET l_wc3 = l_wc3.subString(1,l_wc3.getLength()-5)
    ELSE
        LET l_wc3 = " 1=1 "
    END IF
   
   
   #170406-00001#1---begin---insert放入excute
   LET l_sql = " INSERT INTO cnmq001_tmp VALUES (?,?,?,?,?, ?,?,?,?,?, ?,?,?,?,?, ?,?,? )"
   PREPARE cnmq001_ins_tmp2 FROM l_sql
   #170406-00001#1---end---
   
   
   LET l_sql = " SELECT  UNIQUE nmbc002,‘‘,nmbc005,nmbcdocno,nmbcseq,nmbc006,nmbc007,‘‘,nmbcud001, ", 
               "  nmbc003,‘‘,decode(nmbc006,‘1‘,nmbc103,0) inamt,nmbc100,nmbc101,decode(nmbc006,‘2‘,nmbc103,0) outamt,nmbccrtid,‘‘,nmbccrtdt ",
               " FROM nmbc_t ",
               " WHERE nmbcent = ? AND nmbccomp = ? AND ",l_wc3
   PREPARE cnmq001_ins_tmp FROM l_sql
   DECLARE ins_curs CURSOR FOR cnmq001_ins_tmp  

   OPEN ins_curs USING g_enterprise,g_site
   FOREACH ins_curs INTO lr_tmp.*
     
     SELECT ooag011 INTO lr_tmp.nmbccrtid_desc
      FROM ooag_t WHERE ooagent=g_enterprise 
      AND ooag001 = lr_tmp.nmbccrtid
      
     SELECT nmaal003 INTO lr_tmp.nmbc002_desc 
       FROM nmaal_t WHERE nmaalent=g_enterprise
       AND nmaal001= lr_tmp.nmbc002
    
     SELECT nmajl003 INTO lr_tmp.nmbc007_desc 
       FROM nmajl_t WHERE nmajlent=g_enterprise
       AND nmajl001= lr_tmp.nmbc007
       AND nmajl002 = g_lang
     
      IF NOT cl_null(lr_tmp.nmbc003) THEN
         IF lr_tmp.nmbc003=EMPL THEN
            SELECT apca014 INTO lr_tmp.nmbc003 FROM apca_t 
            WHERE apcaent=g_enterprise 
            AND apcadocno=lr_tmp.nmbcdocno
            
            SELECT ooag011 INTO lr_tmp.nmbc003_desc FROM ooag_t
            WHERE ooagent=g_enterprise AND ooag001 = lr_tmp.nmbc003
          ELSE          
            LET lr_tmp.nmbc003_desc = s_desc_get_trading_partner_full_desc(lr_tmp.nmbc003)
         END IF 
       END IF
       #新增摘要 
       IF cl_null(lr_tmp.nmbcud001) THEN 
         #1.包括其他收支单作业anmt310,客户收款单作业anmt540,抓取的是表nmbb_t,抓取的栏位是nmbb025,
         #如果抓取不到则再去到下一项 
          LET l_nmbb025=‘‘
          LET l_apde010=‘‘
          LET l_nmck042=‘‘
          LET l_nmcq006=‘‘
          LET l_nmch006=‘‘
          SELECT nmbb025 INTO l_nmbb025 FROM nmbb_t 
           WHERE nmbbent=g_enterprise
             AND nmbbdocno=lr_tmp.nmbcdocno
             AND nmbbseq=lr_tmp.nmbcseq
          IF cl_null(l_nmbb025) THEN            
             #2.应付单aapt330,aapt331,aapt310,aapt301,都是应付单,抓取的表都是apde_t,
             #抓取的栏位都是apde010,如果抓取不到则再去到下一项
             SELECT apde010 INTO l_apde010 FROM apde_t
              WHERE apdeent=g_enterprise
                AND apdedocno=lr_tmp.nmbcdocno
                AND apdeseq=lr_tmp.nmbcseq            
             IF cl_null(l_apde010) THEN
                #汇款单anmt460,抓取表nmck_t,抓取的栏位是nmck042,如果抓取不到则再去到下一项
                SELECT nmck042 INTO l_nmck042 FROM nmck_t
                 WHERE nmckent=g_enterprise
                   AND nmckdocno=lr_tmp.nmbcdocno
                IF cl_null(l_nmck042) THEN
                  #4.应收票据兑现单,抓取表nmcq_t,抓取栏位是nmcq006,如果抓取不到则再去到下一项
                  SELECT nmcq006 INTO l_nmcq006 FROM nmcq_t
                   WHERE nmcqent=g_enterprise
                     AND nmcqdocno=lr_tmp.nmbcdocno
                     IF cl_null(l_nmcq006) THEN
                        #5.应付票据兑现单,抓取表nmch_t,抓取栏位是nmch006
                        SELECT nmch006 INTO l_nmch006 FROM nmch_t
                         WHERE nmchent=g_enterprise
                           AND nmchdocno=lr_tmp.nmbcdocno
                        LET lr_tmp.nmbcud001=l_nmch006
                     ELSE
                        LET lr_tmp.nmbcud001=l_nmcq006
                     END IF 
                ELSE
                   LET lr_tmp.nmbcud001=l_nmck042
                END IF 
             ELSE
                LET lr_tmp.nmbcud001=l_apde010
             END IF 
             
          ELSE
            LET lr_tmp.nmbcud001=l_nmbb025
          END IF 
       END IF        
       
       #170406-00001#1
       #INSERT INTO cnmq001_tmp VALUES(lr_tmp.*)
       EXECUTE cnmq001_ins_tmp2 USING lr_tmp.*
       
   END FOREACH

END FUNCTION

 

以上是关于TIPTOP之分割split函数方法getIndexOfsubString等临时表创建;的主要内容,如果未能解决你的问题,请参考以下文章

模拟java的split函数,分割字符串,类似于java的split方法

Python 字符串分割的方法

python split分割次数

Python split()方法分割字符串

Python字符串分割方法总结

Python中的split()函数的使用方法