2016-05-16 2 views
0

Programme: Il s'agit d'un programme de maintenance simple, dans lequel il affiche le code d'article dans une trame et invite l'entrée. Si vous entrez le code de l'article, il doit afficher les champs vides pour cet enregistrement dans pt_mstr et afficher dans une image (pas besoin d'afficher tous les champs vides, seulement 4 ou 5 premiers champs suffisent). et aussi dans ce cadre seulement si l'utilisateur veut le mettre à jour directement à la table principale pt_mstr. Qu'est-ce que j'ai essayé est, je viens d'écrire le code pour obtenir des champs vierges en utilisant tampon gérer et après que je crée une table temporaire et l'affichage des champs, je suis tombé là, je suis incapable de mettre à jour les champs.Comment obtenir dynamiquement le nom du champ et le mettre à jour dans la table principale en cours

Mon code:

/*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. 

Répondre

0

Êtes-vous sûr besoin de vos temp-tables pour le faire? J'ai créé un exemple en utilisant uniquement la table réelle (mais j'ai créé une fausse table temporaire à la place). Vous devrez examiner le traitement des erreurs de données, la validation des données, la transaction, le verrouillage, etc. avant de mettre cela en production bien sûr.

/*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. 
+0

Salut @Jensd, avez-vous bien compris? Si j'entre le code d'article, il cherchera pt_mstr pour cet item et affichera quels sont les champs vides pour cet enregistrement et là même si nous le mettons à jour, cela affectera pt_mstr. –

+0

@LovelyBobby Je dirais que mon exemple le fait - sans appariement dynamique de champs (qui pourrait être ajouté bien sûr). – Jensd

+0

Est-ce impossible avec la correspondance dynamique des champs? bcz votre solution je ne peux pas utiliser dans mon code, allez-vous sugget me meilleure solution pour mon problème –