Suman Goswami Suman Goswami - 1 year ago 63
Java Question

how to handle string list when it is returned by any BAPI using jco3.jar?

I have a BAPI function to be called, which takes input a string and return a string list as output. I was using jco3.jar file in my java code but not able to find any inbuilt method which takes care of string list (String[]) as output parameter, though we have ByteArray/CharArray instead.

function.getExportParameterList().getString("I_DOCNUM"); // it will work if the return parameter - "I_DOCNUM" is of type String only, but not working for String List.

Please help me. Thanks in advance.

Java Code

JCoDestination destination = JCoDestinationManager.getDestination("mySAPSystem");
System.out.println("Attributes:");
System.out.println(destination.getAttributes());
System.out.println(destination.getRepository());
destination.ping();
JCoFunction function = destination.getRepository().getFunction("INBOUND_IDOCS_FOR_TID");
if(function == null)
throw new RuntimeException("INBOUND_IDOCS_FOR_TID not found in SAP.");
function.getImportParameterList().setValue("TID", "0A80351B1927589833E57997");

try
{
function.execute(destination);
}
catch(AbapException e)
{
System.out.println(e.toString());
return;
}

System.out.println("STFC_CONNECTION finished:");
System.out.println(" Echo: " + function.getExportParameterList().getString("I_DOCNUM"));





Function Module:-

INBOUND_IDOCS_FOR_TID.
*"----------------------------------------------------------------------
*"*"Lokale Schnittstelle:
*" IMPORTING
*" VALUE(TID) TYPE EDIDS-TID
*" CHANGING
*" VALUE(I_DOCNUM) TYPE IDOC_TT
*" EXCEPTIONS
*" NO_IDOC_FOUND
*"----------------------------------------------------------------------
data: wa_docnum like edidc-docnum.
select docnum from edids into wa_docnum
where ( status eq '50'
or status eq '56' )
and tid eq tid.
append wa_docnum to i_docnum.
endselect.
if sy-subrc ne 0.
raise no_idoc_found.
endif.
ENDFUNCTION.

Answer Source

IDOC_TT is a table type. So you can access this parameter with

JCoTable tabIDocnums = function.getChangingParameterList().getTable("I_DOCNUM");

Then loop through the rows of the table and access the single field value of each row with:

String strIDocNumber = tabIDocnums.getString("EDI_DOCNUM");

or a little bit better performing via index:

String strIDocNumber = tabIDocnums.getString(0);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download