如何动态获取字段名称并将其更新为正在进行的主表

时间:2016-05-16 08:54:14

标签: progress-4gl openedge

程序:这是一个公正的维护程序,在这个程序中,它在一个框架中显示项目代码,并提示输入。如果输入项目代码,则必须在pt_mstr中显示该记录的空白字段,并在一帧中显示(无需显示所有空白字段,只需显示前4或5个字段)。并且仅在用户想要更新时才在该帧中直接更新到主表pt_mstr。

我尝试的是,我只是编写了使用缓冲区句柄获取空白字段的代码,之后我创建了一个临时表并显示了字段,我自己来了,我无法更新字段。

我的代码:

/*Sample Item master Maintenance Program*/
/* DISPLAY TITLE */ 
{us/mf/mfdtitle.i "3+ "} 
DEFINE VARIABLE hBuffer AS HANDLE NO-UNDO.
DEFINE VARIABLE i       AS INTEGER NO-UNDO. 
DEFINE VARIABLE j       AS INTEGER NO-UNDO.
DEFINE VARIABLE hField  AS HANDLE NO-UNDO.
define variable fldnm as character extent 10 no-undo.
define temp-table tt_temp no-undo
   field tt_part like pt_part
   field field1 as char extent 10. 
form
    pt_part colon 25
    with frame a side-labels width 80.
    setFrameLabels(frame a:handle).
/* DISPLAY */
view frame a.
repeat with frame a:
   prompt-for pt_part
      editing:
   /* FIND NEXT/PREVIOUS RECORD */
     {us/mf/mfnp.i pt_mstr pt_part "pt_mstr.pt_domain = global_domain and pt_part" pt_part pt_part pt_part }
     if recno <> ? then
          do:
display pt_part.
             find pt_mstr where pt_part = input pt_part and pt_domain=global_domain no-lock no-error.
               ASSIGN hBuffer = BUFFER pt_mstr:HANDLE.
               empty temp-table tt_temp.
               j = 1.
               DO i = 1 TO 10:
                ASSIGN hField = hBuffer:BUFFER-FIELD(i).                                                                            
                    IF ((hField:BUFFER-VALUE = "" )) THEN                          
                          do:        
                            /*  message  hField:NAME "test" view-as alert-box.*/
                            find first tt_temp where tt_part = pt_part no-lock no-error.
                             if not avail tt_temp then
                               do:
                                create tt_temp.
                                assign
                                tt_part = pt_part
                                field1[j] = hField:NAME.
                                j = j + 1.
                               end. 
else do:
                    assign
                       field1[j] = hField:NAME.
                       j = j + 1.
                 end.
            end.
                     end.
          end.
               for  each tt_temp:
                display field1[1] field1[2] field1[3] field1[4].
                end.
    end.                                                                                                                                    
end.   

1 个答案:

答案 0 :(得分:1)

您确定需要临时表来执行此操作吗?我创建了一个仅使用实际表的示例(但创建了一个假的临时表)。在将其投入生产之前,您必须先研究数据错误处理,数据验证,事务,锁定等。

/*First we need some fake data */
DEFINE TEMP-TABLE ttMockedData NO-UNDO
    FIELD id AS INTEGER
    FIELD dataName         AS CHARACTER FORMAT "x(8)"
    FIELD dataType         AS CHARACTER FORMAT "x(8)"
    FIELD dataDescrioption AS CHARACTER FORMAT "x(32)".

DEFINE VARIABLE iId     AS INTEGER     NO-UNDO.
DEFINE VARIABLE iSearch AS INTEGER NO-UNDO LABEL "Search".

PROCEDURE createData:
    DEFINE INPUT  PARAMETER pcName AS CHARACTER   NO-UNDO.
    DEFINE INPUT  PARAMETER pcType AS CHARACTER   NO-UNDO.
    DEFINE INPUT  PARAMETER pcDesc AS CHARACTER   NO-UNDO.

    iId = iId + 1.

    CREATE ttMockedData.
    ASSIGN 
        ttMockedData.id       = iId
        ttMockedData.dataName = pcName
        ttMockedData.dataType = pcType
        ttMockedData.dataDesc = pcDesc.

END PROCEDURE.

RUN createData("Test 1", "TESTTYPE", "A TEST").
RUN createData("Test 2", "", "ANOTHER TEST").
RUN createData("", "TESTTYPE 2", "").
RUN createData("4", "", "").

/* Program starts here */
updating:
REPEAT:

    UPDATE iSearch WITH FRAME x0.
    IF iSearch > 0 THEN DO:
        FIND FIRST ttMockedData NO-LOCK WHERE ttMockedData.id = iSearch NO-ERROR.
        IF NOT AVAILABLE ttMockedData THEN DO:
            MESSAGE "Not found" VIEW-AS ALERT-BOX ERROR.
            RETURN ERROR.
        END.
        ELSE DO:

            DISP ttMockedData WITH FRAME x1 1 COLUMNS SIDE-LABELS.

            /* Is there an empty field? - Then we update! */
            IF ttMockedData.dataName         = ""
            OR ttMockedData.dataType         = ""
            OR ttMockedData.dataDescrioption = "" THEN DO:

                DISPLAY
                    ttMockedData.dataName 
                    ttMockedData.DataType 
                    ttMockedData.dataDesc 
                    WITH FRAME x2 1 COLUMN SIDE-LABELS TITLE "Complete the data...". 

                /* This isn't working with temp-tables of course! */
                /* Just here to make sure you handle locking! */
                FIND CURRENT ttMockedData EXCLUSIVE-LOCK.

                UPDATE                                                               
                    ttMockedData.dataName WHEN ttMockedData.dataName = ""            
                    ttMockedData.DataType WHEN ttMockedData.DataType = ""            
                    ttMockedData.dataDesc WHEN ttMockedData.dataDesc = ""            
                    WITH FRAME x2.

                /* This isn't working with temp-tables of course! */
                /* Just here to make sure you handle locking! */
                FIND CURRENT ttMockedData NO-LOCK.
            END.


        END.
    END.
    ELSE LEAVE updating.
END.