You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ABL技术咨询:将单数字后缀作业编号补零后写入UD字段

Fixing Sequence Number Formatting in ABL (Adding Leading Zeros to Suffixes 0-9)

Hey there! As someone new to ABL, I get how tricky these string manipulation tasks can feel at first. Let's walk through exactly how to convert those single-digit suffixes (like -0, -5) to two-digit format (-00, -05) and write the result to your UD field.

Step-by-Step Approach

The core idea is to split the job number into its prefix and suffix parts, format the suffix to always be two digits, then recombine them and update your UD field.

Working ABL Code Example

Here's a practical implementation you can adapt to your database table:

-- Define variables to hold our values
DEFINE VARIABLE cOriginalJobNum AS CHARACTER NO-UNDO.
DEFINE VARIABLE cPrefix AS CHARACTER NO-UNDO.
DEFINE VARIABLE iSuffix AS INTEGER NO-UNDO.
DEFINE VARIABLE cFormattedJobNum AS CHARACTER NO-UNDO.

-- Example input (replace this with your actual field value from the database)
cOriginalJobNum = "99999-0".

-- Split the job number into prefix and suffix parts
cPrefix = SUBSTRING(cOriginalJobNum, 1, INDEX(cOriginalJobNum, "-") - 1).
iSuffix = INTEGER(SUBSTRING(cOriginalJobNum, INDEX(cOriginalJobNum, "-") + 1)).

-- Format the suffix to 2 digits (automatically adds leading zero for values 0-9)
cFormattedJobNum = cPrefix + "-" + STRING(iSuffix, "99").

-- Write the formatted number to your UD field
-- Replace "YourTable" with your actual table name, and adjust the WHERE clause to target the right record
FOR EACH YourTable WHERE YourTable.JobNum = cOriginalJobNum EXCLUSIVE-LOCK:
    ASSIGN YourTable.UDField = cFormattedJobNum.
END.

Key Explanations

  • Splitting the Job Number: We use INDEX() to find the position of the - character, then SUBSTRING() to pull out the prefix (everything before -) and the suffix (everything after).
  • Formatting the Suffix: The STRING(iSuffix, "99") function converts the integer suffix to a string with exactly two digits—so 0 becomes 00, 9 becomes 09, and values like 10 or 150 stay as-is.
  • Updating the UD Field: The FOR EACH loop locks the record (to avoid conflicts) and uses ASSIGN to set the UD field to our formatted job number.

Optional: Add Error Handling

If you want to handle edge cases (like job numbers without a -), you can add a quick check:

IF INDEX(cOriginalJobNum, "-") > 0 THEN DO:
    -- Run the splitting/formatting logic here
END.
ELSE DO:
    -- Handle invalid job number format (log a message or skip the record)
    MESSAGE "Invalid job number format: " cOriginalJobNum VIEW-AS ALERT-BOX.
END.

This should solve your problem perfectly—just tweak the table and field names to match your setup!

内容的提问来源于stack exchange,提问作者Chris Simpson

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.27 10:04:20