Return array of struct from a solidity function: "Expected type name function getPurchaseOrderForVendor" error

+1 vote

I have written the following code to return an array of struct from the function getPurchaseOrderForVendor

pragma solidity ^0.4.21;
pragma experimental ABIEncoderV2;

contract InvoiceSettlement {

struct PurchaseOrderStruct {

    uint8 requisitionNumber;
    uint8 poNumber;

}

PurchaseOrderStruct[10] public PurchaseOrderStructArray;


function InvoiceSettlement()
{
        for (uint i = 0; i < purchaseOrderLength; i++) {

                PurchaseOrderStructArray[i].requisitionNumber = 1;
                PurchaseOrderStructArray[i].poNumber = 1;

        }
}


function  getPurchaseOrderForVendor(string vendorNameInput) constant retu rns (struct[])
{


    struct[] memory y = new struct[](16);

    for (uint i = 0; i < purchaseOrderLength; i++)
    {
        y[i] = PurchaseOrderStructArray[i];
    }
    return (y);

}

}

When I compile the code, I get this error:

 invoiceSettlement.sol:44:80: ParserError: Expected type name function getPurchaseOrderForVendor(string vendorNameInput) constant ret urns (struct[]) ^
Oct 17, 2018 in Blockchain by sabby
• 4,350 points
826 views

1 answer to this question.

+1 vote
Best answer

There's a typo in your code. The proper code should look something like this:

function getPurchaseOrderForVendor(string vendorNameInput) constant returns (PurchaseOrderStruct[])
answered Oct 17, 2018 by Christine
• 15,790 points

selected May 2 by Omkar

Related Questions In Blockchain

0 votes
1 answer
0 votes
1 answer

Access multiple return values (a, b, c) from solidity function in web3js

You'll get an array of return values ...READ MORE

answered Sep 14, 2018 in Blockchain by slayer
• 29,170 points
302 views
0 votes
1 answer

Solidity: How can I return a list of user-defined function?

You can do it with something like ...READ MORE

answered Sep 26, 2018 in Blockchain by digger
• 26,550 points
58 views
0 votes
1 answer
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,790 points
155 views
0 votes
1 answer
0 votes
1 answer

Solidity geth: Error encountered during contract execution [Bad instruction]

recipes is a dynamic storage array. You need ...READ MORE

answered Oct 15, 2018 in Blockchain by Omkar
• 67,620 points
88 views
+4 votes
3 answers

What type of database is blockchain?

Blockchain is a distributed database. what makes ...READ MORE

answered Mar 29, 2018 in Blockchain by Christine
• 15,790 points
68 views
+1 vote
1 answer

I would like to create a blockchain network which will stay at the same level of complexity, is it possible?

You can very easily create a cryptocurrency having a ...READ MORE

answered Apr 4, 2018 in Blockchain by Christine
• 15,790 points
52 views