create a new record for temp-table

Posted by Admin on 10-Jul-2009 02:47

hi..i'm a newbie here..i'm trying to create a new record for temp-table..but it doesn't work..can anybody teach me how to do it?? this is my code..

DEF TEMP-TABLE ttOrder LIKE Order.

/* copy order table to ttOrder. */

FOR EACH order:

    CREATE ttOrder.

    BUFFER-COPY order TO ttOrder.

END.

/* create new record for ttOrder. */

CREATE ttOrder.

ASSIGN

    ttOrder.custnum = 12

    ttOrder.carrier = "Standard Mail"   

    ttOrder.CreditCard = "Visa"

    ttOrder.SalesRep = "BBB"  

    ttOrder.OrderStatus = "Ordered".

/* display ttOrder */

FOR EACH ttOrder:

    DISPLAY

        ttOrder.ordernum

        ttOrder.custnum .

        ttOrder.carrier

        ttOrder.CreditCard

        ttOrder.SalesRep

        ttOrder.OrderStatus./

END.

my problem is,how to create ordernum for ttOrder like ordernum in order table (generate by sequence)?? then how to make it save in ttOrder and original Order table??

thanks in advance..

All Replies

Posted by Thomas Mercer-Hursh on 10-Jul-2009 11:50

If you are creating a new order, then you need to create a new order in the same way that one is created anywhere else a new order is created.  This is specific to your application, not something about which there is a general solution.  It could be coming from a sequence or a number table or (hopefully not) by looking at the highest number in the table or some funny algorithm which depended on the order type or any number of other things.  Worst case, it would be assigned by a trigger when the order is stored, in which case you are going to have a problem.  But, bottom line, you need to figure out how it is done in your application and do the same.

Posted by lace28 on 22-Jul-2009 07:36

You need to figure out how ordernum is being generated when Order is created. A sequence would make sense.

You would need to assign the next sequence value to your temp-table record by doing next-value(SequenceName) first and then create a new Order record by doing a buffer-copy of your temp-table record.

This might be a problem if your order table has a trigger on it for the ordernum.

Olivier

Posted by EdoBar on 24-Jul-2009 12:57

If you already copy from Order to ttOrder, you will need to validate if ttOrder exists on Order when you create your new record, or you will duplicate records (or have warning).

For each ttOrder:

     Find Order where Order.ordernum = ttOrder.ordernum no-lock no-error.

     if available Order then next.

     Create Order.

     Buffer-Copy tt-Order to Order.

End.

*This is only if you want to create a record on this table, but you will need some validations and know other implications when you create orders.

But first, solve the secuence for ordernum.

Regards.

This thread is closed