• Introducing Dark Mode! Switch by clicking on the lightbulb icon next to Search or by clicking on Default style at the bottom left of the page!

Generic Function - Media Object Copy

jdecoder

Well Known Member
Simple Question : Can we make a Generic function to copy media object from any GT to same or different GT using C or any other method ?

E812
DB2/AS400
BSSV on Websphere/Jdev 10g
that's about it....
 

BOster

Legendary Poster
Strictly speaking, yes you can. There are a bunch of C Media Object APIs that take the key as a string (including the API listed below that straight up copies media objects from one GT struct/key to another), however, this would require the caller to correctly format the key string(s) for source and destination which could be a little bit of a pain for the caller.

<font class="small">Code:</font><hr /><pre>
KRNL_RTN(JDEDB_RESULT) JDEWINAPI JDEGTCopyF00165WithKeyStr(
PJSTR szFromObjName,
PJSTR pszFromGTKey,
int nFromSeq, MOTYPE nMOType,
PJSTR szToObjName,
PJSTR pszToGTKey);
</pre><hr />



If it were me, I might be inclined to create the copy routine as a private subroutine that uses:

<font class="small">Code:</font><hr /><pre>
KRNL_RTN(JDEDB_RESULT) JDEWINAPI JDEGTCopyF00165(
PJSTR szFromObjName,
LPVOID pFromMODSKey,
int nFromSeq, MOTYPE nMOType,
PJSTR szToObjName,
LPVOID pToMODSKey);
</pre><hr />


and then add public Functions for each individual case that take the actual data elements of the of the key to hide all that from the caller (the code for each of these public functions would be small and trivial). Example public function sig:

<font class="small">Code:</font><hr /><pre>
CopyMOSalesOrderToPurchaseOrder
szSoOrderCompany
szSoOrderType
mnSoOrderNumber
szPoOrderCompany
szPoOrderType
mnPoOrderNumber
</pre><hr />

In this way, you let JDE handle creating the Key String from the GT data structure instead of having to manually create it yourself and risk errors. Honestly, once the first Public function is created, creating additional ones would be pretty easy, someone that doesn't even know C could probably figure out how to copy code from an existing public Function to a new one.
 

Gov

VIP Member
[ QUOTE ]
Honestly, once the first Public function is created, creating additional ones would be pretty easy, someone that doesn't even know C could probably figure out how to copy code from an existing public Function to a new one.

[/ QUOTE ] 100% true

If you are not comfortable in creating a C Function, then have a look at this function - BD3N0011. This DcLink function has 2 functions. first one to retrieve text of GT and other to write to new GT. you can loop them to execute functionality of Copy. If you have more than one 1 MO Text for each GT|TXKY combination; then it is better to program a C Function to execute irrespective of MOSEQN.

P.S. this dc-link function suggested works only with text MO's.
 

jdecoder

Well Known Member
Thank you for the reply. I Did find APIs like JDEGTAllocFetch() and JDEGTAdd() etc...

I was working with APIs like CopyGenericTextName() where GT Data structure was input and hence cannot be dynamic (lpdsGTxyz had to be defined in the code). Also they we clearing the existing Media Objects.

Now... i dont know why but my JDEGTAllocFetch() is not working it does not return me anything. and this API is not used much in standard (just in B9100010.c). Not sure if this is a server only thing or if its my mistake.


My Code :

PJSTR pStringKey = NULL;
DSABGT dsAbGT = {0};
LPF0016D lpDetail = NULL;
JDEDB_RESULT JDBReturn = JDEDB_PASSED;
BOOL bMOExist = FALSE;

ParseNumericString(&dsAbGT.mnAddressNumber, _J("5752"));
pStringKey = AllocBuildStrFromDstmplName(NULL, _J("ABGT"), &dsAbGT);
pStringKey = StripKey (pStringKey);


bMOExist = JDEGTExists(lpBhvrCom->hEnv, (PCJSTR)_J("ABGT"),
(PCJSTR)pStringKey, (PCJSTR)" ");

if (!bMOExist)
{
FreeBuildStrFromDstmplName(pStringKey);
return ER_ERROR;
}

idGTFetch = JDEGTAllocFetch (lpBhvrCom->hEnv, (PCJSTR) pObjectName,(PCJSTR)pStringKey, (PCJSTR) " ", &lpDetail);



if (JDBReturn != JDEDB_PASSED)
{
//JDBReturn = JDEGTAdd( lpBhvrCom->hEnv, lpDetail, (LPDBREF)NULL);
}

JDEGTFree ((LPF9860)NULL, lpDetail);
FreeBuildStrFromDstmplName(pStringKey);
 

BOster

Legendary Poster
By the time you get to a 8.x tools release there are a TON of media object API calls - many of which more or less do the same thing. However for your situation, I would really look into using JDEGTCopyF00165WithKeyStr or JDEGTCopyF00165. Could potentially save you a bunch of code since they do pretty much what you want. I have used them in the past and they appear to work just fine.
 

jdecoder

Well Known Member
JDEGTCopyF00165WithKeyStr() worked exactly the way i wanted it...
Thanks a lot Brian. I Appreciate your help on this.

Thanks & Regards,
Suraj
 
Top