cancel
Showing results for 
Search instead for 
Did you mean: 

CSV File Upload for Custom BO?

former_member183363
Active Contributor
0 Kudos

Hello everyone,

I'm wondering if it's possible to create a custom BO and corresponding WorkCentre, where one can input a CSV file (for example), and have an ABSL script strip the values out and process them. I know the SAP built-in file upload facility only takes XML thanks to this thread --- http://scn.sap.com/thread/3551730 --- but it is possible/feasible to build your own miniature one? No problem if it's not, I just want to know what's feasible. Thanks in advance.

Lewis

Accepted Solutions (1)

Accepted Solutions (1)

former_member183363
Active Contributor

Bump. No-one with knowledge of handling binary strings in ABSL?

HorstSchaude
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hello Lewis,

Normally binary is used for pictures and such.Therefore there is no need ot convert it to string.

No chance to upload the CSV as text?

Bye,

   Horst

former_member183363
Active Contributor
0 Kudos

Horst,

Ahh I see, so it's not possible to process binary, thanks.

You mean as a .txt file attachment? Wouldn't that still have file contents as binary? Or do you mean insert it into the 'notes' section and process that?

Lewis

Former Member
0 Kudos

Hi Lewis,

it is much easier as you think with the CSV.

If you call the "ToString()" on the BinaryObject.content from the File and the Content is a String the "real" string will be returned.

Rough Example

Test Data

Short ABSL to raise the text lines to the UI


import ABSL;

if(this.AttachmentFolder.IsSet()){

    foreach(var doc in this.AttachmentFolder.Document){

        raise CSVScreenOutput.Create("I", "Processed Document", doc.Name);

        var docContent = doc.FileContent.BinaryObject.content.ToString();

        var line = 1;

        var startLine =  0;

        var endLine = -1;

        while(true){

            endLine = docContent.Find("\n", startLine);

            if(endLine == -1){

                break;

            }

            raise CSVScreenOutput.Create("I", "Document Line " + line.ToString() + " Content", docContent.Substring(startLine, endLine - startLine - 1));

            line = line + 1;

            startLine = endLine + 1;

        }

    }

}

Result

Beste regards

Tobias

former_member183363
Active Contributor
0 Kudos

Ah-ha-ha...we have a winner. This should do the trick! Thanks Tobias, extremely helpful.

Former Member
0 Kudos

Hi Tobias ,

I have tried to upload csv file by following your post . But my entries are not getting saved into the csv file .

This is my bo

This is my absl code

This is my screen where i have given entries to get upload into csv .

As my entries are getting saved in bo . But i cant able to see my entries in csv file

Thanks and regards ,

lokesh

Former Member
0 Kudos

Hi Lokesh,

If i understand you correctly you do not want to import values from an CSV to ByD, you want to export ByD Data to CSV.

Is this correct?

So my code example was made to handle the import case. If you want to have your data exported you can use the export to MS Excel Functionality in the OWL and you have your data of the root node or you can use reports for your own BOs.

Best regards,

Tobias

Former Member
0 Kudos

Hi Tobias ,

                 Thanks for your reply .When i upload csv file with data in it , the data is not saving into the bo . Can you please help me to upload the data by checking my absl code or any thing i am missing ?????????????????

Thanks and regards ,

lokesh

Former Member
0 Kudos

Hi Lokesh,

in your ABSL script there is no handling for the CSV Content Handling so if you add the part where you split the lines into the contents and assign this into your BO everything should work.

Best regards,

Tobias

Answers (3)

Answers (3)

former_member183363
Active Contributor

So I have a file attachment upload facility --- or at least the button that one can place on the UI, see below screenshot --- but it doesn't seem to have done anything. When I click the button it allows me to select a file by using the explorer that pops up, but I stuck a bit in the AfterModify script that shows me whether 'this.Attachments.DocumentList.Count() > 0', but it's not showing anything so I guess I'm missing a piece or two of the puzzle. Any ideas folks?

Former Member
0 Kudos

Hi Lewis,

for using the Attachments Folder you an use an reuse component within the Studio.

You can find this on the following Path:

/SAP_BYD_APPLICATION_UI/Reuse/Attachments/documentlist.EC.uicomponent

Best regards

Tobias

former_member183363
Active Contributor
0 Kudos

EDIT: the below can be ignored. I was flicking through my old training book and realised there was a bit about exactly this, so now I have a working file uploader. I can fetch the binary content of a file --- but does anyone know about parsing this as a CSV file? I need to be able to get the contents of the comma-separated values instead of just a big load of 1s and 0s.

Tobias,

I found it --- Configuration Explorer tab, right? I dragged it in to a new row in the UI designer as in figure 1; however, the screen dumped first time round when I viewed it in ByDesign (see figure 2), and second time round --- after logging off and on again --- only the file upload bit I've put in there appeared. Ideas? Do I need to bind it to something?

Figure 1: the screen with the EC as viewed in the UI designer.

Figure 2: The dump that occurred first time round.

Lewis

Former Member
0 Kudos

Hi Lewis,

you have to bind the Embedded Component to your Attachment folder node (see message in the dump).

This can be done with clicking the bind Button on the Embedded Component after you added the added the Attachment folder to the Data Structure in the PDI.

Beste regards

Tobias

former_member183363
Active Contributor
0 Kudos

Tobias,

I managed it --- see my 'edit' note at the top of the previous reply, thanks.

Lewis

former_member200567
Active Contributor
0 Kudos

Hi Lewis,

->I was flicking through my old training book and realised there was a bit about exactly this, so now I have a working file uploader

I still cannot figure out how to use File Upload and access the uploaded file content.

Can you please share with us?

Best Regards,

Fred

Former Member
0 Kudos

Hi Fred,

I think that you need to bind it to a BinaryObject element?

Thanks,

Will

former_member200567
Active Contributor
0 Kudos

Hi Will,

Thanks.

I bound it, but there is no content in the Binary Object after a file has been selected.

Best Regards,

Fred

Former Member
0 Kudos

I sort of got it working.

I created an element with the datatype BinaryObject (BASIS), then in the UI designer I binded the File data structure to the BO. Then I binded content to the BinaryObject element.

I can now see the file content but nothing else.

Pretty sure I'm doing it wrong though

Will

former_member200567
Active Contributor
0 Kudos

Hi Will,

I still cannot get the file content.

I did the same binding.

Best Regards,

Fred

former_member200567
Active Contributor
0 Kudos

Hi Will,

I still cannot get it right.

Best Regards,

Fred

Former Member
0 Kudos

Hi Fred,

I'll try and do it from scratch again and record the steps

Will

former_member200567
Active Contributor
0 Kudos

Hi Will,

That would be great. 

Thanks,

Fred

Former Member
0 Kudos

Hi,

This will get the file content working, but not the fileName (still cant get that to work)

  1. Delete any existing fileupload buttons and datamodels
  2. Drag in new FileUpload to the screen
  3. On data model tab, drag the BO BinaryObject fileName element to Root->FileUpload->fileName
  4. drag uri to content

Let me know if this works

Will

former_member183363
Active Contributor
0 Kudos

Bump.

Former Member
0 Kudos

Hi Lewis,

this is not an feature of the Cloud Application Studio, but CSV is an very simple format and you could build your very own "Helper BO" to enable CSV Fileupload.

You could create an BO with an attachment folder and some logic to parse the CSV and insert the content to your BO structure.

Best regards

Tobias

former_member183363
Active Contributor
0 Kudos

Oh, that's a good idea. Have you (or anyone else reading this) got any sample code or a brief overview of the process for such a thing? I've not created an attachment folder from scratch before.

Former Member
0 Kudos

You can create an AttachementFolder in your own BO with adding this to your BO Definition:


[DependentObject(AttachmentFolder)]

node Attachments;

After that you can add this to the UI and bind the data and you can also use the data within the folder.

former_member183363
Active Contributor
0 Kudos

Ah-ha, excellent, now I have a starting point. Thanks for this; I'll be seeing if I can implement this shortly, I'll get back to you.

former_member200567
Active Contributor
0 Kudos

Hi Lewis,

Here is some codes.

import AP.Common.GDT;

import  BASIS.Global;

import  DocumentServices.Global;

foreach(var att in  this.myAttachments.Document){

var fileContant =  att.FileContent.BinaryObject.content.ToString();

}

Hope this helps.

Fred.