Stack Exchange
How to provide structure parameter as import in Bapi call with Cloud SDK v3
I am using BAPI BAPI_PR_CREATE on S4HANA on-premise system to create purchase requisition with Cloud SDK v3.
The parameters to create purchase requisition are as below based on BAPI documentation.
Parameter: PRHEADER

PR_TYPE = NB 

Parameter: PRHEADERX

PR_TYPE = X

Parameter: PRITEM

PREQ_ITEM = 00010

PUR_GROUP = 001

MATERIAL = 100-100

PLANT = 1000

QUANTITY = 5.000

Parameter: PRITEMX

PREQ_ITEM = 00010

PREQ_ITEMX = X

PUR_GROUP = X

MATERIAL = X

PLANT = X

QUANTITY = X

The following are my java code. The type of export parameter PRHEADER and PRHEADERX are structure. Could you provide how to construct the object PRHEADER and PRHEADERX?
final BapiRequest bapiCreate = new BapiRequest("BAPI_PR_CREATE")
                                        .withExporting("PRHEADER", "BAPIMEREQHEADER", ????)
                                        .withExporting("PRHEADERX", "BAPIMEREQHEADERX", ????)
                                        .withImporting("NUMBER", "BAPIMEREQHEADER-PREQ_NO")
                                        .withTableAsReturn("BAPIRET2");

        // PR Item table
        bapiCreate.withTable("PRITEM", "BAPIMEREQITEMIMP")
                  .row()
                  // PR Item
                  .field("PREQ_ITEM", "BNFPO", "00010")
                  // Purchase Group
                  .field("PUR_GROUP", "EKGRP", "***")
                  // Material
                  .field("MATERIAL", "MATNR18", "***")
                  // Plant 
                  .field("PLANT", "EWERK", "***")
                  // Requested quantity
                  .field("QUANTITY", "BAMNG", "***")
                  .end();

        // PR ItemX table
        bapiCreate.withTable("PRITEMX", "BAPIMEREQITEMX")
                  .row()
                  // PR Item
                  .field("PREQ_ITEM", "BNFPO", "00010")
                  // PR ItemX
                  .field("PREQ_ITEMX", "BAPIUPDATE", "X")
                  // Purchase Group
                  .field("PUR_GROUP", "BAPIUPDATE", "X")
                  // Material
                  .field("MATERIAL", "BAPIUPDATE", "X")
                  // Plant 
                  .field("PLANT", "BAPIUPDATE", "X")
                  // Requested quantity
                  .field("QUANTITY", "BAPIUPDATE", "X")
                  .end();

Update
I need to use method "withExportingFields" to construct data with type "Structure".
final BapiRequest bapiCreate = new BapiRequest("BAPI_PR_CREATE")
                                        .withExportingFields("PRHEADER", "BAPIMEREQHEADER")
                                        .field("PR_TYPE", "BANFN", "NB")
                                        .end();

        bapiCreate.withExportingFields("PRHEADERX", "BAPIMEREQHEADERX")
                  .field("PR_TYPE", "BAPIUPDATE", "X")
                  .end();


I think you can treat "Structures" similar to "Tables", e.g.
bapiCreate.withExportingFields("PRHEADER", "BAPIMEREQHEADER")
.row()
.field("columnName1", "dataType1", "value1")
.field("columnName2", "dataType2", "value2")
.end();

(Updated withExportingTable to withExportingFields, due to feedback)

Thank you. But I got an exception "Cannot convert field PRHEADER of type STRUCTURE to TableRecord". Seems "PRHEADER" is not type Table.

The answer is withExportingFields. Thank you Alexander. I should look into cloud sdk java documentation.
