บทที่ 5 / 8

การอ่านรายละเอียด COA (Details)

การ JOIN ตาราง การจัดรูปแบบข้อมูล

5 / 8
1

การดึงรายละเอียดจากตาราง COA Detail

หลังจากได้ข้อมูล Header แล้ว จะดึงรายละเอียดการทดสอบจากตาราง sccoa004 พร้อม JOIN กับ qmptc001

การอ่าน COA Detail Records
    select  sccoa004.*, qmptc001.*
    from    sccoa004 JOIN qmptc001 ON qmptc001.char = sccoa004.char
    where   sccoa004.coan = {:sccoa003.coan}         
    order by sccoa004.prts
    selectdo
        rpt.seq = rpt.seq + 1
        row.count = row.count + 1
        rpt.storage = trim$(sccoa003.cwar) & "/" & trim$(sccoa003.loca)
        rpt.mfg.date = sprintf$("%D(%02d/%02m/%04Y)", 
                       convert.utc.to.date(sccoa003.mfgd))
        
        if sccoa003.expd > 0 then 
            rpt.exp.date = sprintf$("%D(%02d/%02m/%04Y)", 
                           convert.utc.to.date(sccoa003.expd))
        else
            rpt.exp.date = ""
        endif
        
        bp.name = trim$(sccoa003.stbp) & "  " & 
                  strip$(tccom130.ln01) & " " & strip$(tccom130.ln02) 
        item.dsca = trim$(sccoa003.item) & "  " & strip$(tcibd001.dsca)
        rpt.char.desc = qmptc001.dsca
    endselect
คำอธิบาย

สิ่งที่เกิดขึ้นในลูป:

  1. JOIN ตาราง sccoa004 (Detail) กับ qmptc001 (Characteristic) ด้วยฟิลด์ char
  2. นับลำดับ (rpt.seq) และ นับแถว (row.count)
  3. จัดรูปแบบวันที่ — แปลงจาก UTC เป็นรูปแบบ DD/MM/YYYY
  4. สร้างข้อความ — รวม item code + description, BP code + name
ฟังก์ชันจัดการ String
  • trim$() — ตัดช่องว่างหน้าหลัง
  • strip$() — ตัดช่องว่างท้ายสตริง
  • & — ต่อสตริง (concatenate)
  • sprintf$() — จัดรูปแบบข้อความ
2

การจัดการค่าผลทดสอบ (Result Formatting)

ค่าผลทดสอบถูกจัดรูปแบบแตกต่างกันตามชนิดของ Characteristic

การจัดรูปแบบผลทดสอบ
    if qmptc001.ctyp = qmptc.ctyp.option then
        | Option Type → ดึงคำอธิบายจากตารางตัวเลือก
        select  qmptc014.*
        from    qmptc014
        where   qmptc014.oset = {:sccoa004.oset} 
                and qmptc014.optn = {:sccoa004.mopt}
        selectdo
            rpt.result = qmptc014.dsca
        endselect
        
    else
        if qmptc001.ctyp = qmptc.ctyp.fraction then
            | Fraction Type → แสดงเป็นทศนิยม
            if trim$(sccoa004.char) = "SP_GRAV2" 
               or trim$(sccoa004.char) = "RE_DEN25" then
                rpt.result = edit$(sccoa004.mval, "ZZZZZZ9VD9999")
            else
                rpt.result = edit$(sccoa004.mval, "ZZZZZZZZ9VD99")
            endif
            
        else
            if qmptc001.ctyp = qmptc.ctyp.integer then
                | Integer Type → แสดงเป็นจำนวนเต็ม
                rpt.result = edit$(sccoa004.mval, "ZZZZZZZZZZZ9")
            endif
        endif
    endif
คำอธิบาย

Characteristic Type มี 3 ประเภทหลัก:

ประเภทตัวอย่างรูปแบบ
Optionสี, กลิ่นดึงคำอธิบายจาก qmptc014
FractionSpecific Gravity, Refractive Index9VD9999 (ทศนิยม 4 ตำแหน่ง)
IntegerColor Value9 (จำนวนเต็ม)
edit$() Format Mask
  • Z — แสดงช่องว่างแทนศูนย์นำหน้า
  • 9 — แสดงตัวเลข (รวมศูนย์)
  • VD — จุดทศนิยม (Virtual Decimal)

เช่น "ZZZ9VD9999"0.9234