Post multiple lines of Inventory adjustment journal via code

Hi there ,

I am able to post one line in journal but when there multiple lines in the journal, I am unable to post

Please HELP

static void Posting3(Args _args)

{
InventJournalTable inventJournalTable;
InventJournalTrans inventJournalTrans;
InventJournalNameId inventJournalName;
InventDim inventDim;
InventJournalId inventJournalId;
JournalCheckPost journalCheckPost;

//Below code creates journal header
inventJournalTable.clear();
inventJournalName = ‘IPL’;
inventJournalTable.initFromInventJournalName(InventJournalName::find(inventJournalName));
inventJournalTable.insert();

//Below code creates journal lines
while select * from inventJournalTable
where inventJournalTable.Posted == 0 &&
inventJournalTable.NumOfLines!=0
if(inventJournalTable.RecId)
{
inventJournalId = inventJournalTable.JournalId;
inventJournalTrans.clear();
inventJournalTrans.initFromInventJournalTable(inventJournalTable);
inventJournalTrans.TransDate = systemDateGet();
select firstOnly * from inventJournalTrans
where inventjournaltrans.JournalId == inventJournalId;
inventJournalTrans.ItemId = inventJournalTrans.ItemId;
inventJournalTrans.initFromInventTable(InventTable::find(inventJournalTrans.ItemId));
inventJournalTrans.Qty = inventJournalTrans.Qty;
inventDim.InventSiteId = ‘XXX’;
inventDim.InventLocationId = ‘XXX’;
inventJournalTrans.InventDimId = inventDim::findOrCreate(inventDim).inventDimId;
inventJournalTrans.Voucher = ‘XXXX’;
inventJournalTrans.insert();
}

//The below code posts the journal
journalCheckPost = InventJournalCheckPost::newPostJournal(inventJournalTable);
journalCheckPost.run();

}

where does the while loop starts and ends? Why you are using that while loop? Please explain.

Can you use insert code option in the forum to show the code?

Moving to developer forum.