cancel
Showing results for 
Search instead for 
Did you mean: 

Writing table line items to RFC parameter recursively in Personas

eedens
Participant
0 Kudos
396

I've seen a lot of "How to read tables" for Personas, but I'm running into the issue of writing the copied table data to an RFC.

Here's the RFC call:

var oRFC = session.createRFC("ZFI_ICWQITEMS");
oRFC.setParameter("GUID", "");
oRFC.setParameter("SOIN_ID", "");
oRFC.setParameter("LINE_ITEMS", [
 {
 MANDT: "",
 GUID: "",
 SOIN_ID: "",
 TAB: "",
 RBLGP: "000000",
 WRBTR: 0,
 MENGE: 0,
 EBELN: "0000000000",
 EBELP: "00000",
 MATNR: "",
 TXZ01: "",
 SAKNR: "0000000000",
 AUFNR: "000000000000",
 KOSTL: "0000000000",
 PRCTR: "0000000000",
 HKONT: "0000000000",
 SHKZG: "",
 MWSKZ: "",
 TXJCD: "",
 SGTXT: "",
 BUKRS: "",
 FKBER: ""
 }
]);
oRFC.requestResults(["LINE_ITEMS"]);
oRFC.send();
var _LINE_ITEMS = oRFC.getResultObject("LINE_ITEMS");

What I'm trying to do is scraping the PO/GL tables in MIRO, and dumping it into the LINE_ITEMS field, while only calling the oRFC.send function once (The table is wiped each time it is updated). I've tried a few different methods:

looping through the table, collecting the results, and pushing them into an array;

creating a JSON string that I turn into an object with JSON.parse();

scraping the table and assigning the parameters in a for loop;

One Example

/* Simplified version, I know this is missing variables, it's just to give an idea of where I've been going with this*/

//Create Array
var allStored = [];  
// create RFC
var uRFC = session.createRFC("ZFI_ICWQUPDATE");
//Add PO Table to allStored array
allStored.push(po_table_Copy);
//Add GL Table to allStored Array
allStored.push(glTableCopy);
//All Stored Array.i length = tab layer
for (var i = 0; i <= allStored.length - 1; i++) {
  //All Stored Array.i.b = line layer
    for (var b = 0; b <= allStored[i].length - 1; b++) {
      //start storing the array.i.b.values 
        uRFC.setParameter("LINE_ITEMS", [
          {
            MANDT: allStored[i][b]['DRSEG-MANDT'] = "120",
            GUID: allStored[i][b]['DRSEG-GUID'] = rgId,
            SOIN_ID: allStored[i][b]['DRSEG-SOIN'] = rsId,
            TAB: allStored[i][b] = i,
            RBLGP: pad("000000", allStored[i][b]['DRSEG-RBLGP'], true),
            WRBTR: allStored[i][b]['DRSEG-WRBTR'],
            MENGE: allStored[i][b]['DRSEG-MENGE'],      
            KOSTL: pad("0000000000", allStored[i][b]['ACGL_ITEM-KOSTL'], true),
            HKONT: pad("0000000000", allStored[i][b]['ACGL_ITEM-HKONT'], true),
            SHKZG: allStored[i][b]['ACGL_ITEM-SHKZG'],
            MWSKZ: allStored[i][b]['ACGL_ITEM-MWSKZ'],
            TXJCD: allStored[i][b]['ACGL_ITEM-TXJCD'],
            SGTXT: allStored[i][b]['ACGL_ITEM-SGTXT'],
            BUKRS: allStored[i][b]['ACGL_ITEM-BUKRS'],
            FKBER: allStored[i][b]['ACGL_ITEM-FKBER']          
          }
        ]);
    }
  }
//RFC Away
uRFC.send();

The closest I think I have been is with this method:

Invoke RFC Function Module to Transfer Contents to the Backend

/* removed variables and actions for readability */


allStored.push(po_table_Copy);
allStored.push(glTableCopy);

var parameters = "[";
var uRFC = session.createRFC("ZFI_ICWQLINEUPDATE");

try {
  for (var i = 0; i <= allStored.length - 1; i++) {
    for (var b = 0; b <= allStored[i].length - 1; b++) {
      //console.log(allStored[i][b]);
      parameters +=
        '{"MANDT":"120"' +
        ',"GUID":"' +
        rgId +
        '","SOIN_ID":"' +
        rsId +
        '","TAB":"' +
        i +
        `","RBLGP":"` +
        pad("000000", allStored[i][b]["DRSEG-RBLGP"], true) +
        '","WRBTR":"' +
        allStored[i][b]["DRSEG-WRBTR"] +
        '","MENGE":"' +
        allStored[i][b]["DRSEG-MENGE"] +
        '","KOSTL":"' +
        pad("0000000000", allStored[i][b]["ACGL_ITEM-KOSTL"], true) +
        '","HKONT":"' +
        pad("0000000000", allStored[i][b]["ACGL_ITEM-HKONT"], true) +
        '","SHKZG":"' +
        allStored[i][b]["ACGL_ITEM-SHKZG"] +
        '","MWSKZ":"' +
        allStored[i][b]["ACGL_ITEM-MWSKZ"] +
        '","TXJCD":"' +
        allStored[i][b]["ACGL_ITEM-TXJCD"] +
        '","SGTXT":"' +
        allStored[i][b]["ACGL_ITEM-SGTXT"] +
        '","BUKRS":"' +
        allStored[i][b]["ACGL_ITEM-BUKRS"] +
        '","FKBER":"' +
        allStored[i][b]["ACGL_ITEM-FKBER"] +
        '"},';
    }
  }
    // Removing the additional comma.
  var finPa = parameters.slice(0, -1);
  finPa += "]";
  var objectifySt = JSON.parse(finPa);
  for (i = 0; i < objectifySt.length; i++) {
    uRFC.setParameter("LINE_ITEM", objectifySt[i]);
    uRFC.send();
  }
} catch (oError) {
  console.log(oError);
}
function pad(pad, str, padLeft) {
  if (typeof str === "undefined") return pad;
  if (padLeft) {
    return (pad + str).slice(-pad.length);
  } else {
    return (str + pad).substring(0, pad.length);
  }
}

Anyone else ever ran into something like this?

Accepted Solutions (0)

Answers (0)