Working with Large objects(LOB) in RAP

Large objects are big data stored in your application, such as:

  • Files (PDFs, images, documents)

  • Large text

  • Binary data

In ABAP, you typically use:

  • STRING - Very long text data

  • XSTRING- Very large binary data (e.g., files, images)

  • RAWSTRING- Large binary data 

Steps to implement LOB

Step 1: Create a Header table with following fields.

@EndUserText.label : 'Header table for Student'

@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE

@AbapCatalog.tableCategory : #TRANSPARENT

@AbapCatalog.deliveryClass : #A

@AbapCatalog.dataMaintenance : #RESTRICTED

define table ztl_ab_hdr_stu12

{


key client : abap.clnt not null;

key stu_id : abap.dec(10,0) not null;

stu_name : abap.char(25);

stu_age : abap.numc(2);

stu_course : abap.char(30);

stu_cour_dur : abap.numc(2);

stu_status : abap_boolean;

stu_gender : abap.char(1);

stu_dob : abap.dats;

last_ch_time : timestampl;

last_ch_date : timestampl;


}

    
        * Check and activate. 

Step 2: Create an item table with following fields.

@EndUserText.label : 'Student Item table'

@AbapCatalog.enhancement.category : #NOT_EXTENSIBLE

@AbapCatalog.tableCategory : #TRANSPARENT

@AbapCatalog.deliveryClass : #A

@AbapCatalog.dataMaintenance : #RESTRICTED

define table ztl_ab_itm_stu12

{


key client : abap.clnt not null;

key attch_id : abap.char(32) not null;

stu_id : abap.dec(10,0) not null;

comments : abap.char(30);

attchment : zattach;

mimetype : abap.char(128);

filename : abap.char(128);


}



            * Check and activate 

Step 3: Create Interface view for header table.

@AbapCatalog.viewEnhancementCategory: [#NONE]

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Header Interface view'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

}

define root view entity ZIV_AB_HDR_STU12

as select from ztl_ab_hdr_stu12

composition [1..*] of ZIV_AB_ITM_STU12 as _attach

{

key stu_id as StuId,

stu_name as StuName,

stu_age as StuAge,

stu_course as StuCourse,

stu_cour_dur as StuCourDur,

stu_status as StuStatus,

stu_gender as StuGender,

stu_dob as StuDob,

last_ch_time as LastChTime,

last_ch_date as LastChDate,

_attach

}

        * Check and activate. 

Step 4: Create Interface view for item table.

@AbapCatalog.viewEnhancementCategory: [#NONE]

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Item Interface view'

@Metadata.ignorePropagatedAnnotations: true

@ObjectModel.usageType:{

serviceQuality: #X,

sizeCategory: #S,

dataClass: #MIXED

}

define view entity ZIV_AB_ITM_STU12

as select from ztl_ab_itm_stu12

association to parent ZIV_AB_HDR_STU12 as _Student

on $projection.StuId = _Student.StuId

{

key ztl_ab_itm_stu12.attch_id as AttchId,

ztl_ab_itm_stu12.stu_id as StuId,

ztl_ab_itm_stu12.comments as Comments,

ztl_ab_itm_stu12.attchment as Attchment,

ztl_ab_itm_stu12.mimetype as Mimetype,

ztl_ab_itm_stu12.filename as Filename,

_Student

}

    
        * Check and activate. 

Step 5: Create projection/consumption view for above header view.

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Consumption view for Header'

@Metadata.ignorePropagatedAnnotations: true

define root view entity zcv_ab_hdr_stu12

provider contract transactional_query

as projection on ZIV_AB_HDR_STU12

{

@UI.facet:

[{

id : 'Student',

purpose: #STANDARD,

type: #IDENTIFICATION_REFERENCE,

label: 'Student',

position: 10

},

{

id : 'attach',

purpose: #STANDARD,

type: #LINEITEM_REFERENCE,

label: 'Attachments',

position: 20,

targetElement: '_attach'

}

]

@UI:

{

lineItem: [{ position: 10 , label : 'Student ID' }],

identification: [{ position: 10 , label : 'Student ID' }],

selectionField: [{ position: 10 }]

}

key StuId,

@UI:

{

lineItem: [{ position: 20 , label : 'Student Name'}],

identification: [{ position: 20 , label : 'Student Name' }],

selectionField: [{ position: 20 }]

}

StuName,

@UI:

{

lineItem: [{ position: 30 , label : 'Student Age'}],

identification: [{ position: 30 , label : 'Student Age' }]

}

StuAge,

@UI:

{

lineItem: [{ position: 40 , label : 'Student Course'}],

identification: [{ position: 40 , label : 'Student Course' }]

}

StuCourse,

@UI:

{

lineItem: [{ position: 50 , label : 'Student Course Duration'}],

identification: [{ position: 50 , label : 'Student Course Duration' }]

}

StuCourDur,

@UI:

{

lineItem: [{ position: 60 , label : 'Student Status'}],

identification: [{ position: 60 , label : 'Student Status' }]

}

StuStatus,

@UI:

{

lineItem: [{ position: 70 , label : 'Student Gender'}],

identification: [{ position: 70 , label : 'Student Gender' }]

}

StuGender,

@UI:

{

lineItem: [{ position: 80 , label : 'Student DOB'}],

identification: [{ position: 80 , label : 'Student DOB' }]

}

StuDob,

LastChTime,

LastChDate,

/* Associations */

_attach : redirected to composition child zcv_ab_itm_stu12

}

        * Check and activate 

Step 6: Create projection/consumption view for above item view.

@AccessControl.authorizationCheck: #NOT_REQUIRED

@EndUserText.label: 'Consumption view for Item'

@Metadata.ignorePropagatedAnnotations: true

define view entity zcv_ab_itm_stu12 as projection on ZIV_AB_ITM_STU12

{

@UI.facet:

[{

id : 'attach',

purpose: #STANDARD,

type: #IDENTIFICATION_REFERENCE,

label: 'Attchment Information',

position: 10

}]

@UI:

{

lineItem: [{ position: 10 , label : 'Attachment ID'}],

identification: [{ position: 10 , label : 'Attachment ID' }]

}

key AttchId,

@UI:

{

lineItem: [{ position: 20 , label : 'Student ID'}],

identification: [{ position: 20 , label : 'Student ID' }]

}

StuId,

@UI:

{

lineItem: [{ position: 30 , label : 'Comments'}],

identification: [{ position: 30 , label : 'Comments' }]

}

Comments,

@Semantics.largeObject:{

mimeType: 'Mimetype',

fileName: 'Filename',

contentDispositionPreference: #INLINE

}

@UI:

{

lineItem: [{ position: 40 , label : 'Attachment'}],

identification: [{ position: 40 , label : 'Attachment' }]

}

Attchment,

Mimetype,

Filename,

/* Associations */

_Student : redirected to parent zcv_ab_hdr_stu12

}

        
    * Check and activate .

Step 7: Create behavior definition for interface view header.

managed implementation in class zbp_iv_ab_hdr_stu12 unique;

strict ( 2 );

with draft;

define behavior for ZIV_AB_HDR_STU12 alias Student

persistent table ztl_ab_hdr_stu12

draft table ztl_ab_hdr_dra12

lock master

total etag LastChDate

authorization master ( instance )

etag master LastChDate

{

create ( authorization : global );

update;

delete;

//field ( readonly ) StuId;

association _attach { create; with draft; }

draft action Activate;

draft action Discard;

draft action Edit;

draft action Resume;

draft determine action Prepare;

mapping for ztl_ab_hdr_stu12

{

StuId = stu_id;

StuName = stu_name;

StuAge = stu_age;

StuCourse = stu_course;

StuCourDur = stu_cour_dur;

StuStatus = stu_status;

StuGender = stu_gender;

StuDob = stu_dob;

LastChDate = last_ch_date;

LastChTime = last_ch_time;

}

}


define behavior for ZIV_AB_ITM_STU12 alias attach

persistent table ztl_ab_itm_stu12

draft table ztl_ab_itm_dra12

lock dependent by _Student

authorization dependent by _Student

//etag master

{

update;

delete;

field ( readonly ) StuId;

association _Student { with draft; }

mapping for ztl_ab_itm_stu12

{

AttchId = attch_id;

StuId = stu_id;

Comments = comments;

Attchment = attchment;

Mimetype = mimetype;

Filename = filename;

}

}

                * Implement the class and method.
                * Check and activate.

Step 8: Create behavior definition for consumption view header.

projection;

strict ( 2 );

use draft;


define behavior for zcv_ab_hdr_stu12 alias Student

{

use create;

use update;

use delete;


use action Activate;

use action Discard;

use action Edit;

use action Resume;

use action Prepare;


use association _attach { create; with draft; }

}


define behavior for zcv_ab_itm_stu12 alias attach

{

use update;

use delete;


use association _Student { with draft; }

}

    
* Check and activate .

Step 9: Create service definition for consumption view.

@EndUserText.label: 'Service definition for Header'

define service Zsd_ab_rap_stu12 {

expose zcv_ab_hdr_stu12;

expose zcv_ab_itm_stu12;

}

    
* Check and activate.

Step 10: Create service binding for consumption view.
        * Check and activate the service.
        * Publish the service.

Testing
        * Preview the application.
        * Create entries.

        * Click on create.
        * If click on file upload button you can see text in new window.


********************************Thank you*****************************


Comments

Popular posts from this blog

New syntax for append- VALUE (new syntax 7.4+) in ABAP

Read statement new syntax in ABAP. (7.4+).

Concatenation new syntax( 7.4+ ).