Skip to Content
Author's profile photo Former Member

Interesting use of Global Variables

I had a situation where I had an IDoc coming from R3 with information.  The IDoc contained 1 Header information segment and then multiple Line information segments.  Previously the customer required me to send through 1 file containing 1 header line and then multiple line item lines.  The output file is created using the File Adaptor.  After being live with this scenario for about 1 month, the customer changed his system and then required me to create a new file for every line item.  This meant having to replicate the header line information for every item line.  I had the option of going back into R3 and changing my IDoc (as this was a custom IDoc), but I decided instead to try using global variables.  So here is my scenario:  For every ZOEM_ASN_LINES from my source message, I needed to create a new File in my target message.  This means that I would have to replicate the values in ZOEM_ASN_HEADER into CRORDH. image So looking at this, you’re probably thinking why not use the CopyValue function together with the RemoveContexts function or collapseContexts function?  Yip, tried this but the contexts of the source file and the target file are really different because of what I am trying to do here.  The standard functions work for the first file created for 1 iteration of ZOEM_ASN_LINES.  But by the time that the second file needs to be created, it has already moved away and forgotten the values needed to populate CRORDH.  So here is what I did:  I created global variables for each of the values to be populated in the CRORDH section. image I then created a simple Set User-Defined Function to populate the global variables: image And then a simple Get User-Defined Function to retrieve the value of the global variables: image And now I used graphical mapping to create my multiple files: image Basically what is happening in the mapping above is the following: I have a counter to count how many iterations I have.  My counter checks whether this is the first iteration.  This I do with using the equalsA function.  If it is the first iteration, I get the value of CONTRACT_NUMBER and then map it to my Set UDF.  The second time that the iteration occurs, the counter value is no longer 1 and therefore it calls the Get UDF to populate the target element.  This way my CRORDH section of my target message is always populated in all the files and I do not have to change my IDoc from R3.

Assigned Tags

      1 Comment
      You must be Logged on to comment or reply to a post.
      Author's profile photo Former Member
      Former Member
      HI Miguel,

      Nice blog , definitely handy, however is there another way of getting the global variable besides using java user-defined functions...some menu shortkey?