cancel
Showing results for 
Search instead for 
Did you mean: 

Conversion of Chinese flat file (GB18030) to XML in SAP PI 7.11

Former Member
0 Kudos

Hi All,

There is a requirement in my project to convert incoming Chinese flat file (GB18030 encoding) to XML as below:

Input Chinese flat file:

So, the input XML in PI should look as below :

<RECORD>

     <TITLE>

          <Title01>SJJK0201</Title01>

          <Title02>已开发票传出897</Title02>

          <Title03>20151026</Title03>

          <Title04>20151026</Title04>

     </TITLE>

     <HEADER>

          <Header01>//发票1</Header01>

          <Header02>0</Header02>

          <Header03>1</Header03>

          <Header04>2</Header04>

          <Header05>3100143320</Header05>

          ...

          <Header25>郑谨</Header25>

     </HEADER>

     <ITEM>

          <Item01>0</Item01>

          <Item02>照明产品31145 欣美LED吊灯白色20W 240V</Item02>

          ...

          <Item11>11520</Item11>

     </ITEM>

     <ITEM>

          <Item01>1</Item01>

          <Item02>折扣行数1(39.261%)</Item02>

          ...

          <Item11>11520</Item11>

     </ITEM>

     <ITEM>

          <Item01>0</Item01>

          <Item02>照明产品33350 恒典(方形)LED吸顶灯</Item02>

          ...

          <Item11>11520</Item11>

     </ITEM>

     <ITEM>

          <Item01>1</Item01>

          <Item02>折扣行数1(39.262%)</Item02>

          ...

          <Item11>11520</Item11>

     </ITEM>

</RECORD>

<RECORD>

     <HEADER>

          <Header01>//发票2</Header02>

          <Header02>0</Header02>

          <Header03>0</Header03>

          <Header04>2</Header04>

          <Header05>3100143320</Header05>

          ...

          <Header25>郑谨</Header25>

     </HEADER>

     <ITEM>

          <Item01>0</Item01>

          <Item02>照明产品31205 木忆LED吸顶灯(钱柜)60W 230V</Item02>

          ...

</RECORD>

We are using SAP PI 7.11 and source adapter is SFTP.

In the source adapter, we have used below modules:
1. localejbs/Seeburger/CharsetConversion -> for converting gb18030 to utf-8

2. localejbs/AF_Modules/MessageTransformBean -> for content conversion

But we are unable to handle it MessageTransformBean module.

Can you please suggest ?

Accepted Solutions (1)

Accepted Solutions (1)

apu_das2
Active Contributor
0 Kudos

Hi Debashis,

As per your requirement only way to create this using FCC is KeyFieldValue.

I am not sure whether you have any keyFieldvalue defined or not in the incoming file. If it has then you can use that to identify Title, Header,ITEM and create your target structure else you have two ways to handle this -

1. Define only single parameter in sender DT and Target like below -

    Source

    Record    -  0.unbound

         Text   -  0.1

   Target

    Record   - 0.unbound

        Title   -0.1

            TitleFieldValue - 0.unbound

        Header - 0.1

            HeaderFieldValue - 0.unbound

        ITEM - 0.unbound

            ITEMFieldValue - 0.unbound

Using simple FCC put your whole file content in Text parameter and then write a UDF to extract the values there and populate in the target side using multiple result List


2. Else use JAVA Mapping.


Thanks,

Apu

Former Member
0 Kudos

Hi Apu,

Thanks for your reply.

The incoming file has no key field value defined. Hence, we are facing problem in handling with FCC.

Now, as per your first option I can use FCC as below:

Plain2XML xml.ConversionType SimplePlain2XML

Plain2XML xml.recordsetName RECORD

Plain2XML xml.recordsetStructure Text,1

Plain2XML xml.Text.endSeparator 'nl'

Plain2XML xml.Text.fieldNames Text01,Text02,Text03,...

Plain2XML xml.Text.fieldSeparator ~~

Is my understanding correct ?

apu_das2
Active Contributor
0 Kudos

Hi,

Make it like that -

Plain2XML xml.ConversionType        SimplePlain2XML

Plain2XML xml.recordsetName    RECORD

Plain2XML xml.recordsetStructure    Text,1

Plain2XML xml.Text.endSeparator     'nl'

Plain2XML xml.Text.fieldNames         Text

Plain2XML xml.Text.fieldSeparator     'nl'

So what will happen- you will get all the value in text field including separator ~~.

Now split it in the UDF and arrange in the array as per your requirement and populate to the target structure

Mapping part of UDF should like below -

Text -> remove Context -> UDF -> ITEM

                                                          -> Split By Value -> ITEMFieldValue

You you face difficulties to handle all in a single UDF then you can write 3 separate UDF (one for Title,one For Header and one for ITEM) and map accordingly.

Thanks,

Apu

Former Member
0 Kudos

Hi Apu,

Thanks for the detailed reply.

I think this is going to work out.

And as an other alternative, how to use JAVA mapping. I mean is the input structure for JAVA mapping is Text structure as discussed above. And how to start with the code for JAVA mapping, any links/blogs to help ?

Regards,

Debashis

apu_das2
Active Contributor
0 Kudos

Hi Debashis,

I think for your requirement UDF will be better than JAVA mapping.

You will get plenty of blogs for writing JAVA mapping. Try the upper mentioned solution.

Search some blogs for JAVA mapping. If you decide to go for JAVA mapping and stuck somewhere let me know I can help you then

Please don't forget to mark my answers helpful/Correct if it really helps you.

Thanks,

Apu

Former Member
0 Kudos

Hi Apu,

I tried implementing UDFs for handling the flat file. But the mapping complexity is increasing, as there are 4 target Title fields, 25 target Header fields and 10 target Item fields. Hence, I am ending up writing 4+25+10 = 39 UDFs, for passing value to each field.

Can you please help here ?

Thanks,

Debashis

apu_das2
Active Contributor
0 Kudos

Hi Denashis,

It can be handled through single UDF.

But if you find it difficult you cal write 3 UDFs.

One for Title fields generation

One for Header fields generation

One for Item fields generation


For all required output parameters you just need to create result List accordingly.

Like for UDF of Header you will have 5 resultlists - one for Root Header target and 4 others for target parameters.


Thanks,

Apu

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi All,

The Chinese flat file has been handled by use of 4 UDFs in PI mapping.
Now I'm facing one more challenge.


The target structure is an xsd version of IDOC and we have to populate the target fields RCVPRT, RCVPRN dynamically.

It has to be populated dynamically because the values of RCVPRT, RCVPRN changes as per environment like Dev, Quality, Prod.

Can you please help with this ?

apu_das2
Active Contributor
0 Kudos

Hi Debashis,

Use separate naming convention for the Business system of your DEV,QA and PROD system.

Then use sender available for graphical mapping and accordingly writing logic you can easily pass RCVPRT and RCVPRN value.

Thansk,

Apu

maheswarareddykonda
Active Contributor
0 Kudos

Hi Debashis,

hope u know me in electrolux

i guess you have maintained system names environment wise..here you just use Sender function which is available under constants in graphical mapping

Sender--fixedvalues---RCVPRT

fixedvalues u can be maintained something like below

DER---DER100

QER---QER100

PER---PER100

markangelo_dihiansan
Active Contributor
0 Kudos

Hi Debashis,

Can you try the steps mentioned in this blog?

Regards,

Mark

Former Member
0 Kudos

Hi Mark,

Thanks for the blog.

The conversion of GB18030 encoding to UTF-8 has been handled via module localejbs/Seeburger/CharsetConversion.

But the problem I'm facing with is how to arrange the input flat file as per the required XML structure. Unable to handle it with MessageTransformBean module.

Regards,

Debashis