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,370 points
5,132 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, 2019 by Omkar

Related Questions In Blockchain

0 votes
1 answer

Web3j v3.3.1 : Error while generating compiled solidity smart contracts which returns array of struct

Solidity does not support returning structs in ...READ MORE

answered Jun 19, 2018 in Blockchain by aryya
• 7,460 points
1,668 views
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,370 points
3,113 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,740 points
1,362 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
1,922 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,451 views
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
• 69,220 points
1,464 views
+4 votes
3 answers

What type of database is blockchain?

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

answered Mar 30, 2018 in Blockchain by Christine
• 15,790 points
1,316 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
847 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP