cancel
Showing results for 
Search instead for 
Did you mean: 

How to concatenate value in Global Variable

Pyae_Phyo_Thwe
Explorer
0 Kudos
381

Pyae_Phyo_Thwe_0-1742466472452.pngPyae_Phyo_Thwe_1-1742466498123.pngPyae_Phyo_Thwe_2-1742466514220.pngPyae_Phyo_Thwe_3-1742466528196.png

Pyae_Phyo_Thwe_5-1742466886861.png

 

1. In data from Payment, I have below data get from Odata.

<A_OperationalAcctgDocItemCube>

<A_OperationalAcctgDocItemCubeType>

<FiscalYear>2025</FiscalYear>

<Customer>15100100</Customer>

<PostingDate>2025-02-06T00:00:00.000</PostingDate>

<AmountInTransactionCurrency>40000</AmountInTransactionCurrency>

<AccountingDocument>1800000006</AccountingDocument>

<DocumentDate>2025-02-08T00:00:00.000</DocumentDate>

<CompanyCode>1510</CompanyCode>

<AccountingDocumentItem>1</AccountingDocumentItem>

<TransactionCurrency>JPY</TransactionCurrency>

</A_OperationalAcctgDocItemCubeType>

</A_OperationalAcctgDocItemCube>

2. I use General Splitter for the result of data as I want to work with each record of "A_OperationalAcctgDocItemCubeType".

3. In Assign Invoice data, I get the AccountingDocument and AmountInTransactionCurrency and assign the value to the Property variable.

4. I call another odata by using the filter value of AccountingDocument get in step-3.

5. I use Write Variable to store the data.

6. I use Router and if there is data in Step-5, it will goes to next step and if no data, it will end.

7. I used Groovy script to update the Variable declared in Step-5. Below is my groovy script. I want to concatenate the InvoiceID used in step-5 with the InvoiceID get from Property.

import com.sap.gateway.ip.core.customdev.util.Message;

def Message processData(Message message) {

    def currentPartialID = message.getProperty("InvoiceID")

    def existingIDs = message.getProperty("PartialInvoiceID") ?: ""

    existingIDs = existingIDs.tokenize(',') // Convert string to list

    if (!existingIDs.contains(currentPartialID)) {

        existingIDs.add(currentPartialID) // Append only if new

    }

    message.setProperty("PartialInvoiceID", existingIDs.join(',')) // Convert list back to string

    return message;

}

 

But when I run my process, the PartialInvoiceID is not concatenate with the InvoiceID and it resets the value when one splitter is finished. And assign only one value.

Is there any way that I can concatenate the PartialInvoiceID?

E.g 
What I want
After 1st Splitter > PartialInvoiceID = 1400000006
After 2nd Splitter > PartialInvoiceID = 1400000006,1400000007
After 3rd Splitter > PartialInvoiceID =  1400000006,1400000007, 1400000008
 
What I get
After 1st Splitter > PartialInvoiceID = 1400000006
After 2nd Splitter > PartialInvoiceID = 1400000007
After 3rd Splitter > PartialInvoiceID =  1400000008
View Entire Topic
robertot4s
Contributor
0 Kudos

Hi @Pyae_Phyo_Thwe ,

With your groovy script you access to the content of a property with name "PartialInvoiceID", but not to the  content of the global variable with the same name. To read the content of a global variable you always need to use a Content Modifier before, here you have an example:

https://community.sap.com/t5/technology-blogs-by-members/cloud-integration-how-to-dynamically-use-a-...

Best regards,

Roberto

Pyae_Phyo_Thwe
Explorer
0 Kudos
I have added the content modifier as in the link you shared. But it does not work and when I traced, it seems that the variable "PartialInvoiceID" is reset after one splitter has finished processing. So, when next splitter comes, it becomes blank and there is no pervious value and it stores the new value. Could you please advise how should I use the variable not to be reset after each splitter? I have also tried by adding the Write Variable and Content Modifier before the splitter begins. But it doesn't work and have same error. Thanks a lot for your answer.
robertot4s
Contributor
0 Kudos

Hi @Pyae_Phyo_Thwe , do you have parallel processing activated in the splitter? With parallel processing I think it cannot work. With sequential processing, you have to Create the property and read the global variable inside the splitter:

robertot4s_1-1742565605426.png

If it doesn't work, another option is to add a join+gather at the end of the splitter and concatenate the invoice ids at the end of the iflow.

Pyae_Phyo_Thwe
Explorer
0 Kudos

Hi @robertot4s.

I have tried by Creating the property. But it is the same and the variable is reset after one splitter is finished working. For the another option, join+gather, do I have to add after the groovy script? Could you pls give advice to me?

Thanks in advance.

Pyae

robertot4s
Contributor
0 Kudos

Hi @Pyae_Phyo_Thwe ,

I have tested in my test environment and it is working fine reading and writing the global variable inside the splitter:

robertot4s_0-1742816013480.png

Regards,

Roberto

 

Pyae_Phyo_Thwe
Explorer
0 Kudos

Hi @roberto4s

Really appreciate for your help and thanks for your support. But I couldn't get the correct value till now. I have shown the step by step screenshot of each component. Could you pls advise which is not the correct one? And also could you provide your steps in details?1.png

 

2.png

3.png

スクリーンショット 2025-03-25 093053.png

5.png6.png

1.png

 

robertot4s
Contributor
0 Kudos

Hi @Pyae_Phyo_Thwe ,

When you write the global variable, in the following step, the name should be "PartialInvoiceID", because it is the name you are using when reading the global variable:

robertot4s_0-1742906606946.png

hope it helps!

Roberto

 

Pyae_Phyo_Thwe
Explorer
0 Kudos

Hi @roberto4s,

Really appreciate for your help and thanks for your support.

Although I write PartialInvoiceID, it is the same error and there is only one value in PartialInvoiceID.

Thanks.

robertot4s
Contributor
0 Kudos

Hi @Pyae_Phyo_Thwe ,

You are deleting the content of PartialInvoiceID in this step, please try removing this step.

robertot4s_0-1742998786944.png

Regards,

Roberto

 

Pyae_Phyo_Thwe
Explorer
0 Kudos

Hi @roberto4s,

Thanks a lot for your help and support. Finally, I got it. I don't even need the Content Modifier 6. But I would like to ask one thing. If I want to use that PartialInvoiceID from another flow, is it possible to use? In my project, I used local process call and PartialInvoiceID is in process call and I want to use that PartialInvoiceID from main flow. I want to call the PartialInvoiceID after the Process Call 1. Is that possible?

Pyae_Phyo_Thwe_0-1743131751398.png

 

Best regards,

Pyae

robertot4s
Contributor
0 Kudos

Hi @Pyae_Phyo_Thwe ,

When you write the global variable, if you have marked the flag "Global scope", you can read the variable from any iflow.

Regards,

Roberto

robertot4s
Contributor
0 Kudos

Hi @Pyae_Phyo_Thwe ,

If it is working fine please mark a comment as 'Accepted Solution' to close de post.

Thanks!

Roberto

 

Pyae_Phyo_Thwe
Explorer
0 Kudos

Hi Roberto, 

Thanks a lot for support and help. It works fine now.

Best Regards,

Pyae

Pyae_Phyo_Thwe
Explorer
0 Kudos

Hi Roberto.

I want to delete the value in PartialInvoiceID in my main flow. And so, I use as in below. But there is still value in PartialInvoiceID. Could you please guide me how should I delete the value in PartialInvoiceID.  The purpose of deleting the value in PartialInvoiceID is to clear the old value assign in that variable.

Pyae_Phyo_Thwe_0-1743668523190.png

Best Regards,

Pyae

 

robertot4s
Contributor
0 Kudos

Hi @Pyae_Phyo_Thwe ,

With the Content Modifier you can delete a property or a header, not a global variable. If you want to clear the global variable, you can use the "Write Variables" and assign an empty value.

Regards,

Roberto